@dream-api/sdk 0.1.33 → 0.1.35
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/index.d.mts +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +48 -3
- package/dist/index.mjs +48 -3
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -325,6 +325,28 @@ declare class AuthHelpers {
|
|
|
325
325
|
getCustomerPortalUrl(options?: {
|
|
326
326
|
returnUrl?: string;
|
|
327
327
|
}): string;
|
|
328
|
+
/**
|
|
329
|
+
* Get the refresh URL for updating JWT after plan changes.
|
|
330
|
+
*
|
|
331
|
+
* Use this as Stripe's success_url to ensure the JWT is refreshed
|
|
332
|
+
* with updated plan metadata after checkout completes.
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* ```typescript
|
|
336
|
+
* const refreshUrl = api.auth.getRefreshUrl({ redirect: '/dashboard' });
|
|
337
|
+
* // Use as Stripe success_url
|
|
338
|
+
* await api.billing.createCheckout({
|
|
339
|
+
* tier: 'pro',
|
|
340
|
+
* successUrl: refreshUrl,
|
|
341
|
+
* });
|
|
342
|
+
* ```
|
|
343
|
+
*/
|
|
344
|
+
getRefreshUrl(options: AuthUrlOptions): string;
|
|
345
|
+
/**
|
|
346
|
+
* Convert a relative path to an absolute URL using current origin.
|
|
347
|
+
* Already-absolute URLs are returned unchanged.
|
|
348
|
+
*/
|
|
349
|
+
private makeAbsoluteUrl;
|
|
328
350
|
}
|
|
329
351
|
|
|
330
352
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -325,6 +325,28 @@ declare class AuthHelpers {
|
|
|
325
325
|
getCustomerPortalUrl(options?: {
|
|
326
326
|
returnUrl?: string;
|
|
327
327
|
}): string;
|
|
328
|
+
/**
|
|
329
|
+
* Get the refresh URL for updating JWT after plan changes.
|
|
330
|
+
*
|
|
331
|
+
* Use this as Stripe's success_url to ensure the JWT is refreshed
|
|
332
|
+
* with updated plan metadata after checkout completes.
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* ```typescript
|
|
336
|
+
* const refreshUrl = api.auth.getRefreshUrl({ redirect: '/dashboard' });
|
|
337
|
+
* // Use as Stripe success_url
|
|
338
|
+
* await api.billing.createCheckout({
|
|
339
|
+
* tier: 'pro',
|
|
340
|
+
* successUrl: refreshUrl,
|
|
341
|
+
* });
|
|
342
|
+
* ```
|
|
343
|
+
*/
|
|
344
|
+
getRefreshUrl(options: AuthUrlOptions): string;
|
|
345
|
+
/**
|
|
346
|
+
* Convert a relative path to an absolute URL using current origin.
|
|
347
|
+
* Already-absolute URLs are returned unchanged.
|
|
348
|
+
*/
|
|
349
|
+
private makeAbsoluteUrl;
|
|
328
350
|
}
|
|
329
351
|
|
|
330
352
|
/**
|
package/dist/index.js
CHANGED
|
@@ -478,9 +478,10 @@ var AuthHelpers = class {
|
|
|
478
478
|
throw new Error("DreamAPI: publishableKey required for auth URLs");
|
|
479
479
|
}
|
|
480
480
|
const baseUrl = this.client.getSignupBaseUrl();
|
|
481
|
+
const redirectUrl = this.makeAbsoluteUrl(options.redirect);
|
|
481
482
|
const params = new URLSearchParams({
|
|
482
483
|
pk,
|
|
483
|
-
redirect:
|
|
484
|
+
redirect: redirectUrl
|
|
484
485
|
});
|
|
485
486
|
return `${baseUrl}/signup?${params.toString()}`;
|
|
486
487
|
}
|
|
@@ -502,9 +503,10 @@ var AuthHelpers = class {
|
|
|
502
503
|
throw new Error("DreamAPI: publishableKey required for auth URLs");
|
|
503
504
|
}
|
|
504
505
|
const baseUrl = this.client.getSignupBaseUrl();
|
|
506
|
+
const redirectUrl = this.makeAbsoluteUrl(options.redirect);
|
|
505
507
|
const params = new URLSearchParams({
|
|
506
508
|
pk,
|
|
507
|
-
redirect:
|
|
509
|
+
redirect: redirectUrl
|
|
508
510
|
});
|
|
509
511
|
return `${baseUrl}/signin?${params.toString()}`;
|
|
510
512
|
}
|
|
@@ -530,12 +532,55 @@ var AuthHelpers = class {
|
|
|
530
532
|
}
|
|
531
533
|
const baseUrl = this.client.getSignupBaseUrl();
|
|
532
534
|
const returnUrl = options?.returnUrl || (typeof window !== "undefined" ? window.location.href : "/");
|
|
535
|
+
const redirectUrl = this.makeAbsoluteUrl(returnUrl);
|
|
533
536
|
const params = new URLSearchParams({
|
|
534
537
|
pk,
|
|
535
|
-
redirect:
|
|
538
|
+
redirect: redirectUrl
|
|
536
539
|
});
|
|
537
540
|
return `${baseUrl}/account?${params.toString()}`;
|
|
538
541
|
}
|
|
542
|
+
/**
|
|
543
|
+
* Get the refresh URL for updating JWT after plan changes.
|
|
544
|
+
*
|
|
545
|
+
* Use this as Stripe's success_url to ensure the JWT is refreshed
|
|
546
|
+
* with updated plan metadata after checkout completes.
|
|
547
|
+
*
|
|
548
|
+
* @example
|
|
549
|
+
* ```typescript
|
|
550
|
+
* const refreshUrl = api.auth.getRefreshUrl({ redirect: '/dashboard' });
|
|
551
|
+
* // Use as Stripe success_url
|
|
552
|
+
* await api.billing.createCheckout({
|
|
553
|
+
* tier: 'pro',
|
|
554
|
+
* successUrl: refreshUrl,
|
|
555
|
+
* });
|
|
556
|
+
* ```
|
|
557
|
+
*/
|
|
558
|
+
getRefreshUrl(options) {
|
|
559
|
+
const pk = this.client.getPublishableKey();
|
|
560
|
+
if (!pk) {
|
|
561
|
+
throw new Error("DreamAPI: publishableKey required for auth URLs");
|
|
562
|
+
}
|
|
563
|
+
const baseUrl = this.client.getSignupBaseUrl();
|
|
564
|
+
const redirectUrl = this.makeAbsoluteUrl(options.redirect);
|
|
565
|
+
const params = new URLSearchParams({
|
|
566
|
+
pk,
|
|
567
|
+
redirect: redirectUrl
|
|
568
|
+
});
|
|
569
|
+
return `${baseUrl}/refresh?${params.toString()}`;
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* Convert a relative path to an absolute URL using current origin.
|
|
573
|
+
* Already-absolute URLs are returned unchanged.
|
|
574
|
+
*/
|
|
575
|
+
makeAbsoluteUrl(path) {
|
|
576
|
+
if (path.startsWith("http://") || path.startsWith("https://")) {
|
|
577
|
+
return path;
|
|
578
|
+
}
|
|
579
|
+
if (typeof window !== "undefined") {
|
|
580
|
+
return new URL(path, window.location.origin).toString();
|
|
581
|
+
}
|
|
582
|
+
return path;
|
|
583
|
+
}
|
|
539
584
|
};
|
|
540
585
|
|
|
541
586
|
// src/index.ts
|
package/dist/index.mjs
CHANGED
|
@@ -450,9 +450,10 @@ var AuthHelpers = class {
|
|
|
450
450
|
throw new Error("DreamAPI: publishableKey required for auth URLs");
|
|
451
451
|
}
|
|
452
452
|
const baseUrl = this.client.getSignupBaseUrl();
|
|
453
|
+
const redirectUrl = this.makeAbsoluteUrl(options.redirect);
|
|
453
454
|
const params = new URLSearchParams({
|
|
454
455
|
pk,
|
|
455
|
-
redirect:
|
|
456
|
+
redirect: redirectUrl
|
|
456
457
|
});
|
|
457
458
|
return `${baseUrl}/signup?${params.toString()}`;
|
|
458
459
|
}
|
|
@@ -474,9 +475,10 @@ var AuthHelpers = class {
|
|
|
474
475
|
throw new Error("DreamAPI: publishableKey required for auth URLs");
|
|
475
476
|
}
|
|
476
477
|
const baseUrl = this.client.getSignupBaseUrl();
|
|
478
|
+
const redirectUrl = this.makeAbsoluteUrl(options.redirect);
|
|
477
479
|
const params = new URLSearchParams({
|
|
478
480
|
pk,
|
|
479
|
-
redirect:
|
|
481
|
+
redirect: redirectUrl
|
|
480
482
|
});
|
|
481
483
|
return `${baseUrl}/signin?${params.toString()}`;
|
|
482
484
|
}
|
|
@@ -502,12 +504,55 @@ var AuthHelpers = class {
|
|
|
502
504
|
}
|
|
503
505
|
const baseUrl = this.client.getSignupBaseUrl();
|
|
504
506
|
const returnUrl = options?.returnUrl || (typeof window !== "undefined" ? window.location.href : "/");
|
|
507
|
+
const redirectUrl = this.makeAbsoluteUrl(returnUrl);
|
|
505
508
|
const params = new URLSearchParams({
|
|
506
509
|
pk,
|
|
507
|
-
redirect:
|
|
510
|
+
redirect: redirectUrl
|
|
508
511
|
});
|
|
509
512
|
return `${baseUrl}/account?${params.toString()}`;
|
|
510
513
|
}
|
|
514
|
+
/**
|
|
515
|
+
* Get the refresh URL for updating JWT after plan changes.
|
|
516
|
+
*
|
|
517
|
+
* Use this as Stripe's success_url to ensure the JWT is refreshed
|
|
518
|
+
* with updated plan metadata after checkout completes.
|
|
519
|
+
*
|
|
520
|
+
* @example
|
|
521
|
+
* ```typescript
|
|
522
|
+
* const refreshUrl = api.auth.getRefreshUrl({ redirect: '/dashboard' });
|
|
523
|
+
* // Use as Stripe success_url
|
|
524
|
+
* await api.billing.createCheckout({
|
|
525
|
+
* tier: 'pro',
|
|
526
|
+
* successUrl: refreshUrl,
|
|
527
|
+
* });
|
|
528
|
+
* ```
|
|
529
|
+
*/
|
|
530
|
+
getRefreshUrl(options) {
|
|
531
|
+
const pk = this.client.getPublishableKey();
|
|
532
|
+
if (!pk) {
|
|
533
|
+
throw new Error("DreamAPI: publishableKey required for auth URLs");
|
|
534
|
+
}
|
|
535
|
+
const baseUrl = this.client.getSignupBaseUrl();
|
|
536
|
+
const redirectUrl = this.makeAbsoluteUrl(options.redirect);
|
|
537
|
+
const params = new URLSearchParams({
|
|
538
|
+
pk,
|
|
539
|
+
redirect: redirectUrl
|
|
540
|
+
});
|
|
541
|
+
return `${baseUrl}/refresh?${params.toString()}`;
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Convert a relative path to an absolute URL using current origin.
|
|
545
|
+
* Already-absolute URLs are returned unchanged.
|
|
546
|
+
*/
|
|
547
|
+
makeAbsoluteUrl(path) {
|
|
548
|
+
if (path.startsWith("http://") || path.startsWith("https://")) {
|
|
549
|
+
return path;
|
|
550
|
+
}
|
|
551
|
+
if (typeof window !== "undefined") {
|
|
552
|
+
return new URL(path, window.location.origin).toString();
|
|
553
|
+
}
|
|
554
|
+
return path;
|
|
555
|
+
}
|
|
511
556
|
};
|
|
512
557
|
|
|
513
558
|
// src/index.ts
|