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