@cimplify/sdk 0.49.2 → 0.50.1
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 +30 -1
- package/dist/server.d.ts +30 -1
- package/dist/server.js +164 -0
- package/dist/server.mjs +164 -1
- package/package.json +6 -3
- package/dist/mock/library.d.mts +0 -15
- package/dist/mock/library.d.ts +0 -15
- package/dist/mock/msw.d.mts +0 -14
- package/dist/mock/msw.d.ts +0 -14
- package/dist/server-CzthOeYS.d.mts +0 -1183
- package/dist/server-CzthOeYS.d.ts +0 -1183
package/dist/server.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { C as CimplifyClient } from './client-BZZK1txR.mjs';
|
|
2
2
|
export { aN as Result } from './client-BZZK1txR.mjs';
|
|
3
|
+
import { IncrementalCache } from '@opennextjs/aws/types/overrides';
|
|
3
4
|
export { ap as Category, h as CimplifyError, ar as Collection, X as Product, aa as ProductWithDetails } from './product-C-xLzh7Q.mjs';
|
|
4
5
|
import './payment-9L_-GWqQ.mjs';
|
|
5
6
|
|
|
@@ -136,6 +137,34 @@ type CacheLifeDefault = typeof CACHE_LIFE_DEFAULT;
|
|
|
136
137
|
/** The TS type of {@link CACHE_LIFE_PROBE} — the `"seconds"` literal. */
|
|
137
138
|
type CacheLifeProbe = typeof CACHE_LIFE_PROBE;
|
|
138
139
|
|
|
140
|
+
/**
|
|
141
|
+
* Cimplify incremental-cache override for Workers for Platforms storefronts.
|
|
142
|
+
*
|
|
143
|
+
* Replaces opennext's stale-while-revalidate model with an evict-on-invalidate
|
|
144
|
+
* model that fits Cimplify's event-driven domain:
|
|
145
|
+
*
|
|
146
|
+
* - `get`: standard R2 fetch. Returns the cached value or null.
|
|
147
|
+
* - `set`: writes to R2 AND emits a tag→cache_key index update to the shared
|
|
148
|
+
* `CIMPLIFY_PATH_INDEX` Durable Object (hosted in cimplify-tag-cache).
|
|
149
|
+
* - `delete`: standard R2 delete (called by opennext on explicit invalidate;
|
|
150
|
+
* also called by us from the Rust EvictionDispatcher path on tag events).
|
|
151
|
+
*
|
|
152
|
+
* The Rust EvictionDispatcher reads the index on bus events, deletes the
|
|
153
|
+
* matching R2 entries directly, and prunes the index — there is no SWR
|
|
154
|
+
* "background refresh" path. opennext's queue and `isStale` checks become
|
|
155
|
+
* no-ops; cached entries are by definition fresh (existed at write time and
|
|
156
|
+
* haven't been evicted), and absence means the next request synchronously
|
|
157
|
+
* re-renders.
|
|
158
|
+
*
|
|
159
|
+
* Why this exists: WfP user workers cannot have `WORKER_SELF_REFERENCE`,
|
|
160
|
+
* which is the binding every built-in opennext queue requires. Rather than
|
|
161
|
+
* recreate SWR via self-fetch tricks, we drop SWR for our domain — Cimplify
|
|
162
|
+
* always knows when data changes (every catalog mutation flows through the
|
|
163
|
+
* bus), so timer-based refresh adds no value.
|
|
164
|
+
*/
|
|
165
|
+
|
|
166
|
+
declare const evictIncrementalCache: IncrementalCache;
|
|
167
|
+
|
|
139
168
|
/** Next 16 cacheLife profile — a built-in name (`'max'`/`'hours'`/…) or `{expire: secs}`. */
|
|
140
169
|
type RevalidateProfile$1 = string | {
|
|
141
170
|
expire: number;
|
|
@@ -193,4 +222,4 @@ interface RevalidateRouteOptions {
|
|
|
193
222
|
}
|
|
194
223
|
declare function revalidateRouteHandler(req: Request, options?: RevalidateRouteOptions): Promise<Response>;
|
|
195
224
|
|
|
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 };
|
|
225
|
+
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, evictIncrementalCache, 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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { C as CimplifyClient } from './client-B8tJnOde.js';
|
|
2
2
|
export { aN as Result } from './client-B8tJnOde.js';
|
|
3
|
+
import { IncrementalCache } from '@opennextjs/aws/types/overrides';
|
|
3
4
|
export { ap as Category, h as CimplifyError, ar as Collection, X as Product, aa as ProductWithDetails } from './product-C-xLzh7Q.js';
|
|
4
5
|
import './payment-_e99nSRj.js';
|
|
5
6
|
|
|
@@ -136,6 +137,34 @@ type CacheLifeDefault = typeof CACHE_LIFE_DEFAULT;
|
|
|
136
137
|
/** The TS type of {@link CACHE_LIFE_PROBE} — the `"seconds"` literal. */
|
|
137
138
|
type CacheLifeProbe = typeof CACHE_LIFE_PROBE;
|
|
138
139
|
|
|
140
|
+
/**
|
|
141
|
+
* Cimplify incremental-cache override for Workers for Platforms storefronts.
|
|
142
|
+
*
|
|
143
|
+
* Replaces opennext's stale-while-revalidate model with an evict-on-invalidate
|
|
144
|
+
* model that fits Cimplify's event-driven domain:
|
|
145
|
+
*
|
|
146
|
+
* - `get`: standard R2 fetch. Returns the cached value or null.
|
|
147
|
+
* - `set`: writes to R2 AND emits a tag→cache_key index update to the shared
|
|
148
|
+
* `CIMPLIFY_PATH_INDEX` Durable Object (hosted in cimplify-tag-cache).
|
|
149
|
+
* - `delete`: standard R2 delete (called by opennext on explicit invalidate;
|
|
150
|
+
* also called by us from the Rust EvictionDispatcher path on tag events).
|
|
151
|
+
*
|
|
152
|
+
* The Rust EvictionDispatcher reads the index on bus events, deletes the
|
|
153
|
+
* matching R2 entries directly, and prunes the index — there is no SWR
|
|
154
|
+
* "background refresh" path. opennext's queue and `isStale` checks become
|
|
155
|
+
* no-ops; cached entries are by definition fresh (existed at write time and
|
|
156
|
+
* haven't been evicted), and absence means the next request synchronously
|
|
157
|
+
* re-renders.
|
|
158
|
+
*
|
|
159
|
+
* Why this exists: WfP user workers cannot have `WORKER_SELF_REFERENCE`,
|
|
160
|
+
* which is the binding every built-in opennext queue requires. Rather than
|
|
161
|
+
* recreate SWR via self-fetch tricks, we drop SWR for our domain — Cimplify
|
|
162
|
+
* always knows when data changes (every catalog mutation flows through the
|
|
163
|
+
* bus), so timer-based refresh adds no value.
|
|
164
|
+
*/
|
|
165
|
+
|
|
166
|
+
declare const evictIncrementalCache: IncrementalCache;
|
|
167
|
+
|
|
139
168
|
/** Next 16 cacheLife profile — a built-in name (`'max'`/`'hours'`/…) or `{expire: secs}`. */
|
|
140
169
|
type RevalidateProfile$1 = string | {
|
|
141
170
|
expire: number;
|
|
@@ -193,4 +222,4 @@ interface RevalidateRouteOptions {
|
|
|
193
222
|
}
|
|
194
223
|
declare function revalidateRouteHandler(req: Request, options?: RevalidateRouteOptions): Promise<Response>;
|
|
195
224
|
|
|
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 };
|
|
225
|
+
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, evictIncrementalCache, 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
|
@@ -5,6 +5,7 @@ require('./chunk-DR4UPU6P.js');
|
|
|
5
5
|
require('./chunk-6RP6OPYO.js');
|
|
6
6
|
var chunkTKOTACKZ_js = require('./chunk-TKOTACKZ.js');
|
|
7
7
|
var react = require('react');
|
|
8
|
+
var crypto$1 = require('crypto');
|
|
8
9
|
|
|
9
10
|
var DEFAULT_PROD_URL = "https://storefronts.cimplify.io";
|
|
10
11
|
var DEFAULT_DEV_URL = "http://127.0.0.1:8787";
|
|
@@ -67,6 +68,168 @@ var tags = {
|
|
|
67
68
|
var CACHE_LIFE_DEFAULT = "max";
|
|
68
69
|
var CACHE_LIFE_PROBE = "seconds";
|
|
69
70
|
|
|
71
|
+
// ../node_modules/.bun/@opennextjs+cloudflare@1.19.11+2f5a8389dca7b522/node_modules/@opennextjs/cloudflare/dist/api/cloudflare-context.js
|
|
72
|
+
var cloudflareContextSymbol = /* @__PURE__ */ Symbol.for("__cloudflare-context__");
|
|
73
|
+
function getCloudflareContext(options = { async: false }) {
|
|
74
|
+
return options.async ? getCloudflareContextAsync() : getCloudflareContextSync();
|
|
75
|
+
}
|
|
76
|
+
function getCloudflareContextFromGlobalScope() {
|
|
77
|
+
const global = globalThis;
|
|
78
|
+
return global[cloudflareContextSymbol];
|
|
79
|
+
}
|
|
80
|
+
function inSSG() {
|
|
81
|
+
const global = globalThis;
|
|
82
|
+
return global.__NEXT_DATA__?.nextExport === true;
|
|
83
|
+
}
|
|
84
|
+
function getCloudflareContextSync() {
|
|
85
|
+
const cloudflareContext = getCloudflareContextFromGlobalScope();
|
|
86
|
+
if (cloudflareContext) {
|
|
87
|
+
return cloudflareContext;
|
|
88
|
+
}
|
|
89
|
+
if (inSSG()) {
|
|
90
|
+
throw new Error(`
|
|
91
|
+
|
|
92
|
+
ERROR: \`getCloudflareContext\` has been called in sync mode in either a static route or at the top level of a non-static one, both cases are not allowed but can be solved by either:
|
|
93
|
+
- make sure that the call is not at the top level and that the route is not static
|
|
94
|
+
- call \`getCloudflareContext({async: true})\` to use the \`async\` mode
|
|
95
|
+
- avoid calling \`getCloudflareContext\` in the route
|
|
96
|
+
`);
|
|
97
|
+
}
|
|
98
|
+
throw new Error(initOpenNextCloudflareForDevErrorMsg);
|
|
99
|
+
}
|
|
100
|
+
async function getCloudflareContextAsync() {
|
|
101
|
+
const cloudflareContext = getCloudflareContextFromGlobalScope();
|
|
102
|
+
if (cloudflareContext) {
|
|
103
|
+
return cloudflareContext;
|
|
104
|
+
}
|
|
105
|
+
const inNodejsRuntime = process.env.NEXT_RUNTIME === "nodejs";
|
|
106
|
+
if (inNodejsRuntime || inSSG()) {
|
|
107
|
+
const cloudflareContext2 = await getCloudflareContextFromWrangler();
|
|
108
|
+
addCloudflareContextToNodejsGlobal(cloudflareContext2);
|
|
109
|
+
return cloudflareContext2;
|
|
110
|
+
}
|
|
111
|
+
throw new Error(initOpenNextCloudflareForDevErrorMsg);
|
|
112
|
+
}
|
|
113
|
+
function addCloudflareContextToNodejsGlobal(cloudflareContext) {
|
|
114
|
+
const global = globalThis;
|
|
115
|
+
global[cloudflareContextSymbol] = cloudflareContext;
|
|
116
|
+
}
|
|
117
|
+
async function getCloudflareContextFromWrangler(options) {
|
|
118
|
+
const { getPlatformProxy } = await import(
|
|
119
|
+
/* webpackIgnore: true */
|
|
120
|
+
`${"__wrangler".replaceAll("_", "")}`
|
|
121
|
+
);
|
|
122
|
+
const environment = process.env.NEXT_DEV_WRANGLER_ENV;
|
|
123
|
+
const { env, cf, ctx } = await getPlatformProxy({
|
|
124
|
+
...options,
|
|
125
|
+
// The `env` passed to the fetch handler does not contain variables from `.env*` files.
|
|
126
|
+
// because we invoke wrangler with `CLOUDFLARE_LOAD_DEV_VARS_FROM_DOT_ENV`=`"false"`.
|
|
127
|
+
// Initializing `envFiles` with an empty list is the equivalent for this API call.
|
|
128
|
+
envFiles: [],
|
|
129
|
+
environment
|
|
130
|
+
});
|
|
131
|
+
return {
|
|
132
|
+
env,
|
|
133
|
+
cf,
|
|
134
|
+
ctx
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
var initOpenNextCloudflareForDevErrorMsg = `
|
|
138
|
+
|
|
139
|
+
ERROR: \`getCloudflareContext\` has been called without having called \`initOpenNextCloudflareForDev\` from the Next.js config file.
|
|
140
|
+
You should update your Next.js config file as shown below:
|
|
141
|
+
|
|
142
|
+
\`\`\`
|
|
143
|
+
// next.config.mjs
|
|
144
|
+
|
|
145
|
+
import { initOpenNextCloudflareForDev } from "@opennextjs/cloudflare";
|
|
146
|
+
|
|
147
|
+
initOpenNextCloudflareForDev();
|
|
148
|
+
|
|
149
|
+
const nextConfig = { ... };
|
|
150
|
+
export default nextConfig;
|
|
151
|
+
\`\`\`
|
|
152
|
+
|
|
153
|
+
`;
|
|
154
|
+
|
|
155
|
+
// ../node_modules/.bun/@opennextjs+cloudflare@1.19.11+2f5a8389dca7b522/node_modules/@opennextjs/cloudflare/dist/api/overrides/internal.js
|
|
156
|
+
var FALLBACK_BUILD_ID = "no-build-id";
|
|
157
|
+
var DEFAULT_PREFIX = "incremental-cache";
|
|
158
|
+
function computeCacheKey(key, options) {
|
|
159
|
+
const { cacheType = "cache", prefix = DEFAULT_PREFIX, buildId = FALLBACK_BUILD_ID } = options;
|
|
160
|
+
const hash = crypto$1.createHash("sha256").update(key).digest("hex");
|
|
161
|
+
return `${prefix}/${buildId}/${hash}.${cacheType}`.replace(/\/+/g, "/");
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// src/server/overrides/evict-incremental-cache.ts
|
|
165
|
+
var R2_BUCKET_BINDING = "NEXT_INC_CACHE_R2_BUCKET";
|
|
166
|
+
var R2_PREFIX_ENV = "NEXT_INC_CACHE_R2_PREFIX";
|
|
167
|
+
var PATH_INDEX_BINDING = "CIMPLIFY_PATH_INDEX";
|
|
168
|
+
var CIMPLIFY_TAG_PREFIX = "cimplify:";
|
|
169
|
+
function r2Key(env, key, cacheType) {
|
|
170
|
+
return computeCacheKey(key, {
|
|
171
|
+
prefix: env[R2_PREFIX_ENV],
|
|
172
|
+
buildId: globalThis.process?.env?.OPEN_NEXT_BUILD_ID,
|
|
173
|
+
cacheType
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
function cimplifyTags(value) {
|
|
177
|
+
return (value?.tags ?? []).filter((t) => t.startsWith(CIMPLIFY_TAG_PREFIX));
|
|
178
|
+
}
|
|
179
|
+
function pathIndexFor(env) {
|
|
180
|
+
const ns = env[PATH_INDEX_BINDING];
|
|
181
|
+
const prefix = env[R2_PREFIX_ENV];
|
|
182
|
+
if (!ns || !prefix) return null;
|
|
183
|
+
return ns.get(ns.idFromName(prefix));
|
|
184
|
+
}
|
|
185
|
+
var evictIncrementalCache = {
|
|
186
|
+
name: "cimplify-evict-r2-cache",
|
|
187
|
+
async get(key, cacheType) {
|
|
188
|
+
const env = getCloudflareContext().env;
|
|
189
|
+
const r2 = env[R2_BUCKET_BINDING];
|
|
190
|
+
if (!r2) return null;
|
|
191
|
+
try {
|
|
192
|
+
const obj = await r2.get(r2Key(env, key, cacheType));
|
|
193
|
+
if (!obj) return null;
|
|
194
|
+
return {
|
|
195
|
+
value: await obj.json(),
|
|
196
|
+
lastModified: obj.uploaded.getTime()
|
|
197
|
+
};
|
|
198
|
+
} catch {
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
async set(key, value, cacheType) {
|
|
203
|
+
const env = getCloudflareContext().env;
|
|
204
|
+
const r2 = env[R2_BUCKET_BINDING];
|
|
205
|
+
if (!r2) return;
|
|
206
|
+
const k = r2Key(env, key, cacheType);
|
|
207
|
+
try {
|
|
208
|
+
await r2.put(k, JSON.stringify(value));
|
|
209
|
+
} catch {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const tags2 = cimplifyTags(value);
|
|
213
|
+
if (tags2.length === 0) return;
|
|
214
|
+
const index = pathIndexFor(env);
|
|
215
|
+
if (!index) return;
|
|
216
|
+
try {
|
|
217
|
+
await index.indexAdd(key, k, tags2, cacheType === "fetch");
|
|
218
|
+
} catch {
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
async delete(key) {
|
|
222
|
+
const env = getCloudflareContext().env;
|
|
223
|
+
const r2 = env[R2_BUCKET_BINDING];
|
|
224
|
+
if (!r2) return;
|
|
225
|
+
try {
|
|
226
|
+
await r2.delete(r2Key(env, key));
|
|
227
|
+
} catch {
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
var evict_incremental_cache_default = evictIncrementalCache;
|
|
232
|
+
|
|
70
233
|
// src/server/revalidate.ts
|
|
71
234
|
var DEFAULT_PROFILE = CACHE_LIFE_DEFAULT;
|
|
72
235
|
var _revalidateTag = null;
|
|
@@ -324,6 +487,7 @@ Object.defineProperty(exports, "CimplifyError", {
|
|
|
324
487
|
});
|
|
325
488
|
exports.CACHE_LIFE_DEFAULT = CACHE_LIFE_DEFAULT;
|
|
326
489
|
exports.CACHE_LIFE_PROBE = CACHE_LIFE_PROBE;
|
|
490
|
+
exports.evictIncrementalCache = evict_incremental_cache_default;
|
|
327
491
|
exports.getServerClient = getServerClient;
|
|
328
492
|
exports.refreshPage = refreshPage;
|
|
329
493
|
exports.revalidateAddOn = revalidateAddOn;
|
package/dist/server.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import './chunk-OFNVLUH4.mjs';
|
|
|
3
3
|
import './chunk-XY2DFX5K.mjs';
|
|
4
4
|
export { CimplifyError } from './chunk-Z2AYLZDF.mjs';
|
|
5
5
|
import { cache } from 'react';
|
|
6
|
+
import { createHash } from 'crypto';
|
|
6
7
|
|
|
7
8
|
var DEFAULT_PROD_URL = "https://storefronts.cimplify.io";
|
|
8
9
|
var DEFAULT_DEV_URL = "http://127.0.0.1:8787";
|
|
@@ -65,6 +66,168 @@ var tags = {
|
|
|
65
66
|
var CACHE_LIFE_DEFAULT = "max";
|
|
66
67
|
var CACHE_LIFE_PROBE = "seconds";
|
|
67
68
|
|
|
69
|
+
// ../node_modules/.bun/@opennextjs+cloudflare@1.19.11+2f5a8389dca7b522/node_modules/@opennextjs/cloudflare/dist/api/cloudflare-context.js
|
|
70
|
+
var cloudflareContextSymbol = /* @__PURE__ */ Symbol.for("__cloudflare-context__");
|
|
71
|
+
function getCloudflareContext(options = { async: false }) {
|
|
72
|
+
return options.async ? getCloudflareContextAsync() : getCloudflareContextSync();
|
|
73
|
+
}
|
|
74
|
+
function getCloudflareContextFromGlobalScope() {
|
|
75
|
+
const global = globalThis;
|
|
76
|
+
return global[cloudflareContextSymbol];
|
|
77
|
+
}
|
|
78
|
+
function inSSG() {
|
|
79
|
+
const global = globalThis;
|
|
80
|
+
return global.__NEXT_DATA__?.nextExport === true;
|
|
81
|
+
}
|
|
82
|
+
function getCloudflareContextSync() {
|
|
83
|
+
const cloudflareContext = getCloudflareContextFromGlobalScope();
|
|
84
|
+
if (cloudflareContext) {
|
|
85
|
+
return cloudflareContext;
|
|
86
|
+
}
|
|
87
|
+
if (inSSG()) {
|
|
88
|
+
throw new Error(`
|
|
89
|
+
|
|
90
|
+
ERROR: \`getCloudflareContext\` has been called in sync mode in either a static route or at the top level of a non-static one, both cases are not allowed but can be solved by either:
|
|
91
|
+
- make sure that the call is not at the top level and that the route is not static
|
|
92
|
+
- call \`getCloudflareContext({async: true})\` to use the \`async\` mode
|
|
93
|
+
- avoid calling \`getCloudflareContext\` in the route
|
|
94
|
+
`);
|
|
95
|
+
}
|
|
96
|
+
throw new Error(initOpenNextCloudflareForDevErrorMsg);
|
|
97
|
+
}
|
|
98
|
+
async function getCloudflareContextAsync() {
|
|
99
|
+
const cloudflareContext = getCloudflareContextFromGlobalScope();
|
|
100
|
+
if (cloudflareContext) {
|
|
101
|
+
return cloudflareContext;
|
|
102
|
+
}
|
|
103
|
+
const inNodejsRuntime = process.env.NEXT_RUNTIME === "nodejs";
|
|
104
|
+
if (inNodejsRuntime || inSSG()) {
|
|
105
|
+
const cloudflareContext2 = await getCloudflareContextFromWrangler();
|
|
106
|
+
addCloudflareContextToNodejsGlobal(cloudflareContext2);
|
|
107
|
+
return cloudflareContext2;
|
|
108
|
+
}
|
|
109
|
+
throw new Error(initOpenNextCloudflareForDevErrorMsg);
|
|
110
|
+
}
|
|
111
|
+
function addCloudflareContextToNodejsGlobal(cloudflareContext) {
|
|
112
|
+
const global = globalThis;
|
|
113
|
+
global[cloudflareContextSymbol] = cloudflareContext;
|
|
114
|
+
}
|
|
115
|
+
async function getCloudflareContextFromWrangler(options) {
|
|
116
|
+
const { getPlatformProxy } = await import(
|
|
117
|
+
/* webpackIgnore: true */
|
|
118
|
+
`${"__wrangler".replaceAll("_", "")}`
|
|
119
|
+
);
|
|
120
|
+
const environment = process.env.NEXT_DEV_WRANGLER_ENV;
|
|
121
|
+
const { env, cf, ctx } = await getPlatformProxy({
|
|
122
|
+
...options,
|
|
123
|
+
// The `env` passed to the fetch handler does not contain variables from `.env*` files.
|
|
124
|
+
// because we invoke wrangler with `CLOUDFLARE_LOAD_DEV_VARS_FROM_DOT_ENV`=`"false"`.
|
|
125
|
+
// Initializing `envFiles` with an empty list is the equivalent for this API call.
|
|
126
|
+
envFiles: [],
|
|
127
|
+
environment
|
|
128
|
+
});
|
|
129
|
+
return {
|
|
130
|
+
env,
|
|
131
|
+
cf,
|
|
132
|
+
ctx
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
var initOpenNextCloudflareForDevErrorMsg = `
|
|
136
|
+
|
|
137
|
+
ERROR: \`getCloudflareContext\` has been called without having called \`initOpenNextCloudflareForDev\` from the Next.js config file.
|
|
138
|
+
You should update your Next.js config file as shown below:
|
|
139
|
+
|
|
140
|
+
\`\`\`
|
|
141
|
+
// next.config.mjs
|
|
142
|
+
|
|
143
|
+
import { initOpenNextCloudflareForDev } from "@opennextjs/cloudflare";
|
|
144
|
+
|
|
145
|
+
initOpenNextCloudflareForDev();
|
|
146
|
+
|
|
147
|
+
const nextConfig = { ... };
|
|
148
|
+
export default nextConfig;
|
|
149
|
+
\`\`\`
|
|
150
|
+
|
|
151
|
+
`;
|
|
152
|
+
|
|
153
|
+
// ../node_modules/.bun/@opennextjs+cloudflare@1.19.11+2f5a8389dca7b522/node_modules/@opennextjs/cloudflare/dist/api/overrides/internal.js
|
|
154
|
+
var FALLBACK_BUILD_ID = "no-build-id";
|
|
155
|
+
var DEFAULT_PREFIX = "incremental-cache";
|
|
156
|
+
function computeCacheKey(key, options) {
|
|
157
|
+
const { cacheType = "cache", prefix = DEFAULT_PREFIX, buildId = FALLBACK_BUILD_ID } = options;
|
|
158
|
+
const hash = createHash("sha256").update(key).digest("hex");
|
|
159
|
+
return `${prefix}/${buildId}/${hash}.${cacheType}`.replace(/\/+/g, "/");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// src/server/overrides/evict-incremental-cache.ts
|
|
163
|
+
var R2_BUCKET_BINDING = "NEXT_INC_CACHE_R2_BUCKET";
|
|
164
|
+
var R2_PREFIX_ENV = "NEXT_INC_CACHE_R2_PREFIX";
|
|
165
|
+
var PATH_INDEX_BINDING = "CIMPLIFY_PATH_INDEX";
|
|
166
|
+
var CIMPLIFY_TAG_PREFIX = "cimplify:";
|
|
167
|
+
function r2Key(env, key, cacheType) {
|
|
168
|
+
return computeCacheKey(key, {
|
|
169
|
+
prefix: env[R2_PREFIX_ENV],
|
|
170
|
+
buildId: globalThis.process?.env?.OPEN_NEXT_BUILD_ID,
|
|
171
|
+
cacheType
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
function cimplifyTags(value) {
|
|
175
|
+
return (value?.tags ?? []).filter((t) => t.startsWith(CIMPLIFY_TAG_PREFIX));
|
|
176
|
+
}
|
|
177
|
+
function pathIndexFor(env) {
|
|
178
|
+
const ns = env[PATH_INDEX_BINDING];
|
|
179
|
+
const prefix = env[R2_PREFIX_ENV];
|
|
180
|
+
if (!ns || !prefix) return null;
|
|
181
|
+
return ns.get(ns.idFromName(prefix));
|
|
182
|
+
}
|
|
183
|
+
var evictIncrementalCache = {
|
|
184
|
+
name: "cimplify-evict-r2-cache",
|
|
185
|
+
async get(key, cacheType) {
|
|
186
|
+
const env = getCloudflareContext().env;
|
|
187
|
+
const r2 = env[R2_BUCKET_BINDING];
|
|
188
|
+
if (!r2) return null;
|
|
189
|
+
try {
|
|
190
|
+
const obj = await r2.get(r2Key(env, key, cacheType));
|
|
191
|
+
if (!obj) return null;
|
|
192
|
+
return {
|
|
193
|
+
value: await obj.json(),
|
|
194
|
+
lastModified: obj.uploaded.getTime()
|
|
195
|
+
};
|
|
196
|
+
} catch {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
async set(key, value, cacheType) {
|
|
201
|
+
const env = getCloudflareContext().env;
|
|
202
|
+
const r2 = env[R2_BUCKET_BINDING];
|
|
203
|
+
if (!r2) return;
|
|
204
|
+
const k = r2Key(env, key, cacheType);
|
|
205
|
+
try {
|
|
206
|
+
await r2.put(k, JSON.stringify(value));
|
|
207
|
+
} catch {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const tags2 = cimplifyTags(value);
|
|
211
|
+
if (tags2.length === 0) return;
|
|
212
|
+
const index = pathIndexFor(env);
|
|
213
|
+
if (!index) return;
|
|
214
|
+
try {
|
|
215
|
+
await index.indexAdd(key, k, tags2, cacheType === "fetch");
|
|
216
|
+
} catch {
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
async delete(key) {
|
|
220
|
+
const env = getCloudflareContext().env;
|
|
221
|
+
const r2 = env[R2_BUCKET_BINDING];
|
|
222
|
+
if (!r2) return;
|
|
223
|
+
try {
|
|
224
|
+
await r2.delete(r2Key(env, key));
|
|
225
|
+
} catch {
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
var evict_incremental_cache_default = evictIncrementalCache;
|
|
230
|
+
|
|
68
231
|
// src/server/revalidate.ts
|
|
69
232
|
var DEFAULT_PROFILE = CACHE_LIFE_DEFAULT;
|
|
70
233
|
var _revalidateTag = null;
|
|
@@ -316,4 +479,4 @@ function text(message, status) {
|
|
|
316
479
|
return new Response(message, { status, headers: { "content-type": "text/plain" } });
|
|
317
480
|
}
|
|
318
481
|
|
|
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 };
|
|
482
|
+
export { CACHE_LIFE_DEFAULT, CACHE_LIFE_PROBE, evict_incremental_cache_default as evictIncrementalCache, 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cimplify/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.50.1",
|
|
4
4
|
"description": "Cimplify Commerce SDK for storefronts",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cimplify",
|
|
@@ -118,16 +118,19 @@
|
|
|
118
118
|
}
|
|
119
119
|
},
|
|
120
120
|
"devDependencies": {
|
|
121
|
+
"@cloudflare/workers-types": "^4.20260503.1",
|
|
121
122
|
"@hono/node-server": "^1.13.7",
|
|
122
|
-
"
|
|
123
|
-
"
|
|
123
|
+
"@opennextjs/aws": "^3.7.10",
|
|
124
|
+
"@opennextjs/cloudflare": "^1.19.11",
|
|
124
125
|
"@tailwindcss/cli": "4.2.2",
|
|
125
126
|
"@testing-library/dom": "^10.4.1",
|
|
126
127
|
"@testing-library/react": "^16.3.2",
|
|
127
128
|
"@types/node": "^25.6.0",
|
|
128
129
|
"@types/react": "^19.2.14",
|
|
129
130
|
"@typescript/native-preview": "^7.0.0-dev.20260503.1",
|
|
131
|
+
"hono": "^4.7.7",
|
|
130
132
|
"jsdom": "^29.1.1",
|
|
133
|
+
"msw": "^2.14.2",
|
|
131
134
|
"react": "^19.2.5",
|
|
132
135
|
"react-dom": "^19.2.5",
|
|
133
136
|
"tailwindcss": "4.2.2",
|
package/dist/mock/library.d.mts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { M as MockBus, a as MockEvent } from '../server-CzthOeYS.mjs';
|
|
2
|
-
export { A as AppHandle, m as Clock, C as CreateAppOptions, D as Deps, I as IdGen, h as MockBusiness, j as MockCart, l as MockEventType, d as MockOptions, k as MockOrder, i as MockProduct, S as SeedName, f as Session, g as StateRegistry, e as applySeed, b as createDeps, c as createMockApp } from '../server-CzthOeYS.mjs';
|
|
3
|
-
import 'hono';
|
|
4
|
-
|
|
5
|
-
interface WebhookOptions {
|
|
6
|
-
url: string;
|
|
7
|
-
secret?: string;
|
|
8
|
-
fetcher?: (input: string, init: RequestInit) => Promise<Response>;
|
|
9
|
-
onError?: (err: unknown, event: MockEvent) => void;
|
|
10
|
-
}
|
|
11
|
-
declare function signPayload(secret: string, body: string): string;
|
|
12
|
-
declare function verifySignature(secret: string, body: string, signature: string): boolean;
|
|
13
|
-
declare function setupWebhooks(bus: MockBus, opts: WebhookOptions): () => void;
|
|
14
|
-
|
|
15
|
-
export { MockBus, MockEvent, type WebhookOptions, setupWebhooks, signPayload, verifySignature };
|
package/dist/mock/library.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { M as MockBus, a as MockEvent } from '../server-CzthOeYS.js';
|
|
2
|
-
export { A as AppHandle, m as Clock, C as CreateAppOptions, D as Deps, I as IdGen, h as MockBusiness, j as MockCart, l as MockEventType, d as MockOptions, k as MockOrder, i as MockProduct, S as SeedName, f as Session, g as StateRegistry, e as applySeed, b as createDeps, c as createMockApp } from '../server-CzthOeYS.js';
|
|
3
|
-
import 'hono';
|
|
4
|
-
|
|
5
|
-
interface WebhookOptions {
|
|
6
|
-
url: string;
|
|
7
|
-
secret?: string;
|
|
8
|
-
fetcher?: (input: string, init: RequestInit) => Promise<Response>;
|
|
9
|
-
onError?: (err: unknown, event: MockEvent) => void;
|
|
10
|
-
}
|
|
11
|
-
declare function signPayload(secret: string, body: string): string;
|
|
12
|
-
declare function verifySignature(secret: string, body: string, signature: string): boolean;
|
|
13
|
-
declare function setupWebhooks(bus: MockBus, opts: WebhookOptions): () => void;
|
|
14
|
-
|
|
15
|
-
export { MockBus, MockEvent, type WebhookOptions, setupWebhooks, signPayload, verifySignature };
|
package/dist/mock/msw.d.mts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { A as AppHandle, C as CreateAppOptions } from '../server-CzthOeYS.mjs';
|
|
2
|
-
import 'hono';
|
|
3
|
-
|
|
4
|
-
interface MswHandlerSetup {
|
|
5
|
-
handlers: unknown[];
|
|
6
|
-
deps: AppHandle["deps"];
|
|
7
|
-
baseUrl: string;
|
|
8
|
-
reset: () => void;
|
|
9
|
-
}
|
|
10
|
-
declare function createMswHandlers(options?: CreateAppOptions & {
|
|
11
|
-
baseUrl?: string;
|
|
12
|
-
}): Promise<MswHandlerSetup>;
|
|
13
|
-
|
|
14
|
-
export { type MswHandlerSetup, createMswHandlers };
|
package/dist/mock/msw.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { A as AppHandle, C as CreateAppOptions } from '../server-CzthOeYS.js';
|
|
2
|
-
import 'hono';
|
|
3
|
-
|
|
4
|
-
interface MswHandlerSetup {
|
|
5
|
-
handlers: unknown[];
|
|
6
|
-
deps: AppHandle["deps"];
|
|
7
|
-
baseUrl: string;
|
|
8
|
-
reset: () => void;
|
|
9
|
-
}
|
|
10
|
-
declare function createMswHandlers(options?: CreateAppOptions & {
|
|
11
|
-
baseUrl?: string;
|
|
12
|
-
}): Promise<MswHandlerSetup>;
|
|
13
|
-
|
|
14
|
-
export { type MswHandlerSetup, createMswHandlers };
|