kassza 0.1.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/LICENSE +21 -0
- package/README.md +150 -0
- package/agents/README.md +59 -0
- package/agents/api.md +206 -0
- package/agents/pitfalls.md +52 -0
- package/agents/recipes.md +217 -0
- package/agents/skills/kassza/SKILL.md +29 -0
- package/assets/logo-wordmark.svg +25 -0
- package/assets/logo.svg +19 -0
- package/dist/binary-B89HM03_.cjs +63 -0
- package/dist/binary-D0M9U2MD.js +34 -0
- package/dist/client-B9kbKKBf.d.cts +748 -0
- package/dist/client-zv4enyq7.d.ts +748 -0
- package/dist/cookie-stores/index.cjs +153 -0
- package/dist/cookie-stores/index.d.cts +63 -0
- package/dist/cookie-stores/index.d.ts +63 -0
- package/dist/cookie-stores/index.js +144 -0
- package/dist/create-BZd6CUO7.cjs +1160 -0
- package/dist/create-DDZaNlOz.js +939 -0
- package/dist/dates-D2XebOIg.js +34 -0
- package/dist/dates-DtHzwNU6.d.cts +7 -0
- package/dist/dates-DtHzwNU6.d.ts +7 -0
- package/dist/dates-PPxH0n5H.cjs +57 -0
- package/dist/errors-B0QJhUW1.cjs +302 -0
- package/dist/errors-DapdV5DK.js +273 -0
- package/dist/index-CYAGCdKJ.d.cts +56 -0
- package/dist/index-CYAGCdKJ.d.ts +56 -0
- package/dist/index.cjs +1406 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +1394 -0
- package/dist/ipn/index.cjs +108 -0
- package/dist/ipn/index.d.cts +32 -0
- package/dist/ipn/index.d.ts +32 -0
- package/dist/ipn/index.js +101 -0
- package/dist/money/index.cjs +15 -0
- package/dist/money/index.d.cts +2 -0
- package/dist/money/index.d.ts +2 -0
- package/dist/money/index.js +2 -0
- package/dist/money-C9j7nBNP.js +258 -0
- package/dist/money-DkiGukAw.cjs +335 -0
- package/dist/session-CRGOuz-R.cjs +100 -0
- package/dist/session-Dm_45x8K.d.cts +11 -0
- package/dist/session-Dm_45x8K.d.ts +11 -0
- package/dist/session-OJMLGufT.js +77 -0
- package/dist/shared-CrxlxI8n.cjs +207 -0
- package/dist/shared-D6DLa4b7.js +100 -0
- package/dist/storage/fs.cjs +88 -0
- package/dist/storage/fs.d.cts +13 -0
- package/dist/storage/fs.d.ts +13 -0
- package/dist/storage/fs.js +87 -0
- package/dist/storage/index.cjs +643 -0
- package/dist/storage/index.d.cts +288 -0
- package/dist/storage/index.d.ts +288 -0
- package/dist/storage/index.js +619 -0
- package/dist/testing/index.cjs +409 -0
- package/dist/testing/index.d.cts +35 -0
- package/dist/testing/index.d.ts +35 -0
- package/dist/testing/index.js +407 -0
- package/dist/types-DVRgwcqg.d.cts +26 -0
- package/dist/types-DVRgwcqg.d.ts +26 -0
- package/dist/validators/index.cjs +296 -0
- package/dist/validators/index.d.cts +51 -0
- package/dist/validators/index.d.ts +51 -0
- package/dist/validators/index.js +278 -0
- package/llms.txt +16 -0
- package/package.json +151 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_binary = require("../binary-B89HM03_.cjs");
|
|
3
|
+
const require_session = require("../session-CRGOuz-R.cjs");
|
|
4
|
+
//#region src/cookie-stores/resilient.ts
|
|
5
|
+
function warnCookieStoreError(event) {
|
|
6
|
+
console.warn(`[szamlazz] A session cookie store "${event.operation}" művelete sikertelen, a kérés session nélkül folytatódik.`, event.error);
|
|
7
|
+
}
|
|
8
|
+
function withTimeout(promise, timeoutMs, operation) {
|
|
9
|
+
if (timeoutMs === void 0) return promise;
|
|
10
|
+
let timer;
|
|
11
|
+
const timeout = new Promise((_, reject) => {
|
|
12
|
+
timer = setTimeout(() => {
|
|
13
|
+
reject(/* @__PURE__ */ new Error(`A session cookie store "${operation}" művelete nem fejeződött be ${timeoutMs} ms alatt.`));
|
|
14
|
+
}, timeoutMs);
|
|
15
|
+
});
|
|
16
|
+
return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
|
|
17
|
+
}
|
|
18
|
+
function resilientCookieStore(store, options = {}) {
|
|
19
|
+
const onError = options.onError ?? warnCookieStoreError;
|
|
20
|
+
if (options.timeoutMs !== void 0 && !(options.timeoutMs > 0)) throw new RangeError(`A timeoutMs pozitív szám legyen, kapott: ${options.timeoutMs}`);
|
|
21
|
+
function report(operation, key, error) {
|
|
22
|
+
try {
|
|
23
|
+
onError({
|
|
24
|
+
operation,
|
|
25
|
+
key,
|
|
26
|
+
error
|
|
27
|
+
});
|
|
28
|
+
} catch {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async function run(operation, key, call) {
|
|
33
|
+
try {
|
|
34
|
+
return await withTimeout(Promise.resolve().then(call), options.timeoutMs, operation);
|
|
35
|
+
} catch (error) {
|
|
36
|
+
report(operation, key, error);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
async get(key) {
|
|
42
|
+
return await run("get", key, () => store.get(key)) ?? void 0;
|
|
43
|
+
},
|
|
44
|
+
async set(key, value, ttlSeconds) {
|
|
45
|
+
await run("set", key, () => store.set(key, value, ttlSeconds));
|
|
46
|
+
},
|
|
47
|
+
async delete(key) {
|
|
48
|
+
await run("delete", key, () => store.delete(key));
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/cookie-stores/shared.ts
|
|
54
|
+
function prefixKey(options, key) {
|
|
55
|
+
const prefix = options?.prefix;
|
|
56
|
+
return prefix ? `${prefix}${key}` : key;
|
|
57
|
+
}
|
|
58
|
+
function finalizeCookieStore(store, options) {
|
|
59
|
+
if (options?.resilient === false) return store;
|
|
60
|
+
return resilientCookieStore(store, {
|
|
61
|
+
onError: options?.onError,
|
|
62
|
+
timeoutMs: options?.timeoutMs
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function readCookieValue(value) {
|
|
66
|
+
if (typeof value === "string") return value === "" ? void 0 : value;
|
|
67
|
+
if (value instanceof Uint8Array) return readCookieValue(require_binary.decodeUtf8(value));
|
|
68
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
69
|
+
}
|
|
70
|
+
function wholeSeconds(ttlSeconds, minimum) {
|
|
71
|
+
if (!Number.isFinite(ttlSeconds)) return minimum;
|
|
72
|
+
return Math.max(minimum, Math.ceil(ttlSeconds));
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/cookie-stores/cloudflare-kv.ts
|
|
76
|
+
const CLOUDFLARE_KV_MIN_TTL_SECONDS = 60;
|
|
77
|
+
function cloudflareKvCookieStore(namespace, options) {
|
|
78
|
+
return finalizeCookieStore({
|
|
79
|
+
async get(key) {
|
|
80
|
+
return readCookieValue(await namespace.get(prefixKey(options, key)));
|
|
81
|
+
},
|
|
82
|
+
async set(key, value, ttlSeconds) {
|
|
83
|
+
await namespace.put(prefixKey(options, key), value, { expirationTtl: wholeSeconds(ttlSeconds, 60) });
|
|
84
|
+
},
|
|
85
|
+
async delete(key) {
|
|
86
|
+
await namespace.delete(prefixKey(options, key));
|
|
87
|
+
}
|
|
88
|
+
}, options);
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/cookie-stores/custom.ts
|
|
92
|
+
function customCookieStore(store, options) {
|
|
93
|
+
return finalizeCookieStore({
|
|
94
|
+
get: (key) => store.get(prefixKey(options, key)),
|
|
95
|
+
set: (key, value, ttlSeconds) => store.set(prefixKey(options, key), value, ttlSeconds),
|
|
96
|
+
delete: (key) => store.delete(prefixKey(options, key))
|
|
97
|
+
}, options);
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/cookie-stores/ioredis.ts
|
|
101
|
+
function ioredisCookieStore(redis, options) {
|
|
102
|
+
return finalizeCookieStore({
|
|
103
|
+
async get(key) {
|
|
104
|
+
return readCookieValue(await redis.get(prefixKey(options, key)));
|
|
105
|
+
},
|
|
106
|
+
async set(key, value, ttlSeconds) {
|
|
107
|
+
await redis.set(prefixKey(options, key), value, "EX", wholeSeconds(ttlSeconds, 1));
|
|
108
|
+
},
|
|
109
|
+
async delete(key) {
|
|
110
|
+
await redis.del(prefixKey(options, key));
|
|
111
|
+
}
|
|
112
|
+
}, options);
|
|
113
|
+
}
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/cookie-stores/node-redis.ts
|
|
116
|
+
function nodeRedisCookieStore(client, options) {
|
|
117
|
+
return finalizeCookieStore({
|
|
118
|
+
async get(key) {
|
|
119
|
+
return readCookieValue(await client.get(prefixKey(options, key)));
|
|
120
|
+
},
|
|
121
|
+
async set(key, value, ttlSeconds) {
|
|
122
|
+
await client.set(prefixKey(options, key), value, { EX: wholeSeconds(ttlSeconds, 1) });
|
|
123
|
+
},
|
|
124
|
+
async delete(key) {
|
|
125
|
+
await client.del(prefixKey(options, key));
|
|
126
|
+
}
|
|
127
|
+
}, options);
|
|
128
|
+
}
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region src/cookie-stores/upstash.ts
|
|
131
|
+
function upstashRedisCookieStore(redis, options) {
|
|
132
|
+
return finalizeCookieStore({
|
|
133
|
+
async get(key) {
|
|
134
|
+
return readCookieValue(await redis.get(prefixKey(options, key)));
|
|
135
|
+
},
|
|
136
|
+
async set(key, value, ttlSeconds) {
|
|
137
|
+
await redis.set(prefixKey(options, key), value, { ex: wholeSeconds(ttlSeconds, 1) });
|
|
138
|
+
},
|
|
139
|
+
async delete(key) {
|
|
140
|
+
await redis.del(prefixKey(options, key));
|
|
141
|
+
}
|
|
142
|
+
}, options);
|
|
143
|
+
}
|
|
144
|
+
//#endregion
|
|
145
|
+
exports.CLOUDFLARE_KV_MIN_TTL_SECONDS = CLOUDFLARE_KV_MIN_TTL_SECONDS;
|
|
146
|
+
exports.SESSION_TTL_SECONDS = require_session.SESSION_TTL_SECONDS;
|
|
147
|
+
exports.cloudflareKvCookieStore = cloudflareKvCookieStore;
|
|
148
|
+
exports.customCookieStore = customCookieStore;
|
|
149
|
+
exports.ioredisCookieStore = ioredisCookieStore;
|
|
150
|
+
exports.memoryCookieStore = require_session.memoryCookieStore;
|
|
151
|
+
exports.nodeRedisCookieStore = nodeRedisCookieStore;
|
|
152
|
+
exports.resilientCookieStore = resilientCookieStore;
|
|
153
|
+
exports.upstashRedisCookieStore = upstashRedisCookieStore;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { n as SESSION_TTL_SECONDS, r as memoryCookieStore, t as CookieStore } from "../session-Dm_45x8K.cjs";
|
|
2
|
+
//#region src/cookie-stores/resilient.d.ts
|
|
3
|
+
type CookieStoreOperation = "get" | "set" | "delete";
|
|
4
|
+
interface CookieStoreErrorEvent {
|
|
5
|
+
readonly operation: CookieStoreOperation;
|
|
6
|
+
readonly key: string;
|
|
7
|
+
readonly error: unknown;
|
|
8
|
+
}
|
|
9
|
+
interface ResilientCookieStoreOptions {
|
|
10
|
+
readonly onError?: ((event: CookieStoreErrorEvent) => void) | undefined;
|
|
11
|
+
readonly timeoutMs?: number | undefined;
|
|
12
|
+
}
|
|
13
|
+
export declare function resilientCookieStore(store: CookieStore, options?: ResilientCookieStoreOptions): CookieStore;
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/cookie-stores/shared.d.ts
|
|
16
|
+
interface CookieStoreAdapterOptions extends ResilientCookieStoreOptions {
|
|
17
|
+
readonly prefix?: string | undefined;
|
|
18
|
+
readonly resilient?: boolean | undefined;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/cookie-stores/cloudflare-kv.d.ts
|
|
22
|
+
export declare const CLOUDFLARE_KV_MIN_TTL_SECONDS = 60;
|
|
23
|
+
interface CloudflareKvNamespaceLike {
|
|
24
|
+
get(key: string): Promise<string | null>;
|
|
25
|
+
put(key: string, value: string, options: {
|
|
26
|
+
expirationTtl: number;
|
|
27
|
+
}): Promise<void>;
|
|
28
|
+
delete(key: string): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
export declare function cloudflareKvCookieStore(namespace: CloudflareKvNamespaceLike, options?: CookieStoreAdapterOptions): CookieStore;
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/cookie-stores/custom.d.ts
|
|
33
|
+
export declare function customCookieStore(store: CookieStore, options?: CookieStoreAdapterOptions): CookieStore;
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/cookie-stores/ioredis.d.ts
|
|
36
|
+
interface IoRedisLike {
|
|
37
|
+
get(key: string): Promise<unknown>;
|
|
38
|
+
set(key: string, value: string, expiryMode: "EX", seconds: number): Promise<unknown>;
|
|
39
|
+
del(key: string): Promise<unknown>;
|
|
40
|
+
}
|
|
41
|
+
export declare function ioredisCookieStore(redis: IoRedisLike, options?: CookieStoreAdapterOptions): CookieStore;
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/cookie-stores/node-redis.d.ts
|
|
44
|
+
interface NodeRedisLike {
|
|
45
|
+
get(key: string): Promise<unknown>;
|
|
46
|
+
set(key: string, value: string, options: {
|
|
47
|
+
EX: number;
|
|
48
|
+
}): Promise<unknown>;
|
|
49
|
+
del(key: string): Promise<unknown>;
|
|
50
|
+
}
|
|
51
|
+
export declare function nodeRedisCookieStore(client: NodeRedisLike, options?: CookieStoreAdapterOptions): CookieStore;
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/cookie-stores/upstash.d.ts
|
|
54
|
+
interface UpstashRedisLike {
|
|
55
|
+
get(key: string): Promise<unknown>;
|
|
56
|
+
set(key: string, value: string, options: {
|
|
57
|
+
ex: number;
|
|
58
|
+
}): Promise<unknown>;
|
|
59
|
+
del(key: string): Promise<unknown>;
|
|
60
|
+
}
|
|
61
|
+
export declare function upstashRedisCookieStore(redis: UpstashRedisLike, options?: CookieStoreAdapterOptions): CookieStore;
|
|
62
|
+
//#endregion
|
|
63
|
+
export { type CloudflareKvNamespaceLike, type CookieStore, type CookieStoreAdapterOptions, type CookieStoreErrorEvent, type CookieStoreOperation, type IoRedisLike, type NodeRedisLike, type ResilientCookieStoreOptions, SESSION_TTL_SECONDS, type UpstashRedisLike, memoryCookieStore };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { n as SESSION_TTL_SECONDS, r as memoryCookieStore, t as CookieStore } from "../session-Dm_45x8K.js";
|
|
2
|
+
//#region src/cookie-stores/resilient.d.ts
|
|
3
|
+
type CookieStoreOperation = "get" | "set" | "delete";
|
|
4
|
+
interface CookieStoreErrorEvent {
|
|
5
|
+
readonly operation: CookieStoreOperation;
|
|
6
|
+
readonly key: string;
|
|
7
|
+
readonly error: unknown;
|
|
8
|
+
}
|
|
9
|
+
interface ResilientCookieStoreOptions {
|
|
10
|
+
readonly onError?: ((event: CookieStoreErrorEvent) => void) | undefined;
|
|
11
|
+
readonly timeoutMs?: number | undefined;
|
|
12
|
+
}
|
|
13
|
+
export declare function resilientCookieStore(store: CookieStore, options?: ResilientCookieStoreOptions): CookieStore;
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/cookie-stores/shared.d.ts
|
|
16
|
+
interface CookieStoreAdapterOptions extends ResilientCookieStoreOptions {
|
|
17
|
+
readonly prefix?: string | undefined;
|
|
18
|
+
readonly resilient?: boolean | undefined;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/cookie-stores/cloudflare-kv.d.ts
|
|
22
|
+
export declare const CLOUDFLARE_KV_MIN_TTL_SECONDS = 60;
|
|
23
|
+
interface CloudflareKvNamespaceLike {
|
|
24
|
+
get(key: string): Promise<string | null>;
|
|
25
|
+
put(key: string, value: string, options: {
|
|
26
|
+
expirationTtl: number;
|
|
27
|
+
}): Promise<void>;
|
|
28
|
+
delete(key: string): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
export declare function cloudflareKvCookieStore(namespace: CloudflareKvNamespaceLike, options?: CookieStoreAdapterOptions): CookieStore;
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/cookie-stores/custom.d.ts
|
|
33
|
+
export declare function customCookieStore(store: CookieStore, options?: CookieStoreAdapterOptions): CookieStore;
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/cookie-stores/ioredis.d.ts
|
|
36
|
+
interface IoRedisLike {
|
|
37
|
+
get(key: string): Promise<unknown>;
|
|
38
|
+
set(key: string, value: string, expiryMode: "EX", seconds: number): Promise<unknown>;
|
|
39
|
+
del(key: string): Promise<unknown>;
|
|
40
|
+
}
|
|
41
|
+
export declare function ioredisCookieStore(redis: IoRedisLike, options?: CookieStoreAdapterOptions): CookieStore;
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/cookie-stores/node-redis.d.ts
|
|
44
|
+
interface NodeRedisLike {
|
|
45
|
+
get(key: string): Promise<unknown>;
|
|
46
|
+
set(key: string, value: string, options: {
|
|
47
|
+
EX: number;
|
|
48
|
+
}): Promise<unknown>;
|
|
49
|
+
del(key: string): Promise<unknown>;
|
|
50
|
+
}
|
|
51
|
+
export declare function nodeRedisCookieStore(client: NodeRedisLike, options?: CookieStoreAdapterOptions): CookieStore;
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/cookie-stores/upstash.d.ts
|
|
54
|
+
interface UpstashRedisLike {
|
|
55
|
+
get(key: string): Promise<unknown>;
|
|
56
|
+
set(key: string, value: string, options: {
|
|
57
|
+
ex: number;
|
|
58
|
+
}): Promise<unknown>;
|
|
59
|
+
del(key: string): Promise<unknown>;
|
|
60
|
+
}
|
|
61
|
+
export declare function upstashRedisCookieStore(redis: UpstashRedisLike, options?: CookieStoreAdapterOptions): CookieStore;
|
|
62
|
+
//#endregion
|
|
63
|
+
export { type CloudflareKvNamespaceLike, type CookieStore, type CookieStoreAdapterOptions, type CookieStoreErrorEvent, type CookieStoreOperation, type IoRedisLike, type NodeRedisLike, type ResilientCookieStoreOptions, SESSION_TTL_SECONDS, type UpstashRedisLike, memoryCookieStore };
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { r as decodeUtf8 } from "../binary-D0M9U2MD.js";
|
|
2
|
+
import { n as memoryCookieStore, t as SESSION_TTL_SECONDS } from "../session-OJMLGufT.js";
|
|
3
|
+
//#region src/cookie-stores/resilient.ts
|
|
4
|
+
function warnCookieStoreError(event) {
|
|
5
|
+
console.warn(`[szamlazz] A session cookie store "${event.operation}" művelete sikertelen, a kérés session nélkül folytatódik.`, event.error);
|
|
6
|
+
}
|
|
7
|
+
function withTimeout(promise, timeoutMs, operation) {
|
|
8
|
+
if (timeoutMs === void 0) return promise;
|
|
9
|
+
let timer;
|
|
10
|
+
const timeout = new Promise((_, reject) => {
|
|
11
|
+
timer = setTimeout(() => {
|
|
12
|
+
reject(/* @__PURE__ */ new Error(`A session cookie store "${operation}" művelete nem fejeződött be ${timeoutMs} ms alatt.`));
|
|
13
|
+
}, timeoutMs);
|
|
14
|
+
});
|
|
15
|
+
return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
|
|
16
|
+
}
|
|
17
|
+
function resilientCookieStore(store, options = {}) {
|
|
18
|
+
const onError = options.onError ?? warnCookieStoreError;
|
|
19
|
+
if (options.timeoutMs !== void 0 && !(options.timeoutMs > 0)) throw new RangeError(`A timeoutMs pozitív szám legyen, kapott: ${options.timeoutMs}`);
|
|
20
|
+
function report(operation, key, error) {
|
|
21
|
+
try {
|
|
22
|
+
onError({
|
|
23
|
+
operation,
|
|
24
|
+
key,
|
|
25
|
+
error
|
|
26
|
+
});
|
|
27
|
+
} catch {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async function run(operation, key, call) {
|
|
32
|
+
try {
|
|
33
|
+
return await withTimeout(Promise.resolve().then(call), options.timeoutMs, operation);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
report(operation, key, error);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
async get(key) {
|
|
41
|
+
return await run("get", key, () => store.get(key)) ?? void 0;
|
|
42
|
+
},
|
|
43
|
+
async set(key, value, ttlSeconds) {
|
|
44
|
+
await run("set", key, () => store.set(key, value, ttlSeconds));
|
|
45
|
+
},
|
|
46
|
+
async delete(key) {
|
|
47
|
+
await run("delete", key, () => store.delete(key));
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/cookie-stores/shared.ts
|
|
53
|
+
function prefixKey(options, key) {
|
|
54
|
+
const prefix = options?.prefix;
|
|
55
|
+
return prefix ? `${prefix}${key}` : key;
|
|
56
|
+
}
|
|
57
|
+
function finalizeCookieStore(store, options) {
|
|
58
|
+
if (options?.resilient === false) return store;
|
|
59
|
+
return resilientCookieStore(store, {
|
|
60
|
+
onError: options?.onError,
|
|
61
|
+
timeoutMs: options?.timeoutMs
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function readCookieValue(value) {
|
|
65
|
+
if (typeof value === "string") return value === "" ? void 0 : value;
|
|
66
|
+
if (value instanceof Uint8Array) return readCookieValue(decodeUtf8(value));
|
|
67
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
68
|
+
}
|
|
69
|
+
function wholeSeconds(ttlSeconds, minimum) {
|
|
70
|
+
if (!Number.isFinite(ttlSeconds)) return minimum;
|
|
71
|
+
return Math.max(minimum, Math.ceil(ttlSeconds));
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/cookie-stores/cloudflare-kv.ts
|
|
75
|
+
const CLOUDFLARE_KV_MIN_TTL_SECONDS = 60;
|
|
76
|
+
function cloudflareKvCookieStore(namespace, options) {
|
|
77
|
+
return finalizeCookieStore({
|
|
78
|
+
async get(key) {
|
|
79
|
+
return readCookieValue(await namespace.get(prefixKey(options, key)));
|
|
80
|
+
},
|
|
81
|
+
async set(key, value, ttlSeconds) {
|
|
82
|
+
await namespace.put(prefixKey(options, key), value, { expirationTtl: wholeSeconds(ttlSeconds, 60) });
|
|
83
|
+
},
|
|
84
|
+
async delete(key) {
|
|
85
|
+
await namespace.delete(prefixKey(options, key));
|
|
86
|
+
}
|
|
87
|
+
}, options);
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/cookie-stores/custom.ts
|
|
91
|
+
function customCookieStore(store, options) {
|
|
92
|
+
return finalizeCookieStore({
|
|
93
|
+
get: (key) => store.get(prefixKey(options, key)),
|
|
94
|
+
set: (key, value, ttlSeconds) => store.set(prefixKey(options, key), value, ttlSeconds),
|
|
95
|
+
delete: (key) => store.delete(prefixKey(options, key))
|
|
96
|
+
}, options);
|
|
97
|
+
}
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/cookie-stores/ioredis.ts
|
|
100
|
+
function ioredisCookieStore(redis, options) {
|
|
101
|
+
return finalizeCookieStore({
|
|
102
|
+
async get(key) {
|
|
103
|
+
return readCookieValue(await redis.get(prefixKey(options, key)));
|
|
104
|
+
},
|
|
105
|
+
async set(key, value, ttlSeconds) {
|
|
106
|
+
await redis.set(prefixKey(options, key), value, "EX", wholeSeconds(ttlSeconds, 1));
|
|
107
|
+
},
|
|
108
|
+
async delete(key) {
|
|
109
|
+
await redis.del(prefixKey(options, key));
|
|
110
|
+
}
|
|
111
|
+
}, options);
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/cookie-stores/node-redis.ts
|
|
115
|
+
function nodeRedisCookieStore(client, options) {
|
|
116
|
+
return finalizeCookieStore({
|
|
117
|
+
async get(key) {
|
|
118
|
+
return readCookieValue(await client.get(prefixKey(options, key)));
|
|
119
|
+
},
|
|
120
|
+
async set(key, value, ttlSeconds) {
|
|
121
|
+
await client.set(prefixKey(options, key), value, { EX: wholeSeconds(ttlSeconds, 1) });
|
|
122
|
+
},
|
|
123
|
+
async delete(key) {
|
|
124
|
+
await client.del(prefixKey(options, key));
|
|
125
|
+
}
|
|
126
|
+
}, options);
|
|
127
|
+
}
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/cookie-stores/upstash.ts
|
|
130
|
+
function upstashRedisCookieStore(redis, options) {
|
|
131
|
+
return finalizeCookieStore({
|
|
132
|
+
async get(key) {
|
|
133
|
+
return readCookieValue(await redis.get(prefixKey(options, key)));
|
|
134
|
+
},
|
|
135
|
+
async set(key, value, ttlSeconds) {
|
|
136
|
+
await redis.set(prefixKey(options, key), value, { ex: wholeSeconds(ttlSeconds, 1) });
|
|
137
|
+
},
|
|
138
|
+
async delete(key) {
|
|
139
|
+
await redis.del(prefixKey(options, key));
|
|
140
|
+
}
|
|
141
|
+
}, options);
|
|
142
|
+
}
|
|
143
|
+
//#endregion
|
|
144
|
+
export { CLOUDFLARE_KV_MIN_TTL_SECONDS, SESSION_TTL_SECONDS, cloudflareKvCookieStore, customCookieStore, ioredisCookieStore, memoryCookieStore, nodeRedisCookieStore, resilientCookieStore, upstashRedisCookieStore };
|