@zappie/sdk 0.6.0 → 0.7.1
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 +22 -0
- package/dist/debug.js +1 -1
- package/dist/index.js +1 -1
- package/dist/server/index.d.ts +15 -1
- package/dist/server/index.js +2 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/sign-in.js +18 -0
- package/dist/server/sign-in.js.map +6 -0
- package/dist/vite/index.d.ts +19 -1
- package/dist/vite/index.js +51 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @zappie/sdk
|
|
2
2
|
|
|
3
|
+
## 0.7.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- f338b08: `@zappie/sdk/vite` adds `zappieHoistImports()`, a build plugin that makes each route's file import every chunk the route needs, so the browser requests them together on a client-side navigation. React Router loads a route by importing its file and nothing else. A chunk that the route reaches only through another chunk was requested only after that one downloaded, one round trip per level. Rollup lists these chunks in the route's own file, and Rolldown, which Vite 8 uses, does not yet. Add it after `reactRouter()`: `plugins: [reactRouter(), zappieHoistImports()]`. It runs only on the client build and keeps the order modules run in.
|
|
8
|
+
|
|
9
|
+
Since 0.6.0, a cart route that imports `@zappie/sdk/checkout` loaded three files one after another: the route, the checkout client and the request helpers it shares with the customer client. On a throttled phone connection the plugin takes that navigation from about 745 ms back to about 600 ms.
|
|
10
|
+
|
|
11
|
+
The starter's `vite.config.ts` adds the plugin.
|
|
12
|
+
|
|
13
|
+
## 0.7.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- 97d7e6a: A shopper who reaches `/sign-in` from a link or `navigate()` now gets Zappie's sign-in page. Before, React Router followed the loader's `redirect("/_zappie/login?…")` inside the app, which has no route for it, so the site showed its not-found page.
|
|
18
|
+
|
|
19
|
+
`@zappie/sdk/server` adds `signInRedirect(returnTo, init?)`. Return it from your `/sign-in` loader: `return signInRedirect(request)`. It reads the request's `return` query parameter, keeps it only when it is a path on this site and falls back to `/`. The response is a 302 to `/_zappie/login?return=<path>` with the header React Router's `redirectDocument` sets, so a client-side navigation loads the page in full. You can pass a path in place of the request, and `init` for extra headers or another status.
|
|
20
|
+
|
|
21
|
+
`eslint-plugin-zappie` adds `platform-routes-full-load`, an error in the recommended config, so `zappie check` reports it. It reports a React Router `redirect` or `replace` to a `/_zappie/` path, `navigate()` or `<Navigate>` to one, and a `<Link>`, `<NavLink>` or `<Form>` that targets one without `reloadDocument`.
|
|
22
|
+
|
|
23
|
+
The starter's `/sign-in` route returns `signInRedirect(request)`, and its `app/safe-return.ts` is gone.
|
|
24
|
+
|
|
3
25
|
## 0.6.0
|
|
4
26
|
|
|
5
27
|
### Minor Changes
|
package/dist/debug.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import { ZappieError, isZappieError } from "./errors.js";
|
|
|
10
10
|
export * from "./models.js";
|
|
11
11
|
import { format, money } from "./money.js";
|
|
12
12
|
import { RestTransport } from "./transport/rest.js";
|
|
13
|
-
var VERSION = true ? "0.
|
|
13
|
+
var VERSION = true ? "0.7.1" : "0.0.0-development";
|
|
14
14
|
export {
|
|
15
15
|
API_VERSION,
|
|
16
16
|
RestTransport,
|
package/dist/server/index.d.ts
CHANGED
|
@@ -588,6 +588,20 @@ declare function inlineScriptHashes(html: string): Promise<string[]>;
|
|
|
588
588
|
/** Build the report-only security headers for a storefront document response. */
|
|
589
589
|
declare function securityHeaders(options?: SecurityHeadersOptions): Headers;
|
|
590
590
|
|
|
591
|
+
/**
|
|
592
|
+
* Send the shopper to Zappie's sign-in page from a route loader or action.
|
|
593
|
+
*
|
|
594
|
+
* The response tells React Router to load the page in full, the way `redirectDocument` does.
|
|
595
|
+
* Zappie hosting serves `/_zappie/login`, so a plain `redirect` followed inside the app would
|
|
596
|
+
* render your not-found page. Other frameworks read it as an ordinary 302.
|
|
597
|
+
*
|
|
598
|
+
* @param returnTo - The request, whose `return` query parameter is read, or the path to come back
|
|
599
|
+
* to. A path that leaves the site, or a missing one, returns the shopper to `/`.
|
|
600
|
+
* @param init - Extra response settings, such as a `Set-Cookie` header. The status defaults to 302.
|
|
601
|
+
* @returns A redirect to `/_zappie/login?return=<path>`.
|
|
602
|
+
*/
|
|
603
|
+
declare function signInRedirect(returnTo: Request | URL | string | null | undefined, init?: ResponseInit): Response;
|
|
604
|
+
|
|
591
605
|
/** Event names sent by the Zappie webhook API. */
|
|
592
606
|
type WebhookEventType = "menu.updated" | "branch.hours_changed" | "store.updated" | "checkout.session.completed" | "checkout.session.expired" | "order.created" | "order.paid" | "order.status_changed" | "customer.signed_in" | "payout.initiated" | "payout.paid" | "payout.failed" | "payout_request.created" | "payout_request.approved" | "payout_request.rejected" | "payment.received";
|
|
593
607
|
/** The event envelope sent in a Zappie webhook request. */
|
|
@@ -663,5 +677,5 @@ declare function createZappieServer({ secretKey, ...config }: ZappieServerConfig
|
|
|
663
677
|
};
|
|
664
678
|
}>;
|
|
665
679
|
|
|
666
|
-
export { STOREFRONT_QUERY_PARAMETERS, STOREFRONT_V1_QUERY_PARAMETERS, ZappieTokenError, ZappieWebhookSignatureError, applyAvailability, buildStorefrontUrl, canonicalJson, cookieSessionStore, createAvailabilityPatch, createMenuSnapshot, createPkce, createSecurityNonce, createStoreSnapshot, createTokenVerifier, createZappieServer, inlineScriptHashes, isMenuSnapshot, menuSnapshotFromPayload, openSealedValue, parseStorefrontUrl, randomToken, sealValue, securityHeaders, snapshotHash, snapshotKeys, storefrontRedirect, verifyWebhook };
|
|
680
|
+
export { STOREFRONT_QUERY_PARAMETERS, STOREFRONT_V1_QUERY_PARAMETERS, ZappieTokenError, ZappieWebhookSignatureError, applyAvailability, buildStorefrontUrl, canonicalJson, cookieSessionStore, createAvailabilityPatch, createMenuSnapshot, createPkce, createSecurityNonce, createStoreSnapshot, createTokenVerifier, createZappieServer, inlineScriptHashes, isMenuSnapshot, menuSnapshotFromPayload, openSealedValue, parseStorefrontUrl, randomToken, sealValue, securityHeaders, signInRedirect, snapshotHash, snapshotKeys, storefrontRedirect, verifyWebhook };
|
|
667
681
|
export type { AvailabilityPatch, AvailabilityPatchInput, CookieSessionStoreOptions, EdgeSnapshotReader, IdTokenChecks, IdTokenClaims, MenuSnapshot, MenuSnapshotInput, MenuSnapshotPayloadInput, PkcePair, SealOptions, SealSecret, SecurityHeadersOptions, SessionData, SessionStore, SnapshotVersionRecord, StoreSnapshot, StorefrontInstallation, StorefrontPageState, StorefrontQuery, StorefrontRoute, StorefrontUrlInput, StorefrontUrlOptions, TokenAlgorithm, TokenClaims, TokenErrorReason, TokenVerifier, TokenVerifierOptions, VerifyTokenChecks, VerifyWebhookOptions, WebhookEvent, WebhookEventType, ZappieServerConfig };
|
package/dist/server/index.js
CHANGED
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
inlineScriptHashes,
|
|
38
38
|
securityHeaders
|
|
39
39
|
} from "./security.js";
|
|
40
|
+
import { signInRedirect } from "./sign-in.js";
|
|
40
41
|
import {
|
|
41
42
|
verifyWebhook,
|
|
42
43
|
ZappieWebhookSignatureError
|
|
@@ -72,6 +73,7 @@ export {
|
|
|
72
73
|
randomToken,
|
|
73
74
|
sealValue,
|
|
74
75
|
securityHeaders,
|
|
76
|
+
signInRedirect,
|
|
75
77
|
snapshotHash,
|
|
76
78
|
snapshotKeys,
|
|
77
79
|
storefrontRedirect,
|
package/dist/server/index.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/server/index.ts"],
|
|
4
|
-
"mappings": ";AAAA,SAAS,mBAAmB;AAG5B,SAAS,eAAe;AACxB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAOK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OASK;AACP;AAAA,EACE;AAAA,OAIK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAQK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AAUA,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA,GAAG;AACL,GAAuB;AACrB,SAAO,YAAY,EAAE,GAAG,QAAQ,KAAK,UAAU,GAAG,IAAI;AACxD;",
|
|
4
|
+
"mappings": ";AAAA,SAAS,mBAAmB;AAG5B,SAAS,eAAe;AACxB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAOK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OASK;AACP;AAAA,EACE;AAAA,OAIK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAQK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AAUA,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA,GAAG;AACL,GAAuB;AACrB,SAAO,YAAY,EAAE,GAAG,QAAQ,KAAK,UAAU,GAAG,IAAI;AACxD;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/server/sign-in.ts
|
|
2
|
+
import { sameOriginPath } from "../internal/return-path.js";
|
|
3
|
+
function signInRedirect(returnTo, init = {}) {
|
|
4
|
+
const path = typeof returnTo === "object" && returnTo !== null ? new URL(
|
|
5
|
+
returnTo instanceof URL ? returnTo : returnTo.url
|
|
6
|
+
).searchParams.get("return") : returnTo;
|
|
7
|
+
const headers = new Headers(init.headers);
|
|
8
|
+
headers.set(
|
|
9
|
+
"Location",
|
|
10
|
+
`/_zappie/login?return=${encodeURIComponent(sameOriginPath(path) ?? "/")}`
|
|
11
|
+
);
|
|
12
|
+
headers.set("X-Remix-Reload-Document", "true");
|
|
13
|
+
return new Response(null, { ...init, status: init.status ?? 302, headers });
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
signInRedirect
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=sign-in.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/server/sign-in.ts"],
|
|
4
|
+
"mappings": ";AAAA,SAAS,sBAAsB;AAcxB,SAAS,eACd,UACA,OAAqB,CAAC,GACZ;AACV,QAAM,OACJ,OAAO,aAAa,YAAY,aAAa,OACzC,IAAI;AAAA,IACF,oBAAoB,MAAM,WAAW,SAAS;AAAA,EAChD,EAAE,aAAa,IAAI,QAAQ,IAC3B;AACN,QAAM,UAAU,IAAI,QAAQ,KAAK,OAAO;AACxC,UAAQ;AAAA,IACN;AAAA,IACA,yBAAyB,mBAAmB,eAAe,IAAI,KAAK,GAAG,CAAC;AAAA,EAC1E;AAEA,UAAQ,IAAI,2BAA2B,MAAM;AAC7C,SAAO,IAAI,SAAS,MAAM,EAAE,GAAG,MAAM,QAAQ,KAAK,UAAU,KAAK,QAAQ,CAAC;AAC5E;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
package/dist/vite/index.d.ts
CHANGED
|
@@ -37,6 +37,24 @@ type MarkedSource = {
|
|
|
37
37
|
declare function zappieSource({ previewHost }: ZappieSourceOptions): Plugin;
|
|
38
38
|
/** Add source and component attributes to the intrinsic elements of one saved `.tsx` or `.jsx` file. */
|
|
39
39
|
declare function markSource(code: string, file: string): MarkedSource | null;
|
|
40
|
+
/**
|
|
41
|
+
* Make each page's code file name every chunk it needs, so the browser requests them together. React Router loads a
|
|
42
|
+
* route by importing its file and nothing else. A chunk that the route's chunk imports only through another chunk is
|
|
43
|
+
* found only after that one downloads, so each extra level costs a round trip on a client-side navigation. Rollup lists
|
|
44
|
+
* these chunks in the entry's own file (`hoistTransitiveImports`), and Rolldown, which Vite 8 uses, does not yet. The
|
|
45
|
+
* plugin adds them as plain imports after the file's own, so modules still run in the same order. It runs only on the
|
|
46
|
+
* client build.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { zappieHoistImports } from "@zappie/sdk/vite";
|
|
51
|
+
*
|
|
52
|
+
* export default defineConfig({
|
|
53
|
+
* plugins: [reactRouter(), zappieHoistImports()],
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare function zappieHoistImports(): Plugin;
|
|
40
58
|
|
|
41
|
-
export { COMPONENT_ATTRIBUTE, SOURCE_ATTRIBUTE, markSource, zappieSource };
|
|
59
|
+
export { COMPONENT_ATTRIBUTE, SOURCE_ATTRIBUTE, markSource, zappieHoistImports, zappieSource };
|
|
42
60
|
export type { MarkedSource, ZappieSourceOptions };
|
package/dist/vite/index.js
CHANGED
|
@@ -146,9 +146,60 @@ function componentName(node) {
|
|
|
146
146
|
}
|
|
147
147
|
return void 0;
|
|
148
148
|
}
|
|
149
|
+
function zappieHoistImports() {
|
|
150
|
+
return {
|
|
151
|
+
name: "zappie-hoist-imports",
|
|
152
|
+
apply: "build",
|
|
153
|
+
applyToEnvironment: (environment) => environment.config.consumer === "client",
|
|
154
|
+
generateBundle(_options, bundle) {
|
|
155
|
+
const importsOf = (fileName) => {
|
|
156
|
+
const chunk = bundle[fileName];
|
|
157
|
+
return chunk?.type === "chunk" ? chunk.imports : [];
|
|
158
|
+
};
|
|
159
|
+
for (const chunk of Object.values(bundle)) {
|
|
160
|
+
if (chunk.type !== "chunk" || !chunk.isEntry) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
const listed = /* @__PURE__ */ new Set([chunk.fileName, ...chunk.imports]);
|
|
164
|
+
const hoisted = [];
|
|
165
|
+
const pending = [...chunk.imports];
|
|
166
|
+
for (let index = 0; index < pending.length; index++) {
|
|
167
|
+
for (const next of importsOf(pending[index])) {
|
|
168
|
+
if (!listed.has(next)) {
|
|
169
|
+
listed.add(next);
|
|
170
|
+
hoisted.push(next);
|
|
171
|
+
pending.push(next);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (hoisted.length === 0) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const from = chunk.fileName.split("/").slice(0, -1);
|
|
179
|
+
chunk.code += `
|
|
180
|
+
${hoisted.map(
|
|
181
|
+
(file) => `import ${JSON.stringify(relativeImport(from, file))};`
|
|
182
|
+
).join("")}
|
|
183
|
+
`;
|
|
184
|
+
chunk.imports.push(...hoisted);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function relativeImport(from, file) {
|
|
190
|
+
const to = file.split("/");
|
|
191
|
+
let shared = 0;
|
|
192
|
+
while (shared < from.length && shared < to.length - 1 && from[shared] === to[shared]) {
|
|
193
|
+
shared++;
|
|
194
|
+
}
|
|
195
|
+
const up = from.length - shared;
|
|
196
|
+
const rest = to.slice(shared).join("/");
|
|
197
|
+
return up === 0 ? `./${rest}` : `${"../".repeat(up)}${rest}`;
|
|
198
|
+
}
|
|
149
199
|
export {
|
|
150
200
|
COMPONENT_ATTRIBUTE,
|
|
151
201
|
SOURCE_ATTRIBUTE,
|
|
152
202
|
markSource,
|
|
203
|
+
zappieHoistImports,
|
|
153
204
|
zappieSource
|
|
154
205
|
};
|