@velastack/patterns 0.0.33 → 0.0.34
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-Czm1C8ow.js +108 -0
- package/dist/chunks/collections-Czm1C8ow.js.map +1 -0
- package/dist/chunks/{env.preview-NYMljYNr.js → env.preview-BZwjhgoi.js} +1 -1
- package/dist/chunks/{env.preview-NYMljYNr.js.map → env.preview-BZwjhgoi.js.map} +1 -1
- package/dist/chunks/{env.runtime-ZUZgxjxf.js → env.runtime-BEdollKV.js} +1 -1
- package/dist/chunks/{env.runtime-ZUZgxjxf.js.map → env.runtime-BEdollKV.js.map} +1 -1
- package/dist/chunks/{generate.runtime-uk9-KOP-.js → generate.runtime-BCz-NNqq.js} +123 -117
- package/dist/chunks/generate.runtime-BCz-NNqq.js.map +1 -0
- package/dist/chunks/{generate.runtime-4zd9-8H_.js → generate.runtime-BZ-KaCUr.js} +118 -102
- package/dist/chunks/generate.runtime-BZ-KaCUr.js.map +1 -0
- package/dist/chunks/generate.runtime-Caqa5ndO.js +85 -0
- package/dist/chunks/{generate.runtime-CbiQhqdL.js.map → generate.runtime-Caqa5ndO.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DpeB3h-P.js → generate.runtime-Cbq2649r.js} +94 -91
- package/dist/chunks/{generate.runtime-DpeB3h-P.js.map → generate.runtime-Cbq2649r.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CXqD8em8.js → generate.runtime-D7ksYerH.js} +133 -130
- package/dist/chunks/{generate.runtime-CXqD8em8.js.map → generate.runtime-D7ksYerH.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BKrtBCRk.js → generate.runtime-DTZ1PeDS.js} +94 -91
- package/dist/chunks/{generate.runtime-BKrtBCRk.js.map → generate.runtime-DTZ1PeDS.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BkjQiaP_.js → generate.runtime-y1Ga_5QI.js} +70 -64
- package/dist/chunks/{generate.runtime-BkjQiaP_.js.map → generate.runtime-y1Ga_5QI.js.map} +1 -1
- package/dist/chunks/logger-BpgCb-ZG.js +9 -0
- package/dist/chunks/logger-BpgCb-ZG.js.map +1 -0
- package/dist/chunks/{modify-file-D3OuKUEp.js → modify-file-DT_1_kvI.js} +1 -1
- package/dist/chunks/{modify-file-D3OuKUEp.js.map → modify-file-DT_1_kvI.js.map} +1 -1
- package/dist/chunks/{modify-svelte-config-remote-Dzgk1OIN.js → modify-svelte-config-remote-CFsA9Mom.js} +1 -1
- package/dist/chunks/{modify-svelte-config-remote-Dzgk1OIN.js.map → modify-svelte-config-remote-CFsA9Mom.js.map} +1 -1
- package/dist/chunks/{pocketbase--dNkFDJ5.js → pocketbase-BiRWz-OQ.js} +1 -1
- package/dist/chunks/{pocketbase--dNkFDJ5.js.map → pocketbase-BiRWz-OQ.js.map} +1 -1
- package/dist/chunks/{pocketbase-W_FJaYZ3.js → pocketbase-iFJBbNJu.js} +1 -1
- package/dist/chunks/{pocketbase-W_FJaYZ3.js.map → pocketbase-iFJBbNJu.js.map} +1 -1
- package/dist/chunks/{ts-morph-helpers-digNcfBD.js → ts-morph-helpers-C0HeJDjR.js} +1 -1
- package/dist/chunks/{ts-morph-helpers-digNcfBD.js.map → ts-morph-helpers-C0HeJDjR.js.map} +1 -1
- package/dist/chunks/write-result-B0-q-egx.js +219 -0
- package/dist/chunks/{write-result-C80dpjr-.js.map → write-result-B0-q-egx.js.map} +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +662 -657
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/collections-BRIAYJ-Q.js +0 -94
- package/dist/chunks/collections-BRIAYJ-Q.js.map +0 -1
- package/dist/chunks/generate.runtime-4zd9-8H_.js.map +0 -1
- package/dist/chunks/generate.runtime-CbiQhqdL.js +0 -82
- package/dist/chunks/generate.runtime-uk9-KOP-.js.map +0 -1
- package/dist/chunks/write-result-C80dpjr-.js +0 -216
|
@@ -1,63 +1,65 @@
|
|
|
1
1
|
import { t as e } from "./dedent-C4qKBQXh.js";
|
|
2
2
|
import { n as t } from "./util-C064WO8o.js";
|
|
3
3
|
import { t as n } from "./taggedTemplateLiteral-Bfbldyfk.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import u from "
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import h from "
|
|
4
|
+
import { n as r } from "./logger-BpgCb-ZG.js";
|
|
5
|
+
import { getMigrationFile as i, migrationDelay as a, withPocketbase as o } from "./pocketbase-iFJBbNJu.js";
|
|
6
|
+
import { createCollectionIdempotent as s } from "./collections-Czm1C8ow.js";
|
|
7
|
+
import { modifyOutcomeToFile as c } from "./modify-file-DT_1_kvI.js";
|
|
8
|
+
import { i as l, t as u } from "./ts-morph-helpers-C0HeJDjR.js";
|
|
9
|
+
import d from "node:fs";
|
|
10
|
+
import f from "node:path";
|
|
11
|
+
import { Project as p, QuoteKind as m, SyntaxKind as h } from "ts-morph";
|
|
12
|
+
import { randomBytes as g } from "node:crypto";
|
|
13
|
+
import _ from "stripe";
|
|
12
14
|
//#region src/patterns/enable/payments/modifies/modify-nav-user.ts
|
|
13
|
-
var
|
|
15
|
+
var v = [
|
|
14
16
|
"import CreditCardIcon from '@lucide/svelte/icons/credit-card';",
|
|
15
17
|
"",
|
|
16
18
|
"// Add to your navUser array:",
|
|
17
19
|
"{ title: 'Billing', url: '/billing', icon: CreditCardIcon }"
|
|
18
|
-
].join("\n"),
|
|
20
|
+
].join("\n"), y = [
|
|
19
21
|
"Add a Billing nav item to nav-user.svelte:",
|
|
20
22
|
"",
|
|
21
|
-
|
|
22
|
-
].join("\n"),
|
|
23
|
+
v
|
|
24
|
+
].join("\n"), b = [
|
|
23
25
|
"Create nav-user.svelte with a Billing entry:",
|
|
24
26
|
"",
|
|
25
|
-
|
|
27
|
+
v
|
|
26
28
|
].join("\n");
|
|
27
|
-
function
|
|
28
|
-
let a = new
|
|
29
|
+
function x(e, t, n, r, i) {
|
|
30
|
+
let a = new l(e), o = !1, s = (e) => {
|
|
29
31
|
o || e((e) => {
|
|
30
|
-
let a =
|
|
32
|
+
let a = u(e, t, n, r, i);
|
|
31
33
|
return a.wasAdded && (o = !0), a.source;
|
|
32
34
|
});
|
|
33
35
|
};
|
|
34
|
-
return
|
|
36
|
+
return s((e) => a.modifyModuleScript(e)), o || s((e) => a.modifyScript(e)), {
|
|
35
37
|
newNavUserSnippet: a.toString(),
|
|
36
38
|
wasAdded: o
|
|
37
39
|
};
|
|
38
40
|
}
|
|
39
|
-
function
|
|
40
|
-
if (!
|
|
41
|
+
function S(e) {
|
|
42
|
+
if (!d.existsSync(e)) return {
|
|
41
43
|
status: "not-found",
|
|
42
|
-
message:
|
|
44
|
+
message: b
|
|
43
45
|
};
|
|
44
|
-
let t =
|
|
46
|
+
let t = d.readFileSync(e, "utf8");
|
|
45
47
|
if (t.includes("/billing")) return {
|
|
46
48
|
status: "success",
|
|
47
49
|
changed: !1
|
|
48
50
|
};
|
|
49
|
-
let { newNavUserSnippet: n, wasAdded: r } =
|
|
50
|
-
return r ? (
|
|
51
|
+
let { newNavUserSnippet: n, wasAdded: r } = x(t, "Billing", "/billing", "CreditCardIcon", "@lucide/svelte/icons/credit-card");
|
|
52
|
+
return r ? (d.writeFileSync(e, n, "utf8"), {
|
|
51
53
|
status: "success",
|
|
52
54
|
changed: !0
|
|
53
55
|
}) : {
|
|
54
56
|
status: "failed",
|
|
55
|
-
message:
|
|
57
|
+
message: y
|
|
56
58
|
};
|
|
57
59
|
}
|
|
58
60
|
//#endregion
|
|
59
61
|
//#region src/patterns/enable/payments/modifies/modify-user-signup.ts
|
|
60
|
-
var
|
|
62
|
+
var C = e`
|
|
61
63
|
const linkStripeCustomer = async (email: string, user: { id: string }, locals: App.Locals) => {
|
|
62
64
|
const matchingCustomer = await stripe.customers.list({
|
|
63
65
|
email: email,
|
|
@@ -116,13 +118,13 @@ var x = e`
|
|
|
116
118
|
} catch {}
|
|
117
119
|
}
|
|
118
120
|
};
|
|
119
|
-
`,
|
|
120
|
-
function
|
|
121
|
-
if (!
|
|
121
|
+
`, w = ["Could not locate the requestVerification call in signup +page.server.ts.", "Add a linkStripeCustomer helper and call it before requestVerification()."].join("\n"), T = ["Create src/routes/(public)/signup/+page.server.ts before enabling payments."].join("\n");
|
|
122
|
+
function E(t) {
|
|
123
|
+
if (!d.existsSync(t)) return {
|
|
122
124
|
status: "not-found",
|
|
123
|
-
message:
|
|
125
|
+
message: T
|
|
124
126
|
};
|
|
125
|
-
let n =
|
|
127
|
+
let n = d.readFileSync(t, "utf8"), r = new p({ manipulationSettings: { quoteKind: m.Single } }).addSourceFileAtPath(t);
|
|
126
128
|
if (r.getImportDeclarations().some((e) => e.getModuleSpecifierValue() === "$lib/stripe")) return {
|
|
127
129
|
status: "success",
|
|
128
130
|
changed: !1
|
|
@@ -131,20 +133,20 @@ function w(t) {
|
|
|
131
133
|
defaultImport: "stripe",
|
|
132
134
|
moduleSpecifier: "$lib/stripe"
|
|
133
135
|
});
|
|
134
|
-
let i = r.getDescendantsOfKind(
|
|
136
|
+
let i = r.getDescendantsOfKind(h.CallExpression).find((e) => {
|
|
135
137
|
let t = e.getExpression();
|
|
136
|
-
return t.getKind() ===
|
|
138
|
+
return t.getKind() === h.PropertyAccessExpression && t.getText().includes("requestVerification");
|
|
137
139
|
});
|
|
138
140
|
if (!i) return {
|
|
139
141
|
status: "failed",
|
|
140
|
-
message:
|
|
142
|
+
message: w
|
|
141
143
|
};
|
|
142
|
-
let a = i.getFirstAncestorByKind(
|
|
144
|
+
let a = i.getFirstAncestorByKind(h.ExpressionStatement);
|
|
143
145
|
if (!a) return {
|
|
144
146
|
status: "failed",
|
|
145
|
-
message:
|
|
147
|
+
message: w
|
|
146
148
|
};
|
|
147
|
-
r.addStatements(
|
|
149
|
+
r.addStatements(C);
|
|
148
150
|
let o = e`
|
|
149
151
|
await linkStripeCustomer(form.data.email, user, locals);
|
|
150
152
|
`;
|
|
@@ -155,35 +157,35 @@ function w(t) {
|
|
|
155
157
|
}
|
|
156
158
|
//#endregion
|
|
157
159
|
//#region src/patterns/enable/payments/modifies/modify-env.ts
|
|
158
|
-
function
|
|
160
|
+
function D(e, t) {
|
|
159
161
|
return (!e.length || e.endsWith("\n") ? e : e + "\n") + t + "\n";
|
|
160
162
|
}
|
|
161
|
-
function
|
|
163
|
+
function O(e, t) {
|
|
162
164
|
let n = e;
|
|
163
165
|
for (let e of t) {
|
|
164
166
|
if (e.type === "comment") {
|
|
165
167
|
let t = `# ${e.key}`;
|
|
166
|
-
n.includes(t) || (n =
|
|
168
|
+
n.includes(t) || (n = D(n, t));
|
|
167
169
|
continue;
|
|
168
170
|
}
|
|
169
|
-
n.includes(`${e.key}=`) || (n =
|
|
171
|
+
n.includes(`${e.key}=`) || (n = D(n, `${e.key}=${e.value ?? ""}`));
|
|
170
172
|
}
|
|
171
173
|
return n;
|
|
172
174
|
}
|
|
173
|
-
function
|
|
174
|
-
let n =
|
|
175
|
+
function k(e, t) {
|
|
176
|
+
let n = d.existsSync(e) ? d.readFileSync(e, "utf8") : "", r = O(n, t);
|
|
175
177
|
return r === n ? {
|
|
176
178
|
status: "success",
|
|
177
179
|
changed: !1
|
|
178
|
-
} : (
|
|
180
|
+
} : (d.writeFileSync(e, r, "utf8"), {
|
|
179
181
|
status: "success",
|
|
180
182
|
changed: !0
|
|
181
183
|
});
|
|
182
184
|
}
|
|
183
185
|
//#endregion
|
|
184
186
|
//#region src/patterns/enable/payments/runtime/stripe.ts
|
|
185
|
-
async function
|
|
186
|
-
let t = new
|
|
187
|
+
async function A(e) {
|
|
188
|
+
let t = new _(e), n = await t.products.search({
|
|
187
189
|
query: "name:\"Test Product\" AND metadata[\"test\"]:\"true\"",
|
|
188
190
|
limit: 1
|
|
189
191
|
});
|
|
@@ -213,26 +215,37 @@ async function O(e) {
|
|
|
213
215
|
existing: !1
|
|
214
216
|
};
|
|
215
217
|
}
|
|
218
|
+
async function j(e, t) {
|
|
219
|
+
let n = new _(e), r = await n.prices.retrieve(t, { expand: ["product"] }), i = typeof r.product == "string" ? await n.products.retrieve(r.product) : r.product;
|
|
220
|
+
return r.product = i.id, {
|
|
221
|
+
product: i,
|
|
222
|
+
price: r,
|
|
223
|
+
existing: !0
|
|
224
|
+
};
|
|
225
|
+
}
|
|
216
226
|
//#endregion
|
|
217
227
|
//#region src/patterns/enable/payments/generate.runtime.ts
|
|
218
|
-
var
|
|
219
|
-
async function
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
228
|
+
var M;
|
|
229
|
+
async function N(e, n, r, o, s = !0) {
|
|
230
|
+
if (!s) return;
|
|
231
|
+
await a();
|
|
232
|
+
let c = i(n, r, o);
|
|
233
|
+
c && e.push({
|
|
234
|
+
path: c,
|
|
235
|
+
language: t(c),
|
|
236
|
+
content: d.readFileSync(c, "utf8"),
|
|
226
237
|
status: "success"
|
|
227
238
|
});
|
|
228
239
|
}
|
|
229
|
-
function
|
|
230
|
-
return e(
|
|
240
|
+
function P(t) {
|
|
241
|
+
return e(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 "]), t);
|
|
231
242
|
}
|
|
232
|
-
async function
|
|
233
|
-
let { stripeSecretKey: t, stripePublishableKey: n, stripeWebhookSecret:
|
|
234
|
-
e &&
|
|
235
|
-
}
|
|
243
|
+
async function F(e) {
|
|
244
|
+
let { stripeSecretKey: t, stripePublishableKey: n, stripeWebhookSecret: i, stripePriceId: a } = e.input, l = e.features.auth, u = r(e), d = [], p = [], m = (e) => {
|
|
245
|
+
e && p.push(e);
|
|
246
|
+
};
|
|
247
|
+
u.info("Writing Stripe credentials to .env");
|
|
248
|
+
let h = g(16).toString("hex"), _ = [
|
|
236
249
|
{
|
|
237
250
|
type: "comment",
|
|
238
251
|
key: "Stripe credentials"
|
|
@@ -250,16 +263,17 @@ async function M(e) {
|
|
|
250
263
|
{
|
|
251
264
|
type: "var",
|
|
252
265
|
key: "STRIPE_WEBHOOK_SECRET",
|
|
253
|
-
value:
|
|
266
|
+
value: i
|
|
254
267
|
},
|
|
255
268
|
{
|
|
256
269
|
type: "var",
|
|
257
270
|
key: "INTERNAL_JOB_SECRET",
|
|
258
|
-
value:
|
|
271
|
+
value: h
|
|
259
272
|
}
|
|
260
|
-
],
|
|
261
|
-
|
|
262
|
-
|
|
273
|
+
], v = f.join(e.root, ".env");
|
|
274
|
+
m(c(v, k(v, _))), await o(e.root, async (t) => {
|
|
275
|
+
let n = (e) => s(t, e, u);
|
|
276
|
+
if (u.info("Creating stripe_products collection"), await N(d, "stripe_products", "created", e, (await n({
|
|
263
277
|
name: "stripe_products",
|
|
264
278
|
type: "base",
|
|
265
279
|
fields: [
|
|
@@ -299,7 +313,7 @@ async function M(e) {
|
|
|
299
313
|
type: "autodate"
|
|
300
314
|
}
|
|
301
315
|
]
|
|
302
|
-
}), await
|
|
316
|
+
})).created), u.info("Creating stripe_prices collection"), await N(d, "stripe_prices", "created", e, (await n({
|
|
303
317
|
name: "stripe_prices",
|
|
304
318
|
type: "base",
|
|
305
319
|
fields: [
|
|
@@ -359,8 +373,9 @@ async function M(e) {
|
|
|
359
373
|
type: "autodate"
|
|
360
374
|
}
|
|
361
375
|
]
|
|
362
|
-
})
|
|
363
|
-
|
|
376
|
+
})).created), l) {
|
|
377
|
+
u.info("Creating stripe_customers collection");
|
|
378
|
+
let r = await n({
|
|
364
379
|
name: "stripe_customers",
|
|
365
380
|
type: "base",
|
|
366
381
|
fields: [
|
|
@@ -393,9 +408,9 @@ async function M(e) {
|
|
|
393
408
|
type: "autodate"
|
|
394
409
|
}
|
|
395
410
|
]
|
|
396
|
-
});
|
|
397
|
-
await
|
|
398
|
-
let
|
|
411
|
+
}), i = r.collection;
|
|
412
|
+
await N(d, "stripe_customers", "created", e, r.created), u.info("Creating stripe_payment_methods collection");
|
|
413
|
+
let a = await n({
|
|
399
414
|
name: "stripe_payment_methods",
|
|
400
415
|
type: "base",
|
|
401
416
|
fields: [
|
|
@@ -428,7 +443,7 @@ async function M(e) {
|
|
|
428
443
|
type: "number"
|
|
429
444
|
},
|
|
430
445
|
{
|
|
431
|
-
collectionId:
|
|
446
|
+
collectionId: i.id,
|
|
432
447
|
maxSelect: 1,
|
|
433
448
|
minSelect: 0,
|
|
434
449
|
name: "customer",
|
|
@@ -449,8 +464,8 @@ async function M(e) {
|
|
|
449
464
|
type: "autodate"
|
|
450
465
|
}
|
|
451
466
|
]
|
|
452
|
-
});
|
|
453
|
-
await
|
|
467
|
+
}), o = a.collection;
|
|
468
|
+
await N(d, "stripe_payment_methods", "created", e, a.created), u.info("Linking default_payment_method on stripe_customers"), await t.collections.update("stripe_customers", { fields: [
|
|
454
469
|
{
|
|
455
470
|
name: "id",
|
|
456
471
|
pattern: "^[a-zA-Z0-9_]+$",
|
|
@@ -468,7 +483,7 @@ async function M(e) {
|
|
|
468
483
|
type: "relation"
|
|
469
484
|
},
|
|
470
485
|
{
|
|
471
|
-
collectionId:
|
|
486
|
+
collectionId: o.id,
|
|
472
487
|
maxSelect: 1,
|
|
473
488
|
minSelect: 0,
|
|
474
489
|
name: "default_payment_method",
|
|
@@ -487,7 +502,7 @@ async function M(e) {
|
|
|
487
502
|
onUpdate: !0,
|
|
488
503
|
type: "autodate"
|
|
489
504
|
}
|
|
490
|
-
] }), await
|
|
505
|
+
] }), await N(d, "stripe_customers", "updated", e), u.info("Creating transactions collection"), await N(d, "transactions", "created", e, (await n({
|
|
491
506
|
name: "transactions",
|
|
492
507
|
type: "base",
|
|
493
508
|
fields: [
|
|
@@ -556,40 +571,41 @@ async function M(e) {
|
|
|
556
571
|
type: "url"
|
|
557
572
|
}
|
|
558
573
|
]
|
|
559
|
-
})
|
|
574
|
+
})).created);
|
|
560
575
|
}
|
|
561
|
-
});
|
|
562
|
-
let { product:
|
|
563
|
-
if (await
|
|
576
|
+
}), a ? u.info(`Fetching Stripe product/price ${a}`) : u.info("Creating test Stripe product and price");
|
|
577
|
+
let { product: y, price: b } = a ? await j(t, a) : await A(t);
|
|
578
|
+
if (u.info("Seeding Stripe product/price records"), await o(e.root, async (e) => {
|
|
564
579
|
await e.collection("stripe_products").create({
|
|
565
|
-
id:
|
|
566
|
-
name:
|
|
567
|
-
active:
|
|
568
|
-
default_price:
|
|
580
|
+
id: y.id,
|
|
581
|
+
name: y.name,
|
|
582
|
+
active: y.active,
|
|
583
|
+
default_price: y.default_price
|
|
569
584
|
}), await e.collection("stripe_prices").create({
|
|
570
|
-
id:
|
|
571
|
-
billing_scheme:
|
|
572
|
-
currency:
|
|
573
|
-
product:
|
|
574
|
-
recurring:
|
|
575
|
-
type:
|
|
576
|
-
unit_amount:
|
|
577
|
-
active:
|
|
585
|
+
id: b.id,
|
|
586
|
+
billing_scheme: b.billing_scheme,
|
|
587
|
+
currency: b.currency,
|
|
588
|
+
product: b.product,
|
|
589
|
+
recurring: b.recurring,
|
|
590
|
+
type: b.type,
|
|
591
|
+
unit_amount: b.unit_amount,
|
|
592
|
+
active: b.active
|
|
578
593
|
});
|
|
579
|
-
}),
|
|
594
|
+
}), u.info("Creating payment +page.svelte"), d.push({
|
|
580
595
|
path: "src/routes/(public)/payment/+page.svelte",
|
|
581
596
|
language: "svelte",
|
|
582
|
-
content:
|
|
597
|
+
content: P(b.id),
|
|
583
598
|
status: "success"
|
|
584
|
-
}),
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
599
|
+
}), l) {
|
|
600
|
+
u.info("Modifying nav-user.svelte");
|
|
601
|
+
let t = f.join(e.root, "src", "lib", "components", "nav-user.svelte");
|
|
602
|
+
m(c(t, S(t))), u.info("Modifying signup +page.server.ts");
|
|
603
|
+
let n = f.join(e.root, "src", "routes", "(public)", "signup", "+page.server.ts");
|
|
604
|
+
m(c(n, E(n)));
|
|
589
605
|
}
|
|
590
606
|
return {
|
|
591
|
-
creates:
|
|
592
|
-
modifies:
|
|
607
|
+
creates: d,
|
|
608
|
+
modifies: p,
|
|
593
609
|
deletes: [],
|
|
594
610
|
components: [],
|
|
595
611
|
packages: [],
|
|
@@ -598,6 +614,6 @@ async function M(e) {
|
|
|
598
614
|
};
|
|
599
615
|
}
|
|
600
616
|
//#endregion
|
|
601
|
-
export {
|
|
617
|
+
export { F as generate };
|
|
602
618
|
|
|
603
|
-
//# sourceMappingURL=generate.runtime-
|
|
619
|
+
//# sourceMappingURL=generate.runtime-BZ-KaCUr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.runtime-BZ-KaCUr.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/modifies/modify-env.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 fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport interface EnvEdit {\n type: \"comment\" | \"var\";\n /** For \"comment\": the text after `# `. For \"var\": the KEY. */\n key: string;\n /** Only for \"var\" entries. */\n value?: string;\n}\n\nfunction appendEnvContent(existing: string, content: string): string {\n const withNewLine =\n !existing.length || existing.endsWith(\"\\n\") ? existing : existing + \"\\n\";\n return withNewLine + content + \"\\n\";\n}\n\nexport function applyEnvEdits(source: string, edits: EnvEdit[]): string {\n let next = source;\n for (const edit of edits) {\n if (edit.type === \"comment\") {\n const commented = `# ${edit.key}`;\n if (!next.includes(commented)) {\n next = appendEnvContent(next, commented);\n }\n continue;\n }\n if (!next.includes(`${edit.key}=`)) {\n next = appendEnvContent(next, `${edit.key}=${edit.value ?? \"\"}`);\n }\n }\n return next;\n}\n\nexport function modifyEnv(envPath: string, edits: EnvEdit[]): ModifyOutcome {\n const existing = fs.existsSync(envPath)\n ? fs.readFileSync(envPath, \"utf8\")\n : \"\";\n const next = applyEnvEdits(existing, edits);\n if (next === existing) {\n return { status: \"success\", changed: false };\n }\n fs.writeFileSync(envPath, next, \"utf8\");\n return { status: \"success\", changed: true };\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 = (\n 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 } = stripePriceId\n ? await getProductAndPriceById(stripeSecretKey, stripePriceId)\n : await createTestProductAndPrice(stripeSecretKey);\n\n logger.info(\"Seeding Stripe product/price records\");\n await withPocketbase(options.root, async (pb) => {\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 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 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 } 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+B,CAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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+
import { t as e } from "./dedent-C4qKBQXh.js";
|
|
2
|
+
import { n as t } from "./logger-BpgCb-ZG.js";
|
|
3
|
+
import { modifyOutcomeToFile as n } from "./modify-file-DT_1_kvI.js";
|
|
4
|
+
import r from "node:fs";
|
|
5
|
+
import i from "node:path";
|
|
6
|
+
import { Project as a, SyntaxKind as o } from "ts-morph";
|
|
7
|
+
//#region src/patterns/enable/api/modifies/hooks.server.ts
|
|
8
|
+
var s = e`
|
|
9
|
+
Configure handlePocketbase() with the api option in hooks.server.ts:
|
|
10
|
+
|
|
11
|
+
handlePocketbase({
|
|
12
|
+
api: { enabled: true },
|
|
13
|
+
});
|
|
14
|
+
`, c = e`
|
|
15
|
+
Create src/hooks.server.ts with handlePocketbase:
|
|
16
|
+
|
|
17
|
+
import { handlePocketbase } from 'velastack/handle';
|
|
18
|
+
|
|
19
|
+
export const handle = handlePocketbase({
|
|
20
|
+
api: { enabled: true },
|
|
21
|
+
});
|
|
22
|
+
`;
|
|
23
|
+
function l(e) {
|
|
24
|
+
if (!r.existsSync(e)) return {
|
|
25
|
+
status: "not-found",
|
|
26
|
+
message: c
|
|
27
|
+
};
|
|
28
|
+
let t = r.readFileSync(e, "utf8"), n = new a().addSourceFileAtPath(e), i = n.getDescendantsOfKind(o.CallExpression).find((e) => e.getExpression().getText() === "handlePocketbase");
|
|
29
|
+
if (!i) return {
|
|
30
|
+
status: "failed",
|
|
31
|
+
message: s
|
|
32
|
+
};
|
|
33
|
+
let l = i.getArguments();
|
|
34
|
+
if (l.length === 0) return i.addArgument("{ api: { enabled: true } }"), n.formatText(), n.saveSync(), {
|
|
35
|
+
status: "success",
|
|
36
|
+
changed: !0
|
|
37
|
+
};
|
|
38
|
+
let u = l[0];
|
|
39
|
+
if (u.getKind() !== o.ObjectLiteralExpression) return i.insertArgument(0, "{ api: { enabled: true } }"), n.formatText(), n.saveSync(), {
|
|
40
|
+
status: "success",
|
|
41
|
+
changed: !0
|
|
42
|
+
};
|
|
43
|
+
let d = u.asKindOrThrow(o.ObjectLiteralExpression), f = d.getProperty("api");
|
|
44
|
+
if (!f) return d.addPropertyAssignment({
|
|
45
|
+
name: "api",
|
|
46
|
+
initializer: "{ enabled: true }"
|
|
47
|
+
}), n.formatText(), n.saveSync(), {
|
|
48
|
+
status: "success",
|
|
49
|
+
changed: !0
|
|
50
|
+
};
|
|
51
|
+
if (f.getKind() === o.PropertyAssignment) {
|
|
52
|
+
let e = f.getInitializer();
|
|
53
|
+
if (e && e.getKind() === o.ObjectLiteralExpression) {
|
|
54
|
+
let t = e;
|
|
55
|
+
t.getProperty("enabled") || t.addPropertyAssignment({
|
|
56
|
+
name: "enabled",
|
|
57
|
+
initializer: "true"
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return n.formatText(), n.saveSync(), {
|
|
62
|
+
status: "success",
|
|
63
|
+
changed: n.getFullText() !== t
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/patterns/enable/api/generate.runtime.ts
|
|
68
|
+
async function u(e) {
|
|
69
|
+
let r = t(e), a = [];
|
|
70
|
+
r.info("Modifying hooks.server.ts");
|
|
71
|
+
let o = i.join(e.root, "src", "hooks.server.ts"), s = n(o, l(o));
|
|
72
|
+
return s && a.push(s), {
|
|
73
|
+
creates: [],
|
|
74
|
+
modifies: a,
|
|
75
|
+
deletes: [],
|
|
76
|
+
components: [],
|
|
77
|
+
packages: [],
|
|
78
|
+
collections: [],
|
|
79
|
+
collectionPatches: []
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
export { u as generate };
|
|
84
|
+
|
|
85
|
+
//# sourceMappingURL=generate.runtime-Caqa5ndO.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-Caqa5ndO.js","names":[],"sources":["../../src/patterns/enable/api/modifies/hooks.server.ts","../../src/patterns/enable/api/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst FAILURE_HINT = dedent`\n Configure handlePocketbase() with the api option in hooks.server.ts:\n\n handlePocketbase({\n api: { enabled: true },\n });\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create src/hooks.server.ts with handlePocketbase:\n\n import { handlePocketbase } from 'velastack/handle';\n\n export const handle = handlePocketbase({\n api: { enabled: true },\n });\n`;\n\nexport function modifyHooksServer(hooksServerPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\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: \"failed\", message: FAILURE_HINT };\n }\n\n const args = callExpr.getArguments();\n if (args.length === 0) {\n callExpr.addArgument(`{ api: { enabled: true } }`);\n sourceFile.formatText();\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const firstArg = args[0];\n if (firstArg.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n callExpr.insertArgument(0, `{ api: { enabled: true } }`);\n sourceFile.formatText();\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const optionsObj = firstArg.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n const apiProp = optionsObj.getProperty(\"api\");\n\n if (!apiProp) {\n optionsObj.addPropertyAssignment({\n name: \"api\",\n initializer: `{ enabled: true }`,\n });\n sourceFile.formatText();\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n if (apiProp.getKind() === SyntaxKind.PropertyAssignment) {\n const apiInit = (\n apiProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (apiInit && apiInit.getKind() === SyntaxKind.ObjectLiteralExpression) {\n const apiObj = apiInit as import(\"ts-morph\").ObjectLiteralExpression;\n const enabledProp = apiObj.getProperty(\"enabled\");\n if (!enabledProp) {\n apiObj.addPropertyAssignment({ name: \"enabled\", initializer: \"true\" });\n }\n }\n }\n\n sourceFile.formatText();\n sourceFile.saveSync();\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 { modifyHooksServer } 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 file = modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServer(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 } satisfies Result;\n}\n"],"mappings":";;;;;;;AAKA,IAAM,IAAe,CAAM;;;;;;GAQrB,IAAiB,CAAM;;;;;;;;;AAU7B,SAAgB,EAAkB,GAAwC;AACxE,KAAI,CAAC,EAAG,WAAW,EAAgB,CACjC,QAAO;EAAE,QAAQ;EAAa,SAAS;EAAgB;CAGzD,IAAM,IAAiB,EAAG,aAAa,GAAiB,OAAO,EAEzD,IADU,IAAI,GAAS,CACF,oBAAoB,EAAgB,EAEzD,IAAW,EACd,qBAAqB,EAAW,eAAe,CAC/C,MAAM,MAAO,EAAG,eAAe,CAAC,SAAS,KAAK,mBAAmB;AAEpE,KAAI,CAAC,EACH,QAAO;EAAE,QAAQ;EAAU,SAAS;EAAc;CAGpD,IAAM,IAAO,EAAS,cAAc;AACpC,KAAI,EAAK,WAAW,EAIlB,QAHA,EA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