@dream-api/sdk 0.1.29 → 0.1.31
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 +8 -6
- package/dist/index.d.ts +8 -6
- package/dist/index.js +36 -21
- package/dist/index.mjs +36 -21
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -297,8 +297,8 @@ declare class AuthHelpers {
|
|
|
297
297
|
/**
|
|
298
298
|
* Get the sign-in URL for returning users.
|
|
299
299
|
*
|
|
300
|
-
* Redirects to
|
|
301
|
-
* users are redirected to your specified URL.
|
|
300
|
+
* Redirects to our auth worker which embeds Clerk. After sign-in,
|
|
301
|
+
* users are redirected to your specified URL with JWT.
|
|
302
302
|
*
|
|
303
303
|
* @example
|
|
304
304
|
* ```typescript
|
|
@@ -310,19 +310,21 @@ declare class AuthHelpers {
|
|
|
310
310
|
/**
|
|
311
311
|
* Get the customer portal URL for account management.
|
|
312
312
|
*
|
|
313
|
-
* Redirects to
|
|
314
|
-
* manage their profile, password, and security settings.
|
|
313
|
+
* Redirects to our auth worker which embeds Clerk's UserProfile.
|
|
314
|
+
* Users can manage their profile, password, and security settings.
|
|
315
315
|
*
|
|
316
316
|
* Note: This is separate from billing management.
|
|
317
317
|
* For billing, use api.billing.openPortal().
|
|
318
318
|
*
|
|
319
319
|
* @example
|
|
320
320
|
* ```typescript
|
|
321
|
-
* const portalUrl = api.auth.getCustomerPortalUrl();
|
|
321
|
+
* const portalUrl = api.auth.getCustomerPortalUrl({ returnUrl: '/dashboard' });
|
|
322
322
|
* window.location.href = portalUrl;
|
|
323
323
|
* ```
|
|
324
324
|
*/
|
|
325
|
-
getCustomerPortalUrl(
|
|
325
|
+
getCustomerPortalUrl(options?: {
|
|
326
|
+
returnUrl?: string;
|
|
327
|
+
}): string;
|
|
326
328
|
}
|
|
327
329
|
|
|
328
330
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -297,8 +297,8 @@ declare class AuthHelpers {
|
|
|
297
297
|
/**
|
|
298
298
|
* Get the sign-in URL for returning users.
|
|
299
299
|
*
|
|
300
|
-
* Redirects to
|
|
301
|
-
* users are redirected to your specified URL.
|
|
300
|
+
* Redirects to our auth worker which embeds Clerk. After sign-in,
|
|
301
|
+
* users are redirected to your specified URL with JWT.
|
|
302
302
|
*
|
|
303
303
|
* @example
|
|
304
304
|
* ```typescript
|
|
@@ -310,19 +310,21 @@ declare class AuthHelpers {
|
|
|
310
310
|
/**
|
|
311
311
|
* Get the customer portal URL for account management.
|
|
312
312
|
*
|
|
313
|
-
* Redirects to
|
|
314
|
-
* manage their profile, password, and security settings.
|
|
313
|
+
* Redirects to our auth worker which embeds Clerk's UserProfile.
|
|
314
|
+
* Users can manage their profile, password, and security settings.
|
|
315
315
|
*
|
|
316
316
|
* Note: This is separate from billing management.
|
|
317
317
|
* For billing, use api.billing.openPortal().
|
|
318
318
|
*
|
|
319
319
|
* @example
|
|
320
320
|
* ```typescript
|
|
321
|
-
* const portalUrl = api.auth.getCustomerPortalUrl();
|
|
321
|
+
* const portalUrl = api.auth.getCustomerPortalUrl({ returnUrl: '/dashboard' });
|
|
322
322
|
* window.location.href = portalUrl;
|
|
323
323
|
* ```
|
|
324
324
|
*/
|
|
325
|
-
getCustomerPortalUrl(
|
|
325
|
+
getCustomerPortalUrl(options?: {
|
|
326
|
+
returnUrl?: string;
|
|
327
|
+
}): string;
|
|
326
328
|
}
|
|
327
329
|
|
|
328
330
|
/**
|
package/dist/index.js
CHANGED
|
@@ -184,15 +184,10 @@ var DreamClient = class {
|
|
|
184
184
|
};
|
|
185
185
|
|
|
186
186
|
// src/clerk.ts
|
|
187
|
-
|
|
188
|
-
if (typeof window === "undefined") return false;
|
|
189
|
-
const hostname = window.location.hostname;
|
|
190
|
-
return hostname === "localhost" || hostname === "127.0.0.1";
|
|
191
|
-
}
|
|
192
|
-
var CLERK_DEV_KEY = "pk_test_Y29tcG9zZWQtYmxvd2Zpc2gtNzYuY2xlcmsuYWNjb3VudHMuZGV2JA";
|
|
187
|
+
var CLERK_TEST_KEY = "pk_test_Y29tcG9zZWQtYmxvd2Zpc2gtNzYuY2xlcmsuYWNjb3VudHMuZGV2JA";
|
|
193
188
|
var CLERK_LIVE_KEY = "pk_live_Y2xlcmsudXNlcnMucGFuYWNlYS10ZWNoLm5ldCQ";
|
|
194
|
-
function getClerkKey() {
|
|
195
|
-
return
|
|
189
|
+
function getClerkKey(mode) {
|
|
190
|
+
return mode === "test" ? CLERK_TEST_KEY : CLERK_LIVE_KEY;
|
|
196
191
|
}
|
|
197
192
|
var CLERK_CDN_URL = "https://cdn.jsdelivr.net/npm/@clerk/clerk-js@5.118.0/dist/clerk.browser.js";
|
|
198
193
|
var JWT_TEMPLATE = "end-user-api";
|
|
@@ -200,9 +195,10 @@ function getClerk() {
|
|
|
200
195
|
return window.Clerk;
|
|
201
196
|
}
|
|
202
197
|
var ClerkManager = class {
|
|
203
|
-
constructor(onTokenChange) {
|
|
198
|
+
constructor(mode, onTokenChange) {
|
|
204
199
|
this.loaded = false;
|
|
205
200
|
this.token = null;
|
|
201
|
+
this.mode = mode;
|
|
206
202
|
this.onTokenChange = onTokenChange;
|
|
207
203
|
}
|
|
208
204
|
/**
|
|
@@ -233,7 +229,7 @@ var ClerkManager = class {
|
|
|
233
229
|
script.src = CLERK_CDN_URL;
|
|
234
230
|
script.async = true;
|
|
235
231
|
script.crossOrigin = "anonymous";
|
|
236
|
-
script.setAttribute("data-clerk-publishable-key", getClerkKey());
|
|
232
|
+
script.setAttribute("data-clerk-publishable-key", getClerkKey(this.mode));
|
|
237
233
|
script.onload = () => resolve();
|
|
238
234
|
script.onerror = () => reject(new Error("Failed to load Clerk SDK"));
|
|
239
235
|
document.head.appendChild(script);
|
|
@@ -399,7 +395,9 @@ var AuthHelpers = class {
|
|
|
399
395
|
constructor(client) {
|
|
400
396
|
this.initialized = false;
|
|
401
397
|
this.client = client;
|
|
402
|
-
|
|
398
|
+
const pk = client.getPublishableKey();
|
|
399
|
+
const mode = pk?.startsWith("pk_test_") ? "test" : "live";
|
|
400
|
+
this.clerk = new ClerkManager(mode, (token) => {
|
|
403
401
|
if (token) {
|
|
404
402
|
this.client.setUserToken(token);
|
|
405
403
|
} else {
|
|
@@ -486,8 +484,8 @@ var AuthHelpers = class {
|
|
|
486
484
|
/**
|
|
487
485
|
* Get the sign-in URL for returning users.
|
|
488
486
|
*
|
|
489
|
-
* Redirects to
|
|
490
|
-
* users are redirected to your specified URL.
|
|
487
|
+
* Redirects to our auth worker which embeds Clerk. After sign-in,
|
|
488
|
+
* users are redirected to your specified URL with JWT.
|
|
491
489
|
*
|
|
492
490
|
* @example
|
|
493
491
|
* ```typescript
|
|
@@ -496,27 +494,44 @@ var AuthHelpers = class {
|
|
|
496
494
|
* ```
|
|
497
495
|
*/
|
|
498
496
|
getSignInUrl(options) {
|
|
499
|
-
const
|
|
500
|
-
|
|
497
|
+
const pk = this.client.getPublishableKey();
|
|
498
|
+
if (!pk) {
|
|
499
|
+
throw new Error("DreamAPI: publishableKey required for auth URLs");
|
|
500
|
+
}
|
|
501
|
+
const baseUrl = this.client.getSignupBaseUrl();
|
|
502
|
+
const params = new URLSearchParams({
|
|
503
|
+
pk,
|
|
504
|
+
redirect: options.redirect
|
|
505
|
+
});
|
|
506
|
+
return `${baseUrl}/signin?${params.toString()}`;
|
|
501
507
|
}
|
|
502
508
|
/**
|
|
503
509
|
* Get the customer portal URL for account management.
|
|
504
510
|
*
|
|
505
|
-
* Redirects to
|
|
506
|
-
* manage their profile, password, and security settings.
|
|
511
|
+
* Redirects to our auth worker which embeds Clerk's UserProfile.
|
|
512
|
+
* Users can manage their profile, password, and security settings.
|
|
507
513
|
*
|
|
508
514
|
* Note: This is separate from billing management.
|
|
509
515
|
* For billing, use api.billing.openPortal().
|
|
510
516
|
*
|
|
511
517
|
* @example
|
|
512
518
|
* ```typescript
|
|
513
|
-
* const portalUrl = api.auth.getCustomerPortalUrl();
|
|
519
|
+
* const portalUrl = api.auth.getCustomerPortalUrl({ returnUrl: '/dashboard' });
|
|
514
520
|
* window.location.href = portalUrl;
|
|
515
521
|
* ```
|
|
516
522
|
*/
|
|
517
|
-
getCustomerPortalUrl() {
|
|
518
|
-
const
|
|
519
|
-
|
|
523
|
+
getCustomerPortalUrl(options) {
|
|
524
|
+
const pk = this.client.getPublishableKey();
|
|
525
|
+
if (!pk) {
|
|
526
|
+
throw new Error("DreamAPI: publishableKey required for auth URLs");
|
|
527
|
+
}
|
|
528
|
+
const baseUrl = this.client.getSignupBaseUrl();
|
|
529
|
+
const returnUrl = options?.returnUrl || (typeof window !== "undefined" ? window.location.href : "/");
|
|
530
|
+
const params = new URLSearchParams({
|
|
531
|
+
pk,
|
|
532
|
+
redirect: returnUrl
|
|
533
|
+
});
|
|
534
|
+
return `${baseUrl}/account?${params.toString()}`;
|
|
520
535
|
}
|
|
521
536
|
};
|
|
522
537
|
|
package/dist/index.mjs
CHANGED
|
@@ -156,15 +156,10 @@ var DreamClient = class {
|
|
|
156
156
|
};
|
|
157
157
|
|
|
158
158
|
// src/clerk.ts
|
|
159
|
-
|
|
160
|
-
if (typeof window === "undefined") return false;
|
|
161
|
-
const hostname = window.location.hostname;
|
|
162
|
-
return hostname === "localhost" || hostname === "127.0.0.1";
|
|
163
|
-
}
|
|
164
|
-
var CLERK_DEV_KEY = "pk_test_Y29tcG9zZWQtYmxvd2Zpc2gtNzYuY2xlcmsuYWNjb3VudHMuZGV2JA";
|
|
159
|
+
var CLERK_TEST_KEY = "pk_test_Y29tcG9zZWQtYmxvd2Zpc2gtNzYuY2xlcmsuYWNjb3VudHMuZGV2JA";
|
|
165
160
|
var CLERK_LIVE_KEY = "pk_live_Y2xlcmsudXNlcnMucGFuYWNlYS10ZWNoLm5ldCQ";
|
|
166
|
-
function getClerkKey() {
|
|
167
|
-
return
|
|
161
|
+
function getClerkKey(mode) {
|
|
162
|
+
return mode === "test" ? CLERK_TEST_KEY : CLERK_LIVE_KEY;
|
|
168
163
|
}
|
|
169
164
|
var CLERK_CDN_URL = "https://cdn.jsdelivr.net/npm/@clerk/clerk-js@5.118.0/dist/clerk.browser.js";
|
|
170
165
|
var JWT_TEMPLATE = "end-user-api";
|
|
@@ -172,9 +167,10 @@ function getClerk() {
|
|
|
172
167
|
return window.Clerk;
|
|
173
168
|
}
|
|
174
169
|
var ClerkManager = class {
|
|
175
|
-
constructor(onTokenChange) {
|
|
170
|
+
constructor(mode, onTokenChange) {
|
|
176
171
|
this.loaded = false;
|
|
177
172
|
this.token = null;
|
|
173
|
+
this.mode = mode;
|
|
178
174
|
this.onTokenChange = onTokenChange;
|
|
179
175
|
}
|
|
180
176
|
/**
|
|
@@ -205,7 +201,7 @@ var ClerkManager = class {
|
|
|
205
201
|
script.src = CLERK_CDN_URL;
|
|
206
202
|
script.async = true;
|
|
207
203
|
script.crossOrigin = "anonymous";
|
|
208
|
-
script.setAttribute("data-clerk-publishable-key", getClerkKey());
|
|
204
|
+
script.setAttribute("data-clerk-publishable-key", getClerkKey(this.mode));
|
|
209
205
|
script.onload = () => resolve();
|
|
210
206
|
script.onerror = () => reject(new Error("Failed to load Clerk SDK"));
|
|
211
207
|
document.head.appendChild(script);
|
|
@@ -371,7 +367,9 @@ var AuthHelpers = class {
|
|
|
371
367
|
constructor(client) {
|
|
372
368
|
this.initialized = false;
|
|
373
369
|
this.client = client;
|
|
374
|
-
|
|
370
|
+
const pk = client.getPublishableKey();
|
|
371
|
+
const mode = pk?.startsWith("pk_test_") ? "test" : "live";
|
|
372
|
+
this.clerk = new ClerkManager(mode, (token) => {
|
|
375
373
|
if (token) {
|
|
376
374
|
this.client.setUserToken(token);
|
|
377
375
|
} else {
|
|
@@ -458,8 +456,8 @@ var AuthHelpers = class {
|
|
|
458
456
|
/**
|
|
459
457
|
* Get the sign-in URL for returning users.
|
|
460
458
|
*
|
|
461
|
-
* Redirects to
|
|
462
|
-
* users are redirected to your specified URL.
|
|
459
|
+
* Redirects to our auth worker which embeds Clerk. After sign-in,
|
|
460
|
+
* users are redirected to your specified URL with JWT.
|
|
463
461
|
*
|
|
464
462
|
* @example
|
|
465
463
|
* ```typescript
|
|
@@ -468,27 +466,44 @@ var AuthHelpers = class {
|
|
|
468
466
|
* ```
|
|
469
467
|
*/
|
|
470
468
|
getSignInUrl(options) {
|
|
471
|
-
const
|
|
472
|
-
|
|
469
|
+
const pk = this.client.getPublishableKey();
|
|
470
|
+
if (!pk) {
|
|
471
|
+
throw new Error("DreamAPI: publishableKey required for auth URLs");
|
|
472
|
+
}
|
|
473
|
+
const baseUrl = this.client.getSignupBaseUrl();
|
|
474
|
+
const params = new URLSearchParams({
|
|
475
|
+
pk,
|
|
476
|
+
redirect: options.redirect
|
|
477
|
+
});
|
|
478
|
+
return `${baseUrl}/signin?${params.toString()}`;
|
|
473
479
|
}
|
|
474
480
|
/**
|
|
475
481
|
* Get the customer portal URL for account management.
|
|
476
482
|
*
|
|
477
|
-
* Redirects to
|
|
478
|
-
* manage their profile, password, and security settings.
|
|
483
|
+
* Redirects to our auth worker which embeds Clerk's UserProfile.
|
|
484
|
+
* Users can manage their profile, password, and security settings.
|
|
479
485
|
*
|
|
480
486
|
* Note: This is separate from billing management.
|
|
481
487
|
* For billing, use api.billing.openPortal().
|
|
482
488
|
*
|
|
483
489
|
* @example
|
|
484
490
|
* ```typescript
|
|
485
|
-
* const portalUrl = api.auth.getCustomerPortalUrl();
|
|
491
|
+
* const portalUrl = api.auth.getCustomerPortalUrl({ returnUrl: '/dashboard' });
|
|
486
492
|
* window.location.href = portalUrl;
|
|
487
493
|
* ```
|
|
488
494
|
*/
|
|
489
|
-
getCustomerPortalUrl() {
|
|
490
|
-
const
|
|
491
|
-
|
|
495
|
+
getCustomerPortalUrl(options) {
|
|
496
|
+
const pk = this.client.getPublishableKey();
|
|
497
|
+
if (!pk) {
|
|
498
|
+
throw new Error("DreamAPI: publishableKey required for auth URLs");
|
|
499
|
+
}
|
|
500
|
+
const baseUrl = this.client.getSignupBaseUrl();
|
|
501
|
+
const returnUrl = options?.returnUrl || (typeof window !== "undefined" ? window.location.href : "/");
|
|
502
|
+
const params = new URLSearchParams({
|
|
503
|
+
pk,
|
|
504
|
+
redirect: returnUrl
|
|
505
|
+
});
|
|
506
|
+
return `${baseUrl}/account?${params.toString()}`;
|
|
492
507
|
}
|
|
493
508
|
};
|
|
494
509
|
|