@swell/apps-sdk 1.0.189 → 2.0.0-alpha.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 +146 -247
- package/dist/backend.d.cts +81 -0
- package/dist/backend.d.ts +81 -0
- package/dist/backend.js +152 -0
- package/dist/browser-refusal.d.cts +1 -0
- package/dist/browser-refusal.d.ts +1 -0
- package/dist/browser-refusal.js +2 -0
- package/dist/context.d.cts +21 -0
- package/dist/context.d.ts +21 -0
- package/dist/context.js +42 -0
- package/dist/error.d.cts +23 -0
- package/dist/error.d.ts +23 -0
- package/dist/error.js +30 -0
- package/dist/guard.d.cts +1 -0
- package/dist/guard.d.ts +1 -0
- package/dist/guard.js +4 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +5 -20298
- package/dist/staff.d.cts +16 -0
- package/dist/staff.d.ts +16 -0
- package/dist/staff.js +33 -0
- package/dist/storefront.d.cts +28 -0
- package/dist/storefront.d.ts +28 -0
- package/dist/storefront.js +44 -0
- package/dist/version.d.cts +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +2 -0
- package/dist/workflow.d.cts +1 -0
- package/dist/workflow.d.ts +1 -0
- package/dist/workflow.js +35 -0
- package/package.json +48 -63
- package/dist/index.cjs +0 -20546
- package/dist/index.cjs.map +0 -7
- package/dist/index.js.map +0 -7
- package/dist/index.mjs +0 -20403
- package/dist/index.mjs.map +0 -7
- package/dist/src/api.d.ts +0 -96
- package/dist/src/cache/cache.d.ts +0 -41
- package/dist/src/cache/cf-worker-kv-keyv-adapter.d.ts +0 -18
- package/dist/src/cache/constants.d.ts +0 -7
- package/dist/src/cache/content-cache.d.ts +0 -21
- package/dist/src/cache/html-cache/html-cache-backend.d.ts +0 -64
- package/dist/src/cache/html-cache/html-cache-factory.d.ts +0 -9
- package/dist/src/cache/html-cache/html-cache-kv.d.ts +0 -38
- package/dist/src/cache/html-cache/html-cache-worker.d.ts +0 -8
- package/dist/src/cache/html-cache/html-cache.d.ts +0 -120
- package/dist/src/cache/html-cache/index.d.ts +0 -4
- package/dist/src/cache/index.d.ts +0 -9
- package/dist/src/cache/kv-variety.d.ts +0 -10
- package/dist/src/cache/request-cache.d.ts +0 -4
- package/dist/src/cache/resource-cache.d.ts +0 -4
- package/dist/src/cache/theme-cache.d.ts +0 -4
- package/dist/src/cache/theme-file-cache.d.ts +0 -87
- package/dist/src/compatibility/drops/all_products.d.ts +0 -10
- package/dist/src/compatibility/drops/articles.d.ts +0 -10
- package/dist/src/compatibility/drops/blogs.d.ts +0 -10
- package/dist/src/compatibility/drops/collections.d.ts +0 -19
- package/dist/src/compatibility/drops/image-src.d.ts +0 -15
- package/dist/src/compatibility/drops/image.d.ts +0 -29
- package/dist/src/compatibility/drops/images.d.ts +0 -9
- package/dist/src/compatibility/drops/money.d.ts +0 -10
- package/dist/src/compatibility/drops/object-handles.d.ts +0 -6
- package/dist/src/compatibility/drops/pages.d.ts +0 -17
- package/dist/src/compatibility/drops/robots-rule.d.ts +0 -9
- package/dist/src/compatibility/drops/template.d.ts +0 -9
- package/dist/src/compatibility/shopify-configs.d.ts +0 -8
- package/dist/src/compatibility/shopify-fonts.d.ts +0 -1
- package/dist/src/compatibility/shopify-objects/address.d.ts +0 -7
- package/dist/src/compatibility/shopify-objects/article.d.ts +0 -7
- package/dist/src/compatibility/shopify-objects/blog.d.ts +0 -6
- package/dist/src/compatibility/shopify-objects/cart.d.ts +0 -6
- package/dist/src/compatibility/shopify-objects/collection.d.ts +0 -7
- package/dist/src/compatibility/shopify-objects/collections.d.ts +0 -6
- package/dist/src/compatibility/shopify-objects/content.d.ts +0 -12
- package/dist/src/compatibility/shopify-objects/currency.d.ts +0 -5
- package/dist/src/compatibility/shopify-objects/customer.d.ts +0 -6
- package/dist/src/compatibility/shopify-objects/filter.d.ts +0 -6
- package/dist/src/compatibility/shopify-objects/font.d.ts +0 -5
- package/dist/src/compatibility/shopify-objects/form.d.ts +0 -29
- package/dist/src/compatibility/shopify-objects/image.d.ts +0 -10
- package/dist/src/compatibility/shopify-objects/index.d.ts +0 -27
- package/dist/src/compatibility/shopify-objects/line_item.d.ts +0 -7
- package/dist/src/compatibility/shopify-objects/link.d.ts +0 -5
- package/dist/src/compatibility/shopify-objects/localization.d.ts +0 -5
- package/dist/src/compatibility/shopify-objects/media.d.ts +0 -9
- package/dist/src/compatibility/shopify-objects/money.d.ts +0 -3
- package/dist/src/compatibility/shopify-objects/order.d.ts +0 -11
- package/dist/src/compatibility/shopify-objects/page.d.ts +0 -5
- package/dist/src/compatibility/shopify-objects/paginate.d.ts +0 -5
- package/dist/src/compatibility/shopify-objects/predictive_search.d.ts +0 -5
- package/dist/src/compatibility/shopify-objects/product.d.ts +0 -9
- package/dist/src/compatibility/shopify-objects/recommendations.d.ts +0 -5
- package/dist/src/compatibility/shopify-objects/resource.d.ts +0 -27
- package/dist/src/compatibility/shopify-objects/search.d.ts +0 -5
- package/dist/src/compatibility/shopify-objects/shop.d.ts +0 -5
- package/dist/src/compatibility/shopify-objects/template.d.ts +0 -4
- package/dist/src/compatibility/shopify-objects/variant.d.ts +0 -6
- package/dist/src/compatibility/shopify.d.ts +0 -134
- package/dist/src/constants.d.ts +0 -598
- package/dist/src/content.d.ts +0 -8
- package/dist/src/easyblocks/config.d.ts +0 -152
- package/dist/src/easyblocks/index.d.ts +0 -2
- package/dist/src/easyblocks/utils.d.ts +0 -23
- package/dist/src/editor/resources.d.ts +0 -9
- package/dist/src/fonts.d.ts +0 -6
- package/dist/src/globals.d.ts +0 -7
- package/dist/src/index.d.ts +0 -16
- package/dist/src/liquid/color.d.ts +0 -33
- package/dist/src/liquid/drops/render.d.ts +0 -10
- package/dist/src/liquid/filters/asset_url.d.ts +0 -3
- package/dist/src/liquid/filters/brightness_difference.d.ts +0 -2
- package/dist/src/liquid/filters/color_brightness.d.ts +0 -2
- package/dist/src/liquid/filters/color_contrast.d.ts +0 -2
- package/dist/src/liquid/filters/color_darken.d.ts +0 -2
- package/dist/src/liquid/filters/color_desaturate.d.ts +0 -2
- package/dist/src/liquid/filters/color_difference.d.ts +0 -2
- package/dist/src/liquid/filters/color_extract.d.ts +0 -4
- package/dist/src/liquid/filters/color_lighten.d.ts +0 -2
- package/dist/src/liquid/filters/color_mix.d.ts +0 -2
- package/dist/src/liquid/filters/color_modify.d.ts +0 -3
- package/dist/src/liquid/filters/color_saturate.d.ts +0 -2
- package/dist/src/liquid/filters/color_to_hex.d.ts +0 -2
- package/dist/src/liquid/filters/color_to_hsl.d.ts +0 -2
- package/dist/src/liquid/filters/color_to_rgb.d.ts +0 -2
- package/dist/src/liquid/filters/date.d.ts +0 -7
- package/dist/src/liquid/filters/date_next_interval.d.ts +0 -3
- package/dist/src/liquid/filters/default_errors.d.ts +0 -3
- package/dist/src/liquid/filters/divided_by.d.ts +0 -2
- package/dist/src/liquid/filters/embedded_content.d.ts +0 -2
- package/dist/src/liquid/filters/escape.d.ts +0 -3
- package/dist/src/liquid/filters/font_face.d.ts +0 -2
- package/dist/src/liquid/filters/font_modify.d.ts +0 -3
- package/dist/src/liquid/filters/font_url.d.ts +0 -2
- package/dist/src/liquid/filters/format_address.d.ts +0 -6
- package/dist/src/liquid/filters/handleize.d.ts +0 -3
- package/dist/src/liquid/filters/image_tag.d.ts +0 -3
- package/dist/src/liquid/filters/image_url.d.ts +0 -8
- package/dist/src/liquid/filters/index.d.ts +0 -120
- package/dist/src/liquid/filters/inline_asset_content.d.ts +0 -2
- package/dist/src/liquid/filters/inline_editable.d.ts +0 -4
- package/dist/src/liquid/filters/json.d.ts +0 -3
- package/dist/src/liquid/filters/json_pretty.d.ts +0 -3
- package/dist/src/liquid/filters/locale_flag.d.ts +0 -2
- package/dist/src/liquid/filters/minus.d.ts +0 -2
- package/dist/src/liquid/filters/money.d.ts +0 -4
- package/dist/src/liquid/filters/money_with_currency.d.ts +0 -3
- package/dist/src/liquid/filters/money_without_currency.d.ts +0 -3
- package/dist/src/liquid/filters/money_without_trailing_zeros.d.ts +0 -3
- package/dist/src/liquid/filters/preload_tag.d.ts +0 -3
- package/dist/src/liquid/filters/script_tag.d.ts +0 -3
- package/dist/src/liquid/filters/shopify/asset_img_url.d.ts +0 -3
- package/dist/src/liquid/filters/shopify/default_pagination.d.ts +0 -3
- package/dist/src/liquid/filters/shopify/hex_to_rgba.d.ts +0 -2
- package/dist/src/liquid/filters/shopify/img_url.d.ts +0 -3
- package/dist/src/liquid/filters/shopify/item_count_for_variant.d.ts +0 -6
- package/dist/src/liquid/filters/shopify/payment_button.d.ts +0 -2
- package/dist/src/liquid/filters/shopify/payment_terms.d.ts +0 -2
- package/dist/src/liquid/filters/shopify/placeholder-svgs/index.d.ts +0 -5
- package/dist/src/liquid/filters/shopify/placeholder_svg_tag.d.ts +0 -3
- package/dist/src/liquid/filters/shopify/shopify_asset_url.d.ts +0 -3
- package/dist/src/liquid/filters/shopify/structured_data.d.ts +0 -3
- package/dist/src/liquid/filters/stylesheet_tag.d.ts +0 -3
- package/dist/src/liquid/filters/time_tag.d.ts +0 -2
- package/dist/src/liquid/filters/translate.d.ts +0 -3
- package/dist/src/liquid/filters/where.d.ts +0 -3
- package/dist/src/liquid/font.d.ts +0 -51
- package/dist/src/liquid/form.d.ts +0 -17
- package/dist/src/liquid/hash.d.ts +0 -5
- package/dist/src/liquid/index.d.ts +0 -52
- package/dist/src/liquid/operators.d.ts +0 -10
- package/dist/src/liquid/tags/assign.d.ts +0 -3
- package/dist/src/liquid/tags/case.d.ts +0 -3
- package/dist/src/liquid/tags/comment.d.ts +0 -3
- package/dist/src/liquid/tags/content_for.d.ts +0 -3
- package/dist/src/liquid/tags/doc.d.ts +0 -2
- package/dist/src/liquid/tags/for.d.ts +0 -3
- package/dist/src/liquid/tags/form.d.ts +0 -3
- package/dist/src/liquid/tags/if.d.ts +0 -4
- package/dist/src/liquid/tags/index.d.ts +0 -42
- package/dist/src/liquid/tags/inline_editable.d.ts +0 -3
- package/dist/src/liquid/tags/javascript.d.ts +0 -3
- package/dist/src/liquid/tags/layout.d.ts +0 -3
- package/dist/src/liquid/tags/paginate.d.ts +0 -3
- package/dist/src/liquid/tags/render.d.ts +0 -6
- package/dist/src/liquid/tags/section.d.ts +0 -3
- package/dist/src/liquid/tags/sections.d.ts +0 -3
- package/dist/src/liquid/tags/shopify/include.d.ts +0 -3
- package/dist/src/liquid/tags/shopify/schema.d.ts +0 -3
- package/dist/src/liquid/tags/style.d.ts +0 -3
- package/dist/src/liquid/tags/stylesheet.d.ts +0 -3
- package/dist/src/liquid/test-helpers.d.ts +0 -8
- package/dist/src/liquid/tokens/identifier-token.d.ts +0 -9
- package/dist/src/liquid/tokens/index.d.ts +0 -2
- package/dist/src/liquid/tokienizer.d.ts +0 -5
- package/dist/src/liquid/utils.d.ts +0 -45
- package/dist/src/menus.d.ts +0 -25
- package/dist/src/resources/account.d.ts +0 -6
- package/dist/src/resources/addresses.d.ts +0 -7
- package/dist/src/resources/blog.d.ts +0 -7
- package/dist/src/resources/blog_category.d.ts +0 -7
- package/dist/src/resources/cart.d.ts +0 -6
- package/dist/src/resources/categories.d.ts +0 -7
- package/dist/src/resources/category.d.ts +0 -7
- package/dist/src/resources/index.d.ts +0 -48
- package/dist/src/resources/order.d.ts +0 -7
- package/dist/src/resources/orders.d.ts +0 -7
- package/dist/src/resources/page.d.ts +0 -7
- package/dist/src/resources/predictive_search.d.ts +0 -6
- package/dist/src/resources/product.d.ts +0 -7
- package/dist/src/resources/product_helpers.d.ts +0 -21
- package/dist/src/resources/search.d.ts +0 -6
- package/dist/src/resources/subscription.d.ts +0 -7
- package/dist/src/resources/subscriptions.d.ts +0 -7
- package/dist/src/resources/swell_types.d.ts +0 -163
- package/dist/src/resources/variant.d.ts +0 -9
- package/dist/src/resources.d.ts +0 -113
- package/dist/src/theme/theme-loader.d.ts +0 -110
- package/dist/src/theme.d.ts +0 -204
- package/dist/src/utils/escape.d.ts +0 -1
- package/dist/src/utils/index.d.ts +0 -34
- package/dist/src/utils/kv-flavor.d.ts +0 -7
- package/dist/src/utils/logger.d.ts +0 -21
- package/dist/src/utils/md5.d.ts +0 -1
- package/dist/types/cloudflare.d.ts +0 -61
- package/dist/types/shopify.d.ts +0 -1035
- package/dist/types/swell.d.ts +0 -576
- package/types/index.d.ts +0 -4
- package/types/svg.d.ts +0 -4
package/dist/staff.d.cts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HeaderReader } from './context.cjs';
|
|
2
|
+
export interface StaffIdentity {
|
|
3
|
+
userId: string;
|
|
4
|
+
storeId: string;
|
|
5
|
+
}
|
|
6
|
+
export interface StaffOptions {
|
|
7
|
+
headers: HeaderReader;
|
|
8
|
+
method: string;
|
|
9
|
+
/** Trusted app/iframe origin, never an unchecked forwarded-host value. */
|
|
10
|
+
origin: string;
|
|
11
|
+
cookies: {
|
|
12
|
+
get(name: string): string | undefined;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/** Verifies store staff identity only. The application still owns authorization policy. */
|
|
16
|
+
export declare function requireStaff({ headers, method, origin, cookies }: StaffOptions): Promise<StaffIdentity>;
|
package/dist/staff.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HeaderReader } from './context.js';
|
|
2
|
+
export interface StaffIdentity {
|
|
3
|
+
userId: string;
|
|
4
|
+
storeId: string;
|
|
5
|
+
}
|
|
6
|
+
export interface StaffOptions {
|
|
7
|
+
headers: HeaderReader;
|
|
8
|
+
method: string;
|
|
9
|
+
/** Trusted app/iframe origin, never an unchecked forwarded-host value. */
|
|
10
|
+
origin: string;
|
|
11
|
+
cookies: {
|
|
12
|
+
get(name: string): string | undefined;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/** Verifies store staff identity only. The application still owns authorization policy. */
|
|
16
|
+
export declare function requireStaff({ headers, method, origin, cookies }: StaffOptions): Promise<StaffIdentity>;
|
package/dist/staff.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { parseSwellHeaders, requireString, validateUrl } from './context.js';
|
|
2
|
+
import { SwellError } from './error.js';
|
|
3
|
+
import { USER_AGENT } from './version.js';
|
|
4
|
+
/** Verifies store staff identity only. The application still owns authorization policy. */
|
|
5
|
+
export async function requireStaff({ headers, method, origin, cookies }) {
|
|
6
|
+
const { storeId, adminUrl } = parseSwellHeaders(headers);
|
|
7
|
+
requireString(storeId, 'storeId');
|
|
8
|
+
const url = validateUrl(adminUrl, 'adminUrl');
|
|
9
|
+
requireString(method, 'method');
|
|
10
|
+
if (method.toUpperCase() !== 'GET') {
|
|
11
|
+
const expected = validateUrl(origin, 'origin');
|
|
12
|
+
const supplied = headers.get('Origin');
|
|
13
|
+
if (new URL(expected).origin !== origin)
|
|
14
|
+
throw new Error('origin must be an absolute app origin');
|
|
15
|
+
if (supplied !== origin || (headers.get('Sec-Fetch-Site') !== null && headers.get('Sec-Fetch-Site') !== 'same-origin')) {
|
|
16
|
+
throw new SwellError('Staff request origin rejected', { status: 403 });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const sessionId = cookies.get('_swell_admin_session');
|
|
20
|
+
if (!sessionId)
|
|
21
|
+
throw new SwellError('Staff session required', { status: 401 });
|
|
22
|
+
const response = await fetch(new URL('/admin/api/session', url), {
|
|
23
|
+
headers: { 'X-Session': sessionId, 'User-Agent': USER_AGENT }, redirect: 'manual',
|
|
24
|
+
});
|
|
25
|
+
if (response.status === 401 || response.status === 403)
|
|
26
|
+
throw new SwellError('Invalid staff session', { status: 401 });
|
|
27
|
+
if (!response.ok)
|
|
28
|
+
throw new SwellError('Staff session verification failed', { status: response.status });
|
|
29
|
+
const session = await response.json();
|
|
30
|
+
if (typeof session?.user_id !== 'string' || !session.user_id || session.client_id !== storeId)
|
|
31
|
+
throw new SwellError('Invalid staff session', { status: 401 });
|
|
32
|
+
return { userId: session.user_id, storeId };
|
|
33
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import './guard.cjs';
|
|
2
|
+
import type { PublicConfig, SwellClient } from 'swell-js';
|
|
3
|
+
export interface CookieOptions {
|
|
4
|
+
path?: string;
|
|
5
|
+
maxAge?: number;
|
|
6
|
+
sameSite?: 'lax' | 'strict' | 'none';
|
|
7
|
+
domain?: string;
|
|
8
|
+
expires?: Date;
|
|
9
|
+
secure?: boolean;
|
|
10
|
+
httpOnly?: boolean;
|
|
11
|
+
[attribute: string]: string | number | boolean | Date | undefined;
|
|
12
|
+
}
|
|
13
|
+
export interface CookieAdapter {
|
|
14
|
+
/** Return decoded current values, including this request's writes/deletes. The adapter owns state. */
|
|
15
|
+
get(name: string): string | undefined;
|
|
16
|
+
/** Owns write policy: may skip a write, or throw when required persistence is unavailable. */
|
|
17
|
+
set?(name: string, value: string, options: CookieOptions): void;
|
|
18
|
+
}
|
|
19
|
+
export interface StorefrontOptions {
|
|
20
|
+
cookies: CookieAdapter;
|
|
21
|
+
/** Replaces native defaults (/, one week, SameSite=Lax). Use {} for adapter-owned policy. */
|
|
22
|
+
cookieOptions?: CookieOptions;
|
|
23
|
+
}
|
|
24
|
+
/** Creates an isolated native swell-js client. Replace request before first use to add caching. */
|
|
25
|
+
export declare function createStorefrontClient(config: PublicConfig<'camel'> & {
|
|
26
|
+
useCamelCase: true;
|
|
27
|
+
}, options: StorefrontOptions): SwellClient<'camel'>;
|
|
28
|
+
export declare function createStorefrontClient<C extends 'snake' | 'camel' = 'snake'>(config: PublicConfig<C>, options: StorefrontOptions): SwellClient<C>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import './guard.js';
|
|
2
|
+
import type { PublicConfig, SwellClient } from 'swell-js';
|
|
3
|
+
export interface CookieOptions {
|
|
4
|
+
path?: string;
|
|
5
|
+
maxAge?: number;
|
|
6
|
+
sameSite?: 'lax' | 'strict' | 'none';
|
|
7
|
+
domain?: string;
|
|
8
|
+
expires?: Date;
|
|
9
|
+
secure?: boolean;
|
|
10
|
+
httpOnly?: boolean;
|
|
11
|
+
[attribute: string]: string | number | boolean | Date | undefined;
|
|
12
|
+
}
|
|
13
|
+
export interface CookieAdapter {
|
|
14
|
+
/** Return decoded current values, including this request's writes/deletes. The adapter owns state. */
|
|
15
|
+
get(name: string): string | undefined;
|
|
16
|
+
/** Owns write policy: may skip a write, or throw when required persistence is unavailable. */
|
|
17
|
+
set?(name: string, value: string, options: CookieOptions): void;
|
|
18
|
+
}
|
|
19
|
+
export interface StorefrontOptions {
|
|
20
|
+
cookies: CookieAdapter;
|
|
21
|
+
/** Replaces native defaults (/, one week, SameSite=Lax). Use {} for adapter-owned policy. */
|
|
22
|
+
cookieOptions?: CookieOptions;
|
|
23
|
+
}
|
|
24
|
+
/** Creates an isolated native swell-js client. Replace request before first use to add caching. */
|
|
25
|
+
export declare function createStorefrontClient(config: PublicConfig<'camel'> & {
|
|
26
|
+
useCamelCase: true;
|
|
27
|
+
}, options: StorefrontOptions): SwellClient<'camel'>;
|
|
28
|
+
export declare function createStorefrontClient<C extends 'snake' | 'camel' = 'snake'>(config: PublicConfig<C>, options: StorefrontOptions): SwellClient<C>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import './guard.js';
|
|
2
|
+
import swell from 'swell-js';
|
|
3
|
+
import { requireString, validateUrl } from './context.js';
|
|
4
|
+
export function createStorefrontClient(config, { cookies, cookieOptions = { path: '/', maxAge: 604800, sameSite: 'lax' } }) {
|
|
5
|
+
for (const field of ['getCookie', 'setCookie', 'getCart', 'updateCart']) {
|
|
6
|
+
if (field in config)
|
|
7
|
+
throw new Error(`Invalid public config callback: ${field}`);
|
|
8
|
+
}
|
|
9
|
+
requireString(config.storeId, 'storeId');
|
|
10
|
+
requireString(config.publicKey, 'publicKey');
|
|
11
|
+
for (const field of ['url', 'vaultUrl']) {
|
|
12
|
+
if (config[field] !== undefined)
|
|
13
|
+
validateUrl(config[field], field);
|
|
14
|
+
}
|
|
15
|
+
for (const field of ['locale', 'currency', 'session', 'store', 'key']) {
|
|
16
|
+
if (config[field] !== undefined && typeof config[field] !== 'string')
|
|
17
|
+
throw new Error(`Invalid ${field}`);
|
|
18
|
+
}
|
|
19
|
+
for (const field of ['useCamelCase', 'previewContent']) {
|
|
20
|
+
if (config[field] !== undefined && typeof config[field] !== 'boolean')
|
|
21
|
+
throw new Error(`Invalid ${field}`);
|
|
22
|
+
}
|
|
23
|
+
if (config.timeout !== undefined && (!Number.isFinite(config.timeout) || config.timeout < 0))
|
|
24
|
+
throw new Error('Invalid timeout');
|
|
25
|
+
if (config.headers !== undefined && (!config.headers || typeof config.headers !== 'object' || Array.isArray(config.headers) || Object.values(config.headers).some(value => typeof value !== 'string')))
|
|
26
|
+
throw new Error('Invalid headers');
|
|
27
|
+
if (!cookies || typeof cookies.get !== 'function' || (cookies.set !== undefined && typeof cookies.set !== 'function'))
|
|
28
|
+
throw new Error('A cookie adapter with get() and optional set() is required');
|
|
29
|
+
return swell.create(config.storeId, config.publicKey, {
|
|
30
|
+
...config,
|
|
31
|
+
headers: { ...config.headers },
|
|
32
|
+
getCookie: name => cookies.get(name),
|
|
33
|
+
setCookie(name, value, attributes = {}) {
|
|
34
|
+
if (!cookies.set)
|
|
35
|
+
throw new Error('Cannot write Swell cookies with a read-only adapter; use a writable route handler or action');
|
|
36
|
+
const options = { ...cookieOptions };
|
|
37
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
38
|
+
const normalized = { 'max-age': 'maxAge', maxage: 'maxAge', samesite: 'sameSite', httponly: 'httpOnly' }[key.toLowerCase()] ?? key;
|
|
39
|
+
options[normalized] = value;
|
|
40
|
+
}
|
|
41
|
+
return cookies.set(name, value, options);
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const USER_AGENT = "swell-apps-sdk/2.0.0-alpha.0";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const USER_AGENT = "swell-apps-sdk/2.0.0-alpha.0";
|
package/dist/version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function validateWorkflowParams(params: unknown): unknown;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function validateWorkflowParams(params: unknown): unknown;
|
package/dist/workflow.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { SwellError } from './error.js';
|
|
2
|
+
function paramsError(code, message) {
|
|
3
|
+
return new SwellError({ error: { code, message, status: 400, retryable: false } }, { code, status: 400 });
|
|
4
|
+
}
|
|
5
|
+
function validateValue(value, seen) {
|
|
6
|
+
if (value === null || typeof value === 'string' || typeof value === 'boolean' || (typeof value === 'number' && Number.isFinite(value)))
|
|
7
|
+
return;
|
|
8
|
+
if (typeof value !== 'object' || value === null || seen.has(value) || Object.getOwnPropertySymbols(value).length) {
|
|
9
|
+
throw paramsError('workflow_params_unserializable', 'Workflow params must be JSON-safe values');
|
|
10
|
+
}
|
|
11
|
+
if (Array.isArray(value)) {
|
|
12
|
+
const keys = Object.keys(value);
|
|
13
|
+
if (keys.some(key => !/^(0|[1-9]\d*)$/.test(key) || Number(key) >= value.length)) {
|
|
14
|
+
throw paramsError('workflow_params_unserializable', 'Workflow params must be JSON-safe values');
|
|
15
|
+
}
|
|
16
|
+
for (let index = 0; index < value.length; index++) {
|
|
17
|
+
if (!Object.prototype.hasOwnProperty.call(value, index))
|
|
18
|
+
throw paramsError('workflow_params_unserializable', 'Workflow params must be JSON-safe values');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) {
|
|
22
|
+
throw paramsError('workflow_params_unserializable', 'Workflow params must be JSON-safe values');
|
|
23
|
+
}
|
|
24
|
+
seen.add(value);
|
|
25
|
+
for (const item of Array.isArray(value) ? value : Object.values(value))
|
|
26
|
+
validateValue(item, seen);
|
|
27
|
+
seen.delete(value);
|
|
28
|
+
}
|
|
29
|
+
export function validateWorkflowParams(params) {
|
|
30
|
+
validateValue(params, new Set());
|
|
31
|
+
if (new TextEncoder().encode(JSON.stringify(params)).length > 128 * 1024) {
|
|
32
|
+
throw paramsError('workflow_params_too_large', 'Workflow params are too large; pass identifiers and re-fetch data inside the workflow');
|
|
33
|
+
}
|
|
34
|
+
return params;
|
|
35
|
+
}
|
package/package.json
CHANGED
|
@@ -1,77 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swell/apps-sdk",
|
|
3
|
+
"version": "2.0.0-alpha.0",
|
|
4
|
+
"description": "Server SDK for Swell apps.",
|
|
3
5
|
"type": "module",
|
|
4
|
-
"version": "1.0.189",
|
|
5
|
-
"description": "Swell SDK for building isomorphic apps.",
|
|
6
|
-
"author": "Swell",
|
|
7
6
|
"license": "MIT",
|
|
8
7
|
"engines": {
|
|
9
|
-
"node": ">=
|
|
10
|
-
"npm": ">=9.3.1"
|
|
11
|
-
},
|
|
12
|
-
"repository": {
|
|
13
|
-
"type": "git",
|
|
14
|
-
"url": "https://github.com/swellstores/swell-apps-sdk"
|
|
15
|
-
},
|
|
16
|
-
"main": "./dist/index.cjs",
|
|
17
|
-
"module": "./dist/index.mjs",
|
|
18
|
-
"browser": "./dist/index.js",
|
|
19
|
-
"types": "./types/index.d.ts",
|
|
20
|
-
"exports": {
|
|
21
|
-
".": {
|
|
22
|
-
"types": "./types/index.d.ts",
|
|
23
|
-
"require": "./dist/index.cjs",
|
|
24
|
-
"import": "./dist/index.mjs"
|
|
25
|
-
}
|
|
8
|
+
"node": ">=22.22.2"
|
|
26
9
|
},
|
|
27
10
|
"files": [
|
|
28
|
-
"dist"
|
|
29
|
-
"types/*.d.ts"
|
|
11
|
+
"dist"
|
|
30
12
|
],
|
|
31
13
|
"scripts": {
|
|
32
|
-
"prebuild": "rimraf dist",
|
|
33
14
|
"build": "node scripts/build.mjs",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"test": "
|
|
15
|
+
"prepack": "npm run build",
|
|
16
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
17
|
+
"test": "npm run build && node --test test/*.test.mjs",
|
|
18
|
+
"test:package": "node scripts/verify-package.mjs",
|
|
19
|
+
"test:boundaries": "node scripts/verify-boundaries.mjs",
|
|
20
|
+
"test:worker": "node scripts/verify-worker.mjs",
|
|
21
|
+
"verify": "npm test && npm run typecheck && npm run test:package && npm run test:boundaries && npm run test:worker"
|
|
39
22
|
},
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"cache-manager": "^7.0.1",
|
|
43
|
-
"color": "^4.2.3",
|
|
44
|
-
"country-flag-icons": "1.5.18",
|
|
45
|
-
"json5": "^2.2.3",
|
|
46
|
-
"keyv": "^5.3.4",
|
|
47
|
-
"liquidjs": "^10.21.0",
|
|
48
|
-
"lodash-es": "^4.17.21",
|
|
49
|
-
"qs": "^6.12.3",
|
|
50
|
-
"strftime": "^0.10.3",
|
|
51
|
-
"swell-js": "^5.1.2"
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"swell-js": ">=5.9.1"
|
|
52
25
|
},
|
|
53
26
|
"devDependencies": {
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
"
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
27
|
+
"esbuild": "0.24.2",
|
|
28
|
+
"miniflare": "5.20260911.1-alpha",
|
|
29
|
+
"swell-js": "5.9.1",
|
|
30
|
+
"typescript": "5.7.3"
|
|
31
|
+
},
|
|
32
|
+
"main": "./dist/index.js",
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"types": {
|
|
37
|
+
"import": "./dist/index.d.ts",
|
|
38
|
+
"require": "./dist/index.d.cts"
|
|
39
|
+
},
|
|
40
|
+
"workerd": "./dist/index.js",
|
|
41
|
+
"node": "./dist/index.js",
|
|
42
|
+
"browser": "./dist/browser-refusal.js",
|
|
43
|
+
"default": "./dist/index.js"
|
|
44
|
+
},
|
|
45
|
+
"./storefront": {
|
|
46
|
+
"types": {
|
|
47
|
+
"import": "./dist/storefront.d.ts",
|
|
48
|
+
"require": "./dist/storefront.d.cts"
|
|
49
|
+
},
|
|
50
|
+
"workerd": "./dist/storefront.js",
|
|
51
|
+
"node": "./dist/storefront.js",
|
|
52
|
+
"browser": "./dist/browser-refusal.js",
|
|
53
|
+
"default": "./dist/storefront.js"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"sideEffects": [
|
|
57
|
+
"./dist/index.js",
|
|
58
|
+
"./dist/storefront.js",
|
|
59
|
+
"./dist/guard.js",
|
|
60
|
+
"./dist/browser-refusal.js"
|
|
61
|
+
]
|
|
77
62
|
}
|