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

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