@swell/apps-sdk 1.0.138 → 1.0.140

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.
@@ -4,7 +4,6 @@ export type CreateCacheOptions = OriginalCreateCacheOptions & {
4
4
  kvStore?: CFWorkerKV;
5
5
  workerCtx?: CFWorkerContext;
6
6
  };
7
- export declare const CF_KV_NAMESPACE = "THEME";
8
7
  /**
9
8
  * Cache supports memory or KV
10
9
  * The KV layer supports namespacing and compression
@@ -13,15 +12,21 @@ export declare class Cache {
13
12
  private client;
14
13
  private workerCtx?;
15
14
  constructor(options?: CreateCacheOptions);
16
- fetch<T>(key: string, fetchFn: () => T | Promise<T>): Promise<T>;
15
+ fetch<T>(key: string, fetchFn: () => T | Promise<T>, ttl?: number): Promise<T>;
16
+ /**
17
+ * Fetch cache using SWR (stale-while-revalidate)
18
+ *
19
+ * This will always return the cached value immediately if exists
20
+ */
17
21
  fetchSWR<T>(key: string, fetchFn: () => T | Promise<T>, ttl?: number): Promise<T>;
18
- get<T>(key: string): Promise<T | null>;
22
+ get<T>(key: string): Promise<T | undefined>;
19
23
  set<T>(key: string, value: T, ttl?: number): Promise<T>;
20
24
  flush(key: string): Promise<void>;
21
25
  /**
22
26
  * Flushes the entire cache.
23
- * WARNING: If the cache store is shared among many cache clients,
24
- * this will flush entries for other clients.
27
+ *
28
+ * __WARNING__: If the cache store is shared among many cache clients,
29
+ * this will flush entries for other clients.
25
30
  */
26
31
  flushAll(): Promise<void>;
27
32
  }
@@ -1,15 +1,18 @@
1
+ import type { KeyvStoreAdapter } from 'keyv';
1
2
  import type { CFWorkerKV } from 'types/swell';
2
3
  /**
3
4
  * CloudFlare Workers KV adapter for Keyv.
4
5
  * Includes namespacing to prevent conflicts within shared storage.
5
6
  */
