@velastack/patterns 0.0.35 → 0.0.37
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-DQbbH7sz.js} +73 -5
- package/dist/chunks/collections-DQbbH7sz.js.map +1 -0
- package/dist/chunks/env-CU-NtvJ7.js +67 -0
- package/dist/chunks/env-CU-NtvJ7.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-B3ygXsYo.js +116 -0
- package/dist/chunks/generate.runtime-B3ygXsYo.js.map +1 -0
- package/dist/chunks/generate.runtime-BK3U_cCw.js +65 -0
- package/dist/chunks/generate.runtime-BK3U_cCw.js.map +1 -0
- package/dist/chunks/{generate.runtime-D7ksYerH.js → generate.runtime-CN5PiWOK.js} +7 -6
- package/dist/chunks/{generate.runtime-D7ksYerH.js.map → generate.runtime-CN5PiWOK.js.map} +1 -1
- package/dist/chunks/generate.runtime-Ci13Xrz_.js +107 -0
- package/dist/chunks/generate.runtime-Ci13Xrz_.js.map +1 -0
- package/dist/chunks/generate.runtime-D5I9Pe1O.js +93 -0
- package/dist/chunks/generate.runtime-D5I9Pe1O.js.map +1 -0
- package/dist/chunks/generate.runtime-D5ZkXanM.js +60 -0
- package/dist/chunks/generate.runtime-D5ZkXanM.js.map +1 -0
- package/dist/chunks/{generate.runtime-Caqa5ndO.js → generate.runtime-DFW9vKsO.js} +4 -3
- package/dist/chunks/{generate.runtime-Caqa5ndO.js.map → generate.runtime-DFW9vKsO.js.map} +1 -1
- package/dist/chunks/generate.runtime-DG7GcbJr.js +210 -0
- package/dist/chunks/generate.runtime-DG7GcbJr.js.map +1 -0
- package/dist/chunks/{generate.runtime-Cbq2649r.js → generate.runtime-DRx_VMuc.js} +29 -28
- package/dist/chunks/{generate.runtime-Cbq2649r.js.map → generate.runtime-DRx_VMuc.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CZKIdbEC.js → generate.runtime-DedHJlsZ.js} +54 -53
- package/dist/chunks/{generate.runtime-CZKIdbEC.js.map → generate.runtime-DedHJlsZ.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BVss5za4.js → generate.runtime-Df6qRZMP.js} +166 -135
- package/dist/chunks/generate.runtime-Df6qRZMP.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-DTZ1PeDS.js → generate.runtime-GoC73zRO.js} +27 -26
- package/dist/chunks/{generate.runtime-DTZ1PeDS.js.map → generate.runtime-GoC73zRO.js.map} +1 -1
- package/dist/chunks/generate.runtime-Vvjaa4sc.js +224 -0
- package/dist/chunks/generate.runtime-Vvjaa4sc.js.map +1 -0
- package/dist/chunks/generate.runtime-fifS2KJv.js +135 -0
- package/dist/chunks/generate.runtime-fifS2KJv.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-BcZVx_jI.js} +1 -1
- package/dist/chunks/{modify-svelte-config-remote-CFsA9Mom.js.map → modify-svelte-config-remote-BcZVx_jI.js.map} +1 -1
- package/dist/chunks/{pocketbase-iFJBbNJu.js → pocketbase-4_89gk_J.js} +1 -1
- package/dist/chunks/{pocketbase-iFJBbNJu.js.map → pocketbase-4_89gk_J.js.map} +1 -1
- package/dist/chunks/shared--goBUhsB.js +27 -0
- package/dist/chunks/shared--goBUhsB.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-BuZpAeOf.js} +12 -7
- package/dist/chunks/{write-result-CqSY1Bww.js.map → write-result-BuZpAeOf.js.map} +1 -1
- package/dist/index.d.ts +912 -209
- package/dist/index.js +1946 -872
- 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--31y_UK2.js +0 -214
- package/dist/chunks/generate.runtime--31y_UK2.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-CU-NtvJ7.js";
|
|
8
|
+
import { getMigrationFile as c, migrationDelay as l, withPocketbase as u } from "./pocketbase-4_89gk_J.js";
|
|
9
|
+
import { createCollectionIdempotent as d } from "./collections-DQbbH7sz.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,63 @@ function E(t) {
|
|
|
156
157
|
};
|
|
157
158
|
}
|
|
158
159
|
//#endregion
|
|
159
|
-
//#region src/patterns/enable/payments/
|
|
160
|
-
function
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
160
|
+
//#region src/patterns/enable/payments/runtime/stripe.ts
|
|
161
|
+
async function O(e, t, n) {
|
|
162
|
+
let r = new v(t), i = await e.collection("users").getFullList(), a = await e.collection("stripe_customers").getFullList(), o = new Set(a.map((e) => e.user)), s = {
|
|
163
|
+
total: i.length,
|
|
164
|
+
linked: o.size,
|
|
165
|
+
created: 0,
|
|
166
|
+
reused: 0,
|
|
167
|
+
skipped: 0
|
|
168
|
+
};
|
|
169
|
+
for (let t of i) {
|
|
170
|
+
if (o.has(t.id)) {
|
|
171
|
+
s.skipped += 1;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (!t.email) {
|
|
175
|
+
n.info(`Skipping user ${t.id} with no email`), s.skipped += 1;
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
let i = await r.customers.list({
|
|
179
|
+
email: t.email,
|
|
180
|
+
limit: 1,
|
|
181
|
+
expand: ["data.invoice_settings"]
|
|
182
|
+
}), a, c = !1;
|
|
183
|
+
i.data.length > 0 ? (a = i.data[0], c = !0, s.reused += 1, n.info(`Reusing Stripe customer ${a.id} for ${t.email}`)) : (a = await r.customers.create({ email: t.email }), s.created += 1, n.info(`Created Stripe customer ${a.id} for ${t.email}`));
|
|
184
|
+
try {
|
|
185
|
+
await e.collection("stripe_customers").create({
|
|
186
|
+
id: a.id,
|
|
187
|
+
user: t.id
|
|
188
|
+
});
|
|
189
|
+
} catch (e) {
|
|
190
|
+
n.info(`Failed to create stripe_customers row for ${t.email}: ${e.message}`);
|
|
169
191
|
continue;
|
|
170
192
|
}
|
|
171
|
-
|
|
193
|
+
if (!c) continue;
|
|
194
|
+
let l = await r.customers.listPaymentMethods(a.id, {
|
|
195
|
+
type: "card",
|
|
196
|
+
allow_redisplay: "always"
|
|
197
|
+
});
|
|
198
|
+
for (let t of l.data) if (t.allow_redisplay !== "unspecified") try {
|
|
199
|
+
await e.collection("stripe_payment_methods").create({
|
|
200
|
+
id: t.id,
|
|
201
|
+
customer: a.id,
|
|
202
|
+
brand: t.card?.brand,
|
|
203
|
+
last4: t.card?.last4,
|
|
204
|
+
exp_month: t.card?.exp_month,
|
|
205
|
+
exp_year: t.card?.exp_year
|
|
206
|
+
});
|
|
207
|
+
} catch {}
|
|
208
|
+
let u = a.invoice_settings?.default_payment_method;
|
|
209
|
+
if (u) try {
|
|
210
|
+
await e.collection("stripe_customers").update(a.id, { default_payment_method: typeof u == "string" ? u : u.id });
|
|
211
|
+
} catch {}
|
|
172
212
|
}
|
|
173
|
-
return
|
|
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
|
-
});
|
|
213
|
+
return s;
|
|
184
214
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
async function A(e) {
|
|
188
|
-
let t = new _(e), n = await t.products.search({
|
|
215
|
+
async function k(e) {
|
|
216
|
+
let t = new v(e), n = await t.products.search({
|
|
189
217
|
query: "name:\"Test Product\" AND metadata[\"test\"]:\"true\"",
|
|
190
218
|
limit: 1
|
|
191
219
|
});
|
|
@@ -215,8 +243,8 @@ async function A(e) {
|
|
|
215
243
|
existing: !1
|
|
216
244
|
};
|
|
217
245
|
}
|
|
218
|
-
async function
|
|
219
|
-
let n = new
|
|
246
|
+
async function A(e, t) {
|
|
247
|
+
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
248
|
return r.product = i.id, {
|
|
221
249
|
product: i,
|
|
222
250
|
price: r,
|
|
@@ -225,27 +253,27 @@ async function j(e, t) {
|
|
|
225
253
|
}
|
|
226
254
|
//#endregion
|
|
227
255
|
//#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:
|
|
256
|
+
var j;
|
|
257
|
+
async function M(e, n, r, i, a = !0) {
|
|
258
|
+
if (!a) return;
|
|
259
|
+
await l();
|
|
260
|
+
let o = c(n, r, i);
|
|
261
|
+
o && e.push({
|
|
262
|
+
path: o,
|
|
263
|
+
language: t(o),
|
|
264
|
+
content: f.readFileSync(o, "utf8"),
|
|
237
265
|
status: "success"
|
|
238
266
|
});
|
|
239
267
|
}
|
|
240
|
-
function
|
|
241
|
-
return e(
|
|
268
|
+
function N(t) {
|
|
269
|
+
return e(j ||= 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
270
|
}
|
|
243
|
-
async function
|
|
244
|
-
let { stripeSecretKey: t, stripePublishableKey: n, stripeWebhookSecret:
|
|
245
|
-
e &&
|
|
271
|
+
async function P(e) {
|
|
272
|
+
let { stripeSecretKey: t, stripePublishableKey: n, stripeWebhookSecret: a, stripePriceId: o } = e.input, c = e.features.auth, l = r(e), f = [], m = [], h = (e) => {
|
|
273
|
+
e && m.push(e);
|
|
246
274
|
};
|
|
247
|
-
|
|
248
|
-
let
|
|
275
|
+
l.info("Writing Stripe credentials to .env");
|
|
276
|
+
let g = _(16).toString("hex"), v = [
|
|
249
277
|
{
|
|
250
278
|
type: "comment",
|
|
251
279
|
key: "Stripe credentials"
|
|
@@ -263,17 +291,17 @@ async function F(e) {
|
|
|
263
291
|
{
|
|
264
292
|
type: "var",
|
|
265
293
|
key: "STRIPE_WEBHOOK_SECRET",
|
|
266
|
-
value:
|
|
294
|
+
value: a
|
|
267
295
|
},
|
|
268
296
|
{
|
|
269
297
|
type: "var",
|
|
270
298
|
key: "INTERNAL_JOB_SECRET",
|
|
271
|
-
value:
|
|
299
|
+
value: g
|
|
272
300
|
}
|
|
273
|
-
],
|
|
274
|
-
|
|
275
|
-
let
|
|
276
|
-
if (
|
|
301
|
+
], y = p.join(e.root, ".env");
|
|
302
|
+
h(i(y, s(y, v))), await u(e.root, async (n) => {
|
|
303
|
+
let r = (e) => d(n, e, l);
|
|
304
|
+
if (l.info("Creating stripe_products collection"), await M(f, "stripe_products", "created", e, (await r({
|
|
277
305
|
name: "stripe_products",
|
|
278
306
|
type: "base",
|
|
279
307
|
fields: [
|
|
@@ -313,7 +341,7 @@ async function F(e) {
|
|
|
313
341
|
type: "autodate"
|
|
314
342
|
}
|
|
315
343
|
]
|
|
316
|
-
})).created),
|
|
344
|
+
})).created), l.info("Creating stripe_prices collection"), await M(f, "stripe_prices", "created", e, (await r({
|
|
317
345
|
name: "stripe_prices",
|
|
318
346
|
type: "base",
|
|
319
347
|
fields: [
|
|
@@ -373,9 +401,9 @@ async function F(e) {
|
|
|
373
401
|
type: "autodate"
|
|
374
402
|
}
|
|
375
403
|
]
|
|
376
|
-
})).created),
|
|
377
|
-
|
|
378
|
-
let
|
|
404
|
+
})).created), c) {
|
|
405
|
+
l.info("Creating stripe_customers collection");
|
|
406
|
+
let i = await r({
|
|
379
407
|
name: "stripe_customers",
|
|
380
408
|
type: "base",
|
|
381
409
|
fields: [
|
|
@@ -408,9 +436,9 @@ async function F(e) {
|
|
|
408
436
|
type: "autodate"
|
|
409
437
|
}
|
|
410
438
|
]
|
|
411
|
-
}),
|
|
412
|
-
await
|
|
413
|
-
let
|
|
439
|
+
}), a = i.collection;
|
|
440
|
+
await M(f, "stripe_customers", "created", e, i.created), l.info("Creating stripe_payment_methods collection");
|
|
441
|
+
let o = await r({
|
|
414
442
|
name: "stripe_payment_methods",
|
|
415
443
|
type: "base",
|
|
416
444
|
fields: [
|
|
@@ -443,7 +471,7 @@ async function F(e) {
|
|
|
443
471
|
type: "number"
|
|
444
472
|
},
|
|
445
473
|
{
|
|
446
|
-
collectionId:
|
|
474
|
+
collectionId: a.id,
|
|
447
475
|
maxSelect: 1,
|
|
448
476
|
minSelect: 0,
|
|
449
477
|
name: "customer",
|
|
@@ -464,8 +492,8 @@ async function F(e) {
|
|
|
464
492
|
type: "autodate"
|
|
465
493
|
}
|
|
466
494
|
]
|
|
467
|
-
}),
|
|
468
|
-
await
|
|
495
|
+
}), s = o.collection;
|
|
496
|
+
await M(f, "stripe_payment_methods", "created", e, o.created), l.info("Linking default_payment_method on stripe_customers"), await n.collections.update("stripe_customers", { fields: [
|
|
469
497
|
{
|
|
470
498
|
name: "id",
|
|
471
499
|
pattern: "^[a-zA-Z0-9_]+$",
|
|
@@ -483,7 +511,7 @@ async function F(e) {
|
|
|
483
511
|
type: "relation"
|
|
484
512
|
},
|
|
485
513
|
{
|
|
486
|
-
collectionId:
|
|
514
|
+
collectionId: s.id,
|
|
487
515
|
maxSelect: 1,
|
|
488
516
|
minSelect: 0,
|
|
489
517
|
name: "default_payment_method",
|
|
@@ -502,7 +530,7 @@ async function F(e) {
|
|
|
502
530
|
onUpdate: !0,
|
|
503
531
|
type: "autodate"
|
|
504
532
|
}
|
|
505
|
-
] }), await
|
|
533
|
+
] }), await M(f, "stripe_customers", "updated", e), l.info("Creating transactions collection"), await M(f, "transactions", "created", e, (await r({
|
|
506
534
|
name: "transactions",
|
|
507
535
|
type: "base",
|
|
508
536
|
fields: [
|
|
@@ -571,58 +599,61 @@ async function F(e) {
|
|
|
571
599
|
type: "url"
|
|
572
600
|
}
|
|
573
601
|
]
|
|
574
|
-
})).created);
|
|
602
|
+
})).created), l.info("Syncing existing PocketBase users to Stripe customers");
|
|
603
|
+
let c = await O(n, t, l);
|
|
604
|
+
l.info(`Synced ${c.total} users (created ${c.created}, reused ${c.reused}, skipped ${c.skipped})`);
|
|
575
605
|
}
|
|
576
|
-
}),
|
|
577
|
-
let { product:
|
|
578
|
-
if (
|
|
606
|
+
}), o ? l.info(`Fetching Stripe product/price ${o}`) : l.info("Creating test Stripe product and price");
|
|
607
|
+
let { product: b, price: x, existing: S } = o ? await A(t, o) : await k(t);
|
|
608
|
+
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
609
|
try {
|
|
580
|
-
await e.collection("stripe_products").getOne(
|
|
610
|
+
await e.collection("stripe_products").getOne(b.id);
|
|
581
611
|
} catch {
|
|
582
612
|
await e.collection("stripe_products").create({
|
|
583
|
-
id:
|
|
584
|
-
name:
|
|
585
|
-
active:
|
|
586
|
-
default_price:
|
|
613
|
+
id: b.id,
|
|
614
|
+
name: b.name,
|
|
615
|
+
active: b.active,
|
|
616
|
+
default_price: b.default_price
|
|
587
617
|
});
|
|
588
618
|
}
|
|
589
619
|
try {
|
|
590
|
-
await e.collection("stripe_prices").getOne(
|
|
620
|
+
await e.collection("stripe_prices").getOne(x.id);
|
|
591
621
|
} catch {
|
|
592
622
|
await e.collection("stripe_prices").create({
|
|
593
|
-
id:
|
|
594
|
-
billing_scheme:
|
|
595
|
-
currency:
|
|
596
|
-
product:
|
|
597
|
-
recurring:
|
|
598
|
-
type:
|
|
599
|
-
unit_amount:
|
|
600
|
-
active:
|
|
623
|
+
id: x.id,
|
|
624
|
+
billing_scheme: x.billing_scheme,
|
|
625
|
+
currency: x.currency,
|
|
626
|
+
product: x.product,
|
|
627
|
+
recurring: x.recurring,
|
|
628
|
+
type: x.type,
|
|
629
|
+
unit_amount: x.unit_amount,
|
|
630
|
+
active: x.active
|
|
601
631
|
});
|
|
602
632
|
}
|
|
603
|
-
}),
|
|
633
|
+
}), l.info("Creating payment +page.svelte"), f.push({
|
|
604
634
|
path: "src/routes/(public)/payment/+page.svelte",
|
|
605
635
|
language: "svelte",
|
|
606
|
-
content:
|
|
636
|
+
content: N(x.id),
|
|
607
637
|
status: "success"
|
|
608
|
-
}),
|
|
609
|
-
|
|
610
|
-
let t =
|
|
611
|
-
|
|
612
|
-
let n =
|
|
613
|
-
|
|
638
|
+
}), c) {
|
|
639
|
+
l.info("Modifying nav-user.svelte");
|
|
640
|
+
let t = p.join(e.root, "src", "lib", "components", "nav-user.svelte");
|
|
641
|
+
h(i(t, C(t))), l.info("Modifying signup +page.server.ts");
|
|
642
|
+
let n = p.join(e.root, "src", "routes", "(public)", "signup", "+page.server.ts");
|
|
643
|
+
h(i(n, D(n)));
|
|
614
644
|
}
|
|
615
645
|
return {
|
|
616
|
-
creates:
|
|
617
|
-
modifies:
|
|
646
|
+
creates: f,
|
|
647
|
+
modifies: m,
|
|
618
648
|
deletes: [],
|
|
619
649
|
components: [],
|
|
620
650
|
packages: [],
|
|
621
651
|
collections: [],
|
|
622
|
-
collectionPatches: []
|
|
652
|
+
collectionPatches: [],
|
|
653
|
+
collectionDrops: []
|
|
623
654
|
};
|
|
624
655
|
}
|
|
625
656
|
//#endregion
|
|
626
|
-
export {
|
|
657
|
+
export { P as generate };
|
|
627
658
|
|
|
628
|
-
//# sourceMappingURL=generate.runtime-
|
|
659
|
+
//# sourceMappingURL=generate.runtime-Df6qRZMP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.runtime-Df6qRZMP.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\";\nimport type PocketBase from \"pocketbase\";\nimport type { Logger } from \"../../../../core/logger\";\n\nexport interface StripeTestFixture {\n product: Stripe.Product;\n price: Stripe.Price;\n existing: boolean;\n}\n\nexport interface SyncUsersResult {\n total: number;\n linked: number;\n created: number;\n reused: number;\n skipped: number;\n}\n\nexport async function syncUsersToStripeCustomers(\n pb: PocketBase,\n stripeSecretKey: string,\n logger: Logger,\n): Promise<SyncUsersResult> {\n const stripe = new Stripe(stripeSecretKey);\n const users = await pb\n .collection(\"users\")\n .getFullList<{ id: string; email: string }>();\n\n const existing = await pb\n .collection(\"stripe_customers\")\n .getFullList<{ id: string; user: string }>();\n const linkedUserIds = new Set(existing.map((c) => c.user));\n\n const result: SyncUsersResult = {\n total: users.length,\n linked: linkedUserIds.size,\n created: 0,\n reused: 0,\n skipped: 0,\n };\n\n for (const user of users) {\n if (linkedUserIds.has(user.id)) {\n result.skipped += 1;\n continue;\n }\n\n if (!user.email) {\n logger.info(`Skipping user ${user.id} with no email`);\n result.skipped += 1;\n continue;\n }\n\n const matching = await stripe.customers.list({\n email: user.email,\n limit: 1,\n expand: [\"data.invoice_settings\"],\n });\n\n let customer: Stripe.Customer;\n let isExistingCustomer = false;\n\n if (matching.data.length > 0) {\n customer = matching.data[0];\n isExistingCustomer = true;\n result.reused += 1;\n logger.info(`Reusing Stripe customer ${customer.id} for ${user.email}`);\n } else {\n customer = await stripe.customers.create({ email: user.email });\n result.created += 1;\n logger.info(`Created Stripe customer ${customer.id} for ${user.email}`);\n }\n\n try {\n await pb.collection(\"stripe_customers\").create({\n id: customer.id,\n user: user.id,\n });\n } catch (error) {\n logger.info(\n `Failed to create stripe_customers row for ${user.email}: ${(error as Error).message}`,\n );\n continue;\n }\n\n if (!isExistingCustomer) {\n continue;\n }\n\n const paymentMethods = await stripe.customers.listPaymentMethods(\n customer.id,\n { type: \"card\", allow_redisplay: \"always\" },\n );\n\n for (const paymentMethod of paymentMethods.data) {\n if (paymentMethod.allow_redisplay === \"unspecified\") continue;\n try {\n await pb.collection(\"stripe_payment_methods\").create({\n id: paymentMethod.id,\n customer: customer.id,\n brand: paymentMethod.card?.brand,\n last4: paymentMethod.card?.last4,\n exp_month: paymentMethod.card?.exp_month,\n exp_year: paymentMethod.card?.exp_year,\n });\n } catch {}\n }\n\n const defaultPaymentMethod =\n customer.invoice_settings?.default_payment_method;\n if (defaultPaymentMethod) {\n try {\n await pb.collection(\"stripe_customers\").update(customer.id, {\n default_payment_method:\n typeof defaultPaymentMethod === \"string\"\n ? defaultPaymentMethod\n : defaultPaymentMethod.id,\n });\n } catch {}\n }\n }\n\n return result;\n}\n\nexport async function createTestProductAndPrice(\n stripeSecretKey: string,\n): Promise<StripeTestFixture> {\n const stripe = new Stripe(stripeSecretKey);\n\n const products = await stripe.products.search({\n query: `name:\"Test Product\" AND metadata[\"test\"]:\"true\"`,\n limit: 1,\n });\n\n if (products.data.length > 0) {\n const product = products.data[0];\n const prices = await stripe.prices.list({\n product: product.id,\n active: true,\n limit: 1,\n });\n if (prices.data.length > 0) {\n return { product, price: prices.data[0], existing: true };\n }\n }\n\n const product = await stripe.products.create({\n name: \"Test Product\",\n metadata: { test: \"true\" },\n });\n\n const price = await stripe.prices.create({\n product: product.id,\n unit_amount: 1000,\n currency: \"usd\",\n });\n\n return { product, price, existing: false };\n}\n\nexport async function getProductAndPriceById(\n stripeSecretKey: string,\n priceId: string,\n): Promise<StripeTestFixture> {\n const stripe = new Stripe(stripeSecretKey);\n const price = await stripe.prices.retrieve(priceId, { expand: [\"product\"] });\n const product =\n typeof price.product === \"string\"\n ? await stripe.products.retrieve(price.product)\n : (price.product as Stripe.Product);\n price.product = product.id;\n return { product, price, existing: true };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { 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 syncUsersToStripeCustomers,\n} from \"./runtime/stripe\";\n\nasync function pushMigrationCreates(\n creates: File[],\n collectionName: string,\n action: \"created\" | \"updated\",\n options: Options,\n created = true,\n) {\n if (!created) return;\n await migrationDelay();\n const migrationFile = getMigrationFile(collectionName, action, options);\n if (!migrationFile) return;\n creates.push({\n path: migrationFile,\n language: languageFromPath(migrationFile),\n content: fs.readFileSync(migrationFile, \"utf8\"),\n status: \"success\",\n });\n}\n\nfunction paymentPageSnippet(priceId: string): string {\n return dedent`\n <script lang=\"ts\">\n import PaymentButton from '$lib/components/payments/payment-button.svelte';\n </script>\n\n <section data-role=\"content\">\n <PaymentButton priceId=\"${priceId}\" />\n </section>\n `;\n}\n\nexport async function generate(options: Options) {\n const {\n stripeSecretKey,\n stripePublishableKey,\n stripeWebhookSecret,\n stripePriceId,\n } = options.input as {\n stripeSecretKey: string;\n stripePublishableKey: string;\n stripeWebhookSecret: string;\n stripePriceId?: string;\n };\n\n const isAppMode = options.features.auth;\n const logger = getLogger(options);\n const creates: File[] = [];\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Writing Stripe credentials to .env\");\n const 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 logger.info(\"Syncing existing PocketBase users to Stripe customers\");\n const syncResult = await syncUsersToStripeCustomers(\n pb,\n stripeSecretKey,\n logger,\n );\n logger.info(\n `Synced ${syncResult.total} users (created ${syncResult.created}, reused ${syncResult.reused}, skipped ${syncResult.skipped})`,\n );\n }\n });\n\n if (stripePriceId) {\n logger.info(`Fetching Stripe product/price ${stripePriceId}`);\n } else {\n logger.info(\"Creating test Stripe product and price\");\n }\n const { product, price, existing } = stripePriceId\n ? await getProductAndPriceById(stripeSecretKey, stripePriceId)\n : await createTestProductAndPrice(stripeSecretKey);\n\n if (existing) {\n logger.info(\"Stripe product/price already exists, skipping creation\");\n }\n\n logger.info(\"Seeding Stripe product/price records\");\n await withPocketbase(options.root, async (pb) => {\n try {\n await pb.collection(\"stripe_products\").getOne(product.id);\n } catch (error) {\n await pb.collection(\"stripe_products\").create({\n id: product.id,\n name: product.name,\n active: product.active,\n default_price: product.default_price,\n });\n }\n\n try {\n await pb.collection(\"stripe_prices\").getOne(price.id);\n } catch (error) {\n await pb.collection(\"stripe_prices\").create({\n id: price.id,\n billing_scheme: price.billing_scheme,\n currency: price.currency,\n product: price.product,\n recurring: price.recurring,\n type: price.type,\n unit_amount: price.unit_amount,\n active: price.active,\n });\n }\n });\n\n logger.info(\"Creating payment +page.svelte\");\n creates.push({\n path: \"src/routes/(public)/payment/+page.svelte\",\n language: \"svelte\",\n content: paymentPageSnippet(price.id),\n status: \"success\",\n });\n\n if (isAppMode) {\n logger.info(\"Modifying nav-user.svelte\");\n const navUserPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"nav-user.svelte\",\n );\n pushResult(modifyOutcomeToFile(navUserPath, modifyNavUser(navUserPath)));\n\n logger.info(\"Modifying signup +page.server.ts\");\n const userSignupPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(public)\",\n \"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;;;;ACr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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":";;;;;;AAIA,SAAgB,EAAoB,GAAwC;AAC1E,KAAI,CAAC,EAAG,WAAW,EAAgB,CACjC,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAG9C,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;EAAW,SAAS;EAAO;CAG9C,IAAM,IAAO,EAAS,cAAc;AACpC,KAAI,EAAK,WAAW,EAClB,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAG9C,IAAM,IAAW,EAAK;AACtB,KAAI,EAAS,SAAS,KAAK,EAAW,wBACpC,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAG9C,IAA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