@absolutejs/auth 0.76.2 → 0.77.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/server.js CHANGED
@@ -5832,14 +5832,15 @@ var base64Url2 = (value) => {
5832
5832
  };
5833
5833
  var deriveAuthSyncNamespace = async ({
5834
5834
  clientId,
5835
+ digestSha256 = async (value) => new Uint8Array(await crypto.subtle.digest("SHA-256", new Uint8Array(value))),
5835
5836
  issuer,
5836
5837
  partition,
5837
5838
  subject
5838
5839
  }) => {
5839
5840
  if (clientId.length === 0 || issuer.length === 0 || subject.length === 0)
5840
5841
  throw new TypeError("Auth Sync namespace requires issuer, clientId, and subject.");
5841
- const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(JSON.stringify([issuer, clientId, subject, partition ?? null])));
5842
- return `auth:v1:${base64Url2(new Uint8Array(digest))}`;
5842
+ const digest = await digestSha256(new TextEncoder().encode(JSON.stringify([issuer, clientId, subject, partition ?? null])));
5843
+ return `auth:v1:${base64Url2(digest)}`;
5843
5844
  };
5844
5845
  var readAuthSyncPartition = (user) => {
5845
5846
  if (typeof user !== "object" || user === null)
@@ -8209,7 +8210,10 @@ var mfaTotpRoutes = ({
8209
8210
  verified: false
8210
8211
  };
8211
8212
  const factors = getMfaFactors(base).filter((existingFactor) => existingFactor.type !== "totp" || existingFactor.verified);
8212
- await mfaStore.saveEnrollment(withMfaFactors({ ...base, updatedAt: now }, [...factors, factor]));
8213
+ await mfaStore.saveEnrollment(withMfaFactors({ ...base, updatedAt: now }, [
8214
+ ...factors,
8215
+ factor
8216
+ ]));
8213
8217
  return status("OK", {
8214
8218
  factorId: factor.id,
8215
8219
  secret,
@@ -35017,17 +35021,17 @@ var resolveBindingFailureStatus = (binding, report) => {
35017
35021
  }
35018
35022
  return binding.status;
35019
35023
  };
35020
- var buildNextGrant = (grant, report, currentTime) => ({
35024
+ var buildNextGrant = (grant, report, currentTime, failurePolicy) => ({
35021
35025
  ...grant,
35022
35026
  lastRefreshError: report.message ?? report.code,
35023
35027
  metadata: annotateFailureMetadata(grant.metadata, report, currentTime),
35024
- status: resolveGrantFailureStatus(grant, report),
35028
+ status: failurePolicy === "record" ? grant.status : resolveGrantFailureStatus(grant, report),
35025
35029
  updatedAt: currentTime
35026
35030
  });
35027
- var buildNextBinding = (binding, report, currentTime) => ({
35031
+ var buildNextBinding = (binding, report, currentTime, failurePolicy) => ({
35028
35032
  ...binding,
35029
35033
  metadata: annotateFailureMetadata(binding.metadata, report, currentTime),
35030
- status: resolveBindingFailureStatus(binding, report),
35034
+ status: failurePolicy === "record" ? binding.status : resolveBindingFailureStatus(binding, report),
35031
35035
  updatedAt: currentTime
35032
35036
  });
35033
35037
  var resolveBindingCredential = async (grantStore, binding, input) => {
@@ -35044,6 +35048,7 @@ var resolveBindingCredential = async (grantStore, binding, input) => {
35044
35048
  var createLinkedProviderCredentialResolver = ({
35045
35049
  grantStore,
35046
35050
  bindingStore,
35051
+ failurePolicy = "latch",
35047
35052
  loadAccessTokenLease,
35048
35053
  refreshAccessTokenLease,
35049
35054
  now = () => Date.now(),
@@ -35089,10 +35094,10 @@ var createLinkedProviderCredentialResolver = ({
35089
35094
  const grant = await grantStore.getGrant(credential.grantId);
35090
35095
  const binding = await bindingStore.getBinding(credential.bindingId);
35091
35096
  if (grant) {
35092
- await grantStore.saveGrant(buildNextGrant(grant, report, currentTime));
35097
+ await grantStore.saveGrant(buildNextGrant(grant, report, currentTime, failurePolicy));
35093
35098
  }
35094
35099
  if (binding) {
35095
- await bindingStore.saveBinding(buildNextBinding(binding, report, currentTime));
35100
+ await bindingStore.saveBinding(buildNextBinding(binding, report, currentTime, failurePolicy));
35096
35101
  }
35097
35102
  await onReportFailure?.({
35098
35103
  binding: binding ?? undefined,
@@ -35391,7 +35396,7 @@ var toBinding2 = (row) => ({
35391
35396
  updatedAt: row.updated_at.getTime(),
35392
35397
  username: row.username ?? undefined
35393
35398
  });
35394
- var createNeonLinkedProviderBindingStore = (db) => ({
35399
+ var createLinkedProviderBindingStore = (db) => ({
35395
35400
  getBinding: async (id2) => {
35396
35401
  const [row] = await db.select().from(linkedProviderBindingsTable).where(eq(linkedProviderBindingsTable.id, id2)).limit(1);
35397
35402
  return row ? toBinding2(row) : undefined;
@@ -35442,7 +35447,7 @@ var createNeonLinkedProviderBindingStore = (db) => ({
35442
35447
  });
35443
35448
  }
35444
35449
  });
35445
- var createNeonLinkedProviderGrantStore = (db) => ({
35450
+ var createLinkedProviderGrantStore = (db) => ({
35446
35451
  getGrant: async (id2) => {
35447
35452
  const [row] = await db.select().from(linkedProviderGrantsTable).where(eq(linkedProviderGrantsTable.id, id2)).limit(1);
35448
35453
  return row ? toGrant2(row) : undefined;
@@ -35498,9 +35503,9 @@ var createNeonLinkedProviderStores = (databaseUrl) => {
35498
35503
  const sql2 = as(databaseUrl);
35499
35504
  const db = drizzle({ client: sql2 });
35500
35505
  return {
35501
- bindingStore: createNeonLinkedProviderBindingStore(db),
35506
+ bindingStore: createLinkedProviderBindingStore(db),
35502
35507
  db,
35503
- grantStore: createNeonLinkedProviderGrantStore(db)
35508
+ grantStore: createLinkedProviderGrantStore(db)
35504
35509
  };
35505
35510
  };
35506
35511
  var createNeonOAuthLinkedProviderCredentialResolver = async ({
@@ -42066,5 +42071,5 @@ export {
42066
42071
  userSessionIdTypebox
42067
42072
  };
42068
42073
 
42069
- //# debugId=EBB1CE453260D04564756E2164756E21
42074
+ //# debugId=6EB6A751AD43F22164756E2164756E21
42070
42075
  //# sourceMappingURL=server.js.map