6
- export declare class CFWorkerKVKeyvAdapter {
7
- private namespace;
7
+ export declare class CFWorkerKVKeyvAdapter implements KeyvStoreAdapter {
8
8
  private store;
9
+ namespace: string;
10
+ opts: unknown;
9
11
  constructor(store: CFWorkerKV);
10
12
  has(key: string): Promise<boolean>;
11
- get(key: string): Promise<any>;
12
- set(key: string, value: any): Promise<any>;
13
- delete(key: string): Promise<void>;
13
+ get<T>(key: string): Promise<T | undefined>;
14
+ set(key: string, value: string, ttl?: number): Promise<void>;
15
+ delete(key: string): Promise<boolean>;
14
16
  clear(): Promise<void>;
17
+ on(_event: string, _listener: (...args: unknown[]) => void): CFWorkerKVKeyvAdapter;
15
18
  }
@@ -1,5 +1,4 @@
1
- import { Cache } from './cache';
2
- import { RequestCache } from './request-cache';
3
- import { ResourceCache } from './resource-cache';
4
- import { ThemeCache } from './theme-cache';
5
- export { Cache, RequestCache, ResourceCache, ThemeCache };
1
+ export { Cache } from './cache';
2
+ export { RequestCache } from './request-cache';
3
+ export { ResourceCache } from './resource-cache';
4
+ export { ThemeCache } from './theme-cache';
@@ -1,5 +1,4 @@
1
- import { type CreateCacheOptions } from './cache';
2
- import { Cache } from './cache';
1
+ import { Cache, type CreateCacheOptions } from './cache';
3
2
  export declare class RequestCache extends Cache {
4
3
  constructor(options?: CreateCacheOptions);
5
4
  }
@@ -1,6 +1,6 @@
1
- import { Swell } from '@/api';
2
1
  import { ThemeCache } from '../cache';
3
- import type { SwellThemeConfig, SwellThemeVersion } from 'types/swell';
2
+ import type { Swell } from '@/api';
3
+ import type { SwellThemeConfig, SwellThemePreload } from 'types/swell';
4
4
  /**
5
5
  * Responsible for loading a theme.
6
6
  */
@@ -27,7 +27,7 @@ export declare class ThemeLoader {
27
27
  /**
28
28
  * Preloads a theme version and configs. This is used to optimize initial theme load.
29
29
  */
30
- preloadTheme(version: SwellThemeVersion, configs: SwellThemeConfig[]): Promise<void>;
30
+ preloadTheme(payload: SwellThemePreload): Promise<void>;
31
31
  /**
32
32
  * Fetches a theme config by file path.
33
33
  */
@@ -53,6 +53,10 @@ export declare class ThemeLoader {
53
53
  * Caches a theme config by hash.
54
54
  */
55
55
  private cacheThemeConfig;
56
+ /**
57
+ * Caches a CDN file url by config hash.
58
+ */
59
+ private cacheThemeFileUrl;
56
60
  /**
57
61
  * Fetches the manifest (set of config hashes) for a theme version.
58
62
  */
@@ -68,6 +72,7 @@ export declare class ThemeLoader {
68
72
  * but we probably need to find why that happens in the first place (TODO).
69
73
  */
70
74
  private fetchThemeConfigsFromSourceByPath;
75
+ private getThemeId;
71
76
  /**
72
77
  * Generates a Swell API query filter for this theme version.
73
78
  */
@@ -3,7 +3,7 @@ import { ShopifyCompatibility } from './compatibility/shopify';
3
3
  import { LiquidSwell, ThemeFont, ThemeForm } from './liquid';
4
4
  import { ThemeLoader } from './theme/theme-loader';
5
5
  import type { FormatInput } from 'swell-js';
6
- import type { ThemeGlobals, ThemeConfigs, ThemeSettings, ThemeResources, ThemeFormConfig, ThemeFormErrorMessages, ThemeLocaleConfig, ThemePresetSchema, ThemeSectionGroup, ThemeSectionGroupInfo, ThemeSectionSchema, ThemeSectionConfig, ThemeSectionSettings, ThemeSettingFieldSchema, ThemeSettingSectionSchema, ThemePageSectionSchema, ThemePageTemplateConfig, ThemeLayoutSectionGroupConfig, SwellData, SwellMenu, SwellRecord, SwellAppConfig, SwellThemeConfig, SwellThemeVersion, SwellAppStorefrontThemeProps, SwellAppShopifyCompatibilityConfig, ThemePage, SwellPageRequest, SwellSettingsGeo } from '../types/swell';
6
+ import type { ThemeGlobals, ThemeConfigs, ThemeSettings, ThemeResources, ThemeFormConfig, ThemeFormErrorMessages, ThemeLocaleConfig, ThemePresetSchema, ThemeSectionGroup, ThemeSectionGroupInfo, ThemeSectionSchema, ThemeSectionConfig, ThemeSectionSettings, ThemeSettingFieldSchema, ThemeSettingSectionSchema, ThemePageSectionSchema, ThemePageTemplateConfig, ThemeLayoutSectionGroupConfig, SwellData, SwellMenu, SwellRecord, SwellAppConfig, SwellThemeConfig, SwellThemePreload, SwellAppStorefrontThemeProps, SwellAppShopifyCompatibilityConfig, ThemePage, SwellPageRequest, SwellSettingsGeo } from '../types/swell';
7
7
  export declare class SwellTheme {
8
8
  swell: Swell;
9
9
  props: SwellAppStorefrontThemeProps;
@@ -46,7 +46,7 @@ export declare class SwellTheme {
46
46
  account: SwellStorefrontSingleton | null;
47
47
  customer?: SwellStorefrontSingleton | null;
48
48
  }>;
49
- fetchSingletonResourceCached<R>(key: string, handler: () => Promise<R>, defaultValue: R): Promise<R | undefined>;
49
+ fetchSingletonResourceCached<R>(key: string, handler: () => Promise<R>, defaultValue: () => R | Promise<R>): Promise<R | undefined>;
50
50
  fetchCart(): Promise<StorefrontResource>;
51
51
  fetchAccount(): Promise<StorefrontResource | null>;
52
52
  getFormConfig(formType: string): ThemeFormConfig | undefined;
@@ -109,7 +109,7 @@ export declare class SwellTheme {
109
109
  /**
110
110
  * Preloads updated theme configs. Used to optimize initial theme load.
111
111
  */
112
- preloadThemeConfigs(version: SwellThemeVersion, configs: SwellThemeConfig[]): Promise<void>;
112
+ preloadThemeConfigs(payload: SwellThemePreload): Promise<void>;
113
113
  getPageConfigPath(pageId: string, altTemplate?: string): string | null;
114
114
  getThemeConfig(filePath: string): Promise<SwellThemeConfig | null>;
115
115
  getThemeConfigsByPath(pathPrefix: string, pathSuffix?: string): Promise<Map<string, SwellThemeConfig>>;
@@ -175,18 +175,33 @@ export interface SwellCollectionPage {
175
175
  end: number;
176
176
  }
177
177
  export type SwellCollectionPages = Record<string, SwellCollectionPage>;
178
- export interface SwellThemeConfig extends SwellRecord {
178
+ export interface SwellFile {
179
+ id: string;
180
+ md5: string;
181
+ url: string;
182
+ length: number;
183
+ filename: string | null;
184
+ content_type: string;
185
+ date_uploaded: string;
186
+ }
187
+ export interface SwellThemeConfig {
179
188
  id: string;
180
189
  type: string;
190
+ name: string;
191
+ hash: string;
192
+ file: SwellFile;
181
193
  file_data: string;
182
194
  file_path: string;
183
195
  }
196
+ export type SwellThemeManifest = Record<string, string>;
184
197
  export interface SwellThemeVersion extends SwellRecord {
185
198
  manifest: SwellThemeManifest;
186
199
  hash: string;
187
200
  }
188
- export interface SwellThemeManifest {
189
- [key: string]: string;
201
+ export interface SwellThemePreload {
202
+ api: number;
203
+ version?: SwellThemeVersion;
204
+ configs?: SwellThemeConfig[];
190
205
  }
191
206
  export interface SwellMenu {
192
207
  id: string;
@@ -509,7 +524,7 @@ export interface ThemeFormConfig {
509
524
  url: string;
510
525
  return_url?: string;
511
526
  params?: ThemeFormConfigParam[];
512
- handler?: () => void;
527
+ handler?: (...args: any[]) => any;
513
528
  }
514
529
  export interface ThemeFormErrorMessage {
515
530
  code?: string;
@@ -550,11 +565,11 @@ export interface CFWorkerKVListResponse {
550
565
  export interface CFWorkerKV {
551
566
  get(key: string, type?: 'text', options?: CFWorkerKVGetOptions<'text'>): Promise<string | null>;
552
567
  get(key: string, type?: 'arrayBuffer', options?: CFWorkerKVGetOptions<'arrayBuffer'>): Promise<ArrayBuffer | null>;
553
- get(key: string, type?: 'stream', options?: CFWorkerKVGetOptions<'stream'>): Promise<ReadableStream | null>;
568
+ get(key: string, type?: 'stream', options?: CFWorkerKVGetOptions<'stream'>): Promise<ReadableStream<Uint8Array> | null>;
554
569
  get<T>(key: string, type?: 'json', options?: CFWorkerKVGetOptions<'json'>): Promise<T | null>;
555
570
  getWithMetadata(key: string, type?: 'text', options?: CFWorkerKVGetOptions<'text'>): Promise<CFWorkerKVGetMetadataResponse<string>>;
556
571
  getWithMetadata(key: string, type?: 'arrayBuffer', options?: CFWorkerKVGetOptions<'arrayBuffer'>): Promise<CFWorkerKVGetMetadataResponse<ArrayBuffer>>;
557
- getWithMetadata(key: string, type?: 'stream', options?: CFWorkerKVGetOptions<'stream'>): Promise<CFWorkerKVGetMetadataResponse<ReadableStream>>;
572
+ getWithMetadata(key: string, type?: 'stream', options?: CFWorkerKVGetOptions<'stream'>): Promise<CFWorkerKVGetMetadataResponse<ReadableStream<Uint8Array>>>;
558
573
  getWithMetadata<T>(key: string, type?: 'json', options?: CFWorkerKVGetOptions<'json'>): Promise<CFWorkerKVGetMetadataResponse<T>>;
559
574
  put(key: string, value: string | ReadableStream | ArrayBuffer, options?: CFWorkerKVPutOptions): Promise<void>;
560
575
  delete(key: string): Promise<void>;
@@ -564,7 +579,7 @@ export interface CFThemeEnv {
564
579
  THEME?: CFWorkerKV;
565
580
  }
566
581
  export interface CFWorkerContext {
567
- waitUntil(promise: Promise<any>): void;
582
+ waitUntil(promise: Promise<unknown>): void;
568
583
  passThroughOnException(): void;
569
584
  }
570
585
  export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@swell/apps-sdk",
3
3
  "type": "module",
4
- "version": "1.0.138",
4
+ "version": "1.0.140",
5
5
  "description": "Swell SDK for building isomorphic apps.",
6
6
  "author": "Swell",
7
7
  "license": "MIT",
@@ -40,11 +40,11 @@
40
40
  "dependencies": {
41
41
  "@swell/easyblocks-core": "^1.0.19",
42
42
  "bluebird": "^3.7.2",
43
- "cache-manager": "^6.3.2",
43
+ "cache-manager": "^7.0.1",
44
44
  "color": "^4.2.3",
45
45
  "country-flag-icons": "1.5.18",
46
46
  "json5": "^2.2.3",
47
- "keyv": "^5.2.3",
47
+ "keyv": "^5.3.4",
48
48
  "liquidjs": "^10.21.0",
49
49
  "lodash": "^4.17.21",
50
50
  "lodash-es": "^4.17.21",