@dream-api/sdk 0.1.30 → 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.js CHANGED
@@ -184,15 +184,10 @@ var DreamClient = class {
184
184
  };
185
185
 
186
186
  // src/clerk.ts
187
- function isLocalhost() {
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 isLocalhost() ? CLERK_DEV_KEY : CLERK_LIVE_KEY;
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
- this.clerk = new ClerkManager((token) => {
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 {
package/dist/index.mjs CHANGED
@@ -156,15 +156,10 @@ var DreamClient = class {
156
156
  };
157
157
 
158
158
  // src/clerk.ts
159
- function isLocalhost() {
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 isLocalhost() ? CLERK_DEV_KEY : CLERK_LIVE_KEY;
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
- this.clerk = new ClerkManager((token) => {
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 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dream-api/sdk",
3
- "version": "0.1.30",
3
+ "version": "0.1.31",
4
4
  "description": "Official SDK for Dream API - Auth, billing, and usage tracking in one API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",