@cimplify/sdk 0.49.0 → 0.49.2
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/server.d.mts +97 -26
- package/dist/server.d.ts +97 -26
- package/dist/server.js +169 -38
- package/dist/server.mjs +150 -39
- package/package.json +1 -1
package/dist/server.d.mts
CHANGED
|
@@ -85,41 +85,112 @@ declare const tags: {
|
|
|
85
85
|
};
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
88
|
+
* Cimplify's opinionated cacheLife profiles for storefront server caches.
|
|
89
|
+
*
|
|
90
|
+
* Pass either of these to Next 16's `cacheLife(...)` inside a `'use cache'`
|
|
91
|
+
* server function. They're typed-literal exports so a typo fails at the SDK
|
|
92
|
+
* import site, not silently at runtime (Next's own `cacheLife(profile: string)`
|
|
93
|
+
* overload would accept anything and look it up as a custom profile).
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* import { cacheLife } from "next/cache";
|
|
98
|
+
* import { CACHE_LIFE_DEFAULT, CACHE_LIFE_PROBE, tags } from "@cimplify/sdk/server";
|
|
99
|
+
*
|
|
100
|
+
* async function getProducts() {
|
|
101
|
+
* "use cache";
|
|
102
|
+
* cacheTag(tags.products());
|
|
103
|
+
* const r = await getServerClient().catalogue.getProducts();
|
|
104
|
+
* // Don't lock in empties / failures — a transient bad render would
|
|
105
|
+
* // otherwise sit cached for the full "max" window.
|
|
106
|
+
* if (!r.ok || r.value.items.length === 0) {
|
|
107
|
+
* cacheLife(CACHE_LIFE_PROBE);
|
|
108
|
+
* return r;
|
|
109
|
+
* }
|
|
110
|
+
* cacheLife(CACHE_LIFE_DEFAULT);
|
|
111
|
+
* return r;
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
90
114
|
*/
|
|
91
|
-
declare function revalidateProducts(): Promise<void>;
|
|
92
115
|
/**
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
116
|
+
* The default cacheLife for cached storefront reads. Resolves to `"max"`,
|
|
117
|
+
* which is Next 16's longest built-in profile (stale 5min, revalidate 30d,
|
|
118
|
+
* never expires). Safe because Cimplify's tag-cache + CF cache-purge wiring
|
|
119
|
+
* invalidates on-demand within ~1s of a merchant edit — there's no benefit
|
|
120
|
+
* to short timer-based expirations on data Cimplify owns.
|
|
96
121
|
*/
|
|
97
|
-
declare
|
|
98
|
-
declare function revalidateCategories(): Promise<void>;
|
|
99
|
-
declare function revalidateCategory(id: string): Promise<void>;
|
|
100
|
-
declare function revalidateCollections(): Promise<void>;
|
|
101
|
-
declare function revalidateCollection(id: string): Promise<void>;
|
|
102
|
-
declare function revalidateBusiness(): Promise<void>;
|
|
103
|
-
declare function revalidateBrand(): Promise<void>;
|
|
104
|
-
declare function revalidateLocations(): Promise<void>;
|
|
105
|
-
declare function revalidateLocation(id: string): Promise<void>;
|
|
106
|
-
declare function revalidatePricing(): Promise<void>;
|
|
107
|
-
declare function revalidateAddOns(): Promise<void>;
|
|
108
|
-
declare function revalidateAddOn(id: string): Promise<void>;
|
|
109
|
-
declare function revalidateSubscriptions(): Promise<void>;
|
|
110
|
-
declare function revalidateSubscription(id: string): Promise<void>;
|
|
111
|
-
declare function revalidateStock(productId?: string): Promise<void>;
|
|
122
|
+
declare const CACHE_LIFE_DEFAULT: "max";
|
|
112
123
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
124
|
+
* Short-lived cacheLife for "probe" results — empty arrays, errors, 404s,
|
|
125
|
+
* anything that *might* be a transient bad render. Resolves to `"seconds"`
|
|
126
|
+
* (stale 30s, revalidate 1s, expires 1min). Use this when the fetch returned
|
|
127
|
+
* no usable data so a momentary backend blip can't get locked into the cache
|
|
128
|
+
* for `CACHE_LIFE_DEFAULT`'s entire window.
|
|
129
|
+
*
|
|
130
|
+
* The tag still gets attached, so a real `revalidateTag(...)` from Cimplify
|
|
131
|
+
* will refresh the entry the moment the underlying data changes.
|
|
115
132
|
*/
|
|
116
|
-
declare
|
|
133
|
+
declare const CACHE_LIFE_PROBE: "seconds";
|
|
134
|
+
/** The TS type of {@link CACHE_LIFE_DEFAULT} — the `"max"` literal. */
|
|
135
|
+
type CacheLifeDefault = typeof CACHE_LIFE_DEFAULT;
|
|
136
|
+
/** The TS type of {@link CACHE_LIFE_PROBE} — the `"seconds"` literal. */
|
|
137
|
+
type CacheLifeProbe = typeof CACHE_LIFE_PROBE;
|
|
138
|
+
|
|
139
|
+
/** Next 16 cacheLife profile — a built-in name (`'max'`/`'hours'`/…) or `{expire: secs}`. */
|
|
140
|
+
type RevalidateProfile$1 = string | {
|
|
141
|
+
expire: number;
|
|
142
|
+
};
|
|
143
|
+
declare function revalidateProducts(profile?: RevalidateProfile$1): Promise<void>;
|
|
144
|
+
declare function revalidateProduct(id: string, profile?: RevalidateProfile$1): Promise<void>;
|
|
145
|
+
declare function revalidateCategories(profile?: RevalidateProfile$1): Promise<void>;
|
|
146
|
+
declare function revalidateCategory(id: string, profile?: RevalidateProfile$1): Promise<void>;
|
|
147
|
+
declare function revalidateCollections(profile?: RevalidateProfile$1): Promise<void>;
|
|
148
|
+
declare function revalidateCollection(id: string, profile?: RevalidateProfile$1): Promise<void>;
|
|
149
|
+
declare function revalidateBusiness(profile?: RevalidateProfile$1): Promise<void>;
|
|
150
|
+
declare function revalidateBrand(profile?: RevalidateProfile$1): Promise<void>;
|
|
151
|
+
declare function revalidateLocations(profile?: RevalidateProfile$1): Promise<void>;
|
|
152
|
+
declare function revalidateLocation(id: string, profile?: RevalidateProfile$1): Promise<void>;
|
|
153
|
+
declare function revalidatePricing(profile?: RevalidateProfile$1): Promise<void>;
|
|
154
|
+
declare function revalidateAddOns(profile?: RevalidateProfile$1): Promise<void>;
|
|
155
|
+
declare function revalidateAddOn(id: string, profile?: RevalidateProfile$1): Promise<void>;
|
|
156
|
+
declare function revalidateSubscriptions(profile?: RevalidateProfile$1): Promise<void>;
|
|
157
|
+
declare function revalidateSubscription(id: string, profile?: RevalidateProfile$1): Promise<void>;
|
|
158
|
+
declare function revalidateStock(productId?: string, profile?: RevalidateProfile$1): Promise<void>;
|
|
159
|
+
declare function revalidateByTag(tag: string, profile?: RevalidateProfile$1): Promise<void>;
|
|
117
160
|
|
|
161
|
+
declare function updateProducts(): Promise<void>;
|
|
162
|
+
declare function updateProduct(id: string): Promise<void>;
|
|
163
|
+
declare function updateCategories(): Promise<void>;
|
|
164
|
+
declare function updateCategory(id: string): Promise<void>;
|
|
165
|
+
declare function updateCollections(): Promise<void>;
|
|
166
|
+
declare function updateCollection(id: string): Promise<void>;
|
|
167
|
+
declare function updateBusiness(): Promise<void>;
|
|
168
|
+
declare function updateBrand(): Promise<void>;
|
|
169
|
+
declare function updateLocations(): Promise<void>;
|
|
170
|
+
declare function updateLocation(id: string): Promise<void>;
|
|
171
|
+
declare function updatePricing(): Promise<void>;
|
|
172
|
+
declare function updateAddOns(): Promise<void>;
|
|
173
|
+
declare function updateAddOn(id: string): Promise<void>;
|
|
174
|
+
declare function updateSubscriptions(): Promise<void>;
|
|
175
|
+
declare function updateSubscription(id: string): Promise<void>;
|
|
176
|
+
declare function updateStock(productId?: string): Promise<void>;
|
|
177
|
+
declare function updateByTag(tag: string): Promise<void>;
|
|
178
|
+
declare function refreshPage(): Promise<void>;
|
|
179
|
+
|
|
180
|
+
/** Next 16 cacheLife profile — a built-in name (`'max'`/`'hours'`/…) or `{expire: secs}`. */
|
|
181
|
+
type RevalidateProfile = string | {
|
|
182
|
+
expire: number;
|
|
183
|
+
};
|
|
118
184
|
interface RevalidateRouteOptions {
|
|
185
|
+
/** Defaults to `process.env.CIMPLIFY_REVALIDATE_SECRET`. */
|
|
119
186
|
secret?: string;
|
|
120
|
-
revalidateTag
|
|
187
|
+
/** Defaults to a lazy import of `next/cache.revalidateTag`. Override for tests. */
|
|
188
|
+
revalidateTag?: (tag: string, profile: RevalidateProfile) => void;
|
|
189
|
+
/** Defaults to `Date.now`. Override for tests. */
|
|
121
190
|
now?: () => number;
|
|
191
|
+
/** Profile used when the request body doesn't include one. Defaults to `'max'`. */
|
|
192
|
+
defaultProfile?: RevalidateProfile;
|
|
122
193
|
}
|
|
123
194
|
declare function revalidateRouteHandler(req: Request, options?: RevalidateRouteOptions): Promise<Response>;
|
|
124
195
|
|
|
125
|
-
export { CimplifyClient, type RevalidateRouteOptions, type ServerClientOptions, getServerClient, revalidateAddOn, revalidateAddOns, revalidateBrand, revalidateBusiness, revalidateByTag, revalidateCategories, revalidateCategory, revalidateCollection, revalidateCollections, revalidateLocation, revalidateLocations, revalidatePricing, revalidateProduct, revalidateProducts, revalidateRouteHandler, revalidateStock, revalidateSubscription, revalidateSubscriptions, tags };
|
|
196
|
+
export { CACHE_LIFE_DEFAULT, CACHE_LIFE_PROBE, type CacheLifeDefault, type CacheLifeProbe, CimplifyClient, type RevalidateProfile$1 as RevalidateProfile, type RevalidateRouteOptions, type RevalidateProfile as RevalidateRouteProfile, type ServerClientOptions, getServerClient, refreshPage, revalidateAddOn, revalidateAddOns, revalidateBrand, revalidateBusiness, revalidateByTag, revalidateCategories, revalidateCategory, revalidateCollection, revalidateCollections, revalidateLocation, revalidateLocations, revalidatePricing, revalidateProduct, revalidateProducts, revalidateRouteHandler, revalidateStock, revalidateSubscription, revalidateSubscriptions, tags, updateAddOn, updateAddOns, updateBrand, updateBusiness, updateByTag, updateCategories, updateCategory, updateCollection, updateCollections, updateLocation, updateLocations, updatePricing, updateProduct, updateProducts, updateStock, updateSubscription, updateSubscriptions };
|
package/dist/server.d.ts
CHANGED
|
@@ -85,41 +85,112 @@ declare const tags: {
|
|
|
85
85
|
};
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
88
|
+
* Cimplify's opinionated cacheLife profiles for storefront server caches.
|
|
89
|
+
*
|
|
90
|
+
* Pass either of these to Next 16's `cacheLife(...)` inside a `'use cache'`
|
|
91
|
+
* server function. They're typed-literal exports so a typo fails at the SDK
|
|
92
|
+
* import site, not silently at runtime (Next's own `cacheLife(profile: string)`
|
|
93
|
+
* overload would accept anything and look it up as a custom profile).
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* import { cacheLife } from "next/cache";
|
|
98
|
+
* import { CACHE_LIFE_DEFAULT, CACHE_LIFE_PROBE, tags } from "@cimplify/sdk/server";
|
|
99
|
+
*
|
|
100
|
+
* async function getProducts() {
|
|
101
|
+
* "use cache";
|
|
102
|
+
* cacheTag(tags.products());
|
|
103
|
+
* const r = await getServerClient().catalogue.getProducts();
|
|
104
|
+
* // Don't lock in empties / failures — a transient bad render would
|
|
105
|
+
* // otherwise sit cached for the full "max" window.
|
|
106
|
+
* if (!r.ok || r.value.items.length === 0) {
|
|
107
|
+
* cacheLife(CACHE_LIFE_PROBE);
|
|
108
|
+
* return r;
|
|
109
|
+
* }
|
|
110
|
+
* cacheLife(CACHE_LIFE_DEFAULT);
|
|
111
|
+
* return r;
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
90
114
|
*/
|
|
91
|
-
declare function revalidateProducts(): Promise<void>;
|
|
92
115
|
/**
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
116
|
+
* The default cacheLife for cached storefront reads. Resolves to `"max"`,
|
|
117
|
+
* which is Next 16's longest built-in profile (stale 5min, revalidate 30d,
|
|
118
|
+
* never expires). Safe because Cimplify's tag-cache + CF cache-purge wiring
|
|
119
|
+
* invalidates on-demand within ~1s of a merchant edit — there's no benefit
|
|
120
|
+
* to short timer-based expirations on data Cimplify owns.
|
|
96
121
|
*/
|
|
97
|
-
declare
|
|
98
|
-
declare function revalidateCategories(): Promise<void>;
|
|
99
|
-
declare function revalidateCategory(id: string): Promise<void>;
|
|
100
|
-
declare function revalidateCollections(): Promise<void>;
|
|
101
|
-
declare function revalidateCollection(id: string): Promise<void>;
|
|
102
|
-
declare function revalidateBusiness(): Promise<void>;
|
|
103
|
-
declare function revalidateBrand(): Promise<void>;
|
|
104
|
-
declare function revalidateLocations(): Promise<void>;
|
|
105
|
-
declare function revalidateLocation(id: string): Promise<void>;
|
|
106
|
-
declare function revalidatePricing(): Promise<void>;
|
|
107
|
-
declare function revalidateAddOns(): Promise<void>;
|
|
108
|
-
declare function revalidateAddOn(id: string): Promise<void>;
|
|
109
|
-
declare function revalidateSubscriptions(): Promise<void>;
|
|
110
|
-
declare function revalidateSubscription(id: string): Promise<void>;
|
|
111
|
-
declare function revalidateStock(productId?: string): Promise<void>;
|
|
122
|
+
declare const CACHE_LIFE_DEFAULT: "max";
|
|
112
123
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
124
|
+
* Short-lived cacheLife for "probe" results — empty arrays, errors, 404s,
|
|
125
|
+
* anything that *might* be a transient bad render. Resolves to `"seconds"`
|
|
126
|
+
* (stale 30s, revalidate 1s, expires 1min). Use this when the fetch returned
|
|
127
|
+
* no usable data so a momentary backend blip can't get locked into the cache
|
|
128
|
+
* for `CACHE_LIFE_DEFAULT`'s entire window.
|
|
129
|
+
*
|
|
130
|
+
* The tag still gets attached, so a real `revalidateTag(...)` from Cimplify
|
|
131
|
+
* will refresh the entry the moment the underlying data changes.
|
|
115
132
|
*/
|
|
116
|
-
declare
|
|
133
|
+
declare const CACHE_LIFE_PROBE: "seconds";
|
|
134
|
+
/** The TS type of {@link CACHE_LIFE_DEFAULT} — the `"max"` literal. */
|
|
135
|
+
type CacheLifeDefault = typeof CACHE_LIFE_DEFAULT;
|
|
136
|
+
/** The TS type of {@link CACHE_LIFE_PROBE} — the `"seconds"` literal. */
|
|
137
|
+
type CacheLifeProbe = typeof CACHE_LIFE_PROBE;
|
|
138
|
+
|
|
139
|
+
/** Next 16 cacheLife profile — a built-in name (`'max'`/`'hours'`/…) or `{expire: secs}`. */
|
|
140
|
+
type RevalidateProfile$1 = string | {
|
|
141
|
+
expire: number;
|
|
142
|
+
};
|
|
143
|
+
declare function revalidateProducts(profile?: RevalidateProfile$1): Promise<void>;
|
|
144
|
+
declare function revalidateProduct(id: string, profile?: RevalidateProfile$1): Promise<void>;
|
|
145
|
+
declare function revalidateCategories(profile?: RevalidateProfile$1): Promise<void>;
|
|
146
|
+
declare function revalidateCategory(id: string, profile?: RevalidateProfile$1): Promise<void>;
|
|
147
|
+
declare function revalidateCollections(profile?: RevalidateProfile$1): Promise<void>;
|
|
148
|
+
declare function revalidateCollection(id: string, profile?: RevalidateProfile$1): Promise<void>;
|
|
149
|
+
declare function revalidateBusiness(profile?: RevalidateProfile$1): Promise<void>;
|
|
150
|
+
declare function revalidateBrand(profile?: RevalidateProfile$1): Promise<void>;
|
|
151
|
+
declare function revalidateLocations(profile?: RevalidateProfile$1): Promise<void>;
|
|
152
|
+
declare function revalidateLocation(id: string, profile?: RevalidateProfile$1): Promise<void>;
|
|
153
|
+
declare function revalidatePricing(profile?: RevalidateProfile$1): Promise<void>;
|
|
154
|
+
declare function revalidateAddOns(profile?: RevalidateProfile$1): Promise<void>;
|
|
155
|
+
declare function revalidateAddOn(id: string, profile?: RevalidateProfile$1): Promise<void>;
|
|
156
|
+
declare function revalidateSubscriptions(profile?: RevalidateProfile$1): Promise<void>;
|
|
157
|
+
declare function revalidateSubscription(id: string, profile?: RevalidateProfile$1): Promise<void>;
|
|
158
|
+
declare function revalidateStock(productId?: string, profile?: RevalidateProfile$1): Promise<void>;
|
|
159
|
+
declare function revalidateByTag(tag: string, profile?: RevalidateProfile$1): Promise<void>;
|
|
117
160
|
|
|
161
|
+
declare function updateProducts(): Promise<void>;
|
|
162
|
+
declare function updateProduct(id: string): Promise<void>;
|
|
163
|
+
declare function updateCategories(): Promise<void>;
|
|
164
|
+
declare function updateCategory(id: string): Promise<void>;
|
|
165
|
+
declare function updateCollections(): Promise<void>;
|
|
166
|
+
declare function updateCollection(id: string): Promise<void>;
|
|
167
|
+
declare function updateBusiness(): Promise<void>;
|
|
168
|
+
declare function updateBrand(): Promise<void>;
|
|
169
|
+
declare function updateLocations(): Promise<void>;
|
|
170
|
+
declare function updateLocation(id: string): Promise<void>;
|
|
171
|
+
declare function updatePricing(): Promise<void>;
|
|
172
|
+
declare function updateAddOns(): Promise<void>;
|
|
173
|
+
declare function updateAddOn(id: string): Promise<void>;
|
|
174
|
+
declare function updateSubscriptions(): Promise<void>;
|
|
175
|
+
declare function updateSubscription(id: string): Promise<void>;
|
|
176
|
+
declare function updateStock(productId?: string): Promise<void>;
|
|
177
|
+
declare function updateByTag(tag: string): Promise<void>;
|
|
178
|
+
declare function refreshPage(): Promise<void>;
|
|
179
|
+
|
|
180
|
+
/** Next 16 cacheLife profile — a built-in name (`'max'`/`'hours'`/…) or `{expire: secs}`. */
|
|
181
|
+
type RevalidateProfile = string | {
|
|
182
|
+
expire: number;
|
|
183
|
+
};
|
|
118
184
|
interface RevalidateRouteOptions {
|
|
185
|
+
/** Defaults to `process.env.CIMPLIFY_REVALIDATE_SECRET`. */
|
|
119
186
|
secret?: string;
|
|
120
|
-
revalidateTag
|
|
187
|
+
/** Defaults to a lazy import of `next/cache.revalidateTag`. Override for tests. */
|
|
188
|
+
revalidateTag?: (tag: string, profile: RevalidateProfile) => void;
|
|
189
|
+
/** Defaults to `Date.now`. Override for tests. */
|
|
121
190
|
now?: () => number;
|
|
191
|
+
/** Profile used when the request body doesn't include one. Defaults to `'max'`. */
|
|
192
|
+
defaultProfile?: RevalidateProfile;
|
|
122
193
|
}
|
|
123
194
|
declare function revalidateRouteHandler(req: Request, options?: RevalidateRouteOptions): Promise<Response>;
|
|
124
195
|
|
|
125
|
-
export { CimplifyClient, type RevalidateRouteOptions, type ServerClientOptions, getServerClient, revalidateAddOn, revalidateAddOns, revalidateBrand, revalidateBusiness, revalidateByTag, revalidateCategories, revalidateCategory, revalidateCollection, revalidateCollections, revalidateLocation, revalidateLocations, revalidatePricing, revalidateProduct, revalidateProducts, revalidateRouteHandler, revalidateStock, revalidateSubscription, revalidateSubscriptions, tags };
|
|
196
|
+
export { CACHE_LIFE_DEFAULT, CACHE_LIFE_PROBE, type CacheLifeDefault, type CacheLifeProbe, CimplifyClient, type RevalidateProfile$1 as RevalidateProfile, type RevalidateRouteOptions, type RevalidateProfile as RevalidateRouteProfile, type ServerClientOptions, getServerClient, refreshPage, revalidateAddOn, revalidateAddOns, revalidateBrand, revalidateBusiness, revalidateByTag, revalidateCategories, revalidateCategory, revalidateCollection, revalidateCollections, revalidateLocation, revalidateLocations, revalidatePricing, revalidateProduct, revalidateProducts, revalidateRouteHandler, revalidateStock, revalidateSubscription, revalidateSubscriptions, tags, updateAddOn, updateAddOns, updateBrand, updateBusiness, updateByTag, updateCategories, updateCategory, updateCollection, updateCollections, updateLocation, updateLocations, updatePricing, updateProduct, updateProducts, updateStock, updateSubscription, updateSubscriptions };
|
package/dist/server.js
CHANGED
|
@@ -6,7 +6,12 @@ require('./chunk-6RP6OPYO.js');
|
|
|
6
6
|
var chunkTKOTACKZ_js = require('./chunk-TKOTACKZ.js');
|
|
7
7
|
var react = require('react');
|
|
8
8
|
|
|
9
|
+
var DEFAULT_PROD_URL = "https://storefronts.cimplify.io";
|
|
9
10
|
var DEFAULT_DEV_URL = "http://127.0.0.1:8787";
|
|
11
|
+
function defaultBaseUrl() {
|
|
12
|
+
const proc = globalThis.process;
|
|
13
|
+
return proc?.env?.NODE_ENV === "production" ? DEFAULT_PROD_URL : DEFAULT_DEV_URL;
|
|
14
|
+
}
|
|
10
15
|
function readEnv(...keys) {
|
|
11
16
|
const env = globalThis.process?.env;
|
|
12
17
|
if (!env) return void 0;
|
|
@@ -17,7 +22,7 @@ function readEnv(...keys) {
|
|
|
17
22
|
return void 0;
|
|
18
23
|
}
|
|
19
24
|
var getServerClient = react.cache((opts = {}) => {
|
|
20
|
-
const baseUrl = opts.apiUrl ?? readEnv("CIMPLIFY_API_URL", "NEXT_PUBLIC_CIMPLIFY_API_URL") ??
|
|
25
|
+
const baseUrl = opts.apiUrl ?? readEnv("CIMPLIFY_API_URL", "NEXT_PUBLIC_CIMPLIFY_API_URL") ?? defaultBaseUrl();
|
|
21
26
|
const publicKey = opts.secretKey ?? readEnv("CIMPLIFY_SECRET_KEY", "NEXT_PUBLIC_CIMPLIFY_PUBLIC_KEY") ?? "mock-dev";
|
|
22
27
|
const client = chunkCYGLTD7D_js.createCimplifyClient({
|
|
23
28
|
baseUrl,
|
|
@@ -58,7 +63,12 @@ var tags = {
|
|
|
58
63
|
order: (id) => `cimplify:order:${id}`
|
|
59
64
|
};
|
|
60
65
|
|
|
66
|
+
// src/server/cache-life.ts
|
|
67
|
+
var CACHE_LIFE_DEFAULT = "max";
|
|
68
|
+
var CACHE_LIFE_PROBE = "seconds";
|
|
69
|
+
|
|
61
70
|
// src/server/revalidate.ts
|
|
71
|
+
var DEFAULT_PROFILE = CACHE_LIFE_DEFAULT;
|
|
62
72
|
var _revalidateTag = null;
|
|
63
73
|
async function getRevalidateTag() {
|
|
64
74
|
if (_revalidateTag) return _revalidateTag;
|
|
@@ -71,64 +81,156 @@ async function getRevalidateTag() {
|
|
|
71
81
|
_revalidateTag = mod.revalidateTag;
|
|
72
82
|
return _revalidateTag;
|
|
73
83
|
}
|
|
74
|
-
async function revalidate(...tagList) {
|
|
84
|
+
async function revalidate(profile, ...tagList) {
|
|
75
85
|
const fn = await getRevalidateTag();
|
|
76
|
-
for (const t of tagList) fn(t);
|
|
86
|
+
for (const t of tagList) fn(t, profile);
|
|
77
87
|
}
|
|
78
|
-
async function revalidateProducts() {
|
|
79
|
-
return revalidate(tags.products());
|
|
88
|
+
async function revalidateProducts(profile = DEFAULT_PROFILE) {
|
|
89
|
+
return revalidate(profile, tags.products());
|
|
80
90
|
}
|
|
81
|
-
async function revalidateProduct(id) {
|
|
82
|
-
return revalidate(tags.product(id), tags.products());
|
|
91
|
+
async function revalidateProduct(id, profile = DEFAULT_PROFILE) {
|
|
92
|
+
return revalidate(profile, tags.product(id), tags.products());
|
|
83
93
|
}
|
|
84
|
-
async function revalidateCategories() {
|
|
85
|
-
return revalidate(tags.categories());
|
|
94
|
+
async function revalidateCategories(profile = DEFAULT_PROFILE) {
|
|
95
|
+
return revalidate(profile, tags.categories());
|
|
86
96
|
}
|
|
87
|
-
async function revalidateCategory(id) {
|
|
88
|
-
return revalidate(tags.category(id), tags.categoryProducts(id), tags.categories());
|
|
97
|
+
async function revalidateCategory(id, profile = DEFAULT_PROFILE) {
|
|
98
|
+
return revalidate(profile, tags.category(id), tags.categoryProducts(id), tags.categories());
|
|
89
99
|
}
|
|
90
|
-
async function revalidateCollections() {
|
|
91
|
-
return revalidate(tags.collections());
|
|
100
|
+
async function revalidateCollections(profile = DEFAULT_PROFILE) {
|
|
101
|
+
return revalidate(profile, tags.collections());
|
|
92
102
|
}
|
|
93
|
-
async function revalidateCollection(id) {
|
|
103
|
+
async function revalidateCollection(id, profile = DEFAULT_PROFILE) {
|
|
94
104
|
return revalidate(
|
|
105
|
+
profile,
|
|
95
106
|
tags.collection(id),
|
|
96
107
|
tags.collectionProducts(id),
|
|
97
108
|
tags.collections()
|
|
98
109
|
);
|
|
99
110
|
}
|
|
100
|
-
async function revalidateBusiness() {
|
|
101
|
-
return revalidate(tags.business());
|
|
111
|
+
async function revalidateBusiness(profile = DEFAULT_PROFILE) {
|
|
112
|
+
return revalidate(profile, tags.business());
|
|
113
|
+
}
|
|
114
|
+
async function revalidateBrand(profile = DEFAULT_PROFILE) {
|
|
115
|
+
return revalidate(profile, tags.brand());
|
|
116
|
+
}
|
|
117
|
+
async function revalidateLocations(profile = DEFAULT_PROFILE) {
|
|
118
|
+
return revalidate(profile, tags.locations());
|
|
119
|
+
}
|
|
120
|
+
async function revalidateLocation(id, profile = DEFAULT_PROFILE) {
|
|
121
|
+
return revalidate(profile, tags.location(id), tags.locations());
|
|
122
|
+
}
|
|
123
|
+
async function revalidatePricing(profile = DEFAULT_PROFILE) {
|
|
124
|
+
return revalidate(profile, tags.pricing(), tags.products());
|
|
125
|
+
}
|
|
126
|
+
async function revalidateAddOns(profile = DEFAULT_PROFILE) {
|
|
127
|
+
return revalidate(profile, tags.addons());
|
|
128
|
+
}
|
|
129
|
+
async function revalidateAddOn(id, profile = DEFAULT_PROFILE) {
|
|
130
|
+
return revalidate(profile, tags.addon(id), tags.addons());
|
|
131
|
+
}
|
|
132
|
+
async function revalidateSubscriptions(profile = DEFAULT_PROFILE) {
|
|
133
|
+
return revalidate(profile, tags.subscriptions());
|
|
134
|
+
}
|
|
135
|
+
async function revalidateSubscription(id, profile = DEFAULT_PROFILE) {
|
|
136
|
+
return revalidate(profile, tags.subscription(id), tags.subscriptions());
|
|
137
|
+
}
|
|
138
|
+
async function revalidateStock(productId, profile = DEFAULT_PROFILE) {
|
|
139
|
+
return productId ? revalidate(profile, tags.stockFor(productId), tags.stock()) : revalidate(profile, tags.stock());
|
|
140
|
+
}
|
|
141
|
+
async function revalidateByTag(tag, profile = DEFAULT_PROFILE) {
|
|
142
|
+
return revalidate(profile, tag);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// src/server/update.ts
|
|
146
|
+
var _updateTag = null;
|
|
147
|
+
var _refresh = null;
|
|
148
|
+
async function getUpdateTag() {
|
|
149
|
+
if (_updateTag) return _updateTag;
|
|
150
|
+
const specifier = "next/cache";
|
|
151
|
+
const mod = await import(
|
|
152
|
+
/* webpackIgnore: true */
|
|
153
|
+
/* @vite-ignore */
|
|
154
|
+
specifier
|
|
155
|
+
);
|
|
156
|
+
if (!mod.updateTag) {
|
|
157
|
+
throw new Error("updateTag is not exported from next/cache \u2014 requires Next 16+");
|
|
158
|
+
}
|
|
159
|
+
_updateTag = mod.updateTag;
|
|
160
|
+
return _updateTag;
|
|
161
|
+
}
|
|
162
|
+
async function getRefresh() {
|
|
163
|
+
if (_refresh) return _refresh;
|
|
164
|
+
const specifier = "next/cache";
|
|
165
|
+
const mod = await import(
|
|
166
|
+
/* webpackIgnore: true */
|
|
167
|
+
/* @vite-ignore */
|
|
168
|
+
specifier
|
|
169
|
+
);
|
|
170
|
+
if (!mod.refresh) {
|
|
171
|
+
throw new Error("refresh is not exported from next/cache \u2014 requires Next 16+");
|
|
172
|
+
}
|
|
173
|
+
_refresh = mod.refresh;
|
|
174
|
+
return _refresh;
|
|
175
|
+
}
|
|
176
|
+
async function update(...tagList) {
|
|
177
|
+
const fn = await getUpdateTag();
|
|
178
|
+
for (const t of tagList) fn(t);
|
|
179
|
+
}
|
|
180
|
+
async function updateProducts() {
|
|
181
|
+
return update(tags.products());
|
|
182
|
+
}
|
|
183
|
+
async function updateProduct(id) {
|
|
184
|
+
return update(tags.product(id), tags.products());
|
|
185
|
+
}
|
|
186
|
+
async function updateCategories() {
|
|
187
|
+
return update(tags.categories());
|
|
188
|
+
}
|
|
189
|
+
async function updateCategory(id) {
|
|
190
|
+
return update(tags.category(id), tags.categoryProducts(id), tags.categories());
|
|
191
|
+
}
|
|
192
|
+
async function updateCollections() {
|
|
193
|
+
return update(tags.collections());
|
|
194
|
+
}
|
|
195
|
+
async function updateCollection(id) {
|
|
196
|
+
return update(tags.collection(id), tags.collectionProducts(id), tags.collections());
|
|
102
197
|
}
|
|
103
|
-
async function
|
|
104
|
-
return
|
|
198
|
+
async function updateBusiness() {
|
|
199
|
+
return update(tags.business());
|
|
105
200
|
}
|
|
106
|
-
async function
|
|
107
|
-
return
|
|
201
|
+
async function updateBrand() {
|
|
202
|
+
return update(tags.brand());
|
|
108
203
|
}
|
|
109
|
-
async function
|
|
110
|
-
return
|
|
204
|
+
async function updateLocations() {
|
|
205
|
+
return update(tags.locations());
|
|
111
206
|
}
|
|
112
|
-
async function
|
|
113
|
-
return
|
|
207
|
+
async function updateLocation(id) {
|
|
208
|
+
return update(tags.location(id), tags.locations());
|
|
114
209
|
}
|
|
115
|
-
async function
|
|
116
|
-
return
|
|
210
|
+
async function updatePricing() {
|
|
211
|
+
return update(tags.pricing(), tags.products());
|
|
117
212
|
}
|
|
118
|
-
async function
|
|
119
|
-
return
|
|
213
|
+
async function updateAddOns() {
|
|
214
|
+
return update(tags.addons());
|
|
120
215
|
}
|
|
121
|
-
async function
|
|
122
|
-
return
|
|
216
|
+
async function updateAddOn(id) {
|
|
217
|
+
return update(tags.addon(id), tags.addons());
|
|
123
218
|
}
|
|
124
|
-
async function
|
|
125
|
-
return
|
|
219
|
+
async function updateSubscriptions() {
|
|
220
|
+
return update(tags.subscriptions());
|
|
126
221
|
}
|
|
127
|
-
async function
|
|
128
|
-
return
|
|
222
|
+
async function updateSubscription(id) {
|
|
223
|
+
return update(tags.subscription(id), tags.subscriptions());
|
|
129
224
|
}
|
|
130
|
-
async function
|
|
131
|
-
return
|
|
225
|
+
async function updateStock(productId) {
|
|
226
|
+
return productId ? update(tags.stockFor(productId), tags.stock()) : update(tags.stock());
|
|
227
|
+
}
|
|
228
|
+
async function updateByTag(tag) {
|
|
229
|
+
return update(tag);
|
|
230
|
+
}
|
|
231
|
+
async function refreshPage() {
|
|
232
|
+
const fn = await getRefresh();
|
|
233
|
+
fn();
|
|
132
234
|
}
|
|
133
235
|
|
|
134
236
|
// src/server/revalidate-route.ts
|
|
@@ -137,6 +239,7 @@ var SIGNATURE_HEADER = "x-cimplify-signature";
|
|
|
137
239
|
var SIGNATURE_PREFIX = "sha256=";
|
|
138
240
|
var MAX_SKEW_MS = 5 * 60 * 1e3;
|
|
139
241
|
var SECRET_ENV = "CIMPLIFY_REVALIDATE_SECRET";
|
|
242
|
+
var DEFAULT_PROFILE2 = CACHE_LIFE_DEFAULT;
|
|
140
243
|
async function revalidateRouteHandler(req, options = {}) {
|
|
141
244
|
const secret = options.secret ?? envSecret();
|
|
142
245
|
if (!secret) return text(`revalidate disabled: ${SECRET_ENV} not set`, 500);
|
|
@@ -160,9 +263,17 @@ async function revalidateRouteHandler(req, options = {}) {
|
|
|
160
263
|
}
|
|
161
264
|
const tags2 = Array.isArray(parsed.tags) ? parsed.tags.filter((t) => typeof t === "string" && t.length > 0) : [];
|
|
162
265
|
if (tags2.length === 0) return text("no tags", 400);
|
|
266
|
+
const profile = parseProfile(parsed.profile) ?? options.defaultProfile ?? DEFAULT_PROFILE2;
|
|
163
267
|
const revalidate2 = options.revalidateTag ?? await loadRevalidateTag();
|
|
164
|
-
for (const tag of tags2) revalidate2(tag);
|
|
165
|
-
return Response.json({ ok: true, revalidated: tags2.length });
|
|
268
|
+
for (const tag of tags2) revalidate2(tag, profile);
|
|
269
|
+
return Response.json({ ok: true, revalidated: tags2.length, profile });
|
|
270
|
+
}
|
|
271
|
+
function parseProfile(raw) {
|
|
272
|
+
if (typeof raw === "string" && raw.length > 0) return raw;
|
|
273
|
+
if (raw && typeof raw === "object" && "expire" in raw && typeof raw.expire === "number") {
|
|
274
|
+
return { expire: raw.expire };
|
|
275
|
+
}
|
|
276
|
+
return void 0;
|
|
166
277
|
}
|
|
167
278
|
var cachedRevalidateTag = null;
|
|
168
279
|
async function loadRevalidateTag() {
|
|
@@ -211,7 +322,10 @@ Object.defineProperty(exports, "CimplifyError", {
|
|
|
211
322
|
enumerable: true,
|
|
212
323
|
get: function () { return chunkTKOTACKZ_js.CimplifyError; }
|
|
213
324
|
});
|
|
325
|
+
exports.CACHE_LIFE_DEFAULT = CACHE_LIFE_DEFAULT;
|
|
326
|
+
exports.CACHE_LIFE_PROBE = CACHE_LIFE_PROBE;
|
|
214
327
|
exports.getServerClient = getServerClient;
|
|
328
|
+
exports.refreshPage = refreshPage;
|
|
215
329
|
exports.revalidateAddOn = revalidateAddOn;
|
|
216
330
|
exports.revalidateAddOns = revalidateAddOns;
|
|
217
331
|
exports.revalidateBrand = revalidateBrand;
|
|
@@ -231,3 +345,20 @@ exports.revalidateStock = revalidateStock;
|
|
|
231
345
|
exports.revalidateSubscription = revalidateSubscription;
|
|
232
346
|
exports.revalidateSubscriptions = revalidateSubscriptions;
|
|
233
347
|
exports.tags = tags;
|
|
348
|
+
exports.updateAddOn = updateAddOn;
|
|
349
|
+
exports.updateAddOns = updateAddOns;
|
|
350
|
+
exports.updateBrand = updateBrand;
|
|
351
|
+
exports.updateBusiness = updateBusiness;
|
|
352
|
+
exports.updateByTag = updateByTag;
|
|
353
|
+
exports.updateCategories = updateCategories;
|
|
354
|
+
exports.updateCategory = updateCategory;
|
|
355
|
+
exports.updateCollection = updateCollection;
|
|
356
|
+
exports.updateCollections = updateCollections;
|
|
357
|
+
exports.updateLocation = updateLocation;
|
|
358
|
+
exports.updateLocations = updateLocations;
|
|
359
|
+
exports.updatePricing = updatePricing;
|
|
360
|
+
exports.updateProduct = updateProduct;
|
|
361
|
+
exports.updateProducts = updateProducts;
|
|
362
|
+
exports.updateStock = updateStock;
|
|
363
|
+
exports.updateSubscription = updateSubscription;
|
|
364
|
+
exports.updateSubscriptions = updateSubscriptions;
|
package/dist/server.mjs
CHANGED
|
@@ -4,7 +4,12 @@ import './chunk-XY2DFX5K.mjs';
|
|
|
4
4
|
export { CimplifyError } from './chunk-Z2AYLZDF.mjs';
|
|
5
5
|
import { cache } from 'react';
|
|
6
6
|
|
|
7
|
+
var DEFAULT_PROD_URL = "https://storefronts.cimplify.io";
|
|
7
8
|
var DEFAULT_DEV_URL = "http://127.0.0.1:8787";
|
|
9
|
+
function defaultBaseUrl() {
|
|
10
|
+
const proc = globalThis.process;
|
|
11
|
+
return proc?.env?.NODE_ENV === "production" ? DEFAULT_PROD_URL : DEFAULT_DEV_URL;
|
|
12
|
+
}
|
|
8
13
|
function readEnv(...keys) {
|
|
9
14
|
const env = globalThis.process?.env;
|
|
10
15
|
if (!env) return void 0;
|
|
@@ -15,7 +20,7 @@ function readEnv(...keys) {
|
|
|
15
20
|
return void 0;
|
|
16
21
|
}
|
|
17
22
|
var getServerClient = cache((opts = {}) => {
|
|
18
|
-
const baseUrl = opts.apiUrl ?? readEnv("CIMPLIFY_API_URL", "NEXT_PUBLIC_CIMPLIFY_API_URL") ??
|
|
23
|
+
const baseUrl = opts.apiUrl ?? readEnv("CIMPLIFY_API_URL", "NEXT_PUBLIC_CIMPLIFY_API_URL") ?? defaultBaseUrl();
|
|
19
24
|
const publicKey = opts.secretKey ?? readEnv("CIMPLIFY_SECRET_KEY", "NEXT_PUBLIC_CIMPLIFY_PUBLIC_KEY") ?? "mock-dev";
|
|
20
25
|
const client = createCimplifyClient({
|
|
21
26
|
baseUrl,
|
|
@@ -56,7 +61,12 @@ var tags = {
|
|
|
56
61
|
order: (id) => `cimplify:order:${id}`
|
|
57
62
|
};
|
|
58
63
|
|
|
64
|
+
// src/server/cache-life.ts
|
|
65
|
+
var CACHE_LIFE_DEFAULT = "max";
|
|
66
|
+
var CACHE_LIFE_PROBE = "seconds";
|
|
67
|
+
|
|
59
68
|
// src/server/revalidate.ts
|
|
69
|
+
var DEFAULT_PROFILE = CACHE_LIFE_DEFAULT;
|
|
60
70
|
var _revalidateTag = null;
|
|
61
71
|
async function getRevalidateTag() {
|
|
62
72
|
if (_revalidateTag) return _revalidateTag;
|
|
@@ -69,64 +79,156 @@ async function getRevalidateTag() {
|
|
|
69
79
|
_revalidateTag = mod.revalidateTag;
|
|
70
80
|
return _revalidateTag;
|
|
71
81
|
}
|
|
72
|
-
async function revalidate(...tagList) {
|
|
82
|
+
async function revalidate(profile, ...tagList) {
|
|
73
83
|
const fn = await getRevalidateTag();
|
|
74
|
-
for (const t of tagList) fn(t);
|
|
84
|
+
for (const t of tagList) fn(t, profile);
|
|
75
85
|
}
|
|
76
|
-
async function revalidateProducts() {
|
|
77
|
-
return revalidate(tags.products());
|
|
86
|
+
async function revalidateProducts(profile = DEFAULT_PROFILE) {
|
|
87
|
+
return revalidate(profile, tags.products());
|
|
78
88
|
}
|
|
79
|
-
async function revalidateProduct(id) {
|
|
80
|
-
return revalidate(tags.product(id), tags.products());
|
|
89
|
+
async function revalidateProduct(id, profile = DEFAULT_PROFILE) {
|
|
90
|
+
return revalidate(profile, tags.product(id), tags.products());
|
|
81
91
|
}
|
|
82
|
-
async function revalidateCategories() {
|
|
83
|
-
return revalidate(tags.categories());
|
|
92
|
+
async function revalidateCategories(profile = DEFAULT_PROFILE) {
|
|
93
|
+
return revalidate(profile, tags.categories());
|
|
84
94
|
}
|
|
85
|
-
async function revalidateCategory(id) {
|
|
86
|
-
return revalidate(tags.category(id), tags.categoryProducts(id), tags.categories());
|
|
95
|
+
async function revalidateCategory(id, profile = DEFAULT_PROFILE) {
|
|
96
|
+
return revalidate(profile, tags.category(id), tags.categoryProducts(id), tags.categories());
|
|
87
97
|
}
|
|
88
|
-
async function revalidateCollections() {
|
|
89
|
-
return revalidate(tags.collections());
|
|
98
|
+
async function revalidateCollections(profile = DEFAULT_PROFILE) {
|
|
99
|
+
return revalidate(profile, tags.collections());
|
|
90
100
|
}
|
|
91
|
-
async function revalidateCollection(id) {
|
|
101
|
+
async function revalidateCollection(id, profile = DEFAULT_PROFILE) {
|
|
92
102
|
return revalidate(
|
|
103
|
+
profile,
|
|
93
104
|
tags.collection(id),
|
|
94
105
|
tags.collectionProducts(id),
|
|
95
106
|
tags.collections()
|
|
96
107
|
);
|
|
97
108
|
}
|
|
98
|
-
async function revalidateBusiness() {
|
|
99
|
-
return revalidate(tags.business());
|
|
109
|
+
async function revalidateBusiness(profile = DEFAULT_PROFILE) {
|
|
110
|
+
return revalidate(profile, tags.business());
|
|
111
|
+
}
|
|
112
|
+
async function revalidateBrand(profile = DEFAULT_PROFILE) {
|
|
113
|
+
return revalidate(profile, tags.brand());
|
|
114
|
+
}
|
|
115
|
+
async function revalidateLocations(profile = DEFAULT_PROFILE) {
|
|
116
|
+
return revalidate(profile, tags.locations());
|
|
117
|
+
}
|
|
118
|
+
async function revalidateLocation(id, profile = DEFAULT_PROFILE) {
|
|
119
|
+
return revalidate(profile, tags.location(id), tags.locations());
|
|
120
|
+
}
|
|
121
|
+
async function revalidatePricing(profile = DEFAULT_PROFILE) {
|
|
122
|
+
return revalidate(profile, tags.pricing(), tags.products());
|
|
123
|
+
}
|
|
124
|
+
async function revalidateAddOns(profile = DEFAULT_PROFILE) {
|
|
125
|
+
return revalidate(profile, tags.addons());
|
|
126
|
+
}
|
|
127
|
+
async function revalidateAddOn(id, profile = DEFAULT_PROFILE) {
|
|
128
|
+
return revalidate(profile, tags.addon(id), tags.addons());
|
|
129
|
+
}
|
|
130
|
+
async function revalidateSubscriptions(profile = DEFAULT_PROFILE) {
|
|
131
|
+
return revalidate(profile, tags.subscriptions());
|
|
132
|
+
}
|
|
133
|
+
async function revalidateSubscription(id, profile = DEFAULT_PROFILE) {
|
|
134
|
+
return revalidate(profile, tags.subscription(id), tags.subscriptions());
|
|
135
|
+
}
|
|
136
|
+
async function revalidateStock(productId, profile = DEFAULT_PROFILE) {
|
|
137
|
+
return productId ? revalidate(profile, tags.stockFor(productId), tags.stock()) : revalidate(profile, tags.stock());
|
|
138
|
+
}
|
|
139
|
+
async function revalidateByTag(tag, profile = DEFAULT_PROFILE) {
|
|
140
|
+
return revalidate(profile, tag);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// src/server/update.ts
|
|
144
|
+
var _updateTag = null;
|
|
145
|
+
var _refresh = null;
|
|
146
|
+
async function getUpdateTag() {
|
|
147
|
+
if (_updateTag) return _updateTag;
|
|
148
|
+
const specifier = "next/cache";
|
|
149
|
+
const mod = await import(
|
|
150
|
+
/* webpackIgnore: true */
|
|
151
|
+
/* @vite-ignore */
|
|
152
|
+
specifier
|
|
153
|
+
);
|
|
154
|
+
if (!mod.updateTag) {
|
|
155
|
+
throw new Error("updateTag is not exported from next/cache \u2014 requires Next 16+");
|
|
156
|
+
}
|
|
157
|
+
_updateTag = mod.updateTag;
|
|
158
|
+
return _updateTag;
|
|
159
|
+
}
|
|
160
|
+
async function getRefresh() {
|
|
161
|
+
if (_refresh) return _refresh;
|
|
162
|
+
const specifier = "next/cache";
|
|
163
|
+
const mod = await import(
|
|
164
|
+
/* webpackIgnore: true */
|
|
165
|
+
/* @vite-ignore */
|
|
166
|
+
specifier
|
|
167
|
+
);
|
|
168
|
+
if (!mod.refresh) {
|
|
169
|
+
throw new Error("refresh is not exported from next/cache \u2014 requires Next 16+");
|
|
170
|
+
}
|
|
171
|
+
_refresh = mod.refresh;
|
|
172
|
+
return _refresh;
|
|
173
|
+
}
|
|
174
|
+
async function update(...tagList) {
|
|
175
|
+
const fn = await getUpdateTag();
|
|
176
|
+
for (const t of tagList) fn(t);
|
|
177
|
+
}
|
|
178
|
+
async function updateProducts() {
|
|
179
|
+
return update(tags.products());
|
|
180
|
+
}
|
|
181
|
+
async function updateProduct(id) {
|
|
182
|
+
return update(tags.product(id), tags.products());
|
|
183
|
+
}
|
|
184
|
+
async function updateCategories() {
|
|
185
|
+
return update(tags.categories());
|
|
186
|
+
}
|
|
187
|
+
async function updateCategory(id) {
|
|
188
|
+
return update(tags.category(id), tags.categoryProducts(id), tags.categories());
|
|
189
|
+
}
|
|
190
|
+
async function updateCollections() {
|
|
191
|
+
return update(tags.collections());
|
|
192
|
+
}
|
|
193
|
+
async function updateCollection(id) {
|
|
194
|
+
return update(tags.collection(id), tags.collectionProducts(id), tags.collections());
|
|
100
195
|
}
|
|
101
|
-
async function
|
|
102
|
-
return
|
|
196
|
+
async function updateBusiness() {
|
|
197
|
+
return update(tags.business());
|
|
103
198
|
}
|
|
104
|
-
async function
|
|
105
|
-
return
|
|
199
|
+
async function updateBrand() {
|
|
200
|
+
return update(tags.brand());
|
|
106
201
|
}
|
|
107
|
-
async function
|
|
108
|
-
return
|
|
202
|
+
async function updateLocations() {
|
|
203
|
+
return update(tags.locations());
|
|
109
204
|
}
|
|
110
|
-
async function
|
|
111
|
-
return
|
|
205
|
+
async function updateLocation(id) {
|
|
206
|
+
return update(tags.location(id), tags.locations());
|
|
112
207
|
}
|
|
113
|
-
async function
|
|
114
|
-
return
|
|
208
|
+
async function updatePricing() {
|
|
209
|
+
return update(tags.pricing(), tags.products());
|
|
115
210
|
}
|
|
116
|
-
async function
|
|
117
|
-
return
|
|
211
|
+
async function updateAddOns() {
|
|
212
|
+
return update(tags.addons());
|
|
118
213
|
}
|
|
119
|
-
async function
|
|
120
|
-
return
|
|
214
|
+
async function updateAddOn(id) {
|
|
215
|
+
return update(tags.addon(id), tags.addons());
|
|
121
216
|
}
|
|
122
|
-
async function
|
|
123
|
-
return
|
|
217
|
+
async function updateSubscriptions() {
|
|
218
|
+
return update(tags.subscriptions());
|
|
124
219
|
}
|
|
125
|
-
async function
|
|
126
|
-
return
|
|
220
|
+
async function updateSubscription(id) {
|
|
221
|
+
return update(tags.subscription(id), tags.subscriptions());
|
|
127
222
|
}
|
|
128
|
-
async function
|
|
129
|
-
return
|
|
223
|
+
async function updateStock(productId) {
|
|
224
|
+
return productId ? update(tags.stockFor(productId), tags.stock()) : update(tags.stock());
|
|
225
|
+
}
|
|
226
|
+
async function updateByTag(tag) {
|
|
227
|
+
return update(tag);
|
|
228
|
+
}
|
|
229
|
+
async function refreshPage() {
|
|
230
|
+
const fn = await getRefresh();
|
|
231
|
+
fn();
|
|
130
232
|
}
|
|
131
233
|
|
|
132
234
|
// src/server/revalidate-route.ts
|
|
@@ -135,6 +237,7 @@ var SIGNATURE_HEADER = "x-cimplify-signature";
|
|
|
135
237
|
var SIGNATURE_PREFIX = "sha256=";
|
|
136
238
|
var MAX_SKEW_MS = 5 * 60 * 1e3;
|
|
137
239
|
var SECRET_ENV = "CIMPLIFY_REVALIDATE_SECRET";
|
|
240
|
+
var DEFAULT_PROFILE2 = CACHE_LIFE_DEFAULT;
|
|
138
241
|
async function revalidateRouteHandler(req, options = {}) {
|
|
139
242
|
const secret = options.secret ?? envSecret();
|
|
140
243
|
if (!secret) return text(`revalidate disabled: ${SECRET_ENV} not set`, 500);
|
|
@@ -158,9 +261,17 @@ async function revalidateRouteHandler(req, options = {}) {
|
|
|
158
261
|
}
|
|
159
262
|
const tags2 = Array.isArray(parsed.tags) ? parsed.tags.filter((t) => typeof t === "string" && t.length > 0) : [];
|
|
160
263
|
if (tags2.length === 0) return text("no tags", 400);
|
|
264
|
+
const profile = parseProfile(parsed.profile) ?? options.defaultProfile ?? DEFAULT_PROFILE2;
|
|
161
265
|
const revalidate2 = options.revalidateTag ?? await loadRevalidateTag();
|
|
162
|
-
for (const tag of tags2) revalidate2(tag);
|
|
163
|
-
return Response.json({ ok: true, revalidated: tags2.length });
|
|
266
|
+
for (const tag of tags2) revalidate2(tag, profile);
|
|
267
|
+
return Response.json({ ok: true, revalidated: tags2.length, profile });
|
|
268
|
+
}
|
|
269
|
+
function parseProfile(raw) {
|
|
270
|
+
if (typeof raw === "string" && raw.length > 0) return raw;
|
|
271
|
+
if (raw && typeof raw === "object" && "expire" in raw && typeof raw.expire === "number") {
|
|
272
|
+
return { expire: raw.expire };
|
|
273
|
+
}
|
|
274
|
+
return void 0;
|
|
164
275
|
}
|
|
165
276
|
var cachedRevalidateTag = null;
|
|
166
277
|
async function loadRevalidateTag() {
|
|
@@ -205,4 +316,4 @@ function text(message, status) {
|
|
|
205
316
|
return new Response(message, { status, headers: { "content-type": "text/plain" } });
|
|
206
317
|
}
|
|
207
318
|
|
|
208
|
-
export { getServerClient, revalidateAddOn, revalidateAddOns, revalidateBrand, revalidateBusiness, revalidateByTag, revalidateCategories, revalidateCategory, revalidateCollection, revalidateCollections, revalidateLocation, revalidateLocations, revalidatePricing, revalidateProduct, revalidateProducts, revalidateRouteHandler, revalidateStock, revalidateSubscription, revalidateSubscriptions, tags };
|
|
319
|
+
export { CACHE_LIFE_DEFAULT, CACHE_LIFE_PROBE, getServerClient, refreshPage, revalidateAddOn, revalidateAddOns, revalidateBrand, revalidateBusiness, revalidateByTag, revalidateCategories, revalidateCategory, revalidateCollection, revalidateCollections, revalidateLocation, revalidateLocations, revalidatePricing, revalidateProduct, revalidateProducts, revalidateRouteHandler, revalidateStock, revalidateSubscription, revalidateSubscriptions, tags, updateAddOn, updateAddOns, updateBrand, updateBusiness, updateByTag, updateCategories, updateCategory, updateCollection, updateCollections, updateLocation, updateLocations, updatePricing, updateProduct, updateProducts, updateStock, updateSubscription, updateSubscriptions };
|