@vunexa/lixa 0.1.6-alpha.7 → 0.1.6-alpha.8
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/README.md +1 -2
- package/README.template.md +1 -2
- package/dist/errors.d.ts +90 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/export-types/index.d.ts +263 -2
- package/dist/index.cjs +301 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +244 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +280 -34
- package/dist/index.js.map +1 -1
- package/dist/lixa.d.ts +11 -2
- package/dist/lixa.d.ts.map +1 -1
- package/dist/utils/cookies.d.ts +142 -0
- package/dist/utils/cookies.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -166,6 +166,80 @@ async function extractUserInfo(tokenData, providerMetadata) {
|
|
|
166
166
|
return { userInfo };
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
+
// src/errors.ts
|
|
170
|
+
var LixaError = class extends Error {
|
|
171
|
+
/**
|
|
172
|
+
* Standard error code string.
|
|
173
|
+
*/
|
|
174
|
+
code;
|
|
175
|
+
/**
|
|
176
|
+
* Additional error context data.
|
|
177
|
+
*/
|
|
178
|
+
details;
|
|
179
|
+
constructor(message, code = "LIXA_ERROR", details) {
|
|
180
|
+
super(message);
|
|
181
|
+
this.name = this.constructor.name;
|
|
182
|
+
this.code = code;
|
|
183
|
+
this.details = details;
|
|
184
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
var InvalidStateError = class extends LixaError {
|
|
188
|
+
constructor(message = "Invalid or expired state", details) {
|
|
189
|
+
super(message, "INVALID_STATE", details);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
var ProviderNotConfiguredError = class extends LixaError {
|
|
193
|
+
constructor(provider, details) {
|
|
194
|
+
const message = details?.message && typeof details.message === "string" ? details.message : `Provider '${provider}' is not available. Either import it from '@vunexa/lixa-providers' and include it in the configuration, or provide a custom implementation using the 'provider' field: { provider: new CustomProvider(), clientId: '...', ... }`;
|
|
195
|
+
super(message, "PROVIDER_NOT_CONFIGURED", {
|
|
196
|
+
provider,
|
|
197
|
+
...details
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
var InvalidProviderConfigError = class extends LixaError {
|
|
202
|
+
constructor(message, details) {
|
|
203
|
+
super(message, "INVALID_PROVIDER_CONFIG", details);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
var InvalidOAuthCallbackError = class extends LixaError {
|
|
207
|
+
constructor(message, details) {
|
|
208
|
+
super(message, "INVALID_OAUTH_CALLBACK", details);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
var TokenExchangeError = class extends LixaError {
|
|
212
|
+
status;
|
|
213
|
+
constructor(message, status, details) {
|
|
214
|
+
super(message, "TOKEN_EXCHANGE_FAILED", { status, ...details });
|
|
215
|
+
this.status = status;
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
var SessionNotFoundError = class extends LixaError {
|
|
219
|
+
constructor(message = "Active session not found or has expired", details) {
|
|
220
|
+
super(message, "SESSION_NOT_FOUND", details);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
var EmailNotVerifiedError = class extends LixaError {
|
|
224
|
+
constructor(email, details) {
|
|
225
|
+
super(
|
|
226
|
+
`Cannot link account: email '${email || "unknown"}' is not verified by the identity provider`,
|
|
227
|
+
"EMAIL_NOT_VERIFIED",
|
|
228
|
+
{ email, ...details }
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
var AccountUnlinkError = class extends LixaError {
|
|
233
|
+
constructor(message, details) {
|
|
234
|
+
super(message, "ACCOUNT_UNLINK_ERROR", details);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
var RefreshTokenError = class extends LixaError {
|
|
238
|
+
constructor(message, details) {
|
|
239
|
+
super(message, "REFRESH_TOKEN_ERROR", details);
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
|
|
169
243
|
// src/lixa.ts
|
|
170
244
|
var Lixa = class _Lixa {
|
|
171
245
|
static DEFAULT_PROVIDERS = /* @__PURE__ */ new Map();
|
|
@@ -211,8 +285,9 @@ var Lixa = class _Lixa {
|
|
|
211
285
|
} else {
|
|
212
286
|
if (!_Lixa.DEFAULT_PROVIDERS.has(name) && !_Lixa.CONFIGURED_PROVIDERS.has(name)) {
|
|
213
287
|
this.log("ERROR", "Init", `Provider '${providerName}' not available`);
|
|
214
|
-
throw new
|
|
215
|
-
|
|
288
|
+
throw new ProviderNotConfiguredError(
|
|
289
|
+
providerName,
|
|
290
|
+
{ hint: `Ensure the provider is registered via '@vunexa/lixa-providers' or provided inline.` }
|
|
216
291
|
);
|
|
217
292
|
}
|
|
218
293
|
this.log("INFO", "Init", `Using registered provider: ${providerName}`);
|
|
@@ -225,7 +300,7 @@ var Lixa = class _Lixa {
|
|
|
225
300
|
*
|
|
226
301
|
* @param name - The provider name
|
|
227
302
|
* @param config - The provider configuration
|
|
228
|
-
* @throws
|
|
303
|
+
* @throws InvalidProviderConfigError when required fields are missing or invalid
|
|
229
304
|
*/
|
|
230
305
|
validateProviderConfig(name, config) {
|
|
231
306
|
const requiredFields = ["clientId", "clientSecret", "redirectUri", "scopes"];
|
|
@@ -234,18 +309,21 @@ var Lixa = class _Lixa {
|
|
|
234
309
|
return value === void 0 || value === null || typeof value === "string" && value.trim() === "";
|
|
235
310
|
});
|
|
236
311
|
if (missingFields.length > 0) {
|
|
237
|
-
throw new
|
|
238
|
-
`Provider '${name}' configuration is missing required fields: ${missingFields.join(", ")}
|
|
312
|
+
throw new InvalidProviderConfigError(
|
|
313
|
+
`Provider '${name}' configuration is missing required fields: ${missingFields.join(", ")}`,
|
|
314
|
+
{ provider: name, missingFields }
|
|
239
315
|
);
|
|
240
316
|
}
|
|
241
317
|
if (!Array.isArray(config.scopes)) {
|
|
242
|
-
throw new
|
|
243
|
-
`Provider '${name}' configuration error: 'scopes' must be an array of strings
|
|
318
|
+
throw new InvalidProviderConfigError(
|
|
319
|
+
`Provider '${name}' configuration error: 'scopes' must be an array of strings`,
|
|
320
|
+
{ provider: name }
|
|
244
321
|
);
|
|
245
322
|
}
|
|
246
323
|
if (config.scopes.length === 0) {
|
|
247
|
-
throw new
|
|
248
|
-
`Provider '${name}' configuration error: 'scopes' array cannot be empty
|
|
324
|
+
throw new InvalidProviderConfigError(
|
|
325
|
+
`Provider '${name}' configuration error: 'scopes' array cannot be empty`,
|
|
326
|
+
{ provider: name }
|
|
249
327
|
);
|
|
250
328
|
}
|
|
251
329
|
}
|
|
@@ -254,7 +332,7 @@ var Lixa = class _Lixa {
|
|
|
254
332
|
*
|
|
255
333
|
* @param name - The provider name
|
|
256
334
|
* @param provider - The provider implementation
|
|
257
|
-
* @throws
|
|
335
|
+
* @throws InvalidProviderConfigError when required properties are missing
|
|
258
336
|
*/
|
|
259
337
|
validateProviderImplementation(name, provider) {
|
|
260
338
|
const requiredProps = ["authorizationEndpoint", "tokenEndpoint", "userInfoEndpoint"];
|
|
@@ -263,8 +341,9 @@ var Lixa = class _Lixa {
|
|
|
263
341
|
return !value || typeof value !== "string" || value.trim() === "";
|
|
264
342
|
});
|
|
265
343
|
if (missingProps.length > 0) {
|
|
266
|
-
throw new
|
|
267
|
-
`Provider '${name}' implementation is missing required properties: ${missingProps.join(", ")}. All IProvider implementations must define: authorizationEndpoint, tokenEndpoint, and userInfoEndpoint
|
|
344
|
+
throw new InvalidProviderConfigError(
|
|
345
|
+
`Provider '${name}' implementation is missing required properties: ${missingProps.join(", ")}. All IProvider implementations must define: authorizationEndpoint, tokenEndpoint, and userInfoEndpoint.`,
|
|
346
|
+
{ provider: name, missingProps }
|
|
268
347
|
);
|
|
269
348
|
}
|
|
270
349
|
}
|
|
@@ -331,8 +410,9 @@ var Lixa = class _Lixa {
|
|
|
331
410
|
if (legacyProvider) {
|
|
332
411
|
return legacyProvider;
|
|
333
412
|
}
|
|
334
|
-
throw new
|
|
335
|
-
|
|
413
|
+
throw new ProviderNotConfiguredError(
|
|
414
|
+
name,
|
|
415
|
+
{ hint: `Ensure the provider is included in the configuration with a 'provider' field, or registered using Lixa.registerProvider().` }
|
|
336
416
|
);
|
|
337
417
|
}
|
|
338
418
|
/**
|
|
@@ -522,7 +602,9 @@ var Lixa = class _Lixa {
|
|
|
522
602
|
const providerConfig = this.findProviderByType(providerType);
|
|
523
603
|
if (!providerConfig) {
|
|
524
604
|
this.log("ERROR", "Auth", `Provider '${String(provider)}' is not configured`);
|
|
525
|
-
throw new
|
|
605
|
+
throw new ProviderNotConfiguredError(String(provider), {
|
|
606
|
+
message: `Provider '${String(provider)}' is not configured in this Lixa instance`
|
|
607
|
+
});
|
|
526
608
|
}
|
|
527
609
|
const providerImpl = this.getProvider(providerType, providerConfig);
|
|
528
610
|
let stateValue;
|
|
@@ -638,18 +720,18 @@ var Lixa = class _Lixa {
|
|
|
638
720
|
this.log("INFO", "Auth", `Handling OAuth callback for provider: ${providerType}`);
|
|
639
721
|
if (!code || code.trim() === "") {
|
|
640
722
|
this.log("ERROR", "Auth", "Invalid or missing authorization code in callback");
|
|
641
|
-
throw new
|
|
723
|
+
throw new InvalidOAuthCallbackError("Invalid or missing code in callback");
|
|
642
724
|
}
|
|
643
725
|
if (!state || state.trim() === "") {
|
|
644
726
|
this.log("ERROR", "Auth", "Invalid or missing state in callback");
|
|
645
|
-
throw new
|
|
727
|
+
throw new InvalidOAuthCallbackError("Invalid or missing state in callback");
|
|
646
728
|
}
|
|
647
729
|
this.log("INFO", "State", "Validating state parameter", { state });
|
|
648
730
|
const stateStorage = this.stateHandler.stateStorage || _Lixa.LOCAL_STATE_HANDLER.stateStorage;
|
|
649
731
|
const cachedState = await stateStorage.getState(state);
|
|
650
732
|
if (!cachedState) {
|
|
651
733
|
this.log("ERROR", "State", "State validation failed: state not found or expired", { state });
|
|
652
|
-
throw new
|
|
734
|
+
throw new InvalidStateError("Invalid or expired state", { state });
|
|
653
735
|
}
|
|
654
736
|
this.log("INFO", "State", "State validated successfully, removing from cache");
|
|
655
737
|
await stateStorage.deleteState(state);
|
|
@@ -657,7 +739,9 @@ var Lixa = class _Lixa {
|
|
|
657
739
|
const providerConfig = this.findProviderByType(providerType);
|
|
658
740
|
if (!providerConfig) {
|
|
659
741
|
this.log("ERROR", "Auth", `Provider '${String(provider)}' is not configured`);
|
|
660
|
-
throw new
|
|
742
|
+
throw new ProviderNotConfiguredError(String(provider), {
|
|
743
|
+
message: `Provider '${String(provider)}' is not configured in this Lixa instance`
|
|
744
|
+
});
|
|
661
745
|
}
|
|
662
746
|
const providerImpl = this.getProvider(providerType, providerConfig);
|
|
663
747
|
this.log("INFO", "Token", `Exchanging authorization code for tokens`, { provider: providerType });
|
|
@@ -750,12 +834,12 @@ var Lixa = class _Lixa {
|
|
|
750
834
|
const sessionStorage = this.sessionHandler.sessionStorage || _Lixa.LOCAL_SESSION_HANDLER.sessionStorage;
|
|
751
835
|
const existingSession = await sessionStorage.getSession(sessionId);
|
|
752
836
|
if (!existingSession) {
|
|
753
|
-
throw new
|
|
837
|
+
throw new SessionNotFoundError("Invalid session ID. User must be authenticated to link an account.", { sessionId });
|
|
754
838
|
}
|
|
755
839
|
const providerType = String(provider).toLowerCase();
|
|
756
840
|
const providerConfig = this.findProviderByType(providerType);
|
|
757
841
|
if (!providerConfig) {
|
|
758
|
-
throw new
|
|
842
|
+
throw new ProviderNotConfiguredError(String(provider));
|
|
759
843
|
}
|
|
760
844
|
const providerImpl = this.getProvider(providerType, providerConfig);
|
|
761
845
|
let codeVerifier = randomBytes2(32).toString("hex");
|
|
@@ -808,11 +892,14 @@ var Lixa = class _Lixa {
|
|
|
808
892
|
const sessionStorage = this.sessionHandler.sessionStorage || _Lixa.LOCAL_SESSION_HANDLER.sessionStorage;
|
|
809
893
|
const session = await sessionStorage.getSession(sessionId);
|
|
810
894
|
if (!session || !session.accounts) {
|
|
811
|
-
throw new
|
|
895
|
+
throw new AccountUnlinkError("Session not found or has no linked accounts.", { sessionId });
|
|
812
896
|
}
|
|
813
897
|
const linkedProviders = Object.keys(session.accounts);
|
|
814
898
|
if (linkedProviders.length <= 1) {
|
|
815
|
-
throw new
|
|
899
|
+
throw new AccountUnlinkError("Cannot unlink the only authentication provider for this account.", {
|
|
900
|
+
sessionId,
|
|
901
|
+
provider: providerToUnlink
|
|
902
|
+
});
|
|
816
903
|
}
|
|
817
904
|
delete session.accounts[providerToUnlink.toLowerCase()];
|
|
818
905
|
await sessionStorage.saveSession(sessionId, session, 86400);
|
|
@@ -834,12 +921,12 @@ var Lixa = class _Lixa {
|
|
|
834
921
|
const sessionStorage = this.sessionHandler.sessionStorage || _Lixa.LOCAL_SESSION_HANDLER.sessionStorage;
|
|
835
922
|
const activeSession = await sessionStorage.getSession(sessionId);
|
|
836
923
|
if (!activeSession) {
|
|
837
|
-
throw new
|
|
924
|
+
throw new SessionNotFoundError("Authentication required. Active session must exist to connect resource providers.", { sessionId });
|
|
838
925
|
}
|
|
839
926
|
const providerType = String(provider).toLowerCase();
|
|
840
927
|
const providerConfig = this.findProviderByType(providerType);
|
|
841
928
|
if (!providerConfig) {
|
|
842
|
-
throw new
|
|
929
|
+
throw new ProviderNotConfiguredError(String(provider));
|
|
843
930
|
}
|
|
844
931
|
const providerImpl = this.getProvider(providerType, providerConfig);
|
|
845
932
|
const stateValue = state || randomBytes2(16).toString("hex");
|
|
@@ -919,12 +1006,12 @@ var Lixa = class _Lixa {
|
|
|
919
1006
|
const sessionStorage = this.sessionHandler.sessionStorage || _Lixa.LOCAL_SESSION_HANDLER.sessionStorage;
|
|
920
1007
|
const activeSession = await sessionStorage.getSession(sessionId);
|
|
921
1008
|
if (!activeSession) {
|
|
922
|
-
throw new
|
|
1009
|
+
throw new SessionNotFoundError("Authentication required. Active session not found for resource connection.", { sessionId });
|
|
923
1010
|
}
|
|
924
1011
|
const providerType = String(provider).toLowerCase();
|
|
925
1012
|
const providerConfig = this.findProviderByType(providerType);
|
|
926
1013
|
if (!providerConfig) {
|
|
927
|
-
throw new
|
|
1014
|
+
throw new ProviderNotConfiguredError(String(provider));
|
|
928
1015
|
}
|
|
929
1016
|
const providerImpl = this.getProvider(providerType, providerConfig);
|
|
930
1017
|
let codeVerifier = randomBytes2(32).toString("hex");
|
|
@@ -1025,11 +1112,14 @@ var Lixa = class _Lixa {
|
|
|
1025
1112
|
const providerType = provider.toLowerCase();
|
|
1026
1113
|
let resource = existingResource || await resourceStorage.getResource(userIdOrEmail, providerType);
|
|
1027
1114
|
if (!resource || !resource.refreshToken) {
|
|
1028
|
-
throw new
|
|
1115
|
+
throw new RefreshTokenError(
|
|
1116
|
+
`No refresh token available for user '${userIdOrEmail}' on connected resource '${provider}'`,
|
|
1117
|
+
{ userId: userIdOrEmail, provider }
|
|
1118
|
+
);
|
|
1029
1119
|
}
|
|
1030
1120
|
const providerConfig = this.findProviderByType(providerType);
|
|
1031
1121
|
if (!providerConfig) {
|
|
1032
|
-
throw new
|
|
1122
|
+
throw new ProviderNotConfiguredError(provider);
|
|
1033
1123
|
}
|
|
1034
1124
|
const providerImpl = this.getProvider(providerType, providerConfig);
|
|
1035
1125
|
const body = {
|
|
@@ -1048,7 +1138,10 @@ var Lixa = class _Lixa {
|
|
|
1048
1138
|
});
|
|
1049
1139
|
if (!response.ok) {
|
|
1050
1140
|
const errorText = await response.text();
|
|
1051
|
-
throw new
|
|
1141
|
+
throw new RefreshTokenError(
|
|
1142
|
+
`Failed to refresh resource token for user '${userIdOrEmail}' on '${provider}': ${response.status} - ${errorText}`,
|
|
1143
|
+
{ userId: userIdOrEmail, provider, status: response.status }
|
|
1144
|
+
);
|
|
1052
1145
|
}
|
|
1053
1146
|
const tokens = await response.json();
|
|
1054
1147
|
const expiresAt = tokens.expires_in ? Date.now() + tokens.expires_in * 1e3 : void 0;
|
|
@@ -1071,7 +1164,7 @@ var Lixa = class _Lixa {
|
|
|
1071
1164
|
const sessionStorage = this.sessionHandler.sessionStorage || _Lixa.LOCAL_SESSION_HANDLER.sessionStorage;
|
|
1072
1165
|
const activeSession = await sessionStorage.getSession(sessionId);
|
|
1073
1166
|
if (!activeSession) {
|
|
1074
|
-
throw new
|
|
1167
|
+
throw new SessionNotFoundError("Active session not found.", { sessionId });
|
|
1075
1168
|
}
|
|
1076
1169
|
const providerType = provider.toLowerCase();
|
|
1077
1170
|
const userKey = this.getUserKeyFromSession(activeSession);
|
|
@@ -1107,10 +1200,22 @@ var Lixa = class _Lixa {
|
|
|
1107
1200
|
}
|
|
1108
1201
|
return false;
|
|
1109
1202
|
}
|
|
1203
|
+
/**
|
|
1204
|
+
* Retrieves active session details from session storage.
|
|
1205
|
+
*/
|
|
1110
1206
|
async fetchSessionInfo(sessionId) {
|
|
1111
1207
|
const sessionStorage = this.sessionHandler.sessionStorage || _Lixa.LOCAL_SESSION_HANDLER.sessionStorage;
|
|
1112
1208
|
return await sessionStorage.getSession(sessionId);
|
|
1113
1209
|
}
|
|
1210
|
+
/**
|
|
1211
|
+
* Deletes a session from session storage (e.g. on logout).
|
|
1212
|
+
*
|
|
1213
|
+
* @param sessionId - Active session identifier
|
|
1214
|
+
*/
|
|
1215
|
+
async deleteSession(sessionId) {
|
|
1216
|
+
const sessionStorage = this.sessionHandler.sessionStorage || _Lixa.LOCAL_SESSION_HANDLER.sessionStorage;
|
|
1217
|
+
await sessionStorage.deleteSession(sessionId);
|
|
1218
|
+
}
|
|
1114
1219
|
async exchangeCodeForToken(code, providerConfig, providerImpl, codeVerifier) {
|
|
1115
1220
|
const body = {
|
|
1116
1221
|
client_id: providerConfig.clientId,
|
|
@@ -1141,8 +1246,10 @@ var Lixa = class _Lixa {
|
|
|
1141
1246
|
statusText: response.statusText,
|
|
1142
1247
|
error: errorBody
|
|
1143
1248
|
});
|
|
1144
|
-
throw new
|
|
1145
|
-
`Token exchange failed: ${response.status} ${response.statusText} - ${errorBody}
|
|
1249
|
+
throw new TokenExchangeError(
|
|
1250
|
+
`Token exchange failed: ${response.status} ${response.statusText} - ${errorBody}`,
|
|
1251
|
+
response.status,
|
|
1252
|
+
{ statusText: response.statusText, errorBody }
|
|
1146
1253
|
);
|
|
1147
1254
|
}
|
|
1148
1255
|
this.log("INFO", "Token", "Token exchange response received successfully");
|
|
@@ -1157,12 +1264,151 @@ var Lixa = class _Lixa {
|
|
|
1157
1264
|
return void 0;
|
|
1158
1265
|
}
|
|
1159
1266
|
};
|
|
1267
|
+
|
|
1268
|
+
// src/utils/cookies.ts
|
|
1269
|
+
var DEFAULT_SESSION_COOKIE_NAME = "lixa_session";
|
|
1270
|
+
var DEFAULT_STATE_COOKIE_NAME = "lixa_oauth_state";
|
|
1271
|
+
var DEFAULT_SESSION_MAX_AGE_SECONDS = 24 * 60 * 60;
|
|
1272
|
+
var DEFAULT_STATE_MAX_AGE_SECONDS = 10 * 60;
|
|
1273
|
+
function isProductionEnvironment() {
|
|
1274
|
+
return typeof process !== "undefined" && process.env?.NODE_ENV === "production";
|
|
1275
|
+
}
|
|
1276
|
+
function serializeCookie(name, value, options) {
|
|
1277
|
+
const isProd = isProductionEnvironment();
|
|
1278
|
+
const path = options?.path ?? "/";
|
|
1279
|
+
const httpOnly = options?.httpOnly ?? true;
|
|
1280
|
+
const secure = options?.secure ?? isProd;
|
|
1281
|
+
const sameSite = options?.sameSite ?? "lax";
|
|
1282
|
+
const parts = [`${encodeURIComponent(name)}=${encodeURIComponent(value)}`];
|
|
1283
|
+
if (path) {
|
|
1284
|
+
parts.push(`Path=${path}`);
|
|
1285
|
+
}
|
|
1286
|
+
if (typeof options?.maxAge === "number") {
|
|
1287
|
+
parts.push(`Max-Age=${Math.floor(options.maxAge)}`);
|
|
1288
|
+
const expires = new Date(Date.now() + options.maxAge * 1e3).toUTCString();
|
|
1289
|
+
parts.push(`Expires=${expires}`);
|
|
1290
|
+
}
|
|
1291
|
+
if (options?.domain) {
|
|
1292
|
+
parts.push(`Domain=${options.domain}`);
|
|
1293
|
+
}
|
|
1294
|
+
if (httpOnly) {
|
|
1295
|
+
parts.push("HttpOnly");
|
|
1296
|
+
}
|
|
1297
|
+
if (secure) {
|
|
1298
|
+
parts.push("Secure");
|
|
1299
|
+
}
|
|
1300
|
+
if (sameSite) {
|
|
1301
|
+
const capitalized = sameSite.charAt(0).toUpperCase() + sameSite.slice(1).toLowerCase();
|
|
1302
|
+
parts.push(`SameSite=${capitalized}`);
|
|
1303
|
+
}
|
|
1304
|
+
return parts.join("; ");
|
|
1305
|
+
}
|
|
1306
|
+
function createSessionCookie(sessionId, options) {
|
|
1307
|
+
const isProd = isProductionEnvironment();
|
|
1308
|
+
const resolvedOptions = {
|
|
1309
|
+
name: options?.name || DEFAULT_SESSION_COOKIE_NAME,
|
|
1310
|
+
path: options?.path ?? "/",
|
|
1311
|
+
maxAge: options?.maxAge ?? DEFAULT_SESSION_MAX_AGE_SECONDS,
|
|
1312
|
+
httpOnly: options?.httpOnly ?? true,
|
|
1313
|
+
secure: options?.secure ?? isProd,
|
|
1314
|
+
sameSite: options?.sameSite ?? "lax",
|
|
1315
|
+
domain: options?.domain
|
|
1316
|
+
};
|
|
1317
|
+
const name = resolvedOptions.name;
|
|
1318
|
+
const header = serializeCookie(name, sessionId, resolvedOptions);
|
|
1319
|
+
return {
|
|
1320
|
+
name,
|
|
1321
|
+
value: sessionId,
|
|
1322
|
+
options: resolvedOptions,
|
|
1323
|
+
header
|
|
1324
|
+
};
|
|
1325
|
+
}
|
|
1326
|
+
function clearSessionCookie(options) {
|
|
1327
|
+
const isProd = isProductionEnvironment();
|
|
1328
|
+
const resolvedOptions = {
|
|
1329
|
+
name: options?.name || DEFAULT_SESSION_COOKIE_NAME,
|
|
1330
|
+
path: options?.path ?? "/",
|
|
1331
|
+
maxAge: 0,
|
|
1332
|
+
httpOnly: options?.httpOnly ?? true,
|
|
1333
|
+
secure: options?.secure ?? isProd,
|
|
1334
|
+
sameSite: options?.sameSite ?? "lax",
|
|
1335
|
+
domain: options?.domain
|
|
1336
|
+
};
|
|
1337
|
+
const name = resolvedOptions.name;
|
|
1338
|
+
const header = serializeCookie(name, "", resolvedOptions);
|
|
1339
|
+
return {
|
|
1340
|
+
name,
|
|
1341
|
+
value: "",
|
|
1342
|
+
options: resolvedOptions,
|
|
1343
|
+
header
|
|
1344
|
+
};
|
|
1345
|
+
}
|
|
1346
|
+
function createStateCookie(state, options) {
|
|
1347
|
+
const isProd = isProductionEnvironment();
|
|
1348
|
+
const resolvedOptions = {
|
|
1349
|
+
name: options?.name || DEFAULT_STATE_COOKIE_NAME,
|
|
1350
|
+
path: options?.path ?? "/",
|
|
1351
|
+
maxAge: options?.maxAge ?? DEFAULT_STATE_MAX_AGE_SECONDS,
|
|
1352
|
+
httpOnly: options?.httpOnly ?? true,
|
|
1353
|
+
secure: options?.secure ?? isProd,
|
|
1354
|
+
sameSite: options?.sameSite ?? "lax",
|
|
1355
|
+
domain: options?.domain
|
|
1356
|
+
};
|
|
1357
|
+
const name = resolvedOptions.name;
|
|
1358
|
+
const header = serializeCookie(name, state, resolvedOptions);
|
|
1359
|
+
return {
|
|
1360
|
+
name,
|
|
1361
|
+
value: state,
|
|
1362
|
+
options: resolvedOptions,
|
|
1363
|
+
header
|
|
1364
|
+
};
|
|
1365
|
+
}
|
|
1366
|
+
function clearStateCookie(options) {
|
|
1367
|
+
const isProd = isProductionEnvironment();
|
|
1368
|
+
const resolvedOptions = {
|
|
1369
|
+
name: options?.name || DEFAULT_STATE_COOKIE_NAME,
|
|
1370
|
+
path: options?.path ?? "/",
|
|
1371
|
+
maxAge: 0,
|
|
1372
|
+
httpOnly: options?.httpOnly ?? true,
|
|
1373
|
+
secure: options?.secure ?? isProd,
|
|
1374
|
+
sameSite: options?.sameSite ?? "lax",
|
|
1375
|
+
domain: options?.domain
|
|
1376
|
+
};
|
|
1377
|
+
const name = resolvedOptions.name;
|
|
1378
|
+
const header = serializeCookie(name, "", resolvedOptions);
|
|
1379
|
+
return {
|
|
1380
|
+
name,
|
|
1381
|
+
value: "",
|
|
1382
|
+
options: resolvedOptions,
|
|
1383
|
+
header
|
|
1384
|
+
};
|
|
1385
|
+
}
|
|
1160
1386
|
export {
|
|
1161
1387
|
AccountLinkingStrategy,
|
|
1388
|
+
AccountUnlinkError,
|
|
1389
|
+
DEFAULT_SESSION_COOKIE_NAME,
|
|
1390
|
+
DEFAULT_SESSION_MAX_AGE_SECONDS,
|
|
1391
|
+
DEFAULT_STATE_COOKIE_NAME,
|
|
1392
|
+
DEFAULT_STATE_MAX_AGE_SECONDS,
|
|
1393
|
+
EmailNotVerifiedError,
|
|
1394
|
+
InvalidOAuthCallbackError,
|
|
1395
|
+
InvalidProviderConfigError,
|
|
1396
|
+
InvalidStateError,
|
|
1162
1397
|
Lixa,
|
|
1398
|
+
LixaError,
|
|
1399
|
+
ProviderNotConfiguredError,
|
|
1400
|
+
RefreshTokenError,
|
|
1401
|
+
SessionNotFoundError,
|
|
1402
|
+
TokenExchangeError,
|
|
1403
|
+
clearSessionCookie,
|
|
1404
|
+
clearStateCookie,
|
|
1405
|
+
createSessionCookie,
|
|
1406
|
+
createStateCookie,
|
|
1163
1407
|
decodeIdToken,
|
|
1164
1408
|
determineProviderFromIssuer,
|
|
1165
1409
|
extractUserInfo,
|
|
1166
|
-
fetchUserInfo
|
|
1410
|
+
fetchUserInfo,
|
|
1411
|
+
isProductionEnvironment,
|
|
1412
|
+
serializeCookie
|
|
1167
1413
|
};
|
|
1168
1414
|
//# sourceMappingURL=index.js.map
|