@swell/apps-sdk 2.0.0-alpha.5 → 2.0.0-alpha.7
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 +129 -0
- package/dist/component-frame.html +13 -0
- package/dist/components-client.d.cts +85 -0
- package/dist/components-client.d.ts +85 -0
- package/dist/components-client.js +196 -0
- package/dist/components-focus.d.cts +2 -0
- package/dist/components-focus.d.ts +2 -0
- package/dist/components-focus.js +68 -0
- package/dist/components-frame.d.cts +18 -0
- package/dist/components-frame.d.ts +18 -0
- package/dist/components-frame.js +251 -0
- package/dist/components-host.d.cts +60 -0
- package/dist/components-host.d.ts +60 -0
- package/dist/components-host.js +315 -0
- package/dist/components-payment.d.cts +11 -0
- package/dist/components-payment.d.ts +11 -0
- package/dist/components-payment.js +52 -0
- package/dist/components-placement.d.cts +18 -0
- package/dist/components-placement.d.ts +18 -0
- package/dist/components-placement.js +131 -0
- package/dist/components-protocol.d.cts +89 -0
- package/dist/components-protocol.d.ts +89 -0
- package/dist/components-protocol.js +20 -0
- package/dist/components-types.d.cts +84 -0
- package/dist/components-types.d.ts +84 -0
- package/dist/components-types.js +1 -0
- package/dist/components.d.cts +6 -0
- package/dist/components.d.ts +6 -0
- package/dist/components.js +2 -0
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/request-context.d.cts +4 -0
- package/dist/request-context.d.ts +4 -0
- package/dist/request-context.js +4 -0
- package/dist/version.d.cts +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +11 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { HeaderReader } from './context.cjs';
|
|
2
2
|
import type { StoreUser } from './store-user.cjs';
|
|
3
|
+
/** Where an app component made the request from. */
|
|
4
|
+
export type SwellSurface = 'admin' | 'checkout' | 'storefront';
|
|
3
5
|
export interface SwellHeadersEnv {
|
|
4
6
|
SWELL_VERIFY_HEADERS?: string;
|
|
5
7
|
SWELL_HEADERS_JWKS_URL?: string;
|
|
@@ -20,6 +22,8 @@ export interface SwellRequestContext {
|
|
|
20
22
|
readonly installationId: string;
|
|
21
23
|
readonly environmentId?: string;
|
|
22
24
|
readonly storefrontId?: string;
|
|
25
|
+
/** Set when an app component made the request. */
|
|
26
|
+
readonly surface?: SwellSurface;
|
|
23
27
|
readonly apiHost: string;
|
|
24
28
|
readonly adminUrl: string;
|
|
25
29
|
readonly accessToken?: string;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { HeaderReader } from './context.js';
|
|
2
2
|
import type { StoreUser } from './store-user.js';
|
|
3
|
+
/** Where an app component made the request from. */
|
|
4
|
+
export type SwellSurface = 'admin' | 'checkout' | 'storefront';
|
|
3
5
|
export interface SwellHeadersEnv {
|
|
4
6
|
SWELL_VERIFY_HEADERS?: string;
|
|
5
7
|
SWELL_HEADERS_JWKS_URL?: string;
|
|
@@ -20,6 +22,8 @@ export interface SwellRequestContext {
|
|
|
20
22
|
readonly installationId: string;
|
|
21
23
|
readonly environmentId?: string;
|
|
22
24
|
readonly storefrontId?: string;
|
|
25
|
+
/** Set when an app component made the request. */
|
|
26
|
+
readonly surface?: SwellSurface;
|
|
23
27
|
readonly apiHost: string;
|
|
24
28
|
readonly adminUrl: string;
|
|
25
29
|
readonly accessToken?: string;
|
package/dist/request-context.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { requireString, validateUrl } from './context.js';
|
|
2
2
|
import { SwellError } from './error.js';
|
|
3
3
|
import { getVerificationKey } from './jwks.js';
|
|
4
|
+
const SURFACES = ['admin', 'checkout', 'storefront'];
|
|
4
5
|
function invalidContext() {
|
|
5
6
|
return new SwellError('Missing or invalid Swell context', { status: 401, code: 'invalid_swell_context' });
|
|
6
7
|
}
|
|
@@ -71,6 +72,8 @@ export async function verifySwellContext(headers, options = {}) {
|
|
|
71
72
|
if (payload[field] != null)
|
|
72
73
|
requireString(payload[field], field);
|
|
73
74
|
}
|
|
75
|
+
if (payload.surface != null && !SURFACES.includes(payload.surface))
|
|
76
|
+
throw invalidContext();
|
|
74
77
|
let storeUser = null;
|
|
75
78
|
if (payload.admin !== null) {
|
|
76
79
|
object(payload.admin);
|
|
@@ -82,6 +85,7 @@ export async function verifySwellContext(headers, options = {}) {
|
|
|
82
85
|
installationId: payload.installation_id,
|
|
83
86
|
environmentId: payload.environment_id ?? undefined,
|
|
84
87
|
storefrontId: payload.storefront_id ?? undefined,
|
|
88
|
+
surface: payload.surface ?? undefined,
|
|
85
89
|
apiHost: validateUrl(payload.api_host, 'api_host'), adminUrl: validateUrl(payload.admin_url, 'admin_url'),
|
|
86
90
|
accessToken: headers.get('Swell-Access-Token') ?? undefined,
|
|
87
91
|
publicKey: headers.get('Swell-Public-Key') ?? undefined,
|
package/dist/version.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const USER_AGENT = "swell-apps-sdk/2.0.0-alpha.
|
|
1
|
+
export declare const USER_AGENT = "swell-apps-sdk/2.0.0-alpha.7";
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const USER_AGENT = "swell-apps-sdk/2.0.0-alpha.
|
|
1
|
+
export declare const USER_AGENT = "swell-apps-sdk/2.0.0-alpha.7";
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Replaced with the package version by the build.
|
|
2
|
-
export const USER_AGENT = 'swell-apps-sdk/2.0.0-alpha.
|
|
2
|
+
export const USER_AGENT = 'swell-apps-sdk/2.0.0-alpha.7';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swell/apps-sdk",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.7",
|
|
4
4
|
"description": "Server SDK for Swell apps.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"test:package": "node scripts/verify-package.mjs",
|
|
19
19
|
"test:boundaries": "node scripts/verify-boundaries.mjs",
|
|
20
20
|
"test:worker": "node scripts/verify-worker.mjs",
|
|
21
|
+
"test:browser": "npm run build && node scripts/verify-components-browser.mjs",
|
|
21
22
|
"verify": "npm test && npm run typecheck && npm run test:package && npm run test:boundaries && npm run test:worker"
|
|
22
23
|
},
|
|
23
24
|
"peerDependencies": {
|
|
@@ -25,7 +26,9 @@
|
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
28
|
"esbuild": "0.24.2",
|
|
29
|
+
"happy-dom": "20.14.5",
|
|
28
30
|
"miniflare": "5.20260911.1-alpha",
|
|
31
|
+
"playwright": "1.63.0",
|
|
29
32
|
"swell-js": "5.9.2",
|
|
30
33
|
"typescript": "5.7.3"
|
|
31
34
|
},
|
|
@@ -51,6 +54,13 @@
|
|
|
51
54
|
"node": "./dist/storefront.js",
|
|
52
55
|
"browser": "./dist/browser-refusal.js",
|
|
53
56
|
"default": "./dist/storefront.js"
|
|
57
|
+
},
|
|
58
|
+
"./components": {
|
|
59
|
+
"types": {
|
|
60
|
+
"import": "./dist/components.d.ts",
|
|
61
|
+
"require": "./dist/components.d.cts"
|
|
62
|
+
},
|
|
63
|
+
"default": "./dist/components.js"
|
|
54
64
|
}
|
|
55
65
|
},
|
|
56
66
|
"sideEffects": [
|