paddle-checkout-accelerator 2.7.1 → 2.8.1

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.
@@ -118,6 +118,205 @@ function appendEnvSafe(values) {
118
118
  }
119
119
  }
120
120
 
121
+ function readPackageJson() {
122
+ const packagePath =
123
+ path.join(cwd, "package.json");
124
+
125
+ if (!fs.existsSync(packagePath)) {
126
+ return null;
127
+ }
128
+
129
+ try {
130
+ return JSON.parse(
131
+ fs.readFileSync(packagePath, "utf8")
132
+ );
133
+ } catch {
134
+ return null;
135
+ }
136
+ }
137
+
138
+ function hasDependency(pkg, name) {
139
+ if (!pkg) return false;
140
+
141
+ return Boolean(
142
+ pkg.dependencies?.[name] ||
143
+ pkg.devDependencies?.[name]
144
+ );
145
+ }
146
+
147
+ function detectAuthProvider() {
148
+ const pkg =
149
+ readPackageJson();
150
+
151
+ const providers = [];
152
+
153
+ if (
154
+ hasDependency(pkg, "@clerk/nextjs") ||
155
+ exists("middleware.ts") ||
156
+ exists("src/middleware.ts")
157
+ ) {
158
+ providers.push("clerk");
159
+ }
160
+
161
+ if (
162
+ hasDependency(pkg, "next-auth") ||
163
+ hasDependency(pkg, "@auth/core") ||
164
+ hasDependency(pkg, "@auth/nextjs") ||
165
+ exists("src/app/api/auth/[...nextauth]/route.ts") ||
166
+ exists("app/api/auth/[...nextauth]/route.ts")
167
+ ) {
168
+ providers.push("authjs");
169
+ }
170
+
171
+ if (
172
+ hasDependency(pkg, "@supabase/supabase-js") ||
173
+ hasDependency(pkg, "@supabase/ssr")
174
+ ) {
175
+ providers.push("supabase");
176
+ }
177
+
178
+ if (
179
+ hasDependency(pkg, "firebase") ||
180
+ hasDependency(pkg, "firebase-admin")
181
+ ) {
182
+ providers.push("firebase");
183
+ }
184
+
185
+ return providers;
186
+ }
187
+
188
+ function writeAuthHelper(provider) {
189
+ if (provider === "clerk") {
190
+ writeFileSafe(
191
+ "src/lib/billing-user.ts",
192
+ `import { auth } from "@clerk/nextjs/server";
193
+
194
+ export async function getBillingUserId() {
195
+ const { userId } = await auth();
196
+
197
+ if (!userId) {
198
+ throw new Error("User not authenticated");
199
+ }
200
+
201
+ return userId;
202
+ }
203
+ `
204
+ );
205
+ return;
206
+ }
207
+
208
+ if (provider === "authjs") {
209
+ writeFileSafe(
210
+ "src/lib/billing-user.ts",
211
+ `import { auth } from "@/auth";
212
+
213
+ export async function getBillingUserId() {
214
+ const session = await auth();
215
+
216
+ const userId =
217
+ session?.user?.id ||
218
+ session?.user?.email;
219
+
220
+ if (!userId) {
221
+ throw new Error("User not authenticated");
222
+ }
223
+
224
+ return userId;
225
+ }
226
+ `
227
+ );
228
+ return;
229
+ }
230
+
231
+ if (provider === "supabase") {
232
+ writeFileSafe(
233
+ "src/lib/billing-user.ts",
234
+ `import { createClient } from "@/lib/supabase/server";
235
+
236
+ export async function getBillingUserId() {
237
+ const supabase =
238
+ await createClient();
239
+
240
+ const {
241
+ data: { user },
242
+ } = await supabase.auth.getUser();
243
+
244
+ if (!user?.id) {
245
+ throw new Error("User not authenticated");
246
+ }
247
+
248
+ return user.id;
249
+ }
250
+ `
251
+ );
252
+ return;
253
+ }
254
+
255
+ if (provider === "firebase") {
256
+ writeFileSafe(
257
+ "src/lib/billing-user.ts",
258
+ `export async function getBillingUserId() {
259
+ throw new Error(
260
+ "Firebase billing user helper requires your app-specific auth token verification."
261
+ );
262
+ }
263
+ `
264
+ );
265
+ return;
266
+ }
267
+
268
+ writeFileSafe(
269
+ "src/lib/billing-user.ts",
270
+ `export async function getBillingUserId() {
271
+ throw new Error(
272
+ "No auth provider detected. Return your authenticated user id here."
273
+ );
274
+ }
275
+ `
276
+ );
277
+ }
278
+
279
+ function runAuth() {
280
+ const providers =
281
+ detectAuthProvider();
282
+
283
+ console.log("");
284
+ console.log("Paddle Checkout Accelerator Auth Detection");
285
+ console.log("");
286
+
287
+ if (providers.length === 0) {
288
+ console.log("❌ No supported auth provider detected");
289
+ console.log("");
290
+ console.log("Supported providers:");
291
+ console.log("- Clerk");
292
+ console.log("- Auth.js / NextAuth");
293
+ console.log("- Supabase");
294
+ console.log("- Firebase");
295
+ console.log("");
296
+ console.log("Generated generic billing user helper.");
297
+ writeAuthHelper("custom");
298
+ process.exit(1);
299
+ }
300
+
301
+ for (const provider of providers) {
302
+ console.log(`✅ ${provider} detected`);
303
+ }
304
+
305
+ const selected =
306
+ providers[0];
307
+
308
+ console.log("");
309
+ console.log(`Using ${selected} for billing user helper.`);
310
+
311
+ writeAuthHelper(selected);
312
+
313
+ console.log("");
314
+ console.log("Created billing user helper:");
315
+ console.log(" src/lib/billing-user.ts");
316
+
317
+ process.exit(0);
318
+ }
319
+
121
320
  function readEnvFile() {
122
321
  const envPath =
123
322
  path.join(cwd, ".env.local");
@@ -229,6 +428,7 @@ function runDoctor() {
229
428
  console.log("Fix the missing items above, then run:");
230
429
  console.log(" npx paddle-checkout-accelerator doctor");
231
430
  console.log(" npx paddle-checkout-accelerator verify");
431
+ console.log(" npx paddle-checkout-accelerator auth");
232
432
 
233
433
  process.exit(1);
234
434
  }
@@ -974,6 +1174,7 @@ Usage:
974
1174
  npx paddle-checkout-accelerator init --force
975
1175
  npx paddle-checkout-accelerator doctor
976
1176
  npx paddle-checkout-accelerator verify
1177
+ npx paddle-checkout-accelerator auth
977
1178
  npx paddle-checkout-accelerator init --minimal
978
1179
  `);
979
1180
  process.exit(0);
@@ -987,6 +1188,10 @@ Usage:
987
1188
  await runVerify();
988
1189
  }
989
1190
 
1191
+ if (command === "auth") {
1192
+ runAuth();
1193
+ }
1194
+
990
1195
  if (command !== "init") {
991
1196
  console.error(
992
1197
  `Unknown command: ${command}`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paddle-checkout-accelerator",
3
- "version": "2.7.1",
3
+ "version": "2.8.1",
4
4
  "scripts": {
5
5
  "dev": "next dev",
6
6
  "build": "next build",