@velastack/patterns 0.0.35 → 0.0.36
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/chunks/{collections-DRN-8nW0.js → collections-DcCZ0dam.js} +73 -5
- package/dist/chunks/collections-DcCZ0dam.js.map +1 -0
- package/dist/chunks/env-DfA_NCKk.js +67 -0
- package/dist/chunks/env-DfA_NCKk.js.map +1 -0
- package/dist/chunks/{env.preview-BZwjhgoi.js → env.preview-7Cc9KCgc.js} +1 -1
- package/dist/chunks/{env.preview-BZwjhgoi.js.map → env.preview-7Cc9KCgc.js.map} +1 -1
- package/dist/chunks/{env.runtime-BEdollKV.js → env.runtime-l1ssTZog.js} +1 -1
- package/dist/chunks/{env.runtime-BEdollKV.js.map → env.runtime-l1ssTZog.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Caqa5ndO.js → generate.runtime-BB0XISiq.js} +4 -3
- package/dist/chunks/{generate.runtime-Caqa5ndO.js.map → generate.runtime-BB0XISiq.js.map} +1 -1
- package/dist/chunks/generate.runtime-Bag8x62P.js +37 -0
- package/dist/chunks/generate.runtime-Bag8x62P.js.map +1 -0
- package/dist/chunks/generate.runtime-Bu5bO86n.js +60 -0
- package/dist/chunks/generate.runtime-Bu5bO86n.js.map +1 -0
- package/dist/chunks/{generate.runtime-DTZ1PeDS.js → generate.runtime-CKouBODu.js} +27 -26
- package/dist/chunks/{generate.runtime-DTZ1PeDS.js.map → generate.runtime-CKouBODu.js.map} +1 -1
- package/dist/chunks/{generate.runtime-D7ksYerH.js → generate.runtime-CS55berV.js} +7 -6
- package/dist/chunks/{generate.runtime-D7ksYerH.js.map → generate.runtime-CS55berV.js.map} +1 -1
- package/dist/chunks/generate.runtime-CVsBIZm4.js +37 -0
- package/dist/chunks/generate.runtime-CVsBIZm4.js.map +1 -0
- package/dist/chunks/{generate.runtime--31y_UK2.js → generate.runtime-Cy56Ypws.js} +27 -26
- package/dist/chunks/{generate.runtime--31y_UK2.js.map → generate.runtime-Cy56Ypws.js.map} +1 -1
- package/dist/chunks/generate.runtime-D3H_yNZA.js +210 -0
- package/dist/chunks/generate.runtime-D3H_yNZA.js.map +1 -0
- package/dist/chunks/generate.runtime-D8DxU99S.js +93 -0
- package/dist/chunks/generate.runtime-D8DxU99S.js.map +1 -0
- package/dist/chunks/generate.runtime-DPbHzukR.js +116 -0
- package/dist/chunks/generate.runtime-DPbHzukR.js.map +1 -0
- package/dist/chunks/{generate.runtime-BVss5za4.js → generate.runtime-DV9S4KW_.js} +106 -131
- package/dist/chunks/generate.runtime-DV9S4KW_.js.map +1 -0
- package/dist/chunks/generate.runtime-GmszNklA.js +56 -0
- package/dist/chunks/generate.runtime-GmszNklA.js.map +1 -0
- package/dist/chunks/generate.runtime-NdlYevoh.js +65 -0
- package/dist/chunks/generate.runtime-NdlYevoh.js.map +1 -0
- package/dist/chunks/{generate.runtime-Cbq2649r.js → generate.runtime-eYyscad0.js} +29 -28
- package/dist/chunks/{generate.runtime-Cbq2649r.js.map → generate.runtime-eYyscad0.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CZKIdbEC.js → generate.runtime-mPNuFTCh.js} +54 -53
- package/dist/chunks/{generate.runtime-CZKIdbEC.js.map → generate.runtime-mPNuFTCh.js.map} +1 -1
- package/dist/chunks/hooks.server-CPVyj3rv.js +75 -0
- package/dist/chunks/hooks.server-CPVyj3rv.js.map +1 -0
- package/dist/chunks/{modify-file-DT_1_kvI.js → modify-file-Bi-4GRwL.js} +2 -2
- package/dist/chunks/{modify-file-DT_1_kvI.js.map → modify-file-Bi-4GRwL.js.map} +1 -1
- package/dist/chunks/{modify-svelte-config-remote-CFsA9Mom.js → modify-svelte-config-remote-B-jnjYqs.js} +1 -1
- package/dist/chunks/{modify-svelte-config-remote-CFsA9Mom.js.map → modify-svelte-config-remote-B-jnjYqs.js.map} +1 -1
- package/dist/chunks/{pocketbase-iFJBbNJu.js → pocketbase-CT78tKFG.js} +1 -1
- package/dist/chunks/{pocketbase-iFJBbNJu.js.map → pocketbase-CT78tKFG.js.map} +1 -1
- package/dist/chunks/shared-D9iYuKxV.js +27 -0
- package/dist/chunks/shared-D9iYuKxV.js.map +1 -0
- package/dist/chunks/{ts-morph-helpers-C0HeJDjR.js → ts-morph-helpers-B0oxeDUU.js} +47 -3
- package/dist/chunks/ts-morph-helpers-B0oxeDUU.js.map +1 -0
- package/dist/chunks/{util-C064WO8o.js → util-CLl3VxaE.js} +4 -3
- package/dist/chunks/util-CLl3VxaE.js.map +1 -0
- package/dist/chunks/{write-result-CqSY1Bww.js → write-result-CRq0kUvL.js} +12 -7
- package/dist/chunks/{write-result-CqSY1Bww.js.map → write-result-CRq0kUvL.js.map} +1 -1
- package/dist/index.d.ts +912 -209
- package/dist/index.js +1868 -871
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/collections-DRN-8nW0.js.map +0 -1
- package/dist/chunks/generate.runtime-BVss5za4.js.map +0 -1
- package/dist/chunks/ts-morph-helpers-C0HeJDjR.js.map +0 -1
- package/dist/chunks/util-C064WO8o.js.map +0 -1
|
@@ -1,65 +1,66 @@
|
|
|
1
1
|
import { t as e } from "./dedent-C4qKBQXh.js";
|
|
2
|
-
import { n as t } from "./util-
|
|
2
|
+
import { n as t } from "./util-CLl3VxaE.js";
|
|
3
3
|
import { t as n } from "./taggedTemplateLiteral-Bfbldyfk.js";
|
|
4
4
|
import { n as r } from "./logger-BpgCb-ZG.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import d from "
|
|
10
|
-
import f from "node:
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
import _ from "
|
|
5
|
+
import { modifyOutcomeToFile as i } from "./modify-file-Bi-4GRwL.js";
|
|
6
|
+
import { o as a, t as o } from "./ts-morph-helpers-B0oxeDUU.js";
|
|
7
|
+
import { t as s } from "./env-DfA_NCKk.js";
|
|
8
|
+
import { getMigrationFile as c, migrationDelay as l, withPocketbase as u } from "./pocketbase-CT78tKFG.js";
|
|
9
|
+
import { createCollectionIdempotent as d } from "./collections-DcCZ0dam.js";
|
|
10
|
+
import f from "node:fs";
|
|
11
|
+
import p from "node:path";
|
|
12
|
+
import { Project as m, QuoteKind as h, SyntaxKind as g } from "ts-morph";
|
|
13
|
+
import { randomBytes as _ } from "node:crypto";
|
|
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
|
|
31
|
-
|
|
32
|
-
let a =
|
|
33
|
-
return a.wasAdded && (
|
|
30
|
+
function S(e, t, n, r, i) {
|
|
31
|
+
let s = new a(e), c = !1, l = (e) => {
|
|
32
|
+
c || e((e) => {
|
|
33
|
+
let a = o(e, t, n, r, i);
|
|
34
|
+
return a.wasAdded && (c = !0), a.source;
|
|
34
35
|
});
|
|
35
36
|
};
|
|
36
|
-
return
|
|
37
|
-
newNavUserSnippet:
|
|
38
|
-
wasAdded:
|
|
37
|
+
return l((e) => s.modifyModuleScript(e)), c || l((e) => s.modifyScript(e)), {
|
|
38
|
+
newNavUserSnippet: s.toString(),
|
|
39
|
+
wasAdded: c
|
|
39
40
|
};
|
|
40
41
|
}
|
|
41
|
-
function
|
|
42
|
-
if (!
|
|
42
|
+
function C(e) {
|
|
43
|
+
if (!f.existsSync(e)) return {
|
|
43
44
|
status: "not-found",
|
|
44
|
-
message:
|
|
45
|
+
message: x
|
|
45
46
|
};
|
|
46
|
-
let t =
|
|
47
|
+
let t = f.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 ? (f.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 = e`
|
|
63
64
|
const linkStripeCustomer = async (email: string, user: { id: string }, locals: App.Locals) => {
|
|
64
65
|
const matchingCustomer = await stripe.customers.list({
|
|
65
66
|
email: email,
|
|
@@ -118,13 +119,13 @@ var C = e`
|
|
|
118
119
|
} catch {}
|
|
119
120
|
}
|
|
120
121
|
};
|
|
121
|
-
`,
|
|
122
|
-
function
|
|
123
|
-
if (!
|
|
122
|
+
`, T = ["Could not locate the requestVerification call in signup +page.server.ts.", "Add a linkStripeCustomer helper and call it before requestVerification()."].join("\n"), E = ["Create src/routes/(public)/signup/+page.server.ts before enabling payments."].join("\n");
|
|
123
|
+
function D(t) {
|
|
124
|
+
if (!f.existsSync(t)) return {
|
|
124
125
|
status: "not-found",
|
|
125
|
-
message:
|
|
126
|
+
message: E
|
|
126
127
|
};
|
|
127
|
-
let n =
|
|
128
|
+
let n = f.readFileSync(t, "utf8"), r = new m({ manipulationSettings: { quoteKind: h.Single } }).addSourceFileAtPath(t);
|
|
128
129
|
if (r.getImportDeclarations().some((e) => e.getModuleSpecifierValue() === "$lib/stripe")) return {
|
|
129
130
|
status: "success",
|
|
130
131
|
changed: !1
|
|
@@ -133,20 +134,20 @@ function E(t) {
|
|
|
133
134
|
defaultImport: "stripe",
|
|
134
135
|
moduleSpecifier: "$lib/stripe"
|
|
135
136
|
});
|
|
136
|
-
let i = r.getDescendantsOfKind(
|
|
137
|
+
let i = r.getDescendantsOfKind(g.CallExpression).find((e) => {
|
|
137
138
|
let t = e.getExpression();
|
|
138
|
-
return t.getKind() ===
|
|
139
|
+
return t.getKind() === g.PropertyAccessExpression && t.getText().includes("requestVerification");
|
|
139
140
|
});
|
|
140
141
|
if (!i) return {
|
|
141
142
|
status: "failed",
|
|
142
|
-
message:
|
|
143
|
+
message: T
|
|
143
144
|
};
|
|
144
|
-
let a = i.getFirstAncestorByKind(
|
|
145
|
+
let a = i.getFirstAncestorByKind(g.ExpressionStatement);
|
|
145
146
|
if (!a) return {
|
|
146
147
|
status: "failed",
|
|
147
|
-
message:
|
|
148
|
+
message: T
|
|
148
149
|
};
|
|
149
|
-
r.addStatements(
|
|
150
|
+
r.addStatements(w);
|
|
150
151
|
let o = e`
|
|
151
152
|
await linkStripeCustomer(form.data.email, user, locals);
|
|
152
153
|
`;
|
|
@@ -156,36 +157,9 @@ function E(t) {
|
|
|
156
157
|
};
|
|
157
158
|
}
|
|
158
159
|
//#endregion
|
|
159
|
-
//#region src/patterns/enable/payments/modifies/modify-env.ts
|
|
160
|
-
function D(e, t) {
|
|
161
|
-
return (!e.length || e.endsWith("\n") ? e : e + "\n") + t + "\n";
|
|
162
|
-
}
|
|
163
|
-
function O(e, t) {
|
|
164
|
-
let n = e;
|
|
165
|
-
for (let e of t) {
|
|
166
|
-
if (e.type === "comment") {
|
|
167
|
-
let t = `# ${e.key}`;
|
|
168
|
-
n.includes(t) || (n = D(n, t));
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
n.includes(`${e.key}=`) || (n = D(n, `${e.key}=${e.value ?? ""}`));
|
|
172
|
-
}
|
|
173
|
-
return n;
|
|
174
|
-
}
|
|
175
|
-
function k(e, t) {
|
|
176
|
-
let n = d.existsSync(e) ? d.readFileSync(e, "utf8") : "", r = O(n, t);
|
|
177
|
-
return r === n ? {
|
|
178
|
-
status: "success",
|
|
179
|
-
changed: !1
|
|
180
|
-
} : (d.writeFileSync(e, r, "utf8"), {
|
|
181
|
-
status: "success",
|
|
182
|
-
changed: !0
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
//#endregion
|
|
186
160
|
//#region src/patterns/enable/payments/runtime/stripe.ts
|
|
187
|
-
async function
|
|
188
|
-
let t = new
|
|
161
|
+
async function O(e) {
|
|
162
|
+
let t = new v(e), n = await t.products.search({
|
|
189
163
|
query: "name:\"Test Product\" AND metadata[\"test\"]:\"true\"",
|
|
190
164
|
limit: 1
|
|
191
165
|
});
|
|
@@ -215,8 +189,8 @@ async function A(e) {
|
|
|
215
189
|
existing: !1
|
|
216
190
|
};
|
|
217
191
|
}
|
|
218
|
-
async function
|
|
219
|
-
let n = new
|
|
192
|
+
async function k(e, t) {
|
|
193
|
+
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;
|
|
220
194
|
return r.product = i.id, {
|
|
221
195
|
product: i,
|
|
222
196
|
price: r,
|
|
@@ -225,27 +199,27 @@ async function j(e, t) {
|
|
|
225
199
|
}
|
|
226
200
|
//#endregion
|
|
227
201
|
//#region src/patterns/enable/payments/generate.runtime.ts
|
|
228
|
-
var
|
|
229
|
-
async function
|
|
230
|
-
if (!
|
|
231
|
-
await
|
|
232
|
-
let
|
|
233
|
-
|
|
234
|
-
path:
|
|
235
|
-
language: t(
|
|
236
|
-
content:
|
|
202
|
+
var A;
|
|
203
|
+
async function j(e, n, r, i, a = !0) {
|
|
204
|
+
if (!a) return;
|
|
205
|
+
await l();
|
|
206
|
+
let o = c(n, r, i);
|
|
207
|
+
o && e.push({
|
|
208
|
+
path: o,
|
|
209
|
+
language: t(o),
|
|
210
|
+
content: f.readFileSync(o, "utf8"),
|
|
237
211
|
status: "success"
|
|
238
212
|
});
|
|
239
213
|
}
|
|
240
|
-
function
|
|
241
|
-
return e(
|
|
214
|
+
function M(t) {
|
|
215
|
+
return e(A ||= 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 "]), t);
|
|
242
216
|
}
|
|
243
|
-
async function
|
|
244
|
-
let { stripeSecretKey: t, stripePublishableKey: n, stripeWebhookSecret:
|
|
245
|
-
e &&
|
|
217
|
+
async function N(e) {
|
|
218
|
+
let { stripeSecretKey: t, stripePublishableKey: n, stripeWebhookSecret: a, stripePriceId: o } = e.input, c = e.features.auth, l = r(e), f = [], m = [], h = (e) => {
|
|
219
|
+
e && m.push(e);
|
|
246
220
|
};
|
|
247
|
-
|
|
248
|
-
let
|
|
221
|
+
l.info("Writing Stripe credentials to .env");
|
|
222
|
+
let g = _(16).toString("hex"), v = [
|
|
249
223
|
{
|
|
250
224
|
type: "comment",
|
|
251
225
|
key: "Stripe credentials"
|
|
@@ -263,17 +237,17 @@ async function F(e) {
|
|
|
263
237
|
{
|
|
264
238
|
type: "var",
|
|
265
239
|
key: "STRIPE_WEBHOOK_SECRET",
|
|
266
|
-
value:
|
|
240
|
+
value: a
|
|
267
241
|
},
|
|
268
242
|
{
|
|
269
243
|
type: "var",
|
|
270
244
|
key: "INTERNAL_JOB_SECRET",
|
|
271
|
-
value:
|
|
245
|
+
value: g
|
|
272
246
|
}
|
|
273
|
-
],
|
|
274
|
-
|
|
275
|
-
let n = (e) =>
|
|
276
|
-
if (
|
|
247
|
+
], y = p.join(e.root, ".env");
|
|
248
|
+
h(i(y, s(y, v))), await u(e.root, async (t) => {
|
|
249
|
+
let n = (e) => d(t, e, l);
|
|
250
|
+
if (l.info("Creating stripe_products collection"), await j(f, "stripe_products", "created", e, (await n({
|
|
277
251
|
name: "stripe_products",
|
|
278
252
|
type: "base",
|
|
279
253
|
fields: [
|
|
@@ -313,7 +287,7 @@ async function F(e) {
|
|
|
313
287
|
type: "autodate"
|
|
314
288
|
}
|
|
315
289
|
]
|
|
316
|
-
})).created),
|
|
290
|
+
})).created), l.info("Creating stripe_prices collection"), await j(f, "stripe_prices", "created", e, (await n({
|
|
317
291
|
name: "stripe_prices",
|
|
318
292
|
type: "base",
|
|
319
293
|
fields: [
|
|
@@ -373,8 +347,8 @@ async function F(e) {
|
|
|
373
347
|
type: "autodate"
|
|
374
348
|
}
|
|
375
349
|
]
|
|
376
|
-
})).created),
|
|
377
|
-
|
|
350
|
+
})).created), c) {
|
|
351
|
+
l.info("Creating stripe_customers collection");
|
|
378
352
|
let r = await n({
|
|
379
353
|
name: "stripe_customers",
|
|
380
354
|
type: "base",
|
|
@@ -409,7 +383,7 @@ async function F(e) {
|
|
|
409
383
|
}
|
|
410
384
|
]
|
|
411
385
|
}), i = r.collection;
|
|
412
|
-
await
|
|
386
|
+
await j(f, "stripe_customers", "created", e, r.created), l.info("Creating stripe_payment_methods collection");
|
|
413
387
|
let a = await n({
|
|
414
388
|
name: "stripe_payment_methods",
|
|
415
389
|
type: "base",
|
|
@@ -465,7 +439,7 @@ async function F(e) {
|
|
|
465
439
|
}
|
|
466
440
|
]
|
|
467
441
|
}), o = a.collection;
|
|
468
|
-
await
|
|
442
|
+
await j(f, "stripe_payment_methods", "created", e, a.created), l.info("Linking default_payment_method on stripe_customers"), await t.collections.update("stripe_customers", { fields: [
|
|
469
443
|
{
|
|
470
444
|
name: "id",
|
|
471
445
|
pattern: "^[a-zA-Z0-9_]+$",
|
|
@@ -502,7 +476,7 @@ async function F(e) {
|
|
|
502
476
|
onUpdate: !0,
|
|
503
477
|
type: "autodate"
|
|
504
478
|
}
|
|
505
|
-
] }), await
|
|
479
|
+
] }), await j(f, "stripe_customers", "updated", e), l.info("Creating transactions collection"), await j(f, "transactions", "created", e, (await n({
|
|
506
480
|
name: "transactions",
|
|
507
481
|
type: "base",
|
|
508
482
|
fields: [
|
|
@@ -573,56 +547,57 @@ async function F(e) {
|
|
|
573
547
|
]
|
|
574
548
|
})).created);
|
|
575
549
|
}
|
|
576
|
-
}),
|
|
577
|
-
let { product:
|
|
578
|
-
if (
|
|
550
|
+
}), o ? l.info(`Fetching Stripe product/price ${o}`) : l.info("Creating test Stripe product and price");
|
|
551
|
+
let { product: b, price: x, existing: S } = o ? await k(t, o) : await O(t);
|
|
552
|
+
if (S && l.info("Stripe product/price already exists, skipping creation"), l.info("Seeding Stripe product/price records"), await u(e.root, async (e) => {
|
|
579
553
|
try {
|
|
580
|
-
await e.collection("stripe_products").getOne(
|
|
554
|
+
await e.collection("stripe_products").getOne(b.id);
|
|
581
555
|
} catch {
|
|
582
556
|
await e.collection("stripe_products").create({
|
|
583
|
-
id:
|
|
584
|
-
name:
|
|
585
|
-
active:
|
|
586
|
-
default_price:
|
|
557
|
+
id: b.id,
|
|
558
|
+
name: b.name,
|
|
559
|
+
active: b.active,
|
|
560
|
+
default_price: b.default_price
|
|
587
561
|
});
|
|
588
562
|
}
|
|
589
563
|
try {
|
|
590
|
-
await e.collection("stripe_prices").getOne(
|
|
564
|
+
await e.collection("stripe_prices").getOne(x.id);
|
|
591
565
|
} catch {
|
|
592
566
|
await e.collection("stripe_prices").create({
|
|
593
|
-
id:
|
|
594
|
-
billing_scheme:
|
|
595
|
-
currency:
|
|
596
|
-
product:
|
|
597
|
-
recurring:
|
|
598
|
-
type:
|
|
599
|
-
unit_amount:
|
|
600
|
-
active:
|
|
567
|
+
id: x.id,
|
|
568
|
+
billing_scheme: x.billing_scheme,
|
|
569
|
+
currency: x.currency,
|
|
570
|
+
product: x.product,
|
|
571
|
+
recurring: x.recurring,
|
|
572
|
+
type: x.type,
|
|
573
|
+
unit_amount: x.unit_amount,
|
|
574
|
+
active: x.active
|
|
601
575
|
});
|
|
602
576
|
}
|
|
603
|
-
}),
|
|
577
|
+
}), l.info("Creating payment +page.svelte"), f.push({
|
|
604
578
|
path: "src/routes/(public)/payment/+page.svelte",
|
|
605
579
|
language: "svelte",
|
|
606
|
-
content:
|
|
580
|
+
content: M(x.id),
|
|
607
581
|
status: "success"
|
|
608
|
-
}),
|
|
609
|
-
|
|
610
|
-
let t =
|
|
611
|
-
|
|
612
|
-
let n =
|
|
613
|
-
|
|
582
|
+
}), c) {
|
|
583
|
+
l.info("Modifying nav-user.svelte");
|
|
584
|
+
let t = p.join(e.root, "src", "lib", "components", "nav-user.svelte");
|
|
585
|
+
h(i(t, C(t))), l.info("Modifying signup +page.server.ts");
|
|
586
|
+
let n = p.join(e.root, "src", "routes", "(public)", "signup", "+page.server.ts");
|
|
587
|
+
h(i(n, D(n)));
|
|
614
588
|
}
|
|
615
589
|
return {
|
|
616
|
-
creates:
|
|
617
|
-
modifies:
|
|
590
|
+
creates: f,
|
|
591
|
+
modifies: m,
|
|
618
592
|
deletes: [],
|
|
619
593
|
components: [],
|
|
620
594
|
packages: [],
|
|
621
595
|
collections: [],
|
|
622
|
-
collectionPatches: []
|
|
596
|
+
collectionPatches: [],
|
|
597
|
+
collectionDrops: []
|
|
623
598
|
};
|
|
624
599
|
}
|
|
625
600
|
//#endregion
|
|
626
|
-
export {
|
|
601
|
+
export { N as generate };
|
|
627
602
|
|
|
628
|
-
//# sourceMappingURL=generate.runtime-
|
|
603
|
+
//# sourceMappingURL=generate.runtime-DV9S4KW_.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.runtime-DV9S4KW_.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\";\n\nconst LINK_STRIPE_CUSTOMER_SNIPPET = dedent`\n const linkStripeCustomer = async (email: string, user: { id: string }, locals: App.Locals) => {\n const matchingCustomer = await stripe.customers.list({\n email: email,\n limit: 1,\n expand: ['data.invoice_settings']\n });\n\n let customer;\n let isExistingCustomer = false;\n\n if (matchingCustomer.data.length > 0) {\n isExistingCustomer = true;\n customer = matchingCustomer.data[0];\n } else {\n customer = await stripe.customers.create({\n email: email\n });\n }\n\n await locals.admin.collection('stripe_customers').create({\n id: customer.id,\n user: user.id\n });\n\n if (!isExistingCustomer) {\n return;\n }\n\n const paymentMethods = await stripe.customers.listPaymentMethods(customer.id, {\n type: 'card',\n allow_redisplay: 'always'\n });\n\n for (const paymentMethod of paymentMethods.data) {\n if (paymentMethod.allow_redisplay === 'unspecified') {\n continue;\n }\n\n await locals.admin.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 }\n\n const defaultPaymentMethod = customer.invoice_settings?.default_payment_method;\n\n if (defaultPaymentMethod) {\n try {\n await locals.admin.collection('stripe_customers').update(customer.id, {\n default_payment_method: defaultPaymentMethod\n });\n } catch {}\n }\n };\n`;\n\nconst FAILURE_HINT = [\n \"Could not locate the requestVerification call in signup +page.server.ts.\",\n \"Add a linkStripeCustomer helper and call it before requestVerification().\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create src/routes/(public)/signup/+page.server.ts before enabling payments.\",\n].join(\"\\n\");\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\n const project = new Project({\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(userSignupPath);\n\n const hasStripeImport = sourceFile\n .getImportDeclarations()\n .some((d) => d.getModuleSpecifierValue() === \"$lib/stripe\");\n\n if (hasStripeImport) {\n return { status: \"success\", changed: false };\n }\n\n sourceFile.addImportDeclaration({\n defaultImport: \"stripe\",\n moduleSpecifier: \"$lib/stripe\",\n });\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.addStatements(LINK_STRIPE_CUSTOMER_SNIPPET);\n\n const stripeCall = dedent`\n await linkStripeCustomer(form.data.email, user, locals);\n `;\n\n statement.replaceWithText(stripeCall + \"\\n\\n\" + statement.getText());\n\n sourceFile.formatText();\n sourceFile.saveSync();\n\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n","import Stripe from \"stripe\";\n\nexport interface StripeTestFixture {\n product: Stripe.Product;\n price: Stripe.Price;\n existing: boolean;\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 { randomBytes } from \"node:crypto\";\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} 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 internalJobSecret = randomBytes(16).toString(\"hex\");\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 { type: \"var\", key: \"INTERNAL_JOB_SECRET\", value: internalJobSecret },\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: \"text\" },\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 });\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 \"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;CACD,CAAC,KAAK,KAAK,EAEN,IAAe;CACnB;CACA;CACA;CACD,CAAC,KAAK,KAAK,EAEN,IAAiB;CACrB;CACA;CACA;CACD,CAAC,KAAK,KAAK;AAEZ,SAAgB,EACd,GACA,GACA,GACA,GACA,GACkD;CAClD,IAAM,IAAO,IAAI,EAAW,EAAe,EACvC,IAAW,IAET,KAAU,MAAgD;AAC1D,OACJ,GAAK,MAAW;GACd,IAAM,IAAS,EACb,GACA,GACA,GACA,GACA,EACD;AAED,UADI,EAAO,aAAU,IAAW,KACzB,EAAO;IACd;;AAMJ,QAHA,GAAQ,MAAO,EAAK,mBAAmB,EAAG,CAAC,EACtC,KAAU,GAAQ,MAAO,EAAK,aAAa,EAAG,CAAC,EAE7C;EAAE,mBAAmB,EAAK,UAAU;EAAE;EAAU;;AAGzD,SAAgB,EAAc,GAAoC;AAChE,KAAI,CAAC,EAAG,WAAW,EAAY,CAC7B,QAAO;EAAE,QAAQ;EAAa,SAAS;EAAgB;CAGzD,IAAM,IAAiB,EAAG,aAAa,GAAa,OAAO;AAC3D,KAAI,EAAe,SAAS,WAAW,CACrC,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAG9C,IAAM,EAAE,sBAAmB,gBAAa,EACtC,GACA,WACA,YACA,kBACA,mCACD;AAOD,QALK,KAIL,EAAG,cAAc,GAAa,GAAmB,OAAO,EACjD;EAAE,QAAQ;EAAW,SAAS;EAAM,IAJlC;EAAE,QAAQ;EAAU,SAAS;EAAc;;;;ACrEtD,IAAM,IAA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AM;IACV,gBAAgB,EAAM;IACtB,UAAU,EAAM;IAChB,SAAS,EAAM;IACf,WAAW,EAAM;IACjB,MAAM,EAAM;IACZ,aAAa,EAAM;IACnB,QAAQ,EAAM;IACf,CAAC;;GAEJ,EAEF,EAAO,KAAK,gCAAgC,EAC5C,EAAQ,KAAK;EACX,MAAM;EACN,UAAU;EACV,SAAS,EAAmB,EAAM,GAAG;EACrC,QAAQ;EACT,CAAC,EAEE,GAAW;AACb,IAAO,KAAK,4BAA4B;EACxC,IAAM,IAAc,EAAK,KACvB,EAAQ,MACR,OACA,OACA,cACA,kBACD;AAGD,EAFA,EAAW,EAAoB,GAAa,EAAc,EAAY,CAAC,CAAC,EAExE,EAAO,KAAK,mCAAmC;EAC/C,IAAM,IAAiB,EAAK,KAC1B,EAAQ,MACR,OACA,UACA,YACA,UACA,kBACD;AACD,IACE,EAAoB,GAAgB,EAAiB,EAAe,CAAC,CACtE;;AAGH,QAAO;EACL;EACA;EACA,SAAS,EAAE;EACX,YAAY,EAAE;EACd,UAAU,EAAE;EACZ,aAAa,EAAE;EACf,mBAAmB,EAAE;EACrB,iBAAiB,EAAE;EACpB"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { n as e } from "./logger-BpgCb-ZG.js";
|
|
2
|
+
import { modifyOutcomeToFile as t } from "./modify-file-Bi-4GRwL.js";
|
|
3
|
+
import n from "node:fs";
|
|
4
|
+
import r from "node:path";
|
|
5
|
+
import { Project as i, SyntaxKind as a } from "ts-morph";
|
|
6
|
+
//#region src/patterns/disable/api/modifies/hooks.server.ts
|
|
7
|
+
function o(e) {
|
|
8
|
+
if (!n.existsSync(e)) return {
|
|
9
|
+
status: "success",
|
|
10
|
+
changed: !1
|
|
11
|
+
};
|
|
12
|
+
let t = n.readFileSync(e, "utf8"), r = new i().addSourceFileAtPath(e), o = r.getDescendantsOfKind(a.CallExpression).find((e) => e.getExpression().getText() === "handlePocketbase");
|
|
13
|
+
if (!o) return {
|
|
14
|
+
status: "success",
|
|
15
|
+
changed: !1
|
|
16
|
+
};
|
|
17
|
+
let s = o.getArguments();
|
|
18
|
+
if (s.length === 0) return {
|
|
19
|
+
status: "success",
|
|
20
|
+
changed: !1
|
|
21
|
+
};
|
|
22
|
+
let c = s[0];
|
|
23
|
+
if (c.getKind() !== a.ObjectLiteralExpression) return {
|
|
24
|
+
status: "success",
|
|
25
|
+
changed: !1
|
|
26
|
+
};
|
|
27
|
+
let l = c.asKindOrThrow(a.ObjectLiteralExpression), u = l.getProperty("api");
|
|
28
|
+
return u ? (u.remove(), l.getProperties().length === 0 && o.removeArgument(0), r.formatText(), r.saveSync(), {
|
|
29
|
+
status: "success",
|
|
30
|
+
changed: r.getFullText() !== t
|
|
31
|
+
}) : {
|
|
32
|
+
status: "success",
|
|
33
|
+
changed: !1
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/patterns/disable/api/generate.runtime.ts
|
|
38
|
+
async function s(n) {
|
|
39
|
+
let i = e(n), a = [];
|
|
40
|
+
i.info("Reverting hooks.server.ts");
|
|
41
|
+
let s = r.join(n.root, "src", "hooks.server.ts"), c = t(s, o(s));
|
|
42
|
+
return c && a.push(c), {
|
|
43
|
+
creates: [],
|
|
44
|
+
modifies: a,
|
|
45
|
+
deletes: [],
|
|
46
|
+
components: [],
|
|
47
|
+
packages: [],
|
|
48
|
+
collections: [],
|
|
49
|
+
collectionPatches: [],
|
|
50
|
+
collectionDrops: []
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { s as generate };
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=generate.runtime-GmszNklA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.runtime-GmszNklA.js","names":[],"sources":["../../src/patterns/disable/api/modifies/hooks.server.ts","../../src/patterns/disable/api/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyHooksServer(hooksServerPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"success\", changed: false };\n }\n\n const originalSource = fs.readFileSync(hooksServerPath, \"utf8\");\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n const callExpr = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"handlePocketbase\");\n\n if (!callExpr) {\n return { status: \"success\", changed: false };\n }\n\n const args = callExpr.getArguments();\n if (args.length === 0) {\n return { status: \"success\", changed: false };\n }\n\n const firstArg = args[0];\n if (firstArg.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n return { status: \"success\", changed: false };\n }\n\n const optionsObj = firstArg.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n const apiProp = optionsObj.getProperty(\"api\");\n if (!apiProp) {\n return { status: \"success\", changed: false };\n }\n\n apiProp.remove();\n\n if (optionsObj.getProperties().length === 0) {\n callExpr.removeArgument(0);\n }\n\n sourceFile.formatText();\n sourceFile.saveSync();\n\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\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 { unmodifyHooksServer } from \"./modifies/hooks.server\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n\n logger.info(\"Reverting hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n const file = modifyOutcomeToFile(\n hooksServerPath,\n unmodifyHooksServer(hooksServerPath),\n );\n if (file) modifies.push(file);\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":";;;;;;AAI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,EAAE;EACpB"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { n as e } from "./logger-BpgCb-ZG.js";
|
|
2
|
+
import { modifyOutcomeToFile as t } from "./modify-file-Bi-4GRwL.js";
|
|
3
|
+
import n from "node:fs";
|
|
4
|
+
import r from "node:path";
|
|
5
|
+
//#region src/patterns/disable/i18n/modifies/gitignore.ts
|
|
6
|
+
function i(e) {
|
|
7
|
+
if (!n.existsSync(e)) return {
|
|
8
|
+
status: "success",
|
|
9
|
+
changed: !1
|
|
10
|
+
};
|
|
11
|
+
let t = n.readFileSync(e, "utf8");
|
|
12
|
+
if (!t.includes("src/locales/.wuchale")) return {
|
|
13
|
+
status: "success",
|
|
14
|
+
changed: !1
|
|
15
|
+
};
|
|
16
|
+
let r = t.split("\n"), i = [];
|
|
17
|
+
for (let e = 0; e < r.length; e++) {
|
|
18
|
+
let t = r[e];
|
|
19
|
+
if (t === "# Wuchale") {
|
|
20
|
+
let t = e + 1, n = !1;
|
|
21
|
+
for (; t < r.length && r[t].trim() !== "";) r[t] === "src/locales/.wuchale" && (n = !0), t++;
|
|
22
|
+
if (n) {
|
|
23
|
+
e = t;
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
t !== "src/locales/.wuchale" && i.push(t);
|
|
28
|
+
}
|
|
29
|
+
let a = i.join("\n");
|
|
30
|
+
return a = a.replace(/\n{3,}/g, "\n\n"), a === t ? {
|
|
31
|
+
status: "success",
|
|
32
|
+
changed: !1
|
|
33
|
+
} : (n.writeFileSync(e, a), {
|
|
34
|
+
status: "success",
|
|
35
|
+
changed: !0
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/patterns/disable/i18n/generate.runtime.ts
|
|
40
|
+
var a = [
|
|
41
|
+
"vite.config, svelte.config, hooks.server, app.html, and +layout.ts must be reverted manually.",
|
|
42
|
+
"The i18n integration touches these files in ways that are not safely reversible by tooling.",
|
|
43
|
+
"See the enable-i18n modifies for the blocks to remove."
|
|
44
|
+
].join(" ");
|
|
45
|
+
async function o(n) {
|
|
46
|
+
let o = e(n), s = [], c = (e) => {
|
|
47
|
+
e && s.push(e);
|
|
48
|
+
};
|
|
49
|
+
o.info("Reverting .gitignore");
|
|
50
|
+
let l = r.join(n.root, ".gitignore");
|
|
51
|
+
return c(t(l, i(l))), o.info(a), {
|
|
52
|
+
creates: [],
|
|
53
|
+
modifies: s,
|
|
54
|
+
deletes: [],
|
|
55
|
+
components: [],
|
|
56
|
+
packages: [],
|
|
57
|
+
collections: [],
|
|
58
|
+
collectionPatches: [],
|
|
59
|
+
collectionDrops: []
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
export { o as generate };
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=generate.runtime-NdlYevoh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.runtime-NdlYevoh.js","names":[],"sources":["../../src/patterns/disable/i18n/modifies/gitignore.ts","../../src/patterns/disable/i18n/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyGitignore(gitignorePath: string): ModifyOutcome {\n if (!fs.existsSync(gitignorePath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(gitignorePath, \"utf8\");\n if (!original.includes(\"src/locales/.wuchale\")) {\n return { status: \"success\", changed: false };\n }\n\n const lines = original.split(\"\\n\");\n const out: string[] = [];\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n if (line === \"# Wuchale\") {\n let j = i + 1;\n let hasWuchale = false;\n while (j < lines.length && lines[j].trim() !== \"\") {\n if (lines[j] === \"src/locales/.wuchale\") {\n hasWuchale = true;\n }\n j++;\n }\n if (hasWuchale) {\n i = j;\n continue;\n }\n }\n if (line === \"src/locales/.wuchale\") continue;\n out.push(line);\n }\n\n let updated = out.join(\"\\n\");\n updated = updated.replace(/\\n{3,}/g, \"\\n\\n\");\n\n if (updated === original) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(gitignorePath, updated);\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 { unmodifyGitignore } from \"./modifies/gitignore\";\n\nconst MANUAL_REMEDIATION = [\n \"vite.config, svelte.config, hooks.server, app.html, and +layout.ts must be reverted manually.\",\n \"The i18n integration touches these files in ways that are not safely reversible by tooling.\",\n \"See the enable-i18n modifies for the blocks to remove.\",\n].join(\" \");\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Reverting .gitignore\");\n const gitignorePath = path.join(options.root, \".gitignore\");\n pushResult(modifyOutcomeToFile(gitignorePath, unmodifyGitignore(gitignorePath)));\n\n logger.info(MANUAL_REMEDIATION);\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":";;;;;AAGA,SAAgB,EAAkB,GAAsC;AACtE,KAAI,CAAC,EAAG,WAAW,EAAc,CAC/B,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAG9C,IAAM,IAAW,EAAG,aAAa,GAAe,OAAO;AACvD,KAAI,CAAC,EAAS,SAAS,uBAAuB,CAC5C,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAG9C,IAAM,IAAQ,EAAS,MAAM,KAAK,EAC5B,IAAgB,EAAE;AACxB,MAAK,IAAI,IAAI,GAAG,IAAI,EAAM,QAAQ,KAAK;EACrC,IAAM,IAAO,EAAM;AACnB,MAAI,MAAS,aAAa;GACxB,IAAI,IAAI,IAAI,GACR,IAAa;AACjB,UAAO,IAAI,EAAM,UAAU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