@docyrus/signin 0.1.0

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.
@@ -0,0 +1,678 @@
1
+ import { defineComponent, ref, shallowRef, provide, onMounted, onUnmounted, h, inject, computed } from 'vue';
2
+ import { RestApiClient, BrowserOAuth2TokenStorage, OAuth2Client } from '@docyrus/api-client';
3
+
4
+ // src/vue/index.ts
5
+
6
+ // src/constants.ts
7
+ var DEFAULT_API_URL = "https://alpha-api.docyrus.com";
8
+ var DEFAULT_OAUTH_SCOPES = [
9
+ "offline_access",
10
+ "Read.All",
11
+ "Users.Read",
12
+ "Users.Read.All",
13
+ "DS.Read.All"
14
+ ];
15
+ var DEFAULT_CALLBACK_PATH = "/auth/callback";
16
+ var DEFAULT_ALLOWED_HOST_PATTERN = /^https:\/\/[^/]+\.docyrus\.app$/;
17
+ var REDIRECT_RETURN_KEY = "docyrus_auth_return_url";
18
+ var TOKEN_EXPIRY_BUFFER_SECONDS = 60;
19
+ var IFRAME_TOKEN_REFRESH_TIMEOUT_MS = 1e4;
20
+
21
+ // src/core/auth-detector.ts
22
+ function detectAuthMode(allowedOrigins, allowedPattern) {
23
+ if (typeof window === "undefined") return "standalone";
24
+ let isInIframe = false;
25
+ try {
26
+ isInIframe = window.self !== window.top;
27
+ } catch {
28
+ isInIframe = true;
29
+ }
30
+ if (!isInIframe) return "standalone";
31
+ const pattern = DEFAULT_ALLOWED_HOST_PATTERN;
32
+ try {
33
+ const referrerOrigin = new URL(document.referrer).origin;
34
+ if (allowedOrigins?.includes(referrerOrigin)) return "iframe";
35
+ if (pattern.test(referrerOrigin)) return "iframe";
36
+ } catch {
37
+ }
38
+ return "standalone";
39
+ }
40
+ var StandaloneOAuth2Auth = class {
41
+ oauth2Client;
42
+ storage;
43
+ callbackPath;
44
+ constructor(config = {}) {
45
+ const apiUrl = config.apiUrl ?? DEFAULT_API_URL;
46
+ if (!config.clientId) {
47
+ throw new Error(
48
+ 'DocyrusAuthProvider: "clientId" is required. Set it via the clientId prop or the VITE_DOCYRUS_CLIENT_ID / NEXT_PUBLIC_DOCYRUS_CLIENT_ID environment variable.'
49
+ );
50
+ }
51
+ const { clientId } = config;
52
+ const scopes = config.scopes ?? DEFAULT_OAUTH_SCOPES;
53
+ this.callbackPath = config.callbackPath ?? DEFAULT_CALLBACK_PATH;
54
+ const redirectUri = config.redirectUri ?? `${window.location.origin}${this.callbackPath}`;
55
+ this.storage = config.tokenStorage ?? new BrowserOAuth2TokenStorage(
56
+ window.localStorage,
57
+ config.storageKeyPrefix ?? "docyrus_oauth2"
58
+ );
59
+ this.oauth2Client = new OAuth2Client({
60
+ baseURL: apiUrl,
61
+ clientId,
62
+ redirectUri,
63
+ defaultScopes: scopes,
64
+ usePKCE: true,
65
+ tokenStorage: this.storage
66
+ });
67
+ }
68
+ /**
69
+ * Check if the current page URL is the OAuth2 callback.
70
+ * Called on app initialization to detect returning from the auth server.
71
+ */
72
+ isCallbackUrl() {
73
+ return window.location.pathname === this.callbackPath && (window.location.search.includes("code=") || window.location.search.includes("error="));
74
+ }
75
+ /**
76
+ * Initiate the OAuth2 authorization code flow.
77
+ * Stores the current URL for post-auth redirect, then navigates
78
+ * the page to the authorization endpoint.
79
+ *
80
+ * PKCE state (codeVerifier, state) is stored in localStorage
81
+ * by the OAuth2Client and survives the page redirect.
82
+ */
83
+ async initiateLogin() {
84
+ window.localStorage.setItem(REDIRECT_RETURN_KEY, window.location.href);
85
+ const { url } = await this.oauth2Client.getAuthorizationUrl();
86
+ window.location.href = url;
87
+ }
88
+ /**
89
+ * Get the authorization URL without navigating.
90
+ * Useful for Electron apps that open the URL in an external browser.
91
+ * PKCE state is stored in storage just like initiateLogin().
92
+ */
93
+ async getAuthorizationUrl() {
94
+ window.localStorage.setItem(REDIRECT_RETURN_KEY, window.location.href);
95
+ const { url } = await this.oauth2Client.getAuthorizationUrl();
96
+ return url;
97
+ }
98
+ /**
99
+ * Handle the OAuth2 callback URL.
100
+ * Reads PKCE state from localStorage, validates the state param,
101
+ * exchanges the authorization code for tokens, and stores them.
102
+ */
103
+ async handleCallback() {
104
+ return this.oauth2Client.handleCallback(window.location.href);
105
+ }
106
+ /**
107
+ * Get the URL the user was on before the OAuth redirect.
108
+ * Clears the stored value after retrieval.
109
+ */
110
+ getReturnUrl() {
111
+ const url = window.localStorage.getItem(REDIRECT_RETURN_KEY);
112
+ window.localStorage.removeItem(REDIRECT_RETURN_KEY);
113
+ return url;
114
+ }
115
+ /** Get currently stored tokens (e.g., on page reload). */
116
+ async getStoredTokens() {
117
+ return this.oauth2Client.getTokens();
118
+ }
119
+ /** Check if the stored token is expired (with 60s buffer). */
120
+ async isTokenExpired() {
121
+ return this.oauth2Client.isTokenExpired();
122
+ }
123
+ /** Refresh the access token using the stored refresh token. */
124
+ async refreshToken() {
125
+ return this.oauth2Client.refreshAccessToken();
126
+ }
127
+ /** Get a valid access token, refreshing if needed. */
128
+ async getValidAccessToken() {
129
+ return this.oauth2Client.getValidAccessToken();
130
+ }
131
+ /** Logout: revoke token and clear storage. */
132
+ async logout() {
133
+ return this.oauth2Client.logout();
134
+ }
135
+ };
136
+
137
+ // src/core/iframe-auth.ts
138
+ var IframeAuth = class {
139
+ allowedOrigins;
140
+ allowedPattern;
141
+ onTokensReceived = null;
142
+ refreshPromise = null;
143
+ messageHandler = null;
144
+ constructor(allowedOrigins, allowedPattern) {
145
+ this.allowedOrigins = allowedOrigins ?? [];
146
+ this.allowedPattern = allowedPattern ?? DEFAULT_ALLOWED_HOST_PATTERN;
147
+ }
148
+ /**
149
+ * Start listening for postMessage events from the host.
150
+ * The callback is invoked every time valid tokens are received.
151
+ */
152
+ start(onTokensReceived) {
153
+ this.onTokensReceived = onTokensReceived;
154
+ this.messageHandler = this.handleMessage.bind(this);
155
+ window.addEventListener("message", this.messageHandler);
156
+ }
157
+ /** Stop listening for postMessage events. */
158
+ stop() {
159
+ if (this.messageHandler) {
160
+ window.removeEventListener("message", this.messageHandler);
161
+ this.messageHandler = null;
162
+ }
163
+ this.rejectPendingRefresh("IframeAuth stopped");
164
+ }
165
+ /**
166
+ * Request fresh tokens from the host.
167
+ * Posts a "token-refresh-request" to the host, then waits for
168
+ * a "signin" response.
169
+ *
170
+ * Only one refresh request can be in-flight at a time.
171
+ * Additional callers share the same promise.
172
+ */
173
+ requestTokenRefresh() {
174
+ if (this.refreshPromise) {
175
+ return new Promise((resolve, reject) => {
176
+ const existing = this.refreshPromise;
177
+ const originalResolve = existing.resolve;
178
+ const originalReject = existing.reject;
179
+ existing.resolve = (tokens) => {
180
+ originalResolve(tokens);
181
+ resolve(tokens);
182
+ };
183
+ existing.reject = (error) => {
184
+ originalReject(error);
185
+ reject(error);
186
+ };
187
+ });
188
+ }
189
+ return new Promise((resolve, reject) => {
190
+ const timeoutId = setTimeout(() => {
191
+ this.refreshPromise = null;
192
+ reject(new Error("Token refresh request timed out"));
193
+ }, IFRAME_TOKEN_REFRESH_TIMEOUT_MS);
194
+ this.refreshPromise = { resolve, reject, timeoutId };
195
+ window.parent.postMessage({ type: "token-refresh-request" }, "*");
196
+ });
197
+ }
198
+ isOriginAllowed(origin) {
199
+ if (this.allowedOrigins.includes(origin)) return true;
200
+ return this.allowedPattern.test(origin);
201
+ }
202
+ handleMessage(ev) {
203
+ if (!this.isOriginAllowed(ev.origin)) return;
204
+ const data = ev.data;
205
+ if (!data || typeof data !== "object" || data.type !== "signin") return;
206
+ const signinData = data;
207
+ if (!signinData.accessToken) return;
208
+ const tokens = {
209
+ accessToken: signinData.accessToken,
210
+ refreshToken: signinData.refreshToken,
211
+ /*
212
+ * We don't know the exact expiry from the host, so estimate 1 hour.
213
+ * The host will send new tokens before expiry via the refresh mechanism.
214
+ */
215
+ expiresAt: Math.floor(Date.now() / 1e3) + 3600,
216
+ scope: ""
217
+ };
218
+ this.onTokensReceived?.(tokens);
219
+ if (this.refreshPromise) {
220
+ clearTimeout(this.refreshPromise.timeoutId);
221
+ this.refreshPromise.resolve(tokens);
222
+ this.refreshPromise = null;
223
+ }
224
+ }
225
+ rejectPendingRefresh(reason) {
226
+ if (this.refreshPromise) {
227
+ clearTimeout(this.refreshPromise.timeoutId);
228
+ this.refreshPromise.reject(new Error(reason));
229
+ this.refreshPromise = null;
230
+ }
231
+ }
232
+ };
233
+
234
+ // src/core/cookie-sync.ts
235
+ var DEFAULT_SSR_COOKIE_KEY = "docyrus-token";
236
+ function syncTokenToCookie(accessToken, cookieKey) {
237
+ if (typeof document === "undefined") return;
238
+ const key = cookieKey ?? DEFAULT_SSR_COOKIE_KEY;
239
+ document.cookie = `${key}=${encodeURIComponent(accessToken)};path=/;SameSite=Lax`;
240
+ }
241
+ function clearTokenCookie(cookieKey) {
242
+ if (typeof document === "undefined") return;
243
+ const key = cookieKey ?? DEFAULT_SSR_COOKIE_KEY;
244
+ document.cookie = `${key}=;path=/;max-age=0;SameSite=Lax`;
245
+ }
246
+
247
+ // src/core/auth-manager.ts
248
+ var AuthManager = class {
249
+ mode;
250
+ status = "loading";
251
+ tokens = null;
252
+ error = null;
253
+ client = null;
254
+ standaloneAuth = null;
255
+ iframeAuth = null;
256
+ tokenRefreshTimer = null;
257
+ listeners = /* @__PURE__ */ new Set();
258
+ config;
259
+ constructor(config = {}) {
260
+ this.config = config;
261
+ this.mode = config.forceMode ?? detectAuthMode(config.allowedHostOrigins);
262
+ }
263
+ getMode() {
264
+ return this.mode;
265
+ }
266
+ getStatus() {
267
+ return this.status;
268
+ }
269
+ getTokens() {
270
+ return this.tokens;
271
+ }
272
+ getClient() {
273
+ return this.client;
274
+ }
275
+ getError() {
276
+ return this.error;
277
+ }
278
+ subscribe(listener) {
279
+ this.listeners.add(listener);
280
+ return () => this.listeners.delete(listener);
281
+ }
282
+ notify() {
283
+ for (const listener of this.listeners) {
284
+ listener({
285
+ status: this.status,
286
+ tokens: this.tokens,
287
+ error: this.error
288
+ });
289
+ }
290
+ }
291
+ /** Initialize the auth manager. Must be called once on mount. */
292
+ async initialize() {
293
+ try {
294
+ if (this.mode === "iframe") {
295
+ this.initializeIframeMode();
296
+ } else {
297
+ await this.initializeStandaloneMode();
298
+ }
299
+ } catch (err) {
300
+ this.error = err instanceof Error ? err : new Error(String(err));
301
+ this.status = "unauthenticated";
302
+ this.notify();
303
+ }
304
+ }
305
+ /**
306
+ * Standalone mode initialization.
307
+ * 1. Check if we're returning from an OAuth callback.
308
+ * 2. If not, check for existing tokens in localStorage.
309
+ * 3. If tokens are expired, try to refresh.
310
+ */
311
+ async initializeStandaloneMode() {
312
+ this.standaloneAuth = new StandaloneOAuth2Auth(this.config);
313
+ if (this.standaloneAuth.isCallbackUrl()) {
314
+ const tokens = await this.standaloneAuth.handleCallback();
315
+ this.setAuthenticated(tokens);
316
+ const returnUrl = this.standaloneAuth.getReturnUrl();
317
+ if (returnUrl) {
318
+ window.location.replace(returnUrl);
319
+ } else {
320
+ window.history.replaceState({}, "", "/");
321
+ }
322
+ return;
323
+ }
324
+ const stored = await this.standaloneAuth.getStoredTokens();
325
+ if (stored) {
326
+ const isExpired = await this.standaloneAuth.isTokenExpired();
327
+ if (!isExpired) {
328
+ this.setAuthenticated(stored);
329
+ return;
330
+ }
331
+ if (stored.refreshToken) {
332
+ try {
333
+ const newTokens = await this.standaloneAuth.refreshToken();
334
+ this.setAuthenticated(newTokens);
335
+ return;
336
+ } catch {
337
+ }
338
+ }
339
+ }
340
+ this.status = "unauthenticated";
341
+ this.notify();
342
+ }
343
+ /**
344
+ * Iframe mode initialization.
345
+ * Listen for postMessage tokens from the host.
346
+ * Status remains 'loading' until the host sends the first signin message.
347
+ */
348
+ initializeIframeMode() {
349
+ this.iframeAuth = new IframeAuth(this.config.allowedHostOrigins);
350
+ this.iframeAuth.start((tokens) => {
351
+ this.setAuthenticated(tokens);
352
+ });
353
+ }
354
+ /** Initiate sign-in. Only meaningful in standalone mode. */
355
+ async signIn() {
356
+ if (this.mode !== "standalone" || !this.standaloneAuth) return;
357
+ await this.standaloneAuth.initiateLogin();
358
+ }
359
+ /**
360
+ * Get the OAuth2 authorization URL without navigating.
361
+ * Use this in Electron apps to open the URL in an external browser.
362
+ * Returns null if not in standalone mode.
363
+ */
364
+ async getAuthorizationUrl() {
365
+ if (this.mode !== "standalone" || !this.standaloneAuth) return null;
366
+ return this.standaloneAuth.getAuthorizationUrl();
367
+ }
368
+ /**
369
+ * Sign out.
370
+ * Standalone: revoke token, clear localStorage, reset state.
371
+ * Iframe: clear local state (host manages the actual session).
372
+ */
373
+ async signOut() {
374
+ this.clearTokenRefreshTimer();
375
+ if (this.mode === "standalone" && this.standaloneAuth) {
376
+ await this.standaloneAuth.logout();
377
+ }
378
+ if (this.mode === "iframe" && this.iframeAuth) {
379
+ this.iframeAuth.stop();
380
+ }
381
+ if (this.config.ssr) {
382
+ clearTokenCookie(this.config.ssrCookieKey);
383
+ }
384
+ this.tokens = null;
385
+ this.client = null;
386
+ this.status = "unauthenticated";
387
+ this.error = null;
388
+ this.notify();
389
+ }
390
+ /**
391
+ * Called when valid tokens are received (either mode).
392
+ * Creates/updates the RestApiClient and schedules token refresh.
393
+ */
394
+ setAuthenticated(tokens) {
395
+ this.tokens = tokens;
396
+ this.error = null;
397
+ this.status = "authenticated";
398
+ if (this.config.ssr) {
399
+ syncTokenToCookie(tokens.accessToken, this.config.ssrCookieKey);
400
+ }
401
+ this.createClient();
402
+ this.scheduleTokenRefresh(tokens);
403
+ this.notify();
404
+ }
405
+ /**
406
+ * Create a RestApiClient with a custom TokenManager that proactively
407
+ * refreshes the token in getToken(). This is necessary because
408
+ * BaseApiClient.getAccessToken() only calls tokenManager.getToken()
409
+ * and does NOT auto-call refreshToken() when the token is expired.
410
+ */
411
+ createClient() {
412
+ const apiUrl = this.config.apiUrl ?? DEFAULT_API_URL;
413
+ const tokenManager = {
414
+ getToken: () => this.getValidToken(),
415
+ setToken: (token) => {
416
+ if (this.tokens) {
417
+ this.tokens = { ...this.tokens, accessToken: token };
418
+ }
419
+ },
420
+ clearToken: () => {
421
+ this.tokens = null;
422
+ },
423
+ refreshToken: () => this.handleTokenRefresh()
424
+ };
425
+ this.client = new RestApiClient({
426
+ baseURL: apiUrl,
427
+ tokenManager
428
+ });
429
+ }
430
+ /**
431
+ * Get a valid access token, proactively refreshing if expired.
432
+ * Called by the RestApiClient on every request via tokenManager.getToken().
433
+ */
434
+ async getValidToken() {
435
+ if (!this.tokens) return null;
436
+ if (this.tokens.expiresAt) {
437
+ const nowSec = Math.floor(Date.now() / 1e3);
438
+ if (nowSec >= this.tokens.expiresAt - TOKEN_EXPIRY_BUFFER_SECONDS) {
439
+ try {
440
+ const freshToken = await this.handleTokenRefresh();
441
+ return freshToken;
442
+ } catch {
443
+ return null;
444
+ }
445
+ }
446
+ }
447
+ return this.tokens.accessToken;
448
+ }
449
+ /**
450
+ * Handle token refresh depending on mode.
451
+ * Standalone: use OAuth2Client.getValidAccessToken() which auto-refreshes.
452
+ * Iframe: send postMessage to host requesting new tokens.
453
+ */
454
+ async handleTokenRefresh() {
455
+ if (this.mode === "standalone" && this.standaloneAuth) {
456
+ const newTokens = await this.standaloneAuth.refreshToken();
457
+ this.tokens = newTokens;
458
+ if (this.config.ssr) {
459
+ syncTokenToCookie(newTokens.accessToken, this.config.ssrCookieKey);
460
+ }
461
+ this.scheduleTokenRefresh(newTokens);
462
+ this.notify();
463
+ return newTokens.accessToken;
464
+ }
465
+ if (this.mode === "iframe" && this.iframeAuth) {
466
+ const newTokens = await this.iframeAuth.requestTokenRefresh();
467
+ return newTokens.accessToken;
468
+ }
469
+ throw new Error("Cannot refresh token: auth not initialized");
470
+ }
471
+ /** Schedule proactive token refresh before expiry. */
472
+ scheduleTokenRefresh(tokens) {
473
+ this.clearTokenRefreshTimer();
474
+ if (!tokens.expiresAt) return;
475
+ const expiresAtMs = tokens.expiresAt * 1e3;
476
+ const bufferMs = TOKEN_EXPIRY_BUFFER_SECONDS * 1e3;
477
+ const refreshInMs = expiresAtMs - bufferMs - Date.now();
478
+ if (refreshInMs <= 0) {
479
+ this.handleTokenRefresh().catch((err) => {
480
+ this.error = err instanceof Error ? err : new Error(String(err));
481
+ this.status = "unauthenticated";
482
+ this.notify();
483
+ });
484
+ return;
485
+ }
486
+ this.tokenRefreshTimer = setTimeout(() => {
487
+ this.handleTokenRefresh().catch((err) => {
488
+ this.error = err instanceof Error ? err : new Error(String(err));
489
+ this.status = "unauthenticated";
490
+ this.notify();
491
+ });
492
+ }, refreshInMs);
493
+ }
494
+ clearTokenRefreshTimer() {
495
+ if (this.tokenRefreshTimer) {
496
+ clearTimeout(this.tokenRefreshTimer);
497
+ this.tokenRefreshTimer = null;
498
+ }
499
+ }
500
+ /** Cleanup: remove listeners, timers, stop iframe auth. */
501
+ destroy() {
502
+ this.clearTokenRefreshTimer();
503
+ if (this.iframeAuth) this.iframeAuth.stop();
504
+ this.listeners.clear();
505
+ }
506
+ };
507
+
508
+ // src/vue/index.ts
509
+ var DOCYRUS_AUTH_KEY = /* @__PURE__ */ Symbol("docyrus-auth");
510
+ function useDocyrusAuth() {
511
+ const context = inject(DOCYRUS_AUTH_KEY);
512
+ if (!context) {
513
+ throw new Error(
514
+ "useDocyrusAuth() must be used within a <DocyrusAuthProvider>. Wrap your app with <DocyrusAuthProvider> to provide auth context."
515
+ );
516
+ }
517
+ return context;
518
+ }
519
+ function useDocyrusClient() {
520
+ const auth = useDocyrusAuth();
521
+ return computed(() => auth.client);
522
+ }
523
+ var DocyrusAuthProvider = defineComponent({
524
+ name: "DocyrusAuthProvider",
525
+ props: {
526
+ clientId: { type: String, default: void 0 },
527
+ apiUrl: { type: String, default: void 0 },
528
+ scopes: { type: Array, default: void 0 },
529
+ redirectUri: { type: String, default: void 0 },
530
+ callbackPath: { type: String, default: void 0 },
531
+ allowedHostOrigins: { type: Array, default: void 0 },
532
+ storageKeyPrefix: { type: String, default: void 0 },
533
+ tokenStorage: { type: Object, default: void 0 },
534
+ forceMode: { type: String, default: void 0 }
535
+ },
536
+ setup(props, { slots }) {
537
+ const status = ref("loading");
538
+ const mode = ref(null);
539
+ const tokens = shallowRef(null);
540
+ const client = shallowRef(null);
541
+ const error = shallowRef(null);
542
+ let manager = null;
543
+ const signIn = () => {
544
+ manager?.signIn();
545
+ };
546
+ const signOut = async () => {
547
+ await manager?.signOut();
548
+ };
549
+ const getAuthorizationUrl = async () => {
550
+ return manager?.getAuthorizationUrl() ?? null;
551
+ };
552
+ const authState = {
553
+ get status() {
554
+ return status.value;
555
+ },
556
+ get mode() {
557
+ return mode.value;
558
+ },
559
+ get tokens() {
560
+ return tokens.value;
561
+ },
562
+ get client() {
563
+ return client.value;
564
+ },
565
+ get error() {
566
+ return error.value;
567
+ },
568
+ signIn,
569
+ getAuthorizationUrl,
570
+ signOut
571
+ };
572
+ provide(DOCYRUS_AUTH_KEY, authState);
573
+ onMounted(() => {
574
+ const config = {
575
+ clientId: props.clientId,
576
+ apiUrl: props.apiUrl,
577
+ scopes: props.scopes,
578
+ redirectUri: props.redirectUri,
579
+ callbackPath: props.callbackPath,
580
+ allowedHostOrigins: props.allowedHostOrigins,
581
+ storageKeyPrefix: props.storageKeyPrefix,
582
+ tokenStorage: props.tokenStorage,
583
+ forceMode: props.forceMode
584
+ };
585
+ manager = new AuthManager(config);
586
+ mode.value = manager.getMode();
587
+ manager.subscribe((state) => {
588
+ status.value = state.status;
589
+ tokens.value = state.tokens;
590
+ error.value = state.error;
591
+ client.value = manager.getClient();
592
+ });
593
+ manager.initialize();
594
+ });
595
+ onUnmounted(() => {
596
+ manager?.destroy();
597
+ manager = null;
598
+ });
599
+ return () => slots.default?.();
600
+ }
601
+ });
602
+ var ICON_SIZE = 20;
603
+ var LOGO_PATH = "M768.11,531.68l-.24.21v101.17c0,26.8-21.79,48.63-48.59,48.63h-101.17c-8.72,0-16.82-2.33-23.88-6.35l-113.69,113.73c7.41,11.02,11.77,24.33,11.77,38.47,0,18.98-7.62,36.17-20.04,48.63-12.42,12.42-29.65,20.04-48.63,20.04s-36.2-7.62-48.63-20.04c-12.42-12.46-20.04-29.65-20.04-48.63,0-37.96,30.75-68.91,68.87-68.91,14.48,0,27.76,4.43,38.78,11.94l113.62-113.62c-4.19-7.1-6.55-15.31-6.55-24.09v-101.17c0-11.12,3.81-21.48,10.19-29.68l-93.72-127.52h-229.96V127.7h246.57v225.88l97.6,132.84c5.56-2.23,11.63-3.36,17.95-3.36h101.17c26.8,0,48.63,21.83,48.63,48.63Z";
604
+ function renderDocyrusLogo(size = ICON_SIZE) {
605
+ return h("svg", {
606
+ xmlns: "http://www.w3.org/2000/svg",
607
+ viewBox: "0 0 1024 1024",
608
+ width: size,
609
+ height: size,
610
+ "aria-hidden": "true",
611
+ style: { display: "block", flexShrink: 0 }
612
+ }, [h("path", { fill: "#dc2626", d: LOGO_PATH })]);
613
+ }
614
+ function renderSpinner(size = ICON_SIZE) {
615
+ return h("svg", {
616
+ xmlns: "http://www.w3.org/2000/svg",
617
+ viewBox: "0 0 24 24",
618
+ width: size,
619
+ height: size,
620
+ fill: "none",
621
+ "aria-hidden": "true",
622
+ style: { display: "block", flexShrink: 0, animation: "docyrus-spin 1s linear infinite" }
623
+ }, [
624
+ h("circle", {
625
+ cx: 12,
626
+ cy: 12,
627
+ r: 10,
628
+ stroke: "currentColor",
629
+ "stroke-width": 3,
630
+ opacity: 0.25
631
+ }),
632
+ h("path", {
633
+ d: "M12 2a10 10 0 0 1 10 10",
634
+ stroke: "currentColor",
635
+ "stroke-width": 3,
636
+ "stroke-linecap": "round"
637
+ }),
638
+ h("style", {}, "@keyframes docyrus-spin{to{transform:rotate(360deg)}}")
639
+ ]);
640
+ }
641
+ var SignInButton = defineComponent({
642
+ name: "SignInButton",
643
+ props: {
644
+ label: { type: String, default: "Sign in with Docyrus" },
645
+ disabled: { type: Boolean, default: false }
646
+ },
647
+ setup(props, { slots, attrs }) {
648
+ const { signIn, status, mode } = useDocyrusAuth();
649
+ return () => {
650
+ const isLoading = status === "loading";
651
+ if (mode === "iframe") return null;
652
+ if (status === "authenticated") return null;
653
+ if (slots.default) {
654
+ return slots.default({ signIn, isLoading, status });
655
+ }
656
+ return h(
657
+ "button",
658
+ {
659
+ type: "button",
660
+ onClick: signIn,
661
+ disabled: props.disabled || isLoading,
662
+ style: {
663
+ display: "inline-flex",
664
+ alignItems: "center",
665
+ justifyContent: "center",
666
+ gap: "8px"
667
+ },
668
+ ...attrs
669
+ },
670
+ [isLoading ? renderSpinner() : renderDocyrusLogo(), h("span", {}, props.label)]
671
+ );
672
+ };
673
+ }
674
+ });
675
+
676
+ export { DocyrusAuthProvider, SignInButton, useDocyrusAuth, useDocyrusClient };
677
+ //# sourceMappingURL=index.js.map
678
+ //# sourceMappingURL=index.js.map