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,335 @@
|
|
|
1
|
+
const require_errors = require("./errors-B0QJhUW1.cjs");
|
|
2
|
+
//#region src/money/rounding.ts
|
|
3
|
+
function roundMoney(value, decimals = 0) {
|
|
4
|
+
if (!Number.isFinite(value)) throw new RangeError(`Nem véges összeg: ${value}`);
|
|
5
|
+
const factor = 10 ** decimals;
|
|
6
|
+
const scaled = Number((Math.abs(value) * factor).toPrecision(15));
|
|
7
|
+
const rounded = Math.sign(value) * Math.round(scaled) / factor;
|
|
8
|
+
return rounded === 0 ? 0 : rounded;
|
|
9
|
+
}
|
|
10
|
+
function decimalPlaces(value) {
|
|
11
|
+
if (!Number.isFinite(value) || Number.isInteger(value)) return 0;
|
|
12
|
+
const normalized = Number(value.toPrecision(15)).toString();
|
|
13
|
+
const exponentMatch = /e-(\d+)$/.exec(normalized);
|
|
14
|
+
if (exponentMatch?.[1]) return Number(exponentMatch[1]);
|
|
15
|
+
return normalized.split(".")[1]?.length ?? 0;
|
|
16
|
+
}
|
|
17
|
+
function addMoney(...values) {
|
|
18
|
+
return roundMoney(values.reduce((sum, value) => sum + value, 0), Math.max(0, ...values.map(decimalPlaces)));
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/money/vat.ts
|
|
22
|
+
const NUMERIC_VAT_RATES = [
|
|
23
|
+
0,
|
|
24
|
+
1,
|
|
25
|
+
2,
|
|
26
|
+
2.1,
|
|
27
|
+
3,
|
|
28
|
+
4,
|
|
29
|
+
4.8,
|
|
30
|
+
5,
|
|
31
|
+
5.5,
|
|
32
|
+
6,
|
|
33
|
+
7,
|
|
34
|
+
7.7,
|
|
35
|
+
8,
|
|
36
|
+
8.1,
|
|
37
|
+
9,
|
|
38
|
+
9.5,
|
|
39
|
+
10,
|
|
40
|
+
11,
|
|
41
|
+
12,
|
|
42
|
+
13,
|
|
43
|
+
13.5,
|
|
44
|
+
14,
|
|
45
|
+
15,
|
|
46
|
+
16,
|
|
47
|
+
17,
|
|
48
|
+
18,
|
|
49
|
+
19,
|
|
50
|
+
20,
|
|
51
|
+
21,
|
|
52
|
+
22,
|
|
53
|
+
23,
|
|
54
|
+
24,
|
|
55
|
+
25,
|
|
56
|
+
25.5,
|
|
57
|
+
26,
|
|
58
|
+
27
|
|
59
|
+
];
|
|
60
|
+
const SPECIAL_VAT_CODES = [
|
|
61
|
+
"TAHK",
|
|
62
|
+
"TAM",
|
|
63
|
+
"AAM",
|
|
64
|
+
"EUT",
|
|
65
|
+
"EUKT",
|
|
66
|
+
"F.AFA",
|
|
67
|
+
"K.AFA",
|
|
68
|
+
"HO",
|
|
69
|
+
"EUE",
|
|
70
|
+
"EUFADE",
|
|
71
|
+
"EUFAD37",
|
|
72
|
+
"ATK",
|
|
73
|
+
"NAM",
|
|
74
|
+
"EAM",
|
|
75
|
+
"KBAUK",
|
|
76
|
+
"KBAET"
|
|
77
|
+
];
|
|
78
|
+
const numericRates = new Set(NUMERIC_VAT_RATES);
|
|
79
|
+
const specialCodes = new Set(SPECIAL_VAT_CODES);
|
|
80
|
+
function isVatRate(value) {
|
|
81
|
+
if (typeof value === "number") return numericRates.has(value);
|
|
82
|
+
return typeof value === "string" && specialCodes.has(value);
|
|
83
|
+
}
|
|
84
|
+
function vatPercentage(rate) {
|
|
85
|
+
return typeof rate === "number" ? rate : 0;
|
|
86
|
+
}
|
|
87
|
+
function formatVatRate(rate) {
|
|
88
|
+
return String(rate);
|
|
89
|
+
}
|
|
90
|
+
const HUF_CURRENCIES = /* @__PURE__ */ new Set([
|
|
91
|
+
"HUF",
|
|
92
|
+
"Ft",
|
|
93
|
+
"FT",
|
|
94
|
+
"huf",
|
|
95
|
+
"ft"
|
|
96
|
+
]);
|
|
97
|
+
function isHuf(currency) {
|
|
98
|
+
return currency === void 0 || HUF_CURRENCIES.has(currency.trim());
|
|
99
|
+
}
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/money/items.ts
|
|
102
|
+
const FOREIGN_CURRENCY_DECIMALS = 2;
|
|
103
|
+
const RECEIPT_HUF_DECIMALS = 2;
|
|
104
|
+
const MAX_UNIT_PRICE_DECIMALS = 6;
|
|
105
|
+
function validationError(message) {
|
|
106
|
+
return new require_errors.SzamlazzError(message, { category: "validation" });
|
|
107
|
+
}
|
|
108
|
+
function assertFiniteNumber(value, field) {
|
|
109
|
+
if (value !== void 0 && !Number.isFinite(value)) throw validationError(`A(z) ${field} mező értéke nem érvényes szám: ${value}`);
|
|
110
|
+
}
|
|
111
|
+
function unitPriceFor(amount, quantity, decimals) {
|
|
112
|
+
const exact = amount / quantity;
|
|
113
|
+
for (let precision = 2; precision <= MAX_UNIT_PRICE_DECIMALS; precision++) {
|
|
114
|
+
const candidate = roundMoney(exact, precision);
|
|
115
|
+
if (roundMoney(candidate * quantity, decimals) === amount) return candidate;
|
|
116
|
+
}
|
|
117
|
+
return roundMoney(exact, MAX_UNIT_PRICE_DECIMALS);
|
|
118
|
+
}
|
|
119
|
+
function roundingRuleFor(kind, currency) {
|
|
120
|
+
if (!isHuf(currency)) return {
|
|
121
|
+
netDecimals: FOREIGN_CURRENCY_DECIMALS,
|
|
122
|
+
vatDecimals: FOREIGN_CURRENCY_DECIMALS,
|
|
123
|
+
grossDecimals: FOREIGN_CURRENCY_DECIMALS
|
|
124
|
+
};
|
|
125
|
+
if (kind === "receipt") return {
|
|
126
|
+
netDecimals: RECEIPT_HUF_DECIMALS,
|
|
127
|
+
vatDecimals: RECEIPT_HUF_DECIMALS,
|
|
128
|
+
grossDecimals: 0
|
|
129
|
+
};
|
|
130
|
+
return {
|
|
131
|
+
netDecimals: 0,
|
|
132
|
+
vatDecimals: 0,
|
|
133
|
+
grossDecimals: 0
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function fromNet(input, quantity, rule) {
|
|
137
|
+
const percentage = vatPercentage(input.vat);
|
|
138
|
+
const netAmount = roundMoney(input.netUnitPrice * quantity, rule.netDecimals);
|
|
139
|
+
if (rule.grossDecimals < rule.netDecimals) {
|
|
140
|
+
const grossAmount = roundMoney(netAmount * (1 + percentage / 100), rule.grossDecimals);
|
|
141
|
+
const vatAmount = roundMoney(grossAmount - netAmount, rule.vatDecimals);
|
|
142
|
+
return {
|
|
143
|
+
quantity,
|
|
144
|
+
vat: input.vat,
|
|
145
|
+
netUnitPrice: input.netUnitPrice,
|
|
146
|
+
netAmount,
|
|
147
|
+
vatAmount,
|
|
148
|
+
grossAmount
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
const vatAmount = roundMoney(netAmount * percentage / 100, rule.vatDecimals);
|
|
152
|
+
const grossAmount = roundMoney(netAmount + vatAmount, rule.grossDecimals);
|
|
153
|
+
return {
|
|
154
|
+
quantity,
|
|
155
|
+
vat: input.vat,
|
|
156
|
+
netUnitPrice: input.netUnitPrice,
|
|
157
|
+
netAmount,
|
|
158
|
+
vatAmount,
|
|
159
|
+
grossAmount
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function fromGross(input, quantity, rule) {
|
|
163
|
+
const percentage = vatPercentage(input.vat);
|
|
164
|
+
const grossAmount = roundMoney(input.grossUnitPrice * quantity, rule.grossDecimals);
|
|
165
|
+
const vatAmount = roundMoney(grossAmount * percentage / (100 + percentage), rule.vatDecimals);
|
|
166
|
+
const netAmount = roundMoney(grossAmount - vatAmount, rule.netDecimals);
|
|
167
|
+
return {
|
|
168
|
+
quantity,
|
|
169
|
+
vat: input.vat,
|
|
170
|
+
netUnitPrice: unitPriceFor(netAmount, quantity, rule.netDecimals),
|
|
171
|
+
netAmount,
|
|
172
|
+
vatAmount,
|
|
173
|
+
grossAmount
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function fromExplicit(input, quantity) {
|
|
177
|
+
const { netAmount, vatAmount, grossAmount } = input;
|
|
178
|
+
if (netAmount === void 0 || vatAmount === void 0 || grossAmount === void 0) throw validationError("Explicit összegeknél a netAmount, vatAmount és grossAmount mezőt is meg kell adni.");
|
|
179
|
+
return {
|
|
180
|
+
quantity,
|
|
181
|
+
vat: input.vat,
|
|
182
|
+
netUnitPrice: input.netUnitPrice ?? unitPriceFor(netAmount, quantity, FOREIGN_CURRENCY_DECIMALS),
|
|
183
|
+
netAmount,
|
|
184
|
+
vatAmount,
|
|
185
|
+
grossAmount
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function calculateItemAmounts(input, options) {
|
|
189
|
+
const quantity = input.quantity ?? 1;
|
|
190
|
+
assertFiniteNumber(quantity, "quantity");
|
|
191
|
+
assertFiniteNumber(input.netUnitPrice, "netUnitPrice");
|
|
192
|
+
assertFiniteNumber(input.grossUnitPrice, "grossUnitPrice");
|
|
193
|
+
assertFiniteNumber(input.netAmount, "netAmount");
|
|
194
|
+
assertFiniteNumber(input.vatAmount, "vatAmount");
|
|
195
|
+
assertFiniteNumber(input.grossAmount, "grossAmount");
|
|
196
|
+
if (quantity === 0) throw validationError("A tétel mennyisége nem lehet 0.");
|
|
197
|
+
if (!isVatRate(input.vat)) throw validationError(`Ismeretlen áfakulcs: ${String(input.vat)}`);
|
|
198
|
+
if (input.netAmount !== void 0 || input.vatAmount !== void 0 || input.grossAmount !== void 0) return fromExplicit(input, quantity);
|
|
199
|
+
if (input.netUnitPrice !== void 0 && input.grossUnitPrice !== void 0) throw validationError("A netUnitPrice és a grossUnitPrice közül csak az egyiket add meg.");
|
|
200
|
+
const rule = roundingRuleFor(options.kind, options.currency);
|
|
201
|
+
if (input.netUnitPrice !== void 0) return fromNet({
|
|
202
|
+
...input,
|
|
203
|
+
netUnitPrice: input.netUnitPrice
|
|
204
|
+
}, quantity, rule);
|
|
205
|
+
if (input.grossUnitPrice !== void 0) return fromGross({
|
|
206
|
+
...input,
|
|
207
|
+
grossUnitPrice: input.grossUnitPrice
|
|
208
|
+
}, quantity, rule);
|
|
209
|
+
throw validationError("A tételnél add meg a netUnitPrice vagy a grossUnitPrice mezőt.");
|
|
210
|
+
}
|
|
211
|
+
function calculateInvoiceItem(input, currency) {
|
|
212
|
+
return calculateItemAmounts(input, {
|
|
213
|
+
kind: "invoice",
|
|
214
|
+
currency
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
function calculateReceiptItem(input, currency) {
|
|
218
|
+
return calculateItemAmounts(input, {
|
|
219
|
+
kind: "receipt",
|
|
220
|
+
currency
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
function summarizeItems(items) {
|
|
224
|
+
const byVat = /* @__PURE__ */ new Map();
|
|
225
|
+
let netAmount = 0;
|
|
226
|
+
let vatAmount = 0;
|
|
227
|
+
let grossAmount = 0;
|
|
228
|
+
for (const item of items) {
|
|
229
|
+
netAmount += item.netAmount;
|
|
230
|
+
vatAmount += item.vatAmount;
|
|
231
|
+
grossAmount += item.grossAmount;
|
|
232
|
+
const key = String(item.vat);
|
|
233
|
+
const bucket = byVat.get(key) ?? {
|
|
234
|
+
vat: item.vat,
|
|
235
|
+
netAmount: 0,
|
|
236
|
+
vatAmount: 0,
|
|
237
|
+
grossAmount: 0
|
|
238
|
+
};
|
|
239
|
+
bucket.netAmount += item.netAmount;
|
|
240
|
+
bucket.vatAmount += item.vatAmount;
|
|
241
|
+
bucket.grossAmount += item.grossAmount;
|
|
242
|
+
byVat.set(key, bucket);
|
|
243
|
+
}
|
|
244
|
+
const round = (value) => roundMoney(value, 6);
|
|
245
|
+
return {
|
|
246
|
+
netAmount: round(netAmount),
|
|
247
|
+
vatAmount: round(vatAmount),
|
|
248
|
+
grossAmount: round(grossAmount),
|
|
249
|
+
byVat: [...byVat.values()].map((bucket) => ({
|
|
250
|
+
vat: bucket.vat,
|
|
251
|
+
netAmount: round(bucket.netAmount),
|
|
252
|
+
vatAmount: round(bucket.vatAmount),
|
|
253
|
+
grossAmount: round(bucket.grossAmount)
|
|
254
|
+
}))
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
//#endregion
|
|
258
|
+
Object.defineProperty(exports, "NUMERIC_VAT_RATES", {
|
|
259
|
+
enumerable: true,
|
|
260
|
+
get: function() {
|
|
261
|
+
return NUMERIC_VAT_RATES;
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
Object.defineProperty(exports, "SPECIAL_VAT_CODES", {
|
|
265
|
+
enumerable: true,
|
|
266
|
+
get: function() {
|
|
267
|
+
return SPECIAL_VAT_CODES;
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
Object.defineProperty(exports, "addMoney", {
|
|
271
|
+
enumerable: true,
|
|
272
|
+
get: function() {
|
|
273
|
+
return addMoney;
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
Object.defineProperty(exports, "calculateInvoiceItem", {
|
|
277
|
+
enumerable: true,
|
|
278
|
+
get: function() {
|
|
279
|
+
return calculateInvoiceItem;
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
Object.defineProperty(exports, "calculateItemAmounts", {
|
|
283
|
+
enumerable: true,
|
|
284
|
+
get: function() {
|
|
285
|
+
return calculateItemAmounts;
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
Object.defineProperty(exports, "calculateReceiptItem", {
|
|
289
|
+
enumerable: true,
|
|
290
|
+
get: function() {
|
|
291
|
+
return calculateReceiptItem;
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
Object.defineProperty(exports, "decimalPlaces", {
|
|
295
|
+
enumerable: true,
|
|
296
|
+
get: function() {
|
|
297
|
+
return decimalPlaces;
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
Object.defineProperty(exports, "formatVatRate", {
|
|
301
|
+
enumerable: true,
|
|
302
|
+
get: function() {
|
|
303
|
+
return formatVatRate;
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
Object.defineProperty(exports, "isHuf", {
|
|
307
|
+
enumerable: true,
|
|
308
|
+
get: function() {
|
|
309
|
+
return isHuf;
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
Object.defineProperty(exports, "isVatRate", {
|
|
313
|
+
enumerable: true,
|
|
314
|
+
get: function() {
|
|
315
|
+
return isVatRate;
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
Object.defineProperty(exports, "roundMoney", {
|
|
319
|
+
enumerable: true,
|
|
320
|
+
get: function() {
|
|
321
|
+
return roundMoney;
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
Object.defineProperty(exports, "summarizeItems", {
|
|
325
|
+
enumerable: true,
|
|
326
|
+
get: function() {
|
|
327
|
+
return summarizeItems;
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
Object.defineProperty(exports, "vatPercentage", {
|
|
331
|
+
enumerable: true,
|
|
332
|
+
get: function() {
|
|
333
|
+
return vatPercentage;
|
|
334
|
+
}
|
|
335
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
//#region src/core/session.ts
|
|
2
|
+
const SESSION_TTL_SECONDS = 5100;
|
|
3
|
+
function memoryCookieStore() {
|
|
4
|
+
const entries = /* @__PURE__ */ new Map();
|
|
5
|
+
return {
|
|
6
|
+
get(key) {
|
|
7
|
+
const entry = entries.get(key);
|
|
8
|
+
if (!entry) return void 0;
|
|
9
|
+
if (entry.expiresAt <= Date.now()) {
|
|
10
|
+
entries.delete(key);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
return entry.value;
|
|
14
|
+
},
|
|
15
|
+
set(key, value, ttlSeconds) {
|
|
16
|
+
entries.set(key, {
|
|
17
|
+
value,
|
|
18
|
+
expiresAt: Date.now() + ttlSeconds * 1e3
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
delete(key) {
|
|
22
|
+
entries.delete(key);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function cyrb53(value, seed) {
|
|
27
|
+
let h1 = 3735928559 ^ seed;
|
|
28
|
+
let h2 = 1103547991 ^ seed;
|
|
29
|
+
for (let index = 0; index < value.length; index++) {
|
|
30
|
+
const code = value.charCodeAt(index);
|
|
31
|
+
h1 = Math.imul(h1 ^ code, 2654435761);
|
|
32
|
+
h2 = Math.imul(h2 ^ code, 1597334677);
|
|
33
|
+
}
|
|
34
|
+
h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
|
|
35
|
+
h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
|
|
36
|
+
return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString(16).padStart(14, "0");
|
|
37
|
+
}
|
|
38
|
+
function sessionKeyFor(secret) {
|
|
39
|
+
return `szamlazz:session:${cyrb53(secret, 1)}${cyrb53(secret, 2)}`;
|
|
40
|
+
}
|
|
41
|
+
function readSetCookieHeaders(headers) {
|
|
42
|
+
const withGetter = headers;
|
|
43
|
+
if (typeof withGetter.getSetCookie === "function") return withGetter.getSetCookie();
|
|
44
|
+
const combined = headers.get("set-cookie");
|
|
45
|
+
return combined ? combined.split(/,(?=\s*[^;,=\s]+=)/) : [];
|
|
46
|
+
}
|
|
47
|
+
function parseCookiePairs(cookieHeader) {
|
|
48
|
+
const pairs = /* @__PURE__ */ new Map();
|
|
49
|
+
if (!cookieHeader) return pairs;
|
|
50
|
+
for (const part of cookieHeader.split(";")) {
|
|
51
|
+
const separator = part.indexOf("=");
|
|
52
|
+
if (separator <= 0) continue;
|
|
53
|
+
pairs.set(part.slice(0, separator).trim(), part.slice(separator + 1).trim());
|
|
54
|
+
}
|
|
55
|
+
return pairs;
|
|
56
|
+
}
|
|
57
|
+
function mergeSetCookies(existing, headers) {
|
|
58
|
+
const setCookies = readSetCookieHeaders(headers);
|
|
59
|
+
if (setCookies.length === 0) return void 0;
|
|
60
|
+
const pairs = parseCookiePairs(existing);
|
|
61
|
+
let changed = false;
|
|
62
|
+
for (const setCookie of setCookies) {
|
|
63
|
+
const [pair] = setCookie.split(";");
|
|
64
|
+
if (!pair) continue;
|
|
65
|
+
const separator = pair.indexOf("=");
|
|
66
|
+
if (separator <= 0) continue;
|
|
67
|
+
const name = pair.slice(0, separator).trim();
|
|
68
|
+
const value = pair.slice(separator + 1).trim();
|
|
69
|
+
if (pairs.get(name) === value) continue;
|
|
70
|
+
pairs.set(name, value);
|
|
71
|
+
changed = true;
|
|
72
|
+
}
|
|
73
|
+
if (!changed) return void 0;
|
|
74
|
+
return [...pairs].map(([name, value]) => `${name}=${value}`).join("; ");
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
Object.defineProperty(exports, "SESSION_TTL_SECONDS", {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
get: function() {
|
|
80
|
+
return SESSION_TTL_SECONDS;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
Object.defineProperty(exports, "memoryCookieStore", {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
get: function() {
|
|
86
|
+
return memoryCookieStore;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
Object.defineProperty(exports, "mergeSetCookies", {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
get: function() {
|
|
92
|
+
return mergeSetCookies;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
Object.defineProperty(exports, "sessionKeyFor", {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
get: function() {
|
|
98
|
+
return sessionKeyFor;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/core/session.d.ts
|
|
2
|
+
type Awaitable<T> = T | Promise<T>;
|
|
3
|
+
interface CookieStore {
|
|
4
|
+
get(key: string): Awaitable<string | undefined | null>;
|
|
5
|
+
set(key: string, value: string, ttlSeconds: number): Awaitable<void>;
|
|
6
|
+
delete(key: string): Awaitable<void>;
|
|
7
|
+
}
|
|
8
|
+
declare const SESSION_TTL_SECONDS: number;
|
|
9
|
+
declare function memoryCookieStore(): CookieStore;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { SESSION_TTL_SECONDS as n, memoryCookieStore as r, CookieStore as t };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/core/session.d.ts
|
|
2
|
+
type Awaitable<T> = T | Promise<T>;
|
|
3
|
+
interface CookieStore {
|
|
4
|
+
get(key: string): Awaitable<string | undefined | null>;
|
|
5
|
+
set(key: string, value: string, ttlSeconds: number): Awaitable<void>;
|
|
6
|
+
delete(key: string): Awaitable<void>;
|
|
7
|
+
}
|
|
8
|
+
declare const SESSION_TTL_SECONDS: number;
|
|
9
|
+
declare function memoryCookieStore(): CookieStore;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { SESSION_TTL_SECONDS as n, memoryCookieStore as r, CookieStore as t };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
//#region src/core/session.ts
|
|
2
|
+
const SESSION_TTL_SECONDS = 5100;
|
|
3
|
+
function memoryCookieStore() {
|
|
4
|
+
const entries = /* @__PURE__ */ new Map();
|
|
5
|
+
return {
|
|
6
|
+
get(key) {
|
|
7
|
+
const entry = entries.get(key);
|
|
8
|
+
if (!entry) return void 0;
|
|
9
|
+
if (entry.expiresAt <= Date.now()) {
|
|
10
|
+
entries.delete(key);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
return entry.value;
|
|
14
|
+
},
|
|
15
|
+
set(key, value, ttlSeconds) {
|
|
16
|
+
entries.set(key, {
|
|
17
|
+
value,
|
|
18
|
+
expiresAt: Date.now() + ttlSeconds * 1e3
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
delete(key) {
|
|
22
|
+
entries.delete(key);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function cyrb53(value, seed) {
|
|
27
|
+
let h1 = 3735928559 ^ seed;
|
|
28
|
+
let h2 = 1103547991 ^ seed;
|
|
29
|
+
for (let index = 0; index < value.length; index++) {
|
|
30
|
+
const code = value.charCodeAt(index);
|
|
31
|
+
h1 = Math.imul(h1 ^ code, 2654435761);
|
|
32
|
+
h2 = Math.imul(h2 ^ code, 1597334677);
|
|
33
|
+
}
|
|
34
|
+
h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
|
|
35
|
+
h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
|
|
36
|
+
return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString(16).padStart(14, "0");
|
|
37
|
+
}
|
|
38
|
+
function sessionKeyFor(secret) {
|
|
39
|
+
return `szamlazz:session:${cyrb53(secret, 1)}${cyrb53(secret, 2)}`;
|
|
40
|
+
}
|
|
41
|
+
function readSetCookieHeaders(headers) {
|
|
42
|
+
const withGetter = headers;
|
|
43
|
+
if (typeof withGetter.getSetCookie === "function") return withGetter.getSetCookie();
|
|
44
|
+
const combined = headers.get("set-cookie");
|
|
45
|
+
return combined ? combined.split(/,(?=\s*[^;,=\s]+=)/) : [];
|
|
46
|
+
}
|
|
47
|
+
function parseCookiePairs(cookieHeader) {
|
|
48
|
+
const pairs = /* @__PURE__ */ new Map();
|
|
49
|
+
if (!cookieHeader) return pairs;
|
|
50
|
+
for (const part of cookieHeader.split(";")) {
|
|
51
|
+
const separator = part.indexOf("=");
|
|
52
|
+
if (separator <= 0) continue;
|
|
53
|
+
pairs.set(part.slice(0, separator).trim(), part.slice(separator + 1).trim());
|
|
54
|
+
}
|
|
55
|
+
return pairs;
|
|
56
|
+
}
|
|
57
|
+
function mergeSetCookies(existing, headers) {
|
|
58
|
+
const setCookies = readSetCookieHeaders(headers);
|
|
59
|
+
if (setCookies.length === 0) return void 0;
|
|
60
|
+
const pairs = parseCookiePairs(existing);
|
|
61
|
+
let changed = false;
|
|
62
|
+
for (const setCookie of setCookies) {
|
|
63
|
+
const [pair] = setCookie.split(";");
|
|
64
|
+
if (!pair) continue;
|
|
65
|
+
const separator = pair.indexOf("=");
|
|
66
|
+
if (separator <= 0) continue;
|
|
67
|
+
const name = pair.slice(0, separator).trim();
|
|
68
|
+
const value = pair.slice(separator + 1).trim();
|
|
69
|
+
if (pairs.get(name) === value) continue;
|
|
70
|
+
pairs.set(name, value);
|
|
71
|
+
changed = true;
|
|
72
|
+
}
|
|
73
|
+
if (!changed) return void 0;
|
|
74
|
+
return [...pairs].map(([name, value]) => `${name}=${value}`).join("; ");
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
export { sessionKeyFor as i, memoryCookieStore as n, mergeSetCookies as r, SESSION_TTL_SECONDS as t };
|