@velastack/patterns 0.3.0 → 0.3.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/README.md +32 -2
- package/dist/chunks/_layout-B7ujvjnA.js +55 -0
- package/dist/chunks/_layout-B7ujvjnA.js.map +1 -0
- package/dist/chunks/{collections-CgdvZXmh.js → collections-UPqYto13.js} +2 -2
- package/dist/chunks/{collections-CgdvZXmh.js.map → collections-UPqYto13.js.map} +1 -1
- package/dist/chunks/{compose-handle-Cg9jnCsS.js → compose-handle-B-CkDcQD.js} +23 -23
- package/dist/chunks/{compose-handle-Cg9jnCsS.js.map → compose-handle-B-CkDcQD.js.map} +1 -1
- package/dist/chunks/config-target-Bln26FJe.js +164 -0
- package/dist/chunks/config-target-Bln26FJe.js.map +1 -0
- package/dist/chunks/errors-DR3gF_7a.js +18 -0
- package/dist/chunks/errors-DR3gF_7a.js.map +1 -0
- package/dist/chunks/{generate-DRA63W0r.js → generate-6snrlnpA.js} +2 -2
- package/dist/chunks/{generate-DRA63W0r.js.map → generate-6snrlnpA.js.map} +1 -1
- package/dist/chunks/{generate-BkQ1xMDp.js → generate-C6xi5S5L.js} +4 -4
- package/dist/chunks/{generate-BkQ1xMDp.js.map → generate-C6xi5S5L.js.map} +1 -1
- package/dist/chunks/{generate-tOkjJFUf.js → generate-CyuY2Ci7.js} +4 -3
- package/dist/chunks/generate-CyuY2Ci7.js.map +1 -0
- package/dist/chunks/{generate-iQP31-m1.js → generate-DHgKgHb7.js} +4 -4
- package/dist/chunks/{generate-iQP31-m1.js.map → generate-DHgKgHb7.js.map} +1 -1
- package/dist/chunks/{generate-_LvrYK6i.js → generate-jsB_oO0b.js} +4 -4
- package/dist/chunks/{generate-_LvrYK6i.js.map → generate-jsB_oO0b.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DAmYsIvF.js → generate.runtime-9R2AUKLS.js} +5 -5
- package/dist/chunks/{generate.runtime-DAmYsIvF.js.map → generate.runtime-9R2AUKLS.js.map} +1 -1
- package/dist/chunks/generate.runtime-B3yX6kl2.js +87 -0
- package/dist/chunks/generate.runtime-B3yX6kl2.js.map +1 -0
- package/dist/chunks/{generate.runtime-BKo-Nidn.js → generate.runtime-B7wkyj-8.js} +6 -6
- package/dist/chunks/{generate.runtime-BKo-Nidn.js.map → generate.runtime-B7wkyj-8.js.map} +1 -1
- package/dist/chunks/generate.runtime-BHf8p_3K.js +94 -0
- package/dist/chunks/generate.runtime-BHf8p_3K.js.map +1 -0
- package/dist/chunks/{generate.runtime-BbIN0tUZ.js → generate.runtime-BSFIwX58.js} +67 -66
- package/dist/chunks/generate.runtime-BSFIwX58.js.map +1 -0
- package/dist/chunks/{generate.runtime-BnWE4qsu.js → generate.runtime-Bb9CCwQm.js} +55 -54
- package/dist/chunks/generate.runtime-Bb9CCwQm.js.map +1 -0
- package/dist/chunks/{generate.runtime-D8vgh5MH.js → generate.runtime-BjciAjq7.js} +156 -76
- package/dist/chunks/generate.runtime-BjciAjq7.js.map +1 -0
- package/dist/chunks/{generate.runtime-BwhGDnGu.js → generate.runtime-BpTpRBdH.js} +151 -150
- package/dist/chunks/generate.runtime-BpTpRBdH.js.map +1 -0
- package/dist/chunks/{generate.runtime-D0icLb5j.js → generate.runtime-Brf08fMW.js} +11 -10
- package/dist/chunks/{generate.runtime-D0icLb5j.js.map → generate.runtime-Brf08fMW.js.map} +1 -1
- package/dist/chunks/{generate.runtime-S5RIgbQx.js → generate.runtime-C6DfW_NO.js} +98 -92
- package/dist/chunks/generate.runtime-C6DfW_NO.js.map +1 -0
- package/dist/chunks/{generate.runtime-DhkaXTq3.js → generate.runtime-C9fSqy6a.js} +61 -59
- package/dist/chunks/generate.runtime-C9fSqy6a.js.map +1 -0
- package/dist/chunks/{generate.runtime-CRYjWJRe.js → generate.runtime-CawvLUoV.js} +89 -88
- package/dist/chunks/generate.runtime-CawvLUoV.js.map +1 -0
- package/dist/chunks/{generate.runtime-DNaQxed-.js → generate.runtime-CzS7PuPN.js} +84 -83
- package/dist/chunks/generate.runtime-CzS7PuPN.js.map +1 -0
- package/dist/chunks/{generate.runtime-B0hhtyAL.js → generate.runtime-D1NZPV6C.js} +27 -26
- package/dist/chunks/generate.runtime-D1NZPV6C.js.map +1 -0
- package/dist/chunks/generate.runtime-D3baqo6a.js +111 -0
- package/dist/chunks/generate.runtime-D3baqo6a.js.map +1 -0
- package/dist/chunks/{generate.runtime-DSqkXvps.js → generate.runtime-D47djbeG.js} +15 -14
- package/dist/chunks/{generate.runtime-DSqkXvps.js.map → generate.runtime-D47djbeG.js.map} +1 -1
- package/dist/chunks/generate.runtime-D72UBiwD.js +313 -0
- package/dist/chunks/generate.runtime-D72UBiwD.js.map +1 -0
- package/dist/chunks/{generate.runtime-CcuAXuV2.js → generate.runtime-DDPoXmqN.js} +15 -14
- package/dist/chunks/{generate.runtime-CcuAXuV2.js.map → generate.runtime-DDPoXmqN.js.map} +1 -1
- package/dist/chunks/{generate.runtime-acRmiU7e.js → generate.runtime-DEnn0HKw.js} +9 -8
- package/dist/chunks/{generate.runtime-acRmiU7e.js.map → generate.runtime-DEnn0HKw.js.map} +1 -1
- package/dist/chunks/{generate.runtime-wA1G3tQ4.js → generate.runtime-DHXkw2gf.js} +38 -37
- package/dist/chunks/generate.runtime-DHXkw2gf.js.map +1 -0
- package/dist/chunks/{generate.runtime-DOuufRLr.js → generate.runtime-DIuCrH6l.js} +82 -81
- package/dist/chunks/generate.runtime-DIuCrH6l.js.map +1 -0
- package/dist/chunks/generate.runtime-DOB4U-Sa.js +57 -0
- package/dist/chunks/generate.runtime-DOB4U-Sa.js.map +1 -0
- package/dist/chunks/generate.runtime-DPAy7Cav.js +328 -0
- package/dist/chunks/generate.runtime-DPAy7Cav.js.map +1 -0
- package/dist/chunks/{generate.runtime-BORbegw_.js → generate.runtime-D_ZqiYt-.js} +123 -122
- package/dist/chunks/generate.runtime-D_ZqiYt-.js.map +1 -0
- package/dist/chunks/{generate.runtime-B49wetSx.js → generate.runtime-Dm7g_WTN.js} +43 -42
- package/dist/chunks/generate.runtime-Dm7g_WTN.js.map +1 -0
- package/dist/chunks/{generate.runtime-DoZdSh9W.js → generate.runtime-HE9rzfXz.js} +58 -57
- package/dist/chunks/generate.runtime-HE9rzfXz.js.map +1 -0
- package/dist/chunks/{generate.runtime-flFRYzpi.js → generate.runtime-ejrt1o6M.js} +62 -61
- package/dist/chunks/generate.runtime-ejrt1o6M.js.map +1 -0
- package/dist/chunks/generate.runtime-l6I-St2R.js +94 -0
- package/dist/chunks/generate.runtime-l6I-St2R.js.map +1 -0
- package/dist/chunks/modify-file-DGe7MJu_.js +46 -0
- package/dist/chunks/modify-file-DGe7MJu_.js.map +1 -0
- package/dist/chunks/{modify-svelte-config-remote-CDKs_Qi0.js → modify-svelte-config-remote-BUU_EaDf.js} +2 -2
- package/dist/chunks/{modify-svelte-config-remote-CDKs_Qi0.js.map → modify-svelte-config-remote-BUU_EaDf.js.map} +1 -1
- package/dist/chunks/{providers-DO9kMyzB.js → providers-BL9vJP_9.js} +2 -2
- package/dist/chunks/{providers-DO9kMyzB.js.map → providers-BL9vJP_9.js.map} +1 -1
- package/dist/chunks/{shared-BwHQM-a9.js → shared-DkGfltvn.js} +2 -2
- package/dist/chunks/{shared-BwHQM-a9.js.map → shared-DkGfltvn.js.map} +1 -1
- package/dist/chunks/{test-setup-B2hd8I-s.js → test-setup-DHEFKEHE.js} +23 -10
- package/dist/chunks/test-setup-DHEFKEHE.js.map +1 -0
- package/dist/chunks/ts-morph-helpers-CeduA--o.js +253 -0
- package/dist/chunks/ts-morph-helpers-CeduA--o.js.map +1 -0
- package/dist/chunks/{ui-B4Tuit-7.js → ui-B3-B3sE2.js} +3 -3
- package/dist/chunks/{ui-B4Tuit-7.js.map → ui-B3-B3sE2.js.map} +1 -1
- package/dist/chunks/{ui-jhXrsw4T.js → ui-DD4NltyN.js} +2 -2
- package/dist/chunks/{ui-jhXrsw4T.js.map → ui-DD4NltyN.js.map} +1 -1
- package/dist/chunks/unmodify-load-jfdcVZ_a.js +81 -0
- package/dist/chunks/unmodify-load-jfdcVZ_a.js.map +1 -0
- package/dist/chunks/write-result-DRwceOV3.js +452 -0
- package/dist/chunks/write-result-DRwceOV3.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +1920 -1903
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/chunks/_layout-DqH4lA_r.js +0 -47
- package/dist/chunks/_layout-DqH4lA_r.js.map +0 -1
- package/dist/chunks/config-target-Co-ij8p3.js +0 -163
- package/dist/chunks/config-target-Co-ij8p3.js.map +0 -1
- package/dist/chunks/errors-D6gyegUK.js +0 -14
- package/dist/chunks/errors-D6gyegUK.js.map +0 -1
- package/dist/chunks/generate-tOkjJFUf.js.map +0 -1
- package/dist/chunks/generate.runtime-B0hhtyAL.js.map +0 -1
- package/dist/chunks/generate.runtime-B49wetSx.js.map +0 -1
- package/dist/chunks/generate.runtime-B7LRx-BU.js +0 -86
- package/dist/chunks/generate.runtime-B7LRx-BU.js.map +0 -1
- package/dist/chunks/generate.runtime-BORbegw_.js.map +0 -1
- package/dist/chunks/generate.runtime-BbIN0tUZ.js.map +0 -1
- package/dist/chunks/generate.runtime-BnWE4qsu.js.map +0 -1
- package/dist/chunks/generate.runtime-BwhGDnGu.js.map +0 -1
- package/dist/chunks/generate.runtime-CCg2Pjcv.js +0 -257
- package/dist/chunks/generate.runtime-CCg2Pjcv.js.map +0 -1
- package/dist/chunks/generate.runtime-CRYjWJRe.js.map +0 -1
- package/dist/chunks/generate.runtime-D2e_KRj0.js +0 -56
- package/dist/chunks/generate.runtime-D2e_KRj0.js.map +0 -1
- package/dist/chunks/generate.runtime-D44gjxRA.js +0 -332
- package/dist/chunks/generate.runtime-D44gjxRA.js.map +0 -1
- package/dist/chunks/generate.runtime-D8vgh5MH.js.map +0 -1
- package/dist/chunks/generate.runtime-DNaQxed-.js.map +0 -1
- package/dist/chunks/generate.runtime-DOuufRLr.js.map +0 -1
- package/dist/chunks/generate.runtime-DhkaXTq3.js.map +0 -1
- package/dist/chunks/generate.runtime-DoZdSh9W.js.map +0 -1
- package/dist/chunks/generate.runtime-S5RIgbQx.js.map +0 -1
- package/dist/chunks/generate.runtime-WmSMWL15.js +0 -82
- package/dist/chunks/generate.runtime-WmSMWL15.js.map +0 -1
- package/dist/chunks/generate.runtime-flFRYzpi.js.map +0 -1
- package/dist/chunks/generate.runtime-gtpOuLNO.js +0 -110
- package/dist/chunks/generate.runtime-gtpOuLNO.js.map +0 -1
- package/dist/chunks/generate.runtime-kLxeDGnS.js +0 -93
- package/dist/chunks/generate.runtime-kLxeDGnS.js.map +0 -1
- package/dist/chunks/generate.runtime-wA1G3tQ4.js.map +0 -1
- package/dist/chunks/modify-file-GQD6uNgI.js +0 -254
- package/dist/chunks/modify-file-GQD6uNgI.js.map +0 -1
- package/dist/chunks/test-setup-B2hd8I-s.js.map +0 -1
- package/dist/chunks/unmodify-load-W1ePZQHr.js +0 -80
- package/dist/chunks/unmodify-load-W1ePZQHr.js.map +0 -1
- package/dist/chunks/write-result-DewHCNhM.js +0 -451
- package/dist/chunks/write-result-DewHCNhM.js.map +0 -1
|
@@ -3,111 +3,112 @@ import { t } from "./dedent-Gq6Krl4n.js";
|
|
|
3
3
|
import { t as n } from "./taggedTemplateLiteral-Dx0fjWiw.js";
|
|
4
4
|
import { n as r } from "./logger-CQONztPm.js";
|
|
5
5
|
import { t as i } from "./env-BPfk1VAw.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import f from "
|
|
11
|
-
import p from "node:
|
|
12
|
-
import
|
|
13
|
-
import _ from "
|
|
6
|
+
import { o as a, t as o } from "./ts-morph-helpers-CeduA--o.js";
|
|
7
|
+
import { modifyOutcomeToFile as s } from "./modify-file-DGe7MJu_.js";
|
|
8
|
+
import { t as c } from "./svelte-file-B3RfgVdt.js";
|
|
9
|
+
import { i as l, n as u, t as d } from "./pocketbase-CeG5BMN2.js";
|
|
10
|
+
import { createCollectionIdempotent as f } from "./collections-UPqYto13.js";
|
|
11
|
+
import p from "node:fs";
|
|
12
|
+
import m from "node:path";
|
|
13
|
+
import { Project as h, QuoteKind as g, SyntaxKind as _ } from "ts-morph";
|
|
14
|
+
import v from "stripe";
|
|
14
15
|
//#region src/patterns/enable/payments/modifies/modify-nav-user.ts
|
|
15
|
-
var
|
|
16
|
+
var y = [
|
|
16
17
|
"import CreditCardIcon from '@lucide/svelte/icons/credit-card';",
|
|
17
18
|
"",
|
|
18
19
|
"// Add to your navUser array:",
|
|
19
20
|
"{ title: 'Billing', url: '/billing', icon: CreditCardIcon }"
|
|
20
|
-
].join("\n"),
|
|
21
|
+
].join("\n"), b = [
|
|
21
22
|
"Add a Billing nav item to nav-user.svelte:",
|
|
22
23
|
"",
|
|
23
|
-
|
|
24
|
-
].join("\n"),
|
|
24
|
+
y
|
|
25
|
+
].join("\n"), x = [
|
|
25
26
|
"Create nav-user.svelte with a Billing entry:",
|
|
26
27
|
"",
|
|
27
|
-
|
|
28
|
+
y
|
|
28
29
|
].join("\n");
|
|
29
|
-
function
|
|
30
|
-
let a = new
|
|
31
|
-
|
|
30
|
+
function S(e, t, n, r, i) {
|
|
31
|
+
let a = new c(e), s = !1, l = (e) => {
|
|
32
|
+
s || e((e) => {
|
|
32
33
|
let a = o(e, t, n, r, i);
|
|
33
|
-
return a.wasAdded && (
|
|
34
|
+
return a.wasAdded && (s = !0), a.source;
|
|
34
35
|
});
|
|
35
36
|
};
|
|
36
|
-
return l((e) => a.modifyModuleScript(e)),
|
|
37
|
+
return l((e) => a.modifyModuleScript(e)), s || l((e) => a.modifyScript(e)), {
|
|
37
38
|
newNavUserSnippet: a.toString(),
|
|
38
|
-
wasAdded:
|
|
39
|
+
wasAdded: s
|
|
39
40
|
};
|
|
40
41
|
}
|
|
41
|
-
function
|
|
42
|
-
if (!
|
|
42
|
+
function C(e) {
|
|
43
|
+
if (!p.existsSync(e)) return {
|
|
43
44
|
status: "not-found",
|
|
44
|
-
message:
|
|
45
|
+
message: x
|
|
45
46
|
};
|
|
46
|
-
let t =
|
|
47
|
+
let t = p.readFileSync(e, "utf8");
|
|
47
48
|
if (t.includes("/billing")) return {
|
|
48
49
|
status: "success",
|
|
49
50
|
changed: !1
|
|
50
51
|
};
|
|
51
|
-
let { newNavUserSnippet: n, wasAdded: r } =
|
|
52
|
-
return r ? (
|
|
52
|
+
let { newNavUserSnippet: n, wasAdded: r } = S(t, "Billing", "/billing", "CreditCardIcon", "@lucide/svelte/icons/credit-card");
|
|
53
|
+
return r ? (p.writeFileSync(e, n, "utf8"), {
|
|
53
54
|
status: "success",
|
|
54
55
|
changed: !0
|
|
55
56
|
}) : {
|
|
56
57
|
status: "failed",
|
|
57
|
-
message:
|
|
58
|
+
message: b
|
|
58
59
|
};
|
|
59
60
|
}
|
|
60
61
|
//#endregion
|
|
61
62
|
//#region src/patterns/enable/payments/modifies/modify-user-signup.ts
|
|
62
|
-
var
|
|
63
|
+
var w = "$lib/workflows/link-stripe-customer", T = t`
|
|
63
64
|
// Queued here, done in the background: the Stripe calls retry on their own,
|
|
64
65
|
// and the key means a retry never makes a second customer for this user.
|
|
65
66
|
await linkStripeCustomer.run(
|
|
66
67
|
{ userId: user.id, email: form.data.email },
|
|
67
68
|
{ idempotencyKey: user.id }
|
|
68
69
|
);
|
|
69
|
-
`,
|
|
70
|
+
`, E = [
|
|
70
71
|
"Could not locate the requestVerification call in signup +page.server.ts.",
|
|
71
72
|
"Start the workflow once the user exists:",
|
|
72
73
|
"",
|
|
73
|
-
`import { linkStripeCustomer } from '${
|
|
74
|
+
`import { linkStripeCustomer } from '${w}';`,
|
|
74
75
|
"",
|
|
75
|
-
|
|
76
|
-
].join("\n"),
|
|
77
|
-
function
|
|
78
|
-
if (!
|
|
76
|
+
T
|
|
77
|
+
].join("\n"), D = ["Create src/routes/(public)/(auth)/signup/+page.server.ts before enabling payments."].join("\n");
|
|
78
|
+
function O(e) {
|
|
79
|
+
if (!p.existsSync(e)) return {
|
|
79
80
|
status: "not-found",
|
|
80
|
-
message:
|
|
81
|
+
message: D
|
|
81
82
|
};
|
|
82
|
-
let t =
|
|
83
|
+
let t = p.readFileSync(e, "utf8");
|
|
83
84
|
if (t.includes("linkStripeCustomer")) return {
|
|
84
85
|
status: "success",
|
|
85
86
|
changed: !1
|
|
86
87
|
};
|
|
87
|
-
let n = new
|
|
88
|
+
let n = new h({ manipulationSettings: { quoteKind: g.Single } }).addSourceFileAtPath(e), r = n.getDescendantsOfKind(_.CallExpression).find((e) => {
|
|
88
89
|
let t = e.getExpression();
|
|
89
|
-
return t.getKind() ===
|
|
90
|
+
return t.getKind() === _.PropertyAccessExpression && t.getText().includes("requestVerification");
|
|
90
91
|
});
|
|
91
92
|
if (!r) return {
|
|
92
93
|
status: "failed",
|
|
93
|
-
message:
|
|
94
|
+
message: E
|
|
94
95
|
};
|
|
95
|
-
let i = r.getFirstAncestorByKind(
|
|
96
|
+
let i = r.getFirstAncestorByKind(_.ExpressionStatement);
|
|
96
97
|
return i ? (n.addImportDeclaration({
|
|
97
98
|
namedImports: ["linkStripeCustomer"],
|
|
98
|
-
moduleSpecifier:
|
|
99
|
-
}), i.replaceWithText(
|
|
99
|
+
moduleSpecifier: w
|
|
100
|
+
}), i.replaceWithText(T + "\n\n" + i.getText()), a(n), n.saveSync(), {
|
|
100
101
|
status: "success",
|
|
101
102
|
changed: n.getFullText() !== t
|
|
102
103
|
}) : {
|
|
103
104
|
status: "failed",
|
|
104
|
-
message:
|
|
105
|
+
message: E
|
|
105
106
|
};
|
|
106
107
|
}
|
|
107
108
|
//#endregion
|
|
108
109
|
//#region src/patterns/enable/payments/runtime/stripe.ts
|
|
109
|
-
async function
|
|
110
|
-
let r = new
|
|
110
|
+
async function k(e, t, n) {
|
|
111
|
+
let r = new v(t), i = await e.collection("users").getFullList(), a = await e.collection("stripe_customers").getFullList(), o = new Set(a.map((e) => e.user)), s = {
|
|
111
112
|
total: i.length,
|
|
112
113
|
linked: o.size,
|
|
113
114
|
created: 0,
|
|
@@ -160,8 +161,8 @@ async function O(e, t, n) {
|
|
|
160
161
|
}
|
|
161
162
|
return s;
|
|
162
163
|
}
|
|
163
|
-
async function
|
|
164
|
-
let t = new
|
|
164
|
+
async function A(e) {
|
|
165
|
+
let t = new v(e), n = await t.products.search({
|
|
165
166
|
query: "name:\"Test Product\" AND metadata[\"test\"]:\"true\"",
|
|
166
167
|
limit: 1
|
|
167
168
|
});
|
|
@@ -191,8 +192,8 @@ async function k(e) {
|
|
|
191
192
|
existing: !1
|
|
192
193
|
};
|
|
193
194
|
}
|
|
194
|
-
async function
|
|
195
|
-
let n = new
|
|
195
|
+
async function j(e, t) {
|
|
196
|
+
let n = new v(e), r = await n.prices.retrieve(t, { expand: ["product"] }), i = typeof r.product == "string" ? await n.products.retrieve(r.product) : r.product;
|
|
196
197
|
return r.product = i.id, {
|
|
197
198
|
product: i,
|
|
198
199
|
price: r,
|
|
@@ -201,24 +202,24 @@ async function A(e, t) {
|
|
|
201
202
|
}
|
|
202
203
|
//#endregion
|
|
203
204
|
//#region src/patterns/enable/payments/generate.runtime.ts
|
|
204
|
-
var
|
|
205
|
-
async function
|
|
205
|
+
var M;
|
|
206
|
+
async function N(t, n, r, i, a = !0) {
|
|
206
207
|
if (!a) return;
|
|
207
|
-
await
|
|
208
|
-
let o =
|
|
208
|
+
await u();
|
|
209
|
+
let o = d(n, r, i);
|
|
209
210
|
o && t.push({
|
|
210
211
|
path: o,
|
|
211
212
|
language: e(o),
|
|
212
|
-
content:
|
|
213
|
+
content: p.readFileSync(o, "utf8"),
|
|
213
214
|
status: "success"
|
|
214
215
|
});
|
|
215
216
|
}
|
|
216
|
-
function
|
|
217
|
-
return t(
|
|
217
|
+
function P(e) {
|
|
218
|
+
return t(M ||= n(["\n <script lang=\"ts\">\n import PaymentButton from '$lib/components/payments/payment-button.svelte';\n <\/script>\n\n <section data-role=\"content\">\n <PaymentButton priceId=\"", "\" />\n </section>\n "]), e);
|
|
218
219
|
}
|
|
219
|
-
async function
|
|
220
|
-
let { stripeSecretKey: t, stripePublishableKey: n, stripeWebhookSecret:
|
|
221
|
-
e &&
|
|
220
|
+
async function F(e) {
|
|
221
|
+
let { stripeSecretKey: t, stripePublishableKey: n, stripeWebhookSecret: a, stripePriceId: o } = e.input, c = e.features.auth, u = r(e), d = [], p = [], h = (e) => {
|
|
222
|
+
e && p.push(e);
|
|
222
223
|
};
|
|
223
224
|
u.info("Writing Stripe credentials to .env");
|
|
224
225
|
let g = [
|
|
@@ -239,11 +240,11 @@ async function P(e) {
|
|
|
239
240
|
{
|
|
240
241
|
type: "var",
|
|
241
242
|
key: "STRIPE_WEBHOOK_SECRET",
|
|
242
|
-
value:
|
|
243
|
+
value: a
|
|
243
244
|
}
|
|
244
|
-
], _ =
|
|
245
|
-
h(
|
|
246
|
-
let r = (e) =>
|
|
245
|
+
], _ = m.join(e.root, ".env");
|
|
246
|
+
h(s(_, i(_, g))), await l(e.root, async (n) => {
|
|
247
|
+
let r = (e) => f(n, e, u);
|
|
247
248
|
u.info("Creating stripe_products collection");
|
|
248
249
|
let i = await r({
|
|
249
250
|
name: "stripe_products",
|
|
@@ -286,7 +287,7 @@ async function P(e) {
|
|
|
286
287
|
}
|
|
287
288
|
]
|
|
288
289
|
});
|
|
289
|
-
await
|
|
290
|
+
await N(d, "stripe_products", "created", e, i.created), u.info("Creating stripe_prices collection");
|
|
290
291
|
let a = await r({
|
|
291
292
|
name: "stripe_prices",
|
|
292
293
|
type: "base",
|
|
@@ -348,7 +349,7 @@ async function P(e) {
|
|
|
348
349
|
}
|
|
349
350
|
]
|
|
350
351
|
});
|
|
351
|
-
if (await
|
|
352
|
+
if (await N(d, "stripe_prices", "created", e, a.created), c) {
|
|
352
353
|
u.info("Creating stripe_customers collection");
|
|
353
354
|
let i = await r({
|
|
354
355
|
name: "stripe_customers",
|
|
@@ -384,7 +385,7 @@ async function P(e) {
|
|
|
384
385
|
}
|
|
385
386
|
]
|
|
386
387
|
}), a = i.collection;
|
|
387
|
-
await
|
|
388
|
+
await N(d, "stripe_customers", "created", e, i.created), u.info("Creating stripe_payment_methods collection");
|
|
388
389
|
let o = await r({
|
|
389
390
|
name: "stripe_payment_methods",
|
|
390
391
|
type: "base",
|
|
@@ -440,7 +441,7 @@ async function P(e) {
|
|
|
440
441
|
}
|
|
441
442
|
]
|
|
442
443
|
}), s = o.collection;
|
|
443
|
-
await
|
|
444
|
+
await N(d, "stripe_payment_methods", "created", e, o.created), u.info("Linking default_payment_method on stripe_customers"), await n.collections.update("stripe_customers", { fields: [
|
|
444
445
|
{
|
|
445
446
|
name: "id",
|
|
446
447
|
pattern: "^[a-zA-Z0-9_]+$",
|
|
@@ -477,7 +478,7 @@ async function P(e) {
|
|
|
477
478
|
onUpdate: !0,
|
|
478
479
|
type: "autodate"
|
|
479
480
|
}
|
|
480
|
-
] }), await
|
|
481
|
+
] }), await N(d, "stripe_customers", "updated", e), u.info("Creating transactions collection");
|
|
481
482
|
let c = await r({
|
|
482
483
|
name: "transactions",
|
|
483
484
|
type: "base",
|
|
@@ -548,13 +549,13 @@ async function P(e) {
|
|
|
548
549
|
}
|
|
549
550
|
]
|
|
550
551
|
});
|
|
551
|
-
await
|
|
552
|
-
let l = await
|
|
552
|
+
await N(d, "transactions", "created", e, c.created), u.info("Syncing existing PocketBase users to Stripe customers");
|
|
553
|
+
let l = await k(n, t, u);
|
|
553
554
|
u.info(`Synced ${l.total} users (created ${l.created}, reused ${l.reused}, skipped ${l.skipped})`);
|
|
554
555
|
}
|
|
555
|
-
}),
|
|
556
|
-
let { product: v, price: y, existing: b } =
|
|
557
|
-
if (b && u.info("Stripe product/price already exists, skipping creation"), u.info("Seeding Stripe product/price records"), await
|
|
556
|
+
}), o ? u.info(`Fetching Stripe product/price ${o}`) : u.info("Creating test Stripe product and price");
|
|
557
|
+
let { product: v, price: y, existing: b } = o ? await j(t, o) : await A(t);
|
|
558
|
+
if (b && u.info("Stripe product/price already exists, skipping creation"), u.info("Seeding Stripe product/price records"), await l(e.root, async (e) => {
|
|
558
559
|
try {
|
|
559
560
|
await e.collection("stripe_products").getOne(v.id);
|
|
560
561
|
} catch {
|
|
@@ -579,21 +580,21 @@ async function P(e) {
|
|
|
579
580
|
active: y.active
|
|
580
581
|
});
|
|
581
582
|
}
|
|
582
|
-
}), u.info("Creating payment +page.svelte"),
|
|
583
|
+
}), u.info("Creating payment +page.svelte"), d.push({
|
|
583
584
|
path: "src/routes/(public)/payment/+page.svelte",
|
|
584
585
|
language: "svelte",
|
|
585
|
-
content:
|
|
586
|
+
content: P(y.id),
|
|
586
587
|
status: "success"
|
|
587
|
-
}),
|
|
588
|
+
}), c) {
|
|
588
589
|
u.info("Modifying nav-user.svelte");
|
|
589
|
-
let t =
|
|
590
|
-
h(
|
|
591
|
-
let n =
|
|
592
|
-
h(
|
|
590
|
+
let t = m.join(e.root, "src", "lib", "components", "nav-user.svelte");
|
|
591
|
+
h(s(t, C(t))), u.info("Modifying signup +page.server.ts");
|
|
592
|
+
let n = m.join(e.root, "src", "routes", "(public)", "(auth)", "signup", "+page.server.ts");
|
|
593
|
+
h(s(n, O(n)));
|
|
593
594
|
}
|
|
594
595
|
return {
|
|
595
|
-
creates:
|
|
596
|
-
modifies:
|
|
596
|
+
creates: d,
|
|
597
|
+
modifies: p,
|
|
597
598
|
deletes: [],
|
|
598
599
|
components: [],
|
|
599
600
|
packages: [],
|
|
@@ -603,6 +604,6 @@ async function P(e) {
|
|
|
603
604
|
};
|
|
604
605
|
}
|
|
605
606
|
//#endregion
|
|
606
|
-
export {
|
|
607
|
+
export { F as generate };
|
|
607
608
|
|
|
608
|
-
//# sourceMappingURL=generate.runtime-
|
|
609
|
+
//# sourceMappingURL=generate.runtime-CzS7PuPN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.runtime-CzS7PuPN.js","names":[],"sources":["../../src/patterns/enable/payments/modifies/modify-nav-user.ts","../../src/patterns/enable/payments/modifies/modify-user-signup.ts","../../src/patterns/enable/payments/runtime/stripe.ts","../../src/patterns/enable/payments/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { addNavItemToScript } from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst BILLING_NAV_SNIPPET = [\n \"import CreditCardIcon from '@lucide/svelte/icons/credit-card';\",\n \"\",\n \"// Add to your navUser array:\",\n \"{ title: 'Billing', url: '/billing', icon: CreditCardIcon }\",\n].join(\"\\n\");\n\nconst FAILURE_HINT = [\n \"Add a Billing nav item to nav-user.svelte:\",\n \"\",\n BILLING_NAV_SNIPPET,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create nav-user.svelte with a Billing entry:\",\n \"\",\n BILLING_NAV_SNIPPET,\n].join(\"\\n\");\n\nexport function addItemToNavUser(\n navUserSnippet: string,\n title: string,\n url: string,\n icon: string,\n iconImportPath: string,\n): { newNavUserSnippet: string; wasAdded: boolean } {\n const file = new SvelteFile(navUserSnippet);\n let wasAdded = false;\n\n const tryAdd = (run: (fn: (s: string) => string) => boolean) => {\n if (wasAdded) return;\n run((source) => {\n const result = addNavItemToScript(\n source,\n title,\n url,\n icon,\n iconImportPath,\n );\n if (result.wasAdded) wasAdded = true;\n return result.source;\n });\n };\n\n tryAdd((fn) => file.modifyModuleScript(fn));\n if (!wasAdded) tryAdd((fn) => file.modifyScript(fn));\n\n return { newNavUserSnippet: file.toString(), wasAdded };\n}\n\nexport function modifyNavUser(navUserPath: string): ModifyOutcome {\n if (!fs.existsSync(navUserPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const navUserSnippet = fs.readFileSync(navUserPath, \"utf8\");\n if (navUserSnippet.includes(\"/billing\")) {\n return { status: \"success\", changed: false };\n }\n\n const { newNavUserSnippet, wasAdded } = addItemToNavUser(\n navUserSnippet,\n \"Billing\",\n \"/billing\",\n \"CreditCardIcon\",\n \"@lucide/svelte/icons/credit-card\",\n );\n\n if (!wasAdded) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n fs.writeFileSync(navUserPath, newNavUserSnippet, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst WORKFLOW_MODULE = \"$lib/workflows/link-stripe-customer\";\n\nconst RUN_SNIPPET = dedent`\n // Queued here, done in the background: the Stripe calls retry on their own,\n // and the key means a retry never makes a second customer for this user.\n await linkStripeCustomer.run(\n { userId: user.id, email: form.data.email },\n { idempotencyKey: user.id }\n );\n`;\n\nconst FAILURE_HINT = [\n \"Could not locate the requestVerification call in signup +page.server.ts.\",\n \"Start the workflow once the user exists:\",\n \"\",\n `import { linkStripeCustomer } from '${WORKFLOW_MODULE}';`,\n \"\",\n RUN_SNIPPET,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create src/routes/(public)/(auth)/signup/+page.server.ts before enabling payments.\",\n].join(\"\\n\");\n\n/**\n * Starts the link-stripe-customer workflow right after the user is created.\n * The work itself lives in src/lib/workflows/link-stripe-customer.ts.\n */\nexport function modifyUserSignup(userSignupPath: string): ModifyOutcome {\n if (!fs.existsSync(userSignupPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const originalSource = fs.readFileSync(userSignupPath, \"utf8\");\n if (originalSource.includes(\"linkStripeCustomer\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(userSignupPath);\n\n const requestVerificationCall = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => {\n const expr = ce.getExpression();\n return (\n expr.getKind() === SyntaxKind.PropertyAccessExpression &&\n expr.getText().includes(\"requestVerification\")\n );\n });\n\n if (!requestVerificationCall) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const statement = requestVerificationCall.getFirstAncestorByKind(\n SyntaxKind.ExpressionStatement,\n );\n\n if (!statement) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n sourceFile.addImportDeclaration({\n namedImports: [\"linkStripeCustomer\"],\n moduleSpecifier: WORKFLOW_MODULE,\n });\n\n statement.replaceWithText(RUN_SNIPPET + \"\\n\\n\" + statement.getText());\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n","import Stripe from \"stripe\";\nimport type PocketBase from \"pocketbase\";\nimport type { Logger } from \"../../../../core/logger\";\n\nexport interface StripeTestFixture {\n product: Stripe.Product;\n price: Stripe.Price;\n existing: boolean;\n}\n\nexport interface SyncUsersResult {\n total: number;\n linked: number;\n created: number;\n reused: number;\n skipped: number;\n}\n\nexport async function syncUsersToStripeCustomers(\n pb: PocketBase,\n stripeSecretKey: string,\n logger: Logger,\n): Promise<SyncUsersResult> {\n const stripe = new Stripe(stripeSecretKey);\n const users = await pb\n .collection(\"users\")\n .getFullList<{ id: string; email: string }>();\n\n const existing = await pb\n .collection(\"stripe_customers\")\n .getFullList<{ id: string; user: string }>();\n const linkedUserIds = new Set(existing.map((c) => c.user));\n\n const result: SyncUsersResult = {\n total: users.length,\n linked: linkedUserIds.size,\n created: 0,\n reused: 0,\n skipped: 0,\n };\n\n for (const user of users) {\n if (linkedUserIds.has(user.id)) {\n result.skipped += 1;\n continue;\n }\n\n if (!user.email) {\n logger.info(`Skipping user ${user.id} with no email`);\n result.skipped += 1;\n continue;\n }\n\n const matching = await stripe.customers.list({\n email: user.email,\n limit: 1,\n expand: [\"data.invoice_settings\"],\n });\n\n let customer: Stripe.Customer;\n let isExistingCustomer = false;\n\n if (matching.data.length > 0) {\n customer = matching.data[0];\n isExistingCustomer = true;\n result.reused += 1;\n logger.info(`Reusing Stripe customer ${customer.id} for ${user.email}`);\n } else {\n customer = await stripe.customers.create({ email: user.email });\n result.created += 1;\n logger.info(`Created Stripe customer ${customer.id} for ${user.email}`);\n }\n\n try {\n await pb.collection(\"stripe_customers\").create({\n id: customer.id,\n user: user.id,\n });\n } catch (error) {\n logger.info(\n `Failed to create stripe_customers row for ${user.email}: ${(error as Error).message}`,\n );\n continue;\n }\n\n if (!isExistingCustomer) {\n continue;\n }\n\n const paymentMethods = await stripe.customers.listPaymentMethods(\n customer.id,\n { type: \"card\", allow_redisplay: \"always\" },\n );\n\n for (const paymentMethod of paymentMethods.data) {\n if (paymentMethod.allow_redisplay === \"unspecified\") continue;\n try {\n await pb.collection(\"stripe_payment_methods\").create({\n id: paymentMethod.id,\n customer: customer.id,\n brand: paymentMethod.card?.brand,\n last4: paymentMethod.card?.last4,\n exp_month: paymentMethod.card?.exp_month,\n exp_year: paymentMethod.card?.exp_year,\n });\n } catch {}\n }\n\n const defaultPaymentMethod =\n customer.invoice_settings?.default_payment_method;\n if (defaultPaymentMethod) {\n try {\n await pb.collection(\"stripe_customers\").update(customer.id, {\n default_payment_method:\n typeof defaultPaymentMethod === \"string\"\n ? defaultPaymentMethod\n : defaultPaymentMethod.id,\n });\n } catch {}\n }\n }\n\n return result;\n}\n\nexport async function createTestProductAndPrice(\n stripeSecretKey: string,\n): Promise<StripeTestFixture> {\n const stripe = new Stripe(stripeSecretKey);\n\n const products = await stripe.products.search({\n query: `name:\"Test Product\" AND metadata[\"test\"]:\"true\"`,\n limit: 1,\n });\n\n if (products.data.length > 0) {\n const product = products.data[0];\n const prices = await stripe.prices.list({\n product: product.id,\n active: true,\n limit: 1,\n });\n if (prices.data.length > 0) {\n return { product, price: prices.data[0], existing: true };\n }\n }\n\n const product = await stripe.products.create({\n name: \"Test Product\",\n metadata: { test: \"true\" },\n });\n\n const price = await stripe.prices.create({\n product: product.id,\n unit_amount: 1000,\n currency: \"usd\",\n });\n\n return { product, price, existing: false };\n}\n\nexport async function getProductAndPriceById(\n stripeSecretKey: string,\n priceId: string,\n): Promise<StripeTestFixture> {\n const stripe = new Stripe(stripeSecretKey);\n const price = await stripe.prices.retrieve(priceId, { expand: [\"product\"] });\n const product =\n typeof price.product === \"string\"\n ? await stripe.products.retrieve(price.product)\n : (price.product as Stripe.Product);\n price.product = product.id;\n return { product, price, existing: true };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport dedent from \"dedent\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { languageFromPath } from \"../../../core/util\";\nimport {\n getMigrationFile,\n migrationDelay,\n withPocketbase,\n} from \"../../../runtime/pocketbase\";\nimport { createCollectionIdempotent } from \"../../../runtime/collections\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyNavUser } from \"./modifies/modify-nav-user\";\nimport { modifyUserSignup } from \"./modifies/modify-user-signup\";\nimport { modifyEnv, type EnvEdit } from \"./modifies/modify-env\";\nimport {\n createTestProductAndPrice,\n getProductAndPriceById,\n syncUsersToStripeCustomers,\n} from \"./runtime/stripe\";\n\nasync function pushMigrationCreates(\n creates: File[],\n collectionName: string,\n action: \"created\" | \"updated\",\n options: Options,\n created = true,\n) {\n if (!created) return;\n await migrationDelay();\n const migrationFile = getMigrationFile(collectionName, action, options);\n if (!migrationFile) return;\n creates.push({\n path: migrationFile,\n language: languageFromPath(migrationFile),\n content: fs.readFileSync(migrationFile, \"utf8\"),\n status: \"success\",\n });\n}\n\nfunction paymentPageSnippet(priceId: string): string {\n return dedent`\n <script lang=\"ts\">\n import PaymentButton from '$lib/components/payments/payment-button.svelte';\n </script>\n\n <section data-role=\"content\">\n <PaymentButton priceId=\"${priceId}\" />\n </section>\n `;\n}\n\nexport async function generate(options: Options) {\n const {\n stripeSecretKey,\n stripePublishableKey,\n stripeWebhookSecret,\n stripePriceId,\n } = options.input as {\n stripeSecretKey: string;\n stripePublishableKey: string;\n stripeWebhookSecret: string;\n stripePriceId?: string;\n };\n\n const isAppMode = options.features.auth;\n const logger = getLogger(options);\n const creates: File[] = [];\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Writing Stripe credentials to .env\");\n const envEdits: EnvEdit[] = [\n { type: \"comment\", key: \"Stripe credentials\" },\n { type: \"var\", key: \"STRIPE_SECRET_KEY\", value: stripeSecretKey },\n {\n type: \"var\",\n key: \"PUBLIC_STRIPE_PUBLISHABLE_KEY\",\n value: stripePublishableKey,\n },\n { type: \"var\", key: \"STRIPE_WEBHOOK_SECRET\", value: stripeWebhookSecret },\n ];\n\n const envPath = path.join(options.root, \".env\");\n pushResult(modifyOutcomeToFile(envPath, modifyEnv(envPath, envEdits)));\n\n await withPocketbase(options.root, async (pb) => {\n const create = (spec: Parameters<typeof createCollectionIdempotent>[1]) =>\n createCollectionIdempotent(pb, spec, logger);\n\n logger.info(\"Creating stripe_products collection\");\n const productsResult = await create({\n name: \"stripe_products\",\n type: \"base\",\n fields: [\n {\n name: \"id\",\n pattern: \"^[a-zA-Z0-9_]+$\",\n primaryKey: true,\n required: true,\n system: true,\n type: \"text\",\n },\n { name: \"name\", required: false, type: \"text\" },\n { name: \"active\", required: false, type: \"text\" },\n { name: \"default_price\", required: false, type: \"text\" },\n { name: \"created\", onCreate: true, onUpdate: false, type: \"autodate\" },\n { name: \"updated\", onCreate: true, onUpdate: true, type: \"autodate\" },\n ],\n });\n await pushMigrationCreates(\n creates,\n \"stripe_products\",\n \"created\",\n options,\n productsResult.created,\n );\n\n logger.info(\"Creating stripe_prices collection\");\n const pricesResult = await create({\n name: \"stripe_prices\",\n type: \"base\",\n fields: [\n {\n name: \"id\",\n pattern: \"^[a-zA-Z0-9_]+$\",\n primaryKey: true,\n required: true,\n system: true,\n type: \"text\",\n },\n { name: \"billing_scheme\", required: false, type: \"text\" },\n { name: \"currency\", required: false, type: \"text\" },\n { name: \"product\", required: false, type: \"text\" },\n { name: \"recurring\", required: false, type: \"json\" },\n { name: \"type\", required: false, type: \"text\" },\n { name: \"unit_amount\", required: false, type: \"number\" },\n { name: \"active\", required: false, type: \"bool\" },\n { name: \"created\", onCreate: true, onUpdate: false, type: \"autodate\" },\n { name: \"updated\", onCreate: true, onUpdate: true, type: \"autodate\" },\n ],\n });\n await pushMigrationCreates(\n creates,\n \"stripe_prices\",\n \"created\",\n options,\n pricesResult.created,\n );\n\n if (isAppMode) {\n logger.info(\"Creating stripe_customers collection\");\n const customersResult = await create({\n name: \"stripe_customers\",\n type: \"base\",\n fields: [\n {\n name: \"id\",\n pattern: \"^[a-zA-Z0-9_]+$\",\n primaryKey: true,\n required: true,\n system: true,\n type: \"text\",\n },\n {\n collectionId: \"_pb_users_auth_\",\n maxSelect: 1,\n minSelect: 0,\n name: \"user\",\n required: true,\n type: \"relation\",\n },\n {\n name: \"created\",\n onCreate: true,\n onUpdate: false,\n type: \"autodate\",\n },\n {\n name: \"updated\",\n onCreate: true,\n onUpdate: true,\n type: \"autodate\",\n },\n ],\n });\n const stripeCustomersCollection = customersResult.collection;\n await pushMigrationCreates(\n creates,\n \"stripe_customers\",\n \"created\",\n options,\n customersResult.created,\n );\n\n logger.info(\"Creating stripe_payment_methods collection\");\n const paymentMethodsResult = await create({\n name: \"stripe_payment_methods\",\n type: \"base\",\n fields: [\n {\n name: \"id\",\n pattern: \"^[a-zA-Z0-9_]+$\",\n primaryKey: true,\n required: true,\n system: true,\n type: \"text\",\n },\n { name: \"brand\", required: true, type: \"text\" },\n { name: \"last4\", required: true, type: \"text\" },\n { name: \"exp_month\", required: true, type: \"number\" },\n { name: \"exp_year\", required: true, type: \"number\" },\n {\n collectionId: stripeCustomersCollection.id,\n maxSelect: 1,\n minSelect: 0,\n name: \"customer\",\n required: true,\n type: \"relation\",\n cascadeDelete: true,\n },\n {\n name: \"created\",\n onCreate: true,\n onUpdate: false,\n type: \"autodate\",\n },\n {\n name: \"updated\",\n onCreate: true,\n onUpdate: true,\n type: \"autodate\",\n },\n ],\n });\n const stripePaymentMethodsCollection = paymentMethodsResult.collection;\n await pushMigrationCreates(\n creates,\n \"stripe_payment_methods\",\n \"created\",\n options,\n paymentMethodsResult.created,\n );\n\n logger.info(\"Linking default_payment_method on stripe_customers\");\n await pb.collections.update(\"stripe_customers\", {\n fields: [\n {\n name: \"id\",\n pattern: \"^[a-zA-Z0-9_]+$\",\n primaryKey: true,\n required: true,\n system: true,\n type: \"text\",\n },\n {\n collectionId: \"_pb_users_auth_\",\n maxSelect: 1,\n minSelect: 0,\n name: \"user\",\n required: true,\n type: \"relation\",\n },\n {\n collectionId: stripePaymentMethodsCollection.id,\n maxSelect: 1,\n minSelect: 0,\n name: \"default_payment_method\",\n required: false,\n type: \"relation\",\n },\n {\n name: \"created\",\n onCreate: true,\n onUpdate: false,\n type: \"autodate\",\n },\n {\n name: \"updated\",\n onCreate: true,\n onUpdate: true,\n type: \"autodate\",\n },\n ],\n });\n await pushMigrationCreates(\n creates,\n \"stripe_customers\",\n \"updated\",\n options,\n );\n\n logger.info(\"Creating transactions collection\");\n const transactionsResult = await create({\n name: \"transactions\",\n type: \"base\",\n fields: [\n {\n autogeneratePattern: \"[a-z0-9]{15}\",\n max: 15,\n min: 15,\n name: \"id\",\n pattern: \"^[a-z0-9]+$\",\n primaryKey: true,\n required: true,\n system: true,\n type: \"text\",\n },\n { name: \"stripe_payment_intent\", required: true, type: \"text\" },\n { name: \"amount\", required: true, type: \"number\" },\n { name: \"currency\", required: true, type: \"text\" },\n { name: \"last4\", required: true, type: \"text\" },\n { name: \"brand\", required: true, type: \"text\" },\n { name: \"created\", required: true, type: \"date\" },\n { name: \"stripe_charge\", required: true, type: \"text\" },\n { name: \"stripe_customer\", required: true, type: \"text\" },\n {\n collectionId: \"_pb_users_auth_\",\n maxSelect: 1,\n minSelect: 0,\n name: \"user\",\n required: true,\n type: \"relation\",\n },\n { name: \"receipt_url\", required: true, type: \"url\" },\n ],\n });\n await pushMigrationCreates(\n creates,\n \"transactions\",\n \"created\",\n options,\n transactionsResult.created,\n );\n\n logger.info(\"Syncing existing PocketBase users to Stripe customers\");\n const syncResult = await syncUsersToStripeCustomers(\n pb,\n stripeSecretKey,\n logger,\n );\n logger.info(\n `Synced ${syncResult.total} users (created ${syncResult.created}, reused ${syncResult.reused}, skipped ${syncResult.skipped})`,\n );\n }\n });\n\n if (stripePriceId) {\n logger.info(`Fetching Stripe product/price ${stripePriceId}`);\n } else {\n logger.info(\"Creating test Stripe product and price\");\n }\n const { product, price, existing } = stripePriceId\n ? await getProductAndPriceById(stripeSecretKey, stripePriceId)\n : await createTestProductAndPrice(stripeSecretKey);\n\n if (existing) {\n logger.info(\"Stripe product/price already exists, skipping creation\");\n }\n\n logger.info(\"Seeding Stripe product/price records\");\n await withPocketbase(options.root, async (pb) => {\n try {\n await pb.collection(\"stripe_products\").getOne(product.id);\n } catch (error) {\n await pb.collection(\"stripe_products\").create({\n id: product.id,\n name: product.name,\n active: product.active,\n default_price: product.default_price,\n });\n }\n\n try {\n await pb.collection(\"stripe_prices\").getOne(price.id);\n } catch (error) {\n await pb.collection(\"stripe_prices\").create({\n id: price.id,\n billing_scheme: price.billing_scheme,\n currency: price.currency,\n product: price.product,\n recurring: price.recurring,\n type: price.type,\n unit_amount: price.unit_amount,\n active: price.active,\n });\n }\n });\n\n logger.info(\"Creating payment +page.svelte\");\n creates.push({\n path: \"src/routes/(public)/payment/+page.svelte\",\n language: \"svelte\",\n content: paymentPageSnippet(price.id),\n status: \"success\",\n });\n\n if (isAppMode) {\n logger.info(\"Modifying nav-user.svelte\");\n const navUserPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"nav-user.svelte\",\n );\n pushResult(modifyOutcomeToFile(navUserPath, modifyNavUser(navUserPath)));\n\n logger.info(\"Modifying signup +page.server.ts\");\n const userSignupPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(public)\",\n \"(auth)\",\n \"signup\",\n \"+page.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(userSignupPath, modifyUserSignup(userSignupPath)),\n );\n }\n\n return {\n creates,\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAKA,IAAM,IAAsB;CAC1B;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI,GAEL,IAAe;CACnB;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI,GAEL,IAAiB;CACrB;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI;AAEX,SAAgB,EACd,GACA,GACA,GACA,GACA,GACkD;CAClD,IAAM,IAAO,IAAI,EAAW,CAAc,GACtC,IAAW,IAET,KAAU,MAAgD;EAC1D,KACJ,GAAK,MAAW;GACd,IAAM,IAAS,EACb,GACA,GACA,GACA,GACA,CACF;GAEA,OADI,EAAO,aAAU,IAAW,KACzB,EAAO;EAChB,CAAC;CACH;CAKA,OAHA,GAAQ,MAAO,EAAK,mBAAmB,CAAE,CAAC,GACrC,KAAU,GAAQ,MAAO,EAAK,aAAa,CAAE,CAAC,GAE5C;EAAE,mBAAmB,EAAK,SAAS;EAAG;CAAS;AACxD;AAEA,SAAgB,EAAc,GAAoC;CAChE,IAAI,CAAC,EAAG,WAAW,CAAW,GAC5B,OAAO;EAAE,QAAQ;EAAa,SAAS;CAAe;CAGxD,IAAM,IAAiB,EAAG,aAAa,GAAa,MAAM;CAC1D,IAAI,EAAe,SAAS,UAAU,GACpC,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,EAAE,sBAAmB,gBAAa,EACtC,GACA,WACA,YACA,kBACA,kCACF;CAOA,OALK,KAIL,EAAG,cAAc,GAAa,GAAmB,MAAM,GAChD;EAAE,QAAQ;EAAW,SAAS;CAAK,KAJjC;EAAE,QAAQ;EAAU,SAAS;CAAa;AAKrD;;;ACzEA,IAAM,IAAkB,uCAElB,IAAc,CAAM;;;;;;;GASpB,IAAe;CACnB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;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { t as e } from "./dedent-Gq6Krl4n.js";
|
|
2
2
|
import { n as t } from "./logger-CQONztPm.js";
|
|
3
|
-
import {
|
|
4
|
-
import r from "
|
|
5
|
-
import i from "node:
|
|
6
|
-
import
|
|
3
|
+
import { o as n } from "./ts-morph-helpers-CeduA--o.js";
|
|
4
|
+
import { modifyOutcomeToFile as r } from "./modify-file-DGe7MJu_.js";
|
|
5
|
+
import i from "node:fs";
|
|
6
|
+
import a from "node:path";
|
|
7
|
+
import { Project as o, QuoteKind as s } from "ts-morph";
|
|
7
8
|
//#region src/patterns/enable/workflows/modifies/hooks.server.ts
|
|
8
|
-
var
|
|
9
|
+
var c = e`
|
|
9
10
|
// Runs once when the server starts: executes the workflows in src/lib/workflows.
|
|
10
11
|
export const init: ServerInit = () => startWorker();
|
|
11
|
-
`,
|
|
12
|
+
`, l = e`
|
|
12
13
|
src/hooks.server.ts already exports an init hook. Start the workflow worker from it:
|
|
13
14
|
|
|
14
15
|
import { startWorker } from '$lib/server/workflows';
|
|
@@ -17,7 +18,7 @@ var s = e`
|
|
|
17
18
|
await startWorker();
|
|
18
19
|
// ...the rest of your init
|
|
19
20
|
};
|
|
20
|
-
`,
|
|
21
|
+
`, u = e`
|
|
21
22
|
Create src/hooks.server.ts and start the workflow worker from its init hook:
|
|
22
23
|
|
|
23
24
|
import type { ServerInit } from '@sveltejs/kit';
|
|
@@ -25,7 +26,7 @@ var s = e`
|
|
|
25
26
|
|
|
26
27
|
export const init: ServerInit = () => startWorker();
|
|
27
28
|
`;
|
|
28
|
-
function
|
|
29
|
+
function d(e, t, n, r = !1) {
|
|
29
30
|
let i = e.getImportDeclarations().find((e) => e.getModuleSpecifierValue() === t);
|
|
30
31
|
if (!i) {
|
|
31
32
|
e.addImportDeclaration({
|
|
@@ -40,39 +41,39 @@ function u(e, t, n, r = !1) {
|
|
|
40
41
|
isTypeOnly: !0
|
|
41
42
|
} : n);
|
|
42
43
|
}
|
|
43
|
-
function
|
|
44
|
+
function f(e) {
|
|
44
45
|
return e.getVariableDeclaration("init") || e.getFunction("init") ? !0 : e.getExportDeclarations().some((e) => e.getNamedExports().some((e) => e.getName() === "init"));
|
|
45
46
|
}
|
|
46
|
-
function
|
|
47
|
-
if (!
|
|
47
|
+
function p(e) {
|
|
48
|
+
if (!i.existsSync(e)) return {
|
|
48
49
|
status: "not-found",
|
|
49
|
-
message:
|
|
50
|
+
message: u
|
|
50
51
|
};
|
|
51
|
-
if (
|
|
52
|
+
if (i.readFileSync(e, "utf8").includes("startWorker")) return {
|
|
52
53
|
status: "success",
|
|
53
54
|
changed: !1
|
|
54
55
|
};
|
|
55
|
-
let t = new
|
|
56
|
+
let t = new o({
|
|
56
57
|
compilerOptions: { allowJs: !0 },
|
|
57
|
-
manipulationSettings: { quoteKind:
|
|
58
|
+
manipulationSettings: { quoteKind: s.Single }
|
|
58
59
|
}).addSourceFileAtPath(e);
|
|
59
|
-
return
|
|
60
|
+
return f(t) ? {
|
|
60
61
|
status: "failed",
|
|
61
|
-
message:
|
|
62
|
-
} : (
|
|
62
|
+
message: l
|
|
63
|
+
} : (d(t, "@sveltejs/kit", "ServerInit", !0), d(t, "$lib/server/workflows", "startWorker"), t.addStatements(`\n${c}`), n(t), t.saveSync(), {
|
|
63
64
|
status: "success",
|
|
64
65
|
changed: !0
|
|
65
66
|
});
|
|
66
67
|
}
|
|
67
68
|
//#endregion
|
|
68
69
|
//#region src/patterns/enable/workflows/generate.runtime.ts
|
|
69
|
-
async function
|
|
70
|
-
let
|
|
71
|
-
|
|
72
|
-
let o =
|
|
73
|
-
return s &&
|
|
70
|
+
async function m(e) {
|
|
71
|
+
let n = t(e), i = [];
|
|
72
|
+
n.info("Modifying hooks.server.ts");
|
|
73
|
+
let o = a.join(e.root, "src", "hooks.server.ts"), s = r(o, p(o));
|
|
74
|
+
return s && i.push(s), {
|
|
74
75
|
creates: [],
|
|
75
|
-
modifies:
|
|
76
|
+
modifies: i,
|
|
76
77
|
deletes: [],
|
|
77
78
|
components: [],
|
|
78
79
|
packages: [],
|
|
@@ -82,6 +83,6 @@ async function p(e) {
|
|
|
82
83
|
};
|
|
83
84
|
}
|
|
84
85
|
//#endregion
|
|
85
|
-
export {
|
|
86
|
+
export { m as generate };
|
|
86
87
|
|
|
87
|
-
//# sourceMappingURL=generate.runtime-
|
|
88
|
+
//# sourceMappingURL=generate.runtime-D1NZPV6C.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.runtime-D1NZPV6C.js","names":[],"sources":["../../src/patterns/enable/workflows/modifies/hooks.server.ts","../../src/patterns/enable/workflows/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, type SourceFile } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst INIT_SNIPPET = dedent`\n // Runs once when the server starts: executes the workflows in src/lib/workflows.\n export const init: ServerInit = () => startWorker();\n`;\n\nconst FAILURE_HINT = dedent`\n src/hooks.server.ts already exports an init hook. Start the workflow worker from it:\n\n import { startWorker } from '$lib/server/workflows';\n\n export const init: ServerInit = async () => {\n await startWorker();\n // ...the rest of your init\n };\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create src/hooks.server.ts and start the workflow worker from its init hook:\n\n import type { ServerInit } from '@sveltejs/kit';\n import { startWorker } from '$lib/server/workflows';\n\n export const init: ServerInit = () => startWorker();\n`;\n\nfunction ensureNamedImport(\n sourceFile: SourceFile,\n moduleSpecifier: string,\n name: string,\n typeOnly = false,\n) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === moduleSpecifier);\n if (!existing) {\n sourceFile.addImportDeclaration({\n isTypeOnly: typeOnly,\n namedImports: [name],\n moduleSpecifier,\n });\n return;\n }\n if (existing.getNamedImports().some((ni) => ni.getName() === name)) return;\n // A declaration that is already `import type` covers the new name; a value\n // import takes the name as an inline `type` specifier.\n existing.addNamedImport(\n typeOnly && !existing.isTypeOnly() ? { name, isTypeOnly: true } : name,\n );\n}\n\nfunction hasInitExport(sourceFile: SourceFile): boolean {\n if (sourceFile.getVariableDeclaration(\"init\")) return true;\n if (sourceFile.getFunction(\"init\")) return true;\n return sourceFile\n .getExportDeclarations()\n .some((d) => d.getNamedExports().some((e) => e.getName() === \"init\"));\n}\n\n/**\n * Adds the `init` hook that starts the workflow worker. Projects created from\n * the base template already have it; this is the upgrade path for older ones.\n */\nexport function modifyHooksServerWorkflows(\n hooksServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n if (original.includes(\"startWorker\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n if (hasInitExport(sourceFile)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n ensureNamedImport(sourceFile, \"@sveltejs/kit\", \"ServerInit\", true);\n ensureNamedImport(sourceFile, \"$lib/server/workflows\", \"startWorker\");\n\n // After everything else, so the hook reads as the last thing the server does on start.\n sourceFile.addStatements(`\\n${INIT_SNIPPET}`);\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyHooksServerWorkflows } from \"./modifies/hooks.server\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n const hooksFile = modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServerWorkflows(hooksServerPath),\n );\n if (hooksFile) modifies.push(hooksFile);\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;AAMA,IAAM,IAAe,CAAM;;;GAKrB,IAAe,CAAM;;;;;;;;;GAWrB,IAAiB,CAAM;;;;;;;;AAS7B,SAAS,EACP,GACA,GACA,GACA,IAAW,IACX;CACA,IAAM,IAAW,EACd,sBAAsB,CAAC,CACvB,MAAM,MAAM,EAAE,wBAAwB,MAAM,CAAe;CAC9D,IAAI,CAAC,GAAU;EACb,EAAW,qBAAqB;GAC9B,YAAY;GACZ,cAAc,CAAC,CAAI;GACnB;EACF,CAAC;EACD;CACF;CACI,EAAS,gBAAgB,CAAC,CAAC,MAAM,MAAO,EAAG,QAAQ,MAAM,CAAI,KAGjE,EAAS,eACP,KAAY,CAAC,EAAS,WAAW,IAAI;EAAE;EAAM,YAAY;CAAK,IAAI,CACpE;AACF;AAEA,SAAS,EAAc,GAAiC;CAGtD,OAFI,EAAW,uBAAuB,MAAM,KACxC,EAAW,YAAY,MAAM,IAAU,KACpC,EACJ,sBAAsB,CAAC,CACvB,MAAM,MAAM,EAAE,gBAAgB,CAAC,CAAC,MAAM,MAAM,EAAE,QAAQ,MAAM,MAAM,CAAC;AACxE;AAMA,SAAgB,EACd,GACe;CACf,IAAI,CAAC,EAAG,WAAW,CAAe,GAChC,OAAO;EAAE,QAAQ;EAAa,SAAS;CAAe;CAIxD,IADiB,EAAG,aAAa,GAAiB,MAC9C,CAAA,CAAS,SAAS,aAAa,GACjC,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAO7C,IAAM,IAAa,IAJC,EAAQ;EAC1B,iBAAiB,EAAE,SAAS,GAAK;EACjC,sBAAsB,EAAE,WAAW,EAAU,OAAO;CACtD,CACmB,CAAA,CAAQ,oBAAoB,CAAe;CAc9D,OAZI,EAAc,CAAU,IACnB;EAAE,QAAQ;EAAU,SAAS;CAAa,KAGnD,EAAkB,GAAY,iBAAiB,cAAc,EAAI,GACjE,EAAkB,GAAY,yBAAyB,aAAa,GAGpE,EAAW,cAAc,KAAK,GAAc,GAE5C,EAAiB,CAAU,GAC3B,EAAW,SAAS,GACb;EAAE,QAAQ;EAAW,SAAS;CAAK;AAC5C;;;AC7FA,eAAsB,EAAS,GAAkB;CAC/C,IAAM,IAAS,EAAU,CAAO,GAC1B,IAAmB,CAAC;CAE1B,EAAO,KAAK,2BAA2B;CACvC,IAAM,IAAkB,EAAK,KAAK,EAAQ,MAAM,OAAO,iBAAiB,GAClE,IAAY,EAChB,GACA,EAA2B,CAAe,CAC5C;CAGA,OAFI,KAAW,EAAS,KAAK,CAAS,GAE/B;EACL,SAAS,CAAC;EACV;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { n as e } from "./logger-CQONztPm.js";
|
|
2
|
+
import { t } from "./shared-DkGfltvn.js";
|
|
3
|
+
import { _ as n, g as r, n as i, o as a, p as o, u as s } from "./ts-morph-helpers-CeduA--o.js";
|
|
4
|
+
import { modifyOutcomeToFile as c } from "./modify-file-DGe7MJu_.js";
|
|
5
|
+
import { t as l } from "./svelte-file-B3RfgVdt.js";
|
|
6
|
+
import u from "node:fs";
|
|
7
|
+
import d from "node:path";
|
|
8
|
+
import { Project as f, SyntaxKind as p } from "ts-morph";
|
|
9
|
+
//#region src/patterns/disable/auth/modifies/+layout.server.ts
|
|
10
|
+
function m(e) {
|
|
11
|
+
if (!u.existsSync(e)) return {
|
|
12
|
+
status: "success",
|
|
13
|
+
changed: !1
|
|
14
|
+
};
|
|
15
|
+
let t = u.readFileSync(e, "utf8");
|
|
16
|
+
if (!t.includes("locals.pb.authStore.record")) return {
|
|
17
|
+
status: "success",
|
|
18
|
+
changed: !1
|
|
19
|
+
};
|
|
20
|
+
let n = new f().addSourceFileAtPath(e), i = n.getDescendantsOfKind(p.ObjectLiteralExpression);
|
|
21
|
+
for (let e of i) {
|
|
22
|
+
let t = e.getProperty("user");
|
|
23
|
+
t && t.getKind() === p.PropertyAssignment && t.getInitializer()?.getText() === "locals.pb.authStore.record" && t.remove();
|
|
24
|
+
}
|
|
25
|
+
return r(n, "locals"), a(n), n.saveSync(), {
|
|
26
|
+
status: "success",
|
|
27
|
+
changed: n.getFullText() !== t
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/patterns/disable/auth/modifies/root-layout.svelte.ts
|
|
32
|
+
function h(e) {
|
|
33
|
+
if (!u.existsSync(e)) return {
|
|
34
|
+
status: "success",
|
|
35
|
+
changed: !1
|
|
36
|
+
};
|
|
37
|
+
let t = u.readFileSync(e, "utf8"), r = new l(t);
|
|
38
|
+
if (!r.hasElement("AuthMenu.Root")) return {
|
|
39
|
+
status: "success",
|
|
40
|
+
changed: !1
|
|
41
|
+
};
|
|
42
|
+
r.removeElement("AuthMenu.Root");
|
|
43
|
+
let a = r.toString().replace(/<script[\s\S]*?<\/script>/g, "");
|
|
44
|
+
return r.modifyScript((e) => {
|
|
45
|
+
let { source: t } = n(e, (e) => {
|
|
46
|
+
s(e, "$lib/components/ui/auth-menu"), s(e, "$lib/components/ui/avatar"), o(e, "data", a), i(e);
|
|
47
|
+
});
|
|
48
|
+
return t;
|
|
49
|
+
}), r.writeTo(e), {
|
|
50
|
+
status: "success",
|
|
51
|
+
changed: r.hasChanged()
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/patterns/disable/auth/modifies/hooks.server.ts
|
|
56
|
+
function g(e) {
|
|
57
|
+
if (!u.existsSync(e)) return {
|
|
58
|
+
status: "success",
|
|
59
|
+
changed: !1
|
|
60
|
+
};
|
|
61
|
+
let t = u.readFileSync(e, "utf8"), n = new f().addSourceFileAtPath(e), r = n.getDescendantsOfKind(p.CallExpression).find((e) => e.getExpression().getText() === "handlePocketbase");
|
|
62
|
+
if (!r) return {
|
|
63
|
+
status: "success",
|
|
64
|
+
changed: !1
|
|
65
|
+
};
|
|
66
|
+
let [i] = r.getArguments();
|
|
67
|
+
if (!i || i.getKind() !== p.ObjectLiteralExpression) return {
|
|
68
|
+
status: "success",
|
|
69
|
+
changed: !1
|
|
70
|
+
};
|
|
71
|
+
let o = i.asKindOrThrow(p.ObjectLiteralExpression), s = o.getProperty("auth");
|
|
72
|
+
return s ? (s.remove(), o.getProperties().length === 0 && r.removeArgument(0), a(n), n.saveSync(), {
|
|
73
|
+
status: "success",
|
|
74
|
+
changed: n.getFullText() !== t
|
|
75
|
+
}) : {
|
|
76
|
+
status: "success",
|
|
77
|
+
changed: !1
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/patterns/disable/auth/generate.runtime.ts
|
|
82
|
+
async function _(n) {
|
|
83
|
+
let r = e(n), i = [], a = (e) => {
|
|
84
|
+
e && i.push(e);
|
|
85
|
+
};
|
|
86
|
+
r.info("Reverting +layout.server.ts");
|
|
87
|
+
let o = d.join(n.root, "src", "routes", "+layout.server.ts");
|
|
88
|
+
a(c(o, m(o))), r.info("Reverting root layout");
|
|
89
|
+
let s = [
|
|
90
|
+
d.join(n.root, "src", "routes", "(public)", "root-layout.svelte"),
|
|
91
|
+
d.join(n.root, "src", "routes", "root-layout.svelte"),
|
|
92
|
+
d.join(n.root, "src", "routes", "(public)", "+layout.svelte"),
|
|
93
|
+
d.join(n.root, "src", "routes", "+layout.svelte")
|
|
94
|
+
], l = s.find((e) => u.existsSync(e)) ?? s[0];
|
|
95
|
+
a(c(l, h(l))), r.info("Reverting hooks.server.ts");
|
|
96
|
+
let f = d.join(n.root, "src", "hooks.server.ts");
|
|
97
|
+
return a(c(f, g(f))), {
|
|
98
|
+
creates: [],
|
|
99
|
+
modifies: i,
|
|
100
|
+
deletes: [],
|
|
101
|
+
components: [],
|
|
102
|
+
packages: [],
|
|
103
|
+
collections: [],
|
|
104
|
+
collectionPatches: [],
|
|
105
|
+
collectionDrops: await t(["oauth_accounts"], n)
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
export { _ as generate };
|
|
110
|
+
|
|
111
|
+
//# sourceMappingURL=generate.runtime-D3baqo6a.js.map
|