@blamejs/blamejs-shop 0.1.5 → 0.1.6
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/CHANGELOG.md +2 -0
- package/README.md +1 -0
- package/lib/checkout.js +7 -0
- package/lib/order.js +24 -3
- package/lib/storefront.js +9 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,8 @@ upgrading across more than a few patches at a time.
|
|
|
8
8
|
|
|
9
9
|
## v0.1.x
|
|
10
10
|
|
|
11
|
+
- v0.1.6 (2026-05-25) — **Claim past guest orders when a shopper signs in.** A shopper who checked out as a guest and later signs in with a provider-verified email now finds those past orders attached to their account. Checkout records a hash of the buyer's email on the order; on Google sign-in, orders placed under that same email — and not yet owned by anyone — are claimed into the account. Linking happens only on an email the identity provider verified, never on an unverified one, so it can't be used to steal another shopper's order history. **Added:** *Guest-order reconciliation on sign-in* — Orders now carry a `customer_email_hash` (migration 0206), written at checkout from the buyer's email with the same key the customers table uses. On a verified Google sign-in, `order.linkGuestOrdersByEmailHash` claims every ownerless order under that email into the account — so prior guest purchases appear in /account and satisfy customer-scoped checks (e.g. verified-buyer reviews). Only ownerless orders are touched (an order already attached to a customer is never reassigned), and only a provider-verified email triggers a link.
|
|
12
|
+
|
|
11
13
|
- v0.1.5 (2026-05-25) — **Tell operators how to turn each integration on.** Every third-party integration (Stripe card checkout, Apple/Google Pay, Sign in with Google) is off by default and only activates when you supply its credentials. This release documents exactly what to set for each — in the README, in a new .env.example, and in the admin console itself. A signed-in operator opens /admin/integrations to see, at a glance, which integrations are live and the precise environment variables (or one-time action) needed to enable the rest. Nothing is enabled without your keys. **Added:** *Admin integrations status page* — `/admin/integrations` lists each integration with a live Enabled / Not configured status and the exact variables or action to turn it on — Stripe keys, the payment-method-domain registration for wallets, the Google OAuth client + redirect URI. Read-only; secrets are never rendered. Linked from the admin landing. · *Operator setup docs* — A README "Optional integrations" section and a top-level `.env.example` enumerate every environment variable, what capability it unlocks, and the external setup (e.g. the Google OAuth redirect URI, the Stripe webhook path). Both note that Apple sign-in + PayPal are planned and that Shop Pay / "Sign in with Shop" isn't available to a self-hosted store.
|
|
12
14
|
|
|
13
15
|
- v0.1.4 (2026-05-25) — **Sign in with Google.** Customers can sign in with Google alongside passkeys. The account login page gains a Continue with Google button; the OIDC authorization-code flow (PKCE, state, nonce, ID-token verification) runs through the framework's OAuth adapter, and the verified identity becomes a shop session. Accounts are keyed on the provider's stable subject, and an existing account is only ever linked on an email the provider has verified — an unverified email that collides with an existing account is refused rather than linked. A cart built before signing in is adopted into the account, so checkout attaches the order to the customer. **Added:** *Google sign-in* — Mounts `/account/login/google` + `/account/auth/google/callback` when the operator sets `GOOGLE_OAUTH_CLIENT_ID`, `GOOGLE_OAUTH_CLIENT_SECRET`, and `SHOP_ORIGIN`. The in-flight state (CSRF state + nonce + PKCE verifier) rides a sealed, /account-scoped, SameSite=Lax cookie; the callback verifies the state before exchanging the code. A forged or stale callback is dropped to the login page. On success the guest session cart is adopted into the account (`cart.setCustomer`), matching the passkey path. · *Federated identity model + safe account linking* — `customers.signInWithOIDC` resolves a verified sign-in to a customer: an existing `(provider, subject)` link, else — only on a provider-verified email — an existing account with that email, else a new account. It never links to an existing account on an unverified email (account-takeover defense). New `customer_oauth_identities` table (migration 0205) + `customers.byOAuthIdentity`.
|
package/README.md
CHANGED
|
@@ -93,6 +93,7 @@ Every primitive is composed on the vendored blamejs surface — no npm runtime d
|
|
|
93
93
|
- `migrations-d1/0026_customer_addresses.sql` — per-customer address book (default shipping/billing flags)
|
|
94
94
|
- `migrations-d1/0023_returns.sql` — return authorizations + lines (RMA lifecycle FSM)
|
|
95
95
|
- `migrations-d1/0205_customer_oauth_identities.sql` — federated sign-in identities (provider + subject, verified-email gating)
|
|
96
|
+
- `migrations-d1/0206_orders_email_hash.sql` — queryable buyer-email hash on orders (guest-order reconciliation key)
|
|
96
97
|
- `migrations-d1/0043_collections.sql` — manual + smart product collections (members + rules + sort strategy)
|
|
97
98
|
- `migrations-d1/0050_recently_viewed.sql` — per-customer / per-session product browse history (dedup + per-subject cap)
|
|
98
99
|
|
package/lib/checkout.js
CHANGED
|
@@ -96,6 +96,10 @@ function create(deps) {
|
|
|
96
96
|
var payment = deps.payment;
|
|
97
97
|
var order = deps.order;
|
|
98
98
|
var subscriptions = deps.subscriptions || null;
|
|
99
|
+
// Optional — when wired, the buyer email is hashed (via the same
|
|
100
|
+
// customers.hashEmail keying the customers table) and stored on the
|
|
101
|
+
// order so a later verified-email sign-in can claim the guest order.
|
|
102
|
+
var customers = deps.customers || null;
|
|
99
103
|
|
|
100
104
|
// Compose a quote from a cart + ship-to + (optional) selected
|
|
101
105
|
// shipping service. Pure read — no DB writes.
|
|
@@ -219,6 +223,9 @@ function create(deps) {
|
|
|
219
223
|
grand_total_minor: quote.totals.grand_total_minor,
|
|
220
224
|
payment_intent_id: pi.id,
|
|
221
225
|
ship_to: input.ship_to,
|
|
226
|
+
// Hash of the buyer email (same key as the customers table) so a
|
|
227
|
+
// later verified-email sign-in can claim this guest order.
|
|
228
|
+
customer_email_hash: customers ? customers.hashEmail(email) : null,
|
|
222
229
|
lines: quote.lines.map(function (l) {
|
|
223
230
|
return {
|
|
224
231
|
variant_id: l.variant_id,
|
package/lib/order.js
CHANGED
|
@@ -174,13 +174,14 @@ function create(opts) {
|
|
|
174
174
|
await query(
|
|
175
175
|
"INSERT INTO orders (id, cart_id, customer_id, session_id, status, currency, " +
|
|
176
176
|
"subtotal_minor, discount_minor, tax_minor, shipping_minor, grand_total_minor, " +
|
|
177
|
-
"payment_intent_id, ship_to_json, created_at, updated_at) " +
|
|
178
|
-
"VALUES (?1, ?2, ?3, ?4, 'pending', ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?
|
|
177
|
+
"payment_intent_id, ship_to_json, customer_email_hash, created_at, updated_at) " +
|
|
178
|
+
"VALUES (?1, ?2, ?3, ?4, 'pending', ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?14)",
|
|
179
179
|
[
|
|
180
180
|
id, input.cart_id, input.customer_id || null, input.session_id,
|
|
181
181
|
input.currency, input.subtotal_minor, input.discount_minor,
|
|
182
182
|
input.tax_minor, input.shipping_minor, input.grand_total_minor,
|
|
183
|
-
input.payment_intent_id || null, JSON.stringify(input.ship_to),
|
|
183
|
+
input.payment_intent_id || null, JSON.stringify(input.ship_to),
|
|
184
|
+
input.customer_email_hash || null, ts,
|
|
184
185
|
],
|
|
185
186
|
);
|
|
186
187
|
for (var i = 0; i < input.lines.length; i += 1) {
|
|
@@ -369,6 +370,26 @@ function create(opts) {
|
|
|
369
370
|
return await this.get(orderId);
|
|
370
371
|
},
|
|
371
372
|
|
|
373
|
+
// Claim guest orders into a customer account by matching the
|
|
374
|
+
// recorded buyer-email hash. The CALLER must only pass a hash for an
|
|
375
|
+
// email the identity provider VERIFIED — this method does not (and
|
|
376
|
+
// cannot) re-verify; linking an unverified email would be account
|
|
377
|
+
// takeover. Only touches orders with no owner yet (customer_id IS
|
|
378
|
+
// NULL), so it never re-assigns another customer's order. Returns
|
|
379
|
+
// the count linked.
|
|
380
|
+
linkGuestOrdersByEmailHash: async function (customerId, emailHash) {
|
|
381
|
+
_uuid(customerId, "customer id");
|
|
382
|
+
if (typeof emailHash !== "string" || !emailHash.length) {
|
|
383
|
+
throw new TypeError("order.linkGuestOrdersByEmailHash: emailHash must be a non-empty string");
|
|
384
|
+
}
|
|
385
|
+
var r = await query(
|
|
386
|
+
"UPDATE orders SET customer_id = ?1, updated_at = ?2 " +
|
|
387
|
+
"WHERE customer_id IS NULL AND customer_email_hash = ?3",
|
|
388
|
+
[customerId, _now(), emailHash],
|
|
389
|
+
);
|
|
390
|
+
return Number(r.rowCount || 0);
|
|
391
|
+
},
|
|
392
|
+
|
|
372
393
|
// Has this customer purchased this product? True iff an order
|
|
373
394
|
// line for any variant of the product sits in an order owned by
|
|
374
395
|
// the customer whose status is a real purchase — anything except
|
package/lib/storefront.js
CHANGED
|
@@ -3294,6 +3294,15 @@ function mount(router, deps) {
|
|
|
3294
3294
|
if (anonCart) await deps.cart.setCustomer(anonCart.id, rv.customer.id);
|
|
3295
3295
|
} catch (_e) { /* best-effort merge; sign-in itself succeeds */ }
|
|
3296
3296
|
}
|
|
3297
|
+
// Claim prior guest orders placed under this email — ONLY because
|
|
3298
|
+
// the provider verified it (claims.email_verified). Links orders
|
|
3299
|
+
// with no owner yet whose recorded email hash matches; best-effort.
|
|
3300
|
+
if (claims.email_verified === true && claims.email && deps.order &&
|
|
3301
|
+
typeof deps.order.linkGuestOrdersByEmailHash === "function") {
|
|
3302
|
+
try {
|
|
3303
|
+
await deps.order.linkGuestOrdersByEmailHash(rv.customer.id, deps.customers.hashEmail(claims.email));
|
|
3304
|
+
} catch (_e) { /* best-effort reconciliation; sign-in succeeds regardless */ }
|
|
3305
|
+
}
|
|
3297
3306
|
_setAuthCookie(res, { customer_id: rv.customer.id, exp: Date.now() + _b().constants.TIME.days(14) });
|
|
3298
3307
|
res.status(303); res.setHeader && res.setHeader("location", "/account");
|
|
3299
3308
|
return res.end ? res.end() : res.send("");
|
package/package.json
CHANGED