@cedarjs/auth-dbauth-setup 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.
- package/dist/index.js +22 -1
- package/dist/setup.js +41 -4
- package/dist/setupData.js +55 -17
- package/dist/setupHandler.d.ts.map +1 -1
- package/dist/setupHandler.js +68 -54
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +61 -26
- package/dist/webAuthn.setupData.js +51 -12
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -1 +1,22 @@
|
|
|
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 index_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(index_exports);
|
|
18
|
+
__reExport(index_exports, require("./setup.js"), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require("./setup.js")
|
|
22
|
+
});
|
package/dist/setup.js
CHANGED
|
@@ -1,4 +1,40 @@
|
|
|
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
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(setup_exports);
|
|
37
|
+
var import_termi_link = require("termi-link");
|
|
2
38
|
const command = "dbAuth";
|
|
3
39
|
const description = "Set up auth for for dbAuth";
|
|
4
40
|
function builder(yargs) {
|
|
@@ -23,7 +59,7 @@ function builder(yargs) {
|
|
|
23
59
|
description: "Generate auth pages (login, signup, etc.)",
|
|
24
60
|
type: "boolean"
|
|
25
61
|
}).epilogue(
|
|
26
|
-
`Also see the ${terminalLink(
|
|
62
|
+
`Also see the ${(0, import_termi_link.terminalLink)(
|
|
27
63
|
"CedarJS CLI Reference",
|
|
28
64
|
"https://cedarjs.com/docs/cli-commands#setup-auth"
|
|
29
65
|
)}`
|
|
@@ -33,9 +69,10 @@ const handler = async (options) => {
|
|
|
33
69
|
const { handler: handler2 } = await import("./setupHandler.js");
|
|
34
70
|
return handler2(options);
|
|
35
71
|
};
|
|
36
|
-
export
|
|
72
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
+
0 && (module.exports = {
|
|
37
74
|
builder,
|
|
38
75
|
command,
|
|
39
76
|
description,
|
|
40
77
|
handler
|
|
41
|
-
};
|
|
78
|
+
});
|
package/dist/setupData.js
CHANGED
|
@@ -1,9 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
|
36
|
+
});
|
|
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.js");
|
|
42
|
+
const secret = import_node_crypto.default.randomBytes(32).toString("base64");
|
|
43
|
+
const extraTask = (0, import_cli_helpers.addEnvVarTask)(
|
|
7
44
|
"SESSION_SECRET",
|
|
8
45
|
secret,
|
|
9
46
|
"Used to encrypt/decrypt session cookies. Change this value and re-deploy to log out all users of your app at once."
|
|
@@ -11,11 +48,11 @@ const extraTask = addEnvVarTask(
|
|
|
11
48
|
const createUserModelTask = {
|
|
12
49
|
title: "Creating model `User`...",
|
|
13
50
|
task: async (ctx) => {
|
|
14
|
-
const hasUserModel = await hasModel("User");
|
|
51
|
+
const hasUserModel = await (0, import_shared.hasModel)("User");
|
|
15
52
|
if (hasUserModel && !ctx.force) {
|
|
16
53
|
throw new Error("User model already exists");
|
|
17
54
|
}
|
|
18
|
-
addModels(`
|
|
55
|
+
(0, import_shared.addModels)(`
|
|
19
56
|
model User {
|
|
20
57
|
id String @id @default(uuid())
|
|
21
58
|
email String @unique
|
|
@@ -30,7 +67,7 @@ model User {
|
|
|
30
67
|
}
|
|
31
68
|
};
|
|
32
69
|
const notes = [
|
|
33
|
-
`${colors.warning("Done! But you have a little more work to do:")}
|
|
70
|
+
`${import_cli_helpers.colors.warning("Done! But you have a little more work to do:")}
|
|
34
71
|
`,
|
|
35
72
|
"You will need to add a couple of fields to your User table in order",
|
|
36
73
|
"to store a hashed password and salt:",
|
|
@@ -58,7 +95,7 @@ const notes = [
|
|
|
58
95
|
"You'll need to let Cedar know what fields you're using for your users'",
|
|
59
96
|
"`id` and `username` fields. In this case we're using `id` and `email`,",
|
|
60
97
|
"so update those in the `authFields` config in",
|
|
61
|
-
`\`${functionsPath}/auth.js\`. This is also the place to tell Cedar if`,
|
|
98
|
+
`\`${import_shared.functionsPath}/auth.js\`. This is also the place to tell Cedar if`,
|
|
62
99
|
"you used a different name for the `hashedPassword`, `salt`,",
|
|
63
100
|
"`resetToken` or `resetTokenExpiresAt`, fields:`",
|
|
64
101
|
"",
|
|
@@ -72,12 +109,12 @@ const notes = [
|
|
|
72
109
|
" },",
|
|
73
110
|
"",
|
|
74
111
|
"To get the actual user that's logged in, take a look at `getCurrentUser()`",
|
|
75
|
-
`in \`${libPath}/auth.js\`. We default it to something simple, but you may`,
|
|
112
|
+
`in \`${import_shared.libPath}/auth.js\`. We default it to something simple, but you may`,
|
|
76
113
|
"use different names for your model or unique ID fields, in which case you",
|
|
77
114
|
"need to update those calls (instructions are in the comment above the code).",
|
|
78
115
|
"",
|
|
79
116
|
"Finally, we created a SESSION_SECRET environment variable for you in",
|
|
80
|
-
`${
|
|
117
|
+
`${import_node_path.default.join((0, import_cli_helpers.getPaths)().base, ".env")}. This value should NOT be checked`,
|
|
81
118
|
"into version control and should be unique for each environment you",
|
|
82
119
|
"deploy to. If you ever need to log everyone out of your app at once",
|
|
83
120
|
"change this secret to a new value and deploy. To create a new secret, run:",
|
|
@@ -86,19 +123,19 @@ const notes = [
|
|
|
86
123
|
""
|
|
87
124
|
];
|
|
88
125
|
const notesCreatedUserModel = [
|
|
89
|
-
`${colors.warning("Done! But you have a little more work to do:")}
|
|
126
|
+
`${import_cli_helpers.colors.warning("Done! But you have a little more work to do:")}
|
|
90
127
|
`,
|
|
91
128
|
"If you expose any of your user data via GraphQL be sure to exclude",
|
|
92
129
|
"`hashedPassword` and `salt` (or whatever you named them) from the",
|
|
93
130
|
"SDL file that defines the fields for your user.",
|
|
94
131
|
"",
|
|
95
132
|
"To get the actual user that's logged in, take a look at `getCurrentUser()`",
|
|
96
|
-
`in \`${libPath}/auth.js\`. We default it to something simple, but you may`,
|
|
133
|
+
`in \`${import_shared.libPath}/auth.js\`. We default it to something simple, but you may`,
|
|
97
134
|
"use different names for your model or unique ID fields, in which case you",
|
|
98
135
|
"need to update those calls (instructions are in the comment above the code).",
|
|
99
136
|
"",
|
|
100
137
|
"Finally, we created a SESSION_SECRET environment variable for you in",
|
|
101
|
-
`${
|
|
138
|
+
`${import_node_path.default.join((0, import_cli_helpers.getPaths)().base, ".env")}. This value should NOT be checked`,
|
|
102
139
|
"into version control and should be unique for each environment you",
|
|
103
140
|
"deploy to. If you ever need to log everyone out of your app at once",
|
|
104
141
|
"change this secret to a new value and deploy. To create a new secret, run:",
|
|
@@ -118,10 +155,11 @@ const noteGenerate = [
|
|
|
118
155
|
"",
|
|
119
156
|
" yarn cedar generate dbAuth"
|
|
120
157
|
];
|
|
121
|
-
export
|
|
158
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
159
|
+
0 && (module.exports = {
|
|
122
160
|
createUserModelTask,
|
|
123
161
|
extraTask,
|
|
124
162
|
noteGenerate,
|
|
125
163
|
notes,
|
|
126
164
|
notesCreatedUserModel
|
|
127
|
-
};
|
|
165
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupHandler.d.ts","sourceRoot":"","sources":["../src/setupHandler.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAuBtC,wBAAsB,OAAO,CAAC,EAC5B,QAAQ,EACR,eAAe,EACf,iBAAiB,EACjB,KAAK,EAAE,QAAQ,GAChB,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"setupHandler.d.ts","sourceRoot":"","sources":["../src/setupHandler.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAuBtC,wBAAsB,OAAO,CAAC,EAC5B,QAAQ,EACR,eAAe,EACf,iBAAiB,EACjB,KAAK,EAAE,QAAQ,GAChB,EAAE,IAAI,iBAoEN;AAsED,eAAO,MAAM,yBAAyB;;;CAuCrC,CAAA"}
|
package/dist/setupHandler.js
CHANGED
|
@@ -1,28 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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 setupHandler_exports = {};
|
|
30
|
+
__export(setupHandler_exports, {
|
|
31
|
+
createAuthDecoderFunction: () => createAuthDecoderFunction,
|
|
32
|
+
handler: () => handler
|
|
33
|
+
});
|
|
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.js");
|
|
40
|
+
var import_shared = require("./shared.js");
|
|
41
|
+
var import_webAuthn_setupData = require("./webAuthn.setupData.js");
|
|
26
42
|
async function handler({
|
|
27
43
|
webauthn,
|
|
28
44
|
createUserModel,
|
|
@@ -30,10 +46,7 @@ async function handler({
|
|
|
30
46
|
force: forceArg
|
|
31
47
|
}) {
|
|
32
48
|
const { version } = JSON.parse(
|
|
33
|
-
|
|
34
|
-
path.resolve(import.meta.dirname, "../package.json"),
|
|
35
|
-
"utf-8"
|
|
36
|
-
)
|
|
49
|
+
import_node_fs.default.readFileSync(import_node_path.default.resolve(__dirname, "../package.json"), "utf-8")
|
|
37
50
|
);
|
|
38
51
|
const webAuthn = await shouldIncludeWebAuthn(webauthn);
|
|
39
52
|
const createDbUserModel = await shouldCreateUserModel(createUserModel);
|
|
@@ -41,57 +54,57 @@ async function handler({
|
|
|
41
54
|
const oneMoreThing = [];
|
|
42
55
|
if (webAuthn) {
|
|
43
56
|
if (createDbUserModel) {
|
|
44
|
-
oneMoreThing.push(...notesCreatedUserModel);
|
|
57
|
+
oneMoreThing.push(...import_setupData.notesCreatedUserModel);
|
|
45
58
|
} else {
|
|
46
|
-
oneMoreThing.push(...
|
|
59
|
+
oneMoreThing.push(...import_webAuthn_setupData.notes);
|
|
47
60
|
}
|
|
48
61
|
if (!generateDbAuthPages) {
|
|
49
|
-
oneMoreThing.push(...
|
|
62
|
+
oneMoreThing.push(...import_webAuthn_setupData.noteGenerate);
|
|
50
63
|
}
|
|
51
64
|
} else {
|
|
52
65
|
if (createDbUserModel) {
|
|
53
|
-
oneMoreThing.push(...notesCreatedUserModel);
|
|
66
|
+
oneMoreThing.push(...import_setupData.notesCreatedUserModel);
|
|
54
67
|
} else {
|
|
55
|
-
oneMoreThing.push(...notes);
|
|
68
|
+
oneMoreThing.push(...import_setupData.notes);
|
|
56
69
|
}
|
|
57
70
|
if (!generateDbAuthPages) {
|
|
58
|
-
oneMoreThing.push(...noteGenerate);
|
|
71
|
+
oneMoreThing.push(...import_setupData.noteGenerate);
|
|
59
72
|
}
|
|
60
73
|
}
|
|
61
74
|
let createDbUserModelTask = void 0;
|
|
62
75
|
if (createDbUserModel) {
|
|
63
76
|
if (webAuthn) {
|
|
64
|
-
createDbUserModelTask =
|
|
77
|
+
createDbUserModelTask = import_webAuthn_setupData.createUserModelTask;
|
|
65
78
|
} else {
|
|
66
|
-
createDbUserModelTask = createUserModelTask;
|
|
79
|
+
createDbUserModelTask = import_setupData.createUserModelTask;
|
|
67
80
|
}
|
|
68
81
|
}
|
|
69
|
-
await standardAuthHandler({
|
|
70
|
-
basedir:
|
|
82
|
+
await (0, import_cli_helpers.standardAuthHandler)({
|
|
83
|
+
basedir: __dirname,
|
|
71
84
|
forceArg,
|
|
72
85
|
provider: "dbAuth",
|
|
73
86
|
authDecoderImport: "import { createAuthDecoder } from '@cedarjs/auth-dbauth-api'",
|
|
74
87
|
webAuthn,
|
|
75
88
|
webPackages: [
|
|
76
89
|
`@cedarjs/auth-dbauth-web@${version}`,
|
|
77
|
-
...webAuthn ?
|
|
90
|
+
...webAuthn ? import_webAuthn_setupData.webPackages : []
|
|
78
91
|
],
|
|
79
92
|
apiPackages: [
|
|
80
93
|
`@cedarjs/auth-dbauth-api@${version}`,
|
|
81
|
-
...webAuthn ?
|
|
94
|
+
...webAuthn ? import_webAuthn_setupData.apiPackages : []
|
|
82
95
|
],
|
|
83
96
|
extraTasks: [
|
|
84
|
-
webAuthn ?
|
|
97
|
+
webAuthn ? import_webAuthn_setupData.extraTask : import_setupData.extraTask,
|
|
85
98
|
createDbUserModelTask,
|
|
86
99
|
createAuthDecoderFunction,
|
|
87
|
-
generateDbAuthPages ? generateAuthPagesTask(createDbUserModel) : void 0
|
|
100
|
+
generateDbAuthPages ? (0, import_shared.generateAuthPagesTask)(createDbUserModel) : void 0
|
|
88
101
|
],
|
|
89
102
|
notes: oneMoreThing
|
|
90
103
|
});
|
|
91
104
|
}
|
|
92
105
|
async function shouldIncludeWebAuthn(webauthn) {
|
|
93
106
|
if (webauthn === null) {
|
|
94
|
-
const webAuthnResponse = await
|
|
107
|
+
const webAuthnResponse = await (0, import_prompts.default)({
|
|
95
108
|
type: "confirm",
|
|
96
109
|
name: "answer",
|
|
97
110
|
message: `Enable WebAuthn support (TouchID/FaceID)? See https://cedarjs.com/docs/auth/dbAuth#webAuthn`,
|
|
@@ -102,14 +115,14 @@ async function shouldIncludeWebAuthn(webauthn) {
|
|
|
102
115
|
return webauthn;
|
|
103
116
|
}
|
|
104
117
|
async function shouldCreateUserModel(createUserModel) {
|
|
105
|
-
const hasUserModel = await hasModel("User");
|
|
106
|
-
const modelNames = await getModelNames();
|
|
118
|
+
const hasUserModel = await (0, import_shared.hasModel)("User");
|
|
119
|
+
const modelNames = await (0, import_shared.getModelNames)();
|
|
107
120
|
const isNewProject = modelNames.length === 1 && modelNames[0] === "UserExample";
|
|
108
121
|
if (isNewProject) {
|
|
109
122
|
return true;
|
|
110
123
|
}
|
|
111
124
|
if (createUserModel === null && !hasUserModel) {
|
|
112
|
-
const createModelResponse = await
|
|
125
|
+
const createModelResponse = await (0, import_prompts.default)({
|
|
113
126
|
type: "confirm",
|
|
114
127
|
name: "answer",
|
|
115
128
|
message: "Create User model?",
|
|
@@ -120,8 +133,8 @@ async function shouldCreateUserModel(createUserModel) {
|
|
|
120
133
|
return createUserModel;
|
|
121
134
|
}
|
|
122
135
|
async function shouldGenerateDbAuthPages(generateAuthPages) {
|
|
123
|
-
if (generateAuthPages === null && !hasAuthPages()) {
|
|
124
|
-
const generateAuthPagesResponse = await
|
|
136
|
+
if (generateAuthPages === null && !(0, import_shared.hasAuthPages)()) {
|
|
137
|
+
const generateAuthPagesResponse = await (0, import_prompts.default)({
|
|
125
138
|
type: "confirm",
|
|
126
139
|
name: "answer",
|
|
127
140
|
message: "Generate auth pages (login, signup, forgotten password, etc)?",
|
|
@@ -134,12 +147,12 @@ async function shouldGenerateDbAuthPages(generateAuthPages) {
|
|
|
134
147
|
const createAuthDecoderFunction = {
|
|
135
148
|
title: "Create auth decoder function",
|
|
136
149
|
task: () => {
|
|
137
|
-
const graphqlPath = getGraphqlPath();
|
|
150
|
+
const graphqlPath = (0, import_cli_helpers.getGraphqlPath)();
|
|
138
151
|
if (!graphqlPath) {
|
|
139
152
|
throw new Error("Could not find your graphql file path");
|
|
140
153
|
}
|
|
141
154
|
const authDecoderCreation = "const authDecoder = createAuthDecoder(cookieName)";
|
|
142
|
-
const content =
|
|
155
|
+
const content = import_node_fs.default.readFileSync(graphqlPath, "utf-8");
|
|
143
156
|
let newContent = content.replace(
|
|
144
157
|
"import { getCurrentUser } from",
|
|
145
158
|
"import { cookieName, getCurrentUser } from"
|
|
@@ -157,13 +170,14 @@ const createAuthDecoderFunction = {
|
|
|
157
170
|
if (!newContent.includes("import { cookieName")) {
|
|
158
171
|
throw new Error("Failed to import cookieName");
|
|
159
172
|
}
|
|
160
|
-
|
|
173
|
+
import_node_fs.default.writeFileSync(graphqlPath, newContent);
|
|
161
174
|
}
|
|
162
175
|
};
|
|
163
176
|
function escapeRegExp(str) {
|
|
164
177
|
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
165
178
|
}
|
|
166
|
-
export
|
|
179
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
180
|
+
0 && (module.exports = {
|
|
167
181
|
createAuthDecoderFunction,
|
|
168
182
|
handler
|
|
169
|
-
};
|
|
183
|
+
});
|
package/dist/shared.d.ts.map
CHANGED
|
@@ -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,
|
|
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;;;EAuBjE"}
|
package/dist/shared.js
CHANGED
|
@@ -1,23 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
38
|
+
});
|
|
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_cli_helpers = require("@cedarjs/cli-helpers");
|
|
44
|
+
var import_exec = require("@cedarjs/cli-helpers/packageManager/exec");
|
|
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,
|
|
14
49
|
""
|
|
15
50
|
);
|
|
16
51
|
const getModelNames = async () => {
|
|
17
|
-
const
|
|
18
|
-
const result = await getPrismaSchemas();
|
|
52
|
+
const result = await (0, import_project_config.getPrismaSchemas)();
|
|
19
53
|
const datamodel = result.schemas;
|
|
20
|
-
const schema = await getDMMF({ datamodel });
|
|
54
|
+
const schema = await (0, import_internals.getDMMF)({ datamodel });
|
|
21
55
|
return schema.datamodel.models.map((model) => model.name);
|
|
22
56
|
};
|
|
23
57
|
const hasModel = async (name) => {
|
|
@@ -32,20 +66,20 @@ const hasModel = async (name) => {
|
|
|
32
66
|
return false;
|
|
33
67
|
};
|
|
34
68
|
async function addModels(models) {
|
|
35
|
-
const schemaPath = await getSchemaPath(getPaths().api.prismaConfig);
|
|
36
|
-
const isDirectory =
|
|
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();
|
|
37
71
|
if (isDirectory) {
|
|
38
|
-
|
|
72
|
+
import_node_fs.default.writeFileSync(import_node_path.default.join(schemaPath, "user.prisma"), models);
|
|
39
73
|
} else {
|
|
40
|
-
|
|
74
|
+
import_node_fs.default.appendFileSync(schemaPath, models);
|
|
41
75
|
}
|
|
42
76
|
}
|
|
43
77
|
function hasAuthPages() {
|
|
44
|
-
const routes =
|
|
78
|
+
const routes = import_node_fs.default.readFileSync((0, import_cli_helpers.getPaths)().web.routes, "utf-8");
|
|
45
79
|
if (/path={?['"]\/(login|signin|signup)['"]}? /i.test(routes)) {
|
|
46
80
|
return true;
|
|
47
81
|
}
|
|
48
|
-
return processPagesDir().some((page) => {
|
|
82
|
+
return (0, import_project_config.processPagesDir)().some((page) => {
|
|
49
83
|
if (page.importName === "LoginPage" || page.importName === "LogInPage" || page.importName === "SigninPage" || page.importName === "SignInPage" || page.importName === "SignupPage" || page.importName === "SignUpPage") {
|
|
50
84
|
return true;
|
|
51
85
|
}
|
|
@@ -56,7 +90,7 @@ function generateAuthPagesTask(generatingUserModel) {
|
|
|
56
90
|
return {
|
|
57
91
|
title: "Adding dbAuth pages...",
|
|
58
92
|
task: async () => {
|
|
59
|
-
const rwjsPaths = getPaths();
|
|
93
|
+
const rwjsPaths = (0, import_cli_helpers.getPaths)();
|
|
60
94
|
const args = ["g", "dbAuth"];
|
|
61
95
|
if (generatingUserModel) {
|
|
62
96
|
args.push(
|
|
@@ -66,14 +100,15 @@ function generateAuthPagesTask(generatingUserModel) {
|
|
|
66
100
|
"password"
|
|
67
101
|
);
|
|
68
102
|
}
|
|
69
|
-
await runBin("cedar", args, {
|
|
103
|
+
await (0, import_exec.runBin)("cedar", args, {
|
|
70
104
|
stdio: "inherit",
|
|
71
105
|
cwd: rwjsPaths.base
|
|
72
106
|
});
|
|
73
107
|
}
|
|
74
108
|
};
|
|
75
109
|
}
|
|
76
|
-
export
|
|
110
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
111
|
+
0 && (module.exports = {
|
|
77
112
|
addModels,
|
|
78
113
|
functionsPath,
|
|
79
114
|
generateAuthPagesTask,
|
|
@@ -81,4 +116,4 @@ export {
|
|
|
81
116
|
hasAuthPages,
|
|
82
117
|
hasModel,
|
|
83
118
|
libPath
|
|
84
|
-
};
|
|
119
|
+
});
|
|
@@ -1,17 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 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
|
+
});
|
|
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.js");
|
|
42
|
+
var import_setupData = require("./setupData.js");
|
|
5
43
|
const webPackages = ["@simplewebauthn/browser@^10"];
|
|
6
44
|
const apiPackages = ["@simplewebauthn/server@^10"];
|
|
7
45
|
const createUserModelTask = {
|
|
8
46
|
title: "Creating model `User`...",
|
|
9
47
|
task: async (ctx) => {
|
|
10
|
-
const hasUserModel = await hasModel("User");
|
|
48
|
+
const hasUserModel = await (0, import_shared.hasModel)("User");
|
|
11
49
|
if (hasUserModel && !ctx.force) {
|
|
12
50
|
throw new Error("User model already exists");
|
|
13
51
|
}
|
|
14
|
-
addModels(`
|
|
52
|
+
(0, import_shared.addModels)(`
|
|
15
53
|
model User {
|
|
16
54
|
id String @id @default(uuid())
|
|
17
55
|
email String @unique
|
|
@@ -37,7 +75,7 @@ model UserCredential {
|
|
|
37
75
|
}
|
|
38
76
|
};
|
|
39
77
|
const notes = [
|
|
40
|
-
`${colors.warning("Done! But you have a little more work to do:")}
|
|
78
|
+
`${import_cli_helpers.colors.warning("Done! But you have a little more work to do:")}
|
|
41
79
|
`,
|
|
42
80
|
"You will need to add a couple of fields to your User table in order",
|
|
43
81
|
"to store a hashed password, salt, reset token, and to connect it to",
|
|
@@ -78,7 +116,7 @@ const notes = [
|
|
|
78
116
|
"You'll need to let Cedar know what fields you're using for your users'",
|
|
79
117
|
"`id` and `username` fields. In this case we're using `id` and `email`,",
|
|
80
118
|
"so update those in the `authFields` config in",
|
|
81
|
-
`\`${functionsPath}/auth.js\`. This is also the place to tell Cedar if`,
|
|
119
|
+
`\`${import_shared.functionsPath}/auth.js\`. This is also the place to tell Cedar if`,
|
|
82
120
|
"you used a different name for the `hashedPassword`, `salt`,",
|
|
83
121
|
"`resetToken` or `resetTokenExpiresAt`, fields:`",
|
|
84
122
|
"",
|
|
@@ -93,12 +131,12 @@ const notes = [
|
|
|
93
131
|
" },",
|
|
94
132
|
"",
|
|
95
133
|
"To get the actual user that's logged in, take a look at `getCurrentUser()`",
|
|
96
|
-
`in \`${libPath}/auth.js\`. We default it to something simple, but you may`,
|
|
134
|
+
`in \`${import_shared.libPath}/auth.js\`. We default it to something simple, but you may`,
|
|
97
135
|
"use different names for your model or unique ID fields, in which case you",
|
|
98
136
|
"need to update those calls (instructions are in the comment above the code).",
|
|
99
137
|
"",
|
|
100
138
|
"Finally, we created a SESSION_SECRET environment variable for you in",
|
|
101
|
-
`${
|
|
139
|
+
`${import_node_path.default.join((0, import_cli_helpers.getPaths)().base, ".env")}. This value should NOT be checked`,
|
|
102
140
|
"into version control and should be unique for each environment you",
|
|
103
141
|
"deploy to. If you ever need to log everyone out of your app at once",
|
|
104
142
|
"change this secret to a new value and deploy. To create a new secret, run:",
|
|
@@ -113,11 +151,12 @@ const noteGenerate = [
|
|
|
113
151
|
"",
|
|
114
152
|
" yarn cedar generate dbAuth"
|
|
115
153
|
];
|
|
116
|
-
export
|
|
154
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
155
|
+
0 && (module.exports = {
|
|
117
156
|
apiPackages,
|
|
118
157
|
createUserModelTask,
|
|
119
158
|
extraTask,
|
|
120
159
|
noteGenerate,
|
|
121
160
|
notes,
|
|
122
161
|
webPackages
|
|
123
|
-
};
|
|
162
|
+
});
|
package/package.json
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/auth-dbauth-setup",
|
|
3
|
-
"version": "5.0.4
|
|
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/setup"
|
|
8
8
|
},
|
|
9
9
|
"license": "MIT",
|
|
10
|
-
"type": "
|
|
10
|
+
"type": "commonjs",
|
|
11
11
|
"main": "./dist/index.js",
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
13
13
|
"files": [
|
|
14
14
|
"dist"
|
|
15
15
|
],
|
|
16
16
|
"scripts": {
|
|
17
|
-
"build": "node ./build.mts",
|
|
17
|
+
"build": "node ./build.mts && yarn build:types",
|
|
18
18
|
"build:pack": "yarn pack -o cedarjs-auth-dbauth-setup.tgz",
|
|
19
|
-
"build:types": "tsc --build --verbose
|
|
19
|
+
"build:types": "tsc --build --verbose",
|
|
20
20
|
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx,template\" --ignore dist --exec \"yarn build\"",
|
|
21
21
|
"prepublishOnly": "NODE_ENV=production yarn build",
|
|
22
22
|
"test": "yarn vitest run src",
|
|
23
23
|
"test:watch": "yarn test --watch"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@cedarjs/cli-helpers": "5.0.4
|
|
27
|
-
"@cedarjs/project-config": "5.0.4-next.167",
|
|
26
|
+
"@cedarjs/cli-helpers": "5.0.4",
|
|
28
27
|
"@prisma/internals": "7.8.0",
|
|
28
|
+
"@simplewebauthn/browser": "10.0.0",
|
|
29
29
|
"prompts": "2.4.2",
|
|
30
30
|
"termi-link": "1.1.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@cedarjs/framework-tools": "5.0.4
|
|
33
|
+
"@cedarjs/framework-tools": "5.0.4",
|
|
34
|
+
"@simplewebauthn/types": "10.0.0",
|
|
34
35
|
"@types/yargs": "17.0.35",
|
|
35
|
-
"dedent": "1.7.2",
|
|
36
|
-
"memfs": "4.64.0",
|
|
37
36
|
"nodemon": "3.1.14",
|
|
37
|
+
"ts-dedent": "2.3.0",
|
|
38
38
|
"typescript": "5.9.3",
|
|
39
|
-
"vitest": "
|
|
39
|
+
"vitest": "3.2.6"
|
|
40
40
|
},
|
|
41
41
|
"engines": {
|
|
42
42
|
"node": ">=24"
|