@cimplify/sdk 0.70.3 → 0.71.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.
@@ -1,4 +1,4 @@
1
- import { createMockApp } from './chunk-QXMO2LGU.mjs';
1
+ import { createMockApp } from './chunk-J7L5LHGK.mjs';
2
2
  import { createCimplifyClient } from './chunk-H337NF4O.mjs';
3
3
  import { z } from 'zod';
4
4
 
@@ -5584,8 +5584,10 @@ function createLinkService({ clock, ids }) {
5584
5584
  return Boolean(s?.preferences.is_link_enabled);
5585
5585
  },
5586
5586
  checkStatus(contact) {
5587
+ const normalized = contact.trim();
5588
+ const emailContact = normalized.includes("@") ? normalized.toLowerCase() : normalized;
5587
5589
  for (const s of customers.values()) {
5588
- if (s.preferences.is_link_enabled && (s.customer.email === contact || s.customer.phone === contact)) {
5590
+ if (s.preferences.is_link_enabled && (s.customer.email?.toLowerCase() === emailContact || s.customer.phone === normalized)) {
5589
5591
  return true;
5590
5592
  }
5591
5593
  }
@@ -5586,8 +5586,10 @@ function createLinkService({ clock, ids }) {
5586
5586
  return Boolean(s?.preferences.is_link_enabled);
5587
5587
  },
5588
5588
  checkStatus(contact) {
5589
+ const normalized = contact.trim();
5590
+ const emailContact = normalized.includes("@") ? normalized.toLowerCase() : normalized;
5589
5591
  for (const s of customers.values()) {
5590
- if (s.preferences.is_link_enabled && (s.customer.email === contact || s.customer.phone === contact)) {
5592
+ if (s.preferences.is_link_enabled && (s.customer.email?.toLowerCase() === emailContact || s.customer.phone === normalized)) {
5591
5593
  return true;
5592
5594
  }
5593
5595
  }
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkXQ6LEDEO_js = require('./chunk-XQ6LEDEO.js');
3
+ var chunkOGQFDCZM_js = require('./chunk-OGQFDCZM.js');
4
4
  var chunkQS4XDVHI_js = require('./chunk-QS4XDVHI.js');
5
5
  var zod = require('zod');
6
6
 
@@ -595,7 +595,7 @@ async function toForwardedRequest(input, init) {
595
595
  };
596
596
  }
597
597
  function createTestClient(options = {}) {
598
- const mock = chunkXQ6LEDEO_js.createMockApp(options);
598
+ const mock = chunkOGQFDCZM_js.createMockApp(options);
599
599
  let sessionToken;
600
600
  const fetchImpl = async (input, init) => {
601
601
  const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
package/dist/mock/cli.mjs CHANGED
@@ -6289,8 +6289,10 @@ function createLinkService({ clock, ids }) {
6289
6289
  return Boolean(s?.preferences.is_link_enabled);
6290
6290
  },
6291
6291
  checkStatus(contact) {
6292
+ const normalized = contact.trim();
6293
+ const emailContact = normalized.includes("@") ? normalized.toLowerCase() : normalized;
6292
6294
  for (const s of customers.values()) {
6293
- if (s.preferences.is_link_enabled && (s.customer.email === contact || s.customer.phone === contact)) {
6295
+ if (s.preferences.is_link_enabled && (s.customer.email?.toLowerCase() === emailContact || s.customer.phone === normalized)) {
6294
6296
  return true;
6295
6297
  }
6296
6298
  }
@@ -5657,8 +5657,10 @@ function createLinkService({ clock, ids }) {
5657
5657
  return Boolean(s?.preferences.is_link_enabled);
5658
5658
  },
5659
5659
  checkStatus(contact) {
5660
+ const normalized = contact.trim();
5661
+ const emailContact = normalized.includes("@") ? normalized.toLowerCase() : normalized;
5660
5662
  for (const s of customers.values()) {
5661
- if (s.preferences.is_link_enabled && (s.customer.email === contact || s.customer.phone === contact)) {
5663
+ if (s.preferences.is_link_enabled && (s.customer.email?.toLowerCase() === emailContact || s.customer.phone === normalized)) {
5662
5664
  return true;
5663
5665
  }
5664
5666
  }
@@ -5655,8 +5655,10 @@ function createLinkService({ clock, ids }) {
5655
5655
  return Boolean(s?.preferences.is_link_enabled);
5656
5656
  },
5657
5657
  checkStatus(contact) {
5658
+ const normalized = contact.trim();
5659
+ const emailContact = normalized.includes("@") ? normalized.toLowerCase() : normalized;
5658
5660
  for (const s of customers.values()) {
5659
- if (s.preferences.is_link_enabled && (s.customer.email === contact || s.customer.phone === contact)) {
5661
+ if (s.preferences.is_link_enabled && (s.customer.email?.toLowerCase() === emailContact || s.customer.phone === normalized)) {
5660
5662
  return true;
5661
5663
  }
5662
5664
  }
package/dist/mock/msw.js CHANGED
@@ -5655,8 +5655,10 @@ function createLinkService({ clock, ids }) {
5655
5655
  return Boolean(s?.preferences.is_link_enabled);
5656
5656
  },
5657
5657
  checkStatus(contact) {
5658
+ const normalized = contact.trim();
5659
+ const emailContact = normalized.includes("@") ? normalized.toLowerCase() : normalized;
5658
5660
  for (const s of customers.values()) {
5659
- if (s.preferences.is_link_enabled && (s.customer.email === contact || s.customer.phone === contact)) {
5661
+ if (s.preferences.is_link_enabled && (s.customer.email?.toLowerCase() === emailContact || s.customer.phone === normalized)) {
5660
5662
  return true;
5661
5663
  }
5662
5664
  }
package/dist/mock/msw.mjs CHANGED
@@ -5653,8 +5653,10 @@ function createLinkService({ clock, ids }) {
5653
5653
  return Boolean(s?.preferences.is_link_enabled);
5654
5654
  },
5655
5655
  checkStatus(contact) {
5656
+ const normalized = contact.trim();
5657
+ const emailContact = normalized.includes("@") ? normalized.toLowerCase() : normalized;
5656
5658
  for (const s of customers.values()) {
5657
- if (s.preferences.is_link_enabled && (s.customer.email === contact || s.customer.phone === contact)) {
5659
+ if (s.preferences.is_link_enabled && (s.customer.email?.toLowerCase() === emailContact || s.customer.phone === normalized)) {
5658
5660
  return true;
5659
5661
  }
5660
5662
  }
@@ -0,0 +1,74 @@
1
+ import { R2Bucket, DurableObjectNamespace } from '@cloudflare/workers-types';
2
+
3
+ /**
4
+ * `@cimplify/sdk/server/tanstack` - TanStack Start/Nitro cache support.
5
+ *
6
+ * The deployment adapter binds:
7
+ * - CIMPLIFY_CACHE_R2_BUCKET
8
+ * - CIMPLIFY_CACHE_R2_PREFIX
9
+ * - CIMPLIFY_PATH_INDEX
10
+ *
11
+ * This driver consumes those bindings and mirrors the Next/OpenNext eviction
12
+ * contract: write to R2, then register cimplify:* tags in PathIndex so the
13
+ * central eviction worker can delete the exact R2 object and purge route URLs.
14
+ */
15
+
16
+ declare const TANSTACK_R2_BUCKET_BINDING = "CIMPLIFY_CACHE_R2_BUCKET";
17
+ declare const TANSTACK_R2_PREFIX_ENV = "CIMPLIFY_CACHE_R2_PREFIX";
18
+ declare const TANSTACK_PATH_INDEX_BINDING = "CIMPLIFY_PATH_INDEX";
19
+ declare const TANSTACK_CACHE_NAMESPACE = "nitro";
20
+ declare const CIMPLIFY_TAG_PREFIX = "cimplify:";
21
+ declare const CIMPLIFY_CACHE_META_FIELD = "__cimplifyCache";
22
+ type Awaitable<T> = T | Promise<T>;
23
+ type R2PutValue = NonNullable<Parameters<R2Bucket["put"]>[1]>;
24
+ interface CimplifyTanstackCacheEnv {
25
+ [TANSTACK_R2_BUCKET_BINDING]?: R2Bucket;
26
+ [TANSTACK_R2_PREFIX_ENV]?: string;
27
+ [TANSTACK_PATH_INDEX_BINDING]?: DurableObjectNamespace;
28
+ }
29
+ interface CimplifyCacheIndexMetadata {
30
+ tags?: readonly string[];
31
+ cacheKey?: string;
32
+ isFetch?: boolean;
33
+ }
34
+ interface CimplifyTanstackCacheSetOptions {
35
+ tags?: readonly string[];
36
+ cimplifyTags?: readonly string[];
37
+ cacheTags?: readonly string[];
38
+ cacheKey?: string;
39
+ cimplifyCacheKey?: string;
40
+ isFetch?: boolean;
41
+ cimplifyIsFetch?: boolean;
42
+ [CIMPLIFY_CACHE_META_FIELD]?: CimplifyCacheIndexMetadata;
43
+ [key: string]: unknown;
44
+ }
45
+ interface CimplifyTanstackCacheDriverOptions {
46
+ env?: CimplifyTanstackCacheEnv;
47
+ getEnv?: () => Awaitable<CimplifyTanstackCacheEnv | undefined>;
48
+ prefix?: string;
49
+ namespace?: string;
50
+ tags?: readonly string[] | ((key: string, value: unknown, options?: unknown) => readonly string[]);
51
+ cacheKey?: string | ((key: string, value: unknown, options?: unknown) => string | undefined);
52
+ isFetch?: boolean | ((key: string, value: unknown, options?: unknown) => boolean);
53
+ }
54
+ interface CimplifyTanstackCacheDriver {
55
+ name: string;
56
+ options: CimplifyTanstackCacheDriverOptions;
57
+ hasItem(key: string): Promise<boolean>;
58
+ getItem<T = unknown>(key: string): Promise<T | null>;
59
+ getItemRaw(key: string): Promise<string | null>;
60
+ setItem(key: string, value: unknown, options?: CimplifyTanstackCacheSetOptions): Promise<void>;
61
+ setItemRaw(key: string, value: R2PutValue, options?: CimplifyTanstackCacheSetOptions): Promise<void>;
62
+ removeItem(key: string): Promise<void>;
63
+ getKeys(base?: string): Promise<string[]>;
64
+ clear(base?: string): Promise<void>;
65
+ }
66
+ declare function cimplifyTanstackR2Key(prefix: string, key: string, namespace?: string): string;
67
+ declare function cimplifyTanstackCacheOptions(metadata: CimplifyCacheIndexMetadata): CimplifyTanstackCacheSetOptions;
68
+ declare function withCimplifyCacheMetadata<T extends Record<string, unknown>>(value: T, metadata: CimplifyCacheIndexMetadata): T & {
69
+ [CIMPLIFY_CACHE_META_FIELD]: CimplifyCacheIndexMetadata;
70
+ };
71
+ declare function createCimplifyTanstackCacheDriver(options?: CimplifyTanstackCacheDriverOptions): CimplifyTanstackCacheDriver;
72
+ declare const cimplifyTanstackCacheDriver: typeof createCimplifyTanstackCacheDriver;
73
+
74
+ export { CIMPLIFY_CACHE_META_FIELD, CIMPLIFY_TAG_PREFIX, type CimplifyCacheIndexMetadata, type CimplifyTanstackCacheDriver, type CimplifyTanstackCacheDriverOptions, type CimplifyTanstackCacheEnv, type CimplifyTanstackCacheSetOptions, TANSTACK_CACHE_NAMESPACE, TANSTACK_PATH_INDEX_BINDING, TANSTACK_R2_BUCKET_BINDING, TANSTACK_R2_PREFIX_ENV, cimplifyTanstackCacheDriver, cimplifyTanstackCacheOptions, cimplifyTanstackR2Key, createCimplifyTanstackCacheDriver, withCimplifyCacheMetadata };
@@ -0,0 +1,74 @@
1
+ import { R2Bucket, DurableObjectNamespace } from '@cloudflare/workers-types';
2
+
3
+ /**
4
+ * `@cimplify/sdk/server/tanstack` - TanStack Start/Nitro cache support.
5
+ *
6
+ * The deployment adapter binds:
7
+ * - CIMPLIFY_CACHE_R2_BUCKET
8
+ * - CIMPLIFY_CACHE_R2_PREFIX
9
+ * - CIMPLIFY_PATH_INDEX
10
+ *
11
+ * This driver consumes those bindings and mirrors the Next/OpenNext eviction
12
+ * contract: write to R2, then register cimplify:* tags in PathIndex so the
13
+ * central eviction worker can delete the exact R2 object and purge route URLs.
14
+ */
15
+
16
+ declare const TANSTACK_R2_BUCKET_BINDING = "CIMPLIFY_CACHE_R2_BUCKET";
17
+ declare const TANSTACK_R2_PREFIX_ENV = "CIMPLIFY_CACHE_R2_PREFIX";
18
+ declare const TANSTACK_PATH_INDEX_BINDING = "CIMPLIFY_PATH_INDEX";
19
+ declare const TANSTACK_CACHE_NAMESPACE = "nitro";
20
+ declare const CIMPLIFY_TAG_PREFIX = "cimplify:";
21
+ declare const CIMPLIFY_CACHE_META_FIELD = "__cimplifyCache";
22
+ type Awaitable<T> = T | Promise<T>;
23
+ type R2PutValue = NonNullable<Parameters<R2Bucket["put"]>[1]>;
24
+ interface CimplifyTanstackCacheEnv {
25
+ [TANSTACK_R2_BUCKET_BINDING]?: R2Bucket;
26
+ [TANSTACK_R2_PREFIX_ENV]?: string;
27
+ [TANSTACK_PATH_INDEX_BINDING]?: DurableObjectNamespace;
28
+ }
29
+ interface CimplifyCacheIndexMetadata {
30
+ tags?: readonly string[];
31
+ cacheKey?: string;
32
+ isFetch?: boolean;
33
+ }
34
+ interface CimplifyTanstackCacheSetOptions {
35
+ tags?: readonly string[];
36
+ cimplifyTags?: readonly string[];
37
+ cacheTags?: readonly string[];
38
+ cacheKey?: string;
39
+ cimplifyCacheKey?: string;
40
+ isFetch?: boolean;
41
+ cimplifyIsFetch?: boolean;
42
+ [CIMPLIFY_CACHE_META_FIELD]?: CimplifyCacheIndexMetadata;
43
+ [key: string]: unknown;
44
+ }
45
+ interface CimplifyTanstackCacheDriverOptions {
46
+ env?: CimplifyTanstackCacheEnv;
47
+ getEnv?: () => Awaitable<CimplifyTanstackCacheEnv | undefined>;
48
+ prefix?: string;
49
+ namespace?: string;
50
+ tags?: readonly string[] | ((key: string, value: unknown, options?: unknown) => readonly string[]);
51
+ cacheKey?: string | ((key: string, value: unknown, options?: unknown) => string | undefined);
52
+ isFetch?: boolean | ((key: string, value: unknown, options?: unknown) => boolean);
53
+ }
54
+ interface CimplifyTanstackCacheDriver {
55
+ name: string;
56
+ options: CimplifyTanstackCacheDriverOptions;
57
+ hasItem(key: string): Promise<boolean>;
58
+ getItem<T = unknown>(key: string): Promise<T | null>;
59
+ getItemRaw(key: string): Promise<string | null>;
60
+ setItem(key: string, value: unknown, options?: CimplifyTanstackCacheSetOptions): Promise<void>;
61
+ setItemRaw(key: string, value: R2PutValue, options?: CimplifyTanstackCacheSetOptions): Promise<void>;
62
+ removeItem(key: string): Promise<void>;
63
+ getKeys(base?: string): Promise<string[]>;
64
+ clear(base?: string): Promise<void>;
65
+ }
66
+ declare function cimplifyTanstackR2Key(prefix: string, key: string, namespace?: string): string;
67
+ declare function cimplifyTanstackCacheOptions(metadata: CimplifyCacheIndexMetadata): CimplifyTanstackCacheSetOptions;
68
+ declare function withCimplifyCacheMetadata<T extends Record<string, unknown>>(value: T, metadata: CimplifyCacheIndexMetadata): T & {
69
+ [CIMPLIFY_CACHE_META_FIELD]: CimplifyCacheIndexMetadata;
70
+ };
71
+ declare function createCimplifyTanstackCacheDriver(options?: CimplifyTanstackCacheDriverOptions): CimplifyTanstackCacheDriver;
72
+ declare const cimplifyTanstackCacheDriver: typeof createCimplifyTanstackCacheDriver;
73
+
74
+ export { CIMPLIFY_CACHE_META_FIELD, CIMPLIFY_TAG_PREFIX, type CimplifyCacheIndexMetadata, type CimplifyTanstackCacheDriver, type CimplifyTanstackCacheDriverOptions, type CimplifyTanstackCacheEnv, type CimplifyTanstackCacheSetOptions, TANSTACK_CACHE_NAMESPACE, TANSTACK_PATH_INDEX_BINDING, TANSTACK_R2_BUCKET_BINDING, TANSTACK_R2_PREFIX_ENV, cimplifyTanstackCacheDriver, cimplifyTanstackCacheOptions, cimplifyTanstackR2Key, createCimplifyTanstackCacheDriver, withCimplifyCacheMetadata };
@@ -0,0 +1,291 @@
1
+ 'use strict';
2
+
3
+ require('../chunk-OWW5GUSB.js');
4
+
5
+ // src/server/tanstack.ts
6
+ var TANSTACK_R2_BUCKET_BINDING = "CIMPLIFY_CACHE_R2_BUCKET";
7
+ var TANSTACK_R2_PREFIX_ENV = "CIMPLIFY_CACHE_R2_PREFIX";
8
+ var TANSTACK_PATH_INDEX_BINDING = "CIMPLIFY_PATH_INDEX";
9
+ var TANSTACK_CACHE_NAMESPACE = "nitro";
10
+ var CIMPLIFY_TAG_PREFIX = "cimplify:";
11
+ var CIMPLIFY_CACHE_META_FIELD = "__cimplifyCache";
12
+ var EMPTY_STORAGE_KEY = "__cimplify_empty_key__";
13
+ function isRecord(value) {
14
+ return typeof value === "object" && value !== null && !Array.isArray(value);
15
+ }
16
+ function stringArray(value) {
17
+ return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
18
+ }
19
+ function metadataFrom(value) {
20
+ if (!isRecord(value)) return void 0;
21
+ const metadata = value[CIMPLIFY_CACHE_META_FIELD];
22
+ return isRecord(metadata) ? metadata : void 0;
23
+ }
24
+ function cimplifyTagsFrom(candidates) {
25
+ const seen = /* @__PURE__ */ new Set();
26
+ for (const candidate of candidates) {
27
+ for (const tag of candidate ?? []) {
28
+ if (!tag.startsWith(CIMPLIFY_TAG_PREFIX) || seen.has(tag)) continue;
29
+ seen.add(tag);
30
+ }
31
+ }
32
+ return [...seen];
33
+ }
34
+ function extractTags(key, value, options, driverOptions) {
35
+ const optionMeta = metadataFrom(options);
36
+ const valueMeta = metadataFrom(value);
37
+ const valueRecord = isRecord(value) ? value : void 0;
38
+ const nestedValue = isRecord(valueRecord?.value) ? valueRecord.value : void 0;
39
+ const configured = typeof driverOptions.tags === "function" ? driverOptions.tags(key, value, options) : driverOptions.tags;
40
+ return cimplifyTagsFrom([
41
+ configured,
42
+ optionMeta?.tags,
43
+ options?.tags,
44
+ options?.cimplifyTags,
45
+ options?.cacheTags,
46
+ valueMeta?.tags,
47
+ stringArray(valueRecord?.tags),
48
+ stringArray(valueRecord?.cimplifyTags),
49
+ stringArray(valueRecord?.cacheTags),
50
+ stringArray(nestedValue?.tags),
51
+ stringArray(nestedValue?.cimplifyTags),
52
+ stringArray(nestedValue?.cacheTags)
53
+ ]);
54
+ }
55
+ function extractCacheKey(key, value, options, driverOptions) {
56
+ const configured = typeof driverOptions.cacheKey === "function" ? driverOptions.cacheKey(key, value, options) : driverOptions.cacheKey;
57
+ if (configured) return configured;
58
+ const optionMeta = metadataFrom(options);
59
+ const valueMeta = metadataFrom(value);
60
+ if (optionMeta?.cacheKey) return optionMeta.cacheKey;
61
+ if (options?.cacheKey) return options.cacheKey;
62
+ if (options?.cimplifyCacheKey) return options.cimplifyCacheKey;
63
+ if (valueMeta?.cacheKey) return valueMeta.cacheKey;
64
+ return key;
65
+ }
66
+ function extractIsFetch(key, value, options, driverOptions) {
67
+ if (typeof driverOptions.isFetch === "function") {
68
+ return driverOptions.isFetch(key, value, options);
69
+ }
70
+ if (typeof driverOptions.isFetch === "boolean") return driverOptions.isFetch;
71
+ const optionMeta = metadataFrom(options);
72
+ const valueMeta = metadataFrom(value);
73
+ return Boolean(
74
+ optionMeta?.isFetch ?? options?.isFetch ?? options?.cimplifyIsFetch ?? valueMeta?.isFetch ?? false
75
+ );
76
+ }
77
+ function valueForStorage(value) {
78
+ if (!isRecord(value) || !(CIMPLIFY_CACHE_META_FIELD in value)) return value;
79
+ const { [CIMPLIFY_CACHE_META_FIELD]: _metadata, ...rest } = value;
80
+ return rest;
81
+ }
82
+ function joinR2Parts(...parts) {
83
+ return parts.map((part) => part.trim().replace(/^\/+|\/+$/g, "")).filter(Boolean).join("/");
84
+ }
85
+ function encodeStorageKey(key) {
86
+ return key === "" ? EMPTY_STORAGE_KEY : encodeURIComponent(key);
87
+ }
88
+ function decodeStorageKey(key) {
89
+ if (key === EMPTY_STORAGE_KEY) return "";
90
+ try {
91
+ return decodeURIComponent(key);
92
+ } catch {
93
+ return key;
94
+ }
95
+ }
96
+ function cimplifyTanstackR2Key(prefix, key, namespace = TANSTACK_CACHE_NAMESPACE) {
97
+ return joinR2Parts(prefix, namespace, encodeStorageKey(key));
98
+ }
99
+ function cimplifyTanstackR2ListPrefix(prefix, base, namespace) {
100
+ if (!base) return `${joinR2Parts(prefix, namespace)}/`;
101
+ return cimplifyTanstackR2Key(prefix, base, namespace);
102
+ }
103
+ function storageKeyFromR2Key(prefix, namespace, key) {
104
+ const base = `${joinR2Parts(prefix, namespace)}/`;
105
+ const encoded = key.startsWith(base) ? key.slice(base.length) : key;
106
+ return decodeStorageKey(encoded);
107
+ }
108
+ function pathIndexFor(env) {
109
+ if (!env.pathIndex) return null;
110
+ return env.pathIndex.get(env.pathIndex.idFromName(env.prefix));
111
+ }
112
+ async function resolveRuntimeEnv(options) {
113
+ const env = await options.getEnv?.() ?? options.env;
114
+ const r2 = env?.[TANSTACK_R2_BUCKET_BINDING];
115
+ const prefix = options.prefix ?? env?.[TANSTACK_R2_PREFIX_ENV];
116
+ if (!r2 || !prefix) return null;
117
+ return {
118
+ r2,
119
+ prefix,
120
+ pathIndex: env?.[TANSTACK_PATH_INDEX_BINDING]
121
+ };
122
+ }
123
+ async function registerIndex(env, cacheKey, r2Key, tags, isFetch) {
124
+ if (tags.length === 0) return;
125
+ const index = pathIndexFor(env);
126
+ if (!index) return;
127
+ try {
128
+ await index.indexAdd(cacheKey, r2Key, tags, isFetch);
129
+ } catch {
130
+ }
131
+ }
132
+ async function listR2Keys(r2, prefix) {
133
+ const keys = [];
134
+ let cursor;
135
+ do {
136
+ const page = await r2.list({ prefix, cursor });
137
+ keys.push(...page.objects.map((object) => object.key));
138
+ cursor = page.truncated ? page.cursor : void 0;
139
+ } while (cursor);
140
+ return keys;
141
+ }
142
+ async function putAndIndex(runtimeEnv, driverOptions, key, storedValue, indexValue, options) {
143
+ const namespace = driverOptions.namespace ?? TANSTACK_CACHE_NAMESPACE;
144
+ const r2Key = cimplifyTanstackR2Key(runtimeEnv.prefix, key, namespace);
145
+ try {
146
+ await runtimeEnv.r2.put(r2Key, storedValue);
147
+ } catch {
148
+ return;
149
+ }
150
+ try {
151
+ const tags = extractTags(key, indexValue, options, driverOptions);
152
+ if (tags.length === 0) return;
153
+ await registerIndex(
154
+ runtimeEnv,
155
+ extractCacheKey(key, indexValue, options, driverOptions),
156
+ r2Key,
157
+ tags,
158
+ extractIsFetch(key, indexValue, options, driverOptions)
159
+ );
160
+ } catch {
161
+ }
162
+ }
163
+ async function getRawItem(driverOptions, key) {
164
+ const runtimeEnv = await resolveRuntimeEnv(driverOptions);
165
+ if (!runtimeEnv) return null;
166
+ try {
167
+ const object = await runtimeEnv.r2.get(
168
+ cimplifyTanstackR2Key(
169
+ runtimeEnv.prefix,
170
+ key,
171
+ driverOptions.namespace ?? TANSTACK_CACHE_NAMESPACE
172
+ )
173
+ );
174
+ return object ? await object.text() : null;
175
+ } catch {
176
+ return null;
177
+ }
178
+ }
179
+ function cimplifyTanstackCacheOptions(metadata) {
180
+ return { [CIMPLIFY_CACHE_META_FIELD]: metadata };
181
+ }
182
+ function withCimplifyCacheMetadata(value, metadata) {
183
+ return { ...value, [CIMPLIFY_CACHE_META_FIELD]: metadata };
184
+ }
185
+ function createCimplifyTanstackCacheDriver(options = {}) {
186
+ const driverOptions = { ...options };
187
+ return {
188
+ name: "cimplify-tanstack-r2-cache",
189
+ options: driverOptions,
190
+ async hasItem(key) {
191
+ const runtimeEnv = await resolveRuntimeEnv(driverOptions);
192
+ if (!runtimeEnv) return false;
193
+ try {
194
+ const object = await runtimeEnv.r2.head(
195
+ cimplifyTanstackR2Key(
196
+ runtimeEnv.prefix,
197
+ key,
198
+ driverOptions.namespace ?? TANSTACK_CACHE_NAMESPACE
199
+ )
200
+ );
201
+ return Boolean(object);
202
+ } catch {
203
+ return false;
204
+ }
205
+ },
206
+ async getItem(key) {
207
+ const raw = await getRawItem(driverOptions, key);
208
+ if (raw === null) return null;
209
+ try {
210
+ return JSON.parse(raw);
211
+ } catch {
212
+ return raw;
213
+ }
214
+ },
215
+ async getItemRaw(key) {
216
+ return getRawItem(driverOptions, key);
217
+ },
218
+ async setItem(key, value, options2) {
219
+ const runtimeEnv = await resolveRuntimeEnv(driverOptions);
220
+ if (!runtimeEnv) return;
221
+ const strippedValue = valueForStorage(value);
222
+ await putAndIndex(
223
+ runtimeEnv,
224
+ driverOptions,
225
+ key,
226
+ JSON.stringify(strippedValue) ?? "null",
227
+ value,
228
+ options2
229
+ );
230
+ },
231
+ async setItemRaw(key, value, options2) {
232
+ const runtimeEnv = await resolveRuntimeEnv(driverOptions);
233
+ if (!runtimeEnv) return;
234
+ await putAndIndex(runtimeEnv, driverOptions, key, value, value, options2);
235
+ },
236
+ async removeItem(key) {
237
+ const runtimeEnv = await resolveRuntimeEnv(driverOptions);
238
+ if (!runtimeEnv) return;
239
+ try {
240
+ await runtimeEnv.r2.delete(
241
+ cimplifyTanstackR2Key(
242
+ runtimeEnv.prefix,
243
+ key,
244
+ driverOptions.namespace ?? TANSTACK_CACHE_NAMESPACE
245
+ )
246
+ );
247
+ } catch {
248
+ }
249
+ },
250
+ async getKeys(base) {
251
+ const runtimeEnv = await resolveRuntimeEnv(driverOptions);
252
+ if (!runtimeEnv) return [];
253
+ const namespace = driverOptions.namespace ?? TANSTACK_CACHE_NAMESPACE;
254
+ try {
255
+ const keys = await listR2Keys(
256
+ runtimeEnv.r2,
257
+ cimplifyTanstackR2ListPrefix(runtimeEnv.prefix, base, namespace)
258
+ );
259
+ return keys.map((key) => storageKeyFromR2Key(runtimeEnv.prefix, namespace, key));
260
+ } catch {
261
+ return [];
262
+ }
263
+ },
264
+ async clear(base) {
265
+ const runtimeEnv = await resolveRuntimeEnv(driverOptions);
266
+ if (!runtimeEnv) return;
267
+ const namespace = driverOptions.namespace ?? TANSTACK_CACHE_NAMESPACE;
268
+ try {
269
+ const keys = await listR2Keys(
270
+ runtimeEnv.r2,
271
+ cimplifyTanstackR2ListPrefix(runtimeEnv.prefix, base, namespace)
272
+ );
273
+ await Promise.all(keys.map((key) => runtimeEnv.r2.delete(key)));
274
+ } catch {
275
+ }
276
+ }
277
+ };
278
+ }
279
+ var cimplifyTanstackCacheDriver = createCimplifyTanstackCacheDriver;
280
+
281
+ exports.CIMPLIFY_CACHE_META_FIELD = CIMPLIFY_CACHE_META_FIELD;
282
+ exports.CIMPLIFY_TAG_PREFIX = CIMPLIFY_TAG_PREFIX;
283
+ exports.TANSTACK_CACHE_NAMESPACE = TANSTACK_CACHE_NAMESPACE;
284
+ exports.TANSTACK_PATH_INDEX_BINDING = TANSTACK_PATH_INDEX_BINDING;
285
+ exports.TANSTACK_R2_BUCKET_BINDING = TANSTACK_R2_BUCKET_BINDING;
286
+ exports.TANSTACK_R2_PREFIX_ENV = TANSTACK_R2_PREFIX_ENV;
287
+ exports.cimplifyTanstackCacheDriver = cimplifyTanstackCacheDriver;
288
+ exports.cimplifyTanstackCacheOptions = cimplifyTanstackCacheOptions;
289
+ exports.cimplifyTanstackR2Key = cimplifyTanstackR2Key;
290
+ exports.createCimplifyTanstackCacheDriver = createCimplifyTanstackCacheDriver;
291
+ exports.withCimplifyCacheMetadata = withCimplifyCacheMetadata;