@dream-api/sdk 0.1.7 → 0.1.9
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 +1 -53
- package/dist/index.mjs +1 -53
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -191,24 +191,14 @@ var ClerkManager = class {
|
|
|
191
191
|
constructor(onTokenChange) {
|
|
192
192
|
this.loaded = false;
|
|
193
193
|
this.token = null;
|
|
194
|
-
this.bootstrapUser = null;
|
|
195
194
|
this.onTokenChange = onTokenChange;
|
|
196
195
|
}
|
|
197
196
|
/**
|
|
198
197
|
* Load Clerk SDK (call once on page load)
|
|
198
|
+
* Clerk automatically handles __clerk_ticket from sign-up redirect
|
|
199
199
|
*/
|
|
200
200
|
async load() {
|
|
201
201
|
if (this.loaded || typeof window === "undefined") return;
|
|
202
|
-
const bootstrapToken = this.checkBootstrapToken();
|
|
203
|
-
if (bootstrapToken) {
|
|
204
|
-
this.token = bootstrapToken.token;
|
|
205
|
-
this.bootstrapUser = bootstrapToken.user;
|
|
206
|
-
this.onTokenChange?.(this.token);
|
|
207
|
-
this.loaded = true;
|
|
208
|
-
console.log("[DreamSDK] Bootstrap token found, user:", bootstrapToken.user.email);
|
|
209
|
-
this.removeTokenFromUrl();
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
202
|
const existingClerk = getClerk();
|
|
213
203
|
if (existingClerk) {
|
|
214
204
|
this.loaded = true;
|
|
@@ -232,45 +222,6 @@ var ClerkManager = class {
|
|
|
232
222
|
this.loaded = true;
|
|
233
223
|
await this.checkSession();
|
|
234
224
|
}
|
|
235
|
-
/**
|
|
236
|
-
* Check for bootstrap token in URL (from sign-up worker redirect)
|
|
237
|
-
*/
|
|
238
|
-
checkBootstrapToken() {
|
|
239
|
-
if (typeof window === "undefined") return null;
|
|
240
|
-
const params = new URLSearchParams(window.location.search);
|
|
241
|
-
const token = params.get("__dream_token");
|
|
242
|
-
if (!token) return null;
|
|
243
|
-
try {
|
|
244
|
-
const parts = token.split(".");
|
|
245
|
-
if (parts.length !== 3) return null;
|
|
246
|
-
const payload = JSON.parse(atob(parts[1].replace(/-/g, "+").replace(/_/g, "/")));
|
|
247
|
-
if (payload.exp && payload.exp < Math.floor(Date.now() / 1e3)) {
|
|
248
|
-
console.log("[DreamSDK] Bootstrap token expired");
|
|
249
|
-
return null;
|
|
250
|
-
}
|
|
251
|
-
return {
|
|
252
|
-
token,
|
|
253
|
-
user: {
|
|
254
|
-
id: payload.userId,
|
|
255
|
-
email: payload.email || "",
|
|
256
|
-
plan: payload.plan || "free",
|
|
257
|
-
publishableKey: payload.publishableKey || ""
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
} catch (err) {
|
|
261
|
-
console.error("[DreamSDK] Failed to parse bootstrap token:", err);
|
|
262
|
-
return null;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* Remove bootstrap token from URL (clean up after reading)
|
|
267
|
-
*/
|
|
268
|
-
removeTokenFromUrl() {
|
|
269
|
-
if (typeof window === "undefined") return;
|
|
270
|
-
const url = new URL(window.location.href);
|
|
271
|
-
url.searchParams.delete("__dream_token");
|
|
272
|
-
window.history.replaceState({}, "", url.toString());
|
|
273
|
-
}
|
|
274
225
|
/**
|
|
275
226
|
* Check if returning from auth and grab token
|
|
276
227
|
*/
|
|
@@ -290,7 +241,6 @@ var ClerkManager = class {
|
|
|
290
241
|
* Check if user is signed in
|
|
291
242
|
*/
|
|
292
243
|
isSignedIn() {
|
|
293
|
-
if (this.bootstrapUser && this.token) return true;
|
|
294
244
|
const clerk = getClerk();
|
|
295
245
|
return !!clerk?.user && !!clerk?.session;
|
|
296
246
|
}
|
|
@@ -298,7 +248,6 @@ var ClerkManager = class {
|
|
|
298
248
|
* Get current user info
|
|
299
249
|
*/
|
|
300
250
|
getUser() {
|
|
301
|
-
if (this.bootstrapUser) return this.bootstrapUser;
|
|
302
251
|
const clerk = getClerk();
|
|
303
252
|
if (!clerk?.user) return null;
|
|
304
253
|
const user = clerk.user;
|
|
@@ -336,7 +285,6 @@ var ClerkManager = class {
|
|
|
336
285
|
* Sign out
|
|
337
286
|
*/
|
|
338
287
|
async signOut() {
|
|
339
|
-
this.bootstrapUser = null;
|
|
340
288
|
this.token = null;
|
|
341
289
|
this.onTokenChange?.(null);
|
|
342
290
|
const clerk = getClerk();
|
package/dist/index.mjs
CHANGED
|
@@ -163,24 +163,14 @@ var ClerkManager = class {
|
|
|
163
163
|
constructor(onTokenChange) {
|
|
164
164
|
this.loaded = false;
|
|
165
165
|
this.token = null;
|
|
166
|
-
this.bootstrapUser = null;
|
|
167
166
|
this.onTokenChange = onTokenChange;
|
|
168
167
|
}
|
|
169
168
|
/**
|
|
170
169
|
* Load Clerk SDK (call once on page load)
|
|
170
|
+
* Clerk automatically handles __clerk_ticket from sign-up redirect
|
|
171
171
|
*/
|
|
172
172
|
async load() {
|
|
173
173
|
if (this.loaded || typeof window === "undefined") return;
|
|
174
|
-
const bootstrapToken = this.checkBootstrapToken();
|
|
175
|
-
if (bootstrapToken) {
|
|
176
|
-
this.token = bootstrapToken.token;
|
|
177
|
-
this.bootstrapUser = bootstrapToken.user;
|
|
178
|
-
this.onTokenChange?.(this.token);
|
|
179
|
-
this.loaded = true;
|
|
180
|
-
console.log("[DreamSDK] Bootstrap token found, user:", bootstrapToken.user.email);
|
|
181
|
-
this.removeTokenFromUrl();
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
174
|
const existingClerk = getClerk();
|
|
185
175
|
if (existingClerk) {
|
|
186
176
|
this.loaded = true;
|
|
@@ -204,45 +194,6 @@ var ClerkManager = class {
|
|
|
204
194
|
this.loaded = true;
|
|
205
195
|
await this.checkSession();
|
|
206
196
|
}
|
|
207
|
-
/**
|
|
208
|
-
* Check for bootstrap token in URL (from sign-up worker redirect)
|
|
209
|
-
*/
|
|
210
|
-
checkBootstrapToken() {
|
|
211
|
-
if (typeof window === "undefined") return null;
|
|
212
|
-
const params = new URLSearchParams(window.location.search);
|
|
213
|
-
const token = params.get("__dream_token");
|
|
214
|
-
if (!token) return null;
|
|
215
|
-
try {
|
|
216
|
-
const parts = token.split(".");
|
|
217
|
-
if (parts.length !== 3) return null;
|
|
218
|
-
const payload = JSON.parse(atob(parts[1].replace(/-/g, "+").replace(/_/g, "/")));
|
|
219
|
-
if (payload.exp && payload.exp < Math.floor(Date.now() / 1e3)) {
|
|
220
|
-
console.log("[DreamSDK] Bootstrap token expired");
|
|
221
|
-
return null;
|
|
222
|
-
}
|
|
223
|
-
return {
|
|
224
|
-
token,
|
|
225
|
-
user: {
|
|
226
|
-
id: payload.userId,
|
|
227
|
-
email: payload.email || "",
|
|
228
|
-
plan: payload.plan || "free",
|
|
229
|
-
publishableKey: payload.publishableKey || ""
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
} catch (err) {
|
|
233
|
-
console.error("[DreamSDK] Failed to parse bootstrap token:", err);
|
|
234
|
-
return null;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Remove bootstrap token from URL (clean up after reading)
|
|
239
|
-
*/
|
|
240
|
-
removeTokenFromUrl() {
|
|
241
|
-
if (typeof window === "undefined") return;
|
|
242
|
-
const url = new URL(window.location.href);
|
|
243
|
-
url.searchParams.delete("__dream_token");
|
|
244
|
-
window.history.replaceState({}, "", url.toString());
|
|
245
|
-
}
|
|
246
197
|
/**
|
|
247
198
|
* Check if returning from auth and grab token
|
|
248
199
|
*/
|
|
@@ -262,7 +213,6 @@ var ClerkManager = class {
|
|
|
262
213
|
* Check if user is signed in
|
|
263
214
|
*/
|
|
264
215
|
isSignedIn() {
|
|
265
|
-
if (this.bootstrapUser && this.token) return true;
|
|
266
216
|
const clerk = getClerk();
|
|
267
217
|
return !!clerk?.user && !!clerk?.session;
|
|
268
218
|
}
|
|
@@ -270,7 +220,6 @@ var ClerkManager = class {
|
|
|
270
220
|
* Get current user info
|
|
271
221
|
*/
|
|
272
222
|
getUser() {
|
|
273
|
-
if (this.bootstrapUser) return this.bootstrapUser;
|
|
274
223
|
const clerk = getClerk();
|
|
275
224
|
if (!clerk?.user) return null;
|
|
276
225
|
const user = clerk.user;
|
|
@@ -308,7 +257,6 @@ var ClerkManager = class {
|
|
|
308
257
|
* Sign out
|
|
309
258
|
*/
|
|
310
259
|
async signOut() {
|
|
311
|
-
this.bootstrapUser = null;
|
|
312
260
|
this.token = null;
|
|
313
261
|
this.onTokenChange?.(null);
|
|
314
262
|
const clerk = getClerk();
|