@rixl/sdk 0.5.0 → 0.7.1
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.ts +9415 -3693
- package/dist/index.js +1288 -1833
- package/dist/index.js.map +1 -1
- package/package.json +10 -7
- package/dist/providers-Cu3u1p1O.js +0 -261
- package/dist/providers-Cu3u1p1O.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rixl/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Official TypeScript/JavaScript SDK for the Rixl platform — typed API client, authentication, and reactive state.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"media",
|
|
@@ -29,6 +29,9 @@
|
|
|
29
29
|
".": "./dist/index.js",
|
|
30
30
|
"./package.json": "./package.json"
|
|
31
31
|
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
32
35
|
"scripts": {
|
|
33
36
|
"dev": "vp pack --watch",
|
|
34
37
|
"build": "vp pack",
|
|
@@ -42,17 +45,17 @@
|
|
|
42
45
|
"typecheck": "tsc --noEmit",
|
|
43
46
|
"examples:check": "tsc --noEmit -p examples/tsconfig.json",
|
|
44
47
|
"prepare": "vp config",
|
|
45
|
-
"ci:release": "vp check && vp pack && npm publish
|
|
48
|
+
"ci:release": "vp check && vp pack && npm publish"
|
|
46
49
|
},
|
|
47
50
|
"dependencies": {
|
|
48
51
|
"jose": "^6.2.3",
|
|
49
52
|
"ky": "^2.0.2",
|
|
50
|
-
"nanostores": "^1.
|
|
51
|
-
"valibot": "^1.4.
|
|
53
|
+
"nanostores": "^1.4.0",
|
|
54
|
+
"valibot": "^1.4.2"
|
|
52
55
|
},
|
|
53
56
|
"devDependencies": {
|
|
54
|
-
"@hey-api/vite-plugin": "0.3.
|
|
55
|
-
"@types/node": "^26.
|
|
57
|
+
"@hey-api/vite-plugin": "0.3.2",
|
|
58
|
+
"@types/node": "^26.1.1",
|
|
56
59
|
"@vitest/coverage-v8": "4.1.10",
|
|
57
60
|
"@vitest/ui": "4.1.10",
|
|
58
61
|
"jsdom": "^29.1.1",
|
|
@@ -61,7 +64,7 @@
|
|
|
61
64
|
"vite-plus": "^0.2.4"
|
|
62
65
|
},
|
|
63
66
|
"engines": {
|
|
64
|
-
"node": ">=
|
|
67
|
+
"node": ">=24"
|
|
65
68
|
},
|
|
66
69
|
"packageManager": "bun@1.3.14"
|
|
67
70
|
}
|
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import { atom } from "nanostores";
|
|
2
|
-
|
|
3
|
-
//#region \0rolldown/runtime.js
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __exportAll = (all, no_symbols) => {
|
|
6
|
-
let target = {};
|
|
7
|
-
for (var name in all) {
|
|
8
|
-
__defProp(target, name, {
|
|
9
|
-
get: all[name],
|
|
10
|
-
enumerable: true
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
if (!no_symbols) {
|
|
14
|
-
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
15
|
-
}
|
|
16
|
-
return target;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
//#endregion
|
|
20
|
-
//#region src/auth/providers/types.ts
|
|
21
|
-
let AuthProvider = /* @__PURE__ */ function(AuthProvider) {
|
|
22
|
-
AuthProvider["TELEGRAM_MINI_APP"] = "tgWebAppData";
|
|
23
|
-
AuthProvider["TELEGRAM_WEB"] = "tgAuthResult";
|
|
24
|
-
AuthProvider["BEARER"] = "Bearer";
|
|
25
|
-
AuthProvider["GOOGLE"] = "google";
|
|
26
|
-
AuthProvider["APPLE"] = "apple";
|
|
27
|
-
AuthProvider["MICROSOFT"] = "microsoft";
|
|
28
|
-
return AuthProvider;
|
|
29
|
-
}({});
|
|
30
|
-
|
|
31
|
-
//#endregion
|
|
32
|
-
//#region src/auth/constants.ts
|
|
33
|
-
/**
|
|
34
|
-
* Global constants for the auth library
|
|
35
|
-
*/
|
|
36
|
-
/** Prefix for all cookies and storage keys */
|
|
37
|
-
const GLOBAL_PREFIX = "__rixl_auth";
|
|
38
|
-
/** OAuth state storage key prefix */
|
|
39
|
-
const STATE_STORAGE_KEY_PREFIX = "__rixl_auth_state_";
|
|
40
|
-
/** Social connect storage key prefix */
|
|
41
|
-
const SOCIAL_CONNECT_KEY_PREFIX = "__rixl_auth_social_connect_";
|
|
42
|
-
/** HTTP Status codes - only codes actually used in the library */
|
|
43
|
-
const HTTP_STATUS = {
|
|
44
|
-
ACCEPTED: 202,
|
|
45
|
-
BAD_REQUEST: 400,
|
|
46
|
-
UNAUTHORIZED: 401,
|
|
47
|
-
FORBIDDEN: 403,
|
|
48
|
-
NOT_FOUND: 404,
|
|
49
|
-
CONFLICT: 409,
|
|
50
|
-
TOO_MANY_REQUESTS: 429,
|
|
51
|
-
INTERNAL_SERVER_ERROR: 500
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
//#endregion
|
|
55
|
-
//#region src/auth/state.ts
|
|
56
|
-
const storagePath = (provider) => STATE_STORAGE_KEY_PREFIX + provider;
|
|
57
|
-
/**
|
|
58
|
-
* Retrieves and validates the OAuth state from session storage
|
|
59
|
-
* @param provider The provider identifier
|
|
60
|
-
* @param state The state value to validate
|
|
61
|
-
* @returns True if the state is valid, false otherwise
|
|
62
|
-
*/
|
|
63
|
-
function validateOAuthState(provider, state) {
|
|
64
|
-
return sessionStorage.getItem(storagePath(provider)) === state;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Gets or Generates a complete state parameter for OAuth requests
|
|
68
|
-
* @param provider The identifier for the provider (e.g., 'google', 'apple')
|
|
69
|
-
* @returns A state string containing the provider identifier and random data
|
|
70
|
-
*/
|
|
71
|
-
function getOauthState(provider) {
|
|
72
|
-
return sessionStorage.getItem(storagePath(provider)) ?? generateOauthState(provider);
|
|
73
|
-
}
|
|
74
|
-
function generateOauthState(provider) {
|
|
75
|
-
const state = `${provider}_${crypto.randomUUID()}`;
|
|
76
|
-
sessionStorage.setItem(storagePath(provider), state);
|
|
77
|
-
return state;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
//#endregion
|
|
81
|
-
//#region src/auth/providers/oauth.ts
|
|
82
|
-
/**
|
|
83
|
-
* Generic OAuth provider configuration and utilities
|
|
84
|
-
* This file contains shared logic for all OAuth providers to reduce duplication
|
|
85
|
-
*/
|
|
86
|
-
/**
|
|
87
|
-
* Builds an OAuth URL from configuration and metadata
|
|
88
|
-
*/
|
|
89
|
-
const buildOAuthUrl = (config, metadata, state) => {
|
|
90
|
-
const params = new URLSearchParams({
|
|
91
|
-
client_id: config.clientId,
|
|
92
|
-
redirect_uri: window.location.origin,
|
|
93
|
-
response_type: metadata.responseType,
|
|
94
|
-
scope: [...metadata.defaultScopes, ...config.scope ? [config.scope] : []].join(" "),
|
|
95
|
-
state
|
|
96
|
-
});
|
|
97
|
-
if (metadata.responseType.includes("id_token")) params.set("nonce", state);
|
|
98
|
-
if (metadata.responseMode) params.set("response_mode", metadata.responseMode);
|
|
99
|
-
if (metadata.additionalParams) Object.entries(metadata.additionalParams).forEach(([key, value]) => {
|
|
100
|
-
params.set(key, value);
|
|
101
|
-
});
|
|
102
|
-
return `${metadata.authBaseUrl}?${params.toString()}`;
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* Warning helper for unconfigured providers
|
|
106
|
-
*/
|
|
107
|
-
const warnProviderNotConfigured = (providerName) => {
|
|
108
|
-
console.warn(`${providerName} provider not configured. Check initClient method.`);
|
|
109
|
-
};
|
|
110
|
-
/**
|
|
111
|
-
* Creates a reusable OAuth provider with configuration and URL management
|
|
112
|
-
* This factory reduces code duplication across OAuth providers
|
|
113
|
-
*/
|
|
114
|
-
const createOAuthProvider = ({ provider, metadata }) => {
|
|
115
|
-
const config = atom(null);
|
|
116
|
-
const authUrl = atom(null);
|
|
117
|
-
const updateAuthUrl = () => {
|
|
118
|
-
const currentConfig = config.get();
|
|
119
|
-
if (!currentConfig) {
|
|
120
|
-
warnProviderNotConfigured(metadata.name);
|
|
121
|
-
authUrl.set(null);
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
const state = getOauthState(provider);
|
|
125
|
-
const url = buildOAuthUrl(currentConfig, metadata, state);
|
|
126
|
-
authUrl.set(url);
|
|
127
|
-
};
|
|
128
|
-
return {
|
|
129
|
-
config,
|
|
130
|
-
authUrl,
|
|
131
|
-
updateAuthUrl
|
|
132
|
-
};
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
//#endregion
|
|
136
|
-
//#region src/auth/providers/google.ts
|
|
137
|
-
const googleProvider = createOAuthProvider({
|
|
138
|
-
provider: "google",
|
|
139
|
-
metadata: {
|
|
140
|
-
name: "Google",
|
|
141
|
-
authBaseUrl: "https://accounts.google.com/o/oauth2/v2/auth",
|
|
142
|
-
defaultScopes: [
|
|
143
|
-
"openid",
|
|
144
|
-
"https://www.googleapis.com/auth/userinfo.email",
|
|
145
|
-
"https://www.googleapis.com/auth/userinfo.profile"
|
|
146
|
-
],
|
|
147
|
-
responseType: "id_token"
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
const googleConfig = googleProvider.config;
|
|
151
|
-
const googleAuthUrl = googleProvider.authUrl;
|
|
152
|
-
const updateGoogleAuthUrl = googleProvider.updateAuthUrl;
|
|
153
|
-
|
|
154
|
-
//#endregion
|
|
155
|
-
//#region src/auth/providers/microsoft.ts
|
|
156
|
-
const microsoftProvider = createOAuthProvider({
|
|
157
|
-
provider: "microsoft",
|
|
158
|
-
metadata: {
|
|
159
|
-
name: "Microsoft",
|
|
160
|
-
authBaseUrl: "https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
|
|
161
|
-
defaultScopes: [
|
|
162
|
-
"openid",
|
|
163
|
-
"profile",
|
|
164
|
-
"email"
|
|
165
|
-
],
|
|
166
|
-
responseType: "id_token",
|
|
167
|
-
responseMode: "fragment"
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
const microsoftConfig = microsoftProvider.config;
|
|
171
|
-
const microsoftAuthUrl = microsoftProvider.authUrl;
|
|
172
|
-
const updateMicrosoftAuthUrl = microsoftProvider.updateAuthUrl;
|
|
173
|
-
|
|
174
|
-
//#endregion
|
|
175
|
-
//#region src/auth/providers/apple.ts
|
|
176
|
-
const appleProvider = createOAuthProvider({
|
|
177
|
-
provider: "apple",
|
|
178
|
-
metadata: {
|
|
179
|
-
name: "Apple",
|
|
180
|
-
authBaseUrl: "https://appleid.apple.com/auth/authorize",
|
|
181
|
-
defaultScopes: ["openid"],
|
|
182
|
-
responseType: "code id_token",
|
|
183
|
-
responseMode: "fragment"
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
const appleConfig = appleProvider.config;
|
|
187
|
-
const appleAuthUrl = appleProvider.authUrl;
|
|
188
|
-
const updateAppleAuthUrl = appleProvider.updateAuthUrl;
|
|
189
|
-
|
|
190
|
-
//#endregion
|
|
191
|
-
//#region src/auth/providers/telegram.ts
|
|
192
|
-
const telegramConfig = atom(null);
|
|
193
|
-
const telegramAuthUrl = atom(null);
|
|
194
|
-
/**
|
|
195
|
-
* Updates the Telegram authentication URL using the configured settings
|
|
196
|
-
*/
|
|
197
|
-
function updateTelegramAuthUrl() {
|
|
198
|
-
const config = telegramConfig.get();
|
|
199
|
-
if (!config) {
|
|
200
|
-
warnProviderNotConfigured("Telegram");
|
|
201
|
-
telegramAuthUrl.set(null);
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
const url = `https://oauth.telegram.org/auth?bot_id=${encodeURIComponent(config.botId)}&origin=${encodeURIComponent(window.location.origin)}&return_to=${encodeURIComponent(window.location.origin + location.pathname)}`;
|
|
205
|
-
telegramAuthUrl.set(url);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
//#endregion
|
|
209
|
-
//#region src/auth/url.ts
|
|
210
|
-
const urlParams = new URLSearchParams(typeof window !== "undefined" ? fromURL(window.location.href) : "");
|
|
211
|
-
function fromURL(urlString) {
|
|
212
|
-
return urlString.replace(/^[^?#]*[?#]/, "").replace(/[?#]/g, "&");
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
//#endregion
|
|
216
|
-
//#region src/auth/providers/utils.ts
|
|
217
|
-
/**
|
|
218
|
-
* Extracts the provider identifier from a state parameter
|
|
219
|
-
* @param state The state parameter from the OAuth redirect
|
|
220
|
-
* @returns The provider identifier or undefined if not found
|
|
221
|
-
*/
|
|
222
|
-
function extractProviderFromState(state) {
|
|
223
|
-
const parts = state.split("_");
|
|
224
|
-
if (parts.length >= 1) return parts[0];
|
|
225
|
-
}
|
|
226
|
-
const OAUTH_PROVIDERS = [
|
|
227
|
-
"google",
|
|
228
|
-
"apple",
|
|
229
|
-
"microsoft"
|
|
230
|
-
];
|
|
231
|
-
/**
|
|
232
|
-
* Detects the authentication provider from URL parameters
|
|
233
|
-
* @returns The detected authentication provider or undefined if none detected
|
|
234
|
-
*/
|
|
235
|
-
function detectProvider() {
|
|
236
|
-
if (urlParams.has("tgWebAppData")) return "tgWebAppData";
|
|
237
|
-
if (urlParams.has("tgAuthResult")) return "tgAuthResult";
|
|
238
|
-
const id_token = urlParams.get("id_token");
|
|
239
|
-
const state = urlParams.get("state");
|
|
240
|
-
if (id_token && state) {
|
|
241
|
-
const providerFromState = extractProviderFromState(state);
|
|
242
|
-
return OAUTH_PROVIDERS.find((p) => providerFromState === p && validateOAuthState(p, state));
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Gets the authentication token or code from the URL based on the provider
|
|
247
|
-
* @param provider The authentication provider
|
|
248
|
-
* @returns The token or code, or undefined if not found
|
|
249
|
-
*/
|
|
250
|
-
function getProviderToken(provider) {
|
|
251
|
-
if (provider === "tgWebAppData" || provider === "tgAuthResult") return urlParams.get(provider) || void 0;
|
|
252
|
-
if (provider === "google" || provider === "apple" || provider === "microsoft") return urlParams.get("id_token") || void 0;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
//#endregion
|
|
256
|
-
//#region src/auth/providers/index.ts
|
|
257
|
-
var providers_exports = /* @__PURE__ */ __exportAll({ AuthProvider: () => AuthProvider });
|
|
258
|
-
|
|
259
|
-
//#endregion
|
|
260
|
-
export { HTTP_STATUS as _, telegramConfig as a, __exportAll as b, appleConfig as c, microsoftConfig as d, updateMicrosoftAuthUrl as f, GLOBAL_PREFIX as g, updateGoogleAuthUrl as h, telegramAuthUrl as i, updateAppleAuthUrl as l, googleConfig as m, detectProvider as n, updateTelegramAuthUrl as o, googleAuthUrl as p, getProviderToken as r, appleAuthUrl as s, providers_exports as t, microsoftAuthUrl as u, SOCIAL_CONNECT_KEY_PREFIX as v, AuthProvider as y };
|
|
261
|
-
//# sourceMappingURL=providers-Cu3u1p1O.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"providers-Cu3u1p1O.js","names":[],"sources":["../src/auth/providers/types.ts","../src/auth/constants.ts","../src/auth/state.ts","../src/auth/providers/oauth.ts","../src/auth/providers/google.ts","../src/auth/providers/microsoft.ts","../src/auth/providers/apple.ts","../src/auth/providers/telegram.ts","../src/auth/url.ts","../src/auth/providers/utils.ts","../src/auth/providers/index.ts"],"sourcesContent":["// Provider types\nexport enum AuthProvider {\n TELEGRAM_MINI_APP = \"tgWebAppData\",\n TELEGRAM_WEB = \"tgAuthResult\",\n BEARER = \"Bearer\",\n GOOGLE = \"google\",\n APPLE = \"apple\",\n MICROSOFT = \"microsoft\",\n}\n","/**\n * Global constants for the auth library\n */\n\n/** Prefix for all cookies and storage keys */\nexport const GLOBAL_PREFIX: string = \"__rixl_auth\";\n\n/** Cookie expiry in days */\nexport const COOKIE_EXPIRY_DAYS: number = 30;\n\n/** OAuth state storage key prefix */\nexport const STATE_STORAGE_KEY_PREFIX: string = GLOBAL_PREFIX + \"_state_\";\n\n/** Social connect storage key prefix */\nexport const SOCIAL_CONNECT_KEY_PREFIX: string = GLOBAL_PREFIX + \"_social_connect_\";\n\ntype HttpStatusMap = Readonly<{\n ACCEPTED: number;\n BAD_REQUEST: number;\n UNAUTHORIZED: number;\n FORBIDDEN: number;\n NOT_FOUND: number;\n CONFLICT: number;\n TOO_MANY_REQUESTS: number;\n INTERNAL_SERVER_ERROR: number;\n}>;\n\n/** HTTP Status codes - only codes actually used in the library */\nexport const HTTP_STATUS: HttpStatusMap = {\n ACCEPTED: 202,\n BAD_REQUEST: 400,\n UNAUTHORIZED: 401,\n FORBIDDEN: 403,\n NOT_FOUND: 404,\n CONFLICT: 409,\n TOO_MANY_REQUESTS: 429,\n INTERNAL_SERVER_ERROR: 500,\n} as const;\n","import {STATE_STORAGE_KEY_PREFIX} from \"./constants\";\n\nconst storagePath = (provider: string) => STATE_STORAGE_KEY_PREFIX + provider;\n\n/**\n * Retrieves and validates the OAuth state from session storage\n * @param provider The provider identifier\n * @param state The state value to validate\n * @returns True if the state is valid, false otherwise\n */\nexport function validateOAuthState(provider: string, state: string): boolean {\n const storedState = sessionStorage.getItem(storagePath(provider));\n return storedState === state;\n}\n\n/**\n * Gets or Generates a complete state parameter for OAuth requests\n * @param provider The identifier for the provider (e.g., 'google', 'apple')\n * @returns A state string containing the provider identifier and random data\n */\nexport function getOauthState(provider: string): string {\n return sessionStorage.getItem(storagePath(provider)) ?? generateOauthState(provider);\n}\n\nfunction generateOauthState(provider: string): string {\n const randomPart = crypto.randomUUID();\n const state = `${provider}_${randomPart}`;\n sessionStorage.setItem(storagePath(provider), state);\n return state;\n}\n","/**\n * Generic OAuth provider configuration and utilities\n * This file contains shared logic for all OAuth providers to reduce duplication\n */\n\nimport {atom, type WritableAtom} from \"nanostores\";\nimport {getOauthState} from \"../state\";\nimport {AuthProvider} from \"./types\";\n\n/**\n * Base configuration for OAuth providers\n */\nexport interface OAuthProviderConfig {\n clientId: string;\n scope?: string;\n}\n\n/**\n * OAuth provider metadata\n */\nexport interface OAuthProviderMetadata {\n name: string;\n authBaseUrl: string;\n defaultScopes: string[];\n responseType: string;\n responseMode?: string;\n additionalParams?: Record<string, string>;\n}\n\n/**\n * Configuration for creating an OAuth provider\n */\nexport interface CreateOAuthProviderConfig {\n provider: AuthProvider;\n metadata: OAuthProviderMetadata;\n}\n\n/**\n * Result of creating an OAuth provider\n */\nexport interface OAuthProviderResult {\n config: WritableAtom<OAuthProviderConfig | null>;\n authUrl: WritableAtom<string | null>;\n updateAuthUrl: () => void;\n}\n\n/**\n * Builds an OAuth URL from configuration and metadata\n */\nexport const buildOAuthUrl = (config: OAuthProviderConfig, metadata: OAuthProviderMetadata, state: string): string => {\n const params = new URLSearchParams({\n client_id: config.clientId,\n redirect_uri: window.location.origin,\n response_type: metadata.responseType,\n scope: [...metadata.defaultScopes, ...(config.scope ? [config.scope] : [])].join(\" \"),\n state: state,\n });\n\n // Add nonce for providers that require it\n if (metadata.responseType.includes(\"id_token\")) {\n params.set(\"nonce\", state);\n }\n\n // Add response mode if specified\n if (metadata.responseMode) {\n params.set(\"response_mode\", metadata.responseMode);\n }\n\n // Add any additional provider-specific params\n if (metadata.additionalParams) {\n Object.entries(metadata.additionalParams).forEach(([key, value]) => {\n params.set(key, value);\n });\n }\n\n return `${metadata.authBaseUrl}?${params.toString()}`;\n};\n\n/**\n * Warning helper for unconfigured providers\n */\nexport const warnProviderNotConfigured = (providerName: string): void => {\n console.warn(`${providerName} provider not configured. Check initClient method.`);\n};\n\n/**\n * Creates a reusable OAuth provider with configuration and URL management\n * This factory reduces code duplication across OAuth providers\n */\nexport const createOAuthProvider = ({provider, metadata}: CreateOAuthProviderConfig): OAuthProviderResult => {\n const config = atom<OAuthProviderConfig | null>(null);\n const authUrl = atom<string | null>(null);\n\n const updateAuthUrl = () => {\n const currentConfig = config.get();\n if (!currentConfig) {\n warnProviderNotConfigured(metadata.name);\n authUrl.set(null);\n return;\n }\n\n const state = getOauthState(provider);\n const url = buildOAuthUrl(currentConfig, metadata, state);\n authUrl.set(url);\n };\n\n return {config, authUrl, updateAuthUrl};\n};\n","import {AuthProvider} from \"./types\";\nimport {createOAuthProvider, type OAuthProviderConfig} from \"./oauth\";\nimport type {WritableAtom} from \"nanostores\";\n\n// Provider configuration interface\nexport interface GoogleProviderConfig extends OAuthProviderConfig {}\n\n// Create the Google provider using the factory\nconst googleProvider = createOAuthProvider({\n provider: AuthProvider.GOOGLE,\n metadata: {\n name: \"Google\",\n authBaseUrl: \"https://accounts.google.com/o/oauth2/v2/auth\",\n defaultScopes: [\"openid\", \"https://www.googleapis.com/auth/userinfo.email\", \"https://www.googleapis.com/auth/userinfo.profile\"],\n responseType: \"id_token\",\n },\n});\n\n// Export the configuration atom, auth URL atom, and update function\nexport const googleConfig: WritableAtom<OAuthProviderConfig | null> = googleProvider.config;\nexport const googleAuthUrl: WritableAtom<string | null> = googleProvider.authUrl;\nexport const updateGoogleAuthUrl: () => void = googleProvider.updateAuthUrl;\n","import {AuthProvider} from \"./types\";\nimport {createOAuthProvider, type OAuthProviderConfig} from \"./oauth\";\nimport type {WritableAtom} from \"nanostores\";\n\n// Provider configuration interface\nexport interface MicrosoftProviderConfig extends OAuthProviderConfig {}\n\n// Create the Microsoft provider using the factory\nconst microsoftProvider = createOAuthProvider({\n provider: AuthProvider.MICROSOFT,\n metadata: {\n name: \"Microsoft\",\n authBaseUrl: \"https://login.microsoftonline.com/common/oauth2/v2.0/authorize\",\n defaultScopes: [\"openid\", \"profile\", \"email\"],\n responseType: \"id_token\",\n responseMode: \"fragment\",\n },\n});\n\n// Export the configuration atom, auth URL atom, and update function\nexport const microsoftConfig: WritableAtom<OAuthProviderConfig | null> = microsoftProvider.config;\nexport const microsoftAuthUrl: WritableAtom<string | null> = microsoftProvider.authUrl;\nexport const updateMicrosoftAuthUrl: () => void = microsoftProvider.updateAuthUrl;\n","import {AuthProvider} from \"./types\";\nimport {createOAuthProvider, type OAuthProviderConfig} from \"./oauth\";\nimport type {WritableAtom} from \"nanostores\";\n\n// Provider configuration interface\nexport interface AppleProviderConfig extends OAuthProviderConfig {}\n\n// Create the Apple provider using the factory\nconst appleProvider = createOAuthProvider({\n provider: AuthProvider.APPLE,\n metadata: {\n name: \"Apple\",\n authBaseUrl: \"https://appleid.apple.com/auth/authorize\",\n defaultScopes: [\"openid\"],\n responseType: \"code id_token\",\n responseMode: \"fragment\",\n },\n});\n\n// Export the configuration atom, auth URL atom, and update function\nexport const appleConfig: WritableAtom<OAuthProviderConfig | null> = appleProvider.config;\nexport const appleAuthUrl: WritableAtom<string | null> = appleProvider.authUrl;\nexport const updateAppleAuthUrl: () => void = appleProvider.updateAuthUrl;\n","import {atom, type WritableAtom} from \"nanostores\";\nimport {warnProviderNotConfigured} from \"./oauth\";\n\n// Provider configuration interface\nexport interface TelegramProviderConfig {\n botId: string;\n}\n\n// Store provider configuration\nexport const telegramConfig: WritableAtom<TelegramProviderConfig | null> = atom<TelegramProviderConfig | null>(null);\n\n// Store for Telegram auth URL\nexport const telegramAuthUrl: WritableAtom<string | null> = atom<string | null>(null);\n\n/**\n * Updates the Telegram authentication URL using the configured settings\n */\nexport function updateTelegramAuthUrl(): void {\n const config = telegramConfig.get();\n if (!config) {\n warnProviderNotConfigured(\"Telegram\");\n telegramAuthUrl.set(null);\n return;\n }\n\n const url =\n \"https://oauth.telegram.org/auth?\" +\n `bot_id=${encodeURIComponent(config.botId)}` +\n `&origin=${encodeURIComponent(window.location.origin)}` +\n `&return_to=${encodeURIComponent(window.location.origin + location.pathname)}`;\n\n telegramAuthUrl.set(url);\n}\n","// Initialize urlParams lazily to avoid accessing window during module import\n// This is important for test environments and SSR\nexport const urlParams: URLSearchParams = new URLSearchParams(typeof window !== \"undefined\" ? fromURL(window.location.href) : \"\");\n\nfunction fromURL(urlString: string): string {\n return (\n urlString\n // Replace everything before this first hashtag or question sign.\n .replace(/^[^?#]*[?#]/, \"\")\n // Replace all hashtags and question signs to make it look like some search params.\n .replace(/[?#]/g, \"&\")\n );\n}\n","import {urlParams} from \"../url\";\nimport {validateOAuthState} from \"../state\";\nimport {AuthProvider} from \"./types\";\n\n/**\n * Extracts the provider identifier from a state parameter\n * @param state The state parameter from the OAuth redirect\n * @returns The provider identifier or undefined if not found\n */\nexport function extractProviderFromState(state: string): string | undefined {\n const parts = state.split(\"_\");\n if (parts.length >= 1) {\n return parts[0];\n }\n return undefined;\n}\n\nconst OAUTH_PROVIDERS = [AuthProvider.GOOGLE, AuthProvider.APPLE, AuthProvider.MICROSOFT] as const;\n\n/**\n * Detects the authentication provider from URL parameters\n * @returns The detected authentication provider or undefined if none detected\n */\nexport function detectProvider(): AuthProvider | undefined {\n // Check for Telegram providers first (they have specific parameters)\n if (urlParams.has(AuthProvider.TELEGRAM_MINI_APP)) {\n return AuthProvider.TELEGRAM_MINI_APP;\n }\n if (urlParams.has(AuthProvider.TELEGRAM_WEB)) {\n return AuthProvider.TELEGRAM_WEB;\n }\n\n // Check for OAuth providers via id_token + state\n const id_token = urlParams.get(\"id_token\");\n const state = urlParams.get(\"state\");\n\n if (id_token && state) {\n const providerFromState = extractProviderFromState(state);\n return OAUTH_PROVIDERS.find((p) => providerFromState === p && validateOAuthState(p, state));\n }\n\n return undefined;\n}\n\n/**\n * Gets the authentication token or code from the URL based on the provider\n * @param provider The authentication provider\n * @returns The token or code, or undefined if not found\n */\nexport function getProviderToken(provider: AuthProvider): string | undefined {\n // For Telegram, the token is in a parameter named after the provider\n if (provider === AuthProvider.TELEGRAM_MINI_APP || provider === AuthProvider.TELEGRAM_WEB) {\n return urlParams.get(provider) || undefined;\n }\n\n // For OAuth providers (Google, Apple, Microsoft), the token is in the 'id_token' parameter\n if (provider === AuthProvider.GOOGLE || provider === AuthProvider.APPLE || provider === AuthProvider.MICROSOFT) {\n return urlParams.get(\"id_token\") || undefined;\n }\n\n return undefined;\n}\n","// Export provider types\nexport {AuthProvider} from \"./types\";\n\n// Export provider configurations and URL atoms\nexport {googleConfig, googleAuthUrl, updateGoogleAuthUrl, type GoogleProviderConfig} from \"./google\";\n\nexport {microsoftConfig, microsoftAuthUrl, updateMicrosoftAuthUrl, type MicrosoftProviderConfig} from \"./microsoft\";\n\nexport {appleConfig, appleAuthUrl, updateAppleAuthUrl, type AppleProviderConfig} from \"./apple\";\n\nexport {telegramConfig, telegramAuthUrl, updateTelegramAuthUrl, type TelegramProviderConfig} from \"./telegram\";\n\n// Export utility functions\nexport {detectProvider, getProviderToken} from \"./utils\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AACA,IAAY,eAAL;CACL;CACA;CACA;CACA;CACA;CACA;;AACF;;;;;;;;ACHA,MAAa,gBAAwB;;AAMrC,MAAa,2BAAmC;;AAGhD,MAAa,4BAAoC;;AAcjD,MAAa,cAA6B;CACxC,UAAU;CACV,aAAa;CACb,cAAc;CACd,WAAW;CACX,WAAW;CACX,UAAU;CACV,mBAAmB;CACnB,uBAAuB;AACzB;;;;ACnCA,MAAM,eAAe,aAAqB,2BAA2B;;;;;;;AAQrE,SAAgB,mBAAmB,UAAkB,OAAwB;CAE3E,OADoB,eAAe,QAAQ,YAAY,QAAQ,CAC9C,MAAM;AACzB;;;;;;AAOA,SAAgB,cAAc,UAA0B;CACtD,OAAO,eAAe,QAAQ,YAAY,QAAQ,CAAC,KAAK,mBAAmB,QAAQ;AACrF;AAEA,SAAS,mBAAmB,UAA0B;CAEpD,MAAM,QAAQ,GAAG,SAAS,GADP,OAAO,WACY;CACtC,eAAe,QAAQ,YAAY,QAAQ,GAAG,KAAK;CACnD,OAAO;AACT;;;;;;;;;;;ACoBA,MAAa,iBAAiB,QAA6B,UAAiC,UAA0B;CACpH,MAAM,SAAS,IAAI,gBAAgB;EACjC,WAAW,OAAO;EAClB,cAAc,OAAO,SAAS;EAC9B,eAAe,SAAS;EACxB,OAAO,CAAC,GAAG,SAAS,eAAe,GAAI,OAAO,QAAQ,CAAC,OAAO,KAAK,IAAI,CAAC,CAAE,CAAC,CAAC,KAAK,GAAG;EAC7E;CACT,CAAC;CAGD,IAAI,SAAS,aAAa,SAAS,UAAU,GAC3C,OAAO,IAAI,SAA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