@shop-on/theme-server 0.9.0 → 0.11.0
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/dist/account-state.js +1 -2
- package/dist/account.d.ts +1 -3
- package/dist/account.js +1 -3
- package/dist/activity.d.ts +1 -3
- package/dist/activity.js +1 -2
- package/dist/analytics-proxy.d.ts +8 -14
- package/dist/analytics-proxy.js +111 -28
- package/dist/analytics-script-proxy.d.ts +1 -5
- package/dist/analytics-script-proxy.js +4 -14
- package/dist/api-contract/src/addresses.js +32 -0
- package/dist/api-contract/src/areas.js +49 -0
- package/dist/api-contract/src/custom-data.d.ts +31 -0
- package/dist/api-contract/src/custom-data.js +303 -0
- package/dist/api-contract/src/ids.js +110 -0
- package/dist/api-contract/src/image.js +65 -0
- package/dist/api-contract/src/limits.js +44 -0
- package/dist/api-contract/src/media.js +13 -0
- package/dist/api-contract/src/pickup.js +11 -0
- package/dist/api-contract/src/recommendations.js +4 -0
- package/dist/api-contract/src/shops.js +27 -0
- package/dist/api-contract/src/storefront/analytics.d.ts +100 -0
- package/dist/api-contract/src/storefront/analytics.js +138 -0
- package/dist/api-contract/src/storefront/areas.d.ts +2 -0
- package/dist/api-contract/src/storefront/cart.d.ts +132 -0
- package/dist/api-contract/src/storefront/cart.js +248 -0
- package/dist/api-contract/src/storefront/catalog.d.ts +3 -0
- package/dist/api-contract/src/storefront/checkout-analytics.d.ts +2 -0
- package/dist/api-contract/src/storefront/checkout.d.ts +2 -0
- package/dist/api-contract/src/storefront/checkout.js +624 -0
- package/dist/api-contract/src/storefront/client.d.ts +3 -0
- package/dist/api-contract/src/storefront/client.js +6 -0
- package/dist/api-contract/src/storefront/content.d.ts +3 -0
- package/dist/api-contract/src/storefront/custom-data.d.ts +2 -0
- package/dist/api-contract/src/storefront/custom-data.js +27 -0
- package/dist/api-contract/src/storefront/customer.d.ts +2 -0
- package/dist/api-contract/src/storefront/customer.js +261 -0
- package/dist/api-contract/src/storefront/downloads.d.ts +2 -0
- package/dist/api-contract/src/storefront/draft-order-invoice.d.ts +2 -0
- package/dist/api-contract/src/storefront/forms.d.ts +2 -0
- package/dist/api-contract/src/storefront/forms.js +82 -0
- package/dist/api-contract/src/storefront/index.d.ts +20956 -0
- package/dist/api-contract/src/storefront/orders.d.ts +2 -0
- package/dist/api-contract/src/storefront/policies.d.ts +2 -0
- package/dist/api-contract/src/storefront/procedure.d.ts +2 -0
- package/dist/api-contract/src/storefront/procedure.js +29 -0
- package/dist/api-contract/src/storefront/reviews.d.ts +20 -0
- package/dist/api-contract/src/storefront/search.d.ts +3 -0
- package/dist/api-contract/src/storefront/seo.d.ts +2 -0
- package/dist/api-contract/src/storefront/seo.js +132 -0
- package/dist/api-contract/src/storefront/shop.d.ts +2 -0
- package/dist/api-contract/src/storefront/shop.js +101 -0
- package/dist/api-contract/src/taxonomy.js +5 -0
- package/dist/api-contract/src/text.js +15 -0
- package/dist/api-contract/src/theme-documents.js +13 -0
- package/dist/api-contract/src/theme-translations.d.ts +14 -0
- package/dist/api-contract/src/theme-translations.js +30 -0
- package/dist/api-contract/src/video.js +19 -0
- package/dist/availability.d.ts +6 -3
- package/dist/availability.js +11 -5
- package/dist/blog.d.ts +53 -59
- package/dist/blog.js +197 -497
- package/dist/cache.d.ts +5 -6
- package/dist/cache.js +1 -2
- package/dist/canonical-host.d.ts +4 -6
- package/dist/canonical-host.js +5 -6
- package/dist/card.js +159 -0
- package/dist/cart-customer.d.ts +1 -3
- package/dist/cart-customer.js +64 -105
- package/dist/cart-mutations.d.ts +43 -77
- package/dist/cart-mutations.js +106 -232
- package/dist/cart-recommendations.d.ts +1 -3
- package/dist/cart-recommendations.js +1 -2
- package/dist/cart-session.d.ts +1 -3
- package/dist/cart-session.js +1 -2
- package/dist/cart.d.ts +63 -224
- package/dist/cart.js +70 -197
- package/dist/checkout.d.ts +13 -17
- package/dist/checkout.js +75 -101
- package/dist/coalesce.js +57 -0
- package/dist/collection.d.ts +89 -298
- package/dist/collection.js +210 -656
- package/dist/contact.d.ts +20 -10
- package/dist/contact.js +36 -30
- package/dist/content-version.d.ts +37 -21
- package/dist/content-version.js +64 -42
- package/dist/contract-kit/src/client.d.ts +12 -0
- package/dist/contract-kit/src/client.js +156 -0
- package/dist/contract-kit/src/errors.d.ts +1 -0
- package/dist/contract-kit/src/errors.js +81 -0
- package/dist/contract-kit/src/ids.d.ts +1 -0
- package/dist/contract-kit/src/ids.js +118 -0
- package/dist/contract-kit/src/index.d.ts +7 -0
- package/dist/contract-kit/src/money.d.ts +1 -0
- package/dist/contract-kit/src/money.js +10 -0
- package/dist/contract-kit/src/pagination.d.ts +1 -0
- package/dist/contract-kit/src/procedure.d.ts +69 -0
- package/dist/contract-kit/src/procedure.js +16 -0
- package/dist/contract-kit/src/realtime.d.ts +1 -0
- package/dist/cookie-secret.js +1 -2
- package/dist/csrf.js +1 -2
- package/dist/customer-handoff.d.ts +1 -3
- package/dist/customer-handoff.js +10 -25
- package/dist/customer-session.d.ts +1 -3
- package/dist/customer-session.js +1 -2
- package/dist/customer.d.ts +2 -3
- package/dist/customer.js +27 -44
- package/dist/files.d.ts +49 -10
- package/dist/files.js +106 -89
- package/dist/fonts.d.ts +3 -5
- package/dist/fonts.js +16 -35
- package/dist/html.d.ts +1 -3
- package/dist/html.js +1 -2
- package/dist/liquid.d.ts +4 -10
- package/dist/liquid.js +25 -32
- package/dist/listing.js +79 -0
- package/dist/marketing-cookies.d.ts +1 -3
- package/dist/marketing-cookies.js +1 -2
- package/dist/menu.d.ts +46 -155
- package/dist/menu.js +51 -61
- package/dist/metafields.d.ts +9 -5
- package/dist/metafields.js +10 -38
- package/dist/metaobject.d.ts +10 -5
- package/dist/metaobject.js +43 -66
- package/dist/money.d.ts +7 -0
- package/dist/money.js +18 -0
- package/dist/newsletter.d.ts +19 -10
- package/dist/newsletter.js +31 -25
- package/dist/page.d.ts +13 -17
- package/dist/page.js +49 -105
- package/dist/password-session.d.ts +1 -3
- package/dist/password-session.js +1 -2
- package/dist/password.d.ts +25 -18
- package/dist/password.js +41 -59
- package/dist/policy.d.ts +7 -7
- package/dist/policy.js +19 -55
- package/dist/product.d.ts +42 -67
- package/dist/product.js +144 -644
- package/dist/read-ahead.d.ts +18 -0
- package/dist/read-ahead.js +32 -0
- package/dist/recommendations.d.ts +6 -12
- package/dist/recommendations.js +36 -60
- package/dist/review.d.ts +134 -94
- package/dist/review.js +257 -469
- package/dist/search.d.ts +59 -64
- package/dist/search.js +170 -469
- package/dist/seo-context.d.ts +1 -3
- package/dist/seo-context.js +4 -5
- package/dist/seo-documents.d.ts +50 -0
- package/dist/seo-documents.js +149 -0
- package/dist/shop-seo.d.ts +3 -5
- package/dist/shop-seo.js +7 -26
- package/dist/shop.d.ts +38 -42
- package/dist/shop.js +37 -51
- package/dist/store-availability.d.ts +12 -14
- package/dist/store-availability.js +18 -56
- package/dist/storefront.js +199 -0
- package/dist/structured-data.d.ts +3 -28
- package/dist/structured-data.js +19 -49
- package/dist/trace.js +1 -2
- package/dist/translations.d.ts +26 -31
- package/dist/translations.js +55 -28
- package/package.json +16 -14
- package/dist/graphql-env.d.ts +0 -22778
- package/dist/graphql.d.ts +0 -64
- package/dist/graphql.js +0 -344
- package/dist/schema.storefront.graphql +0 -10483
- package/dist/seo-proxy.d.ts +0 -11
- package/dist/seo-proxy.js +0 -26
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// ../contract-kit/src/ids.ts
|
|
3
|
+
const ALPHABET = "0123456789abcdefghjkmnpqrstvwxyz";
|
|
4
|
+
const SUFFIX_PATTERN = /^[0-7][0-9a-hjkmnp-tv-z]{25}$/;
|
|
5
|
+
const PREFIX_PATTERN = /^(?:[a-z](?:[a-z_]{0,61}[a-z])?)?$/;
|
|
6
|
+
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
7
|
+
const UUID_V7_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
8
|
+
const suffixSchema = z.string().regex(SUFFIX_PATTERN);
|
|
9
|
+
/** Encodes a UUID as a TypeID. Any spec-valid prefix; `""` gives a bare suffix. */
|
|
10
|
+
function encodeTypeId(prefix, uuid) {
|
|
11
|
+
if (!PREFIX_PATTERN.test(prefix)) throw new TypeError(`Invalid TypeID prefix: ${prefix}`);
|
|
12
|
+
if (!UUID_PATTERN.test(uuid)) throw new TypeError(`Invalid UUID: ${uuid}`);
|
|
13
|
+
let bits = BigInt(`0x${uuid.replaceAll("-", "")}`);
|
|
14
|
+
const suffix = Array.from({ length: 26 });
|
|
15
|
+
for (let i = 25; i >= 0; i--) {
|
|
16
|
+
suffix[i] = ALPHABET[Number(bits & 31n)];
|
|
17
|
+
bits >>= 5n;
|
|
18
|
+
}
|
|
19
|
+
return prefix === "" ? suffix.join("") : `${prefix}_${suffix.join("")}`;
|
|
20
|
+
}
|
|
21
|
+
/** Decodes a TypeID into its prefix and lowercase UUID; throws on anything the spec rejects. */
|
|
22
|
+
function decodeTypeId(typeId) {
|
|
23
|
+
const split = typeId.lastIndexOf("_");
|
|
24
|
+
const prefix = split === -1 ? "" : typeId.slice(0, split);
|
|
25
|
+
const suffix = typeId.slice(split + 1);
|
|
26
|
+
if (split === 0 || !PREFIX_PATTERN.test(prefix) || !SUFFIX_PATTERN.test(suffix)) throw new TypeError(`Invalid TypeID: ${typeId}`);
|
|
27
|
+
let bits = 0n;
|
|
28
|
+
for (const char of suffix) bits = bits << 5n | BigInt(ALPHABET.indexOf(char));
|
|
29
|
+
return {
|
|
30
|
+
prefix,
|
|
31
|
+
uuid: formatUuid(bits.toString(16).padStart(32, "0"))
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const RANDOM_LIMIT = 1n << 74n;
|
|
35
|
+
const LOW_BITS = 62n;
|
|
36
|
+
let lastMs = -1;
|
|
37
|
+
let lastRandom = 0n;
|
|
38
|
+
function randomBits(bytes) {
|
|
39
|
+
const buffer = new Uint8Array(bytes);
|
|
40
|
+
crypto.getRandomValues(buffer);
|
|
41
|
+
let value = 0n;
|
|
42
|
+
for (const byte of buffer) value = value << 8n | BigInt(byte);
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A UUIDv7 (RFC 9562) from the clock and `crypto.getRandomValues`, minted on
|
|
47
|
+
* the caller's side: the register and driver apps mint the ids of what they
|
|
48
|
+
* create offline, so a retried write is the same write.
|
|
49
|
+
*
|
|
50
|
+
* Each is greater than the one this process minted before it (RFC 9562 6.2,
|
|
51
|
+
* method 2): in a millisecond already used, or with the clock set back, the
|
|
52
|
+
* random part is the last one plus a random step, and the millisecond moves
|
|
53
|
+
* on when that runs out. So rows made in a loop read back by id in the order
|
|
54
|
+
* they were made. Across processes ids order by millisecond only.
|
|
55
|
+
*/
|
|
56
|
+
function newUuid() {
|
|
57
|
+
const now = Date.now();
|
|
58
|
+
let ms = lastMs;
|
|
59
|
+
let random;
|
|
60
|
+
if (now > lastMs) {
|
|
61
|
+
ms = now;
|
|
62
|
+
random = randomBits(10) & RANDOM_LIMIT - 1n;
|
|
63
|
+
} else {
|
|
64
|
+
random = lastRandom + 1n + randomBits(4);
|
|
65
|
+
if (random >= RANDOM_LIMIT) {
|
|
66
|
+
ms += 1;
|
|
67
|
+
random = randomBits(10) & RANDOM_LIMIT - 1n;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
lastMs = ms;
|
|
71
|
+
lastRandom = random;
|
|
72
|
+
return formatUuid((BigInt(ms) << 80n | 7n << 76n | random >> LOW_BITS << 64n | 2n << LOW_BITS | random & (1n << LOW_BITS) - 1n).toString(16).padStart(32, "0"));
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A contract package's kinds of row, each a spec-valid TypeID prefix
|
|
76
|
+
* (lowercase a–z, at most 63 characters) mapped to what it names, and the
|
|
77
|
+
* typed helpers for them. Prefixes are never reused: a module adds its
|
|
78
|
+
* tables' prefixes to its package's set.
|
|
79
|
+
*/
|
|
80
|
+
function defineIds(prefixes) {
|
|
81
|
+
for (const prefix of Object.keys(prefixes)) if (prefix === "" || !PREFIX_PATTERN.test(prefix)) throw new TypeError(`Invalid TypeID prefix: ${prefix}`);
|
|
82
|
+
/** The wire id of a database row. */
|
|
83
|
+
function toId(prefix, uuid) {
|
|
84
|
+
return encodeTypeId(prefix, uuid.toLowerCase());
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
prefixes,
|
|
88
|
+
/** Schema for a wire id of one kind: `idSchema("prod")` accepts `prod_…` UUIDv7s only. */
|
|
89
|
+
idSchema(prefix) {
|
|
90
|
+
return z.templateLiteral([
|
|
91
|
+
prefix,
|
|
92
|
+
"_",
|
|
93
|
+
suffixSchema
|
|
94
|
+
]).refine((id) => UUID_V7_PATTERN.test(decodeTypeId(id).uuid), "Not a UUIDv7").brand();
|
|
95
|
+
},
|
|
96
|
+
toId,
|
|
97
|
+
/** The database UUID behind a wire id; throws when the id is of another kind or not a UUIDv7. */
|
|
98
|
+
toUuid(prefix, id) {
|
|
99
|
+
const decoded = decodeTypeId(id);
|
|
100
|
+
if (decoded.prefix !== prefix) throw new TypeError(`Expected a ${prefix}_ id, got ${id}`);
|
|
101
|
+
if (!UUID_V7_PATTERN.test(decoded.uuid)) throw new TypeError(`Not a UUIDv7: ${id}`);
|
|
102
|
+
return decoded.uuid;
|
|
103
|
+
},
|
|
104
|
+
/** Mints a new id on the caller's side (`newUuid`). */
|
|
105
|
+
newId(prefix) {
|
|
106
|
+
return toId(prefix, newUuid());
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
const ID_PREFIXES = {
|
|
111
|
+
prod: "product",
|
|
112
|
+
shop: "shop"
|
|
113
|
+
};
|
|
114
|
+
const { idSchema, toId, toUuid, newId } = defineIds(ID_PREFIXES);
|
|
115
|
+
function formatUuid(hex) {
|
|
116
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
117
|
+
}
|
|
118
|
+
export { ID_PREFIXES, decodeTypeId, defineIds, encodeTypeId, newUuid };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import "./errors.js";
|
|
2
|
+
import "./ids.js";
|
|
3
|
+
import "./money.js";
|
|
4
|
+
import "./pagination.js";
|
|
5
|
+
import { McpExposure, ProcedureAccess, ProcedureMeta, RATE_LIMIT_CLASSES, RateLimitClass, RateLimitDeclaration } from "./procedure.js";
|
|
6
|
+
import "./realtime.js";
|
|
7
|
+
export { McpExposure, ProcedureAccess, ProcedureMeta, RATE_LIMIT_CLASSES, RateLimitClass, RateLimitDeclaration };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "zod";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// ../contract-kit/src/money.ts
|
|
3
|
+
/** An amount in möngö. `z.int()` is bounded to the safe integers. */
|
|
4
|
+
const mnt = z.int();
|
|
5
|
+
const mntNonNegative = z.int().nonnegative();
|
|
6
|
+
/** Rates are integers where 100 000 is 100% (10 000 is 10%), like the database `kernel.rate`. */
|
|
7
|
+
const RATE_SCALE = 1e5;
|
|
8
|
+
const rate = z.int().min(0).max(RATE_SCALE);
|
|
9
|
+
BigInt(Number.MAX_SAFE_INTEGER);
|
|
10
|
+
export { RATE_SCALE, mnt, mntNonNegative, rate };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "zod";
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import "zod";
|
|
2
|
+
import "@orpc/contract";
|
|
3
|
+
/** MCP tool annotations (the spec's `readOnlyHint`, `destructiveHint`, `idempotentHint`). */
|
|
4
|
+
export interface McpExposure {
|
|
5
|
+
readOnly: boolean;
|
|
6
|
+
destructive: boolean;
|
|
7
|
+
idempotent: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* The installable app the tool reaches into, by the server's name for it:
|
|
10
|
+
* the tool is offered, and called, only while the caller's tenant has it
|
|
11
|
+
* installed (server-kit `mountMcp`'s `installed`), as its pages show only
|
|
12
|
+
* then. A call of it meanwhile is an unknown tool.
|
|
13
|
+
*/
|
|
14
|
+
app?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Who may call it: a permission key the caller's actor must hold, or
|
|
18
|
+
* `public: true` for anyone. Nothing declared fails closed when the router
|
|
19
|
+
* is built, and so does a key outside the audience's rules (server-kit
|
|
20
|
+
* `./access`). `TPermission` is the audience's catalogue of keys.
|
|
21
|
+
* `alsoRequires` names further keys the caller must hold as well: a write
|
|
22
|
+
* that changes two kinds of data needs the right to change each.
|
|
23
|
+
*/
|
|
24
|
+
export type ProcedureAccess<TPermission extends string = string> = {
|
|
25
|
+
permission: TPermission;
|
|
26
|
+
alsoRequires?: readonly TPermission[];
|
|
27
|
+
public?: never;
|
|
28
|
+
} | {
|
|
29
|
+
public: true;
|
|
30
|
+
permission?: never;
|
|
31
|
+
alsoRequires?: never;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* The rate-limit classes a call can be counted under. What each one keys on,
|
|
35
|
+
* its numbers and what it does when the store is down are the server's
|
|
36
|
+
* (server-kit `./http`, `RATE_LIMITS`); a procedure only names its class.
|
|
37
|
+
* `mount` is the edge's own, never a procedure's: every request to a mount
|
|
38
|
+
* counts against it before anything else runs. `mcp-write` is the MCP
|
|
39
|
+
* mount's own too: each call of a writing tool, per connection.
|
|
40
|
+
*/
|
|
41
|
+
export declare const RATE_LIMIT_CLASSES: readonly ["sign-in", "code-send", "code-redeem", "link-write", "provider-callback", "courier-webhook", "provider-push", "promo-guess", "gift-card-guess", "register-gift-card-guess", "gift-card-reveal", "theme-submission", "public-read", "read", "write", "storefront", "storefront-unlock", "driver-sign-in", "storefront-review", "storefront-contact", "storefront-newsletter", "storefront-sitemap", "storefront-analytics", "storefront-cart", "buyer-write", "buyer-email-change", "google-nonce", "expensive", "checkpoint", "editor-presence", "webhook-create", "webhook-update", "webhook-delete", "webhook-test", "webhook-redeliver", "webhook-rotate", "editor-bell", "feedback", "sticker", "mcp-write", "mount"];
|
|
42
|
+
export type RateLimitClass = (typeof RATE_LIMIT_CLASSES)[number];
|
|
43
|
+
/**
|
|
44
|
+
* A procedure's class, or for a class counted per identifier (`sign-in`,
|
|
45
|
+
* `code-send`, `driver-sign-in`, `link-write`, `provider-callback`, `checkpoint`,
|
|
46
|
+
* `editor-bell`, `storefront-newsletter`) the class and the top-level input
|
|
47
|
+
* field holding the email, phone, link token or what it counts per, which
|
|
48
|
+
* the server hashes before it becomes a key.
|
|
49
|
+
*/
|
|
50
|
+
export type RateLimitDeclaration = RateLimitClass | {
|
|
51
|
+
class: RateLimitClass;
|
|
52
|
+
identifier: string;
|
|
53
|
+
};
|
|
54
|
+
export type ProcedureMeta<TPermission extends string = string> = ProcedureAccess<TPermission> & {
|
|
55
|
+
/**
|
|
56
|
+
* How calls are counted. Required on a public procedure and on any that
|
|
57
|
+
* may write; a permission-guarded read (`mcp.readOnly`, or a GET route)
|
|
58
|
+
* may leave it out and takes its audience's read class. Nothing declared
|
|
59
|
+
* where it is required fails closed when the router is built.
|
|
60
|
+
*/
|
|
61
|
+
rateLimit?: RateLimitDeclaration;
|
|
62
|
+
/** Exposed as an MCP tool, with these annotations. Needs a `route.description`. */
|
|
63
|
+
mcp?: McpExposure;
|
|
64
|
+
/**
|
|
65
|
+
* Exposed over the REST API (the audience a server mounts with `mountRest`:
|
|
66
|
+
* the api's `app`, Cody Pay's `merchant`). Needs `route.method` and `route.path`.
|
|
67
|
+
*/
|
|
68
|
+
rest?: true;
|
|
69
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { commonErrors } from "./errors.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { oc } from "@orpc/contract";
|
|
4
|
+
// ../contract-kit/src/procedure.ts
|
|
5
|
+
/**
|
|
6
|
+
* The base of an audience's procedures whose `permission` must be one of
|
|
7
|
+
* `TPermission`, its catalogue's keys (`merchantProcedure` in api-contract):
|
|
8
|
+
* a key outside it is a type error here and refused when the router is built.
|
|
9
|
+
*/
|
|
10
|
+
function audienceProcedure() {
|
|
11
|
+
return oc.$meta({}).errors(commonErrors);
|
|
12
|
+
}
|
|
13
|
+
audienceProcedure();
|
|
14
|
+
/** Input of a procedure that takes none; an object so it stays a valid MCP tool input. */
|
|
15
|
+
const noInput = z.object({}).optional();
|
|
16
|
+
export { audienceProcedure, noInput };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "zod";
|
package/dist/cookie-secret.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { createServerOnlyFn } from "@tanstack/react-start";
|
|
2
|
-
|
|
2
|
+
// src/cookie-secret.ts
|
|
3
3
|
const derivedCookieSecret = createServerOnlyFn(async (label) => {
|
|
4
4
|
const secret = process.env.STOREFRONT_CUSTOMER_SESSION_SECRET;
|
|
5
5
|
if (!secret) throw new Error(`${label} cookie: STOREFRONT_CUSTOMER_SESSION_SECRET missing — orchestrator did not inject it`);
|
|
6
6
|
const { createHmac } = await import("node:crypto");
|
|
7
7
|
return createHmac("sha256", secret).update(label).digest("hex");
|
|
8
8
|
});
|
|
9
|
-
//#endregion
|
|
10
9
|
export { derivedCookieSecret };
|
package/dist/csrf.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/csrf.ts
|
|
2
2
|
function checkOrigin(originHeader, expectedOrigin) {
|
|
3
3
|
if (!originHeader) return {
|
|
4
4
|
ok: false,
|
|
@@ -17,5 +17,4 @@ function checkOrigin(originHeader, expectedOrigin) {
|
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
//#endregion
|
|
21
20
|
export { checkOrigin };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/customer-handoff.d.ts
|
|
2
1
|
export type ConsumeCustomerHandoffResult = {
|
|
3
2
|
ok: true;
|
|
4
3
|
} | {
|
|
@@ -9,5 +8,4 @@ export type ConsumeCustomerHandoffResult = {
|
|
|
9
8
|
* Plain server-only helper. Tested directly; each theme wraps it in a thin
|
|
10
9
|
* `createServerFn` for its root route's `beforeLoad`.
|
|
11
10
|
*/
|
|
12
|
-
export declare const consumeCustomerHandoff: (nonce: string, state: string | undefined) => Promise<ConsumeCustomerHandoffResult>;
|
|
13
|
-
//#endregion
|
|
11
|
+
export declare const consumeCustomerHandoff: (nonce: string, state: string | undefined) => Promise<ConsumeCustomerHandoffResult>;
|
package/dist/customer-handoff.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { writeCustomerSession } from "./customer-session.js";
|
|
2
1
|
import { matchesAccountState } from "./account-state.js";
|
|
2
|
+
import { writeCustomerSession } from "./customer-session.js";
|
|
3
|
+
import { errorCode, storefront } from "./storefront.js";
|
|
3
4
|
import { createServerOnlyFn } from "@tanstack/react-start";
|
|
4
|
-
|
|
5
|
+
// src/customer-handoff.ts
|
|
5
6
|
/**
|
|
6
7
|
* Plain server-only helper. Tested directly; each theme wraps it in a thin
|
|
7
8
|
* `createServerFn` for its root route's `beforeLoad`.
|
|
@@ -33,37 +34,21 @@ const consumeAndStore = createServerOnlyFn(async (nonce, state) => {
|
|
|
33
34
|
reason: "unbound"
|
|
34
35
|
};
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
let session;
|
|
38
|
+
try {
|
|
39
|
+
session = await storefront().customer.handoff.consume({ token: nonce });
|
|
40
|
+
} catch (error) {
|
|
41
|
+
if (errorCode(error) !== "NOT_FOUND") throw error;
|
|
39
42
|
console.warn(JSON.stringify({
|
|
40
43
|
event: "theme_customer_handoff_consume_failed",
|
|
41
|
-
reason: result.reason,
|
|
42
|
-
ts: Date.now()
|
|
43
|
-
}));
|
|
44
|
-
return {
|
|
45
|
-
ok: false,
|
|
46
|
-
reason: result.reason
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
const expectedShop = process.env.STORE_SLUG;
|
|
50
|
-
if (!expectedShop || result.payload.shopHandle !== expectedShop) {
|
|
51
|
-
console.warn(JSON.stringify({
|
|
52
|
-
event: "theme_customer_handoff_cross_shop",
|
|
53
|
-
payloadShop: result.payload.shopHandle,
|
|
54
|
-
expectedShop,
|
|
55
44
|
ts: Date.now()
|
|
56
45
|
}));
|
|
57
46
|
return {
|
|
58
47
|
ok: false,
|
|
59
|
-
reason: "
|
|
48
|
+
reason: "not_found"
|
|
60
49
|
};
|
|
61
50
|
}
|
|
62
|
-
await writeCustomerSession(
|
|
63
|
-
token: result.payload.customerSessionToken,
|
|
64
|
-
expiresAt: result.payload.customerSessionExpiresAt
|
|
65
|
-
});
|
|
51
|
+
await writeCustomerSession(session);
|
|
66
52
|
return { ok: true };
|
|
67
53
|
});
|
|
68
|
-
//#endregion
|
|
69
54
|
export { consumeCustomerHandoff };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/customer-session.d.ts
|
|
2
1
|
export interface CustomerSessionData {
|
|
3
2
|
token?: string;
|
|
4
3
|
expiresAt?: string;
|
|
@@ -8,5 +7,4 @@ export declare const writeCustomerSession: (data: {
|
|
|
8
7
|
token: string;
|
|
9
8
|
expiresAt: string;
|
|
10
9
|
}) => Promise<void>;
|
|
11
|
-
export declare const clearCustomerSession: () => Promise<void>;
|
|
12
|
-
//#endregion
|
|
10
|
+
export declare const clearCustomerSession: () => Promise<void>;
|
package/dist/customer-session.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { derivedCookieSecret } from "./cookie-secret.js";
|
|
2
2
|
import { createServerOnlyFn } from "@tanstack/react-start";
|
|
3
3
|
import { createShopBoundCookieConfig } from "@shop-on/customer-runtime/session-cookie";
|
|
4
|
-
|
|
4
|
+
// src/customer-session.ts
|
|
5
5
|
const TTL_SECONDS = 2592e3;
|
|
6
6
|
const DOMAIN_LABEL = "customer";
|
|
7
7
|
const sessionConfig = createServerOnlyFn(async () => {
|
|
@@ -37,5 +37,4 @@ const writeCustomerSession = createServerOnlyFn(async (data) => {
|
|
|
37
37
|
const clearCustomerSession = createServerOnlyFn(async () => {
|
|
38
38
|
await (await loadSession()).clear();
|
|
39
39
|
});
|
|
40
|
-
//#endregion
|
|
41
40
|
export { clearCustomerSession, readCustomerSession, writeCustomerSession };
|
package/dist/customer.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
//#region src/customer.d.ts
|
|
2
1
|
export type CurrentCustomer = {
|
|
3
2
|
id: string;
|
|
4
3
|
email: string | null;
|
|
5
4
|
firstName: string | null;
|
|
6
5
|
lastName: string | null;
|
|
6
|
+
/** First and last name joined, null when neither is set. */
|
|
7
7
|
name: string | null;
|
|
8
8
|
};
|
|
9
9
|
export declare function probeCurrentCustomer(): Promise<CurrentCustomer | null>;
|
|
10
|
-
export declare function revokeCustomerSession(): Promise<void>;
|
|
11
|
-
//#endregion
|
|
10
|
+
export declare function revokeCustomerSession(): Promise<void>;
|
package/dist/customer.js
CHANGED
|
@@ -1,61 +1,44 @@
|
|
|
1
|
-
import { graphql, request } from "./graphql.js";
|
|
2
1
|
import { clearCustomerSession, readCustomerSession } from "./customer-session.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
`);
|
|
15
|
-
const CustomerLogoutMutation = graphql(`
|
|
16
|
-
mutation ThemeCustomerLogout($input: CustomerLogoutInput!) {
|
|
17
|
-
customerLogout(input: $input) {
|
|
18
|
-
success
|
|
19
|
-
userErrors {
|
|
20
|
-
code
|
|
21
|
-
field
|
|
22
|
-
message
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
`);
|
|
2
|
+
import { StorefrontConfigError, buyerStorefront, errorCode } from "./storefront.js";
|
|
3
|
+
// src/customer.ts
|
|
4
|
+
function warn(event, error) {
|
|
5
|
+
console.warn(JSON.stringify({
|
|
6
|
+
event,
|
|
7
|
+
error: errorCode(error) ?? String(error),
|
|
8
|
+
ts: Date.now()
|
|
9
|
+
}));
|
|
10
|
+
}
|
|
27
11
|
async function probeCurrentCustomer() {
|
|
28
12
|
const session = await readCustomerSession();
|
|
29
|
-
if (!session?.token
|
|
30
|
-
let
|
|
13
|
+
if (!session?.token) return null;
|
|
14
|
+
let customer;
|
|
31
15
|
try {
|
|
32
|
-
|
|
33
|
-
} catch (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
error: err instanceof Error ? `${err.name}: ${err.message}` : String(err),
|
|
37
|
-
ts: Date.now()
|
|
38
|
-
}));
|
|
16
|
+
({customer} = await buyerStorefront(session.token).customer.get({}));
|
|
17
|
+
} catch (error) {
|
|
18
|
+
if (error instanceof StorefrontConfigError) throw error;
|
|
19
|
+
warn("current_customer_probe_failed", error);
|
|
39
20
|
return null;
|
|
40
21
|
}
|
|
41
|
-
if (!
|
|
22
|
+
if (!customer) {
|
|
42
23
|
await clearCustomerSession();
|
|
43
24
|
return null;
|
|
44
25
|
}
|
|
45
|
-
|
|
26
|
+
const { id, email, firstName, lastName } = customer;
|
|
27
|
+
return {
|
|
28
|
+
id,
|
|
29
|
+
email,
|
|
30
|
+
firstName,
|
|
31
|
+
lastName,
|
|
32
|
+
name: [firstName, lastName].filter(Boolean).join(" ") || null
|
|
33
|
+
};
|
|
46
34
|
}
|
|
47
35
|
async function revokeCustomerSession() {
|
|
48
36
|
const session = await readCustomerSession();
|
|
49
37
|
if (!session?.token) return;
|
|
50
38
|
try {
|
|
51
|
-
await
|
|
52
|
-
} catch (
|
|
53
|
-
|
|
54
|
-
event: "theme_customer_logout_revoke_failed",
|
|
55
|
-
error: err instanceof Error ? `${err.name}: ${err.message}` : String(err),
|
|
56
|
-
ts: Date.now()
|
|
57
|
-
}));
|
|
39
|
+
await buyerStorefront(session.token).customer.signOut({});
|
|
40
|
+
} catch (error) {
|
|
41
|
+
warn("theme_customer_logout_revoke_failed", error);
|
|
58
42
|
}
|
|
59
43
|
}
|
|
60
|
-
//#endregion
|
|
61
44
|
export { probeCurrentCustomer, revokeCustomerSession };
|
package/dist/files.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/files.d.ts
|
|
2
1
|
export type FocalPoint = {
|
|
3
2
|
x: number;
|
|
4
3
|
y: number;
|
|
@@ -50,20 +49,60 @@ type FileLikeNode = {
|
|
|
50
49
|
} | null;
|
|
51
50
|
} | null | undefined;
|
|
52
51
|
export declare function toFileInfo(node: FileLikeNode, extra?: {
|
|
53
|
-
srcset?: string | null;
|
|
54
|
-
thumbUrl?: string | null;
|
|
55
|
-
thumbhash?: string | null;
|
|
56
52
|
baseWidth?: number;
|
|
57
53
|
}): FileInfo | null;
|
|
54
|
+
/** An image as the storefront procedures answer it (`@shop-on/api-contract/image`). */
|
|
55
|
+
export type StorefrontImage = {
|
|
56
|
+
id: string;
|
|
57
|
+
url: string;
|
|
58
|
+
/** `url` resized: `{width}`, `{height}` and `{fit}` to fill in; null when it cannot be resized. */
|
|
59
|
+
sized: string | null;
|
|
60
|
+
width: number;
|
|
61
|
+
height: number;
|
|
62
|
+
alt: string | null;
|
|
63
|
+
thumbhash: string | null;
|
|
64
|
+
focalPoint: FocalPoint | null;
|
|
65
|
+
};
|
|
66
|
+
/** `image` as every renderer draws it: `url` at `baseWidth`, a srcset of its
|
|
67
|
+
* 1×, 1.5×, 2× and 3× rungs, and an 80px thumb. A rung past the original's
|
|
68
|
+
* width is left out and every size is `scale-down`, so an image is never
|
|
69
|
+
* enlarged (legacy's `maxWidth`); an image that cannot be resized is its
|
|
70
|
+
* original, with no srcset. */
|
|
71
|
+
export declare function imageFileInfo(image: StorefrontImage, baseWidth: number): ImageFileInfo;
|
|
72
|
+
/** A video as the storefront procedures answer it (`@shop-on/api-contract/video`):
|
|
73
|
+
* only once it is ready, so its MP4, HLS bundle and poster are all there. */
|
|
74
|
+
export type StorefrontVideo = {
|
|
75
|
+
id: string;
|
|
76
|
+
url: string;
|
|
77
|
+
hlsUrl: string;
|
|
78
|
+
width: number;
|
|
79
|
+
height: number;
|
|
80
|
+
durationMs: number;
|
|
81
|
+
alt: string | null;
|
|
82
|
+
poster: StorefrontImage;
|
|
83
|
+
};
|
|
84
|
+
/** `video` as every player loads it: the HLS bundle, and its poster at
|
|
85
|
+
* `baseWidth`. The MP4 stays off the payload: a ready video always has its
|
|
86
|
+
* bundle. */
|
|
87
|
+
export declare function videoFileInfo(video: StorefrontVideo, baseWidth: number): VideoFileInfo;
|
|
88
|
+
/** A product's media item (`@shop-on/api-contract/media`) as renderers draw
|
|
89
|
+
* it; its id is its file's, the one a variant's media ids name. Null while
|
|
90
|
+
* the file is still processing. */
|
|
91
|
+
export declare function mediaFileInfo(media: {
|
|
92
|
+
image: StorefrontImage | null;
|
|
93
|
+
video: StorefrontVideo | null;
|
|
94
|
+
}, baseWidth: number): FileInfo | null;
|
|
95
|
+
/** The box a file setting draws its image in, as the theme asks for it. */
|
|
58
96
|
export type Transform = {
|
|
59
|
-
maxHeight?: number;
|
|
60
97
|
maxWidth?: number;
|
|
61
|
-
|
|
62
|
-
scale?: number;
|
|
98
|
+
maxHeight?: number;
|
|
63
99
|
};
|
|
64
|
-
|
|
100
|
+
/** A library file by its id (an `image_picker`, `video` or logo setting), an
|
|
101
|
+
* image drawn in `transform`'s box. Null for anything a buyer may not see: not
|
|
102
|
+
* a `file_…` id (no call), still processing, not the library's, a font or a
|
|
103
|
+
* document; and on a failed read, which is not cached. */
|
|
104
|
+
export declare function fetchFileById(file: {
|
|
65
105
|
id: string;
|
|
66
106
|
transform?: Transform;
|
|
67
|
-
})
|
|
68
|
-
//#endregion
|
|
107
|
+
}): Promise<FileInfo | null>;
|
|
69
108
|
export {};
|