@fragno-dev/stripe 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/client/react.d.ts +5 -5
- package/dist/browser/client/react.d.ts.map +1 -1
- package/dist/browser/client/react.js +105 -13
- package/dist/browser/client/react.js.map +1 -1
- package/dist/browser/client/solid.d.ts +5 -5
- package/dist/browser/client/solid.d.ts.map +1 -1
- package/dist/browser/client/solid.js +25 -11
- package/dist/browser/client/solid.js.map +1 -1
- package/dist/browser/client/svelte.d.ts +5 -5
- package/dist/browser/client/svelte.d.ts.map +1 -1
- package/dist/browser/client/svelte.js +11 -3
- package/dist/browser/client/svelte.js.map +1 -1
- package/dist/browser/client/vanilla.d.ts +5 -5
- package/dist/browser/client/vanilla.d.ts.map +1 -1
- package/dist/browser/client/vanilla.js +21 -1
- package/dist/browser/client/vanilla.js.map +1 -1
- package/dist/browser/client/vue.d.ts +1 -1
- package/dist/browser/client/vue.d.ts.map +1 -1
- package/dist/browser/client/vue.js +19 -11
- package/dist/browser/client/vue.js.map +1 -1
- package/dist/browser/index.d.ts +31 -67
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/browser/{src-D1l5aeYY.js → src-D6VWnvEs.js} +496 -450
- package/dist/browser/src-D6VWnvEs.js.map +1 -0
- package/dist/node/index.d.ts +32 -68
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +511 -461
- package/dist/node/index.js.map +1 -1
- package/package.json +28 -49
- package/dist/browser/src-D1l5aeYY.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { defineFragment, defineRoutes } from "@fragno-dev/core";
|
|
2
|
+
import { column, idColumn, schema } from "@fragno-dev/db/schema";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
|
|
4
5
|
//#region ../fragno/dist/api/route.js
|
|
@@ -15,6 +16,80 @@ function resolveRouteFactories(context, routesOrFactories) {
|
|
|
15
16
|
return routes$1;
|
|
16
17
|
}
|
|
17
18
|
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region ../fragno/dist/api/internal/path.js
|
|
21
|
+
/**
|
|
22
|
+
* Extract parameter names from a path pattern at runtime.
|
|
23
|
+
* Examples:
|
|
24
|
+
* - "/users/:id" => ["id"]
|
|
25
|
+
* - "/files/**" => ["**"]
|
|
26
|
+
* - "/files/**:rest" => ["rest"]
|
|
27
|
+
*/
|
|
28
|
+
function extractPathParams(pathPattern) {
|
|
29
|
+
const segments = pathPattern.split("/").filter((s) => s.length > 0);
|
|
30
|
+
const names = [];
|
|
31
|
+
for (const segment of segments) {
|
|
32
|
+
if (segment.startsWith(":")) {
|
|
33
|
+
names.push(segment.slice(1));
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (segment === "**") {
|
|
37
|
+
names.push("**");
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (segment.startsWith("**:")) {
|
|
41
|
+
names.push(segment.slice(3));
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return names;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Build a concrete path by replacing placeholders in a path pattern with values.
|
|
49
|
+
*
|
|
50
|
+
* Supports the same placeholder syntax as the matcher:
|
|
51
|
+
* - Named parameter ":name" is URL-encoded as a single segment
|
|
52
|
+
* - Anonymous wildcard "**" inserts the remainder as-is (slashes preserved)
|
|
53
|
+
* - Named wildcard "**:name" inserts the remainder from the named key
|
|
54
|
+
*
|
|
55
|
+
* Examples:
|
|
56
|
+
* - buildPath("/users/:id", { id: "123" }) => "/users/123"
|
|
57
|
+
* - buildPath("/files/**", { "**": "a/b" }) => "/files/a/b"
|
|
58
|
+
* - buildPath("/files/**:rest", { rest: "a/b" }) => "/files/a/b"
|
|
59
|
+
*/
|
|
60
|
+
function buildPath(pathPattern, params) {
|
|
61
|
+
const patternSegments = pathPattern.split("/");
|
|
62
|
+
const builtSegments = [];
|
|
63
|
+
for (const segment of patternSegments) {
|
|
64
|
+
if (segment.length === 0) {
|
|
65
|
+
builtSegments.push("");
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (segment.startsWith(":")) {
|
|
69
|
+
const name = segment.slice(1);
|
|
70
|
+
const value = params[name];
|
|
71
|
+
if (value === void 0) throw new Error(`Missing value for path parameter :${name}`);
|
|
72
|
+
builtSegments.push(encodeURIComponent(value));
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (segment === "**") {
|
|
76
|
+
const value = params["**"];
|
|
77
|
+
if (value === void 0) throw new Error("Missing value for path wildcard **");
|
|
78
|
+
builtSegments.push(value);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (segment.startsWith("**:")) {
|
|
82
|
+
const name = segment.slice(3);
|
|
83
|
+
const value = params[name];
|
|
84
|
+
if (value === void 0) throw new Error(`Missing value for path wildcard **:${name}`);
|
|
85
|
+
builtSegments.push(value);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
builtSegments.push(segment);
|
|
89
|
+
}
|
|
90
|
+
return builtSegments.join("/");
|
|
91
|
+
}
|
|
92
|
+
|
|
18
93
|
//#endregion
|
|
19
94
|
//#region ../fragno/dist/api/internal/route.js
|
|
20
95
|
function getMountRoute(opts) {
|
|
@@ -444,170 +519,6 @@ var RequestOutputContext = class extends OutputContext {
|
|
|
444
519
|
}
|
|
445
520
|
};
|
|
446
521
|
|
|
447
|
-
//#endregion
|
|
448
|
-
//#region ../fragno/dist/api/internal/path.js
|
|
449
|
-
/**
|
|
450
|
-
* Extract parameter names from a path pattern at runtime.
|
|
451
|
-
* Examples:
|
|
452
|
-
* - "/users/:id" => ["id"]
|
|
453
|
-
* - "/files/**" => ["**"]
|
|
454
|
-
* - "/files/**:rest" => ["rest"]
|
|
455
|
-
*/
|
|
456
|
-
function extractPathParams(pathPattern) {
|
|
457
|
-
const segments = pathPattern.split("/").filter((s) => s.length > 0);
|
|
458
|
-
const names = [];
|
|
459
|
-
for (const segment of segments) {
|
|
460
|
-
if (segment.startsWith(":")) {
|
|
461
|
-
names.push(segment.slice(1));
|
|
462
|
-
continue;
|
|
463
|
-
}
|
|
464
|
-
if (segment === "**") {
|
|
465
|
-
names.push("**");
|
|
466
|
-
continue;
|
|
467
|
-
}
|
|
468
|
-
if (segment.startsWith("**:")) {
|
|
469
|
-
names.push(segment.slice(3));
|
|
470
|
-
continue;
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
return names;
|
|
474
|
-
}
|
|
475
|
-
/**
|
|
476
|
-
* Build a concrete path by replacing placeholders in a path pattern with values.
|
|
477
|
-
*
|
|
478
|
-
* Supports the same placeholder syntax as the matcher:
|
|
479
|
-
* - Named parameter ":name" is URL-encoded as a single segment
|
|
480
|
-
* - Anonymous wildcard "**" inserts the remainder as-is (slashes preserved)
|
|
481
|
-
* - Named wildcard "**:name" inserts the remainder from the named key
|
|
482
|
-
*
|
|
483
|
-
* Examples:
|
|
484
|
-
* - buildPath("/users/:id", { id: "123" }) => "/users/123"
|
|
485
|
-
* - buildPath("/files/**", { "**": "a/b" }) => "/files/a/b"
|
|
486
|
-
* - buildPath("/files/**:rest", { rest: "a/b" }) => "/files/a/b"
|
|
487
|
-
*/
|
|
488
|
-
function buildPath(pathPattern, params) {
|
|
489
|
-
const patternSegments = pathPattern.split("/");
|
|
490
|
-
const builtSegments = [];
|
|
491
|
-
for (const segment of patternSegments) {
|
|
492
|
-
if (segment.length === 0) {
|
|
493
|
-
builtSegments.push("");
|
|
494
|
-
continue;
|
|
495
|
-
}
|
|
496
|
-
if (segment.startsWith(":")) {
|
|
497
|
-
const name = segment.slice(1);
|
|
498
|
-
const value = params[name];
|
|
499
|
-
if (value === void 0) throw new Error(`Missing value for path parameter :${name}`);
|
|
500
|
-
builtSegments.push(encodeURIComponent(value));
|
|
501
|
-
continue;
|
|
502
|
-
}
|
|
503
|
-
if (segment === "**") {
|
|
504
|
-
const value = params["**"];
|
|
505
|
-
if (value === void 0) throw new Error("Missing value for path wildcard **");
|
|
506
|
-
builtSegments.push(value);
|
|
507
|
-
continue;
|
|
508
|
-
}
|
|
509
|
-
if (segment.startsWith("**:")) {
|
|
510
|
-
const name = segment.slice(3);
|
|
511
|
-
const value = params[name];
|
|
512
|
-
if (value === void 0) throw new Error(`Missing value for path wildcard **:${name}`);
|
|
513
|
-
builtSegments.push(value);
|
|
514
|
-
continue;
|
|
515
|
-
}
|
|
516
|
-
builtSegments.push(segment);
|
|
517
|
-
}
|
|
518
|
-
return builtSegments.join("/");
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
//#endregion
|
|
522
|
-
//#region ../fragno/dist/client/client-error.js
|
|
523
|
-
/**
|
|
524
|
-
* Base error class for all Fragno client errors.
|
|
525
|
-
*/
|
|
526
|
-
var FragnoClientError = class extends Error {
|
|
527
|
-
#code;
|
|
528
|
-
constructor(message, code, options = {}) {
|
|
529
|
-
super(message, { cause: options.cause });
|
|
530
|
-
this.name = "FragnoClientError";
|
|
531
|
-
this.#code = code;
|
|
532
|
-
}
|
|
533
|
-
get code() {
|
|
534
|
-
return this.#code;
|
|
535
|
-
}
|
|
536
|
-
};
|
|
537
|
-
var FragnoClientFetchError = class extends FragnoClientError {
|
|
538
|
-
constructor(message, code, options = {}) {
|
|
539
|
-
super(message, code, options);
|
|
540
|
-
this.name = "FragnoClientFetchError";
|
|
541
|
-
}
|
|
542
|
-
static fromUnknownFetchError(error) {
|
|
543
|
-
if (!(error instanceof Error)) return new FragnoClientFetchNetworkError("Network request failed", { cause: error });
|
|
544
|
-
if (error.name === "AbortError") return new FragnoClientFetchAbortError("Request was aborted", { cause: error });
|
|
545
|
-
return new FragnoClientFetchNetworkError("Network request failed", { cause: error });
|
|
546
|
-
}
|
|
547
|
-
};
|
|
548
|
-
/**
|
|
549
|
-
* Error thrown when a network request fails (e.g., no internet connection, DNS failure).
|
|
550
|
-
*/
|
|
551
|
-
var FragnoClientFetchNetworkError = class extends FragnoClientFetchError {
|
|
552
|
-
constructor(message = "Network request failed", options = {}) {
|
|
553
|
-
super(message, "NETWORK_ERROR", options);
|
|
554
|
-
this.name = "FragnoClientFetchNetworkError";
|
|
555
|
-
}
|
|
556
|
-
};
|
|
557
|
-
/**
|
|
558
|
-
* Error thrown when a request is aborted (e.g., user cancels request, timeout).
|
|
559
|
-
*/
|
|
560
|
-
var FragnoClientFetchAbortError = class extends FragnoClientFetchError {
|
|
561
|
-
constructor(message = "Request was aborted", options = {}) {
|
|
562
|
-
super(message, "ABORT_ERROR", options);
|
|
563
|
-
this.name = "FragnoClientFetchAbortError";
|
|
564
|
-
}
|
|
565
|
-
};
|
|
566
|
-
/**
|
|
567
|
-
* Error thrown when the API result is unexpected, e.g. no json is returned.
|
|
568
|
-
*/
|
|
569
|
-
var FragnoClientUnknownApiError = class extends FragnoClientError {
|
|
570
|
-
#status;
|
|
571
|
-
constructor(message = "Unknown API error", status, options = {}) {
|
|
572
|
-
super(message, "UNKNOWN_API_ERROR", options);
|
|
573
|
-
this.name = "FragnoClientUnknownApiError";
|
|
574
|
-
this.#status = status;
|
|
575
|
-
}
|
|
576
|
-
get status() {
|
|
577
|
-
return this.#status;
|
|
578
|
-
}
|
|
579
|
-
};
|
|
580
|
-
var FragnoClientApiError = class FragnoClientApiError$1 extends FragnoClientError {
|
|
581
|
-
#status;
|
|
582
|
-
constructor({ message, code }, status, options = {}) {
|
|
583
|
-
super(message, code, options);
|
|
584
|
-
this.name = "FragnoClientApiError";
|
|
585
|
-
this.#status = status;
|
|
586
|
-
}
|
|
587
|
-
get status() {
|
|
588
|
-
return this.#status;
|
|
589
|
-
}
|
|
590
|
-
/**
|
|
591
|
-
* The error code returned by the API.
|
|
592
|
-
*
|
|
593
|
-
* The type is `TErrorCode` (the set of known error codes for this route), but may also be a string
|
|
594
|
-
* for forward compatibility with future error codes.
|
|
595
|
-
*/
|
|
596
|
-
get code() {
|
|
597
|
-
return super.code;
|
|
598
|
-
}
|
|
599
|
-
static async fromResponse(response) {
|
|
600
|
-
const unknown = await response.json();
|
|
601
|
-
const status = response.status;
|
|
602
|
-
if (!("message" in unknown || "code" in unknown)) return new FragnoClientUnknownApiError("Unknown API error", status);
|
|
603
|
-
if (!(typeof unknown.message === "string" && typeof unknown.code === "string")) return new FragnoClientUnknownApiError("Unknown API error", status);
|
|
604
|
-
return new FragnoClientApiError$1({
|
|
605
|
-
message: unknown.message,
|
|
606
|
-
code: unknown.code
|
|
607
|
-
}, status);
|
|
608
|
-
}
|
|
609
|
-
};
|
|
610
|
-
|
|
611
522
|
//#endregion
|
|
612
523
|
//#region ../fragno/dist/util/content-type.js
|
|
613
524
|
/**
|
|
@@ -656,142 +567,36 @@ function parseContentType(contentType) {
|
|
|
656
567
|
}
|
|
657
568
|
|
|
658
569
|
//#endregion
|
|
659
|
-
//#region ../fragno/dist/
|
|
570
|
+
//#region ../fragno/dist/util/nanostores.js
|
|
660
571
|
/**
|
|
661
|
-
*
|
|
572
|
+
* Normalizes a value that could be a plain value, an Atom, or a Vue Ref to a plain value.
|
|
662
573
|
*/
|
|
663
|
-
function
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
reject(new FragnoClientFetchAbortError("Operation was aborted"));
|
|
667
|
-
};
|
|
668
|
-
if (abortSignal.aborted) abortHandler();
|
|
669
|
-
else abortSignal.addEventListener("abort", abortHandler, { once: true });
|
|
670
|
-
});
|
|
574
|
+
function unwrapAtom(value) {
|
|
575
|
+
if (value && typeof value === "object" && "get" in value && typeof value.get === "function") return value.get();
|
|
576
|
+
return value;
|
|
671
577
|
}
|
|
672
578
|
/**
|
|
673
|
-
*
|
|
674
|
-
*
|
|
675
|
-
*
|
|
676
|
-
* This makes it so that we can wait until the first chunk before updating the store, if we did
|
|
677
|
-
* not do this, `loading` would briefly be false before the first item would be populated in the
|
|
678
|
-
* result.
|
|
679
|
-
*
|
|
680
|
-
* @param response - The fetch Response object containing the NDJSON stream
|
|
681
|
-
* @param store - The fetcher store to update with streaming data
|
|
682
|
-
* @param abortSignal - Optional AbortSignal to cancel the streaming operation
|
|
683
|
-
* @returns A promise that resolves to an object containing the first item and a streaming promise
|
|
579
|
+
* Normalizes an object where values can be plain values, Atoms, or Vue Refs.
|
|
580
|
+
* Returns a new object with all values normalized to plain values.
|
|
684
581
|
*/
|
|
685
|
-
|
|
686
|
-
if (!
|
|
687
|
-
|
|
688
|
-
if (abortSignal?.aborted) throw new FragnoClientFetchAbortError("Operation was aborted");
|
|
689
|
-
const decoder = new TextDecoder();
|
|
690
|
-
const reader = response.body.getReader();
|
|
691
|
-
let buffer = "";
|
|
692
|
-
let firstItem = null;
|
|
693
|
-
const items = [];
|
|
694
|
-
try {
|
|
695
|
-
while (firstItem === null) {
|
|
696
|
-
if (abortSignal?.aborted) {
|
|
697
|
-
reader.releaseLock();
|
|
698
|
-
throw new FragnoClientFetchAbortError("Operation was aborted");
|
|
699
|
-
}
|
|
700
|
-
const { done, value } = await (abortSignal ? Promise.race([reader.read(), createAbortPromise(abortSignal)]) : reader.read());
|
|
701
|
-
if (done) break;
|
|
702
|
-
buffer += decoder.decode(value, { stream: true });
|
|
703
|
-
const lines = buffer.split("\n");
|
|
704
|
-
buffer = lines.pop() || "";
|
|
705
|
-
for (const line of lines) {
|
|
706
|
-
if (!line.trim()) continue;
|
|
707
|
-
try {
|
|
708
|
-
const jsonObject = JSON.parse(line);
|
|
709
|
-
items.push(jsonObject);
|
|
710
|
-
if (firstItem === null) {
|
|
711
|
-
firstItem = jsonObject;
|
|
712
|
-
const streamingPromise = continueStreaming(reader, decoder, buffer, items, store, abortSignal);
|
|
713
|
-
return {
|
|
714
|
-
firstItem,
|
|
715
|
-
streamingPromise
|
|
716
|
-
};
|
|
717
|
-
}
|
|
718
|
-
} catch (parseError) {
|
|
719
|
-
throw new FragnoClientUnknownApiError("Failed to parse NDJSON line", 500, { cause: parseError });
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
if (firstItem === null) {
|
|
724
|
-
reader.releaseLock();
|
|
725
|
-
throw new FragnoClientUnknownApiError("NDJSON stream contained no valid items", 500);
|
|
726
|
-
}
|
|
727
|
-
reader.releaseLock();
|
|
728
|
-
throw new FragnoClientFetchError("Unexpected end of stream processing", "NO_BODY");
|
|
729
|
-
} catch (error) {
|
|
730
|
-
if (error instanceof FragnoClientError) {
|
|
731
|
-
store?.setError(error);
|
|
732
|
-
throw error;
|
|
733
|
-
} else {
|
|
734
|
-
const clientError = new FragnoClientUnknownApiError("Unknown streaming error", 500, { cause: error });
|
|
735
|
-
store?.setError(clientError);
|
|
736
|
-
throw clientError;
|
|
737
|
-
}
|
|
738
|
-
}
|
|
582
|
+
function unwrapObject(params) {
|
|
583
|
+
if (!params) return;
|
|
584
|
+
return Object.fromEntries(Object.entries(params).map(([key, value]) => [key, unwrapAtom(value)]));
|
|
739
585
|
}
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
if (buffer.trim()) {
|
|
751
|
-
const lines$1 = buffer.split("\n");
|
|
752
|
-
for (const line of lines$1) {
|
|
753
|
-
if (!line.trim()) continue;
|
|
754
|
-
try {
|
|
755
|
-
const jsonObject = JSON.parse(line);
|
|
756
|
-
items.push(jsonObject);
|
|
757
|
-
store?.setData([...items]);
|
|
758
|
-
} catch (parseError) {
|
|
759
|
-
throw new FragnoClientUnknownApiError("Failed to parse NDJSON line", 400, { cause: parseError });
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
break;
|
|
764
|
-
}
|
|
765
|
-
buffer += decoder.decode(value, { stream: true });
|
|
766
|
-
const lines = buffer.split("\n");
|
|
767
|
-
buffer = lines.pop() || "";
|
|
768
|
-
for (const line of lines) {
|
|
769
|
-
if (!line.trim()) continue;
|
|
770
|
-
try {
|
|
771
|
-
const jsonObject = JSON.parse(line);
|
|
772
|
-
items.push(jsonObject);
|
|
773
|
-
store?.setData([...items]);
|
|
774
|
-
} catch (parseError) {
|
|
775
|
-
throw new FragnoClientUnknownApiError("Failed to parse NDJSON line", 400, { cause: parseError });
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
} catch (error) {
|
|
780
|
-
if (error instanceof FragnoClientError) store?.setError(error);
|
|
781
|
-
else {
|
|
782
|
-
const clientError = new FragnoClientUnknownApiError("Unknown streaming error", 400, { cause: error });
|
|
783
|
-
store?.setError(clientError);
|
|
784
|
-
throw clientError;
|
|
785
|
-
}
|
|
786
|
-
throw error;
|
|
787
|
-
} finally {
|
|
788
|
-
reader.releaseLock();
|
|
789
|
-
}
|
|
790
|
-
return items;
|
|
586
|
+
function isReadableAtom(value) {
|
|
587
|
+
if (!value) return false;
|
|
588
|
+
if (typeof value !== "object" || value === null) return false;
|
|
589
|
+
if (!("get" in value) || typeof value.get !== "function") return false;
|
|
590
|
+
if (!("lc" in value) || typeof value.lc !== "number") return false;
|
|
591
|
+
if (!("notify" in value) || typeof value.notify !== "function") return false;
|
|
592
|
+
if (!("off" in value) || typeof value.off !== "function") return false;
|
|
593
|
+
if (!("subscribe" in value) || typeof value.subscribe !== "function") return false;
|
|
594
|
+
if (!("value" in value)) return false;
|
|
595
|
+
return true;
|
|
791
596
|
}
|
|
792
597
|
|
|
793
598
|
//#endregion
|
|
794
|
-
//#region ../../node_modules/.pnpm/nanostores@1.
|
|
599
|
+
//#region ../../node_modules/.pnpm/nanostores@1.2.0/node_modules/nanostores/task/index.js
|
|
795
600
|
let tasks = 0;
|
|
796
601
|
let resolves = [];
|
|
797
602
|
function startTask() {
|
|
@@ -813,11 +618,11 @@ function task(cb) {
|
|
|
813
618
|
}
|
|
814
619
|
|
|
815
620
|
//#endregion
|
|
816
|
-
//#region ../../node_modules/.pnpm/nanostores@1.
|
|
621
|
+
//#region ../../node_modules/.pnpm/nanostores@1.2.0/node_modules/nanostores/clean-stores/index.js
|
|
817
622
|
let clean = Symbol("clean");
|
|
818
623
|
|
|
819
624
|
//#endregion
|
|
820
|
-
//#region ../../node_modules/.pnpm/nanostores@1.
|
|
625
|
+
//#region ../../node_modules/.pnpm/nanostores@1.2.0/node_modules/nanostores/atom/index.js
|
|
821
626
|
let listenerQueue = [];
|
|
822
627
|
let lqIndex = 0;
|
|
823
628
|
const QUEUE_ITEMS_PER_LISTENER = 4;
|
|
@@ -829,6 +634,7 @@ const atom = /* @__NO_SIDE_EFFECTS__ */ (initialValue) => {
|
|
|
829
634
|
if (!$atom.lc) $atom.listen(() => {})();
|
|
830
635
|
return $atom.value;
|
|
831
636
|
},
|
|
637
|
+
init: initialValue,
|
|
832
638
|
lc: 0,
|
|
833
639
|
listen(listener) {
|
|
834
640
|
$atom.lc = listeners.push(listener);
|
|
@@ -875,7 +681,7 @@ const atom = /* @__NO_SIDE_EFFECTS__ */ (initialValue) => {
|
|
|
875
681
|
};
|
|
876
682
|
|
|
877
683
|
//#endregion
|
|
878
|
-
//#region ../../node_modules/.pnpm/nanostores@1.
|
|
684
|
+
//#region ../../node_modules/.pnpm/nanostores@1.2.0/node_modules/nanostores/lifecycle/index.js
|
|
879
685
|
const START = 0;
|
|
880
686
|
const STOP = 1;
|
|
881
687
|
const MOUNT = 5;
|
|
@@ -970,7 +776,21 @@ let onMount = ($store, initialize) => {
|
|
|
970
776
|
};
|
|
971
777
|
|
|
972
778
|
//#endregion
|
|
973
|
-
//#region ../../node_modules/.pnpm/nanostores@1.
|
|
779
|
+
//#region ../../node_modules/.pnpm/nanostores@1.2.0/node_modules/nanostores/warn/index.js
|
|
780
|
+
let warned = {};
|
|
781
|
+
function warn(text) {
|
|
782
|
+
if (!warned[text]) {
|
|
783
|
+
warned[text] = true;
|
|
784
|
+
if (typeof console !== "undefined" && console.warn) {
|
|
785
|
+
console.groupCollapsed("Nano Stores: " + text);
|
|
786
|
+
console.trace("Source of deprecated call");
|
|
787
|
+
console.groupEnd();
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
//#endregion
|
|
793
|
+
//#region ../../node_modules/.pnpm/nanostores@1.2.0/node_modules/nanostores/computed/index.js
|
|
974
794
|
let computedStore = (stores$1, cb, batched$1) => {
|
|
975
795
|
if (!Array.isArray(stores$1)) stores$1 = [stores$1];
|
|
976
796
|
let previousArgs;
|
|
@@ -982,10 +802,12 @@ let computedStore = (stores$1, cb, batched$1) => {
|
|
|
982
802
|
if (!previousArgs || args.some((arg, i) => arg !== previousArgs[i])) {
|
|
983
803
|
previousArgs = args;
|
|
984
804
|
let value = cb(...args);
|
|
985
|
-
if (value && value.then && value.t)
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
805
|
+
if (value && value.then && value.t) {
|
|
806
|
+
warn("Use @nanostores/async for async computed. We will remove Promise support in computed() in Nano Stores 2.0");
|
|
807
|
+
value.then((asyncValue) => {
|
|
808
|
+
if (previousArgs === args) $computed.set(asyncValue);
|
|
809
|
+
});
|
|
810
|
+
} else {
|
|
989
811
|
$computed.set(value);
|
|
990
812
|
currentEpoch = epoch;
|
|
991
813
|
}
|
|
@@ -1015,7 +837,7 @@ const computed = /* @__NO_SIDE_EFFECTS__ */ (stores$1, fn) => computedStore(stor
|
|
|
1015
837
|
const batched = /* @__NO_SIDE_EFFECTS__ */ (stores$1, fn) => computedStore(stores$1, fn, true);
|
|
1016
838
|
|
|
1017
839
|
//#endregion
|
|
1018
|
-
//#region ../../node_modules/.pnpm/nanostores@1.
|
|
840
|
+
//#region ../../node_modules/.pnpm/nanostores@1.2.0/node_modules/nanostores/map/index.js
|
|
1019
841
|
const map = /* @__NO_SIDE_EFFECTS__ */ (initial = {}) => {
|
|
1020
842
|
let $map = atom(initial);
|
|
1021
843
|
$map.setKey = function(key, value) {
|
|
@@ -1052,33 +874,94 @@ function getInitialData(key) {
|
|
|
1052
874
|
}
|
|
1053
875
|
|
|
1054
876
|
//#endregion
|
|
1055
|
-
//#region ../fragno/dist/
|
|
877
|
+
//#region ../fragno/dist/client/client-error.js
|
|
1056
878
|
/**
|
|
1057
|
-
*
|
|
879
|
+
* Base error class for all Fragno client errors.
|
|
1058
880
|
*/
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
}
|
|
881
|
+
var FragnoClientError = class extends Error {
|
|
882
|
+
#code;
|
|
883
|
+
constructor(message, code, options = {}) {
|
|
884
|
+
super(message, { cause: options.cause });
|
|
885
|
+
this.name = "FragnoClientError";
|
|
886
|
+
this.#code = code;
|
|
887
|
+
}
|
|
888
|
+
get code() {
|
|
889
|
+
return this.#code;
|
|
890
|
+
}
|
|
891
|
+
};
|
|
892
|
+
var FragnoClientFetchError = class extends FragnoClientError {
|
|
893
|
+
constructor(message, code, options = {}) {
|
|
894
|
+
super(message, code, options);
|
|
895
|
+
this.name = "FragnoClientFetchError";
|
|
896
|
+
}
|
|
897
|
+
static fromUnknownFetchError(error) {
|
|
898
|
+
if (!(error instanceof Error)) return new FragnoClientFetchNetworkError("Network request failed", { cause: error });
|
|
899
|
+
if (error.name === "AbortError") return new FragnoClientFetchAbortError("Request was aborted", { cause: error });
|
|
900
|
+
return new FragnoClientFetchNetworkError("Network request failed", { cause: error });
|
|
901
|
+
}
|
|
902
|
+
};
|
|
1063
903
|
/**
|
|
1064
|
-
*
|
|
1065
|
-
* Returns a new object with all values normalized to plain values.
|
|
904
|
+
* Error thrown when a network request fails (e.g., no internet connection, DNS failure).
|
|
1066
905
|
*/
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
}
|
|
906
|
+
var FragnoClientFetchNetworkError = class extends FragnoClientFetchError {
|
|
907
|
+
constructor(message = "Network request failed", options = {}) {
|
|
908
|
+
super(message, "NETWORK_ERROR", options);
|
|
909
|
+
this.name = "FragnoClientFetchNetworkError";
|
|
910
|
+
}
|
|
911
|
+
};
|
|
912
|
+
/**
|
|
913
|
+
* Error thrown when a request is aborted (e.g., user cancels request, timeout).
|
|
914
|
+
*/
|
|
915
|
+
var FragnoClientFetchAbortError = class extends FragnoClientFetchError {
|
|
916
|
+
constructor(message = "Request was aborted", options = {}) {
|
|
917
|
+
super(message, "ABORT_ERROR", options);
|
|
918
|
+
this.name = "FragnoClientFetchAbortError";
|
|
919
|
+
}
|
|
920
|
+
};
|
|
921
|
+
/**
|
|
922
|
+
* Error thrown when the API result is unexpected, e.g. no json is returned.
|
|
923
|
+
*/
|
|
924
|
+
var FragnoClientUnknownApiError = class extends FragnoClientError {
|
|
925
|
+
#status;
|
|
926
|
+
constructor(message = "Unknown API error", status, options = {}) {
|
|
927
|
+
super(message, "UNKNOWN_API_ERROR", options);
|
|
928
|
+
this.name = "FragnoClientUnknownApiError";
|
|
929
|
+
this.#status = status;
|
|
930
|
+
}
|
|
931
|
+
get status() {
|
|
932
|
+
return this.#status;
|
|
933
|
+
}
|
|
934
|
+
};
|
|
935
|
+
var FragnoClientApiError = class FragnoClientApiError$1 extends FragnoClientError {
|
|
936
|
+
#status;
|
|
937
|
+
constructor({ message, code }, status, options = {}) {
|
|
938
|
+
super(message, code, options);
|
|
939
|
+
this.name = "FragnoClientApiError";
|
|
940
|
+
this.#status = status;
|
|
941
|
+
}
|
|
942
|
+
get status() {
|
|
943
|
+
return this.#status;
|
|
944
|
+
}
|
|
945
|
+
/**
|
|
946
|
+
* The error code returned by the API.
|
|
947
|
+
*
|
|
948
|
+
* The type is `TErrorCode` (the set of known error codes for this route), but may also be a string
|
|
949
|
+
* for forward compatibility with future error codes.
|
|
950
|
+
*/
|
|
951
|
+
get code() {
|
|
952
|
+
return super.code;
|
|
953
|
+
}
|
|
954
|
+
static async fromResponse(response) {
|
|
955
|
+
const unknown = await response.json();
|
|
956
|
+
const status = response.status;
|
|
957
|
+
if (!("message" in unknown || "code" in unknown)) return new FragnoClientUnknownApiError("Unknown API error", status);
|
|
958
|
+
if (!(typeof unknown.message === "string" && typeof unknown.code === "string")) return new FragnoClientUnknownApiError("Unknown API error", status);
|
|
959
|
+
return new FragnoClientApiError$1({
|
|
960
|
+
message: unknown.message,
|
|
961
|
+
code: unknown.code
|
|
962
|
+
}, status);
|
|
963
|
+
}
|
|
964
|
+
};
|
|
1082
965
|
|
|
1083
966
|
//#endregion
|
|
1084
967
|
//#region ../fragno/dist/client/internal/fetcher-merge.js
|
|
@@ -1100,18 +983,153 @@ function mergeFetcherConfigs(authorConfig, userConfig) {
|
|
|
1100
983
|
...userOpts,
|
|
1101
984
|
headers: mergeHeaders(authorOpts.headers, userOpts.headers)
|
|
1102
985
|
}
|
|
1103
|
-
};
|
|
1104
|
-
}
|
|
1105
|
-
/**
|
|
1106
|
-
* Merge headers from author and user configs.
|
|
1107
|
-
* User headers override author headers.
|
|
1108
|
-
*/
|
|
1109
|
-
function mergeHeaders(author, user) {
|
|
1110
|
-
if (!author && !user) return;
|
|
1111
|
-
const merged = new Headers(author);
|
|
1112
|
-
new Headers(user).forEach((value, key) => merged.set(key, value));
|
|
1113
|
-
if (merged.keys().next().done) return;
|
|
1114
|
-
return merged;
|
|
986
|
+
};
|
|
987
|
+
}
|
|
988
|
+
/**
|
|
989
|
+
* Merge headers from author and user configs.
|
|
990
|
+
* User headers override author headers.
|
|
991
|
+
*/
|
|
992
|
+
function mergeHeaders(author, user) {
|
|
993
|
+
if (!author && !user) return;
|
|
994
|
+
const merged = new Headers(author);
|
|
995
|
+
new Headers(user).forEach((value, key) => merged.set(key, value));
|
|
996
|
+
if (merged.keys().next().done) return;
|
|
997
|
+
return merged;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
//#endregion
|
|
1001
|
+
//#region ../fragno/dist/client/internal/ndjson-streaming.js
|
|
1002
|
+
/**
|
|
1003
|
+
* Creates a promise that rejects when the abort signal is triggered
|
|
1004
|
+
*/
|
|
1005
|
+
function createAbortPromise(abortSignal) {
|
|
1006
|
+
return new Promise((_, reject) => {
|
|
1007
|
+
const abortHandler = () => {
|
|
1008
|
+
reject(new FragnoClientFetchAbortError("Operation was aborted"));
|
|
1009
|
+
};
|
|
1010
|
+
if (abortSignal.aborted) abortHandler();
|
|
1011
|
+
else abortSignal.addEventListener("abort", abortHandler, { once: true });
|
|
1012
|
+
});
|
|
1013
|
+
}
|
|
1014
|
+
/**
|
|
1015
|
+
* Handles NDJSON streaming responses by returning the first item from the fetcher
|
|
1016
|
+
* and then continuing to stream updates via the store's mutate method.
|
|
1017
|
+
*
|
|
1018
|
+
* This makes it so that we can wait until the first chunk before updating the store, if we did
|
|
1019
|
+
* not do this, `loading` would briefly be false before the first item would be populated in the
|
|
1020
|
+
* result.
|
|
1021
|
+
*
|
|
1022
|
+
* @param response - The fetch Response object containing the NDJSON stream
|
|
1023
|
+
* @param store - The fetcher store to update with streaming data
|
|
1024
|
+
* @param abortSignal - Optional AbortSignal to cancel the streaming operation
|
|
1025
|
+
* @returns A promise that resolves to an object containing the first item and a streaming promise
|
|
1026
|
+
*/
|
|
1027
|
+
async function handleNdjsonStreamingFirstItem(response, store, options = {}) {
|
|
1028
|
+
if (!response.body) throw new FragnoClientFetchError("Streaming response has no body", "NO_BODY");
|
|
1029
|
+
const { abortSignal } = options;
|
|
1030
|
+
if (abortSignal?.aborted) throw new FragnoClientFetchAbortError("Operation was aborted");
|
|
1031
|
+
const decoder = new TextDecoder();
|
|
1032
|
+
const reader = response.body.getReader();
|
|
1033
|
+
let buffer = "";
|
|
1034
|
+
let firstItem = null;
|
|
1035
|
+
const items = [];
|
|
1036
|
+
try {
|
|
1037
|
+
while (firstItem === null) {
|
|
1038
|
+
if (abortSignal?.aborted) {
|
|
1039
|
+
reader.releaseLock();
|
|
1040
|
+
throw new FragnoClientFetchAbortError("Operation was aborted");
|
|
1041
|
+
}
|
|
1042
|
+
const { done, value } = await (abortSignal ? Promise.race([reader.read(), createAbortPromise(abortSignal)]) : reader.read());
|
|
1043
|
+
if (done) break;
|
|
1044
|
+
buffer += decoder.decode(value, { stream: true });
|
|
1045
|
+
const lines = buffer.split("\n");
|
|
1046
|
+
buffer = lines.pop() || "";
|
|
1047
|
+
for (const line of lines) {
|
|
1048
|
+
if (!line.trim()) continue;
|
|
1049
|
+
try {
|
|
1050
|
+
const jsonObject = JSON.parse(line);
|
|
1051
|
+
items.push(jsonObject);
|
|
1052
|
+
if (firstItem === null) {
|
|
1053
|
+
firstItem = jsonObject;
|
|
1054
|
+
const streamingPromise = continueStreaming(reader, decoder, buffer, items, store, abortSignal);
|
|
1055
|
+
return {
|
|
1056
|
+
firstItem,
|
|
1057
|
+
streamingPromise
|
|
1058
|
+
};
|
|
1059
|
+
}
|
|
1060
|
+
} catch (parseError) {
|
|
1061
|
+
throw new FragnoClientUnknownApiError("Failed to parse NDJSON line", 500, { cause: parseError });
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
if (firstItem === null) {
|
|
1066
|
+
reader.releaseLock();
|
|
1067
|
+
throw new FragnoClientUnknownApiError("NDJSON stream contained no valid items", 500);
|
|
1068
|
+
}
|
|
1069
|
+
reader.releaseLock();
|
|
1070
|
+
throw new FragnoClientFetchError("Unexpected end of stream processing", "NO_BODY");
|
|
1071
|
+
} catch (error) {
|
|
1072
|
+
if (error instanceof FragnoClientError) {
|
|
1073
|
+
store?.setError(error);
|
|
1074
|
+
throw error;
|
|
1075
|
+
} else {
|
|
1076
|
+
const clientError = new FragnoClientUnknownApiError("Unknown streaming error", 500, { cause: error });
|
|
1077
|
+
store?.setError(clientError);
|
|
1078
|
+
throw clientError;
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
/**
|
|
1083
|
+
* Continues streaming the remaining items in the background
|
|
1084
|
+
*/
|
|
1085
|
+
async function continueStreaming(reader, decoder, initialBuffer, items, store, abortSignal) {
|
|
1086
|
+
let buffer = initialBuffer;
|
|
1087
|
+
try {
|
|
1088
|
+
while (true) {
|
|
1089
|
+
if (abortSignal?.aborted) throw new FragnoClientFetchAbortError("Operation was aborted");
|
|
1090
|
+
const { done, value } = await (abortSignal ? Promise.race([reader.read(), createAbortPromise(abortSignal)]) : reader.read());
|
|
1091
|
+
if (done) {
|
|
1092
|
+
if (buffer.trim()) {
|
|
1093
|
+
const lines$1 = buffer.split("\n");
|
|
1094
|
+
for (const line of lines$1) {
|
|
1095
|
+
if (!line.trim()) continue;
|
|
1096
|
+
try {
|
|
1097
|
+
const jsonObject = JSON.parse(line);
|
|
1098
|
+
items.push(jsonObject);
|
|
1099
|
+
store?.setData([...items]);
|
|
1100
|
+
} catch (parseError) {
|
|
1101
|
+
throw new FragnoClientUnknownApiError("Failed to parse NDJSON line", 400, { cause: parseError });
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
break;
|
|
1106
|
+
}
|
|
1107
|
+
buffer += decoder.decode(value, { stream: true });
|
|
1108
|
+
const lines = buffer.split("\n");
|
|
1109
|
+
buffer = lines.pop() || "";
|
|
1110
|
+
for (const line of lines) {
|
|
1111
|
+
if (!line.trim()) continue;
|
|
1112
|
+
try {
|
|
1113
|
+
const jsonObject = JSON.parse(line);
|
|
1114
|
+
items.push(jsonObject);
|
|
1115
|
+
store?.setData([...items]);
|
|
1116
|
+
} catch (parseError) {
|
|
1117
|
+
throw new FragnoClientUnknownApiError("Failed to parse NDJSON line", 400, { cause: parseError });
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
} catch (error) {
|
|
1122
|
+
if (error instanceof FragnoClientError) store?.setError(error);
|
|
1123
|
+
else {
|
|
1124
|
+
const clientError = new FragnoClientUnknownApiError("Unknown streaming error", 400, { cause: error });
|
|
1125
|
+
store?.setError(clientError);
|
|
1126
|
+
throw clientError;
|
|
1127
|
+
}
|
|
1128
|
+
throw error;
|
|
1129
|
+
} finally {
|
|
1130
|
+
reader.releaseLock();
|
|
1131
|
+
}
|
|
1132
|
+
return items;
|
|
1115
1133
|
}
|
|
1116
1134
|
|
|
1117
1135
|
//#endregion
|
|
@@ -1130,7 +1148,7 @@ let createNanoEvents = () => ({
|
|
|
1130
1148
|
});
|
|
1131
1149
|
|
|
1132
1150
|
//#endregion
|
|
1133
|
-
//#region ../../node_modules/.pnpm/@nanostores+query@0.3.4_nanostores@1.
|
|
1151
|
+
//#region ../../node_modules/.pnpm/@nanostores+query@0.3.4_nanostores@1.2.0/node_modules/@nanostores/query/dist/nanoquery.js
|
|
1134
1152
|
function defaultOnErrorRetry({ retryCount }) {
|
|
1135
1153
|
return ~~((Math.random() + .5) * (1 << (retryCount < 8 ? retryCount : 8))) * 2e3;
|
|
1136
1154
|
}
|
|
@@ -1540,6 +1558,18 @@ function prepareRequestBody(body, contentType) {
|
|
|
1540
1558
|
headers: { "Content-Type": "application/json" }
|
|
1541
1559
|
};
|
|
1542
1560
|
}
|
|
1561
|
+
async function schemaAllowsUndefined(schema$1) {
|
|
1562
|
+
try {
|
|
1563
|
+
return !(await schema$1["~standard"].validate(void 0)).issues;
|
|
1564
|
+
} catch {
|
|
1565
|
+
return false;
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
async function assertBodyProvided(body, inputSchema, errorMessage) {
|
|
1569
|
+
if (typeof body !== "undefined" || inputSchema === void 0) return;
|
|
1570
|
+
if (await schemaAllowsUndefined(inputSchema)) return;
|
|
1571
|
+
throw new Error(errorMessage);
|
|
1572
|
+
}
|
|
1543
1573
|
/**
|
|
1544
1574
|
* Merge request headers from multiple sources.
|
|
1545
1575
|
* Returns undefined if there are no headers to merge.
|
|
@@ -1650,9 +1680,13 @@ var ClientBuilder = class {
|
|
|
1650
1680
|
get cacheEntries() {
|
|
1651
1681
|
return Object.fromEntries(this.#cache.entries());
|
|
1652
1682
|
}
|
|
1653
|
-
createStore(
|
|
1683
|
+
createStore(input) {
|
|
1684
|
+
if (typeof input === "function") return {
|
|
1685
|
+
factory: input,
|
|
1686
|
+
[STORE_SYMBOL]: true
|
|
1687
|
+
};
|
|
1654
1688
|
return {
|
|
1655
|
-
obj,
|
|
1689
|
+
obj: input,
|
|
1656
1690
|
[STORE_SYMBOL]: true
|
|
1657
1691
|
};
|
|
1658
1692
|
}
|
|
@@ -1685,7 +1719,7 @@ var ClientBuilder = class {
|
|
|
1685
1719
|
}
|
|
1686
1720
|
#getFetcher() {
|
|
1687
1721
|
if (this.#fetcherConfig?.type === "function") return this.#fetcherConfig.fetcher;
|
|
1688
|
-
return fetch;
|
|
1722
|
+
return globalThis.fetch.bind(globalThis);
|
|
1689
1723
|
}
|
|
1690
1724
|
#getFetcherOptions() {
|
|
1691
1725
|
if (this.#fetcherConfig?.type === "options") return this.#fetcherConfig.options;
|
|
@@ -1859,7 +1893,7 @@ var ClientBuilder = class {
|
|
|
1859
1893
|
const mutatorStore = this.#createMutatorStore(async ({ data }) => {
|
|
1860
1894
|
if (typeof window === "undefined") {}
|
|
1861
1895
|
const { body, path, query } = data;
|
|
1862
|
-
|
|
1896
|
+
await assertBodyProvided(body, route.inputSchema, "Body is required.");
|
|
1863
1897
|
const response = await executeMutateQuery({
|
|
1864
1898
|
body,
|
|
1865
1899
|
path,
|
|
@@ -1898,7 +1932,7 @@ var ClientBuilder = class {
|
|
|
1898
1932
|
} });
|
|
1899
1933
|
const mutateQuery = async (data) => {
|
|
1900
1934
|
const { body, path, query } = data;
|
|
1901
|
-
|
|
1935
|
+
await assertBodyProvided(body, route.inputSchema, "Body is required for mutateQuery");
|
|
1902
1936
|
const response = await executeMutateQuery({
|
|
1903
1937
|
body,
|
|
1904
1938
|
path,
|
|
@@ -1957,24 +1991,19 @@ function createClientBuilder(definition, publicConfig, routesOrFactories, author
|
|
|
1957
1991
|
}
|
|
1958
1992
|
|
|
1959
1993
|
//#endregion
|
|
1960
|
-
//#region src/
|
|
1961
|
-
|
|
1994
|
+
//#region src/database/schema.ts
|
|
1995
|
+
/**
|
|
1996
|
+
* Database schema for subscriptions that are linked to external stripe subscriptions.
|
|
1997
|
+
*/
|
|
1998
|
+
const stripeSchema = schema("stripe", (s) => {
|
|
1999
|
+
return s.addTable("subscription", (t) => {
|
|
2000
|
+
return t.addColumn("id", idColumn()).addColumn("referenceId", column("string").nullable()).addColumn("stripePriceId", column("string")).addColumn("stripeCustomerId", column("string")).addColumn("stripeSubscriptionId", column("string")).addColumn("status", column("string").defaultTo("incomplete")).addColumn("periodStart", column("timestamp").nullable()).addColumn("periodEnd", column("timestamp").nullable()).addColumn("trialStart", column("timestamp").nullable()).addColumn("trialEnd", column("timestamp").nullable()).addColumn("cancelAtPeriodEnd", column("bool").defaultTo(false)).addColumn("cancelAt", column("timestamp").nullable()).addColumn("seats", column("integer").nullable()).addColumn("createdAt", column("timestamp").defaultTo((b) => b.now())).addColumn("updatedAt", column("timestamp").defaultTo((b) => b.now())).createIndex("idx_stripe_customer_id", ["stripeCustomerId"]).createIndex("idx_stripe_subscription_id", ["stripeSubscriptionId"]).createIndex("idx_reference_id", ["referenceId"]);
|
|
2001
|
+
});
|
|
2002
|
+
});
|
|
1962
2003
|
|
|
1963
2004
|
//#endregion
|
|
1964
|
-
//#region src/
|
|
1965
|
-
const
|
|
1966
|
-
return [defineRoute({
|
|
1967
|
-
method: "POST",
|
|
1968
|
-
path: "/webhook",
|
|
1969
|
-
outputSchema: z.object({ success: z.boolean() }),
|
|
1970
|
-
errorCodes: [
|
|
1971
|
-
"MISSING_SIGNATURE",
|
|
1972
|
-
"WEBHOOK_SIGNATURE_INVALID",
|
|
1973
|
-
"WEBHOOK_ERROR"
|
|
1974
|
-
],
|
|
1975
|
-
handler: () => {}
|
|
1976
|
-
})];
|
|
1977
|
-
});
|
|
2005
|
+
//#region src/definition.ts
|
|
2006
|
+
const stripeFragmentDefinition = defineFragment("stripe").extend((x) => x).withDependencies(() => {}).providesBaseService(() => {}).build();
|
|
1978
2007
|
|
|
1979
2008
|
//#endregion
|
|
1980
2009
|
//#region src/models/customers.ts
|
|
@@ -2028,6 +2057,104 @@ const customersRoutesFactory = defineRoutes(stripeFragmentDefinition).create(({
|
|
|
2028
2057
|
})];
|
|
2029
2058
|
});
|
|
2030
2059
|
|
|
2060
|
+
//#endregion
|
|
2061
|
+
//#region src/models/prices.ts
|
|
2062
|
+
const PriceResponseSchema = z.object({
|
|
2063
|
+
id: z.string(),
|
|
2064
|
+
object: z.literal("price"),
|
|
2065
|
+
active: z.boolean(),
|
|
2066
|
+
billing_scheme: z.string(),
|
|
2067
|
+
created: z.number(),
|
|
2068
|
+
currency: z.string(),
|
|
2069
|
+
custom_unit_amount: z.any().nullable().optional(),
|
|
2070
|
+
deleted: z.void().optional(),
|
|
2071
|
+
livemode: z.boolean(),
|
|
2072
|
+
lookup_key: z.string().nullable().optional(),
|
|
2073
|
+
metadata: z.any(),
|
|
2074
|
+
nickname: z.string().nullable().optional(),
|
|
2075
|
+
product: z.union([z.string(), z.any()]),
|
|
2076
|
+
recurring: z.object({
|
|
2077
|
+
aggregate_usage: z.string().nullable().optional(),
|
|
2078
|
+
interval: z.enum([
|
|
2079
|
+
"day",
|
|
2080
|
+
"week",
|
|
2081
|
+
"month",
|
|
2082
|
+
"year"
|
|
2083
|
+
]),
|
|
2084
|
+
interval_count: z.number(),
|
|
2085
|
+
meter: z.string().nullable().optional(),
|
|
2086
|
+
trial_period_days: z.number().nullable().optional(),
|
|
2087
|
+
usage_type: z.string()
|
|
2088
|
+
}).nullable().optional(),
|
|
2089
|
+
tax_behavior: z.string().nullable().optional(),
|
|
2090
|
+
tiers_mode: z.string().nullable().optional(),
|
|
2091
|
+
transform_quantity: z.any().nullable().optional(),
|
|
2092
|
+
type: z.enum(["one_time", "recurring"]),
|
|
2093
|
+
unit_amount: z.number().nullable().optional(),
|
|
2094
|
+
unit_amount_decimal: z.string().nullable().optional()
|
|
2095
|
+
});
|
|
2096
|
+
|
|
2097
|
+
//#endregion
|
|
2098
|
+
//#region src/routes/prices.ts
|
|
2099
|
+
const pricesRoutesFactory = defineRoutes(stripeFragmentDefinition).create(({ deps, config, defineRoute }) => {
|
|
2100
|
+
return [defineRoute({
|
|
2101
|
+
method: "GET",
|
|
2102
|
+
path: "/admin/products/:productId/prices",
|
|
2103
|
+
inputSchema: z.object({
|
|
2104
|
+
limit: z.number().int().positive().max(100).optional().default(50).describe("Number of prices to return (max 100)"),
|
|
2105
|
+
startingAfter: z.string().optional().describe("Price ID to start after for pagination")
|
|
2106
|
+
}),
|
|
2107
|
+
outputSchema: z.object({
|
|
2108
|
+
prices: z.array(PriceResponseSchema),
|
|
2109
|
+
hasMore: z.boolean().describe("Whether there are more items to fetch")
|
|
2110
|
+
}),
|
|
2111
|
+
handler: () => {}
|
|
2112
|
+
})];
|
|
2113
|
+
});
|
|
2114
|
+
|
|
2115
|
+
//#endregion
|
|
2116
|
+
//#region src/models/products.ts
|
|
2117
|
+
const ProductResponseSchema = z.object({
|
|
2118
|
+
id: z.string(),
|
|
2119
|
+
object: z.literal("product"),
|
|
2120
|
+
active: z.boolean(),
|
|
2121
|
+
created: z.number(),
|
|
2122
|
+
default_price: z.union([z.string(), z.any()]).nullable().optional(),
|
|
2123
|
+
deleted: z.void().optional(),
|
|
2124
|
+
description: z.string().nullable(),
|
|
2125
|
+
images: z.array(z.string()),
|
|
2126
|
+
livemode: z.boolean(),
|
|
2127
|
+
marketing_features: z.array(z.any()),
|
|
2128
|
+
metadata: z.any(),
|
|
2129
|
+
name: z.string(),
|
|
2130
|
+
package_dimensions: z.any().nullable(),
|
|
2131
|
+
shippable: z.boolean().nullable(),
|
|
2132
|
+
statement_descriptor: z.string().nullable().optional(),
|
|
2133
|
+
tax_code: z.union([z.string(), z.any()]).nullable(),
|
|
2134
|
+
type: z.string(),
|
|
2135
|
+
unit_label: z.string().nullable().optional(),
|
|
2136
|
+
updated: z.number(),
|
|
2137
|
+
url: z.string().nullable()
|
|
2138
|
+
});
|
|
2139
|
+
|
|
2140
|
+
//#endregion
|
|
2141
|
+
//#region src/routes/products.ts
|
|
2142
|
+
const productsRoutesFactory = defineRoutes(stripeFragmentDefinition).create(({ deps, config, defineRoute }) => {
|
|
2143
|
+
return [defineRoute({
|
|
2144
|
+
method: "GET",
|
|
2145
|
+
path: "/admin/products",
|
|
2146
|
+
inputSchema: z.object({
|
|
2147
|
+
limit: z.number().int().positive().max(100).optional().default(50).describe("Number of products to return (max 100)"),
|
|
2148
|
+
startingAfter: z.string().optional().describe("Product ID to start after for pagination")
|
|
2149
|
+
}),
|
|
2150
|
+
outputSchema: z.object({
|
|
2151
|
+
products: z.array(ProductResponseSchema),
|
|
2152
|
+
hasMore: z.boolean().describe("Whether there are more items to fetch")
|
|
2153
|
+
}),
|
|
2154
|
+
handler: () => {}
|
|
2155
|
+
})];
|
|
2156
|
+
});
|
|
2157
|
+
|
|
2031
2158
|
//#endregion
|
|
2032
2159
|
//#region src/models/subscriptions.ts
|
|
2033
2160
|
const SubscriptionReponseSchema = z.object({
|
|
@@ -2073,6 +2200,7 @@ const subscriptionsRoutesFactory = defineRoutes(stripeFragmentDefinition).create
|
|
|
2073
2200
|
defineRoute({
|
|
2074
2201
|
method: "GET",
|
|
2075
2202
|
path: "/admin/subscriptions",
|
|
2203
|
+
errorCodes: ["UNAUTHORIZED"],
|
|
2076
2204
|
outputSchema: z.object({ subscriptions: z.array(SubscriptionReponseSchema) }),
|
|
2077
2205
|
handler: () => {}
|
|
2078
2206
|
}),
|
|
@@ -2122,99 +2250,17 @@ const subscriptionsRoutesFactory = defineRoutes(stripeFragmentDefinition).create
|
|
|
2122
2250
|
});
|
|
2123
2251
|
|
|
2124
2252
|
//#endregion
|
|
2125
|
-
//#region src/
|
|
2126
|
-
const
|
|
2127
|
-
id: z.string(),
|
|
2128
|
-
object: z.literal("product"),
|
|
2129
|
-
active: z.boolean(),
|
|
2130
|
-
created: z.number(),
|
|
2131
|
-
default_price: z.union([z.string(), z.any()]).nullable().optional(),
|
|
2132
|
-
deleted: z.void().optional(),
|
|
2133
|
-
description: z.string().nullable(),
|
|
2134
|
-
images: z.array(z.string()),
|
|
2135
|
-
livemode: z.boolean(),
|
|
2136
|
-
marketing_features: z.array(z.any()),
|
|
2137
|
-
metadata: z.any(),
|
|
2138
|
-
name: z.string(),
|
|
2139
|
-
package_dimensions: z.any().nullable(),
|
|
2140
|
-
shippable: z.boolean().nullable(),
|
|
2141
|
-
statement_descriptor: z.string().nullable().optional(),
|
|
2142
|
-
tax_code: z.union([z.string(), z.any()]).nullable(),
|
|
2143
|
-
type: z.string(),
|
|
2144
|
-
unit_label: z.string().nullable().optional(),
|
|
2145
|
-
updated: z.number(),
|
|
2146
|
-
url: z.string().nullable()
|
|
2147
|
-
});
|
|
2148
|
-
|
|
2149
|
-
//#endregion
|
|
2150
|
-
//#region src/routes/products.ts
|
|
2151
|
-
const productsRoutesFactory = defineRoutes(stripeFragmentDefinition).create(({ deps, config, defineRoute }) => {
|
|
2152
|
-
return [defineRoute({
|
|
2153
|
-
method: "GET",
|
|
2154
|
-
path: "/admin/products",
|
|
2155
|
-
inputSchema: z.object({
|
|
2156
|
-
limit: z.number().int().positive().max(100).optional().default(50).describe("Number of products to return (max 100)"),
|
|
2157
|
-
startingAfter: z.string().optional().describe("Product ID to start after for pagination")
|
|
2158
|
-
}),
|
|
2159
|
-
outputSchema: z.object({
|
|
2160
|
-
products: z.array(ProductResponseSchema),
|
|
2161
|
-
hasMore: z.boolean().describe("Whether there are more items to fetch")
|
|
2162
|
-
}),
|
|
2163
|
-
handler: () => {}
|
|
2164
|
-
})];
|
|
2165
|
-
});
|
|
2166
|
-
|
|
2167
|
-
//#endregion
|
|
2168
|
-
//#region src/models/prices.ts
|
|
2169
|
-
const PriceResponseSchema = z.object({
|
|
2170
|
-
id: z.string(),
|
|
2171
|
-
object: z.literal("price"),
|
|
2172
|
-
active: z.boolean(),
|
|
2173
|
-
billing_scheme: z.string(),
|
|
2174
|
-
created: z.number(),
|
|
2175
|
-
currency: z.string(),
|
|
2176
|
-
custom_unit_amount: z.any().nullable().optional(),
|
|
2177
|
-
deleted: z.void().optional(),
|
|
2178
|
-
livemode: z.boolean(),
|
|
2179
|
-
lookup_key: z.string().nullable().optional(),
|
|
2180
|
-
metadata: z.any(),
|
|
2181
|
-
nickname: z.string().nullable().optional(),
|
|
2182
|
-
product: z.union([z.string(), z.any()]),
|
|
2183
|
-
recurring: z.object({
|
|
2184
|
-
aggregate_usage: z.string().nullable().optional(),
|
|
2185
|
-
interval: z.enum([
|
|
2186
|
-
"day",
|
|
2187
|
-
"week",
|
|
2188
|
-
"month",
|
|
2189
|
-
"year"
|
|
2190
|
-
]),
|
|
2191
|
-
interval_count: z.number(),
|
|
2192
|
-
meter: z.string().nullable().optional(),
|
|
2193
|
-
trial_period_days: z.number().nullable().optional(),
|
|
2194
|
-
usage_type: z.string()
|
|
2195
|
-
}).nullable().optional(),
|
|
2196
|
-
tax_behavior: z.string().nullable().optional(),
|
|
2197
|
-
tiers_mode: z.string().nullable().optional(),
|
|
2198
|
-
transform_quantity: z.any().nullable().optional(),
|
|
2199
|
-
type: z.enum(["one_time", "recurring"]),
|
|
2200
|
-
unit_amount: z.number().nullable().optional(),
|
|
2201
|
-
unit_amount_decimal: z.string().nullable().optional()
|
|
2202
|
-
});
|
|
2203
|
-
|
|
2204
|
-
//#endregion
|
|
2205
|
-
//#region src/routes/prices.ts
|
|
2206
|
-
const pricesRoutesFactory = defineRoutes(stripeFragmentDefinition).create(({ deps, config, defineRoute }) => {
|
|
2253
|
+
//#region src/routes/webhooks.ts
|
|
2254
|
+
const webhookRoutesFactory = defineRoutes(stripeFragmentDefinition).create(({ config, deps, services, defineRoute }) => {
|
|
2207
2255
|
return [defineRoute({
|
|
2208
|
-
method: "
|
|
2209
|
-
path: "/
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
hasMore: z.boolean().describe("Whether there are more items to fetch")
|
|
2217
|
-
}),
|
|
2256
|
+
method: "POST",
|
|
2257
|
+
path: "/webhook",
|
|
2258
|
+
outputSchema: z.object({ success: z.boolean() }),
|
|
2259
|
+
errorCodes: [
|
|
2260
|
+
"MISSING_SIGNATURE",
|
|
2261
|
+
"WEBHOOK_SIGNATURE_INVALID",
|
|
2262
|
+
"WEBHOOK_ERROR"
|
|
2263
|
+
],
|
|
2218
2264
|
handler: () => {}
|
|
2219
2265
|
})];
|
|
2220
2266
|
});
|
|
@@ -2246,4 +2292,4 @@ function createStripeFragmentClients(fragnoConfig = {}) {
|
|
|
2246
2292
|
|
|
2247
2293
|
//#endregion
|
|
2248
2294
|
export { atom, createStripeFragment, createStripeFragmentClients, isGetHook, isMutatorHook, isReadableAtom, isStore, stripeFragmentDefinition };
|
|
2249
|
-
//# sourceMappingURL=src-
|
|
2295
|
+
//# sourceMappingURL=src-D6VWnvEs.js.map
|