@paddle/better-auth 0.1.0 → 0.1.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.
- package/README.md +5 -3
- package/dist/index.js +6 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -367,7 +367,8 @@ await authClient.paddle.subscription.restore();
|
|
|
367
367
|
```
|
|
368
368
|
|
|
369
369
|
`restore` only works while a cancellation or pause is *scheduled*; it returns a `400` once the
|
|
370
|
-
subscription has actually canceled or paused, or when nothing is scheduled.
|
|
370
|
+
subscription has actually canceled or paused, or when nothing is scheduled. It checks Paddle
|
|
371
|
+
rather than the local table, so it works straight after `cancel` or `pause`, before the webhook arrives.
|
|
371
372
|
|
|
372
373
|
### Pause and resume
|
|
373
374
|
|
|
@@ -383,8 +384,9 @@ await authClient.paddle.subscription.resume();
|
|
|
383
384
|
await authClient.paddle.subscription.resume({ onResume: "continue_existing_billing_period" });
|
|
384
385
|
```
|
|
385
386
|
|
|
386
|
-
`resume` only works on a subscription that is actually `paused`, and returns a `400` otherwise.
|
|
387
|
-
|
|
387
|
+
`resume` only works on a subscription that is actually `paused`, and returns a `400` otherwise. Like
|
|
388
|
+
`restore`, it checks Paddle rather than the local table. To cancel a pause that is still scheduled,
|
|
389
|
+
use `restore`. `onResume` is passed through to Paddle, which
|
|
388
390
|
defaults to `start_new_billing_period`.
|
|
389
391
|
|
|
390
392
|
Pausing revokes access and resuming grants it again, through `onRevokeAccess` / `onGrantAccess`, once
|
package/dist/index.js
CHANGED
|
@@ -240,13 +240,8 @@ async function findOwnedSubscription(ctx, subscriptionId) {
|
|
|
240
240
|
return active[0];
|
|
241
241
|
}
|
|
242
242
|
var RESTORABLE_ACTIONS = /* @__PURE__ */ new Set(["cancel", "pause"]);
|
|
243
|
-
function
|
|
244
|
-
|
|
245
|
-
try {
|
|
246
|
-
return JSON.parse(row.scheduledChange).action ?? null;
|
|
247
|
-
} catch {
|
|
248
|
-
return null;
|
|
249
|
-
}
|
|
243
|
+
function fetchLiveSubscription(options, row) {
|
|
244
|
+
return withPaddleErrors(() => options.paddleClient.subscriptions.get(row.paddleSubscriptionId));
|
|
250
245
|
}
|
|
251
246
|
var subscriptionList = (_options) => createAuthEndpoint3(
|
|
252
247
|
"/paddle/subscription/list",
|
|
@@ -288,7 +283,8 @@ var subscriptionRestore = (options) => createAuthEndpoint3(
|
|
|
288
283
|
},
|
|
289
284
|
async (ctx) => {
|
|
290
285
|
const row = await findOwnedSubscription(ctx, ctx.body.subscriptionId);
|
|
291
|
-
const
|
|
286
|
+
const live = await fetchLiveSubscription(options, row);
|
|
287
|
+
const action = live.scheduledChange?.action;
|
|
292
288
|
if (!action || !RESTORABLE_ACTIONS.has(action)) {
|
|
293
289
|
throw new APIError4("BAD_REQUEST", { message: "No scheduled cancellation or pause to restore" });
|
|
294
290
|
}
|
|
@@ -332,7 +328,8 @@ var subscriptionResume = (options) => createAuthEndpoint3(
|
|
|
332
328
|
},
|
|
333
329
|
async (ctx) => {
|
|
334
330
|
const row = await findOwnedSubscription(ctx, ctx.body.subscriptionId);
|
|
335
|
-
|
|
331
|
+
const live = await fetchLiveSubscription(options, row);
|
|
332
|
+
if (live.status !== "paused") {
|
|
336
333
|
throw new APIError4("BAD_REQUEST", { message: "Subscription is not paused" });
|
|
337
334
|
}
|
|
338
335
|
const result = await withPaddleErrors(
|