@swell/apps-sdk 1.0.182 → 1.0.184
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/dist/index.cjs +217 -162
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +217 -162
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +197 -142
- package/dist/index.mjs.map +4 -4
- package/dist/src/cache/html-cache/html-cache.d.ts +45 -14
- package/dist/src/compatibility/drops/collections.d.ts +2 -0
- package/dist/src/liquid/filters/escape.d.ts +3 -0
- package/dist/src/liquid/filters/index.d.ts +2 -0
- package/package.json +2 -4
|
@@ -1,26 +1,39 @@
|
|
|
1
1
|
import type { CacheBackend, CachedEntry } from './html-cache-backend';
|
|
2
2
|
/**
|
|
3
3
|
* Configuration for path-specific cache behavior.
|
|
4
|
+
*
|
|
4
5
|
* Paths support wildcards:
|
|
5
|
-
* -
|
|
6
|
-
* -
|
|
7
|
-
*
|
|
6
|
+
* - `*` matches any characters except `/`
|
|
7
|
+
* - `**` matches any characters including `/`
|
|
8
|
+
*
|
|
9
|
+
* Examples: `/account/*`, `/api/**`, `*.json`
|
|
10
|
+
*
|
|
8
11
|
* First matching rule wins.
|
|
9
12
|
*/
|
|
10
13
|
export interface PathRule {
|
|
11
14
|
path: string;
|
|
15
|
+
/** Time-to-live in seconds */
|
|
12
16
|
ttl?: number;
|
|
17
|
+
/** Stale-while-revalidate in seconds */
|
|
13
18
|
swr?: number;
|
|
19
|
+
/** If true, skip caching for this path */
|
|
14
20
|
skip?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Optional list of allowed Content-Types for caching.
|
|
23
|
+
*
|
|
24
|
+
* If provided, responses whose Content-Type starts with one of these values are cacheable.
|
|
25
|
+
*
|
|
26
|
+
* If omitted, defaults to only allowing `text/html`.
|
|
27
|
+
*/
|
|
15
28
|
contentTypes?: string[];
|
|
16
29
|
}
|
|
17
30
|
export interface CacheRules {
|
|
18
|
-
defaults
|
|
19
|
-
live
|
|
31
|
+
defaults: {
|
|
32
|
+
live: {
|
|
20
33
|
ttl: number;
|
|
21
34
|
swr: number;
|
|
22
35
|
};
|
|
23
|
-
preview
|
|
36
|
+
preview: {
|
|
24
37
|
ttl: number;
|
|
25
38
|
swr: number;
|
|
26
39
|
};
|
|
@@ -28,6 +41,22 @@ export interface CacheRules {
|
|
|
28
41
|
pathRules?: PathRule[];
|
|
29
42
|
}
|
|
30
43
|
export declare const DEFAULT_CACHE_RULES: CacheRules;
|
|
44
|
+
interface PathRuleInner extends PathRule {
|
|
45
|
+
regex: RegExp;
|
|
46
|
+
}
|
|
47
|
+
interface CacheRulesInner {
|
|
48
|
+
defaults: {
|
|
49
|
+
live: {
|
|
50
|
+
ttl: number;
|
|
51
|
+
swr: number;
|
|
52
|
+
};
|
|
53
|
+
preview: {
|
|
54
|
+
ttl: number;
|
|
55
|
+
swr: number;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
pathRules?: PathRuleInner[];
|
|
59
|
+
}
|
|
31
60
|
type DeploymentMode = 'live' | 'preview';
|
|
32
61
|
export interface CacheResult {
|
|
33
62
|
found: boolean;
|
|
@@ -47,8 +76,15 @@ export interface CacheResult {
|
|
|
47
76
|
export declare class HtmlCache {
|
|
48
77
|
protected epoch: string;
|
|
49
78
|
protected backend: CacheBackend;
|
|
50
|
-
protected cacheRules:
|
|
79
|
+
protected cacheRules: CacheRulesInner;
|
|
51
80
|
constructor(epoch: string, backend: CacheBackend, cacheRules?: CacheRules);
|
|
81
|
+
/**
|
|
82
|
+
* Converts wildcard pattern to regex and tests against path.
|
|
83
|
+
*
|
|
84
|
+
* - `*` matches any characters except `/`
|
|
85
|
+
* - `**` matches any characters including `/`
|
|
86
|
+
*/
|
|
87
|
+
protected convertPathToRegex(pattern: string): RegExp;
|
|
52
88
|
get(request: Request): Promise<CacheResult | null>;
|
|
53
89
|
getWithConditionals(request: Request): Promise<CacheResult | null>;
|
|
54
90
|
put(request: Request, response: Response): Promise<void>;
|
|
@@ -62,20 +98,15 @@ export declare class HtmlCache {
|
|
|
62
98
|
protected ifNoneMatchMatches(ifNoneMatch: string | null, etag: string | null): boolean;
|
|
63
99
|
protected quoteETag(value: string): string;
|
|
64
100
|
protected sanitizeClientHeaders(headers: Headers): void;
|
|
101
|
+
getCacheKeyHeaders(headers: Headers): Headers;
|
|
65
102
|
protected generateVersionHash(headers: Headers): string;
|
|
66
|
-
protected extractSwellData(
|
|
103
|
+
protected extractSwellData(cookie: string | null): Record<string, unknown>;
|
|
67
104
|
protected isRequestCacheable(request: Request): boolean;
|
|
68
105
|
protected isResponseCacheable(response: Response, matchedRule?: PathRule): boolean;
|
|
69
106
|
protected getDeploymentMode(headers: Headers): DeploymentMode;
|
|
70
107
|
protected getTTLForRequest(request: Request): number;
|
|
71
108
|
protected getSWRForRequest(request: Request): number;
|
|
72
109
|
protected getEntryAge(entry: CachedEntry): number;
|
|
73
|
-
/**
|
|
74
|
-
* Converts wildcard pattern to regex and tests against path.
|
|
75
|
-
* - * matches any characters except /
|
|
76
|
-
* - ** matches any characters including /
|
|
77
|
-
*/
|
|
78
|
-
protected pathMatches(pattern: string, path: string): boolean;
|
|
79
110
|
protected normalizeHeaders(headers: Headers): Record<string, string>;
|
|
80
111
|
protected resolvePathRule(request: Request): {
|
|
81
112
|
rule?: PathRule;
|
|
@@ -8,6 +8,8 @@ declare class CollectionsDrop extends Drop {
|
|
|
8
8
|
constructor(instance: ShopifyCompatibility);
|
|
9
9
|
liquidMethodMissing(key: unknown): unknown;
|
|
10
10
|
getCollection(slug: string): ShopifyResource<ShopifyCollectionType>;
|
|
11
|
+
getAllCollection(): ShopifyResource<ShopifyCollectionType>;
|
|
12
|
+
getAllCollectionsSize(): Promise<number> | number;
|
|
11
13
|
}
|
|
12
14
|
export default class Collections extends SwellStorefrontCollection<ShopifyCollectionType> {
|
|
13
15
|
#private;
|
|
@@ -18,6 +18,7 @@ import date from './date';
|
|
|
18
18
|
import default_errors from './default_errors';
|
|
19
19
|
import divided_by from './divided_by';
|
|
20
20
|
import embedded_content from './embedded_content';
|
|
21
|
+
import escape from './escape';
|
|
21
22
|
import font_face from './font_face';
|
|
22
23
|
import font_modify from './font_modify';
|
|
23
24
|
import font_url from './font_url';
|
|
@@ -69,6 +70,7 @@ export declare const filters: {
|
|
|
69
70
|
default_errors: typeof default_errors;
|
|
70
71
|
divided_by: typeof divided_by;
|
|
71
72
|
embedded_content: typeof embedded_content;
|
|
73
|
+
escape: typeof escape;
|
|
72
74
|
font_face: typeof font_face;
|
|
73
75
|
font_modify: typeof font_modify;
|
|
74
76
|
font_url: typeof font_url;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swell/apps-sdk",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.184",
|
|
5
5
|
"description": "Swell SDK for building isomorphic apps.",
|
|
6
6
|
"author": "Swell",
|
|
7
7
|
"license": "MIT",
|
|
@@ -45,7 +45,6 @@
|
|
|
45
45
|
"json5": "^2.2.3",
|
|
46
46
|
"keyv": "^5.3.4",
|
|
47
47
|
"liquidjs": "^10.21.0",
|
|
48
|
-
"lodash": "^4.17.21",
|
|
49
48
|
"lodash-es": "^4.17.21",
|
|
50
49
|
"qs": "^6.12.3",
|
|
51
50
|
"strftime": "^0.10.3",
|
|
@@ -57,19 +56,18 @@
|
|
|
57
56
|
"@jest/transform": "^29.7.0",
|
|
58
57
|
"@types/color": "^4.2.0",
|
|
59
58
|
"@types/jest": "^29.5.14",
|
|
60
|
-
"@types/lodash": "^4.17.15",
|
|
61
59
|
"@types/lodash-es": "^4.17.12",
|
|
62
60
|
"@types/qs": "^6.9.15",
|
|
63
61
|
"@types/react": "^18.2.64",
|
|
64
62
|
"@types/react-dom": "^18.2.21",
|
|
65
63
|
"@types/strftime": "^0.9.8",
|
|
66
64
|
"esbuild": "^0.24.2",
|
|
67
|
-
"esbuild-jest": "^0.5.0",
|
|
68
65
|
"eslint": "^9.19.0",
|
|
69
66
|
"eslint-config-prettier": "^10.0.1",
|
|
70
67
|
"eslint-plugin-jest": "^28.11.0",
|
|
71
68
|
"eslint-plugin-prettier": "^5.2.3",
|
|
72
69
|
"jest": "29.7.0",
|
|
70
|
+
"jest-esbuild": "^0.4.0",
|
|
73
71
|
"prettier": "^3.4.2",
|
|
74
72
|
"rimraf": "^6.0.1",
|
|
75
73
|
"ts-jest": "^29.2.5",
|