@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,261 @@
|
|
|
1
|
+
import { mntNonNegative } from "../../../contract-kit/src/money.js";
|
|
2
|
+
import { liteId } from "../ids.js";
|
|
3
|
+
import { customerAddressInput } from "../addresses.js";
|
|
4
|
+
import { typedEmail } from "../text.js";
|
|
5
|
+
import { checkoutSavedAddress } from "./checkout.js";
|
|
6
|
+
import { turnstileToken } from "./forms.js";
|
|
7
|
+
import { TURNSTILE_FAILED, storefrontBase, storefrontProcedure } from "./procedure.js";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
// ../api-contract/src/storefront/customer.ts
|
|
10
|
+
/** The header a storefront call carries its signed-in buyer's session in, beside the storefront key. */
|
|
11
|
+
const BUYER_SESSION_HEADER = "x-buyer-session";
|
|
12
|
+
/** A buyer's session: the bearer to send in `x-buyer-session`, shown once. */
|
|
13
|
+
const buyerSession = z.object({
|
|
14
|
+
token: z.string(),
|
|
15
|
+
expiresAt: z.iso.datetime()
|
|
16
|
+
});
|
|
17
|
+
const storefrontCustomer = z.object({
|
|
18
|
+
id: liteId("customer"),
|
|
19
|
+
email: z.string().nullable(),
|
|
20
|
+
phone: z.string().nullable(),
|
|
21
|
+
firstName: z.string().nullable(),
|
|
22
|
+
lastName: z.string().nullable()
|
|
23
|
+
});
|
|
24
|
+
/** An ID token or a link token is far below this; past it nothing is Google's. */
|
|
25
|
+
const GOOGLE_TOKEN_MAX = 4096;
|
|
26
|
+
storefrontBase.meta({
|
|
27
|
+
permission: "storefront.read",
|
|
28
|
+
rateLimit: {
|
|
29
|
+
class: "code-send",
|
|
30
|
+
identifier: "email"
|
|
31
|
+
}
|
|
32
|
+
}).route({
|
|
33
|
+
summary: "Mail a buyer a sign-in code",
|
|
34
|
+
description: "Mails a 6-digit code, good for 15 minutes and once, to the address; a new code replaces the one before. The shop's customer with the address signs in by it, a new one made (pending) when none has it, so the answer is the same whether or not the address was a customer's. When the platform's Turnstile is on, `turnstileToken` is its widget's token, checked first: TURNSTILE_FAILED when Cloudflare does not pass it. VALIDATION_FAILED for a malformed address. Counted per buyer address (20 an hour) and per email (1 a minute, 5 an hour); RATE_LIMITED past either, refused while the counter is down. Answered whatever the shop's status: a closed or suspended shop's buyers still sign in to read their orders (legacy's)."
|
|
35
|
+
}).errors({ TURNSTILE_FAILED }).input(z.object({
|
|
36
|
+
email: typedEmail,
|
|
37
|
+
turnstileToken
|
|
38
|
+
})).output(z.object({}));
|
|
39
|
+
storefrontBase.meta({
|
|
40
|
+
permission: "storefront.read",
|
|
41
|
+
rateLimit: {
|
|
42
|
+
class: "sign-in",
|
|
43
|
+
identifier: "email"
|
|
44
|
+
}
|
|
45
|
+
}).route({
|
|
46
|
+
summary: "Sign a buyer in with their code",
|
|
47
|
+
description: "Checks the code `signIn.requestCode` mailed to the address and opens a session: the customer becomes active, its email verified (the first time kept), and `acceptsMarketing`, when sent, records or withdraws their consent. CODE_REFUSED for a wrong code, an expired or spent one, a code mailed to another address, an address with none, or one guessed wrong five times (ask for a new one); after a wrong guess the next is refused for attempts³ seconds. TURNSTILE_FAILED as `requestCode`. Counted per buyer address (10 a minute) and per email (5 a minute, 20 an hour). Answered whatever the shop's status, as `requestCode`."
|
|
48
|
+
}).errors({
|
|
49
|
+
TURNSTILE_FAILED,
|
|
50
|
+
CODE_REFUSED: {
|
|
51
|
+
status: 422,
|
|
52
|
+
data: z.object({})
|
|
53
|
+
}
|
|
54
|
+
}).input(z.object({
|
|
55
|
+
email: typedEmail,
|
|
56
|
+
code: z.string().trim().max(16),
|
|
57
|
+
turnstileToken,
|
|
58
|
+
acceptsMarketing: z.boolean().optional(),
|
|
59
|
+
/** The `linkToken` `google.signIn` answered with `confirmEmail`: the Google account is linked once the code checks out. */
|
|
60
|
+
googleLinkToken: z.string().max(GOOGLE_TOKEN_MAX).optional()
|
|
61
|
+
})).output(buyerSession);
|
|
62
|
+
const googleCredential = z.string().min(1).max(GOOGLE_TOKEN_MAX);
|
|
63
|
+
const GOOGLE_REFUSED = {
|
|
64
|
+
status: 422,
|
|
65
|
+
data: z.object({})
|
|
66
|
+
};
|
|
67
|
+
const GOOGLE_EMAIL_UNVERIFIED = {
|
|
68
|
+
status: 422,
|
|
69
|
+
data: z.object({})
|
|
70
|
+
};
|
|
71
|
+
storefrontBase.meta({
|
|
72
|
+
permission: "storefront.read",
|
|
73
|
+
rateLimit: "google-nonce"
|
|
74
|
+
}).route({
|
|
75
|
+
summary: "Mint a nonce for the Google button",
|
|
76
|
+
description: "A one-time nonce, good for 5 minutes, for the Sign in with Google button's `nonce`: every `google.signIn` and `google.link` spends one. Null while Google sign-in is off for the shop (its owner's `google_sign_in` flag) or the api has no Google client. Counted per buyer address (10 a minute). Answered whatever the shop's status, as `signIn.requestCode`."
|
|
77
|
+
}).input(z.object({})).output(z.object({ nonce: z.string().nullable() }));
|
|
78
|
+
storefrontBase.meta({
|
|
79
|
+
permission: "storefront.read",
|
|
80
|
+
rateLimit: "code-redeem"
|
|
81
|
+
}).route({
|
|
82
|
+
summary: "Sign a buyer in with Google",
|
|
83
|
+
description: "Signs in with the ID token the Google button returned, its nonce spent. A Google account linked in the shop signs in as its customer, whatever address it carries now. An address Google vouches for (Gmail, or a Workspace domain) signs in as the shop's customer on it, made if new, and links the account. Either opens the session `signIn.verifyCode` opens (`session`). An address Google verified but does not own answers `confirmEmail` and a `linkToken` (15 minutes): ask `signIn.requestCode` for the address, then pass the token to `signIn.verifyCode`. GOOGLE_EMAIL_UNVERIFIED when Google has not verified the address; GOOGLE_REFUSED for anything else (a token that does not verify, a nonce not this shop's or spent, Google unreachable). Counted per buyer address (10 a minute). Answered whatever the shop's status."
|
|
84
|
+
}).errors({
|
|
85
|
+
GOOGLE_REFUSED,
|
|
86
|
+
GOOGLE_EMAIL_UNVERIFIED
|
|
87
|
+
}).input(z.object({
|
|
88
|
+
credential: googleCredential,
|
|
89
|
+
acceptsMarketing: z.boolean().optional()
|
|
90
|
+
})).output(z.object({
|
|
91
|
+
session: buyerSession.nullable(),
|
|
92
|
+
confirmEmail: z.string().nullable(),
|
|
93
|
+
linkToken: z.string().nullable()
|
|
94
|
+
}));
|
|
95
|
+
storefrontBase.meta({
|
|
96
|
+
permission: "storefront.read",
|
|
97
|
+
rateLimit: "buyer-write"
|
|
98
|
+
}).route({
|
|
99
|
+
summary: "Link a Google account to the buyer's sign-in",
|
|
100
|
+
description: "Links the Google account of the ID token (its nonce spent) to the signed-in buyer, and mails them that it now signs them in. ALREADY_LINKED when they have one (unlink it first); GOOGLE_EMAIL_UNVERIFIED when Google has not verified its address; GOOGLE_ACCOUNT_TAKEN when another customer of the shop signs in with it; GOOGLE_REFUSED for a token that does not verify, a nonce not this shop's, Google unreachable, or an erased buyer."
|
|
101
|
+
}).errors({
|
|
102
|
+
GOOGLE_REFUSED,
|
|
103
|
+
GOOGLE_EMAIL_UNVERIFIED,
|
|
104
|
+
ALREADY_LINKED: {
|
|
105
|
+
status: 409,
|
|
106
|
+
data: z.object({})
|
|
107
|
+
},
|
|
108
|
+
GOOGLE_ACCOUNT_TAKEN: {
|
|
109
|
+
status: 409,
|
|
110
|
+
data: z.object({})
|
|
111
|
+
}
|
|
112
|
+
}).input(z.object({ credential: googleCredential })).output(z.object({}));
|
|
113
|
+
storefrontBase.meta({
|
|
114
|
+
permission: "storefront.read",
|
|
115
|
+
rateLimit: "buyer-write"
|
|
116
|
+
}).route({
|
|
117
|
+
summary: "Unlink the buyer's Google account",
|
|
118
|
+
description: "Unlinks the signed-in buyer's Google account and ends their other sessions (this one stays). `unlinked` false when none was linked. Never refused for the way in it leaves: the code to their address signs them in."
|
|
119
|
+
}).input(z.object({})).output(z.object({ unlinked: z.boolean() }));
|
|
120
|
+
storefrontProcedure.meta({
|
|
121
|
+
permission: "storefront.read",
|
|
122
|
+
rateLimit: "storefront"
|
|
123
|
+
}).route({
|
|
124
|
+
summary: "Read the signed-in buyer",
|
|
125
|
+
description: "The customer whose session came in `x-buyer-session`; null with none, or one revoked, expired or of another shop (the storefront then drops its cookie)."
|
|
126
|
+
}).input(z.object({})).output(z.object({ customer: storefrontCustomer.nullable() }));
|
|
127
|
+
/** The signed-in buyer's account page: their profile, consent, sign-in methods, store credit and address book. */
|
|
128
|
+
const storefrontAccount = storefrontCustomer.extend({
|
|
129
|
+
/** Whether they agreed to hear from the shop. */
|
|
130
|
+
acceptsMarketing: z.boolean(),
|
|
131
|
+
/** Whether a Google account signs them in. */
|
|
132
|
+
googleLinked: z.boolean(),
|
|
133
|
+
storeCredit: z.object({
|
|
134
|
+
/** Whether the shop lets buyers spend store credit: the account shows the balance only then. */
|
|
135
|
+
enabled: z.boolean(),
|
|
136
|
+
/** What they can spend now, with what a payment under way holds of it. */
|
|
137
|
+
balance: mntNonNegative,
|
|
138
|
+
/** The soonest expiry and what expires then; null when nothing does. */
|
|
139
|
+
nextExpiry: z.object({
|
|
140
|
+
amount: mntNonNegative,
|
|
141
|
+
expiresAt: z.iso.datetime()
|
|
142
|
+
}).nullable()
|
|
143
|
+
}),
|
|
144
|
+
/** The default first, then oldest first. */
|
|
145
|
+
addresses: z.array(checkoutSavedAddress)
|
|
146
|
+
});
|
|
147
|
+
storefrontBase.meta({
|
|
148
|
+
permission: "storefront.read",
|
|
149
|
+
rateLimit: "storefront"
|
|
150
|
+
}).route({
|
|
151
|
+
summary: "Read the signed-in buyer's account",
|
|
152
|
+
description: "The account app's signed-in pages: the customer whose session came in `x-buyer-session` with their marketing consent, whether Google signs them in, their store credit and saved addresses; null as `get` is. Answered whatever the shop's status: a closed shop's buyers still read their orders."
|
|
153
|
+
}).input(z.object({})).output(z.object({ customer: storefrontAccount.nullable() }));
|
|
154
|
+
storefrontProcedure.meta({
|
|
155
|
+
permission: "storefront.read",
|
|
156
|
+
rateLimit: "write"
|
|
157
|
+
}).route({
|
|
158
|
+
summary: "Sign the buyer out",
|
|
159
|
+
description: "Revokes the session sent in `x-buyer-session`, this one only: the buyer's other devices stay signed in. Answers the same with no session."
|
|
160
|
+
}).input(z.object({})).output(z.object({}));
|
|
161
|
+
storefrontProcedure.meta({
|
|
162
|
+
permission: "storefront.read",
|
|
163
|
+
rateLimit: "buyer-write"
|
|
164
|
+
}).route({
|
|
165
|
+
summary: "Hand the signed-in buyer to the storefront",
|
|
166
|
+
description: "A one-time token, good for 5 minutes, that opens a session of its own for the buyer whose session came in `x-buyer-session` (`handoff.consume`): the account app appends it to the storefront URL it sends the buyer back to. UNAUTHENTICATED without a signed-in buyer."
|
|
167
|
+
}).input(z.object({})).output(z.object({
|
|
168
|
+
token: z.string(),
|
|
169
|
+
expiresAt: z.iso.datetime()
|
|
170
|
+
}));
|
|
171
|
+
storefrontProcedure.meta({
|
|
172
|
+
permission: "storefront.read",
|
|
173
|
+
rateLimit: "code-redeem"
|
|
174
|
+
}).route({
|
|
175
|
+
summary: "Open the session a handoff token carries",
|
|
176
|
+
description: "Spends a token `handoff.create` minted in this shop and opens a new session for its buyer. NOT_FOUND `{ resource: \"handoff\" }` for a token that is unknown, another shop's, expired or spent. Counted per buyer address (10 a minute)."
|
|
177
|
+
}).input(z.object({ token: z.string().max(64) })).output(buyerSession);
|
|
178
|
+
const buyerName = z.string().trim().max(255).nullable().optional();
|
|
179
|
+
storefrontBase.meta({
|
|
180
|
+
permission: "storefront.read",
|
|
181
|
+
rateLimit: "buyer-write"
|
|
182
|
+
}).route({
|
|
183
|
+
summary: "Change the signed-in buyer's profile",
|
|
184
|
+
description: "Changes the fields named (legacy's PATCH): a name left out is kept, null or blank clears it; `acceptsMarketing` records or withdraws their consent (a consent already given keeps its time). Their email changes only through `emailChange`, their phone not here. PRECONDITION_FAILED `customers.erased` for an erased customer."
|
|
185
|
+
}).input(z.object({
|
|
186
|
+
firstName: buyerName,
|
|
187
|
+
lastName: buyerName,
|
|
188
|
+
acceptsMarketing: z.boolean().optional()
|
|
189
|
+
})).output(z.object({ customer: storefrontCustomer }));
|
|
190
|
+
storefrontBase.meta({
|
|
191
|
+
permission: "storefront.read",
|
|
192
|
+
rateLimit: "buyer-write"
|
|
193
|
+
}).route({
|
|
194
|
+
summary: "Ask to sign in with another email",
|
|
195
|
+
description: `Parks the address with a 6-digit code mailed to it, good for 15 minutes and once (\`emailChange.confirm\`); the buyer's email stays as it is until then, and a new request replaces the code before. An address another customer of the shop holds is answered the same: that customer is mailed that the address already has an account here, and no code is sent, so nothing can confirm it. \`pendingEmail\` is the address waiting; null when it was the buyer's own (any waiting change is dropped). Within 60 seconds of the buyer's last code, the same address is answered as waiting with \`retryAfterSeconds\` (the seconds left; nothing is mailed again) and another is CHANGE_IN_PROGRESS; \`retryAfterSeconds\` is null otherwise. TURNSTILE_FAILED as \`signIn.requestCode\`, VALIDATION_FAILED for a malformed address. A request that mails is counted past both checks: 10 an hour per buyer address, 5 per buyer, 10 per email asked for in the shop; RATE_LIMITED past any, refused while the counter is down.`
|
|
196
|
+
}).errors({
|
|
197
|
+
TURNSTILE_FAILED,
|
|
198
|
+
CHANGE_IN_PROGRESS: {
|
|
199
|
+
status: 409,
|
|
200
|
+
data: z.object({})
|
|
201
|
+
}
|
|
202
|
+
}).input(z.object({
|
|
203
|
+
email: typedEmail,
|
|
204
|
+
turnstileToken
|
|
205
|
+
})).output(z.object({
|
|
206
|
+
pendingEmail: z.string().nullable(),
|
|
207
|
+
retryAfterSeconds: z.int().positive().nullable()
|
|
208
|
+
}));
|
|
209
|
+
storefrontBase.meta({
|
|
210
|
+
permission: "storefront.read",
|
|
211
|
+
rateLimit: "code-redeem"
|
|
212
|
+
}).route({
|
|
213
|
+
summary: "Move the buyer's sign-in to the new email",
|
|
214
|
+
description: "Checks the code `emailChange.request` mailed: the email becomes the parked address, verified; the buyer's linked Google accounts are unlinked, every other session of theirs ends (the one this came with stays), and the old address is told. NO_PENDING_CHANGE when no change waits (none asked, or spent); CODE_REFUSED for a wrong, expired or guessed-out code (after a wrong guess the next is refused for attempts³ seconds); CONFLICT `{ resource: \"customer\", field: \"email\" }` when another customer took the address meanwhile, the change then dropped. Counted per buyer address."
|
|
215
|
+
}).errors({
|
|
216
|
+
CODE_REFUSED: {
|
|
217
|
+
status: 422,
|
|
218
|
+
data: z.object({})
|
|
219
|
+
},
|
|
220
|
+
NO_PENDING_CHANGE: {
|
|
221
|
+
status: 409,
|
|
222
|
+
data: z.object({})
|
|
223
|
+
}
|
|
224
|
+
}).input(z.object({ code: z.string().trim().max(16) })).output(z.object({ customer: storefrontCustomer }));
|
|
225
|
+
const addressId = z.object({ addressId: liteId("customer_address") });
|
|
226
|
+
storefrontBase.meta({
|
|
227
|
+
permission: "storefront.read",
|
|
228
|
+
rateLimit: "buyer-write"
|
|
229
|
+
}).route({
|
|
230
|
+
summary: "Add an address to the buyer's book",
|
|
231
|
+
description: `Adds an address, the default when \`isDefault\` or whenever none of theirs is the default. A buyer keeps at most 5 (LIMIT_EXCEEDED). The id is the caller's: the same id again answers the address as stored; an id another address has is CONFLICT on \`id\`. NOT_FOUND \`{ resource: "area" }\` for an area there is not.`
|
|
232
|
+
}).errors({ LIMIT_EXCEEDED: {
|
|
233
|
+
status: 422,
|
|
234
|
+
data: z.object({ limit: z.int() })
|
|
235
|
+
} }).input(z.object({
|
|
236
|
+
id: liteId("customer_address"),
|
|
237
|
+
address: customerAddressInput,
|
|
238
|
+
isDefault: z.boolean().default(false)
|
|
239
|
+
})).output(z.object({ address: checkoutSavedAddress }));
|
|
240
|
+
storefrontBase.meta({
|
|
241
|
+
permission: "storefront.read",
|
|
242
|
+
rateLimit: "buyer-write"
|
|
243
|
+
}).route({
|
|
244
|
+
summary: "Change an address in the buyer's book",
|
|
245
|
+
description: "Replaces the address whole with the one given; its default flag is kept."
|
|
246
|
+
}).input(addressId.extend({ address: customerAddressInput })).output(z.object({ address: checkoutSavedAddress }));
|
|
247
|
+
storefrontBase.meta({
|
|
248
|
+
permission: "storefront.read",
|
|
249
|
+
rateLimit: "buyer-write"
|
|
250
|
+
}).route({
|
|
251
|
+
summary: "Delete an address from the buyer's book",
|
|
252
|
+
description: "Deletes the address. When it was the default, the buyer has none until they choose one."
|
|
253
|
+
}).input(addressId).output(z.object({ deletedId: liteId("customer_address") }));
|
|
254
|
+
storefrontBase.meta({
|
|
255
|
+
permission: "storefront.read",
|
|
256
|
+
rateLimit: "buyer-write"
|
|
257
|
+
}).route({
|
|
258
|
+
summary: "Make an address the buyer's default",
|
|
259
|
+
description: "Makes one of the buyer's addresses the one checkout preselects; the one before it stops being the default. Answers the book, the default first."
|
|
260
|
+
}).input(addressId).output(z.object({ addresses: z.array(checkoutSavedAddress) }));
|
|
261
|
+
export { BUYER_SESSION_HEADER, buyerSession, storefrontAccount, storefrontCustomer };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { CONTACT_BODY_MAX, CONTACT_FIELDS_TOTAL_MAX, TURNSTILE_TOKEN_MAX } from "../limits.js";
|
|
2
|
+
import { typedEmail } from "../text.js";
|
|
3
|
+
import { TURNSTILE_FAILED, storefrontProcedure } from "./procedure.js";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
// ../api-contract/src/storefront/forms.ts
|
|
6
|
+
/** The widget's token; checked only while a widget applies. */
|
|
7
|
+
const turnstileToken = z.string().max(TURNSTILE_TOKEN_MAX).optional();
|
|
8
|
+
/** A row of the contact form: a label the theme or merchant chose and what the buyer entered. */
|
|
9
|
+
const contactField = z.object({
|
|
10
|
+
label: z.string().trim().max(CONTACT_FIELDS_TOTAL_MAX),
|
|
11
|
+
value: z.string().trim().max(CONTACT_FIELDS_TOTAL_MAX)
|
|
12
|
+
});
|
|
13
|
+
/** The rows a contact form keeps, in order: a row with a blank label or value is dropped, a repeated label kept (legacy's). */
|
|
14
|
+
const keptContactFields = (fields = []) => fields.filter((field) => field.label !== "" && field.value !== "");
|
|
15
|
+
storefrontProcedure.meta({
|
|
16
|
+
permission: "storefront.read",
|
|
17
|
+
rateLimit: "storefront-contact"
|
|
18
|
+
}).route({
|
|
19
|
+
summary: "Send the contact form",
|
|
20
|
+
description: `Mails the buyer's message to the shop's contact email, replies going to the buyer. \`email\` is required; \`name\`, \`phone\` and \`body\` are optional, and \`fields\` carries the form's other rows, each printed as its own line (a row with a blank label or value is dropped). VALIDATION_FAILED: a malformed email; \`too_small\` on \`body\` when the message and every row are blank; \`too_big\` on \`body\` past ${CONTACT_BODY_MAX} characters, on a row's label past 64, on \`fields\` past 20 rows kept (\`origin: "array"\`) or ${CONTACT_FIELDS_TOTAL_MAX} characters of labels and values together (\`origin: "string"\`). PRECONDITION_FAILED \`shops.contact_email_missing\` while the shop has no contact email. Counted per buyer address (5 an hour) and per shop (300 an hour). Nothing is stored.`
|
|
21
|
+
}).errors({ TURNSTILE_FAILED }).input(z.object({
|
|
22
|
+
email: typedEmail,
|
|
23
|
+
name: z.string().trim().max(255).optional(),
|
|
24
|
+
phone: z.string().trim().max(64).optional(),
|
|
25
|
+
body: z.string().trim().max(CONTACT_BODY_MAX).optional(),
|
|
26
|
+
fields: z.array(contactField).max(100).optional(),
|
|
27
|
+
turnstileToken
|
|
28
|
+
}).superRefine((input, context) => {
|
|
29
|
+
const kept = keptContactFields(input.fields);
|
|
30
|
+
if (!input.body && kept.length === 0) context.addIssue({
|
|
31
|
+
code: "too_small",
|
|
32
|
+
path: ["body"],
|
|
33
|
+
origin: "string",
|
|
34
|
+
minimum: 1,
|
|
35
|
+
inclusive: true,
|
|
36
|
+
message: "Blank submission"
|
|
37
|
+
});
|
|
38
|
+
if (kept.length > 20) context.addIssue({
|
|
39
|
+
code: "too_big",
|
|
40
|
+
path: ["fields"],
|
|
41
|
+
origin: "array",
|
|
42
|
+
maximum: 20,
|
|
43
|
+
inclusive: true,
|
|
44
|
+
message: "Too many rows"
|
|
45
|
+
});
|
|
46
|
+
(input.fields ?? []).forEach((field, at) => {
|
|
47
|
+
if (field.value !== "" && field.label.length > 64) context.addIssue({
|
|
48
|
+
code: "too_big",
|
|
49
|
+
path: [
|
|
50
|
+
"fields",
|
|
51
|
+
at,
|
|
52
|
+
"label"
|
|
53
|
+
],
|
|
54
|
+
origin: "string",
|
|
55
|
+
maximum: 64,
|
|
56
|
+
inclusive: true,
|
|
57
|
+
message: "Label too long"
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
if (kept.reduce((sum, f) => sum + f.label.length + f.value.length, 0) > 5e3) context.addIssue({
|
|
61
|
+
code: "too_big",
|
|
62
|
+
path: ["fields"],
|
|
63
|
+
origin: "string",
|
|
64
|
+
maximum: CONTACT_FIELDS_TOTAL_MAX,
|
|
65
|
+
inclusive: true,
|
|
66
|
+
message: "Rows too long"
|
|
67
|
+
});
|
|
68
|
+
})).output(z.object({}));
|
|
69
|
+
storefrontProcedure.meta({
|
|
70
|
+
permission: "storefront.read",
|
|
71
|
+
rateLimit: {
|
|
72
|
+
class: "storefront-newsletter",
|
|
73
|
+
identifier: "email"
|
|
74
|
+
}
|
|
75
|
+
}).route({
|
|
76
|
+
summary: "Subscribe to the newsletter",
|
|
77
|
+
description: "Records the buyer's consent to marketing email: the shop's customer with this email (a new one made when none has it) is marked subscribed, unless it already was. Answers the same whether or not the email was a customer's. VALIDATION_FAILED for a malformed email. Counted per buyer address (30 an hour), per email (1 a minute, 3 an hour, 5 a day) and per shop (1,200 an hour)."
|
|
78
|
+
}).errors({ TURNSTILE_FAILED }).input(z.object({
|
|
79
|
+
email: typedEmail,
|
|
80
|
+
turnstileToken
|
|
81
|
+
})).output(z.object({}));
|
|
82
|
+
export { contactField, keptContactFields, turnstileToken };
|