@cedarjs/auth-dbauth-setup 2.8.1-next.116 → 2.8.1

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.js CHANGED
@@ -1,22 +1,20 @@
1
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 __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
- var src_exports = {};
17
- module.exports = __toCommonJS(src_exports);
18
- __reExport(src_exports, require("./setup"), module.exports);
19
- // Annotate the CommonJS export names for ESM import in node:
20
- 0 && (module.exports = {
21
- ...require("./setup")
2
+
3
+ var _context;
4
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js/object/define-property");
5
+ var _forEachInstanceProperty = require("@babel/runtime-corejs3/core-js/instance/for-each");
6
+ var _Object$keys = require("@babel/runtime-corejs3/core-js/object/keys");
7
+ _Object$defineProperty(exports, "__esModule", {
8
+ value: true
22
9
  });
10
+ var _setup = require("./setup");
11
+ _forEachInstanceProperty(_context = _Object$keys(_setup)).call(_context, function (key) {
12
+ if (key === "default" || key === "__esModule") return;
13
+ if (key in exports && exports[key] === _setup[key]) return;
14
+ _Object$defineProperty(exports, key, {
15
+ enumerable: true,
16
+ get: function () {
17
+ return _setup[key];
18
+ }
19
+ });
20
+ });
package/dist/setup.js CHANGED
@@ -1,78 +1,41 @@
1
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 setup_exports = {};
30
- __export(setup_exports, {
31
- builder: () => builder,
32
- command: () => command,
33
- description: () => description,
34
- handler: () => handler
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js/object/define-property");
4
+ _Object$defineProperty(exports, "__esModule", {
5
+ value: true
35
6
  });
36
- module.exports = __toCommonJS(setup_exports);
37
- var import_termi_link = require("termi-link");
38
- const command = "dbAuth";
39
- const description = "Set up auth for for dbAuth";
7
+ exports.builder = builder;
8
+ exports.handler = exports.description = exports.command = void 0;
9
+ var _termiLink = require("termi-link");
10
+ const command = exports.command = 'dbAuth';
11
+ const description = exports.description = 'Set up auth for for dbAuth';
40
12
  function builder(yargs) {
41
- yargs.option("force", {
42
- alias: "f",
13
+ yargs.option('force', {
14
+ alias: 'f',
43
15
  default: false,
44
- description: "Overwrite existing configuration",
45
- type: "boolean"
46
- }).option("webauthn", {
47
- alias: "w",
16
+ description: 'Overwrite existing configuration',
17
+ type: 'boolean'
18
+ }).option('webauthn', {
19
+ alias: 'w',
48
20
  default: null,
49
- description: "Include WebAuthn support (TouchID/FaceID)",
50
- type: "boolean"
51
- }).option("createUserModel", {
52
- alias: "u",
21
+ description: 'Include WebAuthn support (TouchID/FaceID)',
22
+ type: 'boolean'
23
+ }).option('createUserModel', {
24
+ alias: 'u',
53
25
  default: null,
54
- description: "Create a User database model",
55
- type: "boolean"
56
- }).option("generateAuthPages", {
57
- alias: "g",
26
+ description: 'Create a User database model',
27
+ type: 'boolean'
28
+ }).option('generateAuthPages', {
29
+ alias: 'g',
58
30
  default: null,
59
- description: "Generate auth pages (login, signup, etc.)",
60
- type: "boolean"
61
- }).epilogue(
62
- `Also see the ${(0, import_termi_link.terminalLink)(
63
- "CedarJS CLI Reference",
64
- "https://cedarjs.com/docs/cli-commands#setup-auth"
65
- )}`
66
- );
31
+ description: 'Generate auth pages (login, signup, etc.)',
32
+ type: 'boolean'
33
+ }).epilogue(`Also see the ${(0, _termiLink.terminalLink)('CedarJS CLI Reference', 'https://cedarjs.com/docs/cli-commands#setup-auth')}`);
67
34
  }
68
- const handler = async (options) => {
69
- const { handler: handler2 } = await import("./setupHandler.js");
70
- return handler2(options);
35
+ const handler = async options => {
36
+ const {
37
+ handler
38
+ } = await import('./setupHandler.js');
39
+ return handler(options);
71
40
  };
72
- // Annotate the CommonJS export names for ESM import in node:
73
- 0 && (module.exports = {
74
- builder,
75
- command,
76
- description,
77
- handler
78
- });
41
+ exports.handler = handler;
package/dist/setupData.js CHANGED
@@ -1,58 +1,25 @@
1
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 setupData_exports = {};
30
- __export(setupData_exports, {
31
- createUserModelTask: () => createUserModelTask,
32
- extraTask: () => extraTask,
33
- noteGenerate: () => noteGenerate,
34
- notes: () => notes,
35
- notesCreatedUserModel: () => notesCreatedUserModel
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js/object/define-property");
4
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
5
+ _Object$defineProperty(exports, "__esModule", {
6
+ value: true
36
7
  });
37
- module.exports = __toCommonJS(setupData_exports);
38
- var import_node_crypto = __toESM(require("node:crypto"));
39
- var import_node_path = __toESM(require("node:path"));
40
- var import_cli_helpers = require("@cedarjs/cli-helpers");
41
- var import_shared = require("./shared");
42
- const secret = import_node_crypto.default.randomBytes(32).toString("base64");
43
- const extraTask = (0, import_cli_helpers.addEnvVarTask)(
44
- "SESSION_SECRET",
45
- secret,
46
- "Used to encrypt/decrypt session cookies. Change this value and re-deploy to log out all users of your app at once."
47
- );
48
- const createUserModelTask = {
49
- title: "Creating model `User`...",
50
- task: async (ctx) => {
51
- const hasUserModel = await (0, import_shared.hasModel)("User");
8
+ exports.notesCreatedUserModel = exports.notes = exports.noteGenerate = exports.extraTask = exports.createUserModelTask = void 0;
9
+ var _nodeCrypto = _interopRequireDefault(require("node:crypto"));
10
+ var _path = _interopRequireDefault(require("path"));
11
+ var _cliHelpers = require("@cedarjs/cli-helpers");
12
+ var _shared = require("./shared");
13
+ const secret = _nodeCrypto.default.randomBytes(32).toString('base64');
14
+ const extraTask = exports.extraTask = (0, _cliHelpers.addEnvVarTask)('SESSION_SECRET', secret, 'Used to encrypt/decrypt session cookies. Change this value and re-deploy ' + 'to log out all users of your app at once.');
15
+ const createUserModelTask = exports.createUserModelTask = {
16
+ title: 'Creating model `User`...',
17
+ task: async ctx => {
18
+ const hasUserModel = await (0, _shared.hasModel)('User');
52
19
  if (hasUserModel && !ctx.force) {
53
- throw new Error("User model already exists");
20
+ throw new Error('User model already exists');
54
21
  }
55
- (0, import_shared.addModels)(`
22
+ (0, _shared.addModels)(`
56
23
  model User {
57
24
  id String @id @default(uuid())
58
25
  email String @unique
@@ -66,100 +33,8 @@ model User {
66
33
  `);
67
34
  }
68
35
  };
69
- const notes = [
70
- `${import_cli_helpers.colors.warning("Done! But you have a little more work to do:")}
71
- `,
72
- "You will need to add a couple of fields to your User table in order",
73
- "to store a hashed password and salt:",
74
- "",
75
- " model User {",
76
- " id String @id @default(uuid())",
77
- " email String @unique",
78
- " hashedPassword String // <\u2500\u2510",
79
- " salt String // <\u2500\u253C\u2500 add these lines",
80
- " resetToken String? // <\u2500\u2524",
81
- " resetTokenExpiresAt DateTime? // <\u2500\u2518",
82
- " }",
83
- "",
84
- "If you already have existing user records you will need to provide",
85
- "a default value for `hashedPassword` and `salt` or Prisma complains, so",
86
- "change those to: ",
87
- "",
88
- ' hashedPassword String @default("")',
89
- ' salt String @default("")',
90
- "",
91
- "If you expose any of your user data via GraphQL be sure to exclude",
92
- "`hashedPassword` and `salt` (or whatever you named them) from the",
93
- "SDL file that defines the fields for your user.",
94
- "",
95
- "You'll need to let Cedar know what fields you're using for your users'",
96
- "`id` and `username` fields. In this case we're using `id` and `email`,",
97
- "so update those in the `authFields` config in",
98
- `\`${import_shared.functionsPath}/auth.js\`. This is also the place to tell Cedar if`,
99
- "you used a different name for the `hashedPassword`, `salt`,",
100
- "`resetToken` or `resetTokenExpiresAt`, fields:`",
101
- "",
102
- " authFields: {",
103
- " id: 'id',",
104
- " username: 'email',",
105
- " hashedPassword: 'hashedPassword',",
106
- " salt: 'salt',",
107
- " resetToken: 'resetToken',",
108
- " resetTokenExpiresAt: 'resetTokenExpiresAt',",
109
- " },",
110
- "",
111
- "To get the actual user that's logged in, take a look at `getCurrentUser()`",
112
- `in \`${import_shared.libPath}/auth.js\`. We default it to something simple, but you may`,
113
- "use different names for your model or unique ID fields, in which case you",
114
- "need to update those calls (instructions are in the comment above the code).",
115
- "",
116
- "Finally, we created a SESSION_SECRET environment variable for you in",
117
- `${import_node_path.default.join((0, import_cli_helpers.getPaths)().base, ".env")}. This value should NOT be checked`,
118
- "into version control and should be unique for each environment you",
119
- "deploy to. If you ever need to log everyone out of your app at once",
120
- "change this secret to a new value and deploy. To create a new secret, run:",
121
- "",
122
- " yarn cedar generate secret",
123
- ""
124
- ];
125
- const notesCreatedUserModel = [
126
- `${import_cli_helpers.colors.warning("Done! But you have a little more work to do:")}
127
- `,
128
- "If you expose any of your user data via GraphQL be sure to exclude",
129
- "`hashedPassword` and `salt` (or whatever you named them) from the",
130
- "SDL file that defines the fields for your user.",
131
- "",
132
- "To get the actual user that's logged in, take a look at `getCurrentUser()`",
133
- `in \`${import_shared.libPath}/auth.js\`. We default it to something simple, but you may`,
134
- "use different names for your model or unique ID fields, in which case you",
135
- "need to update those calls (instructions are in the comment above the code).",
136
- "",
137
- "Finally, we created a SESSION_SECRET environment variable for you in",
138
- `${import_node_path.default.join((0, import_cli_helpers.getPaths)().base, ".env")}. This value should NOT be checked`,
139
- "into version control and should be unique for each environment you",
140
- "deploy to. If you ever need to log everyone out of your app at once",
141
- "change this secret to a new value and deploy. To create a new secret, run:",
142
- "",
143
- " yarn cedar generate secret",
144
- "",
145
- "A new User model was added to your schema. Don't forget to migrate your db",
146
- "before you try using dbAuth:",
147
- "",
148
- " yarn cedar prisma migrate dev",
149
- ""
150
- ];
151
- const noteGenerate = [
152
- "",
153
- "Need simple Login, Signup and Forgot Password pages? We've got a generator",
154
- "for those as well:",
155
- "",
156
- " yarn cedar generate dbAuth"
157
- ];
158
- // Annotate the CommonJS export names for ESM import in node:
159
- 0 && (module.exports = {
160
- createUserModelTask,
161
- extraTask,
162
- noteGenerate,
163
- notes,
164
- notesCreatedUserModel
165
- });
36
+
37
+ // any notes to print out when the job is done
38
+ const notes = exports.notes = [`${_cliHelpers.colors.warning('Done! But you have a little more work to do:')}\n`, 'You will need to add a couple of fields to your User table in order', 'to store a hashed password and salt:', '', ' model User {', ' id String @id @default(uuid())', ' email String @unique', ' hashedPassword String // <─┐', ' salt String // <─┼─ add these lines', ' resetToken String? // <─┤', ' resetTokenExpiresAt DateTime? // <─┘', ' }', '', 'If you already have existing user records you will need to provide', 'a default value for `hashedPassword` and `salt` or Prisma complains, so', 'change those to: ', '', ' hashedPassword String @default("")', ' salt String @default("")', '', 'If you expose any of your user data via GraphQL be sure to exclude', '`hashedPassword` and `salt` (or whatever you named them) from the', 'SDL file that defines the fields for your user.', '', "You'll need to let Cedar know what fields you're using for your users'", "`id` and `username` fields. In this case we're using `id` and `email`,", 'so update those in the `authFields` config in', `\`${_shared.functionsPath}/auth.js\`. This is also the place to tell Cedar if`, 'you used a different name for the `hashedPassword`, `salt`,', '`resetToken` or `resetTokenExpiresAt`, fields:`', '', ' authFields: {', " id: 'id',", " username: 'email',", " hashedPassword: 'hashedPassword',", " salt: 'salt',", " resetToken: 'resetToken',", " resetTokenExpiresAt: 'resetTokenExpiresAt',", ' },', '', "To get the actual user that's logged in, take a look at `getCurrentUser()`", `in \`${_shared.libPath}/auth.js\`. We default it to something simple, but you may`, 'use different names for your model or unique ID fields, in which case you', 'need to update those calls (instructions are in the comment above the code).', '', 'Finally, we created a SESSION_SECRET environment variable for you in', `${_path.default.join((0, _cliHelpers.getPaths)().base, '.env')}. This value should NOT be checked`, 'into version control and should be unique for each environment you', 'deploy to. If you ever need to log everyone out of your app at once', 'change this secret to a new value and deploy. To create a new secret, run:', '', ' yarn cedar generate secret', ''];
39
+ const notesCreatedUserModel = exports.notesCreatedUserModel = [`${_cliHelpers.colors.warning('Done! But you have a little more work to do:')}\n`, 'If you expose any of your user data via GraphQL be sure to exclude', '`hashedPassword` and `salt` (or whatever you named them) from the', 'SDL file that defines the fields for your user.', '', "To get the actual user that's logged in, take a look at `getCurrentUser()`", `in \`${_shared.libPath}/auth.js\`. We default it to something simple, but you may`, 'use different names for your model or unique ID fields, in which case you', 'need to update those calls (instructions are in the comment above the code).', '', 'Finally, we created a SESSION_SECRET environment variable for you in', `${_path.default.join((0, _cliHelpers.getPaths)().base, '.env')}. This value should NOT be checked`, 'into version control and should be unique for each environment you', 'deploy to. If you ever need to log everyone out of your app at once', 'change this secret to a new value and deploy. To create a new secret, run:', '', ' yarn cedar generate secret', '', "A new User model was added to your schema. Don't forget to migrate your db", 'before you try using dbAuth:', '', ' yarn cedar prisma migrate dev', ''];
40
+ const noteGenerate = exports.noteGenerate = ['', "Need simple Login, Signup and Forgot Password pages? We've got a generator", 'for those as well:', '', ' yarn cedar generate dbAuth'];
@@ -1,112 +1,84 @@
1
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 setupHandler_exports = {};
30
- __export(setupHandler_exports, {
31
- createAuthDecoderFunction: () => createAuthDecoderFunction,
32
- handler: () => handler
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js/object/define-property");
4
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
5
+ _Object$defineProperty(exports, "__esModule", {
6
+ value: true
33
7
  });
34
- module.exports = __toCommonJS(setupHandler_exports);
35
- var import_node_fs = __toESM(require("node:fs"));
36
- var import_node_path = __toESM(require("node:path"));
37
- var import_prompts = __toESM(require("prompts"));
38
- var import_cli_helpers = require("@cedarjs/cli-helpers");
39
- var import_setupData = require("./setupData");
40
- var import_shared = require("./shared");
41
- var import_webAuthn = require("./webAuthn.setupData");
8
+ exports.createAuthDecoderFunction = void 0;
9
+ exports.handler = handler;
10
+ var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/includes"));
11
+ require("core-js/modules/es.array.push.js");
12
+ require("core-js/modules/es.json.parse.js");
13
+ var _nodeFs = _interopRequireDefault(require("node:fs"));
14
+ var _path = _interopRequireDefault(require("path"));
15
+ var _prompts = _interopRequireDefault(require("prompts"));
16
+ var _cliHelpers = require("@cedarjs/cli-helpers");
17
+ var _setupData = require("./setupData");
18
+ var _shared = require("./shared");
19
+ var _webAuthn = require("./webAuthn.setupData");
42
20
  async function handler({
43
21
  webauthn,
44
22
  createUserModel,
45
23
  generateAuthPages,
46
24
  force: forceArg
47
25
  }) {
48
- const { version } = JSON.parse(
49
- import_node_fs.default.readFileSync(import_node_path.default.resolve(__dirname, "../package.json"), "utf-8")
50
- );
26
+ const {
27
+ version
28
+ } = JSON.parse(_nodeFs.default.readFileSync(_path.default.resolve(__dirname, '../package.json'), 'utf-8'));
51
29
  const webAuthn = await shouldIncludeWebAuthn(webauthn);
52
30
  const createDbUserModel = await shouldCreateUserModel(createUserModel);
53
31
  const generateDbAuthPages = await shouldGenerateDbAuthPages(generateAuthPages);
54
32
  const oneMoreThing = [];
55
33
  if (webAuthn) {
56
34
  if (createDbUserModel) {
57
- oneMoreThing.push(...import_setupData.notesCreatedUserModel);
35
+ oneMoreThing.push(..._setupData.notesCreatedUserModel);
58
36
  } else {
59
- oneMoreThing.push(...import_webAuthn.notes);
37
+ oneMoreThing.push(..._webAuthn.notes);
60
38
  }
61
39
  if (!generateDbAuthPages) {
62
- oneMoreThing.push(...import_webAuthn.noteGenerate);
40
+ oneMoreThing.push(..._webAuthn.noteGenerate);
63
41
  }
64
42
  } else {
65
43
  if (createDbUserModel) {
66
- oneMoreThing.push(...import_setupData.notesCreatedUserModel);
44
+ oneMoreThing.push(..._setupData.notesCreatedUserModel);
67
45
  } else {
68
- oneMoreThing.push(...import_setupData.notes);
46
+ oneMoreThing.push(..._setupData.notes);
69
47
  }
70
48
  if (!generateDbAuthPages) {
71
- oneMoreThing.push(...import_setupData.noteGenerate);
49
+ oneMoreThing.push(..._setupData.noteGenerate);
72
50
  }
73
51
  }
74
- let createDbUserModelTask = void 0;
52
+ let createDbUserModelTask = undefined;
75
53
  if (createDbUserModel) {
76
54
  if (webAuthn) {
77
- createDbUserModelTask = import_webAuthn.createUserModelTask;
55
+ createDbUserModelTask = _webAuthn.createUserModelTask;
78
56
  } else {
79
- createDbUserModelTask = import_setupData.createUserModelTask;
57
+ createDbUserModelTask = _setupData.createUserModelTask;
80
58
  }
81
59
  }
82
- await (0, import_cli_helpers.standardAuthHandler)({
60
+ await (0, _cliHelpers.standardAuthHandler)({
83
61
  basedir: __dirname,
84
62
  forceArg,
85
- provider: "dbAuth",
63
+ provider: 'dbAuth',
86
64
  authDecoderImport: "import { createAuthDecoder } from '@cedarjs/auth-dbauth-api'",
87
65
  webAuthn,
88
- webPackages: [
89
- `@cedarjs/auth-dbauth-web@${version}`,
90
- ...webAuthn ? import_webAuthn.webPackages : []
91
- ],
92
- apiPackages: [
93
- `@cedarjs/auth-dbauth-api@${version}`,
94
- ...webAuthn ? import_webAuthn.apiPackages : []
95
- ],
96
- extraTasks: [
97
- webAuthn ? import_webAuthn.extraTask : import_setupData.extraTask,
98
- createDbUserModelTask,
99
- createAuthDecoderFunction,
100
- generateDbAuthPages ? (0, import_shared.generateAuthPagesTask)(createDbUserModel) : void 0
101
- ],
66
+ webPackages: [`@cedarjs/auth-dbauth-web@${version}`, ...(webAuthn ? _webAuthn.webPackages : [])],
67
+ apiPackages: [`@cedarjs/auth-dbauth-api@${version}`, ...(webAuthn ? _webAuthn.apiPackages : [])],
68
+ extraTasks: [webAuthn ? _webAuthn.extraTask : _setupData.extraTask, createDbUserModelTask, createAuthDecoderFunction, generateDbAuthPages ? (0, _shared.generateAuthPagesTask)(createDbUserModel) : undefined],
102
69
  notes: oneMoreThing
103
70
  });
104
71
  }
72
+
73
+ /**
74
+ * Prompt the user (unless already specified on the command line) if they want
75
+ * to enable WebAuthn support
76
+ */
105
77
  async function shouldIncludeWebAuthn(webauthn) {
106
78
  if (webauthn === null) {
107
- const webAuthnResponse = await (0, import_prompts.default)({
108
- type: "confirm",
109
- name: "answer",
79
+ const webAuthnResponse = await (0, _prompts.default)({
80
+ type: 'confirm',
81
+ name: 'answer',
110
82
  message: `Enable WebAuthn support (TouchID/FaceID)? See https://cedarjs.com/docs/auth/dbAuth#webAuthn`,
111
83
  initial: false
112
84
  });
@@ -114,70 +86,69 @@ async function shouldIncludeWebAuthn(webauthn) {
114
86
  }
115
87
  return webauthn;
116
88
  }
89
+
90
+ /**
91
+ * Prompt the user (unless already specified on the command line) if they want
92
+ * to create a User model in their Prisma schema
93
+ */
117
94
  async function shouldCreateUserModel(createUserModel) {
118
- const hasUserModel = await (0, import_shared.hasModel)("User");
119
- const modelNames = await (0, import_shared.getModelNames)();
120
- const isNewProject = modelNames.length === 1 && modelNames[0] === "UserExample";
95
+ const hasUserModel = await (0, _shared.hasModel)('User');
96
+ const modelNames = await (0, _shared.getModelNames)();
97
+ const isNewProject = modelNames.length === 1 && modelNames[0] === 'UserExample';
121
98
  if (isNewProject) {
122
99
  return true;
123
100
  }
124
101
  if (createUserModel === null && !hasUserModel) {
125
- const createModelResponse = await (0, import_prompts.default)({
126
- type: "confirm",
127
- name: "answer",
128
- message: "Create User model?",
102
+ const createModelResponse = await (0, _prompts.default)({
103
+ type: 'confirm',
104
+ name: 'answer',
105
+ message: 'Create User model?',
129
106
  initial: false
130
107
  });
131
108
  return createModelResponse.answer;
132
109
  }
133
110
  return createUserModel;
134
111
  }
112
+
113
+ /**
114
+ * Prompt the user (unless already specified on the command line) if they want
115
+ * to generate auth pages. Also checks to make sure auth pages don't already
116
+ * exist before prompting.
117
+ */
135
118
  async function shouldGenerateDbAuthPages(generateAuthPages) {
136
- if (generateAuthPages === null && !(0, import_shared.hasAuthPages)()) {
137
- const generateAuthPagesResponse = await (0, import_prompts.default)({
138
- type: "confirm",
139
- name: "answer",
140
- message: "Generate auth pages (login, signup, forgotten password, etc)?",
119
+ if (generateAuthPages === null && !(0, _shared.hasAuthPages)()) {
120
+ const generateAuthPagesResponse = await (0, _prompts.default)({
121
+ type: 'confirm',
122
+ name: 'answer',
123
+ message: 'Generate auth pages (login, signup, forgotten password, etc)?',
141
124
  initial: false
142
125
  });
143
126
  return generateAuthPagesResponse.answer;
144
127
  }
145
128
  return generateAuthPages;
146
129
  }
147
- const createAuthDecoderFunction = {
148
- title: "Create auth decoder function",
130
+ const createAuthDecoderFunction = exports.createAuthDecoderFunction = {
131
+ title: 'Create auth decoder function',
149
132
  task: () => {
150
- const graphqlPath = (0, import_cli_helpers.getGraphqlPath)();
133
+ const graphqlPath = (0, _cliHelpers.getGraphqlPath)();
151
134
  if (!graphqlPath) {
152
- throw new Error("Could not find your graphql file path");
135
+ throw new Error('Could not find your graphql file path');
153
136
  }
154
- const authDecoderCreation = "const authDecoder = createAuthDecoder(cookieName)";
155
- const content = import_node_fs.default.readFileSync(graphqlPath, "utf-8");
156
- let newContent = content.replace(
157
- "import { getCurrentUser } from",
158
- "import { cookieName, getCurrentUser } from"
159
- );
160
- const authDecoderCreationRegexp = new RegExp(
161
- "^" + escapeRegExp(authDecoderCreation),
162
- "m"
163
- );
137
+ const authDecoderCreation = 'const authDecoder = createAuthDecoder(cookieName)';
138
+ const content = _nodeFs.default.readFileSync(graphqlPath, 'utf-8');
139
+ let newContent = content.replace('import { getCurrentUser } from', 'import { cookieName, getCurrentUser } from');
140
+ const authDecoderCreationRegexp = new RegExp('^' + escapeRegExp(authDecoderCreation), 'm');
164
141
  if (!authDecoderCreationRegexp.test(newContent)) {
165
- newContent = newContent.replace(
166
- "export const handler = createGraphQLHandler({",
167
- authDecoderCreation + "\n\nexport const handler = createGraphQLHandler({"
168
- );
142
+ newContent = newContent.replace('export const handler = createGraphQLHandler({', authDecoderCreation + '\n\n' + 'export const handler = createGraphQLHandler({');
169
143
  }
170
- if (!newContent.includes("import { cookieName")) {
171
- throw new Error("Failed to import cookieName");
144
+ if (!(0, _includes.default)(newContent).call(newContent, 'import { cookieName')) {
145
+ throw new Error('Failed to import cookieName');
172
146
  }
173
- import_node_fs.default.writeFileSync(graphqlPath, newContent);
147
+ _nodeFs.default.writeFileSync(graphqlPath, newContent);
174
148
  }
175
149
  };
150
+
151
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping
176
152
  function escapeRegExp(str) {
177
- return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
178
- }
179
- // Annotate the CommonJS export names for ESM import in node:
180
- 0 && (module.exports = {
181
- createAuthDecoderFunction,
182
- handler
183
- });
153
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
154
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,OAAO,QAAkD,CAAA;AACtE,eAAO,MAAM,aAAa,QAGzB,CAAA;AAED,eAAO,MAAM,aAAa,yBAMzB,CAAA;AAED,eAAO,MAAM,QAAQ,GAAU,MAAM,MAAM,qBAe1C,CAAA;AAED,wBAAsB,SAAS,CAAC,MAAM,EAAE,MAAM,iBAS7C;AAED,wBAAgB,YAAY,YAuB3B;AAED,wBAAgB,qBAAqB,CAAC,mBAAmB,EAAE,OAAO;;;EAwBjE"}
1
+ {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,OAAO,QAAkD,CAAA;AACtE,eAAO,MAAM,aAAa,QAGzB,CAAA;AAED,eAAO,MAAM,aAAa,yBAOzB,CAAA;AAED,eAAO,MAAM,QAAQ,GAAU,MAAM,MAAM,qBAe1C,CAAA;AAED,wBAAsB,SAAS,CAAC,MAAM,EAAE,MAAM,iBAS7C;AAED,wBAAgB,YAAY,YAuB3B;AAED,wBAAgB,qBAAqB,CAAC,mBAAmB,EAAE,OAAO;;;EAwBjE"}
package/dist/shared.js CHANGED
@@ -1,86 +1,75 @@
1
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
- addModels: () => addModels,
32
- functionsPath: () => functionsPath,
33
- generateAuthPagesTask: () => generateAuthPagesTask,
34
- getModelNames: () => getModelNames,
35
- hasAuthPages: () => hasAuthPages,
36
- hasModel: () => hasModel,
37
- libPath: () => libPath
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js/object/define-property");
4
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
5
+ _Object$defineProperty(exports, "__esModule", {
6
+ value: true
38
7
  });
39
- module.exports = __toCommonJS(shared_exports);
40
- var import_node_fs = __toESM(require("node:fs"));
41
- var import_node_path = __toESM(require("node:path"));
42
- var import_internals = require("@prisma/internals");
43
- var import_execa = __toESM(require("execa"));
44
- var import_cli_helpers = require("@cedarjs/cli-helpers");
45
- var import_project_config = require("@cedarjs/project-config");
46
- const libPath = (0, import_cli_helpers.getPaths)().api.lib.replace((0, import_cli_helpers.getPaths)().base, "");
47
- const functionsPath = (0, import_cli_helpers.getPaths)().api.functions.replace(
48
- (0, import_cli_helpers.getPaths)().base,
49
- ""
50
- );
8
+ exports.addModels = addModels;
9
+ exports.functionsPath = void 0;
10
+ exports.generateAuthPagesTask = generateAuthPagesTask;
11
+ exports.getModelNames = void 0;
12
+ exports.hasAuthPages = hasAuthPages;
13
+ exports.libPath = exports.hasModel = void 0;
14
+ require("core-js/modules/es.array.push.js");
15
+ var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/map"));
16
+ var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/includes"));
17
+ var _some = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/some"));
18
+ var _nodeFs = _interopRequireDefault(require("node:fs"));
19
+ var _nodePath = _interopRequireDefault(require("node:path"));
20
+ var _internals = require("@prisma/internals");
21
+ var _execa = _interopRequireDefault(require("execa"));
22
+ var _cliHelpers = require("@cedarjs/cli-helpers");
23
+ var _projectConfig = require("@cedarjs/project-config");
24
+ const libPath = exports.libPath = (0, _cliHelpers.getPaths)().api.lib.replace((0, _cliHelpers.getPaths)().base, '');
25
+ const functionsPath = exports.functionsPath = (0, _cliHelpers.getPaths)().api.functions.replace((0, _cliHelpers.getPaths)().base, '');
51
26
  const getModelNames = async () => {
52
- const result = await (0, import_project_config.getPrismaSchemas)();
27
+ var _context;
28
+ const schemaPath = await (0, _projectConfig.getSchemaPath)((0, _cliHelpers.getPaths)().api.prismaConfig);
29
+ const result = await (0, _internals.getSchemaWithPath)(schemaPath);
53
30
  const datamodel = result.schemas;
54
- const schema = await (0, import_internals.getDMMF)({ datamodel });
55
- return schema.datamodel.models.map((model) => model.name);
31
+ const schema = await (0, _internals.getDMMF)({
32
+ datamodel
33
+ });
34
+ return (0, _map.default)(_context = schema.datamodel.models).call(_context, model => model.name);
56
35
  };
57
- const hasModel = async (name) => {
36
+ exports.getModelNames = getModelNames;
37
+ const hasModel = async name => {
38
+ var _context2;
58
39
  if (!name) {
59
40
  return false;
60
41
  }
61
- const modelName = name.replace(/[_-]/g, "").toLowerCase();
62
- const modelNames = (await getModelNames()).map((name2) => name2.toLowerCase());
63
- if (modelNames.includes(modelName)) {
42
+
43
+ // Support PascalCase, camelCase, kebab-case, UPPER_CASE, and lowercase model
44
+ // names
45
+ const modelName = name.replace(/[_-]/g, '').toLowerCase();
46
+ const modelNames = (0, _map.default)(_context2 = await getModelNames()).call(_context2, name => name.toLowerCase());
47
+ if ((0, _includes.default)(modelNames).call(modelNames, modelName)) {
64
48
  return true;
65
49
  }
66
50
  return false;
67
51
  };
52
+ exports.hasModel = hasModel;
68
53
  async function addModels(models) {
69
- const schemaPath = await (0, import_project_config.getSchemaPath)((0, import_cli_helpers.getPaths)().api.prismaConfig);
70
- const isDirectory = import_node_fs.default.statSync(schemaPath).isDirectory();
54
+ const schemaPath = await (0, _projectConfig.getSchemaPath)((0, _cliHelpers.getPaths)().api.prismaConfig);
55
+ const isDirectory = _nodeFs.default.statSync(schemaPath).isDirectory();
71
56
  if (isDirectory) {
72
- import_node_fs.default.writeFileSync(import_node_path.default.join(schemaPath, "user.prisma"), models);
57
+ _nodeFs.default.writeFileSync(_nodePath.default.join(schemaPath, 'user.prisma'), models);
73
58
  } else {
74
- import_node_fs.default.appendFileSync(schemaPath, models);
59
+ _nodeFs.default.appendFileSync(schemaPath, models);
75
60
  }
76
61
  }
77
62
  function hasAuthPages() {
78
- const routes = import_node_fs.default.readFileSync((0, import_cli_helpers.getPaths)().web.routes, "utf-8");
63
+ var _context3;
64
+ const routes = _nodeFs.default.readFileSync((0, _cliHelpers.getPaths)().web.routes, 'utf-8');
65
+
66
+ // If the user already has a route for /login, /signin, or /signup, we
67
+ // assume auth pages are already set up
79
68
  if (/path={?['"]\/(login|signin|signup)['"]}? /i.test(routes)) {
80
69
  return true;
81
70
  }
82
- return (0, import_project_config.processPagesDir)().some((page) => {
83
- if (page.importName === "LoginPage" || page.importName === "LogInPage" || page.importName === "SigninPage" || page.importName === "SignInPage" || page.importName === "SignupPage" || page.importName === "SignUpPage") {
71
+ return (0, _some.default)(_context3 = (0, _projectConfig.processPagesDir)()).call(_context3, page => {
72
+ if (page.importName === 'LoginPage' || page.importName === 'LogInPage' || page.importName === 'SigninPage' || page.importName === 'SignInPage' || page.importName === 'SignupPage' || page.importName === 'SignUpPage') {
84
73
  return true;
85
74
  }
86
75
  return false;
@@ -88,33 +77,18 @@ function hasAuthPages() {
88
77
  }
89
78
  function generateAuthPagesTask(generatingUserModel) {
90
79
  return {
91
- title: "Adding dbAuth pages...",
80
+ title: 'Adding dbAuth pages...',
92
81
  task: async () => {
93
- const rwjsPaths = (0, import_cli_helpers.getPaths)();
94
- const args = ["cedar", "g", "dbAuth"];
82
+ const rwjsPaths = (0, _cliHelpers.getPaths)();
83
+ const args = ['cedar', 'g', 'dbAuth'];
95
84
  if (generatingUserModel) {
96
- args.push(
97
- "--username-label",
98
- "username",
99
- "--password-label",
100
- "password"
101
- );
85
+ args.push('--username-label', 'username', '--password-label', 'password');
102
86
  }
103
- await (0, import_execa.default)("yarn", args, {
104
- stdio: "inherit",
87
+ await (0, _execa.default)('yarn', args, {
88
+ stdio: 'inherit',
105
89
  shell: true,
106
90
  cwd: rwjsPaths.base
107
91
  });
108
92
  }
109
93
  };
110
- }
111
- // Annotate the CommonJS export names for ESM import in node:
112
- 0 && (module.exports = {
113
- addModels,
114
- functionsPath,
115
- generateAuthPagesTask,
116
- getModelNames,
117
- hasAuthPages,
118
- hasModel,
119
- libPath
120
- });
94
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"webAuthn.setupData.d.ts","sourceRoot":"","sources":["../src/webAuthn.setupData.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAA;AAKlF,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAGvC,eAAO,MAAM,WAAW,UAAkC,CAAA;AAG1D,eAAO,MAAM,WAAW,UAAiC,CAAA;AAEzD,eAAO,MAAM,mBAAmB;;gBAEZ,gBAAgB;CA+BnC,CAAA;AAGD,eAAO,MAAM,KAAK,UAoEjB,CAAA;AAED,eAAO,MAAM,YAAY,UAMxB,CAAA"}
1
+ {"version":3,"file":"webAuthn.setupData.d.ts","sourceRoot":"","sources":["../src/webAuthn.setupData.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAA;AAKlF,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAGvC,eAAO,MAAM,WAAW,UAAiC,CAAA;AAGzD,eAAO,MAAM,WAAW,UAAgC,CAAA;AAExD,eAAO,MAAM,mBAAmB;;gBAEZ,gBAAgB;CA+BnC,CAAA;AAGD,eAAO,MAAM,KAAK,UAoEjB,CAAA;AAED,eAAO,MAAM,YAAY,UAMxB,CAAA"}
@@ -1,55 +1,37 @@
1
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 });
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js/object/define-property");
4
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
5
+ _Object$defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createUserModelTask = exports.apiPackages = void 0;
9
+ _Object$defineProperty(exports, "extraTask", {
10
+ enumerable: true,
11
+ get: function () {
12
+ return _setupData.extraTask;
17
13
  }
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 webAuthn_setupData_exports = {};
30
- __export(webAuthn_setupData_exports, {
31
- apiPackages: () => apiPackages,
32
- createUserModelTask: () => createUserModelTask,
33
- extraTask: () => import_setupData.extraTask,
34
- noteGenerate: () => noteGenerate,
35
- notes: () => notes,
36
- webPackages: () => webPackages
37
14
  });
38
- module.exports = __toCommonJS(webAuthn_setupData_exports);
39
- var import_node_path = __toESM(require("node:path"));
40
- var import_cli_helpers = require("@cedarjs/cli-helpers");
41
- var import_shared = require("./shared");
42
- var import_setupData = require("./setupData");
43
- const webPackages = ["@simplewebauthn/browser@^10"];
44
- const apiPackages = ["@simplewebauthn/server@^10"];
45
- const createUserModelTask = {
46
- title: "Creating model `User`...",
47
- task: async (ctx) => {
48
- const hasUserModel = await (0, import_shared.hasModel)("User");
15
+ exports.webPackages = exports.notes = exports.noteGenerate = void 0;
16
+ var _path = _interopRequireDefault(require("path"));
17
+ var _cliHelpers = require("@cedarjs/cli-helpers");
18
+ var _shared = require("./shared");
19
+ var _setupData = require("./setupData");
20
+ // copy some identical values from dbAuth provider
21
+
22
+ // required packages to install on the web side
23
+ const webPackages = exports.webPackages = ['@simplewebauthn/browser@^9'];
24
+
25
+ // required packages to install on the api side
26
+ const apiPackages = exports.apiPackages = ['@simplewebauthn/server@^9'];
27
+ const createUserModelTask = exports.createUserModelTask = {
28
+ title: 'Creating model `User`...',
29
+ task: async ctx => {
30
+ const hasUserModel = await (0, _shared.hasModel)('User');
49
31
  if (hasUserModel && !ctx.force) {
50
- throw new Error("User model already exists");
32
+ throw new Error('User model already exists');
51
33
  }
52
- (0, import_shared.addModels)(`
34
+ (0, _shared.addModels)(`
53
35
  model User {
54
36
  id String @id @default(uuid())
55
37
  email String @unique
@@ -74,89 +56,7 @@ model UserCredential {
74
56
  `);
75
57
  }
76
58
  };
77
- const notes = [
78
- `${import_cli_helpers.colors.warning("Done! But you have a little more work to do:")}
79
- `,
80
- "You will need to add a couple of fields to your User table in order",
81
- "to store a hashed password, salt, reset token, and to connect it to",
82
- "a new UserCredential model to keep track of any devices used with",
83
- "WebAuthn authentication:",
84
- "",
85
- " model User {",
86
- " id String @id @default(uuid())",
87
- " email String @unique",
88
- " hashedPassword String",
89
- " salt String",
90
- " resetToken String?",
91
- " resetTokenExpiresAt DateTime?",
92
- " webAuthnChallenge String? @unique",
93
- " credentials UserCredential[]",
94
- " }",
95
- "",
96
- " model UserCredential {",
97
- " id String @id",
98
- " userId String",
99
- " user User @relation(fields: [userId], references: [id])",
100
- " publicKey Bytes",
101
- " transports String?",
102
- " counter BigInt",
103
- " }",
104
- "",
105
- "If you already have existing user records you will need to provide",
106
- "a default value for `hashedPassword` and `salt` or Prisma complains, so",
107
- "change those to: ",
108
- "",
109
- ' hashedPassword String @default("")',
110
- ' salt String @default("")',
111
- "",
112
- "If you expose any of your user data via GraphQL be sure to exclude",
113
- "`hashedPassword` and `salt` (or whatever you named them) from the",
114
- "SDL file that defines the fields for your user.",
115
- "",
116
- "You'll need to let Cedar know what fields you're using for your users'",
117
- "`id` and `username` fields. In this case we're using `id` and `email`,",
118
- "so update those in the `authFields` config in",
119
- `\`${import_shared.functionsPath}/auth.js\`. This is also the place to tell Cedar if`,
120
- "you used a different name for the `hashedPassword`, `salt`,",
121
- "`resetToken` or `resetTokenExpiresAt`, fields:`",
122
- "",
123
- " authFields: {",
124
- " id: 'id',",
125
- " username: 'email',",
126
- " hashedPassword: 'hashedPassword',",
127
- " salt: 'salt',",
128
- " resetToken: 'resetToken',",
129
- " resetTokenExpiresAt: 'resetTokenExpiresAt',",
130
- " challenge: 'webAuthnChallenge'",
131
- " },",
132
- "",
133
- "To get the actual user that's logged in, take a look at `getCurrentUser()`",
134
- `in \`${import_shared.libPath}/auth.js\`. We default it to something simple, but you may`,
135
- "use different names for your model or unique ID fields, in which case you",
136
- "need to update those calls (instructions are in the comment above the code).",
137
- "",
138
- "Finally, we created a SESSION_SECRET environment variable for you in",
139
- `${import_node_path.default.join((0, import_cli_helpers.getPaths)().base, ".env")}. This value should NOT be checked`,
140
- "into version control and should be unique for each environment you",
141
- "deploy to. If you ever need to log everyone out of your app at once",
142
- "change this secret to a new value and deploy. To create a new secret, run:",
143
- "",
144
- " yarn cedar generate secret",
145
- ""
146
- ];
147
- const noteGenerate = [
148
- "",
149
- "Need simple Login, Signup, Forgot Password pages and WebAuthn prompts?",
150
- "We've got a generator for those as well:",
151
- "",
152
- " yarn cedar generate dbAuth"
153
- ];
154
- // Annotate the CommonJS export names for ESM import in node:
155
- 0 && (module.exports = {
156
- apiPackages,
157
- createUserModelTask,
158
- extraTask,
159
- noteGenerate,
160
- notes,
161
- webPackages
162
- });
59
+
60
+ // any notes to print out when the job is done
61
+ const notes = exports.notes = [`${_cliHelpers.colors.warning('Done! But you have a little more work to do:')}\n`, 'You will need to add a couple of fields to your User table in order', 'to store a hashed password, salt, reset token, and to connect it to', 'a new UserCredential model to keep track of any devices used with', 'WebAuthn authentication:', '', ' model User {', ' id String @id @default(uuid())', ' email String @unique', ' hashedPassword String', ' salt String', ' resetToken String?', ' resetTokenExpiresAt DateTime?', ' webAuthnChallenge String? @unique', ' credentials UserCredential[]', ' }', '', ' model UserCredential {', ' id String @id', ' userId String', ' user User @relation(fields: [userId], references: [id])', ' publicKey Bytes', ' transports String?', ' counter BigInt', ' }', '', 'If you already have existing user records you will need to provide', 'a default value for `hashedPassword` and `salt` or Prisma complains, so', 'change those to: ', '', ' hashedPassword String @default("")', ' salt String @default("")', '', 'If you expose any of your user data via GraphQL be sure to exclude', '`hashedPassword` and `salt` (or whatever you named them) from the', 'SDL file that defines the fields for your user.', '', "You'll need to let Cedar know what fields you're using for your users'", "`id` and `username` fields. In this case we're using `id` and `email`,", 'so update those in the `authFields` config in', `\`${_shared.functionsPath}/auth.js\`. This is also the place to tell Cedar if`, 'you used a different name for the `hashedPassword`, `salt`,', '`resetToken` or `resetTokenExpiresAt`, fields:`', '', ' authFields: {', " id: 'id',", " username: 'email',", " hashedPassword: 'hashedPassword',", " salt: 'salt',", " resetToken: 'resetToken',", " resetTokenExpiresAt: 'resetTokenExpiresAt',", " challenge: 'webAuthnChallenge'", ' },', '', "To get the actual user that's logged in, take a look at `getCurrentUser()`", `in \`${_shared.libPath}/auth.js\`. We default it to something simple, but you may`, 'use different names for your model or unique ID fields, in which case you', 'need to update those calls (instructions are in the comment above the code).', '', 'Finally, we created a SESSION_SECRET environment variable for you in', `${_path.default.join((0, _cliHelpers.getPaths)().base, '.env')}. This value should NOT be checked`, 'into version control and should be unique for each environment you', 'deploy to. If you ever need to log everyone out of your app at once', 'change this secret to a new value and deploy. To create a new secret, run:', '', ' yarn cedar generate secret', ''];
62
+ const noteGenerate = exports.noteGenerate = ['', 'Need simple Login, Signup, Forgot Password pages and WebAuthn prompts?', "We've got a generator for those as well:", '', ' yarn cedar generate dbAuth'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/auth-dbauth-setup",
3
- "version": "2.8.1-next.116+784d2c048",
3
+ "version": "2.8.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cedarjs/cedar.git",
@@ -13,7 +13,9 @@
13
13
  "dist"
14
14
  ],
15
15
  "scripts": {
16
- "build": "node ./build.mts && yarn build:types",
16
+ "// build:js": "Including .snap in extensions because of https://github.com/babel/babel/issues/11394",
17
+ "build": "yarn build:js && yarn build:types",
18
+ "build:js": "babel src -d dist --extensions \".js,.ts,.snap\" --copy-files --no-copy-ignored",
17
19
  "build:pack": "yarn pack -o cedarjs-auth-dbauth-setup.tgz",
18
20
  "build:types": "tsc --build --verbose",
19
21
  "build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx,template\" --ignore dist --exec \"yarn build\"",
@@ -22,17 +24,19 @@
22
24
  "test:watch": "yarn test --watch"
23
25
  },
24
26
  "dependencies": {
25
- "@cedarjs/cli-helpers": "2.8.1-next.116+784d2c048",
26
- "@prisma/internals": "7.5.0",
27
- "@simplewebauthn/browser": "10.0.0",
27
+ "@babel/runtime-corejs3": "7.29.0",
28
+ "@cedarjs/cli-helpers": "2.8.1",
29
+ "@prisma/internals": "6.19.2",
30
+ "@simplewebauthn/browser": "9.0.1",
31
+ "core-js": "3.48.0",
28
32
  "prompts": "2.4.2",
29
33
  "termi-link": "1.1.0"
30
34
  },
31
35
  "devDependencies": {
32
- "@cedarjs/framework-tools": "2.8.1-next.116",
33
- "@simplewebauthn/types": "10.0.0",
36
+ "@babel/cli": "7.28.6",
37
+ "@babel/core": "^7.26.10",
38
+ "@simplewebauthn/types": "9.0.1",
34
39
  "@types/yargs": "17.0.35",
35
- "nodemon": "3.1.14",
36
40
  "ts-dedent": "2.2.0",
37
41
  "typescript": "5.9.3",
38
42
  "vitest": "3.2.4"
@@ -40,5 +44,5 @@
40
44
  "publishConfig": {
41
45
  "access": "public"
42
46
  },
43
- "gitHead": "784d2c0484936b2d853e5b316d167602bd80d996"
47
+ "gitHead": "b1a808f72ff10c72375d0ff2c0be03631a1b79a2"
44
48
  }