@redeemid/emdash 0.0.20 → 0.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -18
- package/docs/developer-api.md +13 -10
- package/docs/shopify-flow.md +3 -3
- package/docs/shopify-setup.md +13 -7
- package/package.json +1 -1
- package/src/access.ts +3 -0
- package/src/api-version.ts +1 -1
- package/src/contract.ts +1 -1
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ Memberships and paywalls for [EmDash](https://github.com/emdash-cms/emdash) site
|
|
|
7
7
|
|
|
8
8
|
Readers sign in with the store's own customer account. Their Shopify customer tags decide what they can read. Shopify keeps the store, checkout, orders and subscriptions, and EmDash keeps the content. Nothing on the site grants access by itself, so there is one source of truth for who paid for what.
|
|
9
9
|
|
|
10
|
-
**Status: 0.0.
|
|
10
|
+
**Status: 0.0.21, early.** Runs on Node and Cloudflare Workers. Unit tests and an end-to-end test that boots a real EmDash site against a fake Shopify store cover the features below. Expect changes before 1.0.
|
|
11
11
|
|
|
12
12
|
## Contents
|
|
13
13
|
|
|
@@ -129,10 +129,10 @@ Set them as runtime secrets of the site (`.env` locally, `wrangler secret put` o
|
|
|
129
129
|
```sh
|
|
130
130
|
REDEEMID_SHOPIFY_CUSTOMER_ACCOUNT_CLIENT_ID=… # sign-in
|
|
131
131
|
REDEEMID_SHOPIFY_ADMIN_APP_CLIENT_SECRET=… # verifies webhooks
|
|
132
|
-
REDEEMID_SHOPIFY_STOREFRONT_PRIVATE_TOKEN=… # plans, shop and checkout
|
|
132
|
+
REDEEMID_SHOPIFY_STOREFRONT_PRIVATE_TOKEN=… # only to sell on the site: plans, shop and checkout
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
-
The [secrets reference](#secrets) lists the
|
|
135
|
+
The [secrets reference](#secrets) lists the rest. The Setup page prints the command for each secret its steps need.
|
|
136
136
|
|
|
137
137
|
### 5. Render content through RedeemID
|
|
138
138
|
|
|
@@ -148,7 +148,7 @@ import Notices from "@redeemid/emdash/components/Notices.astro";
|
|
|
148
148
|
<Content value={post.data.content} collection="posts" terms={post.data.terms} id={post.id} title={post.data.title} />
|
|
149
149
|
```
|
|
150
150
|
|
|
151
|
-
Use `<Content>` in place of `<PortableText>` for every body that may be locked
|
|
151
|
+
Use `<Content>` in place of `<PortableText>` for every body that may be locked, because plain `<PortableText>` shows everything. You don't have to find them by hand: `redeemidGuard()` scans the site's `.astro` files at build time, and the Status page names each template, with its line, that renders a gated collection's body with `<PortableText>`. While any rule is on, it also lists templates whose collection it can't tell (such as a component given the body as a prop), so you can check them.
|
|
152
152
|
|
|
153
153
|
### 6. Check it
|
|
154
154
|
|
|
@@ -202,15 +202,19 @@ Pass `id` on the entry's own page. It lets the meter count the read, and a locke
|
|
|
202
202
|
**In your own code** (`@redeemid/emdash/access`):
|
|
203
203
|
|
|
204
204
|
```ts
|
|
205
|
-
import { canRead, entryRequirement, readEntry } from "@redeemid/emdash/access";
|
|
205
|
+
import { canRead, entryRequirement, readEntry, siteConfig } from "@redeemid/emdash/access";
|
|
206
206
|
|
|
207
|
-
const verdict = await canRead(Astro, { collection: "posts", terms: post.data.terms });
|
|
207
|
+
const verdict = await canRead(Astro, { collection: "posts", terms: post.data.terms, id: post.id });
|
|
208
208
|
// verdict.allowed; verdict.reason: open | allowed | sign_in | upgrade | disabled | unconfigured
|
|
209
209
|
const read = await readEntry(Astro, { collection: "posts", terms: post.data.terms, id: post.id });
|
|
210
210
|
// adds drip (read.opensAt) and the meter (read.meterLeft), and counts a metered read
|
|
211
|
+
|
|
212
|
+
const config = await siteConfig(Astro.locals);
|
|
213
|
+
const needs = await entryRequirement(config, "posts", post.data.terms, post.id);
|
|
214
|
+
// e.g. [["gold", "pro"]]: readers pass every clause, each with any one of its levels; null when open
|
|
211
215
|
```
|
|
212
216
|
|
|
213
|
-
`
|
|
217
|
+
`siteConfig(Astro.locals)` is the config for this request: your code's config with the Access page's saved settings laid over it. Pass it to the functions that take a `config`, such as `entryRequirement()`, `readPreferences()` and the storefront and catalog calls.
|
|
214
218
|
|
|
215
219
|
## Guides
|
|
216
220
|
|
|
@@ -251,10 +255,12 @@ Each saved entry also gets an **Access** panel in the editor. It shows who can r
|
|
|
251
255
|
| --- | --- |
|
|
252
256
|
| Follow the site rules | What the rules say (the default) |
|
|
253
257
|
| Free to everyone | Nothing |
|
|
254
|
-
| Only
|
|
255
|
-
|
|
|
258
|
+
| Only some levels | One of the levels ticked (none ticked: any signed-in member) |
|
|
259
|
+
| Site rules plus a level | What the rules say and one of the levels ticked |
|
|
260
|
+
|
|
261
|
+
The panel can also hold the entry back for some days of membership, keep the meter off it, lock it until a date and then open it, or keep it free until a date and then lock it. Pass the entry's `id` (or slug) to `<Content>`, `<AccessBadge>` and `<Gate>` so its own rule applies there.
|
|
256
262
|
|
|
257
|
-
Moving an entry to the trash keeps its rule for a restore but frees its slug, so a new entry that takes the slug doesn't inherit the rule.
|
|
263
|
+
Moving an entry to the trash keeps its rule for a restore but frees its slug, so a new entry that takes the slug doesn't inherit the rule.
|
|
258
264
|
|
|
259
265
|
### Meter and drip
|
|
260
266
|
|
|
@@ -359,7 +365,7 @@ Define each field in Shopify (**Settings → Custom data → Customers**); the d
|
|
|
359
365
|
| Decimal | A number, as a string |
|
|
360
366
|
| Date | `YYYY-MM-DD` |
|
|
361
367
|
|
|
362
|
-
Every value is checked against the definition first. One refusal saves nothing, and an empty value clears the field. Scripts can `GET` `/_emdash/api/auth/redeemid/preferences` for `{ fields }`, or `POST` JSON `{ values: { "namespace.key": value } }`. A refused save answers `400` with `fields` mapping each key to `unknown_field`, `read_only`, `invalid_type`, `invalid_choice`, `invalid_length` or `invalid_range`. Saves are limited to 10 a minute per member (`429`). `readPreferences()` and `savePreferences()` in `@redeemid/emdash/preferences` do the same from
|
|
368
|
+
Every value is checked against the definition first. One refusal saves nothing, and an empty value clears the field. Scripts can `GET` `/_emdash/api/auth/redeemid/preferences` for `{ fields }`, or `POST` JSON `{ values: { "namespace.key": value } }`. A refused save answers `400` with `fields` mapping each key to `unknown_field`, `read_only`, `invalid_type`, `invalid_choice`, `invalid_length` or `invalid_range`. Saves are limited to 10 a minute per member (`429`). From your own code, `readPreferences(config, customerId)` and `savePreferences(config, customerId, values)` in `@redeemid/emdash/preferences` do the same (no rate limit there; `config` comes from `siteConfig()`).
|
|
363
369
|
|
|
364
370
|
### Protected files
|
|
365
371
|
|
|
@@ -425,7 +431,7 @@ RedeemID reads them with the Admin API (resync, sign-in, tag webhooks), so they
|
|
|
425
431
|
Members gain and lose access only when Shopify sends tag changes, so RedeemID shows what arrived and warns when deliveries stop.
|
|
426
432
|
|
|
427
433
|
- **Webhooks → Received.** Each delivery's topic, what became of it (processed, skipped, older than what's stored, not used) and the customer ID, with counts of deliveries turned away (bad signature) and failed (storage errors; Shopify sends those again).
|
|
428
|
-
- **Webhooks → Health.** Once a day RedeemID registers again any subscription Shopify dropped (with the Admin API app), and warns when no webhook has come in for a number of days (3 by default, 0 turns it off), or when deliveries were turned away or failed in the last day. **Check now** runs it at once. Warnings show on the page and the dashboard widget
|
|
434
|
+
- **Webhooks → Health.** Once a day RedeemID registers again any subscription Shopify dropped (with the Admin API app), and warns when no webhook has come in for a number of days (3 by default, 0 turns it off), or when deliveries were turned away or failed in the last day. **Check now** runs it at once. Warnings show on the page and the dashboard widget. If you enter an address on the Health tab and the site has an EmDash email provider, they also go by email: once when problems start or change, then once a week while they last.
|
|
429
435
|
- **Webhooks → Setup.** The endpoint, whether signatures can be checked, and the subscriptions.
|
|
430
436
|
- **App events.** What RedeemID did and what came of it: webhooks received, turned away and failed, sign-ins and refusals (by reason), Admin API calls (by operation, with timings), resyncs, tag edits, webhook registrations, settings saves, outbound events that failed, metered reads and the health checks. Filter by event or show problems only. Entries hold ids, labels and outcomes, never bodies, tokens or emails. Failed outbound events also keep the event body (ids and levels, never an email or a name) so they can be sent again.
|
|
431
437
|
- **Reports.** Members on each level, who joined and left in the last 30 days and by week for 12 weeks (from each member's tag dates), sign-ins and metered reads.
|
|
@@ -459,7 +465,7 @@ npx -p @redeemid/emdash redeemid-emdash access posts --id my-story --tags gold-m
|
|
|
459
465
|
npx -p @redeemid/emdash redeemid-emdash member jane@example.com
|
|
460
466
|
```
|
|
461
467
|
|
|
462
|
-
Each command
|
|
468
|
+
Each command POSTs JSON to a staff-only route under `/_emdash/api/plugins/redeemid/`, named after its tool with hyphens (`explain_access` is `explain-access`). Scripts can call those routes directly.
|
|
463
469
|
|
|
464
470
|
### Replacement text
|
|
465
471
|
|
|
@@ -508,7 +514,7 @@ On Cloudflare Workers, `redeemidGuard({ rateLimit: true })` limits how often one
|
|
|
508
514
|
"ratelimits": [{ "name": "REDEEMID_RATE_LIMIT", "namespace_id": "1001", "simple": { "limit": 20, "period": 60 } }]
|
|
509
515
|
```
|
|
510
516
|
|
|
511
|
-
Each action counts separately per visitor (by `CF-Connecting-IP`), and Cloudflare's count is approximate. A visitor over the limit goes back to their page with the `too_many_requests` notice
|
|
517
|
+
Each action counts separately per visitor (by `CF-Connecting-IP`), and Cloudflare's count is approximate. A visitor over the limit goes back to their page with the `too_many_requests` notice; the JSON routes answer `429` with `{ "error": "too_many_requests" }`. If the binding is missing or fails, nothing is limited. Off by default; leave it off on Node.
|
|
512
518
|
|
|
513
519
|
## Reference
|
|
514
520
|
|
|
@@ -548,8 +554,8 @@ Pass one object to both `redeemid(config)` and `redeemidPlugin(config)`. `levels
|
|
|
548
554
|
| `REDEEMID_SHOPIFY_CUSTOMER_ACCOUNT_CLIENT_ID` | Sign-in | Client ID of the Headless storefront's Customer Account API client |
|
|
549
555
|
| `REDEEMID_SHOPIFY_CUSTOMER_ACCOUNT_CLIENT_SECRET` | Sign-in, confidential clients | Its client secret. Leave unset for a public client. |
|
|
550
556
|
| `REDEEMID_SHOPIFY_ADMIN_APP_CLIENT_SECRET` | Webhooks | Client secret of the app that sends the webhooks. Shopify signs each webhook with it. |
|
|
551
|
-
| `REDEEMID_SHOPIFY_ADMIN_APP_CLIENT_ID` |
|
|
552
|
-
| `REDEEMID_SHOPIFY_STOREFRONT_PRIVATE_TOKEN` | Plans, shop, checkout | Storefront API private access token, used server-side |
|
|
557
|
+
| `REDEEMID_SHOPIFY_ADMIN_APP_CLIENT_ID` | Webhook registration, staff tools, preferences, membership dates, Shopify erasure requests | Client ID of that same app. Optional, but most of the admin needs it. |
|
|
558
|
+
| `REDEEMID_SHOPIFY_STOREFRONT_PRIVATE_TOKEN` | Plans, shop, checkout | Storefront API private access token, used server-side. Optional if the site sells nothing. |
|
|
553
559
|
| `REDEEMID_SHOPIFY_STOREFRONT_PUBLIC_TOKEN` | Plans, shop, checkout | Public access token, only used without the private one |
|
|
554
560
|
| `REDEEMID_SHOPIFY_STORE_DOMAIN` | Discovery | The store's domain, only when `shop` isn't in the config |
|
|
555
561
|
| `REDEEMID_EVENTS_SECRET` | Events | Signs outbound events. Set it with `events.url`. |
|
|
@@ -578,6 +584,7 @@ Import each from `@redeemid/emdash/components/<Name>.astro`.
|
|
|
578
584
|
| `ProductSearch` | `productHref`, `limit`, `boxOnly`, `action`, `label`, `quickAdd` | Product search |
|
|
579
585
|
| `Recommendations` | `handle`, `intent`, `limit`, `productHref`, `title`, `quickAdd` | Shopify's recommendations |
|
|
580
586
|
| `ProductGrid` | `products`, `productHref`, `heading`, `quickAdd` | Product cards, for your own lists |
|
|
587
|
+
| `BrowseControls` | `filters`, `pageInfo`, `id`, `search`, `query` | Sort, filter and page controls, for your own lists from `collectionPage()` or `searchProducts()` |
|
|
581
588
|
| `Cart` | `label`, `href`, `drawer` | The cart count, linking to checkout or opening the drawer |
|
|
582
589
|
| `CartView` | `productHref`, `empty` | A cart page |
|
|
583
590
|
| `CartDrawer` | `title` | The cart in a slide-in dialog |
|
|
@@ -605,7 +612,7 @@ Import each from `@redeemid/emdash/components/<Name>.astro`.
|
|
|
605
612
|
| Import | Gives |
|
|
606
613
|
| --- | --- |
|
|
607
614
|
| `@redeemid/emdash` | `redeemid()`, `redeemidPlugin()`, `redeemidGuard()`, config types |
|
|
608
|
-
| `@redeemid/emdash/access` | `canRead()`, `readEntry()`, `entryRequirement()`, `viewer()`, and links: `signInUrl()`, `signOutUrl()`, `accountUrl()`, `cartUrl()`, `refreshUrl()` |
|
|
615
|
+
| `@redeemid/emdash/access` | `siteConfig()`, `canRead()`, `readEntry()`, `entryRequirement()`, `viewer()`, and links: `signInUrl()`, `signOutUrl()`, `accountUrl()`, `cartUrl()`, `refreshUrl()` |
|
|
609
616
|
| `@redeemid/emdash/features` | `hasFeature()`, `viewerFeatures()` |
|
|
610
617
|
| `@redeemid/emdash/preferences` | `readPreferences()`, `savePreferences()` |
|
|
611
618
|
| `@redeemid/emdash/storefront` | `product()`, `collection()`, `plan()`, `money()` and the cart calls |
|
|
@@ -620,7 +627,7 @@ The full developer API (stable exports, JSON routes, the browser client and its
|
|
|
620
627
|
|
|
621
628
|
Under `/_emdash/api/auth/redeemid/`: `login`, `callback`, `logout`, `webhook`, `buy`, `cart`, `cart-edit`, `account`, `preferences` and `privacy`, and the JSON routes `api/state`, `api/cart` and `api/search`. Staff-only routes for the admin, agents and the command line are under `/_emdash/api/plugins/redeemid/`.
|
|
622
629
|
|
|
623
|
-
In the Customer Account API client, set the callback URI to `https://<site>/_emdash/api/auth/redeemid/callback`, the logout URI to `https://<site>/`, and (public clients) the JavaScript origin to `https://<site>`. Point webhooks at `https://<site>/_emdash/api/auth/redeemid/webhook`: `customers/create`, `customers/update`, `customers/delete`, `customers/disable`, `customers/enable`, `customers/merge`, `customer.tags_added
|
|
630
|
+
In the Customer Account API client, set the callback URI to `https://<site>/_emdash/api/auth/redeemid/callback`, the logout URI to `https://<site>/`, and (public clients) the JavaScript origin to `https://<site>`. Point webhooks at `https://<site>/_emdash/api/auth/redeemid/webhook`: `customers/create`, `customers/update`, `customers/delete`, `customers/disable`, `customers/enable`, `customers/merge`, `customer.tags_added` and `customer.tags_removed` (the Setup page registers these for you). The compliance topics `customers/data_request`, `customers/redact` and `shop/redact` go to the same URL, set in the app's own configuration.
|
|
624
631
|
|
|
625
632
|
### Notices
|
|
626
633
|
|
package/docs/developer-api.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Developer API
|
|
2
2
|
|
|
3
|
-
What site code, other plugins and AI agents can rely on in `@redeemid/emdash`. API version **1.
|
|
3
|
+
What site code, other plugins and AI agents can rely on in `@redeemid/emdash`. API version **1.1.0** (`API_VERSION` in `@redeemid/emdash/contract`, also in `api/state` and `window.redeemid.apiVersion`).
|
|
4
4
|
|
|
5
5
|
Everything on this page is stable: it changes only with a changelog entry and an API version bump (minor when something is added, major when something changes or goes). Anything not listed is internal, even when a module exports it. `src/contract.ts` is the same list as code, and a test fails when the code, that list and this page disagree.
|
|
6
6
|
|
|
@@ -17,7 +17,7 @@ Import these in Astro pages, components and endpoints.
|
|
|
17
17
|
| Import | Stable exports |
|
|
18
18
|
| --- | --- |
|
|
19
19
|
| `@redeemid/emdash` | `redeemid`, `redeemidGuard`, `redeemidPlugin` |
|
|
20
|
-
| `@redeemid/emdash/access` | `viewer`, `canRead`, `readEntry`, `entryRequirement`, `meterUsage`, `membership`, `levelsFor`, `signInUrl`, `signOutUrl`, `accountUrl`, `cartUrl`, `refreshUrl`, `safeReturn` |
|
|
20
|
+
| `@redeemid/emdash/access` | `siteConfig`, `viewer`, `canRead`, `readEntry`, `entryRequirement`, `meterUsage`, `membership`, `levelsFor`, `signInUrl`, `signOutUrl`, `accountUrl`, `cartUrl`, `refreshUrl`, `safeReturn` |
|
|
21
21
|
| `@redeemid/emdash/features` | `hasFeature`, `viewerFeatures`, `featuresFor` |
|
|
22
22
|
| `@redeemid/emdash/preferences` | `readPreferences`, `savePreferences`, `preferenceFields` |
|
|
23
23
|
| `@redeemid/emdash/storefront` | `plan`, `product`, `collection`, `money`, `realOptions`, `variantFor`, `storeContext`, `cartDetails`, `addToCart`, `updateLines`, `removeLines`, `setDiscountCodes` |
|
|
@@ -25,16 +25,19 @@ Import these in Astro pages, components and endpoints.
|
|
|
25
25
|
| `@redeemid/emdash/events` | `signBody` |
|
|
26
26
|
| `@redeemid/emdash/text` | `STRINGS`, `text`, `textParts` |
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
Functions that take a `config` want the site's config for the request: `await siteConfig(Astro.locals)`, which is the code's config with the admin's saved settings laid over it. Passing the object from `astro.config.mjs` instead skips what staff saved on the Access page. A few examples:
|
|
29
29
|
|
|
30
30
|
```astro
|
|
31
31
|
---
|
|
32
|
-
import { canRead,
|
|
32
|
+
import { canRead, siteConfig } from "@redeemid/emdash/access";
|
|
33
33
|
import { hasFeature } from "@redeemid/emdash/features";
|
|
34
34
|
import { searchProducts } from "@redeemid/emdash/catalog";
|
|
35
|
+
import { storeContext } from "@redeemid/emdash/storefront";
|
|
35
36
|
|
|
36
37
|
const verdict = await canRead(Astro, { collection: "posts", terms: post.data.terms, id: post.id });
|
|
37
38
|
const adFree = await hasFeature(Astro, "ad-free");
|
|
39
|
+
const config = await siteConfig(Astro.locals);
|
|
40
|
+
const totes = config && (await searchProducts(config, "tote", {}, { context: storeContext(config, Astro.request) }));
|
|
38
41
|
---
|
|
39
42
|
```
|
|
40
43
|
|
|
@@ -47,7 +50,7 @@ Under `/_emdash/api/auth/redeemid/`. Same-origin only: EmDash checks `Origin` on
|
|
|
47
50
|
- `api/state` (GET): the visitor's own state.
|
|
48
51
|
|
|
49
52
|
```json
|
|
50
|
-
{ "apiVersion": "1.
|
|
53
|
+
{ "apiVersion": "1.1.0", "version": "0.0.21", "signedIn": true, "linked": true,
|
|
51
54
|
"levels": ["gold"], "features": ["ad-free"], "cart": { "count": 2 },
|
|
52
55
|
"meter": { "used": 1, "limit": 3, "period": "month" } }
|
|
53
56
|
```
|
|
@@ -57,16 +60,16 @@ Under `/_emdash/api/auth/redeemid/`. Same-origin only: EmDash checks `Origin` on
|
|
|
57
60
|
- `update`: `line`, `quantity` (0 removes); `remove`: `line`; `discount`: `code` (`""` clears);
|
|
58
61
|
- `checkout`: answers `{ checkoutUrl }`, signed in for members.
|
|
59
62
|
|
|
60
|
-
Other actions answer `{ notice, cart, added? }`. An add Shopify can't fill answers 422 with `notice: "plan_unavailable"`. Over the rate limit (with `redeemidGuard({ rateLimit: true })`) POST answers 429
|
|
63
|
+
Other actions answer `{ notice, cart, added? }`. An add Shopify can't fill answers 422 with `notice: "plan_unavailable"`. Over the rate limit (with `redeemidGuard({ rateLimit: true })`) POST answers 429 with `{ "error": "too_many_requests" }`.
|
|
61
64
|
- `api/search` (GET): public catalog data, `Cache-Control: public, max-age=60` (private when `market.country` is `"visitor"`).
|
|
62
65
|
- `?q=tote&suggest=1[&limit=6]`: `{ queries, products, collections }`, for search-as-you-type;
|
|
63
66
|
- `?q=tote`: `{ products, filters, pageInfo, total }`;
|
|
64
67
|
- `?collection=shop`: the collection's page, `{ handle, title, description, products, filters, pageInfo }`.
|
|
65
68
|
|
|
66
|
-
Both take `first` (1 to 50), `sort`, `after` or `before` (cursors from `pageInfo`), `filter` (repeatable: a filter value's `input` exactly as Shopify gave it), `price_min` and `price_max`. Sorts are `relevance`, `best-selling`, `newest`, `price-asc`, `price-desc`, `title-asc`, `title-desc` (search: relevance and price only).
|
|
69
|
+
Both take `first` (1 to 50), `sort`, `after` or `before` (cursors from `pageInfo`), `filter` (repeatable: a filter value's `input` exactly as Shopify gave it), `price_min` and `price_max`. Sorts are `relevance`, `best-selling`, `newest`, `price-asc`, `price-desc`, `title-asc`, `title-desc` (search: relevance and price only). Over the rate limit a search answers 429, as `api/cart` does.
|
|
67
70
|
- `preferences` (GET, POST) and `privacy` (GET export, POST erase): see the README.
|
|
68
71
|
|
|
69
|
-
Form routes, which redirect back with `?redeemid_notice=<code
|
|
72
|
+
Form routes, which redirect back with `?redeemid_notice=<code>` when something needs saying: `login`, `callback`, `logout`, `buy`, `cart`, `cart-edit`, `account`. `webhook` is for Shopify only and answers with a status code.
|
|
70
73
|
|
|
71
74
|
## Browser client
|
|
72
75
|
|
|
@@ -114,13 +117,13 @@ Signed outbound webhooks to config `events.url` (see the README): `member.signed
|
|
|
114
117
|
|
|
115
118
|
## MCP and the command line
|
|
116
119
|
|
|
117
|
-
RedeemID's tools join EmDash's MCP server once staff turn them on for RedeemID under Plugins. They need
|
|
120
|
+
RedeemID's tools join EmDash's MCP server once staff turn them on for RedeemID under Plugins. They need an administrator's API token (the routes ask for `users:read`, which only Admins hold) with the `mcp:tools` or `mcp:tools:redeemid` scope. Always offered, read-only:
|
|
118
121
|
|
|
119
122
|
- `explain_access`, `list_levels`, `get_rules`, `get_member`, `site_health`, `level_changes`
|
|
120
123
|
- `find_products`, `get_product`, `get_collection`: the Shopify catalog the site sells, so an agent writing content can find the right product and collection handles.
|
|
121
124
|
|
|
122
125
|
Only with config `agents: { actions: true }`: `resync_member`, `resync_batch`, `edit_member_tags`.
|
|
123
126
|
|
|
124
|
-
The `redeemid-emdash` command line calls the same routes (`npx redeemid-emdash --help`).
|
|
127
|
+
The `redeemid-emdash` command line calls the same routes (`npx -p @redeemid/emdash redeemid-emdash --help`).
|
|
125
128
|
|
|
126
129
|
For shoppers' own agents (browsing products, building a cart, checking out), point them at Shopify's Storefront MCP server for the store, `https://<store domain>/api/mcp`. It runs on Shopify, where checkout and prices already live, so RedeemID doesn't repeat it.
|
package/docs/shopify-flow.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
RedeemID never grants access itself. A member's levels come from tags on their Shopify customer, and something in Shopify has to put those tags on and take them off. That is usually [Shopify Flow](https://help.shopify.com/manual/shopify-flow), which comes free with every Shopify plan, or a subscription app.
|
|
4
4
|
|
|
5
|
-
When a tag changes, Shopify sends `
|
|
5
|
+
When a tag changes, Shopify sends a `customer.tags_added` or `customer.tags_removed` webhook. With the Admin API app's client ID set, RedeemID reads the customer's tags as they are now; without it, it applies the change the webhook carries. Access follows within seconds, and nobody has to sign in again.
|
|
6
6
|
|
|
7
7
|
Each recipe below is one Flow workflow. In Flow, open **Create workflow**, pick the trigger, add the condition, then add the action. The trigger and action names here are the ones Flow shows in English. The field paths in conditions can read slightly differently in Flow's picker. Subscription triggers come from your subscription app, so their names depend on the app.
|
|
8
8
|
|
|
@@ -28,7 +28,7 @@ A partial refund of something else in the same order matches nothing, so the tag
|
|
|
28
28
|
|
|
29
29
|
## 3. A cancelled subscription removes it
|
|
30
30
|
|
|
31
|
-
Subscription apps that work with Flow add their own triggers, such as "Subscription contract cancelled" or "Subscription contract status updated".
|
|
31
|
+
Subscription apps that work with Flow add their own triggers, such as "Subscription contract cancelled" or "Subscription contract status updated". The names vary by app, so check your app's Flow listing.
|
|
32
32
|
|
|
33
33
|
- **Trigger:** your app's cancel trigger. If the app only offers a status-changed trigger, add the condition status is `CANCELLED`, and treat `EXPIRED` the same way.
|
|
34
34
|
- **Action:** Remove customer tags, with `member`.
|
|
@@ -63,7 +63,7 @@ After a purchase, **Refresh membership** on the member card reads their tags aga
|
|
|
63
63
|
|
|
64
64
|
## Check a recipe
|
|
65
65
|
|
|
66
|
-
1. Under **Plugins → RedeemID → Webhooks**, make sure `
|
|
66
|
+
1. Under **Plugins → RedeemID → Webhooks → Setup**, make sure `customer.tags_added` and `customer.tags_removed` show as Registered. The Setup page registers them for you.
|
|
67
67
|
2. Buy the product with a test customer, using Shopify's Bogus Gateway or a 100% discount code.
|
|
68
68
|
3. In Flow, open the workflow's **Recent runs**. The run should show the tag added.
|
|
69
69
|
4. Open **Plugins → RedeemID → Members**, then the customer. The tag and level should be there.
|
package/docs/shopify-setup.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
What to set up in Shopify, and on the site, to run RedeemID on an EmDash site. One store can serve several sites: each site gets its own Headless storefront for sign-in, and each receives webhooks.
|
|
4
4
|
|
|
5
|
+
Once the package is installed, **Plugins → RedeemID → Setup** in the EmDash admin walks through these same steps with your site's own addresses filled in, checks each one, and registers the webhooks for you.
|
|
6
|
+
|
|
5
7
|
## 1. Sign-in: a Headless storefront
|
|
6
8
|
|
|
7
9
|
1. In Shopify admin, open **Sales channels → Headless** (add the channel if it isn't there) and **Create storefront**. Name it after the site.
|
|
@@ -23,15 +25,17 @@ The store must use the new customer accounts (Settings → Customer accounts). C
|
|
|
23
25
|
|
|
24
26
|
## 2. Webhooks
|
|
25
27
|
|
|
26
|
-
RedeemID keeps tags and status current from webhooks.
|
|
28
|
+
RedeemID keeps tags and status current from webhooks sent by a Shopify app on the store (for example a Dev Dashboard app). Shopify signs every webhook with that app's **client secret**, which is the site's webhook secret.
|
|
29
|
+
|
|
30
|
+
Give the app the `read_customers` and `write_customers` Admin API scopes, plus `read_customer_merge` for `customers/merge`, and set its **client ID** on the site as well. Then the Setup page (or **Webhooks → Setup**) registers these topics at `https://<site>/_emdash/api/auth/redeemid/webhook` with one button:
|
|
27
31
|
|
|
28
|
-
`customers/create`, `customers/update`, `customers/delete`, `customers/disable`, `customers/enable`, `customers/merge`, `customer.tags_added`, `customer.tags_removed
|
|
32
|
+
`customers/create`, `customers/update`, `customers/delete`, `customers/disable`, `customers/enable`, `customers/merge`, `customer.tags_added`, `customer.tags_removed`
|
|
29
33
|
|
|
30
|
-
|
|
34
|
+
Without the client ID, subscribe them to that URL yourself. If the app already sends webhooks to another site, add this URL as extra subscriptions.
|
|
31
35
|
|
|
32
|
-
|
|
36
|
+
The client ID and those scopes also run the staff tools (member resync and tag edits written to Shopify), member preferences, and the reads that keep tags in order (see the README). RedeemID uses the client credentials grant, which works when the app and the store are in the same Shopify organization. For the **Also request erasure in Shopify** button on a member's page, add the optional `write_customer_data_erasure` scope.
|
|
33
37
|
|
|
34
|
-
Shopify's compliance topics (`customers/data_request`, `customers/redact`, `shop/redact`) reach only apps that declare them in the app's configuration, under `[webhooks.privacy_compliance]`. Point all three at the same webhook URL. RedeemID logs each one on the Privacy page.
|
|
38
|
+
Shopify's compliance topics (`customers/data_request`, `customers/redact`, `shop/redact`) can't be registered by the button: they reach only apps that declare them in the app's configuration, under `[webhooks.privacy_compliance]`. Point all three at the same webhook URL. RedeemID logs each one on the Privacy page and acts on it (see the README's privacy requests).
|
|
35
39
|
|
|
36
40
|
## 3. The site
|
|
37
41
|
|
|
@@ -46,12 +50,14 @@ npx wrangler secret put REDEEMID_SHOPIFY_CUSTOMER_ACCOUNT_CLIENT_SECRET # confid
|
|
|
46
50
|
npx wrangler secret put REDEEMID_SHOPIFY_ADMIN_APP_CLIENT_SECRET # the webhook app's client secret
|
|
47
51
|
npx wrangler secret put REDEEMID_SHOPIFY_ADMIN_APP_CLIENT_ID # optional; the webhook app's client ID, for the staff tools
|
|
48
52
|
npx wrangler secret put REDEEMID_EVENTS_SECRET # optional; signs outbound events (events.url)
|
|
49
|
-
npx wrangler secret put REDEEMID_SHOPIFY_STOREFRONT_PRIVATE_TOKEN #
|
|
53
|
+
npx wrangler secret put REDEEMID_SHOPIFY_STOREFRONT_PRIVATE_TOKEN # optional; the Storefront API private token, to sell on the site (plans, shop, checkout)
|
|
50
54
|
npx wrangler secret put REDEEMID_SHOPIFY_STOREFRONT_PUBLIC_TOKEN # optional; used only without the private token
|
|
51
55
|
```
|
|
52
56
|
|
|
53
57
|
The Workers free plan is enough: RedeemID is a native plugin and doesn't need sandboxing. Worker secrets reach the code through `nodejs_compat`, which EmDash's Cloudflare templates turn on.
|
|
54
58
|
|
|
59
|
+
On Workers, also add a Cron Trigger to the site's Worker, as EmDash's deployment guide describes, so EmDash's scheduler runs RedeemID's daily webhook health check.
|
|
60
|
+
|
|
55
61
|
## 4. Try it
|
|
56
62
|
|
|
57
63
|
1. Finish EmDash setup as staff first. Store customers can't create the first account.
|
|
@@ -59,4 +65,4 @@ The Workers free plan is enough: RedeemID is a native plugin and doesn't need sa
|
|
|
59
65
|
3. Click **Sign in**, sign in with that customer's email, and you come back to the post, unlocked.
|
|
60
66
|
4. Add or remove the tag in Shopify; the post opens or locks again once the webhook arrives.
|
|
61
67
|
|
|
62
|
-
If sign-in sends you back with `?redeemid_notice=…`, the code says why: `not_configured`
|
|
68
|
+
If sign-in sends you back with `?redeemid_notice=…`, the code says why: `not_configured` means the client ID or `shop` is missing, and `sign_in_unavailable` means store discovery failed, usually a wrong `shop`. The README lists [every notice](../README.md#notices).
|
package/package.json
CHANGED
package/src/access.ts
CHANGED
|
@@ -15,6 +15,9 @@ import { UNAVAILABLE, type EntryRule } from "./settings.js";
|
|
|
15
15
|
import { siteConfig } from "./site-config.js";
|
|
16
16
|
import { memberForUser, stores, type MemberRecord, type MeterRecord } from "./storage.js";
|
|
17
17
|
|
|
18
|
+
/** The site's config for a request: the code's config with the admin's saved settings laid over it. */
|
|
19
|
+
export { siteConfig };
|
|
20
|
+
|
|
18
21
|
/** The parts of Astro's global that access checks read. */
|
|
19
22
|
export interface AstroLike {
|
|
20
23
|
locals: unknown;
|
package/src/api-version.ts
CHANGED
package/src/contract.ts
CHANGED
|
@@ -16,7 +16,7 @@ export { API_VERSION } from "./api-version.js";
|
|
|
16
16
|
/** Stable exports, by import path. */
|
|
17
17
|
export const MODULES = {
|
|
18
18
|
"@redeemid/emdash": ["redeemid", "redeemidGuard", "redeemidPlugin"],
|
|
19
|
-
"@redeemid/emdash/access": ["viewer", "canRead", "readEntry", "entryRequirement", "meterUsage", "membership", "levelsFor", "signInUrl", "signOutUrl", "accountUrl", "cartUrl", "refreshUrl", "safeReturn"],
|
|
19
|
+
"@redeemid/emdash/access": ["siteConfig", "viewer", "canRead", "readEntry", "entryRequirement", "meterUsage", "membership", "levelsFor", "signInUrl", "signOutUrl", "accountUrl", "cartUrl", "refreshUrl", "safeReturn"],
|
|
20
20
|
"@redeemid/emdash/features": ["hasFeature", "viewerFeatures", "featuresFor"],
|
|
21
21
|
"@redeemid/emdash/preferences": ["readPreferences", "savePreferences", "preferenceFields"],
|
|
22
22
|
"@redeemid/emdash/storefront": ["plan", "product", "collection", "money", "realOptions", "variantFor", "storeContext", "cartDetails", "addToCart", "updateLines", "removeLines", "setDiscountCodes"],
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.0.
|
|
1
|
+
export const VERSION = "0.0.21";
|