@dream-api/sdk 0.1.25 → 0.1.27

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 CHANGED
@@ -137,6 +137,8 @@ declare class DreamAPIException extends Error {
137
137
  *
138
138
  * Handles all HTTP communication with the Dream API.
139
139
  * Automatically injects authentication headers.
140
+ *
141
+ * Auto-detects localhost vs production for sign-up URLs.
140
142
  */
141
143
 
142
144
  declare class DreamClient {
@@ -216,6 +218,8 @@ declare class DreamClient {
216
218
  *
217
219
  * Handles loading Clerk internally so devs never touch it.
218
220
  * Uses the shared end-user-api Clerk app.
221
+ *
222
+ * Auto-detects localhost vs production and uses appropriate keys.
219
223
  */
220
224
  interface ClerkUser {
221
225
  id: string;
package/dist/index.d.ts CHANGED
@@ -137,6 +137,8 @@ declare class DreamAPIException extends Error {
137
137
  *
138
138
  * Handles all HTTP communication with the Dream API.
139
139
  * Automatically injects authentication headers.
140
+ *
141
+ * Auto-detects localhost vs production for sign-up URLs.
140
142
  */
141
143
 
142
144
  declare class DreamClient {
@@ -216,6 +218,8 @@ declare class DreamClient {
216
218
  *
217
219
  * Handles loading Clerk internally so devs never touch it.
218
220
  * Uses the shared end-user-api Clerk app.
221
+ *
222
+ * Auto-detects localhost vs production and uses appropriate keys.
219
223
  */
220
224
  interface ClerkUser {
221
225
  id: string;
package/dist/index.js CHANGED
@@ -38,8 +38,10 @@ var DreamAPIException = class extends Error {
38
38
 
39
39
  // src/client.ts
40
40
  var DEFAULT_BASE_URL = "https://api-multi.k-c-sheffield012376.workers.dev";
41
- var DEFAULT_SIGNUP_URL = "https://signup.users.panacea-tech.net";
42
- var DEFAULT_CLERK_URL = "https://users.panacea-tech.net";
41
+ var SIGNUP_URL_TEST = "https://sign-up.k-c-sheffield012376.workers.dev";
42
+ var SIGNUP_URL_LIVE = "https://signup.users.panacea-tech.net";
43
+ var CLERK_URL_TEST = "https://composed-blowfish-76.clerk.accounts.dev";
44
+ var CLERK_URL_LIVE = "https://users.panacea-tech.net";
43
45
  var DreamClient = class {
44
46
  constructor(config) {
45
47
  this.userToken = null;
@@ -50,8 +52,9 @@ var DreamClient = class {
50
52
  this.secretKey = config.secretKey;
51
53
  this.publishableKey = config.publishableKey;
52
54
  this.baseUrl = config.baseUrl || DEFAULT_BASE_URL;
53
- this.signupUrl = config.signupUrl || DEFAULT_SIGNUP_URL;
54
- this.clerkUrl = config.clerkBaseUrl || DEFAULT_CLERK_URL;
55
+ const isTestKey = this.publishableKey?.startsWith("pk_test_");
56
+ this.signupUrl = config.signupUrl || (isTestKey ? SIGNUP_URL_TEST : SIGNUP_URL_LIVE);
57
+ this.clerkUrl = config.clerkBaseUrl || (isTestKey ? CLERK_URL_TEST : CLERK_URL_LIVE);
55
58
  this.frontendOnly = !config.secretKey && !!config.publishableKey;
56
59
  if (this.frontendOnly) {
57
60
  console.log("[DreamAPI] Running in frontend-only mode (PK auth)");
@@ -181,7 +184,16 @@ var DreamClient = class {
181
184
  };
182
185
 
183
186
  // src/clerk.ts
184
- var CLERK_PUBLISHABLE_KEY = "pk_live_Y2xlcmsudXNlcnMucGFuYWNlYS10ZWNoLm5ldCQ";
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";
193
+ var CLERK_LIVE_KEY = "pk_live_Y2xlcmsudXNlcnMucGFuYWNlYS10ZWNoLm5ldCQ";
194
+ function getClerkKey() {
195
+ return isLocalhost() ? CLERK_DEV_KEY : CLERK_LIVE_KEY;
196
+ }
185
197
  var CLERK_CDN_URL = "https://cdn.jsdelivr.net/npm/@clerk/clerk-js@5.118.0/dist/clerk.browser.js";
186
198
  var JWT_TEMPLATE = "end-user-api";
187
199
  function getClerk() {
@@ -209,7 +221,7 @@ var ClerkManager = class {
209
221
  script.src = CLERK_CDN_URL;
210
222
  script.async = true;
211
223
  script.crossOrigin = "anonymous";
212
- script.setAttribute("data-clerk-publishable-key", CLERK_PUBLISHABLE_KEY);
224
+ script.setAttribute("data-clerk-publishable-key", getClerkKey());
213
225
  script.onload = () => resolve();
214
226
  script.onerror = () => reject(new Error("Failed to load Clerk SDK"));
215
227
  document.head.appendChild(script);
package/dist/index.mjs CHANGED
@@ -10,8 +10,10 @@ var DreamAPIException = class extends Error {
10
10
 
11
11
  // src/client.ts
12
12
  var DEFAULT_BASE_URL = "https://api-multi.k-c-sheffield012376.workers.dev";
13
- var DEFAULT_SIGNUP_URL = "https://signup.users.panacea-tech.net";
14
- var DEFAULT_CLERK_URL = "https://users.panacea-tech.net";
13
+ var SIGNUP_URL_TEST = "https://sign-up.k-c-sheffield012376.workers.dev";
14
+ var SIGNUP_URL_LIVE = "https://signup.users.panacea-tech.net";
15
+ var CLERK_URL_TEST = "https://composed-blowfish-76.clerk.accounts.dev";
16
+ var CLERK_URL_LIVE = "https://users.panacea-tech.net";
15
17
  var DreamClient = class {
16
18
  constructor(config) {
17
19
  this.userToken = null;
@@ -22,8 +24,9 @@ var DreamClient = class {
22
24
  this.secretKey = config.secretKey;
23
25
  this.publishableKey = config.publishableKey;
24
26
  this.baseUrl = config.baseUrl || DEFAULT_BASE_URL;
25
- this.signupUrl = config.signupUrl || DEFAULT_SIGNUP_URL;
26
- this.clerkUrl = config.clerkBaseUrl || DEFAULT_CLERK_URL;
27
+ const isTestKey = this.publishableKey?.startsWith("pk_test_");
28
+ this.signupUrl = config.signupUrl || (isTestKey ? SIGNUP_URL_TEST : SIGNUP_URL_LIVE);
29
+ this.clerkUrl = config.clerkBaseUrl || (isTestKey ? CLERK_URL_TEST : CLERK_URL_LIVE);
27
30
  this.frontendOnly = !config.secretKey && !!config.publishableKey;
28
31
  if (this.frontendOnly) {
29
32
  console.log("[DreamAPI] Running in frontend-only mode (PK auth)");
@@ -153,7 +156,16 @@ var DreamClient = class {
153
156
  };
154
157
 
155
158
  // src/clerk.ts
156
- var CLERK_PUBLISHABLE_KEY = "pk_live_Y2xlcmsudXNlcnMucGFuYWNlYS10ZWNoLm5ldCQ";
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";
165
+ var CLERK_LIVE_KEY = "pk_live_Y2xlcmsudXNlcnMucGFuYWNlYS10ZWNoLm5ldCQ";
166
+ function getClerkKey() {
167
+ return isLocalhost() ? CLERK_DEV_KEY : CLERK_LIVE_KEY;
168
+ }
157
169
  var CLERK_CDN_URL = "https://cdn.jsdelivr.net/npm/@clerk/clerk-js@5.118.0/dist/clerk.browser.js";
158
170
  var JWT_TEMPLATE = "end-user-api";
159
171
  function getClerk() {
@@ -181,7 +193,7 @@ var ClerkManager = class {
181
193
  script.src = CLERK_CDN_URL;
182
194
  script.async = true;
183
195
  script.crossOrigin = "anonymous";
184
- script.setAttribute("data-clerk-publishable-key", CLERK_PUBLISHABLE_KEY);
196
+ script.setAttribute("data-clerk-publishable-key", getClerkKey());
185
197
  script.onload = () => resolve();
186
198
  script.onerror = () => reject(new Error("Failed to load Clerk SDK"));
187
199
  document.head.appendChild(script);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dream-api/sdk",
3
- "version": "0.1.25",
3
+ "version": "0.1.27",
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",