@cimplify/sdk 0.49.1 → 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 +59 -25
- package/dist/server.d.ts +59 -25
- package/dist/server.js +14 -3
- package/dist/server.mjs +13 -4
- package/package.json +1 -1
package/dist/server.d.mts
CHANGED
|
@@ -84,21 +84,63 @@ declare const tags: {
|
|
|
84
84
|
readonly order: (id: string) => string;
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
-
/** Next 16 `revalidateTag` profile arg — built-in name (`'max'`/`'hours'`/…) or `{expire: secs}`. */
|
|
88
|
-
type RevalidateProfile$1 = string | {
|
|
89
|
-
expire: number;
|
|
90
|
-
};
|
|
91
87
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
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
|
+
* ```
|
|
95
114
|
*/
|
|
96
|
-
declare function revalidateProducts(profile?: RevalidateProfile$1): Promise<void>;
|
|
97
115
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
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.
|
|
101
121
|
*/
|
|
122
|
+
declare const CACHE_LIFE_DEFAULT: "max";
|
|
123
|
+
/**
|
|
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.
|
|
132
|
+
*/
|
|
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>;
|
|
102
144
|
declare function revalidateProduct(id: string, profile?: RevalidateProfile$1): Promise<void>;
|
|
103
145
|
declare function revalidateCategories(profile?: RevalidateProfile$1): Promise<void>;
|
|
104
146
|
declare function revalidateCategory(id: string, profile?: RevalidateProfile$1): Promise<void>;
|
|
@@ -114,15 +156,9 @@ declare function revalidateAddOn(id: string, profile?: RevalidateProfile$1): Pro
|
|
|
114
156
|
declare function revalidateSubscriptions(profile?: RevalidateProfile$1): Promise<void>;
|
|
115
157
|
declare function revalidateSubscription(id: string, profile?: RevalidateProfile$1): Promise<void>;
|
|
116
158
|
declare function revalidateStock(productId?: string, profile?: RevalidateProfile$1): Promise<void>;
|
|
117
|
-
/**
|
|
118
|
-
* Escape hatch: invalidate by raw tag string. Prefer the typed helpers
|
|
119
|
-
* above where possible — they keep the tag scheme in one place.
|
|
120
|
-
*/
|
|
121
159
|
declare function revalidateByTag(tag: string, profile?: RevalidateProfile$1): Promise<void>;
|
|
122
160
|
|
|
123
|
-
/** Expire the products list with read-your-writes. Call from a Server Action that creates / deletes / reorders. */
|
|
124
161
|
declare function updateProducts(): Promise<void>;
|
|
125
|
-
/** Expire a single product + the products list with read-your-writes. */
|
|
126
162
|
declare function updateProduct(id: string): Promise<void>;
|
|
127
163
|
declare function updateCategories(): Promise<void>;
|
|
128
164
|
declare function updateCategory(id: string): Promise<void>;
|
|
@@ -138,25 +174,23 @@ declare function updateAddOn(id: string): Promise<void>;
|
|
|
138
174
|
declare function updateSubscriptions(): Promise<void>;
|
|
139
175
|
declare function updateSubscription(id: string): Promise<void>;
|
|
140
176
|
declare function updateStock(productId?: string): Promise<void>;
|
|
141
|
-
/** Escape hatch: expire a raw tag with read-your-writes. Prefer the typed helpers above. */
|
|
142
177
|
declare function updateByTag(tag: string): Promise<void>;
|
|
143
|
-
/**
|
|
144
|
-
* Refresh uncached data on the current page (notification counts, live
|
|
145
|
-
* metrics, status indicators). Server-Action-only. Complements
|
|
146
|
-
* `router.refresh()` on the client.
|
|
147
|
-
*/
|
|
148
178
|
declare function refreshPage(): Promise<void>;
|
|
149
179
|
|
|
150
|
-
/** Next 16
|
|
180
|
+
/** Next 16 cacheLife profile — a built-in name (`'max'`/`'hours'`/…) or `{expire: secs}`. */
|
|
151
181
|
type RevalidateProfile = string | {
|
|
152
182
|
expire: number;
|
|
153
183
|
};
|
|
154
184
|
interface RevalidateRouteOptions {
|
|
185
|
+
/** Defaults to `process.env.CIMPLIFY_REVALIDATE_SECRET`. */
|
|
155
186
|
secret?: string;
|
|
187
|
+
/** Defaults to a lazy import of `next/cache.revalidateTag`. Override for tests. */
|
|
156
188
|
revalidateTag?: (tag: string, profile: RevalidateProfile) => void;
|
|
189
|
+
/** Defaults to `Date.now`. Override for tests. */
|
|
157
190
|
now?: () => number;
|
|
191
|
+
/** Profile used when the request body doesn't include one. Defaults to `'max'`. */
|
|
158
192
|
defaultProfile?: RevalidateProfile;
|
|
159
193
|
}
|
|
160
194
|
declare function revalidateRouteHandler(req: Request, options?: RevalidateRouteOptions): Promise<Response>;
|
|
161
195
|
|
|
162
|
-
export { 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 };
|
|
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
|
@@ -84,21 +84,63 @@ declare const tags: {
|
|
|
84
84
|
readonly order: (id: string) => string;
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
-
/** Next 16 `revalidateTag` profile arg — built-in name (`'max'`/`'hours'`/…) or `{expire: secs}`. */
|
|
88
|
-
type RevalidateProfile$1 = string | {
|
|
89
|
-
expire: number;
|
|
90
|
-
};
|
|
91
87
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
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
|
+
* ```
|
|
95
114
|
*/
|
|
96
|
-
declare function revalidateProducts(profile?: RevalidateProfile$1): Promise<void>;
|
|
97
115
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
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.
|
|
101
121
|
*/
|
|
122
|
+
declare const CACHE_LIFE_DEFAULT: "max";
|
|
123
|
+
/**
|
|
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.
|
|
132
|
+
*/
|
|
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>;
|
|
102
144
|
declare function revalidateProduct(id: string, profile?: RevalidateProfile$1): Promise<void>;
|
|
103
145
|
declare function revalidateCategories(profile?: RevalidateProfile$1): Promise<void>;
|
|
104
146
|
declare function revalidateCategory(id: string, profile?: RevalidateProfile$1): Promise<void>;
|
|
@@ -114,15 +156,9 @@ declare function revalidateAddOn(id: string, profile?: RevalidateProfile$1): Pro
|
|
|
114
156
|
declare function revalidateSubscriptions(profile?: RevalidateProfile$1): Promise<void>;
|
|
115
157
|
declare function revalidateSubscription(id: string, profile?: RevalidateProfile$1): Promise<void>;
|
|
116
158
|
declare function revalidateStock(productId?: string, profile?: RevalidateProfile$1): Promise<void>;
|
|
117
|
-
/**
|
|
118
|
-
* Escape hatch: invalidate by raw tag string. Prefer the typed helpers
|
|
119
|
-
* above where possible — they keep the tag scheme in one place.
|
|
120
|
-
*/
|
|
121
159
|
declare function revalidateByTag(tag: string, profile?: RevalidateProfile$1): Promise<void>;
|
|
122
160
|
|
|
123
|
-
/** Expire the products list with read-your-writes. Call from a Server Action that creates / deletes / reorders. */
|
|
124
161
|
declare function updateProducts(): Promise<void>;
|
|
125
|
-
/** Expire a single product + the products list with read-your-writes. */
|
|
126
162
|
declare function updateProduct(id: string): Promise<void>;
|
|
127
163
|
declare function updateCategories(): Promise<void>;
|
|
128
164
|
declare function updateCategory(id: string): Promise<void>;
|
|
@@ -138,25 +174,23 @@ declare function updateAddOn(id: string): Promise<void>;
|
|
|
138
174
|
declare function updateSubscriptions(): Promise<void>;
|
|
139
175
|
declare function updateSubscription(id: string): Promise<void>;
|
|
140
176
|
declare function updateStock(productId?: string): Promise<void>;
|
|
141
|
-
/** Escape hatch: expire a raw tag with read-your-writes. Prefer the typed helpers above. */
|
|
142
177
|
declare function updateByTag(tag: string): Promise<void>;
|
|
143
|
-
/**
|
|
144
|
-
* Refresh uncached data on the current page (notification counts, live
|
|
145
|
-
* metrics, status indicators). Server-Action-only. Complements
|
|
146
|
-
* `router.refresh()` on the client.
|
|
147
|
-
*/
|
|
148
178
|
declare function refreshPage(): Promise<void>;
|
|
149
179
|
|
|
150
|
-
/** Next 16
|
|
180
|
+
/** Next 16 cacheLife profile — a built-in name (`'max'`/`'hours'`/…) or `{expire: secs}`. */
|
|
151
181
|
type RevalidateProfile = string | {
|
|
152
182
|
expire: number;
|
|
153
183
|
};
|
|
154
184
|
interface RevalidateRouteOptions {
|
|
185
|
+
/** Defaults to `process.env.CIMPLIFY_REVALIDATE_SECRET`. */
|
|
155
186
|
secret?: string;
|
|
187
|
+
/** Defaults to a lazy import of `next/cache.revalidateTag`. Override for tests. */
|
|
156
188
|
revalidateTag?: (tag: string, profile: RevalidateProfile) => void;
|
|
189
|
+
/** Defaults to `Date.now`. Override for tests. */
|
|
157
190
|
now?: () => number;
|
|
191
|
+
/** Profile used when the request body doesn't include one. Defaults to `'max'`. */
|
|
158
192
|
defaultProfile?: RevalidateProfile;
|
|
159
193
|
}
|
|
160
194
|
declare function revalidateRouteHandler(req: Request, options?: RevalidateRouteOptions): Promise<Response>;
|
|
161
195
|
|
|
162
|
-
export { 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 };
|
|
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,8 +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
|
|
62
|
-
var DEFAULT_PROFILE =
|
|
71
|
+
var DEFAULT_PROFILE = CACHE_LIFE_DEFAULT;
|
|
63
72
|
var _revalidateTag = null;
|
|
64
73
|
async function getRevalidateTag() {
|
|
65
74
|
if (_revalidateTag) return _revalidateTag;
|
|
@@ -230,7 +239,7 @@ var SIGNATURE_HEADER = "x-cimplify-signature";
|
|
|
230
239
|
var SIGNATURE_PREFIX = "sha256=";
|
|
231
240
|
var MAX_SKEW_MS = 5 * 60 * 1e3;
|
|
232
241
|
var SECRET_ENV = "CIMPLIFY_REVALIDATE_SECRET";
|
|
233
|
-
var DEFAULT_PROFILE2 =
|
|
242
|
+
var DEFAULT_PROFILE2 = CACHE_LIFE_DEFAULT;
|
|
234
243
|
async function revalidateRouteHandler(req, options = {}) {
|
|
235
244
|
const secret = options.secret ?? envSecret();
|
|
236
245
|
if (!secret) return text(`revalidate disabled: ${SECRET_ENV} not set`, 500);
|
|
@@ -313,6 +322,8 @@ Object.defineProperty(exports, "CimplifyError", {
|
|
|
313
322
|
enumerable: true,
|
|
314
323
|
get: function () { return chunkTKOTACKZ_js.CimplifyError; }
|
|
315
324
|
});
|
|
325
|
+
exports.CACHE_LIFE_DEFAULT = CACHE_LIFE_DEFAULT;
|
|
326
|
+
exports.CACHE_LIFE_PROBE = CACHE_LIFE_PROBE;
|
|
316
327
|
exports.getServerClient = getServerClient;
|
|
317
328
|
exports.refreshPage = refreshPage;
|
|
318
329
|
exports.revalidateAddOn = revalidateAddOn;
|
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,8 +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
|
|
60
|
-
var DEFAULT_PROFILE =
|
|
69
|
+
var DEFAULT_PROFILE = CACHE_LIFE_DEFAULT;
|
|
61
70
|
var _revalidateTag = null;
|
|
62
71
|
async function getRevalidateTag() {
|
|
63
72
|
if (_revalidateTag) return _revalidateTag;
|
|
@@ -228,7 +237,7 @@ var SIGNATURE_HEADER = "x-cimplify-signature";
|
|
|
228
237
|
var SIGNATURE_PREFIX = "sha256=";
|
|
229
238
|
var MAX_SKEW_MS = 5 * 60 * 1e3;
|
|
230
239
|
var SECRET_ENV = "CIMPLIFY_REVALIDATE_SECRET";
|
|
231
|
-
var DEFAULT_PROFILE2 =
|
|
240
|
+
var DEFAULT_PROFILE2 = CACHE_LIFE_DEFAULT;
|
|
232
241
|
async function revalidateRouteHandler(req, options = {}) {
|
|
233
242
|
const secret = options.secret ?? envSecret();
|
|
234
243
|
if (!secret) return text(`revalidate disabled: ${SECRET_ENV} not set`, 500);
|
|
@@ -307,4 +316,4 @@ function text(message, status) {
|
|
|
307
316
|
return new Response(message, { status, headers: { "content-type": "text/plain" } });
|
|
308
317
|
}
|
|
309
318
|
|
|
310
|
-
export { 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 };
|
|
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 };
|