@holo-js/auth-workos 0.2.5 → 0.3.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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { AuthResult, AuthenticatedAuthUser, AuthEstablishedSession, AuthFieldErrors, AuthLogoutResult, authRuntimeInternals } from '@holo-js/auth';
2
- import { NormalizedAuthWorkosProviderConfig } from '@holo-js/config';
1
+ import { NormalizedAuthWorkosProviderConfig, AuthResult, AuthenticatedAuthUser, AuthEstablishedSession, AuthFieldErrors, AuthLogoutResult, authRuntimeInternals } from '@holo-js/auth';
3
2
 
4
3
  type WorkosJsonValue = string | number | boolean | null | readonly WorkosJsonValue[] | {
5
4
  readonly [key: string]: WorkosJsonValue;
package/dist/index.mjs CHANGED
@@ -113,6 +113,7 @@ async function verifyWorkosSessionToken(token, config) {
113
113
  if ((typeof parsed.payload.sid !== "string" || !parsed.payload.sid.trim()) && (typeof parsed.payload.session_id !== "string" || !parsed.payload.session_id.trim())) {
114
114
  throw new Error("[@holo-js/auth-workos] WorkOS token did not include a session id.");
115
115
  }
116
+ const sessionId = typeof parsed.payload.sid === "string" && parsed.payload.sid.trim() ? parsed.payload.sid.trim() : parsed.payload.session_id.trim();
116
117
  const audience = parsed.payload.aud;
117
118
  const audiences = Array.isArray(audience) ? audience.filter((value) => typeof value === "string") : typeof audience === "string" ? [audience] : [];
118
119
  if (!audiences.includes(clientId)) {
@@ -122,7 +123,12 @@ async function verifyWorkosSessionToken(token, config) {
122
123
  if (typeof nbf === "number" && nbf * 1e3 > Date.now()) {
123
124
  throw new Error("[@holo-js/auth-workos] WorkOS token is not valid yet.");
124
125
  }
125
- return parsed.payload;
126
+ return Object.freeze({
127
+ ...parsed.payload,
128
+ exp,
129
+ sessionId,
130
+ sub: parsed.payload.sub.trim()
131
+ });
126
132
  }
127
133
  function toWorkosJsonValue(value) {
128
134
  if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
@@ -192,17 +198,12 @@ function createDefaultProviderRuntime(providerName, config) {
192
198
  const runtime = Object.freeze({
193
199
  async verifySession({ token }) {
194
200
  const claims = await verifyWorkosSessionToken(token, config);
195
- const userId = typeof claims.sub === "string" ? claims.sub : "";
196
- if (!userId) {
197
- throw new Error("[@holo-js/auth-workos] WorkOS token did not include a subject.");
198
- }
199
- const profile = await fetchWorkosUserProfile(userId, config);
200
- const sessionId = typeof claims.sid === "string" ? claims.sid : typeof claims.session_id === "string" ? claims.session_id : token;
201
+ const profile = await fetchWorkosUserProfile(claims.sub, config);
201
202
  return Object.freeze({
202
- sessionId,
203
+ sessionId: claims.sessionId,
203
204
  identity: profile,
204
205
  accessToken: token,
205
- expiresAt: typeof claims.exp === "number" ? new Date(claims.exp * 1e3) : void 0,
206
+ expiresAt: new Date(claims.exp * 1e3),
206
207
  raw: Object.freeze({
207
208
  claims,
208
209
  user: profile.raw
@@ -222,7 +223,7 @@ function resolveConfiguredProviderName(provider) {
222
223
  if (configuredDefaultProvider) {
223
224
  return configuredDefaultProvider;
224
225
  }
225
- const configuredProviders = Object.entries(bindings.config.workos).flatMap(([name, value]) => name !== "provider" && name !== "identityStore" && isNormalizedWorkosProviderConfig(value) ? [name] : []);
226
+ const configuredProviders = Object.entries(bindings.config.workos).flatMap(([name]) => name !== "provider" && name !== "identityStore" ? [name] : []);
226
227
  if (configuredProviders.length === 0) {
227
228
  return "default";
228
229
  }
@@ -347,7 +348,7 @@ function createWorkosErrorResponse(error, code) {
347
348
  code,
348
349
  message: getErrorMessage(error)
349
350
  }, {
350
- status: error instanceof WorkosAuthConflictError ? 409 : 422
351
+ status: 422
351
352
  });
352
353
  }
353
354
  function resolveGuardAndProvider(provider) {
@@ -355,9 +356,6 @@ function resolveGuardAndProvider(provider) {
355
356
  const providerConfig = getConfiguredProviderConfig(provider);
356
357
  const guardName = providerConfig.guard ?? authBindings.config.defaults.guard;
357
358
  const guard = authBindings.config.guards[guardName];
358
- if (!guard) {
359
- throw new Error(`[@holo-js/auth-workos] Guard "${guardName}" is not configured for WorkOS provider "${providerConfig.name}".`);
360
- }
361
359
  if (guard.driver !== "session") {
362
360
  throw new Error(`[@holo-js/auth-workos] WorkOS sign-in requires auth guard "${guardName}" to use the session driver.`);
363
361
  }
@@ -373,9 +371,6 @@ function resolveGuardAndProvider(provider) {
373
371
  };
374
372
  }
375
373
  function requireUserId(adapter, user, message) {
376
- if (!user || typeof user !== "object") {
377
- throw new Error(message);
378
- }
379
374
  const userId = adapter.getId(user);
380
375
  if (typeof userId !== "string" && typeof userId !== "number") {
381
376
  throw new Error(message);
@@ -388,17 +383,8 @@ function requireUserRecord(user, message) {
388
383
  }
389
384
  return user;
390
385
  }
391
- function requireSerializedUser(user, message) {
392
- if (typeof user.id === "string" || typeof user.id === "number") {
393
- return user;
394
- }
395
- throw new Error(message);
396
- }
397
386
  function createWorkosSessionPayload(authenticated, session) {
398
- const user = requireSerializedUser(
399
- authenticated.user,
400
- "[@holo-js/auth-workos] WorkOS-authenticated local users must expose a serializable id."
401
- );
387
+ const user = authenticated.user;
402
388
  return Object.freeze({
403
389
  guard: authenticated.guard,
404
390
  provider: authenticated.authProvider,
@@ -441,7 +427,7 @@ function serializeLocalUser(adapter, user, providerName) {
441
427
  configurable: true
442
428
  });
443
429
  Object.defineProperty(result, "can", {
444
- value: () => false,
430
+ value: async () => false,
445
431
  enumerable: false,
446
432
  configurable: true
447
433
  });
@@ -462,7 +448,7 @@ function resolveDisplayNameForUpdate(profile) {
462
448
  return fullName || void 0;
463
449
  }
464
450
  function resolveEmailForCreation(profile) {
465
- const normalized = typeof profile.email === "string" ? profile.email.trim() : "";
451
+ const normalized = profile.email.trim();
466
452
  if (normalized) {
467
453
  return normalized;
468
454
  }
@@ -490,7 +476,7 @@ function resolveCreateUserInput(profile, mapper) {
490
476
  }
491
477
  function resolveUpdateUserInput(profile, mapper) {
492
478
  return toAdapterInput({
493
- email: typeof profile.email === "string" ? profile.email.trim() || void 0 : void 0,
479
+ email: profile.email.trim() || void 0,
494
480
  name: resolveDisplayNameForUpdate(profile),
495
481
  avatar: profile.profilePictureUrl,
496
482
  email_verified_at: profile.emailVerified ? /* @__PURE__ */ new Date() : void 0,
@@ -511,9 +497,6 @@ function normalizeHostedProfile(profile) {
511
497
  });
512
498
  }
513
499
  async function findUserByEmail(adapter, email) {
514
- if (!email?.trim()) {
515
- return null;
516
- }
517
500
  const user = await adapter.findByCredentials({ email: email.trim() });
518
501
  return user ? requireUserRecord(user, "[@holo-js/auth-workos] Auth provider lookups must return object users.") : null;
519
502
  }
@@ -542,7 +525,7 @@ async function updateLocalUser(adapter, user, input) {
542
525
  );
543
526
  }
544
527
  async function ensureNoUnexpectedEmailCollision(adapter, providerName, profile, currentUserId) {
545
- const email = typeof profile.email === "string" ? profile.email.trim() : "";
528
+ const email = profile.email.trim();
546
529
  if (!email) {
547
530
  return;
548
531
  }
@@ -722,7 +705,7 @@ async function syncIdentity(session, provider, options = {}) {
722
705
  const profile = session.identity;
723
706
  const { guard, authProvider, adapter } = resolveGuardAndProvider(providerName);
724
707
  const verificationRequired = isEmailVerificationRequired();
725
- const profileEmail = typeof profile.email === "string" ? profile.email.trim() : "";
708
+ const profileEmail = profile.email.trim();
726
709
  const verifiedEmail = profile.emailVerified === true && profileEmail ? profileEmail : void 0;
727
710
  if (verificationRequired && !verifiedEmail) {
728
711
  throw new Error(`[@holo-js/auth-workos] WorkOS identity "${profile.id}" must provide a verified email address.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@holo-js/auth-workos",
3
- "version": "0.2.5",
3
+ "version": "0.3.0",
4
4
  "description": "Holo-JS Framework - WorkOS auth integration contracts",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -23,9 +23,8 @@
23
23
  "test": "vitest --run"
24
24
  },
25
25
  "dependencies": {
26
- "@holo-js/auth": "^0.2.5",
27
- "@holo-js/config": "^0.2.5",
28
- "@holo-js/session": "^0.2.5"
26
+ "@holo-js/auth": "^0.3.0",
27
+ "@holo-js/session": "^0.3.0"
29
28
  },
30
29
  "devDependencies": {
31
30
  "@types/node": "^22.10.2",