@cimplify/sdk 0.49.1 → 0.50.0
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 +88 -25
- package/dist/server.d.ts +88 -25
- package/dist/server.js +178 -3
- package/dist/server.mjs +176 -4
- 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.mjs
CHANGED
|
@@ -3,8 +3,14 @@ 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
|
|
|
8
|
+
var DEFAULT_PROD_URL = "https://storefronts.cimplify.io";
|
|
7
9
|
var DEFAULT_DEV_URL = "http://127.0.0.1:8787";
|
|
10
|
+
function defaultBaseUrl() {
|
|
11
|
+
const proc = globalThis.process;
|
|
12
|
+
return proc?.env?.NODE_ENV === "production" ? DEFAULT_PROD_URL : DEFAULT_DEV_URL;
|
|
13
|
+
}
|
|
8
14
|
function readEnv(...keys) {
|
|
9
15
|
const env = globalThis.process?.env;
|
|
10
16
|
if (!env) return void 0;
|
|
@@ -15,7 +21,7 @@ function readEnv(...keys) {
|
|
|
15
21
|
return void 0;
|
|
16
22
|
}
|
|
17
23
|
var getServerClient = cache((opts = {}) => {
|
|
18
|
-
const baseUrl = opts.apiUrl ?? readEnv("CIMPLIFY_API_URL", "NEXT_PUBLIC_CIMPLIFY_API_URL") ??
|
|
24
|
+
const baseUrl = opts.apiUrl ?? readEnv("CIMPLIFY_API_URL", "NEXT_PUBLIC_CIMPLIFY_API_URL") ?? defaultBaseUrl();
|
|
19
25
|
const publicKey = opts.secretKey ?? readEnv("CIMPLIFY_SECRET_KEY", "NEXT_PUBLIC_CIMPLIFY_PUBLIC_KEY") ?? "mock-dev";
|
|
20
26
|
const client = createCimplifyClient({
|
|
21
27
|
baseUrl,
|
|
@@ -56,8 +62,174 @@ var tags = {
|
|
|
56
62
|
order: (id) => `cimplify:order:${id}`
|
|
57
63
|
};
|
|
58
64
|
|
|
65
|
+
// src/server/cache-life.ts
|
|
66
|
+
var CACHE_LIFE_DEFAULT = "max";
|
|
67
|
+
var CACHE_LIFE_PROBE = "seconds";
|
|
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, 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
|
+
|
|
59
231
|
// src/server/revalidate.ts
|
|
60
|
-
var DEFAULT_PROFILE =
|
|
232
|
+
var DEFAULT_PROFILE = CACHE_LIFE_DEFAULT;
|
|
61
233
|
var _revalidateTag = null;
|
|
62
234
|
async function getRevalidateTag() {
|
|
63
235
|
if (_revalidateTag) return _revalidateTag;
|
|
@@ -228,7 +400,7 @@ var SIGNATURE_HEADER = "x-cimplify-signature";
|
|
|
228
400
|
var SIGNATURE_PREFIX = "sha256=";
|
|
229
401
|
var MAX_SKEW_MS = 5 * 60 * 1e3;
|
|
230
402
|
var SECRET_ENV = "CIMPLIFY_REVALIDATE_SECRET";
|
|
231
|
-
var DEFAULT_PROFILE2 =
|
|
403
|
+
var DEFAULT_PROFILE2 = CACHE_LIFE_DEFAULT;
|
|
232
404
|
async function revalidateRouteHandler(req, options = {}) {
|
|
233
405
|
const secret = options.secret ?? envSecret();
|
|
234
406
|
if (!secret) return text(`revalidate disabled: ${SECRET_ENV} not set`, 500);
|
|
@@ -307,4 +479,4 @@ function text(message, status) {
|
|
|
307
479
|
return new Response(message, { status, headers: { "content-type": "text/plain" } });
|
|
308
480
|
}
|
|
309
481
|
|
|
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 };
|
|
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.0",
|
|
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 };
|