@cedarjs/auth-dbauth-api 5.0.4-next.167 → 5.0.4

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.
@@ -1,25 +1,41 @@
1
- import md5 from "md5";
2
- import { v4 as uuidv4 } from "uuid";
3
- import {
4
- createCorsContext,
5
- isFetchApiRequest,
6
- normalizeRequest
7
- } from "@cedarjs/api";
8
- import * as DbAuthError from "./errors.js";
9
- import {
10
- decryptSession,
11
- encryptSession,
12
- extractCookie,
13
- extractHashingOptions,
14
- generateCookieName,
15
- getDbAuthResponseBuilder,
16
- getSession,
17
- hashPassword,
18
- hashToken,
19
- isLegacySession,
20
- legacyHashPassword,
21
- webAuthnSession
22
- } from "./shared.js";
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var DbAuthHandler_exports = {};
30
+ __export(DbAuthHandler_exports, {
31
+ DbAuthHandler: () => DbAuthHandler
32
+ });
33
+ module.exports = __toCommonJS(DbAuthHandler_exports);
34
+ var import_md5 = __toESM(require("md5"));
35
+ var import_uuid = require("uuid");
36
+ var import_api = require("@cedarjs/api");
37
+ var DbAuthError = __toESM(require("./errors.js"));
38
+ var import_shared = require("./shared.js");
23
39
  const DEFAULT_ALLOWED_USER_FIELDS = ["id", "email"];
