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.
Files changed (67) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +150 -0
  3. package/agents/README.md +59 -0
  4. package/agents/api.md +206 -0
  5. package/agents/pitfalls.md +52 -0
  6. package/agents/recipes.md +217 -0
  7. package/agents/skills/kassza/SKILL.md +29 -0
  8. package/assets/logo-wordmark.svg +25 -0
  9. package/assets/logo.svg +19 -0
  10. package/dist/binary-B89HM03_.cjs +63 -0
  11. package/dist/binary-D0M9U2MD.js +34 -0
  12. package/dist/client-B9kbKKBf.d.cts +748 -0
  13. package/dist/client-zv4enyq7.d.ts +748 -0
  14. package/dist/cookie-stores/index.cjs +153 -0
  15. package/dist/cookie-stores/index.d.cts +63 -0
  16. package/dist/cookie-stores/index.d.ts +63 -0
  17. package/dist/cookie-stores/index.js +144 -0
  18. package/dist/create-BZd6CUO7.cjs +1160 -0
  19. package/dist/create-DDZaNlOz.js +939 -0
  20. package/dist/dates-D2XebOIg.js +34 -0
  21. package/dist/dates-DtHzwNU6.d.cts +7 -0
  22. package/dist/dates-DtHzwNU6.d.ts +7 -0
  23. package/dist/dates-PPxH0n5H.cjs +57 -0
  24. package/dist/errors-B0QJhUW1.cjs +302 -0
  25. package/dist/errors-DapdV5DK.js +273 -0
  26. package/dist/index-CYAGCdKJ.d.cts +56 -0
  27. package/dist/index-CYAGCdKJ.d.ts +56 -0
  28. package/dist/index.cjs +1406 -0
  29. package/dist/index.d.cts +8 -0
  30. package/dist/index.d.ts +8 -0
  31. package/dist/index.js +1394 -0
  32. package/dist/ipn/index.cjs +108 -0
  33. package/dist/ipn/index.d.cts +32 -0
  34. package/dist/ipn/index.d.ts +32 -0
  35. package/dist/ipn/index.js +101 -0
  36. package/dist/money/index.cjs +15 -0
  37. package/dist/money/index.d.cts +2 -0
  38. package/dist/money/index.d.ts +2 -0
  39. package/dist/money/index.js +2 -0
  40. package/dist/money-C9j7nBNP.js +258 -0
  41. package/dist/money-DkiGukAw.cjs +335 -0
  42. package/dist/session-CRGOuz-R.cjs +100 -0
  43. package/dist/session-Dm_45x8K.d.cts +11 -0
  44. package/dist/session-Dm_45x8K.d.ts +11 -0
  45. package/dist/session-OJMLGufT.js +77 -0
  46. package/dist/shared-CrxlxI8n.cjs +207 -0
  47. package/dist/shared-D6DLa4b7.js +100 -0
  48. package/dist/storage/fs.cjs +88 -0
  49. package/dist/storage/fs.d.cts +13 -0
  50. package/dist/storage/fs.d.ts +13 -0
  51. package/dist/storage/fs.js +87 -0
  52. package/dist/storage/index.cjs +643 -0
  53. package/dist/storage/index.d.cts +288 -0
  54. package/dist/storage/index.d.ts +288 -0
  55. package/dist/storage/index.js +619 -0
  56. package/dist/testing/index.cjs +409 -0
  57. package/dist/testing/index.d.cts +35 -0
  58. package/dist/testing/index.d.ts +35 -0
  59. package/dist/testing/index.js +407 -0
  60. package/dist/types-DVRgwcqg.d.cts +26 -0
  61. package/dist/types-DVRgwcqg.d.ts +26 -0
  62. package/dist/validators/index.cjs +296 -0
  63. package/dist/validators/index.d.cts +51 -0
  64. package/dist/validators/index.d.ts +51 -0
  65. package/dist/validators/index.js +278 -0
  66. package/llms.txt +16 -0
  67. package/package.json +151 -0
