Skip to content

Give survey finishers a free sticker claim link - #6608

Open
brsbl wants to merge 4 commits into
web/community-surveyfrom
web/community-survey-stickers
Open

brsbl wants to merge 4 commits into
web/community-surveyfrom
web/community-survey-stickers

Conversation

@brsbl

@brsbl brsbl commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Survey finishers had no way to claim their thank-you stickers, and a list of codes would have had to be hand-loaded into the production database. Layer 3 of 4.

What changed

  • Finishing the survey reserves a sticker claim, then asks Shopify to create a one-time $0 discount for it.
  • The thank-you shows "Claim my bb stickers", which opens a $0 checkout with the code and email filled in.
  • Nothing is loaded into the database: codes are random, stored on the claim and created through the Shopify Admin API.
  • One claim per email (ignoring case and +tags), up to COMMUNITY_STICKER_LIMIT (1000).
  • Repeat emails, the limit and missing Shopify settings each get their own message; people who finish while claims are closed can claim later.
  • A claim Shopify couldn't create stays pending. Email survey finishers their answers and claim link #6609 retries it and emails the link, so don't enable collection on this layer alone.
  • claims.ts owns the claim: the save batch, the Shopify step and the messages. The handler only checks the request and replies.
  • Shopify calls time out after 5 seconds, refuse redirects, and reuse the stored code so a retry never creates a second discount.
  • Uses the community_sticker_claim and community_survey_email tables from Add a community survey API that stores answers #6624's migration.
  • deploy-web.yml syncs SHOPIFY_CLIENT_ID and SHOPIFY_CLIENT_SECRET from GitHub secrets and skips them while they're unset.

How you verified

  • Handler tests run against a real D1 database with a stubbed Shopify API.
  • They cover one claim per email, the limit under four concurrent finishers, claims reopening after a closed period, a pending claim when Shopify is down or rejects the token, a duplicate-code error or lost reply treated as created, and rollback.
  • Headless Chromium against a dev server whose Shopify token request really failed: pending, repeat-email, limit and not-open messages all showed, and the D1 rows matched.
  • Creating a code in a real store needs the Shopify app, which is a launch step.
  • Remote CI: passed. Run

BB-Thread-ID: thr_yz6t8hi7s8

AGENT GENERATED

@brsbl
brsbl force-pushed the web/community-survey-stickers branch 2 times, most recently from 6d54d39 to 9ee44d7 Compare October 30, 2026 03:12
@brsbl
brsbl force-pushed the web/community-survey-stickers branch 3 times, most recently from 64fe7a4 to b2820b6 Compare October 30, 2026 04:21
@brsbl
brsbl force-pushed the web/community-survey-stickers branch from b2820b6 to e77b0c4 Compare October 30, 2026 04:24
@brsbl
brsbl added this pull request to stack #6625 October 30, 2026 04:38
@brsbl
brsbl force-pushed the web/community-survey-stickers branch from e77b0c4 to e8918bf Compare October 30, 2026 04:43
@brsbl
brsbl force-pushed the web/community-survey-stickers branch from e8918bf to db3d733 Compare October 30, 2026 05:23
@brsbl
brsbl force-pushed the web/community-survey-stickers branch 2 times, most recently from 220b7bb to d335e3d Compare October 30, 2026 06:16
@brsbl
brsbl force-pushed the web/community-survey-stickers branch from d335e3d to 14fc24b Compare October 30, 2026 06:29
@brsbl
brsbl force-pushed the web/community-survey-stickers branch from 14fc24b to 2d253c7 Compare October 30, 2026 06:50
@brsbl
brsbl force-pushed the web/community-survey-stickers branch 2 times, most recently from 1241c56 to 4772fa1 Compare October 30, 2026 07:09
@brsbl
brsbl force-pushed the web/community-survey-stickers branch from 4772fa1 to 524a487 Compare October 30, 2026 08:40
@brsbl
brsbl force-pushed the web/community-survey-stickers branch from 524a487 to 376ccf9 Compare October 30, 2026 10:04
@brsbl
brsbl marked this pull request as ready for review October 30, 2026 10:27
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T10:28:59.378574Z 2d67646 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2d67646051

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +256 to +259
{result.claimLink ? (
<a
className="btn btn-primary"
href={result.claimLink}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Expose sticker claims through the SDK and bb CLI

The new sticker-claim feature is available only through the survey's web UI. Searching packages/sdk, packages/plugin-sdk, and apps/cli finds no survey submission or sticker-claim surface, so SDK and CLI users cannot obtain the claim link through a supported interface. Add and document corresponding SDK and CLI entry points alongside this UI, as required by the root AGENTS.md feature-parity rule.

AGENTS.md reference: AGENTS.md:L26-L26

Useful? React with 👍 / 👎.

@brsbl
brsbl force-pushed the web/community-survey-stickers branch 2 times, most recently from 21fa41b to e972839 Compare October 30, 2026 11:38
brsbl and others added 4 commits October 30, 2026 12:03
Each saved survey claims one random one-time Shopify code, at most one per
normalized email, in the same D1 batch as the answers. The thank-you view
links to the store's cart with the code applied and the email filled in.

BB-Thread-ID: thr_yz6t8hi7s8

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The save batch now reserves a claim with a random stored code, under a
pack limit and one claim per normalized email, then creates a one-time
discount for that code through the Admin API. A claim Shopify can't create
stays pending. Nothing has to be loaded into the database, and the deploy
workflow syncs the Shopify app credentials when they exist.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fetch the token once per create and skip the lookup when the token itself
failed, refuse redirects so credentials never follow one, surface GraphQL
error codes as the failure reason, default the pack limit to 1000, and
don't report a saved survey as failed when the follow-up status write
fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claims.ts now owns the save batch, the Shopify step and the claim
messages, so the handler only checks the request and replies. The Shopify
client fetches a token per create instead of caching one, reports
failures as auth, unreachable or rejected, and the tests use one Shopify
mode per case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant