@asstio-dev/storefront 0.46.0 → 0.48.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/README.md +28 -2
- package/dist/account/browser.d.ts +65 -3
- package/dist/account/browser.js +79 -5
- package/dist/account/cookies.d.ts +10 -0
- package/dist/account/cookies.js +7 -0
- package/dist/account/index.d.ts +7 -1
- package/dist/account/index.js +9 -8
- package/dist/account/next.d.ts +123 -2
- package/dist/account/next.js +289 -4
- package/dist/analytics/events.d.ts +8 -2
- package/dist/analytics/events.js +7 -2
- package/dist/cart-codes.d.ts +38 -0
- package/dist/cart-codes.js +28 -0
- package/dist/consent/codec.d.ts +141 -0
- package/dist/consent/codec.js +239 -0
- package/dist/consent/coordinator.d.ts +107 -0
- package/dist/consent/coordinator.js +608 -0
- package/dist/consent/index.d.ts +8 -0
- package/dist/consent/index.js +8 -0
- package/dist/consent/notice.d.ts +10 -0
- package/dist/consent/notice.js +11 -0
- package/dist/consent/server.d.ts +36 -0
- package/dist/consent/server.js +45 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/schema.d.ts +3706 -428
- package/dist/shopper/index.d.ts +54 -0
- package/dist/shopper/index.js +36 -0
- package/package.json +17 -3
- package/src/schema.d.ts +3706 -428
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@asstio-dev/storefront/shopper` — stock watches (shopper-state spec §6, §9.4): the two watch projections and the mail's cancel
|
|
3
|
+
* link. Browser and server safe: nothing here holds a server key, a session or a shopper token. The watch actions themselves
|
|
4
|
+
* (`create`, `list`, `cancel`, `stopAll`) are `shopperActions(config).watches` in `account/next`.
|
|
5
|
+
*/
|
|
6
|
+
import type { Client } from "openapi-fetch";
|
|
7
|
+
import type { components } from "../schema";
|
|
8
|
+
import type { StorefrontPaths } from "../index.js";
|
|
9
|
+
import { type AccountResult } from "../account/index.js";
|
|
10
|
+
type Schemas = components["schemas"];
|
|
11
|
+
/** The owner projection (S26): what a shopper token, or an account owning a watch addressed to another e-mail, sees. `status` is
|
|
12
|
+
* `open` or `ended` whatever happened at the address; the e-mail is masked. It has no recipient-only member. */
|
|
13
|
+
export type ShopperWatch = Schemas["WatchDtoOwnerWatchDto"];
|
|
14
|
+
/** The recipient projection (S26): only for an account whose e-mail the watch is addressed to. `status` is `open`, `fired`,
|
|
15
|
+
* `expired` or `cancelled`; `notifiedAt` when a mail event exists, `cancelScope` (`watch`, `all`) when a cancel reached it. */
|
|
16
|
+
export type RecipientWatch = Schemas["WatchDtoRecipientWatchDto"];
|
|
17
|
+
/** Every answer that holds a watch (creation, lists, `GET /v1/shopper`, the adoption answer): narrow it by `projection`. */
|
|
18
|
+
export type Watch = ShopperWatch | RecipientWatch;
|
|
19
|
+
/** `GET /v1/shopper/watches`, `GET /v1/me/watches`: newest first. */
|
|
20
|
+
export type WatchList = Schemas["WatchListDto"];
|
|
21
|
+
/** A creation's answer: the watch (owner projection for a guest) and, from the guest route, the minted shopper token. */
|
|
22
|
+
export type WatchAnswer = Schemas["WatchAnswerDto"];
|
|
23
|
+
/** What to watch (spec §6.1): the variant of a product. `email` is the guest's own address; it is not sent under a session
|
|
24
|
+
* (the watch goes to the account's e-mail). `language` defaults to the client's `X-Locale` language. */
|
|
25
|
+
export type CreateWatchInput = {
|
|
26
|
+
productId: number;
|
|
27
|
+
variantId: number;
|
|
28
|
+
email?: string | null;
|
|
29
|
+
language?: string | null;
|
|
30
|
+
source?: string | null;
|
|
31
|
+
};
|
|
32
|
+
/** The mail's cancel scope: `watch` cancels that watch, `all` stops every watch for the e-mail the mail went to. */
|
|
33
|
+
export type WatchCancelScope = "watch" | "all";
|
|
34
|
+
export type CancelWatchByTokenOptions = {
|
|
35
|
+
/**
|
|
36
|
+
* Server side only: the shopper's IP (`shopperIpFrom`), sent as `X-Shopper-Ip` with a server-key client. A tokenless call is rate
|
|
37
|
+
* limited per verified shopper IP behind the server key; without it every recipient behind one SSR page would share the server's
|
|
38
|
+
* connection bucket. Ignored (never sent) with a publishable key, where the API counts the connection.
|
|
39
|
+
*/
|
|
40
|
+
shopperIp?: string | null;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* `POST /v1/watches/cancel` — the mail's cancel link (spec §6.2, WL6), with the link's `t` query parameter. Two ways to call it:
|
|
44
|
+
* - **in the browser**: the public client, `createStorefrontClient({ siteKey: <publishable key>, … })`; the API counts the
|
|
45
|
+
* shopper's own connection;
|
|
46
|
+
* - **on the server** (an SSR cancel page or a server action): a server-key client (`createShopperClient({ serverKey, shopperIp })`,
|
|
47
|
+
* or `createStorefrontClient` with the server key plus `{ shopperIp }` here), so the rate limit is the shopper's, never one bucket
|
|
48
|
+
* for the whole shop behind the server. Without a shopper IP the API answers `400 SHOPPER_IP_REQUIRED`.
|
|
49
|
+
*
|
|
50
|
+
* The request never carries a session or a shopper token (nor cookies). The API answers `204` whatever the token is: show a fixed
|
|
51
|
+
* text, never a watch state ("If a mail is already on its way you may still receive one."). A refusal comes back as `ok: false`.
|
|
52
|
+
*/
|
|
53
|
+
export declare function cancelWatchByToken(client: Client<StorefrontPaths>, token: string, scope: WatchCancelScope, options?: CancelWatchByTokenOptions): Promise<AccountResult<void>>;
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { accountResult } from "../account/index.js";
|
|
2
|
+
const isServerKey = (key) => key !== null && key.startsWith("sfk_srv_");
|
|
3
|
+
/**
|
|
4
|
+
* Whatever the caller's client carries, the cancel link's request holds no session and no shopper token (spec §6.2); `X-Shopper-Ip`
|
|
5
|
+
* only with the server key: the option's value, else what the client set (`createShopperClient({ shopperIp })`).
|
|
6
|
+
*/
|
|
7
|
+
function cancelHeaders(shopperIp) {
|
|
8
|
+
return {
|
|
9
|
+
onRequest({ request }) {
|
|
10
|
+
request.headers.delete("X-Shopper-Session");
|
|
11
|
+
request.headers.delete("X-Shopper-Token");
|
|
12
|
+
if (!isServerKey(request.headers.get("X-Site-Key")))
|
|
13
|
+
request.headers.delete("X-Shopper-Ip");
|
|
14
|
+
else if (shopperIp)
|
|
15
|
+
request.headers.set("X-Shopper-Ip", shopperIp);
|
|
16
|
+
return request;
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* `POST /v1/watches/cancel` — the mail's cancel link (spec §6.2, WL6), with the link's `t` query parameter. Two ways to call it:
|
|
22
|
+
* - **in the browser**: the public client, `createStorefrontClient({ siteKey: <publishable key>, … })`; the API counts the
|
|
23
|
+
* shopper's own connection;
|
|
24
|
+
* - **on the server** (an SSR cancel page or a server action): a server-key client (`createShopperClient({ serverKey, shopperIp })`,
|
|
25
|
+
* or `createStorefrontClient` with the server key plus `{ shopperIp }` here), so the rate limit is the shopper's, never one bucket
|
|
26
|
+
* for the whole shop behind the server. Without a shopper IP the API answers `400 SHOPPER_IP_REQUIRED`.
|
|
27
|
+
*
|
|
28
|
+
* The request never carries a session or a shopper token (nor cookies). The API answers `204` whatever the token is: show a fixed
|
|
29
|
+
* text, never a watch state ("If a mail is already on its way you may still receive one."). A refusal comes back as `ok: false`.
|
|
30
|
+
*/
|
|
31
|
+
export async function cancelWatchByToken(client, token, scope, options = {}) {
|
|
32
|
+
const r = await client.POST("/v1/watches/cancel", {
|
|
33
|
+
body: { token, scope }, credentials: "omit", middleware: [cancelHeaders(options.shopperIp ?? null)],
|
|
34
|
+
});
|
|
35
|
+
return r.response.ok ? { ok: true, data: undefined } : accountResult({ ...r, data: undefined });
|
|
36
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asstio-dev/storefront",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.48.0",
|
|
4
4
|
"description": "Typed client for the Asstio Storefront API (generated from OpenAPI).",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,6 +27,18 @@
|
|
|
27
27
|
"types": "./dist/account/next.d.ts",
|
|
28
28
|
"default": "./dist/account/next.js"
|
|
29
29
|
},
|
|
30
|
+
"./consent": {
|
|
31
|
+
"types": "./dist/consent/index.d.ts",
|
|
32
|
+
"default": "./dist/consent/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./consent/server": {
|
|
35
|
+
"types": "./dist/consent/server.d.ts",
|
|
36
|
+
"default": "./dist/consent/server.js"
|
|
37
|
+
},
|
|
38
|
+
"./shopper": {
|
|
39
|
+
"types": "./dist/shopper/index.d.ts",
|
|
40
|
+
"default": "./dist/shopper/index.js"
|
|
41
|
+
},
|
|
30
42
|
"./package.json": "./package.json"
|
|
31
43
|
},
|
|
32
44
|
"files": [
|
|
@@ -40,8 +52,10 @@
|
|
|
40
52
|
"test": "vitest run",
|
|
41
53
|
"test:browser": "playwright test -c browser/playwright.config.ts",
|
|
42
54
|
"check": "npm run generate && npm run typecheck-examples && npm test && git diff --exit-code -- src/schema.d.ts && test -z \"$(git status --porcelain -- src/schema.d.ts)\"",
|
|
43
|
-
"smoke": "node --input-type=module -e \"import(\\\"./dist/index.js\\\").then(m => { for (const f of [\\\"createStorefrontClient\\\", \\\"filterQuery\\\", \\\"encodeFilterValues\\\", \\\"decodeFilterValues\\\", \\\"pictureSources\\\", \\\"mediaUrl\\\", \\\"formatImage\\\", \\\"styleToCss\\\", \\\"startCheckout\\\", \\\"syncCheckout\\\", \\\"completeCheckout\\\", \\\"getCheckoutStatus\\\", \\\"liveShippingFor\\\", \\\"getOrder\\\", \\\"awaitCompletion\\\", \\\"mountCheckout\\\", \\\"productJsonLd\\\", \\\"gtinJsonLd\\\", \\\"breadcrumbJsonLd\\\", \\\"productHead\\\", \\\"collectionHead\\\", \\\"brandHead\\\", \\\"toNextMetadata\\\", \\\"sitemapEntries\\\", \\\"toNextSitemap\\\", \\\"jsonLdScript\\\", \\\"SeoError\\\", \\\"productFacts\\\", \\\"toGa4Item\\\", \\\"toGa4Ecommerce\\\", \\\"longestCategory\\\", \\\"AnalyticsError\\\", \\\"trackSearchEvents\\\", \\\"variantUrl\\\", \\\"readVariantParam\\\", \\\"variantQueryForApi\\\", \\\"redirectTarget\\\", \\\"displayPrice\\\", \\\"isPriceVisible\\\", \\\"isBuyable\\\", \\\"requireBinding\\\", \\\"hreflangFor\\\", \\\"isCheckoutContextMismatch\\\"]) if (typeof m[f] !== \\\"function\\\") throw new Error(\\\"missing export \\\" + f) })\" && npm run smoke:account",
|
|
44
|
-
"smoke:
|
|
55
|
+
"smoke": "node --input-type=module -e \"import(\\\"./dist/index.js\\\").then(m => { for (const f of [\\\"createStorefrontClient\\\", \\\"filterQuery\\\", \\\"encodeFilterValues\\\", \\\"decodeFilterValues\\\", \\\"pictureSources\\\", \\\"mediaUrl\\\", \\\"formatImage\\\", \\\"styleToCss\\\", \\\"startCheckout\\\", \\\"syncCheckout\\\", \\\"completeCheckout\\\", \\\"getCheckoutStatus\\\", \\\"liveShippingFor\\\", \\\"getOrder\\\", \\\"awaitCompletion\\\", \\\"mountCheckout\\\", \\\"productJsonLd\\\", \\\"gtinJsonLd\\\", \\\"breadcrumbJsonLd\\\", \\\"productHead\\\", \\\"collectionHead\\\", \\\"brandHead\\\", \\\"toNextMetadata\\\", \\\"sitemapEntries\\\", \\\"toNextSitemap\\\", \\\"jsonLdScript\\\", \\\"SeoError\\\", \\\"productFacts\\\", \\\"toGa4Item\\\", \\\"toGa4Ecommerce\\\", \\\"longestCategory\\\", \\\"AnalyticsError\\\", \\\"trackSearchEvents\\\", \\\"variantUrl\\\", \\\"readVariantParam\\\", \\\"variantQueryForApi\\\", \\\"redirectTarget\\\", \\\"displayPrice\\\", \\\"isPriceVisible\\\", \\\"isBuyable\\\", \\\"requireBinding\\\", \\\"hreflangFor\\\", \\\"isCheckoutContextMismatch\\\", \\\"consentNotice\\\"]) if (typeof m[f] !== \\\"function\\\") throw new Error(\\\"missing export \\\" + f) })\" && npm run smoke:account && npm run smoke:consent && npm run smoke:shopper",
|
|
56
|
+
"smoke:consent": "node --input-type=module -e \"const checks = { \\\"./dist/consent/index.js\\\": [\\\"parseConsent\\\", \\\"parseRefusal\\\", \\\"serializeConsent\\\", \\\"serializeRefusal\\\", \\\"ConsentCookieTooLarge\\\", \\\"withEntry\\\", \\\"withoutEntries\\\", \\\"grantedFor\\\", \\\"fold\\\", \\\"refusalBlocks\\\", \\\"refusalMark\\\", \\\"isFallback\\\", \\\"consentCookieNames\\\", \\\"consentNotice\\\", \\\"createConsentCoordinator\\\"], \\\"./dist/consent/server.js\\\": [\\\"readConsentCookie\\\", \\\"consentOwner\\\", \\\"tokenOwner\\\", \\\"accountOwner\\\"] }; for (const [file, names] of Object.entries(checks)) { const m = await import(file); for (const f of names) if (typeof m[f] !== \\\"function\\\") throw new Error(\\\"missing export \\\" + f + \\\" in \\\" + file); } const c = await import(\\\"./dist/consent/index.js\\\"); for (const n of [\\\"MAX_UNSYNCED\\\", \\\"PENDING_TTL_MS\\\", \\\"PUT_TIMEOUT_MS\\\"]) if (typeof c[n] !== \\\"number\\\") throw new Error(\\\"missing constant \\\" + n);\"",
|
|
57
|
+
"smoke:shopper": "node --input-type=module -e \"import(\\\"./dist/shopper/index.js\\\").then(m => { if (typeof m.cancelWatchByToken !== \\\"function\\\") throw new Error(\\\"missing export cancelWatchByToken\\\") })\"",
|
|
58
|
+
"smoke:account": "node --input-type=module -e \"const checks = { \\\"./dist/account/index.js\\\": [\\\"createShopperClient\\\", \\\"startSignIn\\\", \\\"verifySignIn\\\", \\\"signOut\\\", \\\"switchPrincipal\\\", \\\"getSession\\\", \\\"getMe\\\", \\\"getMyCompany\\\", \\\"linkChallengeId\\\", \\\"linkToken\\\", \\\"sessionCookie\\\", \\\"signInCookie\\\", \\\"cartCookie\\\", \\\"browserCartCookie\\\", \\\"copyBrowserCart\\\", \\\"CopyBrowserCartError\\\", \\\"cookieSecurity\\\", \\\"readSignInCookie\\\", \\\"serializeCookie\\\", \\\"shopperCookie\\\", \\\"accountResult\\\", \\\"shopperIpFrom\\\", \\\"assertSameOrigin\\\", \\\"safeReturnPath\\\", \\\"CrossOriginError\\\"], \\\"./dist/account/browser.js\\\": [\\\"readLinkFragment\\\", \\\"withShopperLock\\\"], \\\"./dist/account/next.js\\\": [\\\"startSignInAction\\\", \\\"verifySignInAction\\\", \\\"signOutAction\\\", \\\"switchPrincipalAction\\\", \\\"shopperClient\\\", \\\"copyBrowserCartAction\\\", \\\"shopperActions\\\"] }; for (const [file, names] of Object.entries(checks)) { const m = await import(file); for (const f of names) if (typeof m[f] !== \\\"function\\\") throw new Error(\\\"missing export \\\" + f + \\\" in \\\" + file); }\""
|
|
45
59
|
},
|
|
46
60
|
"dependencies": {
|
|
47
61
|
"openapi-fetch": "0.17.0"
|