@@ -0,0 +1,643 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_errors = require("../errors-B0QJhUW1.cjs");
3
+ const require_binary = require("../binary-B89HM03_.cjs");
4
+ const require_dates = require("../dates-PPxH0n5H.cjs");
5
+ const require_shared = require("../shared-CrxlxI8n.cjs");
6
+ //#region src/storage/keys.ts
7
+ const DEFAULT_INVOICE_KEY_PREFIX = "szamlak";
8
+ const DEFAULT_RECEIPT_KEY_PREFIX = "nyugtak";
9
+ const KIND_FOLDERS = {
10
+ invoice: void 0,
11
+ proforma: "dijbekero",
12
+ advance: "elolegszamla",
13
+ final: "vegszamla",
14
+ corrective: "helyesbito",
15
+ storno: "sztorno",
16
+ deliveryNote: "szallitolevel"
17
+ };
18
+ const COMBINING_MARKS = /\p{M}/gu;
19
+ function sanitizeKeySegment(value) {
20
+ return value.normalize("NFKD").replace(COMBINING_MARKS, "").replace(/[^A-Za-z0-9._-]+/g, "-").replace(/-{2,}/g, "-").replace(/^[-.]+|[-.]+$/g, "");
21
+ }
22
+ function datedPdfKey(prefix, folder, number, date) {
23
+ const fileName = sanitizeKeySegment(number);
24
+ if (fileName === "") throw new require_shared.StorageError(`A bizonylatszámból nem képezhető fájlnév: ${JSON.stringify(number)}`, { operation: "key" });
25
+ const [year = "", month = ""] = (date === void 0 ? require_dates.todayInBudapest() : require_dates.toAgentDate(date)).split("-");
26
+ return [
27
+ ...prefix.split("/"),
28
+ folder ?? "",
29
+ year,
30
+ month
31
+ ].map(sanitizeKeySegment).filter((segment) => segment !== "").concat(`${fileName}.pdf`).join("/");
32
+ }
33
+ function invoicePdfKey(input) {
34
+ return datedPdfKey(input.prefix ?? "szamlak", KIND_FOLDERS[input.type ?? "invoice"], input.number, input.date);
35
+ }
36
+ function receiptPdfKey(input) {
37
+ return datedPdfKey(input.prefix ?? "nyugtak", void 0, input.number, input.date);
38
+ }
39
+ //#endregion
40
+ //#region src/storage/memory.ts
41
+ const MEMORY_BASE_URL = "memory://storage";
42
+ function memoryStorage(options = {}) {
43
+ const prefix = require_shared.normalizePrefix(options.prefix);
44
+ const files = /* @__PURE__ */ new Map();
45
+ const urlFor = (fullKey) => require_shared.joinPublicUrl(options.publicBaseUrl ?? MEMORY_BASE_URL, fullKey);
46
+ return {
47
+ files,
48
+ async put(key, body, putOptions) {
49
+ const fullKey = require_shared.resolveKey(prefix, key);
50
+ files.set(fullKey, {
51
+ body: body.slice(),
52
+ contentType: putOptions.contentType
53
+ });
54
+ return {
55
+ key,
56
+ url: urlFor(fullKey),
57
+ size: body.byteLength,
58
+ contentType: putOptions.contentType
59
+ };
60
+ },
61
+ async get(key) {
62
+ return files.get(require_shared.resolveKey(prefix, key))?.body.slice();
63
+ },
64
+ async delete(key) {
65
+ files.delete(require_shared.resolveKey(prefix, key));
66
+ },
67
+ async getUrl(key) {
68
+ const fullKey = require_shared.resolveKey(prefix, key);
69
+ if (!files.has(fullKey)) throw new require_shared.StorageError(`Nincs ilyen fájl: ${key}`, {
70
+ operation: "getUrl",
71
+ key,
72
+ status: 404
73
+ });
74
+ return urlFor(fullKey);
75
+ },
76
+ clear() {
77
+ files.clear();
78
+ }
79
+ };
80
+ }
81
+ //#endregion
82
+ //#region src/storage/r2-binding.ts
83
+ function r2BindingStorage(bucket, options = {}) {
84
+ const prefix = require_shared.normalizePrefix(options.prefix);
85
+ return {
86
+ async put(key, body, putOptions) {
87
+ const fullKey = require_shared.resolveKey(prefix, key);
88
+ const object = await require_shared.guardStorageCall("R2", "put", key, () => bucket.put(fullKey, body, { httpMetadata: { contentType: putOptions.contentType } }));
89
+ if (!object) throw new require_shared.StorageError("Az R2 nem mentette el a fájlt (a put null-t adott vissza).", {
90
+ operation: "put",
91
+ key
92
+ });
93
+ return {
94
+ key,
95
+ url: options.publicBaseUrl ? require_shared.joinPublicUrl(options.publicBaseUrl, fullKey) : void 0,
96
+ size: object.size,
97
+ contentType: putOptions.contentType
98
+ };
99
+ },
100
+ async get(key) {
101
+ const fullKey = require_shared.resolveKey(prefix, key);
102
+ const object = await require_shared.guardStorageCall("R2", "get", key, () => bucket.get(fullKey));
103
+ if (!object) return void 0;
104
+ return new Uint8Array(await require_shared.guardStorageCall("R2", "get", key, () => object.arrayBuffer()));
105
+ },
106
+ async delete(key) {
107
+ const fullKey = require_shared.resolveKey(prefix, key);
108
+ await require_shared.guardStorageCall("R2", "delete", key, () => bucket.delete(fullKey));
109
+ },
110
+ async getUrl(key, urlOptions = {}) {
111
+ const fullKey = require_shared.resolveKey(prefix, key);
112
+ if (urlOptions.expiresInSeconds !== void 0) throw require_shared.unsupportedSignedUrl("r2BindingStorage", key);
113
+ if (!options.publicBaseUrl) throw require_shared.missingPublicBaseUrl("r2BindingStorage", key);
114
+ return require_shared.joinPublicUrl(options.publicBaseUrl, fullKey);
115
+ }
116
+ };
117
+ }
118
+ //#endregion
119
+ //#region src/storage/s3.ts
120
+ function statusOf(error) {
121
+ const status = error?.$metadata?.httpStatusCode;
122
+ return typeof status === "number" ? status : void 0;
123
+ }
124
+ function isNotFound$1(error) {
125
+ const name = error?.name;
126
+ return name === "NoSuchKey" || name === "NotFound" || statusOf(error) === 404;
127
+ }
128
+ function wrap(operation, key, error) {
129
+ return new require_shared.StorageError(`S3 hiba (${operation}): ${require_shared.describeError(error)}`, {
130
+ operation,
131
+ key,
132
+ status: statusOf(error),
133
+ cause: error
134
+ });
135
+ }
136
+ function missingCommand(name, key, operation) {
137
+ return new require_shared.StorageError(`Ehhez a művelethez add meg a commands.${name} osztályt.`, {
138
+ operation,
139
+ key
140
+ });
141
+ }
142
+ async function readBody(output) {
143
+ const body = output?.Body;
144
+ if (!body || typeof body.transformToByteArray !== "function") throw new Error("A GetObject válasza nem tartalmaz olvasható Body-t.");
145
+ return await body.transformToByteArray();
146
+ }
147
+ function s3Storage(options) {
148
+ const prefix = require_shared.normalizePrefix(options.prefix);
149
+ const { client, bucket, commands } = options;
150
+ return {
151
+ async put(key, body, putOptions) {
152
+ const fullKey = require_shared.resolveKey(prefix, key);
153
+ try {
154
+ await client.send(new commands.PutObjectCommand({
155
+ Bucket: bucket,
156
+ Key: fullKey,
157
+ Body: body,
158
+ ContentType: putOptions.contentType,
159
+ ContentLength: body.byteLength
160
+ }));
161
+ } catch (error) {
162
+ throw wrap("put", key, error);
163
+ }
164
+ return {
165
+ key,
166
+ url: options.publicBaseUrl ? require_shared.joinPublicUrl(options.publicBaseUrl, fullKey) : void 0,
167
+ size: body.byteLength,
168
+ contentType: putOptions.contentType
169
+ };
170
+ },
171
+ async get(key) {
172
+ const fullKey = require_shared.resolveKey(prefix, key);
173
+ if (!commands.GetObjectCommand) throw missingCommand("GetObjectCommand", key, "get");
174
+ try {
175
+ return await readBody(await client.send(new commands.GetObjectCommand({
176
+ Bucket: bucket,
177
+ Key: fullKey
178
+ })));
179
+ } catch (error) {
180
+ if (isNotFound$1(error)) return void 0;
181
+ throw wrap("get", key, error);
182
+ }
183
+ },
184
+ async delete(key) {
185
+ const fullKey = require_shared.resolveKey(prefix, key);
186
+ if (!commands.DeleteObjectCommand) throw missingCommand("DeleteObjectCommand", key, "delete");
187
+ try {
188
+ await client.send(new commands.DeleteObjectCommand({
189
+ Bucket: bucket,
190
+ Key: fullKey
191
+ }));
192
+ } catch (error) {
193
+ throw wrap("delete", key, error);
194
+ }
195
+ },
196
+ async getUrl(key, urlOptions = {}) {
197
+ const fullKey = require_shared.resolveKey(prefix, key);
198
+ if (urlOptions.expiresInSeconds === void 0 && options.publicBaseUrl) return require_shared.joinPublicUrl(options.publicBaseUrl, fullKey);
199
+ if (!options.getSignedUrl || !commands.GetObjectCommand) throw new require_shared.StorageError("URL készítéséhez add meg a publicBaseUrl opciót, vagy aláírt URL-hez a getSignedUrl függvényt (@aws-sdk/s3-request-presigner) és a commands.GetObjectCommand osztályt.", {
200
+ operation: "getUrl",
201
+ key
202
+ });
203
+ const expiresIn = require_shared.assertExpires(urlOptions.expiresInSeconds ?? 3600, require_shared.S3_MAX_PRESIGN_SECONDS, key);
204
+ try {
205
+ return await options.getSignedUrl(client, new commands.GetObjectCommand({
206
+ Bucket: bucket,
207
+ Key: fullKey
208
+ }), { expiresIn });
209
+ } catch (error) {
210
+ throw wrap("getUrl", key, error);
211
+ }
212
+ }
213
+ };
214
+ }
215
+ //#endregion
216
+ //#region src/storage/sigv4.ts
217
+ const AWS_SIGV4_ALGORITHM = "AWS4-HMAC-SHA256";
218
+ const UNSIGNED_PAYLOAD = "UNSIGNED-PAYLOAD";
219
+ const encoder = new TextEncoder();
220
+ function toHex(buffer) {
221
+ return Array.from(new Uint8Array(buffer), (byte) => byte.toString(16).padStart(2, "0")).join("");
222
+ }
223
+ function toBuffer(data) {
224
+ return typeof data === "string" ? require_shared.toArrayBuffer(encoder.encode(data)) : require_shared.toArrayBuffer(data);
225
+ }
226
+ async function sha256Hex(data) {
227
+ return toHex(await crypto.subtle.digest("SHA-256", toBuffer(data)));
228
+ }
229
+ async function hmac(key, data) {
230
+ const cryptoKey = await crypto.subtle.importKey("raw", key, {
231
+ name: "HMAC",
232
+ hash: "SHA-256"
233
+ }, false, ["sign"]);
234
+ return crypto.subtle.sign("HMAC", cryptoKey, toBuffer(data));
235
+ }
236
+ function toAmzDate(date) {
237
+ return date.toISOString().replace(/[:-]|\.\d{3}/g, "");
238
+ }
239
+ function canonicalPath(url) {
240
+ return url.pathname.split("/").map((segment) => require_shared.encodeRfc3986(decodeURIComponent(segment))).join("/");
241
+ }
242
+ function canonicalQuery(params) {
243
+ return [...params].map(([name, value]) => [require_shared.encodeRfc3986(name), require_shared.encodeRfc3986(value)]).sort(([nameA, valueA], [nameB, valueB]) => nameA === nameB ? valueA < valueB ? -1 : 1 : nameA < nameB ? -1 : 1).map(([name, value]) => `${name}=${value}`).join("&");
244
+ }
245
+ function normalizeHeaders(headers) {
246
+ const normalized = /* @__PURE__ */ new Map();
247
+ for (const [name, value] of Object.entries(headers)) normalized.set(name.toLowerCase(), value.trim().replace(/\s+/g, " "));
248
+ return new Map([...normalized].sort(([a], [b]) => a < b ? -1 : 1));
249
+ }
250
+ function canonicalRequest(input) {
251
+ const signedHeaders = [...input.headers.keys()].join(";");
252
+ const headerLines = [...input.headers].map(([name, value]) => `${name}:${value}\n`).join("");
253
+ return {
254
+ request: [
255
+ input.method.toUpperCase(),
256
+ canonicalPath(input.url),
257
+ canonicalQuery(input.url.searchParams),
258
+ headerLines,
259
+ signedHeaders,
260
+ input.payloadHash
261
+ ].join("\n"),
262
+ signedHeaders
263
+ };
264
+ }
265
+ async function signCanonical(scope, amzDate, request) {
266
+ const day = amzDate.slice(0, 8);
267
+ const credentialScope = `${day}/${scope.region}/${scope.service}/aws4_request`;
268
+ const stringToSign = [
269
+ AWS_SIGV4_ALGORITHM,
270
+ amzDate,
271
+ credentialScope,
272
+ await sha256Hex(request)
273
+ ].join("\n");
274
+ return {
275
+ signature: toHex(await hmac(await hmac(await hmac(await hmac(await hmac(toBuffer(`AWS4${scope.credentials.secretAccessKey}`), day), scope.region), scope.service), "aws4_request"), stringToSign)),
276
+ credentialScope
277
+ };
278
+ }
279
+ async function signAwsRequest(input) {
280
+ const url = new URL(input.url);
281
+ const amzDate = toAmzDate(input.date ?? /* @__PURE__ */ new Date());
282
+ const payloadHash = input.payloadHash ?? await sha256Hex(input.body ?? "");
283
+ const extra = {
284
+ host: url.host,
285
+ "x-amz-date": amzDate
286
+ };
287
+ if (input.service === "s3") extra["x-amz-content-sha256"] = payloadHash;
288
+ if (input.credentials.sessionToken) extra["x-amz-security-token"] = input.credentials.sessionToken;
289
+ const headers = normalizeHeaders({
290
+ ...input.headers,
291
+ ...extra
292
+ });
293
+ const { request, signedHeaders } = canonicalRequest({
294
+ method: input.method,
295
+ url,
296
+ headers,
297
+ payloadHash
298
+ });
299
+ const { signature, credentialScope } = await signCanonical(input, amzDate, request);
300
+ const result = {};
301
+ for (const [name, value] of headers) if (name !== "host") result[name] = value;
302
+ result.authorization = `${AWS_SIGV4_ALGORITHM} Credential=${input.credentials.accessKeyId}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${signature}`;
303
+ return result;
304
+ }
305
+ async function presignAwsUrl(input) {
306
+ const url = new URL(input.url);
307
+ const amzDate = toAmzDate(input.date ?? /* @__PURE__ */ new Date());
308
+ const credentialScope = `${amzDate.slice(0, 8)}/${input.region}/${input.service}/aws4_request`;
309
+ url.searchParams.set("X-Amz-Algorithm", AWS_SIGV4_ALGORITHM);
310
+ url.searchParams.set("X-Amz-Credential", `${input.credentials.accessKeyId}/${credentialScope}`);
311
+ url.searchParams.set("X-Amz-Date", amzDate);
312
+ url.searchParams.set("X-Amz-Expires", String(input.expiresInSeconds));
313
+ if (input.credentials.sessionToken) url.searchParams.set("X-Amz-Security-Token", input.credentials.sessionToken);
314
+ url.searchParams.set("X-Amz-SignedHeaders", "host");
315
+ const { request } = canonicalRequest({
316
+ method: input.method,
317
+ url,
318
+ headers: /* @__PURE__ */ new Map([["host", url.host]]),
319
+ payloadHash: UNSIGNED_PAYLOAD
320
+ });
321
+ const { signature } = await signCanonical(input, amzDate, request);
322
+ const query = `${canonicalQuery(url.searchParams)}&X-Amz-Signature=${signature}`;
323
+ return `${url.origin}${canonicalPath(url)}?${query}`;
324
+ }
325
+ //#endregion
326
+ //#region src/storage/s3-fetch.ts
327
+ function requireOption(value, name) {
328
+ if (typeof value !== "string" || value.trim() === "") throw new require_errors.SzamlazzError(`Az s3FetchStorage ${name} opciója kötelező.`, { category: "configuration" });
329
+ return value;
330
+ }
331
+ function bucketBaseUrl(options) {
332
+ const bucket = options.bucket;
333
+ if (options.endpoint === void 0) return options.forcePathStyle ?? bucket.includes(".") ? `https://s3.${options.region}.amazonaws.com/${bucket}` : `https://${bucket}.s3.${options.region}.amazonaws.com`;
334
+ let endpoint;
335
+ try {
336
+ endpoint = new URL(options.endpoint);
337
+ } catch (error) {
338
+ throw new require_errors.SzamlazzError(`Érvénytelen S3 endpoint: ${options.endpoint}`, {
339
+ category: "configuration",
340
+ cause: error
341
+ });
342
+ }
343
+ const basePath = endpoint.pathname.replace(/\/+$/, "");
344
+ if (options.forcePathStyle ?? true) return `${endpoint.origin}${basePath}/${bucket}`;
345
+ return `${endpoint.protocol}//${bucket}.${endpoint.host}${basePath}`;
346
+ }
347
+ function readS3ErrorCode(body) {
348
+ const code = /<Code>([^<]*)<\/Code>/.exec(body)?.[1];
349
+ const message = /<Message>([^<]*)<\/Message>/.exec(body)?.[1];
350
+ if (!code) return void 0;
351
+ return message ? `${code}: ${message}` : code;
352
+ }
353
+ function s3FetchStorage(options) {
354
+ requireOption(options.bucket, "bucket");
355
+ requireOption(options.region, "region");
356
+ const credentials = {
357
+ accessKeyId: requireOption(options.accessKeyId, "accessKeyId"),
358
+ secretAccessKey: requireOption(options.secretAccessKey, "secretAccessKey"),
359
+ sessionToken: options.sessionToken
360
+ };
361
+ const baseUrl = bucketBaseUrl(options);
362
+ const prefix = require_shared.normalizePrefix(options.prefix);
363
+ const scope = {
364
+ credentials,
365
+ region: options.region,
366
+ service: "s3"
367
+ };
368
+ const objectUrl = (fullKey) => `${baseUrl}/${require_shared.encodeKeyPath(fullKey)}`;
369
+ async function send(operation, key, init) {
370
+ const doFetch = options.fetch ?? globalThis.fetch;
371
+ try {
372
+ return await doFetch(init.url, {
373
+ method: init.method,
374
+ headers: init.headers,
375
+ ...init.body === void 0 ? {} : { body: init.body }
376
+ });
377
+ } catch (error) {
378
+ throw new require_shared.StorageError(`S3 hálózati hiba (${operation}): ${require_shared.describeError(error)}`, {
379
+ operation,
380
+ key,
381
+ cause: error
382
+ });
383
+ }
384
+ }
385
+ async function failure(operation, key, response) {
386
+ const detail = readS3ErrorCode(await response.text().catch(() => "")) ?? response.statusText;
387
+ return new require_shared.StorageError(`S3 hiba (${operation}, HTTP ${response.status})${detail ? `: ${detail}` : ""}`, {
388
+ operation,
389
+ key,
390
+ status: response.status
391
+ });
392
+ }
393
+ return {
394
+ async put(key, body, putOptions) {
395
+ const fullKey = require_shared.resolveKey(prefix, key);
396
+ const url = objectUrl(fullKey);
397
+ const response = await send("put", key, {
398
+ method: "PUT",
399
+ url,
400
+ headers: await signAwsRequest({
401
+ ...scope,
402
+ method: "PUT",
403
+ url,
404
+ headers: { "content-type": putOptions.contentType },
405
+ payloadHash: await sha256Hex(body)
406
+ }),
407
+ body: require_shared.toArrayBuffer(body)
408
+ });
409
+ if (!response.ok) throw await failure("put", key, response);
410
+ return {
411
+ key,
412
+ url: options.publicBaseUrl ? require_shared.joinPublicUrl(options.publicBaseUrl, fullKey) : void 0,
413
+ size: body.byteLength,
414
+ contentType: putOptions.contentType
415
+ };
416
+ },
417
+ async get(key) {
418
+ const url = objectUrl(require_shared.resolveKey(prefix, key));
419
+ const response = await send("get", key, {
420
+ method: "GET",
421
+ url,
422
+ headers: await signAwsRequest({
423
+ ...scope,
424
+ method: "GET",
425
+ url
426
+ })
427
+ });
428
+ if (response.status === 404) return void 0;
429
+ if (!response.ok) throw await failure("get", key, response);
430
+ return new Uint8Array(await response.arrayBuffer());
431
+ },
432
+ async delete(key) {
433
+ const url = objectUrl(require_shared.resolveKey(prefix, key));
434
+ const response = await send("delete", key, {
435
+ method: "DELETE",
436
+ url,
437
+ headers: await signAwsRequest({
438
+ ...scope,
439
+ method: "DELETE",
440
+ url
441
+ })
442
+ });
443
+ if (!response.ok && response.status !== 404) throw await failure("delete", key, response);
444
+ },
445
+ async getUrl(key, urlOptions = {}) {
446
+ const fullKey = require_shared.resolveKey(prefix, key);
447
+ if (urlOptions.expiresInSeconds === void 0 && options.publicBaseUrl) return require_shared.joinPublicUrl(options.publicBaseUrl, fullKey);
448
+ return presignAwsUrl({
449
+ ...scope,
450
+ method: "GET",
451
+ url: objectUrl(fullKey),
452
+ expiresInSeconds: require_shared.assertExpires(urlOptions.expiresInSeconds ?? 3600, require_shared.S3_MAX_PRESIGN_SECONDS, key)
453
+ });
454
+ }
455
+ };
456
+ }
457
+ //#endregion
458
+ //#region src/storage/store-pdf.ts
459
+ async function storePdf(storage, key, pdf) {
460
+ if (!require_binary.isPdf(pdf)) throw new require_shared.StorageError("A tárolandó tartalom nem PDF (hiányzik a %PDF fejléc).", {
461
+ operation: "put",
462
+ key
463
+ });
464
+ return storage.put(key, pdf, { contentType: require_shared.PDF_CONTENT_TYPE });
465
+ }
466
+ //#endregion
467
+ //#region src/storage/supabase.ts
468
+ const SUPABASE_MAX_SIGNED_URL_SECONDS = 31536e3;
469
+ function isNotFound(error) {
470
+ return error.status === 404 || error.statusCode === "404" || /not[\s_-]?found/i.test(error.message);
471
+ }
472
+ const run = (operation, key, call) => require_shared.guardStorageCall("Supabase Storage", operation, key, call);
473
+ function failure(operation, key, error) {
474
+ return new require_shared.StorageError(`Supabase Storage hiba (${operation}): ${error?.message ?? "üres válasz"}`, {
475
+ operation,
476
+ key,
477
+ status: error?.status,
478
+ cause: error ?? void 0
479
+ });
480
+ }
481
+ function supabaseStorage(options) {
482
+ const prefix = require_shared.normalizePrefix(options.prefix);
483
+ const bucket = () => options.client.storage.from(options.bucket);
484
+ return {
485
+ async put(key, body, putOptions) {
486
+ const path = require_shared.resolveKey(prefix, key);
487
+ const uploadOptions = {
488
+ contentType: putOptions.contentType,
489
+ upsert: options.upsert ?? true,
490
+ ...options.cacheControl === void 0 ? {} : { cacheControl: options.cacheControl }
491
+ };
492
+ const result = await run("put", key, () => bucket().upload(path, body, uploadOptions));
493
+ if (!result.data) throw failure("put", key, result.error);
494
+ return {
495
+ key,
496
+ url: options.public ? bucket().getPublicUrl(path).data.publicUrl : void 0,
497
+ size: body.byteLength,
498
+ contentType: putOptions.contentType
499
+ };
500
+ },
501
+ async get(key) {
502
+ const path = require_shared.resolveKey(prefix, key);
503
+ const result = await run("get", key, () => bucket().download(path));
504
+ if (!result.data) {
505
+ if (result.error && isNotFound(result.error)) return void 0;
506
+ throw failure("get", key, result.error);
507
+ }
508
+ const blob = result.data;
509
+ return new Uint8Array(await blob.arrayBuffer());
510
+ },
511
+ async delete(key) {
512
+ const path = require_shared.resolveKey(prefix, key);
513
+ const result = await run("delete", key, () => bucket().remove([path]));
514
+ if (result.error) throw failure("delete", key, result.error);
515
+ },
516
+ async getUrl(key, urlOptions = {}) {
517
+ const path = require_shared.resolveKey(prefix, key);
518
+ if (options.public && urlOptions.expiresInSeconds === void 0) return bucket().getPublicUrl(path).data.publicUrl;
519
+ const expiresIn = require_shared.assertExpires(urlOptions.expiresInSeconds ?? 3600, SUPABASE_MAX_SIGNED_URL_SECONDS, key);
520
+ const result = await run("getUrl", key, () => bucket().createSignedUrl(path, expiresIn));
521
+ if (!result.data) throw failure("getUrl", key, result.error);
522
+ return result.data.signedUrl;
523
+ }
524
+ };
525
+ }
526
+ //#endregion
527
+ //#region src/storage/uploadthing.ts
528
+ const UPLOADTHING_MAX_CUSTOM_ID_LENGTH = 128;
529
+ const UPLOADTHING_MAX_SIGNED_URL_SECONDS = 604800;
530
+ function uploadthingStorage(options) {
531
+ const { utapi } = options;
532
+ const prefix = require_shared.normalizePrefix(options.prefix);
533
+ const uploadOptions = {
534
+ ...options.acl === void 0 ? {} : { acl: options.acl },
535
+ ...options.contentDisposition === void 0 ? {} : { contentDisposition: options.contentDisposition }
536
+ };
537
+ return {
538
+ async put(key, body, putOptions) {
539
+ const customId = require_shared.resolveKey(prefix, key);
540
+ if (customId.length > 128) throw new require_shared.StorageError(`Az UploadThing customId legfeljebb 128 karakter lehet, a kulcs ${customId.length} karakteres.`, {
541
+ operation: "key",
542
+ key
543
+ });
544
+ const file = Object.assign(new File([require_shared.toArrayBuffer(body)], require_shared.basename(customId), { type: putOptions.contentType }), { customId });
545
+ const result = await require_shared.guardStorageCall("UploadThing", "put", key, () => utapi.uploadFiles(file, uploadOptions));
546
+ if (!result.data) throw new require_shared.StorageError(`UploadThing hiba (put): ${result.error?.message ?? "ismeretlen hiba"}`, {
547
+ operation: "put",
548
+ key,
549
+ cause: result.error
550
+ });
551
+ return {
552
+ key,
553
+ url: result.data.ufsUrl ?? result.data.url,
554
+ size: result.data.size,
555
+ contentType: putOptions.contentType
556
+ };
557
+ },
558
+ async delete(key) {
559
+ const customId = require_shared.resolveKey(prefix, key);
560
+ await require_shared.guardStorageCall("UploadThing", "delete", key, () => utapi.deleteFiles(customId, { keyType: "customId" }));
561
+ },
562
+ async getUrl(key, urlOptions = {}) {
563
+ const customId = require_shared.resolveKey(prefix, key);
564
+ const generate = utapi.generateSignedURL;
565
+ if (!generate) throw new require_shared.StorageError("Ez az UploadThing verzió nem támogatja a generateSignedURL-t, frissíts uploadthing v7-re.", {
566
+ operation: "getUrl",
567
+ key
568
+ });
569
+ const expiresIn = require_shared.assertExpires(urlOptions.expiresInSeconds ?? 3600, UPLOADTHING_MAX_SIGNED_URL_SECONDS, key);
570
+ return (await require_shared.guardStorageCall("UploadThing", "getUrl", key, () => generate.call(utapi, customId, { expiresIn }))).ufsUrl;
571
+ }
572
+ };
573
+ }
574
+ //#endregion
575
+ //#region src/storage/vercel-blob.ts
576
+ function missingFunction(name, key, operation) {
577
+ return new require_shared.StorageError(`Ehhez a művelethez add át a @vercel/blob ${name} függvényét a vercelBlobStorage-nak.`, {
578
+ operation,
579
+ key
580
+ });
581
+ }
582
+ function vercelBlobStorage(options) {
583
+ const prefix = require_shared.normalizePrefix(options.prefix);
584
+ const commandOptions = options.token ? { token: options.token } : {};
585
+ return {
586
+ async put(key, body, putOptions) {
587
+ const fullKey = require_shared.resolveKey(prefix, key);
588
+ const blobOptions = {
589
+ access: options.access,
590
+ contentType: putOptions.contentType,
591
+ addRandomSuffix: false,
592
+ allowOverwrite: options.allowOverwrite ?? true,
593
+ ...commandOptions,
594
+ ...options.cacheControlMaxAge === void 0 ? {} : { cacheControlMaxAge: options.cacheControlMaxAge }
595
+ };
596
+ const blob = new Blob([require_shared.toArrayBuffer(body)], { type: putOptions.contentType });
597
+ return {
598
+ key,
599
+ url: (await require_shared.guardStorageCall("Vercel Blob", "put", key, () => options.put(fullKey, blob, blobOptions))).url,
600
+ size: body.byteLength,
601
+ contentType: putOptions.contentType
602
+ };
603
+ },
604
+ async delete(key) {
605
+ const fullKey = require_shared.resolveKey(prefix, key);
606
+ const del = options.del;
607
+ if (!del) throw missingFunction("del", key, "delete");
608
+ await require_shared.guardStorageCall("Vercel Blob", "delete", key, () => del(fullKey, commandOptions));
609
+ },
610
+ async getUrl(key, urlOptions = {}) {
611
+ const fullKey = require_shared.resolveKey(prefix, key);
612
+ if (urlOptions.expiresInSeconds !== void 0) throw require_shared.unsupportedSignedUrl("vercelBlobStorage", key);
613
+ const head = options.head;
614
+ if (!head) throw missingFunction("head", key, "getUrl");
615
+ return (await require_shared.guardStorageCall("Vercel Blob", "getUrl", key, () => head(fullKey, commandOptions))).url;
616
+ }
617
+ };
618
+ }
619
+ //#endregion
620
+ exports.DEFAULT_INVOICE_KEY_PREFIX = DEFAULT_INVOICE_KEY_PREFIX;
621
+ exports.DEFAULT_RECEIPT_KEY_PREFIX = DEFAULT_RECEIPT_KEY_PREFIX;
622
+ exports.PDF_CONTENT_TYPE = require_shared.PDF_CONTENT_TYPE;
623
+ exports.S3_MAX_PRESIGN_SECONDS = require_shared.S3_MAX_PRESIGN_SECONDS;
624
+ exports.SUPABASE_MAX_SIGNED_URL_SECONDS = SUPABASE_MAX_SIGNED_URL_SECONDS;
625
+ exports.StorageError = require_shared.StorageError;
626
+ exports.UPLOADTHING_MAX_CUSTOM_ID_LENGTH = UPLOADTHING_MAX_CUSTOM_ID_LENGTH;
627
+ exports.UPLOADTHING_MAX_SIGNED_URL_SECONDS = UPLOADTHING_MAX_SIGNED_URL_SECONDS;
628
+ exports.assertStorageKey = require_shared.assertStorageKey;
629
+ exports.guardStorageCall = require_shared.guardStorageCall;
630
+ exports.invoicePdfKey = invoicePdfKey;
631
+ exports.isStorageError = require_shared.isStorageError;
632
+ exports.memoryStorage = memoryStorage;
633
+ exports.presignAwsUrl = presignAwsUrl;
634
+ exports.r2BindingStorage = r2BindingStorage;
635
+ exports.receiptPdfKey = receiptPdfKey;
636
+ exports.s3FetchStorage = s3FetchStorage;
637
+ exports.s3Storage = s3Storage;
638
+ exports.sanitizeKeySegment = sanitizeKeySegment;
639
+ exports.signAwsRequest = signAwsRequest;
640
+ exports.storePdf = storePdf;
641
+ exports.supabaseStorage = supabaseStorage;
642
+ exports.uploadthingStorage = uploadthingStorage;
643
+ exports.vercelBlobStorage = vercelBlobStorage;