@kotao/storefront 0.2.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/LICENSE +21 -0
- package/README.md +34 -0
- package/dist/cart-documents-CwwRTvm8.d.ts +21 -0
- package/dist/cart-documents.d.ts +2 -0
- package/dist/cart-documents.js +3 -0
- package/dist/cart-documents.js.map +1 -0
- package/dist/chunk-2IWNUDSZ.js +104 -0
- package/dist/chunk-2IWNUDSZ.js.map +1 -0
- package/dist/chunk-3YQXJNR7.js +70 -0
- package/dist/chunk-3YQXJNR7.js.map +1 -0
- package/dist/chunk-5QOFKGKD.js +51 -0
- package/dist/chunk-5QOFKGKD.js.map +1 -0
- package/dist/chunk-GCQI6OKH.js +239 -0
- package/dist/chunk-GCQI6OKH.js.map +1 -0
- package/dist/chunk-ISAFEOR2.js +214 -0
- package/dist/chunk-ISAFEOR2.js.map +1 -0
- package/dist/chunk-MYDKIJRH.js +81 -0
- package/dist/chunk-MYDKIJRH.js.map +1 -0
- package/dist/chunk-OGWYTYYS.js +72 -0
- package/dist/chunk-OGWYTYYS.js.map +1 -0
- package/dist/chunk-PXZ737N3.js +439 -0
- package/dist/chunk-PXZ737N3.js.map +1 -0
- package/dist/chunk-QOEEUTHQ.js +110 -0
- package/dist/chunk-QOEEUTHQ.js.map +1 -0
- package/dist/chunk-U5677AEA.js +1690 -0
- package/dist/chunk-U5677AEA.js.map +1 -0
- package/dist/chunk-XMTWFJCZ.js +138 -0
- package/dist/chunk-XMTWFJCZ.js.map +1 -0
- package/dist/client-D9YYA2w6.d.ts +159 -0
- package/dist/customer-account-api-types.d.ts +144 -0
- package/dist/customer-account-api-types.js +3 -0
- package/dist/customer-account-api-types.js.map +1 -0
- package/dist/editor.d.ts +112 -0
- package/dist/editor.js +3 -0
- package/dist/editor.js.map +1 -0
- package/dist/image.d.ts +89 -0
- package/dist/image.js +3 -0
- package/dist/image.js.map +1 -0
- package/dist/index.d.ts +183 -0
- package/dist/index.js +208 -0
- package/dist/index.js.map +1 -0
- package/dist/pagination-CPgH3fAa.d.ts +77 -0
- package/dist/product.d.ts +105 -0
- package/dist/product.js +4 -0
- package/dist/product.js.map +1 -0
- package/dist/react-router.d.ts +29 -0
- package/dist/react-router.js +33 -0
- package/dist/react-router.js.map +1 -0
- package/dist/react.d.ts +299 -0
- package/dist/react.js +1813 -0
- package/dist/react.js.map +1 -0
- package/dist/routing-BfUp49o8.d.ts +302 -0
- package/dist/seo.d.ts +155 -0
- package/dist/seo.js +4 -0
- package/dist/seo.js.map +1 -0
- package/dist/settings.d.ts +87 -0
- package/dist/settings.js +3 -0
- package/dist/settings.js.map +1 -0
- package/dist/shop-DkQmro-Y.d.ts +202 -0
- package/dist/store-DQK1nhob.d.ts +67 -0
- package/dist/storefront-api-types.d.ts +312 -0
- package/dist/storefront-api-types.js +3 -0
- package/dist/storefront-api-types.js.map +1 -0
- package/dist/types-BDhHWZsP.d.ts +77 -0
- package/dist/types-Df3bGbKU.d.ts +167 -0
- package/package.json +82 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
interface CacheStrategy {
|
|
2
|
+
readonly mode: 'none' | 'short' | 'long' | 'custom';
|
|
3
|
+
/** seconds the value is considered fresh */
|
|
4
|
+
readonly maxAge: number;
|
|
5
|
+
/** extra seconds the stale value may be served while revalidating */
|
|
6
|
+
readonly staleWhileRevalidate: number;
|
|
7
|
+
}
|
|
8
|
+
declare const CacheNone: () => CacheStrategy;
|
|
9
|
+
declare const CacheShort: (o?: Partial<Omit<CacheStrategy, "mode">>) => CacheStrategy;
|
|
10
|
+
declare const CacheLong: (o?: Partial<Omit<CacheStrategy, "mode">>) => CacheStrategy;
|
|
11
|
+
declare const CacheCustom: (s: Omit<CacheStrategy, "mode">) => CacheStrategy;
|
|
12
|
+
/** Hydrogen-parity storefront sub-request default: fresh 1s, serveable up to ~1 day. */
|
|
13
|
+
declare const StorefrontDefaultCache: () => CacheStrategy;
|
|
14
|
+
declare function generateCacheControlHeader(strategy: CacheStrategy): string;
|
|
15
|
+
interface KotaoCache {
|
|
16
|
+
run<T>(key: string, strategy: CacheStrategy, fn: () => Promise<T>): Promise<T>;
|
|
17
|
+
readonly raw: Cache;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Stale-while-revalidate cache over an injected Cache (WFP untrusted mode disables
|
|
21
|
+
* `caches.default`; each user Worker gets an isolated `caches.open(...)`). `now` is injectable
|
|
22
|
+
* for deterministic tests and to sidestep workerd's intra-request frozen clock — only
|
|
23
|
+
* cross-request age is ever compared, which `Date.now()` reports correctly.
|
|
24
|
+
*/
|
|
25
|
+
declare function createCache(opts: {
|
|
26
|
+
cache: Cache;
|
|
27
|
+
waitUntil: (p: Promise<unknown>) => void;
|
|
28
|
+
now?: () => number;
|
|
29
|
+
}): KotaoCache;
|
|
30
|
+
|
|
31
|
+
interface StorefrontQueryOptions {
|
|
32
|
+
variables?: Record<string, unknown>;
|
|
33
|
+
cache?: CacheStrategy;
|
|
34
|
+
storefrontApiVersion?: string;
|
|
35
|
+
}
|
|
36
|
+
interface StorefrontLooseConnection<T = any> {
|
|
37
|
+
readonly nodes: T[];
|
|
38
|
+
readonly pageInfo: any;
|
|
39
|
+
}
|
|
40
|
+
interface StorefrontLooseProductCollection {
|
|
41
|
+
readonly description: string;
|
|
42
|
+
readonly handle: string;
|
|
43
|
+
readonly id: string;
|
|
44
|
+
readonly products: StorefrontLooseConnection & {
|
|
45
|
+
readonly filters: readonly {
|
|
46
|
+
readonly values: readonly {
|
|
47
|
+
readonly id: string;
|
|
48
|
+
readonly input?: string | null;
|
|
49
|
+
readonly label: string;
|
|
50
|
+
}[];
|
|
51
|
+
}[];
|
|
52
|
+
};
|
|
53
|
+
readonly title: string;
|
|
54
|
+
}
|
|
55
|
+
interface StorefrontDefaultQueryData {
|
|
56
|
+
[key: string]: any;
|
|
57
|
+
additional: StorefrontLooseConnection;
|
|
58
|
+
articles: StorefrontLooseConnection;
|
|
59
|
+
blog: {
|
|
60
|
+
readonly articles: StorefrontLooseConnection;
|
|
61
|
+
readonly seo?: any;
|
|
62
|
+
readonly title: string;
|
|
63
|
+
};
|
|
64
|
+
blogs: StorefrontLooseConnection;
|
|
65
|
+
collection: StorefrontLooseProductCollection;
|
|
66
|
+
collections: StorefrontLooseConnection<{
|
|
67
|
+
handle: string;
|
|
68
|
+
title: string;
|
|
69
|
+
}>;
|
|
70
|
+
page: any;
|
|
71
|
+
policies: any[];
|
|
72
|
+
product: any;
|
|
73
|
+
products: StorefrontLooseConnection;
|
|
74
|
+
recommended: any[];
|
|
75
|
+
search: StorefrontLooseConnection;
|
|
76
|
+
shop: any;
|
|
77
|
+
}
|
|
78
|
+
interface StorefrontQueryPromise<T> extends Promise<T> {
|
|
79
|
+
catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): Promise<T | TResult>;
|
|
80
|
+
}
|
|
81
|
+
interface StorefrontClient {
|
|
82
|
+
query<T = StorefrontDefaultQueryData>(query: string, options?: StorefrontQueryOptions): StorefrontQueryPromise<T>;
|
|
83
|
+
mutate<T = any>(mutation: string, options?: {
|
|
84
|
+
variables?: Record<string, unknown>;
|
|
85
|
+
}): Promise<T>;
|
|
86
|
+
CacheNone: typeof CacheNone;
|
|
87
|
+
CacheShort: typeof CacheShort;
|
|
88
|
+
CacheLong: typeof CacheLong;
|
|
89
|
+
CacheCustom: typeof CacheCustom;
|
|
90
|
+
readonly cache: Cache;
|
|
91
|
+
readonly i18n: StorefrontI18n;
|
|
92
|
+
}
|
|
93
|
+
type Storefront<I18n = unknown> = StorefrontClient & {
|
|
94
|
+
readonly i18n: I18n;
|
|
95
|
+
};
|
|
96
|
+
type StorefrontClientResult<I18n = StorefrontI18n> = Storefront<I18n> & {
|
|
97
|
+
readonly storefront: Storefront<I18n>;
|
|
98
|
+
};
|
|
99
|
+
interface StorefrontI18n {
|
|
100
|
+
readonly language: string;
|
|
101
|
+
readonly country: string;
|
|
102
|
+
readonly currency: string;
|
|
103
|
+
readonly pathPrefix: string;
|
|
104
|
+
}
|
|
105
|
+
type StorefrontAuthHeader = 'x-kotao-storefront-token' | 'x-api-key' | 'x-shopify-storefront-access-token';
|
|
106
|
+
interface StorefrontClientOptions {
|
|
107
|
+
endpoint: string;
|
|
108
|
+
token: string;
|
|
109
|
+
tokenHeader?: StorefrontAuthHeader;
|
|
110
|
+
siteId?: string;
|
|
111
|
+
cache: KotaoCache;
|
|
112
|
+
fetch?: typeof fetch | undefined;
|
|
113
|
+
defaultStrategy?: CacheStrategy | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* Pre-signed `x-kotao-shop` / `x-kotao-shop-signature` header pair, merged into every request.
|
|
116
|
+
* In production the Gateway signs the shop-context; in local dev (no Gateway) the theme dev
|
|
117
|
+
* server signs it (see createKotaoContext). Absent in production.
|
|
118
|
+
*/
|
|
119
|
+
signedShopContextHeaders?: Readonly<Record<string, string>> | undefined;
|
|
120
|
+
/**
|
|
121
|
+
* Additional server request headers to forward to direct Storefront API calls. Used by
|
|
122
|
+
* Hydrogen-compatible server adapters for `storefrontHeaders`.
|
|
123
|
+
*/
|
|
124
|
+
extraHeaders?: HeadersInit | undefined;
|
|
125
|
+
/**
|
|
126
|
+
* BCP 47 locale tag derived from the localization cookie (e.g. `'nl'`, `'es'`, `'de-de'`).
|
|
127
|
+
* When set, `x-kotao-locale` is added to every request so storefront-api can overlay
|
|
128
|
+
* translations. Also folds into the SWR cache key so locales never share a cached response.
|
|
129
|
+
*/
|
|
130
|
+
locale?: string | undefined;
|
|
131
|
+
/**
|
|
132
|
+
* ISO 3166-1 alpha-2 country selected by the localization cookie. When valid, sent as
|
|
133
|
+
* `x-kotao-country` and folded into the SWR key so country-specific prices never share cache.
|
|
134
|
+
*/
|
|
135
|
+
country?: string | undefined;
|
|
136
|
+
i18n?: Partial<StorefrontI18n> | undefined;
|
|
137
|
+
}
|
|
138
|
+
interface HydrogenStorefrontClientOptions<I18n extends object = StorefrontI18n> {
|
|
139
|
+
cache: Cache;
|
|
140
|
+
waitUntil: (promise: Promise<unknown>) => void;
|
|
141
|
+
i18n?: I18n | undefined;
|
|
142
|
+
publicStorefrontToken: string;
|
|
143
|
+
privateStorefrontToken?: string | undefined;
|
|
144
|
+
storeDomain: string;
|
|
145
|
+
storefrontId?: string | undefined;
|
|
146
|
+
storefrontHeaders?: HeadersInit | undefined;
|
|
147
|
+
storefrontApiVersion?: string | undefined;
|
|
148
|
+
fetch?: typeof fetch | undefined;
|
|
149
|
+
defaultStrategy?: CacheStrategy | undefined;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Typed GraphQL client mirroring Hydrogen's `createStorefrontClient`. Queries are SWR-cached
|
|
153
|
+
* (default {@link StorefrontDefaultCache}); mutations are never cached. Talks to the same-origin
|
|
154
|
+
* `/api/storefront` proxy (#85) so tokens stay server-side and themes need no CORS.
|
|
155
|
+
*/
|
|
156
|
+
declare function createStorefrontClient(opts: StorefrontClientOptions): StorefrontClientResult;
|
|
157
|
+
declare function createStorefrontClient<I18n extends object = StorefrontI18n>(opts: HydrogenStorefrontClientOptions<I18n>): StorefrontClientResult<StorefrontI18n & I18n>;
|
|
158
|
+
|
|
159
|
+
export { type CacheStrategy as C, type HydrogenStorefrontClientOptions as H, type KotaoCache as K, type StorefrontClient as S, CacheCustom as a, CacheLong as b, CacheNone as c, CacheShort as d, type Storefront as e, type StorefrontAuthHeader as f, type StorefrontClientOptions as g, type StorefrontClientResult as h, StorefrontDefaultCache as i, type StorefrontQueryOptions as j, createCache as k, createStorefrontClient as l, generateCacheControlHeader as m };
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
type Maybe<T> = T | null;
|
|
2
|
+
type InputMaybe<T> = Maybe<T>;
|
|
3
|
+
type Exact<T extends Record<string, unknown>> = {
|
|
4
|
+
[K in keyof T]: T[K];
|
|
5
|
+
};
|
|
6
|
+
interface Scalars {
|
|
7
|
+
readonly ID: {
|
|
8
|
+
readonly input: string;
|
|
9
|
+
readonly output: string;
|
|
10
|
+
};
|
|
11
|
+
readonly String: {
|
|
12
|
+
readonly input: string;
|
|
13
|
+
readonly output: string;
|
|
14
|
+
};
|
|
15
|
+
readonly Boolean: {
|
|
16
|
+
readonly input: boolean;
|
|
17
|
+
readonly output: boolean;
|
|
18
|
+
};
|
|
19
|
+
readonly Int: {
|
|
20
|
+
readonly input: number;
|
|
21
|
+
readonly output: number;
|
|
22
|
+
};
|
|
23
|
+
readonly Float: {
|
|
24
|
+
readonly input: number;
|
|
25
|
+
readonly output: number;
|
|
26
|
+
};
|
|
27
|
+
readonly DateTime: {
|
|
28
|
+
readonly input: string;
|
|
29
|
+
readonly output: string;
|
|
30
|
+
};
|
|
31
|
+
readonly [key: string]: {
|
|
32
|
+
readonly input: any;
|
|
33
|
+
readonly output: any;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
interface LooseObject {
|
|
37
|
+
[key: string]: any;
|
|
38
|
+
}
|
|
39
|
+
type FulfillmentStatus = string;
|
|
40
|
+
interface MoneyV2 extends LooseObject {
|
|
41
|
+
readonly amount: string;
|
|
42
|
+
readonly currencyCode: string;
|
|
43
|
+
}
|
|
44
|
+
interface Image extends LooseObject {
|
|
45
|
+
readonly altText?: string | null;
|
|
46
|
+
readonly height?: number | null;
|
|
47
|
+
readonly url: string;
|
|
48
|
+
readonly width?: number | null;
|
|
49
|
+
}
|
|
50
|
+
interface CustomerPhoneNumber extends LooseObject {
|
|
51
|
+
readonly phoneNumber: string;
|
|
52
|
+
}
|
|
53
|
+
interface CustomerEmailAddress extends LooseObject {
|
|
54
|
+
readonly emailAddress: string;
|
|
55
|
+
}
|
|
56
|
+
interface CustomerAddressInput {
|
|
57
|
+
address1?: string | null;
|
|
58
|
+
address2?: string | null;
|
|
59
|
+
city?: string | null;
|
|
60
|
+
company?: string | null;
|
|
61
|
+
firstName?: string | null;
|
|
62
|
+
lastName?: string | null;
|
|
63
|
+
phoneNumber?: string | null;
|
|
64
|
+
territoryCode?: string | null;
|
|
65
|
+
zip?: string | null;
|
|
66
|
+
zoneCode?: string | null;
|
|
67
|
+
}
|
|
68
|
+
interface CustomerAddress extends CustomerAddressInput {
|
|
69
|
+
readonly formatted?: readonly string[];
|
|
70
|
+
readonly formattedArea?: string | null;
|
|
71
|
+
readonly id: string;
|
|
72
|
+
readonly name?: string | null;
|
|
73
|
+
}
|
|
74
|
+
interface CustomerUpdateInput {
|
|
75
|
+
firstName?: string | null;
|
|
76
|
+
lastName?: string | null;
|
|
77
|
+
phoneNumber?: string | null;
|
|
78
|
+
}
|
|
79
|
+
interface Customer extends LooseObject {
|
|
80
|
+
readonly addresses?: {
|
|
81
|
+
readonly edges?: readonly {
|
|
82
|
+
readonly node: CustomerAddress;
|
|
83
|
+
}[];
|
|
84
|
+
};
|
|
85
|
+
readonly defaultAddress?: CustomerAddress | null;
|
|
86
|
+
readonly emailAddress?: CustomerEmailAddress | null;
|
|
87
|
+
readonly firstName?: string | null;
|
|
88
|
+
readonly id?: string;
|
|
89
|
+
readonly lastName?: string | null;
|
|
90
|
+
readonly phoneNumber?: CustomerPhoneNumber | null;
|
|
91
|
+
}
|
|
92
|
+
interface UserErrorsCustomerAddressUserErrors extends LooseObject {
|
|
93
|
+
readonly code?: string | null;
|
|
94
|
+
readonly field?: readonly string[] | null;
|
|
95
|
+
readonly message: string;
|
|
96
|
+
}
|
|
97
|
+
interface UserErrorsCustomerUserErrors extends LooseObject {
|
|
98
|
+
readonly code?: string | null;
|
|
99
|
+
readonly field?: readonly string[] | null;
|
|
100
|
+
readonly message: string;
|
|
101
|
+
}
|
|
102
|
+
interface CustomerAddressDeletePayload extends LooseObject {
|
|
103
|
+
readonly deletedAddressId?: string | null;
|
|
104
|
+
readonly userErrors?: readonly UserErrorsCustomerAddressUserErrors[];
|
|
105
|
+
}
|
|
106
|
+
interface Fulfillment extends LooseObject {
|
|
107
|
+
readonly status: FulfillmentStatus;
|
|
108
|
+
}
|
|
109
|
+
interface LineItem extends LooseObject {
|
|
110
|
+
readonly id?: string;
|
|
111
|
+
readonly image?: Image | null;
|
|
112
|
+
readonly quantity?: number;
|
|
113
|
+
readonly title: string;
|
|
114
|
+
readonly variantTitle?: string | null;
|
|
115
|
+
}
|
|
116
|
+
interface PricingPercentageValue extends LooseObject {
|
|
117
|
+
readonly percentage: number;
|
|
118
|
+
}
|
|
119
|
+
interface Order extends LooseObject {
|
|
120
|
+
readonly discountApplications?: {
|
|
121
|
+
readonly nodes?: readonly LooseObject[];
|
|
122
|
+
};
|
|
123
|
+
readonly financialStatus?: string | null;
|
|
124
|
+
readonly fulfillments?: {
|
|
125
|
+
readonly nodes?: readonly Fulfillment[];
|
|
126
|
+
};
|
|
127
|
+
readonly id: string;
|
|
128
|
+
readonly lineItems?: {
|
|
129
|
+
readonly edges?: readonly {
|
|
130
|
+
readonly node: LineItem;
|
|
131
|
+
}[];
|
|
132
|
+
readonly nodes?: readonly LineItem[];
|
|
133
|
+
};
|
|
134
|
+
readonly name?: string;
|
|
135
|
+
readonly number?: string | number;
|
|
136
|
+
readonly processedAt: string;
|
|
137
|
+
readonly shippingAddress?: CustomerAddress | null;
|
|
138
|
+
readonly statusPageUrl?: string;
|
|
139
|
+
readonly subtotal?: MoneyV2 | null;
|
|
140
|
+
readonly totalTax?: MoneyV2 | null;
|
|
141
|
+
readonly totalPrice?: MoneyV2;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export type { Customer, CustomerAddress, CustomerAddressDeletePayload, CustomerAddressInput, CustomerEmailAddress, CustomerPhoneNumber, CustomerUpdateInput, Exact, Fulfillment, FulfillmentStatus, Image, InputMaybe, LineItem, Maybe, MoneyV2, Order, PricingPercentageValue, Scalars, UserErrorsCustomerAddressUserErrors, UserErrorsCustomerUserErrors };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"customer-account-api-types.js"}
|
package/dist/editor.d.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { c as ThemeSettingsStore, b as ResolvedSettings, a as ResolvedSection, R as ResolvedBlock } from './store-DQK1nhob.js';
|
|
2
|
+
|
|
3
|
+
interface StorefrontEditorMessageTarget {
|
|
4
|
+
postMessage(message: unknown, targetOrigin: string): void;
|
|
5
|
+
}
|
|
6
|
+
interface StorefrontEditorMessageEvent {
|
|
7
|
+
readonly origin: string;
|
|
8
|
+
readonly data: unknown;
|
|
9
|
+
readonly source?: StorefrontEditorMessageTarget | null;
|
|
10
|
+
}
|
|
11
|
+
interface StorefrontEditorMessageSource {
|
|
12
|
+
addEventListener(type: 'message', listener: (event: StorefrontEditorMessageEvent) => void): void;
|
|
13
|
+
removeEventListener(type: 'message', listener: (event: StorefrontEditorMessageEvent) => void): void;
|
|
14
|
+
}
|
|
15
|
+
interface StorefrontEditorBridge {
|
|
16
|
+
ready(): void;
|
|
17
|
+
selectSection(sectionId: string): void;
|
|
18
|
+
dispose(): void;
|
|
19
|
+
}
|
|
20
|
+
interface StorefrontEditorSettingOption {
|
|
21
|
+
readonly value: string;
|
|
22
|
+
readonly label: string;
|
|
23
|
+
}
|
|
24
|
+
interface StorefrontEditorSettingInput {
|
|
25
|
+
readonly type: string;
|
|
26
|
+
readonly name: string;
|
|
27
|
+
readonly label: string;
|
|
28
|
+
readonly defaultValue?: unknown;
|
|
29
|
+
readonly placeholder?: string;
|
|
30
|
+
readonly helpText?: string;
|
|
31
|
+
readonly options?: readonly StorefrontEditorSettingOption[];
|
|
32
|
+
readonly min?: number;
|
|
33
|
+
readonly max?: number;
|
|
34
|
+
readonly step?: number;
|
|
35
|
+
readonly unit?: string;
|
|
36
|
+
}
|
|
37
|
+
interface StorefrontEditorBlockSchema {
|
|
38
|
+
readonly type: string;
|
|
39
|
+
readonly label: string;
|
|
40
|
+
readonly settings: readonly StorefrontEditorSettingInput[];
|
|
41
|
+
}
|
|
42
|
+
interface StorefrontEditorSectionPresetBlock {
|
|
43
|
+
readonly type: string;
|
|
44
|
+
readonly settings?: ResolvedSettings;
|
|
45
|
+
}
|
|
46
|
+
interface StorefrontEditorSectionPreset {
|
|
47
|
+
readonly name: string;
|
|
48
|
+
readonly settings?: ResolvedSettings;
|
|
49
|
+
readonly blocks?: readonly StorefrontEditorSectionPresetBlock[];
|
|
50
|
+
}
|
|
51
|
+
interface StorefrontEditorSectionSchema {
|
|
52
|
+
readonly type: string;
|
|
53
|
+
readonly label: string;
|
|
54
|
+
readonly settings: readonly StorefrontEditorSettingInput[];
|
|
55
|
+
readonly blocks?: readonly StorefrontEditorBlockSchema[];
|
|
56
|
+
readonly presets?: readonly StorefrontEditorSectionPreset[];
|
|
57
|
+
}
|
|
58
|
+
interface StorefrontEditorSelection {
|
|
59
|
+
readonly sectionId: string;
|
|
60
|
+
readonly section?: ResolvedSection;
|
|
61
|
+
readonly sections?: readonly ResolvedSection[];
|
|
62
|
+
readonly schema?: StorefrontEditorSectionSchema;
|
|
63
|
+
readonly schemas?: Readonly<Record<string, StorefrontEditorSectionSchema>>;
|
|
64
|
+
}
|
|
65
|
+
interface StorefrontEditorValuesDocument {
|
|
66
|
+
readonly shopId: string;
|
|
67
|
+
readonly sections: readonly ResolvedSection[];
|
|
68
|
+
}
|
|
69
|
+
interface StorefrontEditorReady {
|
|
70
|
+
readonly sections: readonly ResolvedSection[];
|
|
71
|
+
readonly schemas?: Readonly<Record<string, StorefrontEditorSectionSchema>>;
|
|
72
|
+
readonly globalInputs?: readonly StorefrontEditorSettingInput[];
|
|
73
|
+
readonly templates?: Readonly<Record<string, StorefrontEditorValuesDocument>>;
|
|
74
|
+
readonly sectionGroups?: Readonly<Record<string, StorefrontEditorValuesDocument>>;
|
|
75
|
+
}
|
|
76
|
+
interface StorefrontEditorHostBridge {
|
|
77
|
+
patchSection(sectionId: string, settings: ResolvedSettings): void;
|
|
78
|
+
patchGlobal(settings: ResolvedSettings): void;
|
|
79
|
+
insertSection(section: ResolvedSection, index?: number): void;
|
|
80
|
+
removeSection(sectionId: string): void;
|
|
81
|
+
reorderSection(sectionId: string, index: number): void;
|
|
82
|
+
patchBlock(sectionId: string, blockId: string, settings: ResolvedSettings): void;
|
|
83
|
+
insertBlock(sectionId: string, block: ResolvedBlock, index?: number): void;
|
|
84
|
+
removeBlock(sectionId: string, blockId: string): void;
|
|
85
|
+
reorderBlock(sectionId: string, blockId: string, index: number): void;
|
|
86
|
+
replaceTemplate(handle: string, document: StorefrontEditorValuesDocument): void;
|
|
87
|
+
replaceSectionGroup(handle: string, document: StorefrontEditorValuesDocument): void;
|
|
88
|
+
dispose(): void;
|
|
89
|
+
}
|
|
90
|
+
interface CreateStorefrontEditorBridgeArgs {
|
|
91
|
+
readonly adminOrigin: string;
|
|
92
|
+
readonly shopId: string;
|
|
93
|
+
readonly store: ThemeSettingsStore;
|
|
94
|
+
readonly schemas?: Readonly<Record<string, StorefrontEditorSectionSchema>>;
|
|
95
|
+
readonly globalInputs?: readonly StorefrontEditorSettingInput[];
|
|
96
|
+
readonly templates?: Readonly<Record<string, StorefrontEditorValuesDocument>>;
|
|
97
|
+
readonly sectionGroups?: Readonly<Record<string, StorefrontEditorValuesDocument>>;
|
|
98
|
+
readonly transport: StorefrontEditorMessageSource;
|
|
99
|
+
readonly target: StorefrontEditorMessageTarget;
|
|
100
|
+
}
|
|
101
|
+
interface CreateStorefrontEditorHostBridgeArgs {
|
|
102
|
+
readonly onSelectSection: (selection: StorefrontEditorSelection) => void;
|
|
103
|
+
readonly onReady?: (ready: StorefrontEditorReady) => void;
|
|
104
|
+
readonly previewOrigin: string;
|
|
105
|
+
readonly shopId: string;
|
|
106
|
+
readonly transport: StorefrontEditorMessageSource;
|
|
107
|
+
readonly target: StorefrontEditorMessageTarget;
|
|
108
|
+
}
|
|
109
|
+
declare function createStorefrontEditorBridge({ adminOrigin, globalInputs, schemas, sectionGroups, shopId, store, target, templates, transport, }: CreateStorefrontEditorBridgeArgs): StorefrontEditorBridge;
|
|
110
|
+
declare function createStorefrontEditorHostBridge({ onReady, onSelectSection, previewOrigin, shopId, target, transport, }: CreateStorefrontEditorHostBridgeArgs): StorefrontEditorHostBridge;
|
|
111
|
+
|
|
112
|
+
export { type CreateStorefrontEditorBridgeArgs, type CreateStorefrontEditorHostBridgeArgs, type StorefrontEditorBlockSchema, type StorefrontEditorBridge, type StorefrontEditorHostBridge, type StorefrontEditorMessageEvent, type StorefrontEditorMessageSource, type StorefrontEditorMessageTarget, type StorefrontEditorReady, type StorefrontEditorSectionPreset, type StorefrontEditorSectionPresetBlock, type StorefrontEditorSectionSchema, type StorefrontEditorSelection, type StorefrontEditorSettingInput, type StorefrontEditorSettingOption, type StorefrontEditorValuesDocument, createStorefrontEditorBridge, createStorefrontEditorHostBridge };
|
package/dist/editor.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"editor.js"}
|
package/dist/image.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-agnostic image-URL builders for the storefront SDK (ADR-0003 §SDK image-URL contract).
|
|
3
|
+
* They build Cloudflare `/cdn-cgi/image/<opts>/<path>` path-form transform URLs for `https://cdn.kotao.*`
|
|
4
|
+
* bases, allowing the CDN to serve optimized renderings. Non-CDN URLs (external, data:, theme `/assets/...`)
|
|
5
|
+
* pass through unchanged. Wire-native params — `width`/`height`/`fit`/`format`/`quality` — matching
|
|
6
|
+
* Cloudflare's native image resizing; a Hydrogen-shaped React `<Image>` (with `crop`, `srcSet`/`sizes`
|
|
7
|
+
* props) layers on top in the framework presets (#92). Pure string building, no framework imports, so it
|
|
8
|
+
* stays in the SDK core.
|
|
9
|
+
*/
|
|
10
|
+
/** Cloudflare-native resize mode (the Gateway's `fit` param). */
|
|
11
|
+
type ImageFit = 'scale-down' | 'contain' | 'pad' | 'squeeze' | 'cover' | 'crop';
|
|
12
|
+
/** Output format query value (the Gateway maps it to a content-type). */
|
|
13
|
+
type ImageFormat = 'webp' | 'avif' | 'jpeg' | 'png';
|
|
14
|
+
interface ImageUrlOptions {
|
|
15
|
+
width?: number;
|
|
16
|
+
height?: number;
|
|
17
|
+
fit?: ImageFit;
|
|
18
|
+
format?: ImageFormat;
|
|
19
|
+
/** 1–100. */
|
|
20
|
+
quality?: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Build a Cloudflare `/cdn-cgi/image/` path-form transform URL for a CDN image. For transformable
|
|
24
|
+
* URLs (absolute `https://cdn.kotao.*`), emits `/cdn-cgi/image/{opts}/{path}` where `{opts}` is
|
|
25
|
+
* the comma-joined key=value list (in stable order: width,height,fit,format,quality) and `{path}`
|
|
26
|
+
* is the original pathname. Chaining replaces any existing `/cdn-cgi/image/` segment.
|
|
27
|
+
* Non-CDN URLs pass through unchanged.
|
|
28
|
+
*/
|
|
29
|
+
declare function imageUrl(url: string, options?: ImageUrlOptions): string;
|
|
30
|
+
interface ImageSrcSetOptions extends Omit<ImageUrlOptions, 'width'> {
|
|
31
|
+
/** Candidate widths (px) for the `srcset` descriptors. */
|
|
32
|
+
widths: number[];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Build a `srcset` string — one `url width` candidate per width — for responsive `<img srcset>` /
|
|
36
|
+
* `<source srcset>`. Pair with a `sizes` attribute the theme controls.
|
|
37
|
+
*/
|
|
38
|
+
declare function imageSrcSet(url: string, options: ImageSrcSetOptions): string;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Framework-agnostic `<img>` attribute builder (ADR-0003 §SDK image-URL contract). Turns the
|
|
42
|
+
* Hydrogen-shaped `<Image>` surface (data/aspectRatio/crop/sizes/width/height) into concrete img
|
|
43
|
+
* attributes (src, srcSet, sizes, width, height, style) over the `cdn.kotao.*` R2-native transform
|
|
44
|
+
* contract, via the pure `imageUrl`/`imageSrcSet` builders. The React `<Image>` is a thin wrapper
|
|
45
|
+
* that spreads these — so all logic lives here, in the core, unit-tested without a DOM.
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
interface ImageData {
|
|
49
|
+
url: string;
|
|
50
|
+
altText?: string | null;
|
|
51
|
+
width?: number | null;
|
|
52
|
+
height?: number | null;
|
|
53
|
+
}
|
|
54
|
+
/** Hydrogen crop region. v1 maps any crop to a fill+crop (Cloudflare `fit=cover`); positional gravity
|
|
55
|
+
* (top/bottom/left/right) is not on the wire yet, so all values currently centre-crop. */
|
|
56
|
+
type ImageCrop = 'center' | 'top' | 'bottom' | 'left' | 'right';
|
|
57
|
+
interface ImageAttrsOptions {
|
|
58
|
+
data: ImageData;
|
|
59
|
+
/** Override `data.url`. */
|
|
60
|
+
src?: string | undefined;
|
|
61
|
+
/** "width/height" (e.g. "4/5") — sets the intrinsic box for CLS-free layout. */
|
|
62
|
+
aspectRatio?: string | undefined;
|
|
63
|
+
crop?: ImageCrop | undefined;
|
|
64
|
+
/** The responsive `sizes` attribute; the theme owns it. */
|
|
65
|
+
sizes?: string | undefined;
|
|
66
|
+
/** Fixed render width (px). With it, the srcSet becomes 1x/2x/3x instead of the responsive set. */
|
|
67
|
+
width?: number | undefined;
|
|
68
|
+
height?: number | undefined;
|
|
69
|
+
loading?: ('eager' | 'lazy') | undefined;
|
|
70
|
+
/** srcSet candidate widths; defaults to a responsive set (or 1x/2x/3x when `width` is fixed). */
|
|
71
|
+
srcSetWidths?: number[] | undefined;
|
|
72
|
+
format?: ImageFormat | undefined;
|
|
73
|
+
quality?: number | undefined;
|
|
74
|
+
}
|
|
75
|
+
interface ImageAttrs {
|
|
76
|
+
src: string;
|
|
77
|
+
srcSet: string;
|
|
78
|
+
sizes?: string;
|
|
79
|
+
width?: number;
|
|
80
|
+
height?: number;
|
|
81
|
+
alt: string;
|
|
82
|
+
loading: 'eager' | 'lazy';
|
|
83
|
+
style?: {
|
|
84
|
+
aspectRatio: string;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
declare function buildImageAttrs(options: ImageAttrsOptions): ImageAttrs;
|
|
88
|
+
|
|
89
|
+
export { type ImageAttrs, type ImageAttrsOptions, type ImageCrop, type ImageData, type ImageFit, type ImageFormat, type ImageSrcSetOptions, type ImageUrlOptions, buildImageAttrs, imageSrcSet, imageUrl };
|
package/dist/image.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"image.js"}
|