24
40
  class DbAuthHandler {
25
41
  event;
@@ -85,7 +101,7 @@ class DbAuthHandler {
85
101
  }
86
102
  // generate a new token (standard UUID)
87
103
  static get CSRF_TOKEN() {
88
- return uuidv4();
104
+ return (0, import_uuid.v4)();
89
105
  }
90
106
  static get AVAILABLE_WEBAUTHN_TRANSPORTS() {
91
107
  return ["usb", "ble", "nfc", "internal"];
@@ -104,7 +120,7 @@ class DbAuthHandler {
104
120
  deleteHeaders.append(
105
121
  "set-cookie",
106
122
  [
107
- `${generateCookieName(this.options.cookie?.name)}=`,
123
+ `${(0, import_shared.generateCookieName)(this.options.cookie?.name)}=`,
108
124
  ...this._cookieAttributes({ expires: "now" })
109
125
  ].join(";")
110
126
  );
@@ -119,9 +135,9 @@ class DbAuthHandler {
119
135
  constructor(event, _context, options) {
120
136
  this.options = options;
121
137
  this.event = event;
122
- this.httpMethod = isFetchApiRequest(event) ? event.method : event.httpMethod;
123
- this.cookie = extractCookie(event) || "";
124
- this.createResponse = getDbAuthResponseBuilder(event);
138
+ this.httpMethod = (0, import_api.isFetchApiRequest)(event) ? event.method : event.httpMethod;
139
+ this.cookie = (0, import_shared.extractCookie)(event) || "";
140
+ this.createResponse = (0, import_shared.getDbAuthResponseBuilder)(event);
125
141
  this._validateOptions();
126
142
  this.db = this.options.db;
127
143
  this.dbAccessor = this.db[this.options.authModelAccessor];
@@ -139,11 +155,11 @@ class DbAuthHandler {
139
155
  );
140
156
  this.webAuthnExpiresDate = webAuthnExpiresAt.toUTCString();
141
157
  if (options.cors) {
142
- this.corsContext = createCorsContext(options.cors);
158
+ this.corsContext = (0, import_api.createCorsContext)(options.cors);
143
159
  }
144
160
  try {
145
- this.encryptedSession = getSession(this.cookie, this.options.cookie?.name);
146
- const [session, csrfToken] = decryptSession(this.encryptedSession);
161
+ this.encryptedSession = (0, import_shared.getSession)(this.cookie, this.options.cookie?.name);
162
+ const [session, csrfToken] = (0, import_shared.decryptSession)(this.encryptedSession);
147
163
  this.session = session;
148
164
  this.sessionCsrfToken = csrfToken;
149
165
  } catch (e) {
@@ -158,7 +174,7 @@ class DbAuthHandler {
158
174
  // is parsed async
159
175
  async init() {
160
176
  if (!this._normalizedRequest) {
161
- this._normalizedRequest = await normalizeRequest(
177
+ this._normalizedRequest = await (0, import_api.normalizeRequest)(
162
178
  this.event
163
179
  );
164
180
  }
@@ -227,10 +243,10 @@ class DbAuthHandler {
227
243
  tokenExpires.setSeconds(
228
244
  tokenExpires.getSeconds() + this.options.forgotPassword.expires
229
245
  );
230
- let token = md5(uuidv4());
246
+ let token = (0, import_md5.default)((0, import_uuid.v4)());
231
247
  const buffer = Buffer.from(token);
232
248
  token = buffer.toString("base64").replace("=", "").substring(0, 16);
233
- const tokenHash = hashToken(token);
249
+ const tokenHash = (0, import_shared.hashToken)(token);
234
250
  try {
235
251
  user = await this.dbAccessor.update({
236
252
  where: {
@@ -259,7 +275,7 @@ class DbAuthHandler {
259
275
  try {
260
276
  const user = await this._getCurrentUser();
261
277
  let headers = new Headers();
262
- if (isLegacySession(this.cookie)) {
278
+ if ((0, import_shared.isLegacySession)(this.cookie)) {
263
279
  headers = this._loginResponse(user)[1];
264
280
  }
265
281
  return [user[this.options.authFields.id], headers];
@@ -310,10 +326,10 @@ class DbAuthHandler {
310
326
  ;
311
327
  this.options.signup.passwordValidation?.(password);
312
328
  let user = await this._findUserByToken(resetToken);
313
- const [hashedPassword] = hashPassword(password, {
329
+ const [hashedPassword] = (0, import_shared.hashPassword)(password, {
314
330
  salt: user.salt
315
331
  });
316
- const [legacyHashedPassword] = legacyHashPassword(password, user.salt);
332
+ const [legacyHashedPassword] = (0, import_shared.legacyHashPassword)(password, user.salt);
317
333
  if (!this.options.resetPassword.allowReusedPassword && user.hashedPassword === hashedPassword || user.hashedPassword === legacyHashedPassword) {
318
334
  throw new DbAuthError.ReusedPasswordError(
319
335
  this.options.resetPassword?.errors?.reusedPassword
@@ -440,7 +456,7 @@ class DbAuthHandler {
440
456
  throw new DbAuthError.WebAuthnError("WebAuthn is not enabled");
441
457
  }
442
458
  const webAuthnOptions = this.options.webAuthn;
443
- const credentialId = webAuthnSession(this.event);
459
+ const credentialId = (0, import_shared.webAuthnSession)(this.event);
444
460
  let user;
445
461
  if (credentialId) {
446
462
  const credential = await this.dbCredentialAccessor.findUnique({
@@ -669,9 +685,9 @@ class DbAuthHandler {
669
685
  // creates the session)
670
686
  _createSessionCookieString(data, csrfToken) {
671
687
  const session = JSON.stringify(data) + ";" + csrfToken;
672
- const encrypted = encryptSession(session);
688
+ const encrypted = (0, import_shared.encryptSession)(session);
673
689
  const sessionCookieString = [
674
- `${generateCookieName(this.options.cookie?.name)}=${encrypted}`,
690
+ `${(0, import_shared.generateCookieName)(this.options.cookie?.name)}=${encrypted}`,
675
691
  ...this._cookieAttributes({ expires: this.sessionExpiresDate })
676
692
  ].join(";");
677
693
  return sessionCookieString;
@@ -689,7 +705,7 @@ class DbAuthHandler {
689
705
  tokenExpires.setSeconds(
690
706
  tokenExpires.getSeconds() - this.options.forgotPassword.expires
691
707
  );
692
- const tokenHash = hashToken(token);
708
+ const tokenHash = (0, import_shared.hashToken)(token);
693
709
  const user = await this.dbAccessor.findFirst({
694
710
  where: {
695
711
  [this.options.authFields.resetToken]: tokenHash
@@ -755,11 +771,11 @@ class DbAuthHandler {
755
771
  // with the one in the database. Falls back to the legacy CryptoJS algorihtm
756
772
  // if no options are present.
757
773
  async _verifyPassword(user, password) {
758
- const options = extractHashingOptions(
774
+ const options = (0, import_shared.extractHashingOptions)(
759
775
  user[this.options.authFields.hashedPassword]
760
776
  );
761
777
  if (Object.keys(options).length) {
762
- const [hashedPassword] = hashPassword(password, {
778
+ const [hashedPassword] = (0, import_shared.hashPassword)(password, {
763
779
  salt: user[this.options.authFields.salt],
764
780
  options
765
781
  });
@@ -767,12 +783,12 @@ class DbAuthHandler {
767
783
  return user;
768
784
  }
769
785
  } else {
770
- const [legacyHashedPassword] = legacyHashPassword(
786
+ const [legacyHashedPassword] = (0, import_shared.legacyHashPassword)(
771
787
  password,
772
788
  user[this.options.authFields.salt]
773
789
  );
774
790
  if (legacyHashedPassword === user[this.options.authFields.hashedPassword]) {
775
- const [newHashedPassword] = hashPassword(password, {
791
+ const [newHashedPassword] = (0, import_shared.hashPassword)(password, {
776
792
  salt: user[this.options.authFields.salt]
777
793
  });
778
794
  await this.dbAccessor.update({
@@ -831,7 +847,7 @@ class DbAuthHandler {
831
847
  this.options.signup?.errors?.usernameTaken
832
848
  );
833
849
  }
834
- const [hashedPassword, salt] = hashPassword(password);
850
+ const [hashedPassword, salt] = (0, import_shared.hashPassword)(password);
835
851
  const newUser = await this.options.signup.handler({
836
852
  username,
837
853
  hashedPassword,
@@ -909,6 +925,7 @@ class DbAuthHandler {
909
925
  return findUniqueUserMatchCriteriaOptions;
910
926
  }
911
927
  }
912
- export {
928
+ // Annotate the CommonJS export names for ESM import in node:
929
+ 0 && (module.exports = {
913
930
  DbAuthHandler
914
- };
931
+ });
package/dist/decoder.js CHANGED
@@ -1,10 +1,34 @@
1
- import { dbAuthSession } from "./shared.js";
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var decoder_exports = {};
20
+ __export(decoder_exports, {
21
+ authDecoder: () => authDecoder,
22
+ createAuthDecoder: () => createAuthDecoder
23
+ });
24
+ module.exports = __toCommonJS(decoder_exports);
25
+ var import_shared = require("./shared.js");
2
26
  const createAuthDecoder = (cookieNameTemplate) => {
3
27
  return async (_token, type, req) => {
4
28
  if (type !== "dbAuth") {
5
29
  return null;
6
30
  }
7
- const session = dbAuthSession(req.event, cookieNameTemplate);
31
+ const session = (0, import_shared.dbAuthSession)(req.event, cookieNameTemplate);
8
32
  return session;
9
33
  };
10
34
  };
@@ -12,10 +36,11 @@ const authDecoder = async (_authHeaderValue, type, req) => {
12
36
  if (type !== "dbAuth") {
13
37
  return null;
14
38
  }
15
- const session = dbAuthSession(req.event, void 0);
39
+ const session = (0, import_shared.dbAuthSession)(req.event, void 0);
16
40
  return session;
17
41
  };
18
- export {
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
19
44
  authDecoder,
20
45
  createAuthDecoder
21
- };
46
+ });
package/dist/errors.js CHANGED
@@ -1,3 +1,56 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var errors_exports = {};
20
+ __export(errors_exports, {
21
+ CsrfTokenMismatchError: () => CsrfTokenMismatchError,
22
+ DuplicateUsernameError: () => DuplicateUsernameError,
23
+ FieldRequiredError: () => FieldRequiredError,
24
+ FlowNotEnabledError: () => FlowNotEnabledError,
25
+ GenericError: () => GenericError,
26
+ IncorrectPasswordError: () => IncorrectPasswordError,
27
+ MissingWebAuthnConfigError: () => MissingWebAuthnConfigError,
28
+ NoForgotPasswordHandlerError: () => NoForgotPasswordHandlerError,
29
+ NoLoginHandlerError: () => NoLoginHandlerError,
30
+ NoResetPasswordHandlerError: () => NoResetPasswordHandlerError,
31
+ NoSessionExpirationError: () => NoSessionExpirationError,
32
+ NoSessionSecretError: () => NoSessionSecretError,
33
+ NoSignupHandlerError: () => NoSignupHandlerError,
34
+ NoUserIdError: () => NoUserIdError,
35
+ NoWebAuthnConfigError: () => NoWebAuthnConfigError,
36
+ NoWebAuthnSessionError: () => NoWebAuthnSessionError,
37
+ NotLoggedInError: () => NotLoggedInError,
38
+ PasswordRequiredError: () => PasswordRequiredError,
39
+ PasswordValidationError: () => PasswordValidationError,
40
+ ResetTokenExpiredError: () => ResetTokenExpiredError,
41
+ ResetTokenInvalidError: () => ResetTokenInvalidError,
42
+ ResetTokenRequiredError: () => ResetTokenRequiredError,
43
+ ReusedPasswordError: () => ReusedPasswordError,
44
+ SessionDecryptionError: () => SessionDecryptionError,
45
+ UnknownAuthMethodError: () => UnknownAuthMethodError,
46
+ UserNotFoundError: () => UserNotFoundError,
47
+ UsernameAndPasswordRequiredError: () => UsernameAndPasswordRequiredError,
48
+ UsernameNotFoundError: () => UsernameNotFoundError,
49
+ UsernameRequiredError: () => UsernameRequiredError,
50
+ WebAuthnError: () => WebAuthnError,
51
+ WrongVerbError: () => WrongVerbError
52
+ });
53
+ module.exports = __toCommonJS(errors_exports);
1
54
  class NoSessionSecretError extends Error {
2
55
  constructor() {
3
56
  super(
@@ -196,7 +249,8 @@ class NoWebAuthnSessionError extends WebAuthnError {
196
249
  this.name = "NoWebAuthnSessionError";
197
250
  }
198
251
  }
199
- export {
252
+ // Annotate the CommonJS export names for ESM import in node:
253
+ 0 && (module.exports = {
200
254
  CsrfTokenMismatchError,
201
255
  DuplicateUsernameError,
202
256
  FieldRequiredError,
@@ -228,4 +282,4 @@ export {
228
282
  UsernameRequiredError,
229
283
  WebAuthnError,
230
284
  WrongVerbError
231
- };
285
+ });
package/dist/index.js CHANGED
@@ -1,9 +1,38 @@
1
- export * from "./DbAuthHandler.js";
2
- import { PasswordValidationError } from "./errors.js";
3
- export * from "./shared.js";
4
- import { authDecoder, createAuthDecoder } from "./decoder.js";
5
- export {
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var index_exports = {};
21
+ __export(index_exports, {
22
+ PasswordValidationError: () => import_errors.PasswordValidationError,
23
+ authDecoder: () => import_decoder.authDecoder,
24
+ createAuthDecoder: () => import_decoder.createAuthDecoder
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ __reExport(index_exports, require("./DbAuthHandler.js"), module.exports);
28
+ var import_errors = require("./errors.js");
29
+ __reExport(index_exports, require("./shared.js"), module.exports);
30
+ var import_decoder = require("./decoder.js");
31
+ // Annotate the CommonJS export names for ESM import in node:
32
+ 0 && (module.exports = {
6
33
  PasswordValidationError,
7
34
  authDecoder,
8
- createAuthDecoder
9
- };
35
+ createAuthDecoder,
36
+ ...require("./DbAuthHandler.js"),
37
+ ...require("./shared.js")
38
+ });
package/dist/shared.js CHANGED
@@ -1,7 +1,52 @@
1
- import crypto from "node:crypto";
2
- import { getEventHeader, isFetchApiRequest } from "@cedarjs/api";
3
- import { getConfig, getConfigPath } from "@cedarjs/project-config";
4
- import * as DbAuthError from "./errors.js";
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var shared_exports = {};
30
+ __export(shared_exports, {
31
+ dbAuthSession: () => dbAuthSession,
32
+ decryptSession: () => decryptSession,
33
+ encryptSession: () => encryptSession,
34
+ extractCookie: () => extractCookie,
35
+ extractHashingOptions: () => extractHashingOptions,
36
+ generateCookieName: () => generateCookieName,
37
+ getDbAuthResponseBuilder: () => getDbAuthResponseBuilder,
38
+ getSession: () => getSession,
39
+ hashPassword: () => hashPassword,
40
+ hashToken: () => hashToken,
41
+ isLegacySession: () => isLegacySession,
42
+ legacyHashPassword: () => legacyHashPassword,
43
+ webAuthnSession: () => webAuthnSession
44
+ });
45
+ module.exports = __toCommonJS(shared_exports);
46
+ var import_node_crypto = __toESM(require("node:crypto"));
47
+ var import_api = require("@cedarjs/api");
48
+ var import_project_config = require("@cedarjs/project-config");
49
+ var DbAuthError = __toESM(require("./errors.js"));
5
50
  const DEFAULT_SCRYPT_OPTIONS = {
6
51
  cost: 2 ** 14,
7
52
  blockSize: 8,
@@ -9,17 +54,17 @@ const DEFAULT_SCRYPT_OPTIONS = {
9
54
  };
10
55
  const getPort = () => {
11
56
  try {
12
- getConfigPath();
57
+ (0, import_project_config.getConfigPath)();
13
58
  } catch {
14
59
  return 8911;
15
60
  }
16
- return getConfig().api.port;
61
+ return (0, import_project_config.getConfig)().api.port;
17
62
  };
18
63
  const eventGraphiQLHeadersCookie = (event) => {
19
64
  if (process.env.NODE_ENV !== "development") {
20
65
  return;
21
66
  }
22
- const impersationationHeader = getEventHeader(
67
+ const impersationationHeader = (0, import_api.getEventHeader)(
23
68
  event,
24
69
  "rw-studio-impersonation-cookie"
25
70
  );
@@ -27,7 +72,7 @@ const eventGraphiQLHeadersCookie = (event) => {
27
72
  return impersationationHeader;
28
73
  }
29
74
  try {
30
- if (!isFetchApiRequest(event)) {
75
+ if (!(0, import_api.isFetchApiRequest)(event)) {
31
76
  const jsonBody = JSON.parse(event.body ?? "{}");
32
77
  return jsonBody?.extensions?.headers?.cookie || jsonBody?.extensions?.headers?.Cookie;
33
78
  }
@@ -45,17 +90,17 @@ const legacyDecryptSession = (encryptedText) => {
45
90
  const md5Hashes = [];
46
91
  let digest = password;
47
92
  for (let i = 0; i < 3; i++) {
48
- md5Hashes[i] = crypto.createHash("md5").update(digest).digest();
93
+ md5Hashes[i] = import_node_crypto.default.createHash("md5").update(digest).digest();
49
94
  digest = Buffer.concat([md5Hashes[i], password]);
50
95
  }
51
96
  const key = Buffer.concat([md5Hashes[0], md5Hashes[1]]);
52
97
  const iv = md5Hashes[2];
53
98
  const contents = cypher.slice(16);
54
- const decipher = crypto.createDecipheriv("aes-256-cbc", key, iv);
99
+ const decipher = import_node_crypto.default.createDecipheriv("aes-256-cbc", key, iv);
55
100
  return decipher.update(contents) + decipher.final("utf-8");
56
101
  };
57
102
  const extractCookie = (event) => {
58
- return eventGraphiQLHeadersCookie(event) || getEventHeader(event, "Cookie");
103
+ return eventGraphiQLHeadersCookie(event) || (0, import_api.getEventHeader)(event, "Cookie");
59
104
  };
60
105
  const isLegacySession = (text) => {
61
106
  if (!text) {
@@ -72,7 +117,7 @@ const decryptSession = (text) => {
72
117
  const [encryptedText, iv] = text.split("|");
73
118
  try {
74
119
  if (iv) {
75
- const decipher = crypto.createDecipheriv(
120
+ const decipher = import_node_crypto.default.createDecipheriv(
76
121
  "aes-256-cbc",
77
122
  process.env.SESSION_SECRET.substring(0, 32),
78
123
  Buffer.from(iv, "base64")
@@ -89,8 +134,8 @@ const decryptSession = (text) => {
89
134
  }
90
135
  };
91
136
  const encryptSession = (dataString) => {
92
- const iv = crypto.randomBytes(16);
93
- const cipher = crypto.createCipheriv(
137
+ const iv = import_node_crypto.default.randomBytes(16);
138
+ const cipher = import_node_crypto.default.createCipheriv(
94
139
  "aes-256-cbc",
95
140
  process.env.SESSION_SECRET.substring(0, 32),
96
141
  iv
@@ -137,13 +182,13 @@ const webAuthnSession = (event) => {
137
182
  return webAuthnCookie.split("=")[1].trim();
138
183
  };
139
184
  const hashToken = (token) => {
140
- return crypto.createHash("sha256").update(token).digest("hex");
185
+ return import_node_crypto.default.createHash("sha256").update(token).digest("hex");
141
186
  };
142
187
  const hashPassword = (text, {
143
- salt = crypto.randomBytes(32).toString("hex"),
188
+ salt = import_node_crypto.default.randomBytes(32).toString("hex"),
144
189
  options = DEFAULT_SCRYPT_OPTIONS
145
190
  } = {}) => {
146
- const encryptedString = crypto.scryptSync(text.normalize("NFC"), salt, 32, options).toString("hex");
191
+ const encryptedString = import_node_crypto.default.scryptSync(text.normalize("NFC"), salt, 32, options).toString("hex");
147
192
  const optionsToString = [
148
193
  options.cost,
149
194
  options.blockSize,
@@ -152,9 +197,9 @@ const hashPassword = (text, {
152
197
  return [`${encryptedString}|${optionsToString.join("|")}`, salt];
153
198
  };
154
199
  const legacyHashPassword = (text, salt) => {
155
- const useSalt = salt || crypto.randomBytes(32).toString("hex");
200
+ const useSalt = salt || import_node_crypto.default.randomBytes(32).toString("hex");
156
201
  return [
157
- crypto.pbkdf2Sync(text, useSalt, 1, 32, "SHA1").toString("hex"),
202
+ import_node_crypto.default.pbkdf2Sync(text, useSalt, 1, 32, "SHA1").toString("hex"),
158
203
  useSalt
159
204
  ];
160
205
  };
@@ -205,7 +250,8 @@ const extractHashingOptions = (text) => {
205
250
  return {};
206
251
  }
207
252
  };
208
- export {
253
+ // Annotate the CommonJS export names for ESM import in node:
254
+ 0 && (module.exports = {
209
255
  dbAuthSession,
210
256
  decryptSession,
211
257
  encryptSession,
@@ -219,4 +265,4 @@ export {
219
265
  isLegacySession,
220
266
  legacyHashPassword,
221
267
  webAuthnSession
222
- };
268
+ });
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@cedarjs/auth-dbauth-api",
3
- "version": "5.0.4-next.167",
3
+ "version": "5.0.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cedarjs/cedar.git",
7
7
  "directory": "packages/auth-providers/dbAuth/api"
8
8
  },
9
9
  "license": "MIT",
10
- "type": "module",
10
+ "type": "commonjs",
11
11
  "exports": {
12
12
  ".": {
13
13
  "default": {
@@ -46,9 +46,9 @@
46
46
  "dist"
47
47
  ],
48
48
  "scripts": {
49
- "build": "node ./build.mts",
49
+ "build": "node ./build.mts && yarn build:types",
50
50
  "build:pack": "yarn pack -o cedarjs-auth-dbauth-api.tgz",
51
- "build:types": "tsc --build --verbose ./tsconfig.build.json",
51
+ "build:types": "tsc --build --verbose ./tsconfig.json",
52
52
  "build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx,template\" --ignore dist --exec \"yarn build\"",
53
53
  "check:attw": "yarn cedar-fwtools-attw",
54
54
  "check:package": "concurrently npm:check:attw yarn:publint",
@@ -57,21 +57,20 @@
57
57
  "test:watch": "vitest watch"
58
58
  },
59
59
  "dependencies": {
60
- "@cedarjs/project-config": "5.0.4-next.167",
60
+ "@cedarjs/project-config": "5.0.4",
61
61
  "md5": "2.3.0",
62
62
  "uuid": "11.1.0"
63
63
  },
64
64
  "devDependencies": {
65
- "@cedarjs/api": "5.0.4-next.167",
66
- "@cedarjs/framework-tools": "5.0.4-next.167",
65
+ "@arethetypeswrong/cli": "0.18.4",
66
+ "@cedarjs/api": "5.0.4",
67
+ "@cedarjs/framework-tools": "5.0.4",
67
68
  "@simplewebauthn/server": "10.0.1",
68
- "@simplewebauthn/types": "10.0.0",
69
- "@types/aws-lambda": "8.10.162",
70
69
  "@types/md5": "2.3.6",
71
70
  "concurrently": "9.2.4",
72
- "publint": "0.3.22",
71
+ "publint": "0.3.21",
73
72
  "typescript": "5.9.3",
74
- "vitest": "4.1.10"
73
+ "vitest": "3.2.6"
75
74
  },
76
75
  "engines": {
77
76
  "node": ">=24"