@cedarjs/cli-helpers 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/auth/authTasks.d.ts.map +1 -1
- package/dist/auth/authTasks.js +4 -11
- package/dist/cjs/auth/authFiles.d.ts +44 -0
- package/dist/cjs/auth/authFiles.d.ts.map +1 -0
- package/dist/cjs/auth/authFiles.js +109 -0
- package/dist/cjs/auth/authTasks.d.ts +49 -0
- package/dist/cjs/auth/authTasks.d.ts.map +1 -0
- package/dist/cjs/auth/authTasks.js +384 -0
- package/dist/cjs/auth/setupHelpers.d.ts +27 -0
- package/dist/cjs/auth/setupHelpers.d.ts.map +1 -0
- package/dist/cjs/auth/setupHelpers.js +141 -0
- package/dist/cjs/index.d.ts +12 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +52 -0
- package/dist/cjs/lib/colors.d.ts +24 -0
- package/dist/cjs/lib/colors.d.ts.map +1 -0
- package/dist/cjs/lib/colors.js +52 -0
- package/dist/cjs/lib/index.d.ts +22 -0
- package/dist/cjs/lib/index.d.ts.map +1 -0
- package/dist/cjs/lib/index.js +147 -0
- package/dist/cjs/lib/installHelpers.d.ts +17 -0
- package/dist/cjs/lib/installHelpers.d.ts.map +1 -0
- package/dist/cjs/lib/installHelpers.js +65 -0
- package/dist/cjs/lib/loadEnvFiles.d.ts +5 -0
- package/dist/cjs/lib/loadEnvFiles.d.ts.map +1 -0
- package/dist/cjs/lib/loadEnvFiles.js +99 -0
- package/dist/cjs/lib/paths.d.ts +6 -0
- package/dist/cjs/lib/paths.d.ts.map +1 -0
- package/dist/cjs/lib/paths.js +42 -0
- package/dist/cjs/lib/project.d.ts +44 -0
- package/dist/cjs/lib/project.d.ts.map +1 -0
- package/dist/cjs/lib/project.js +268 -0
- package/dist/cjs/lib/version.d.ts +17 -0
- package/dist/cjs/lib/version.d.ts.map +1 -0
- package/dist/cjs/lib/version.js +107 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/packageManager/display.d.ts +90 -0
- package/dist/cjs/packageManager/display.d.ts.map +1 -0
- package/dist/cjs/packageManager/display.js +139 -0
- package/dist/cjs/packageManager/exec.d.ts +77 -0
- package/dist/cjs/packageManager/exec.d.ts.map +1 -0
- package/dist/cjs/packageManager/exec.js +152 -0
- package/dist/cjs/packageManager/index.d.ts +13 -0
- package/dist/cjs/packageManager/index.d.ts.map +1 -0
- package/dist/cjs/packageManager/index.js +73 -0
- package/dist/cjs/packageManager/packages.d.ts +39 -0
- package/dist/cjs/packageManager/packages.d.ts.map +1 -0
- package/dist/cjs/packageManager/packages.js +91 -0
- package/dist/cjs/packageManager/workspaces.d.ts +4 -0
- package/dist/cjs/packageManager/workspaces.d.ts.map +1 -0
- package/dist/cjs/packageManager/workspaces.js +93 -0
- package/dist/cjs/telemetry/index.d.ts +20 -0
- package/dist/cjs/telemetry/index.d.ts.map +1 -0
- package/dist/cjs/telemetry/index.js +64 -0
- package/dist/lib/project.d.ts.map +1 -1
- package/dist/lib/project.js +1 -2
- package/dist/package.json +1 -0
- package/package.json +50 -18
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authTasks.d.ts","sourceRoot":"","sources":["../../src/auth/authTasks.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"authTasks.d.ts","sourceRoot":"","sources":["../../src/auth/authTasks.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAA;AAmBxE,eAAO,MAAM,aAAa,cAA2B,CAAA;AAwDrD,eAAO,MAAM,YAAY,GAAI,+CAG1B;IACD,qBAAqB,EAAE,OAAO,CAAA;IAC9B,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC3B,SAgDA,CAAA;AAmCD,eAAO,MAAM,eAAe,GAAI,SAAS,MAAM,YAE9C,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,WA6CjD,CAAA;AAoED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,SAAS,OAAO,aAAa,OAClC,SAAS,CAAC,gBAAgB,EAAE,QAAQ,CA0CxC,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,EAAE,UAAU,OAAO;;gBAgC1C,gBAAgB;CA0CrC,CAAA;AAED,eAAO,MAAM,iBAAiB;;;CAmB7B,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAAI,QAAQ,SAAS,OAAO,aAAa,EACxE,SAAS,MAAM,EACf,UAAU,OAAO,KAChB,SAAS,CAAC,gBAAgB,EAAE,QAAQ,CAgDtC,CAAA;AASD,eAAO,MAAM,qBAAqB,GAChC,QAAQ,SAAS,OAAO,aAAa,EACrC,gBAAgB,SAAS,OAAO,aAAa,EAE7C,oBAAoB,MAAM;;gBAInB,gBAAgB,SACd,gBAAgB,CAAC,gBAAgB,EAAE,QAAQ,EAAE,gBAAgB,CAAC;CAcvE,CAAA;AAEF,MAAM,MAAM,aAAa,GACrB,OAAO,GACP,SAAS,GACT,SAAS,GACT,SAAS,CAAA;AAEb,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,aAAa,CAAA;IACxB,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,OAAO,CAAA;CACf;AAED,eAAO,MAAM,gBAAgB,GAC3B,QAAQ,SAAS,OAAO,aAAa,EACrC,gBAAgB,SAAS,OAAO,aAAa,EAE7C,OAAO,OAAO;;gBAKL,gBAAgB,QACf,gBAAgB,CAAC,gBAAgB,EAAE,QAAQ,EAAE,gBAAgB,CAAC;CA2CzE,CAAA"}
|
package/dist/auth/authTasks.js
CHANGED
|
@@ -13,10 +13,6 @@ import {
|
|
|
13
13
|
import { apiSideFiles, generateUniqueFileNames } from "./authFiles.js";
|
|
14
14
|
const AUTH_PROVIDER_HOOK_IMPORT = `import { AuthProvider, useAuth } from './auth.js'`;
|
|
15
15
|
const AUTH_HOOK_IMPORT = `import { useAuth } from './auth.js'`;
|
|
16
|
-
const APOLLO_PROVIDER_COMPONENT_NAMES = [
|
|
17
|
-
"CedarApolloProvider",
|
|
18
|
-
"RedwoodApolloProvider"
|
|
19
|
-
];
|
|
20
16
|
const getWebAppPath = () => getPaths().web.app;
|
|
21
17
|
function addAuthDecoderToCreateGraphQLHandler(content) {
|
|
22
18
|
if (!new RegExp("(?=(^.*?createGraphQLHandler))\\1.*\\bauthDecoder", "s").test(
|
|
@@ -188,16 +184,13 @@ const addConfigToWebApp = () => {
|
|
|
188
184
|
);
|
|
189
185
|
}
|
|
190
186
|
content = addAuthProviderToApp(content, ctx.setupMode);
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
if (apolloProviderComponentName) {
|
|
195
|
-
if (!hasUseAuthHook(apolloProviderComponentName, content)) {
|
|
196
|
-
content = addUseAuthHook(apolloProviderComponentName, content);
|
|
187
|
+
if (/\s*<RedwoodApolloProvider/.test(content)) {
|
|
188
|
+
if (!hasUseAuthHook("RedwoodApolloProvider", content)) {
|
|
189
|
+
content = addUseAuthHook("RedwoodApolloProvider", content);
|
|
197
190
|
}
|
|
198
191
|
} else {
|
|
199
192
|
task.output = colors.warning(
|
|
200
|
-
"Could not find <
|
|
193
|
+
"Could not find <RedwoodApolloProvider>.\nIf you are using a custom GraphQL Client you will have to make sure it gets access to your `useAuth`, if it needs it."
|
|
201
194
|
);
|
|
202
195
|
}
|
|
203
196
|
fs.writeFileSync(webAppPath, content);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
interface FilesArgs {
|
|
2
|
+
basedir: string;
|
|
3
|
+
webAuthn: boolean;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Get the api side file paths and file contents to write
|
|
7
|
+
*
|
|
8
|
+
* Example return value:
|
|
9
|
+
* ```json
|
|
10
|
+
* {
|
|
11
|
+
* "/Users/tobbe/dev/rw-app/api/src/lib/auth.ts": "<file content>",
|
|
12
|
+
* "/Users/tobbe/dev/rw-app/api/src/lib/helperFunctions.ts": "<file content>",
|
|
13
|
+
* "/Users/tobbe/dev/rw-app/api/src/functions/auth.ts": "<file content>"
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare const apiSideFiles: ({ basedir, webAuthn }: FilesArgs) => Promise<Record<string, string>>;
|
|
18
|
+
/**
|
|
19
|
+
* Loops through the keys in `filesRecord` and generates unique file paths if
|
|
20
|
+
* they conflict with existing files
|
|
21
|
+
*
|
|
22
|
+
* Given this input:
|
|
23
|
+
* ```json
|
|
24
|
+
* {
|
|
25
|
+
* "/Users/tobbe/dev/rw-app/api/src/lib/auth.ts": "<file content>",
|
|
26
|
+
* "/Users/tobbe/dev/rw-app/api/src/lib/helperFunctions.ts": "<file content>",
|
|
27
|
+
* "/Users/tobbe/dev/rw-app/api/src/lib/supertokens.ts": "<file content>",
|
|
28
|
+
* "/Users/tobbe/dev/rw-app/api/src/functions/auth.ts": "<file content>"
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* You could get this output, depending on what existing files there are
|
|
33
|
+
* ```json
|
|
34
|
+
* {
|
|
35
|
+
* "/Users/tobbe/dev/rw-app/api/src/lib/supertokensAuth3.ts": "<file content>",
|
|
36
|
+
* "/Users/tobbe/dev/rw-app/api/src/lib/supertokensHelperFunctions.ts": "<file content>",
|
|
37
|
+
* "/Users/tobbe/dev/rw-app/api/src/lib/supertokens2.ts": "<file content>",
|
|
38
|
+
* "/Users/tobbe/dev/rw-app/api/src/functions/auth.ts": "<file content>"
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function generateUniqueFileNames(filesRecord: Record<string, string>, provider: string): Record<string, string>;
|
|
43
|
+
export {};
|
|
44
|
+
//# sourceMappingURL=authFiles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authFiles.d.ts","sourceRoot":"","sources":["../../../src/auth/authFiles.ts"],"names":[],"mappings":"AASA,UAAU,SAAS;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,OAAO,CAAA;CAClB;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY,GAAU,uBAAuB,SAAS,oCAmElE,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACnC,QAAQ,EAAE,MAAM,0BAwCjB"}
|
|
@@ -0,0 +1,109 @@
|
|
|
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 authFiles_exports = {};
|
|
30
|
+
__export(authFiles_exports, {
|
|
31
|
+
apiSideFiles: () => apiSideFiles,
|
|
32
|
+
generateUniqueFileNames: () => generateUniqueFileNames
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(authFiles_exports);
|
|
35
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
36
|
+
var import_path = __toESM(require("path"), 1);
|
|
37
|
+
var import_pascalcase = __toESM(require("pascalcase"), 1);
|
|
38
|
+
var import_lib = require("../lib/index.js");
|
|
39
|
+
var import_paths = require("../lib/paths.js");
|
|
40
|
+
var import_project = require("../lib/project.js");
|
|
41
|
+
const apiSideFiles = async ({ basedir, webAuthn }) => {
|
|
42
|
+
const apiSrcPath = (0, import_paths.getPaths)().api.src;
|
|
43
|
+
const apiBaseTemplatePath = import_path.default.join(basedir, "templates", "api");
|
|
44
|
+
const templateDirectories = import_node_fs.default.readdirSync(apiBaseTemplatePath);
|
|
45
|
+
let filesRecord = {};
|
|
46
|
+
for (const dir of templateDirectories) {
|
|
47
|
+
const templateFiles = import_node_fs.default.readdirSync(import_path.default.join(apiBaseTemplatePath, dir));
|
|
48
|
+
const filePaths = templateFiles.filter((fileName) => {
|
|
49
|
+
const fileNameParts = fileName.split(".");
|
|
50
|
+
return fileNameParts.length <= 3 || fileNameParts.at(-3) !== "webAuthn";
|
|
51
|
+
}).map((fileName) => {
|
|
52
|
+
let outputFileName = fileName.replace(/\.template$/, "");
|
|
53
|
+
if (!(0, import_project.isTypeScriptProject)()) {
|
|
54
|
+
outputFileName = outputFileName.replace(/\.ts(x?)$/, ".js$1");
|
|
55
|
+
}
|
|
56
|
+
if (!webAuthn) {
|
|
57
|
+
return { templateFileName: fileName, outputFileName };
|
|
58
|
+
}
|
|
59
|
+
const webAuthnFileName = fileName.split(".").reverse().map((part, i) => i === 1 ? "webAuthn." + part : part).reverse().join(".");
|
|
60
|
+
if (templateFiles.includes(webAuthnFileName)) {
|
|
61
|
+
return { templateFileName: webAuthnFileName, outputFileName };
|
|
62
|
+
} else {
|
|
63
|
+
return { templateFileName: fileName, outputFileName };
|
|
64
|
+
}
|
|
65
|
+
}).map((f) => {
|
|
66
|
+
const templateFilePath = import_path.default.join(
|
|
67
|
+
apiBaseTemplatePath,
|
|
68
|
+
dir,
|
|
69
|
+
f.templateFileName
|
|
70
|
+
);
|
|
71
|
+
const outputFilePath = import_path.default.join(apiSrcPath, dir, f.outputFileName);
|
|
72
|
+
return { templateFilePath, outputFilePath };
|
|
73
|
+
});
|
|
74
|
+
for (const paths of filePaths) {
|
|
75
|
+
const content = import_node_fs.default.readFileSync(paths.templateFilePath, "utf8");
|
|
76
|
+
filesRecord = {
|
|
77
|
+
...filesRecord,
|
|
78
|
+
[paths.outputFilePath]: (0, import_project.isTypeScriptProject)() ? content : await (0, import_lib.transformTSToJS)(paths.outputFilePath, content)
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return filesRecord;
|
|
83
|
+
};
|
|
84
|
+
function generateUniqueFileNames(filesRecord, provider) {
|
|
85
|
+
const newFilesRecord = {};
|
|
86
|
+
Object.keys(filesRecord).forEach((fullPath) => {
|
|
87
|
+
let newFullPath = fullPath;
|
|
88
|
+
let i = 1;
|
|
89
|
+
while (import_node_fs.default.existsSync(newFullPath)) {
|
|
90
|
+
const nameParts = import_path.default.basename(fullPath).split(".");
|
|
91
|
+
if (nameParts[0] === provider) {
|
|
92
|
+
const newFileName = provider + (i + 1) + "." + nameParts.slice(1).join(".");
|
|
93
|
+
newFullPath = import_path.default.join(import_path.default.dirname(fullPath), newFileName);
|
|
94
|
+
} else {
|
|
95
|
+
const count = i > 1 ? i : "";
|
|
96
|
+
const newFileName = provider + (0, import_pascalcase.default)(nameParts[0]) + count + "." + nameParts.slice(1).join(".");
|
|
97
|
+
newFullPath = import_path.default.join(import_path.default.dirname(fullPath), newFileName);
|
|
98
|
+
}
|
|
99
|
+
i++;
|
|
100
|
+
}
|
|
101
|
+
newFilesRecord[newFullPath] = filesRecord[fullPath];
|
|
102
|
+
});
|
|
103
|
+
return newFilesRecord;
|
|
104
|
+
}
|
|
105
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
106
|
+
0 && (module.exports = {
|
|
107
|
+
apiSideFiles,
|
|
108
|
+
generateUniqueFileNames
|
|
109
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ListrRenderer, ListrTask, ListrTaskWrapper } from 'listr2';
|
|
2
|
+
export declare const getWebAppPath: () => string;
|
|
3
|
+
export declare const addApiConfig: ({ replaceExistingImport, authDecoderImport, }: {
|
|
4
|
+
replaceExistingImport: boolean;
|
|
5
|
+
authDecoderImport?: string;
|
|
6
|
+
}) => void;
|
|
7
|
+
export declare const hasAuthProvider: (content: string) => boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Removes <AuthProvider ...> and </AuthProvider> if they exist, and un-indents
|
|
10
|
+
* the content.
|
|
11
|
+
*
|
|
12
|
+
* Exported for testing
|
|
13
|
+
*/
|
|
14
|
+
export declare const removeAuthProvider: (content: string) => string;
|
|
15
|
+
/**
|
|
16
|
+
* Actually inserts the required config lines into App.{jsx,tsx}
|
|
17
|
+
* Exported for testing
|
|
18
|
+
*/
|
|
19
|
+
export declare const addConfigToWebApp: <Renderer extends typeof ListrRenderer>() => ListrTask<AuthGeneratorCtx, Renderer>;
|
|
20
|
+
export declare const createWebAuth: (basedir: string, webAuthn: boolean) => {
|
|
21
|
+
title: string;
|
|
22
|
+
task: (ctx: AuthGeneratorCtx) => Promise<void>;
|
|
23
|
+
};
|
|
24
|
+
export declare const addConfigToRoutes: () => {
|
|
25
|
+
title: string;
|
|
26
|
+
task: () => void;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Will find the templates inside `${basedir}/templates/api`,
|
|
30
|
+
* and write these files to disk with unique names if they are clashing.
|
|
31
|
+
*
|
|
32
|
+
* @returns Listr task
|
|
33
|
+
*/
|
|
34
|
+
export declare const generateAuthApiFiles: <Renderer extends typeof ListrRenderer>(basedir: string, webAuthn: boolean) => ListrTask<AuthGeneratorCtx, Renderer>;
|
|
35
|
+
export declare const addAuthConfigToGqlApi: <Renderer extends typeof ListrRenderer, FallbackRenderer extends typeof ListrRenderer>(authDecoderImport?: string) => {
|
|
36
|
+
title: string;
|
|
37
|
+
task: (ctx: AuthGeneratorCtx, _task: ListrTaskWrapper<AuthGeneratorCtx, Renderer, FallbackRenderer>) => void;
|
|
38
|
+
};
|
|
39
|
+
export type AuthSetupMode = 'FORCE' | 'REPLACE' | 'COMBINE' | 'UNKNOWN';
|
|
40
|
+
export interface AuthGeneratorCtx {
|
|
41
|
+
setupMode: AuthSetupMode;
|
|
42
|
+
provider: string;
|
|
43
|
+
force: boolean;
|
|
44
|
+
}
|
|
45
|
+
export declare const setAuthSetupMode: <Renderer extends typeof ListrRenderer, FallbackRenderer extends typeof ListrRenderer>(force: boolean) => {
|
|
46
|
+
title: string;
|
|
47
|
+
task: (ctx: AuthGeneratorCtx, task: ListrTaskWrapper<AuthGeneratorCtx, Renderer, FallbackRenderer>) => Promise<void>;
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=authTasks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authTasks.d.ts","sourceRoot":"","sources":["../../../src/auth/authTasks.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAA;AAmBxE,eAAO,MAAM,aAAa,cAA2B,CAAA;AAwDrD,eAAO,MAAM,YAAY,GAAI,+CAG1B;IACD,qBAAqB,EAAE,OAAO,CAAA;IAC9B,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC3B,SAgDA,CAAA;AAmCD,eAAO,MAAM,eAAe,GAAI,SAAS,MAAM,YAE9C,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,WA6CjD,CAAA;AAoED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,SAAS,OAAO,aAAa,OAClC,SAAS,CAAC,gBAAgB,EAAE,QAAQ,CA0CxC,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,EAAE,UAAU,OAAO;;gBAgC1C,gBAAgB;CA0CrC,CAAA;AAED,eAAO,MAAM,iBAAiB;;;CAmB7B,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAAI,QAAQ,SAAS,OAAO,aAAa,EACxE,SAAS,MAAM,EACf,UAAU,OAAO,KAChB,SAAS,CAAC,gBAAgB,EAAE,QAAQ,CAgDtC,CAAA;AASD,eAAO,MAAM,qBAAqB,GAChC,QAAQ,SAAS,OAAO,aAAa,EACrC,gBAAgB,SAAS,OAAO,aAAa,EAE7C,oBAAoB,MAAM;;gBAInB,gBAAgB,SACd,gBAAgB,CAAC,gBAAgB,EAAE,QAAQ,EAAE,gBAAgB,CAAC;CAcvE,CAAA;AAEF,MAAM,MAAM,aAAa,GACrB,OAAO,GACP,SAAS,GACT,SAAS,GACT,SAAS,CAAA;AAEb,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,aAAa,CAAA;IACxB,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,OAAO,CAAA;CACf;AAED,eAAO,MAAM,gBAAgB,GAC3B,QAAQ,SAAS,OAAO,aAAa,EACrC,gBAAgB,SAAS,OAAO,aAAa,EAE7C,OAAO,OAAO;;gBAKL,gBAAgB,QACf,gBAAgB,CAAC,gBAAgB,EAAE,QAAQ,EAAE,gBAAgB,CAAC;CA2CzE,CAAA"}
|
|
@@ -0,0 +1,384 @@
|
|
|
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 authTasks_exports = {};
|
|
30
|
+
__export(authTasks_exports, {
|
|
31
|
+
addApiConfig: () => addApiConfig,
|
|
32
|
+
addAuthConfigToGqlApi: () => addAuthConfigToGqlApi,
|
|
33
|
+
addConfigToRoutes: () => addConfigToRoutes,
|
|
34
|
+
addConfigToWebApp: () => addConfigToWebApp,
|
|
35
|
+
createWebAuth: () => createWebAuth,
|
|
36
|
+
generateAuthApiFiles: () => generateAuthApiFiles,
|
|
37
|
+
getWebAppPath: () => getWebAppPath,
|
|
38
|
+
hasAuthProvider: () => hasAuthProvider,
|
|
39
|
+
removeAuthProvider: () => removeAuthProvider,
|
|
40
|
+
setAuthSetupMode: () => setAuthSetupMode
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(authTasks_exports);
|
|
43
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
44
|
+
var import_path = __toESM(require("path"), 1);
|
|
45
|
+
var import_prompt_adapter_enquirer = require("@listr2/prompt-adapter-enquirer");
|
|
46
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
47
|
+
var import_colors = require("../lib/colors.js");
|
|
48
|
+
var import_lib = require("../lib/index.js");
|
|
49
|
+
var import_paths = require("../lib/paths.js");
|
|
50
|
+
var import_project = require("../lib/project.js");
|
|
51
|
+
var import_authFiles = require("./authFiles.js");
|
|
52
|
+
const AUTH_PROVIDER_HOOK_IMPORT = `import { AuthProvider, useAuth } from './auth.js'`;
|
|
53
|
+
const AUTH_HOOK_IMPORT = `import { useAuth } from './auth.js'`;
|
|
54
|
+
const getWebAppPath = () => (0, import_paths.getPaths)().web.app;
|
|
55
|
+
function addAuthDecoderToCreateGraphQLHandler(content) {
|
|
56
|
+
if (!new RegExp("(?=(^.*?createGraphQLHandler))\\1.*\\bauthDecoder", "s").test(
|
|
57
|
+
content
|
|
58
|
+
)) {
|
|
59
|
+
return content.replace(
|
|
60
|
+
/^(?<indentation>\s*)(loggerConfig:)(.*)$/m,
|
|
61
|
+
`$<indentation>authDecoder,
|
|
62
|
+
$<indentation>$2$3`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
return content;
|
|
66
|
+
}
|
|
67
|
+
function replaceAuthDecoderImport(content, decoderImport) {
|
|
68
|
+
return content.replace(/^import { authDecoder .*} from .+/, decoderImport);
|
|
69
|
+
}
|
|
70
|
+
function replaceAuthDecoderArg(content) {
|
|
71
|
+
return content.replace(/^(\s+)authDecoder\b.+/m, "$1authDecoder,");
|
|
72
|
+
}
|
|
73
|
+
const addApiConfig = ({
|
|
74
|
+
replaceExistingImport,
|
|
75
|
+
authDecoderImport
|
|
76
|
+
}) => {
|
|
77
|
+
const graphqlPath = (0, import_project.getGraphqlPath)();
|
|
78
|
+
if (!graphqlPath) {
|
|
79
|
+
throw new Error("Could not find your graphql file path");
|
|
80
|
+
}
|
|
81
|
+
const content = import_node_fs.default.readFileSync(graphqlPath).toString();
|
|
82
|
+
let newContent = content;
|
|
83
|
+
if (authDecoderImport) {
|
|
84
|
+
if (replaceExistingImport) {
|
|
85
|
+
newContent = replaceAuthDecoderImport(newContent, authDecoderImport);
|
|
86
|
+
newContent = replaceAuthDecoderArg(newContent);
|
|
87
|
+
}
|
|
88
|
+
const didReplace = newContent.includes(authDecoderImport);
|
|
89
|
+
if (!replaceExistingImport || !didReplace) {
|
|
90
|
+
newContent = authDecoderImport + "\n" + newContent;
|
|
91
|
+
newContent = addAuthDecoderToCreateGraphQLHandler(newContent);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const hasCurrentUserImport = /(^import {.*?getCurrentUser(?!getCurrentUser).*?} from ['"]src\/lib\/auth(?:\.js)?['"])/s.test(
|
|
95
|
+
newContent
|
|
96
|
+
);
|
|
97
|
+
if (!hasCurrentUserImport) {
|
|
98
|
+
newContent = newContent.replace(
|
|
99
|
+
/^(import { db } from ['"]src\/lib\/db(?:\.js)?['"])$/m,
|
|
100
|
+
`import { getCurrentUser } from 'src/lib/auth'
|
|
101
|
+
$1`
|
|
102
|
+
);
|
|
103
|
+
newContent = newContent.replace(
|
|
104
|
+
/^(\s*)(loggerConfig:)(.*)$/m,
|
|
105
|
+
`$1getCurrentUser,
|
|
106
|
+
$1$2$3`
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
if (newContent !== content) {
|
|
110
|
+
import_node_fs.default.writeFileSync(graphqlPath, newContent);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const apiSrcDoesExist = () => {
|
|
114
|
+
return import_node_fs.default.existsSync(import_path.default.join((0, import_paths.getPaths)().api.src));
|
|
115
|
+
};
|
|
116
|
+
const addAuthImportToApp = (content) => {
|
|
117
|
+
const contentLines = content.split("\n");
|
|
118
|
+
const importIndex = contentLines.findLastIndex(
|
|
119
|
+
(line) => /^\s*import (?!.*(?:.css['"]|.scss['"]))/.test(line)
|
|
120
|
+
);
|
|
121
|
+
contentLines.splice(importIndex + 1, 0, "", AUTH_PROVIDER_HOOK_IMPORT);
|
|
122
|
+
return contentLines.join("\n");
|
|
123
|
+
};
|
|
124
|
+
const addAuthImportToRoutes = (content) => {
|
|
125
|
+
const contentLines = content.split("\n");
|
|
126
|
+
const importIndex = contentLines.findLastIndex(
|
|
127
|
+
(line) => /^\s*import (?!.*(?:.css['"]|.scss['"]))/.test(line)
|
|
128
|
+
);
|
|
129
|
+
contentLines.splice(importIndex + 1, 0, "", AUTH_HOOK_IMPORT);
|
|
130
|
+
return contentLines.join("\n");
|
|
131
|
+
};
|
|
132
|
+
const hasAuthProvider = (content) => {
|
|
133
|
+
return /\s*<AuthProvider([\s>]|$)/.test(content);
|
|
134
|
+
};
|
|
135
|
+
const removeAuthProvider = (content) => {
|
|
136
|
+
let remove = false;
|
|
137
|
+
let end = "";
|
|
138
|
+
let unindent = false;
|
|
139
|
+
return content.split("\n").reduce((acc, line) => {
|
|
140
|
+
let keep = !remove;
|
|
141
|
+
if (hasAuthProvider(line)) {
|
|
142
|
+
remove = true;
|
|
143
|
+
keep = false;
|
|
144
|
+
unindent = true;
|
|
145
|
+
end = line.replace(/^(\s*)<Auth.*/s, "$1") + ">";
|
|
146
|
+
}
|
|
147
|
+
if (hasAuthProvider(line) && line.trimEnd().at(-1) === ">" || line.trimEnd() === end) {
|
|
148
|
+
remove = false;
|
|
149
|
+
}
|
|
150
|
+
if (/\s*<\/AuthProvider>/.test(line)) {
|
|
151
|
+
keep = false;
|
|
152
|
+
unindent = false;
|
|
153
|
+
}
|
|
154
|
+
if (keep) {
|
|
155
|
+
if (unindent) {
|
|
156
|
+
acc.push(line.replace(" ", ""));
|
|
157
|
+
} else {
|
|
158
|
+
acc.push(line);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return acc;
|
|
162
|
+
}, []).join("\n");
|
|
163
|
+
};
|
|
164
|
+
const addAuthProviderToApp = (content, setupMode) => {
|
|
165
|
+
if (setupMode === "FORCE" || setupMode === "REPLACE") {
|
|
166
|
+
content = removeAuthProvider(content);
|
|
167
|
+
}
|
|
168
|
+
const match = content.match(
|
|
169
|
+
/(\s+)(<RedwoodProvider.*?>)(.*)(<\/RedwoodProvider>)/s
|
|
170
|
+
);
|
|
171
|
+
if (!match) {
|
|
172
|
+
throw new Error("Could not find <RedwoodProvider> in App.{jsx,tsx}");
|
|
173
|
+
}
|
|
174
|
+
if (/\s+<AuthProvider>/.test(content)) {
|
|
175
|
+
return content;
|
|
176
|
+
}
|
|
177
|
+
const [
|
|
178
|
+
_,
|
|
179
|
+
newlineAndIndent,
|
|
180
|
+
redwoodProviderOpen,
|
|
181
|
+
redwoodProviderChildren,
|
|
182
|
+
redwoodProviderClose
|
|
183
|
+
] = match;
|
|
184
|
+
const redwoodProviderChildrenLines = redwoodProviderChildren.split("\n").map((line, index) => {
|
|
185
|
+
return `${index === 0 ? "" : " "}` + line;
|
|
186
|
+
});
|
|
187
|
+
const renderContent = newlineAndIndent + redwoodProviderOpen + newlineAndIndent + ` <AuthProvider>` + redwoodProviderChildrenLines.join("\n") + `</AuthProvider>` + newlineAndIndent + redwoodProviderClose;
|
|
188
|
+
return content.replace(
|
|
189
|
+
/\s+<RedwoodProvider.*?>.*<\/RedwoodProvider>/s,
|
|
190
|
+
renderContent
|
|
191
|
+
);
|
|
192
|
+
};
|
|
193
|
+
const hasUseAuthHook = (componentName, content) => {
|
|
194
|
+
return new RegExp(
|
|
195
|
+
`<${componentName}.*useAuth={.*?}.*?>.*</${componentName}>`,
|
|
196
|
+
"s"
|
|
197
|
+
).test(content);
|
|
198
|
+
};
|
|
199
|
+
const addUseAuthHook = (componentName, content) => {
|
|
200
|
+
return content.replace(
|
|
201
|
+
`<${componentName}`,
|
|
202
|
+
`<${componentName} useAuth={useAuth}`
|
|
203
|
+
);
|
|
204
|
+
};
|
|
205
|
+
const addConfigToWebApp = () => {
|
|
206
|
+
return {
|
|
207
|
+
title: "Updating web/src/App.{jsx,tsx}",
|
|
208
|
+
task: (ctx, task) => {
|
|
209
|
+
const webAppPath = getWebAppPath();
|
|
210
|
+
if (!import_node_fs.default.existsSync(webAppPath)) {
|
|
211
|
+
const ext = (0, import_project.isTypeScriptProject)() ? "tsx" : "jsx";
|
|
212
|
+
throw new Error(`Could not find root App.${ext}`);
|
|
213
|
+
}
|
|
214
|
+
let content = import_node_fs.default.readFileSync(webAppPath, "utf-8");
|
|
215
|
+
if (!content.includes(AUTH_PROVIDER_HOOK_IMPORT)) {
|
|
216
|
+
content = addAuthImportToApp(content);
|
|
217
|
+
}
|
|
218
|
+
if (ctx.setupMode === "REPLACE" || ctx.setupMode === "FORCE") {
|
|
219
|
+
content = content.replace(
|
|
220
|
+
"import { AuthProvider } from '@cedarjs/auth'\n",
|
|
221
|
+
""
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
content = addAuthProviderToApp(content, ctx.setupMode);
|
|
225
|
+
if (/\s*<RedwoodApolloProvider/.test(content)) {
|
|
226
|
+
if (!hasUseAuthHook("RedwoodApolloProvider", content)) {
|
|
227
|
+
content = addUseAuthHook("RedwoodApolloProvider", content);
|
|
228
|
+
}
|
|
229
|
+
} else {
|
|
230
|
+
task.output = import_colors.colors.warning(
|
|
231
|
+
"Could not find <RedwoodApolloProvider>.\nIf you are using a custom GraphQL Client you will have to make sure it gets access to your `useAuth`, if it needs it."
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
import_node_fs.default.writeFileSync(webAppPath, content);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
const createWebAuth = (basedir, webAuthn) => {
|
|
239
|
+
const templatesBaseDir = import_path.default.join(basedir, "templates", "web");
|
|
240
|
+
const templates = import_node_fs.default.readdirSync(templatesBaseDir);
|
|
241
|
+
const rscEnabled = (0, import_project_config.getConfig)().experimental?.rsc?.enabled;
|
|
242
|
+
const templateStart = "auth" + (webAuthn ? ".webAuthn" : "") + (rscEnabled ? ".rsc" : "") + ".ts";
|
|
243
|
+
const templateFileName = templates.find((template) => {
|
|
244
|
+
return template.startsWith(templateStart);
|
|
245
|
+
});
|
|
246
|
+
if (!templateFileName) {
|
|
247
|
+
throw new Error(
|
|
248
|
+
"Could not find the auth.ts(x) template, looking for filename starting with " + templateStart
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
const templateExtension = templateFileName.split(".").at(-2);
|
|
252
|
+
const isTSProject = (0, import_project.isTypeScriptProject)();
|
|
253
|
+
let ext = templateExtension;
|
|
254
|
+
if (!(0, import_project.isTypeScriptProject)()) {
|
|
255
|
+
ext = ext?.replace("ts", "js");
|
|
256
|
+
}
|
|
257
|
+
return {
|
|
258
|
+
title: `Creating web/src/auth.${ext}`,
|
|
259
|
+
task: async (ctx) => {
|
|
260
|
+
let authFileName = import_path.default.join((0, import_paths.getPaths)().web.src, "auth");
|
|
261
|
+
if (ctx.setupMode === "COMBINE") {
|
|
262
|
+
let i = 1;
|
|
263
|
+
while ((0, import_project_config.resolveFile)(authFileName)) {
|
|
264
|
+
const count = i > 1 ? i : "";
|
|
265
|
+
authFileName = import_path.default.join(
|
|
266
|
+
(0, import_paths.getPaths)().web.src,
|
|
267
|
+
ctx.provider + "Auth" + count
|
|
268
|
+
);
|
|
269
|
+
i++;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
authFileName = authFileName + "." + ext;
|
|
273
|
+
let template = import_node_fs.default.readFileSync(
|
|
274
|
+
import_path.default.join(templatesBaseDir, templateFileName),
|
|
275
|
+
"utf-8"
|
|
276
|
+
);
|
|
277
|
+
template = isTSProject ? template : await (0, import_lib.transformTSToJS)(authFileName, template);
|
|
278
|
+
import_node_fs.default.writeFileSync(authFileName, template);
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
};
|
|
282
|
+
const addConfigToRoutes = () => {
|
|
283
|
+
return {
|
|
284
|
+
title: "Updating Routes file...",
|
|
285
|
+
task: () => {
|
|
286
|
+
const webRoutesPath = (0, import_paths.getPaths)().web.routes;
|
|
287
|
+
let content = import_node_fs.default.readFileSync(webRoutesPath).toString();
|
|
288
|
+
if (!content.includes(AUTH_HOOK_IMPORT)) {
|
|
289
|
+
content = addAuthImportToRoutes(content);
|
|
290
|
+
}
|
|
291
|
+
if (!hasUseAuthHook("Router", content)) {
|
|
292
|
+
content = addUseAuthHook("Router", content);
|
|
293
|
+
}
|
|
294
|
+
import_node_fs.default.writeFileSync(webRoutesPath, content);
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
const generateAuthApiFiles = (basedir, webAuthn) => {
|
|
299
|
+
return {
|
|
300
|
+
title: "Generating auth api side files...",
|
|
301
|
+
task: async (ctx, task) => {
|
|
302
|
+
if (!apiSrcDoesExist()) {
|
|
303
|
+
return new Error(
|
|
304
|
+
"Could not find api/src directory. Cannot continue setup!"
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
let filesRecord = await (0, import_authFiles.apiSideFiles)({ basedir, webAuthn });
|
|
308
|
+
let existingFiles = "FAIL";
|
|
309
|
+
if (ctx.setupMode === "FORCE") {
|
|
310
|
+
existingFiles = "OVERWRITE";
|
|
311
|
+
} else if (ctx.setupMode === "REPLACE") {
|
|
312
|
+
const filesToOverwrite = findExistingFiles(filesRecord);
|
|
313
|
+
const prompt = task.prompt(import_prompt_adapter_enquirer.ListrEnquirerPromptAdapter);
|
|
314
|
+
const overwrite = await prompt.run({
|
|
315
|
+
type: "confirm",
|
|
316
|
+
message: `Overwrite existing ${filesToOverwrite.join(", ")}?`,
|
|
317
|
+
initial: false
|
|
318
|
+
});
|
|
319
|
+
existingFiles = overwrite ? "OVERWRITE" : "SKIP";
|
|
320
|
+
} else if (ctx.setupMode === "COMBINE") {
|
|
321
|
+
const uniqueFilesRecord = (0, import_authFiles.generateUniqueFileNames)(
|
|
322
|
+
filesRecord,
|
|
323
|
+
ctx.provider
|
|
324
|
+
);
|
|
325
|
+
filesRecord = uniqueFilesRecord;
|
|
326
|
+
existingFiles = "FAIL";
|
|
327
|
+
}
|
|
328
|
+
return (0, import_lib.writeFilesTask)(filesRecord, {
|
|
329
|
+
existingFiles
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
};
|
|
334
|
+
function findExistingFiles(filesMap) {
|
|
335
|
+
return Object.keys(filesMap).filter((filePath) => import_node_fs.default.existsSync(filePath)).map((filePath) => filePath.replace((0, import_paths.getPaths)().base, ""));
|
|
336
|
+
}
|
|
337
|
+
const addAuthConfigToGqlApi = (authDecoderImport) => ({
|
|
338
|
+
title: "Adding auth config to GraphQL API...",
|
|
339
|
+
task: (ctx, _task) => {
|
|
340
|
+
if ((0, import_project.graphFunctionDoesExist)()) {
|
|
341
|
+
addApiConfig({
|
|
342
|
+
authDecoderImport,
|
|
343
|
+
replaceExistingImport: ctx.setupMode === "REPLACE" || ctx.setupMode === "FORCE"
|
|
344
|
+
});
|
|
345
|
+
} else {
|
|
346
|
+
throw new Error(
|
|
347
|
+
"GraphQL function not found. You will need to pass the decoder to the createGraphQLHandler function."
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
const setAuthSetupMode = (force) => {
|
|
353
|
+
return {
|
|
354
|
+
title: "Checking project for existing auth...",
|
|
355
|
+
task: async (ctx, task) => {
|
|
356
|
+
if (force) {
|
|
357
|
+
ctx.setupMode = "FORCE";
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
const webAppContents = import_node_fs.default.readFileSync(getWebAppPath(), "utf-8");
|
|
361
|
+
if (hasAuthProvider(webAppContents) && ctx.setupMode === "UNKNOWN") {
|
|
362
|
+
const setupMode = "REPLACE";
|
|
363
|
+
ctx.setupMode = setupMode;
|
|
364
|
+
return;
|
|
365
|
+
} else {
|
|
366
|
+
ctx.setupMode = "FORCE";
|
|
367
|
+
task.skip("Setting up Auth from scratch");
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
};
|
|
372
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
373
|
+
0 && (module.exports = {
|
|
374
|
+
addApiConfig,
|
|
375
|
+
addAuthConfigToGqlApi,
|
|
376
|
+
addConfigToRoutes,
|
|
377
|
+
addConfigToWebApp,
|
|
378
|
+
createWebAuth,
|
|
379
|
+
generateAuthApiFiles,
|
|
380
|
+
getWebAppPath,
|
|
381
|
+
hasAuthProvider,
|
|
382
|
+
removeAuthProvider,
|
|
383
|
+
setAuthSetupMode
|
|
384
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ListrTask } from 'listr2';
|
|
2
|
+
import type { Argv } from 'yargs';
|
|
3
|
+
import type { AuthGeneratorCtx } from './authTasks.js';
|
|
4
|
+
export type { AuthGeneratorCtx };
|
|
5
|
+
export declare const standardAuthBuilder: (yargs: Argv) => Argv<{
|
|
6
|
+
force: boolean;
|
|
7
|
+
} & {
|
|
8
|
+
verbose: boolean;
|
|
9
|
+
}>;
|
|
10
|
+
export interface AuthHandlerArgs {
|
|
11
|
+
basedir: string;
|
|
12
|
+
forceArg: boolean;
|
|
13
|
+
provider: string;
|
|
14
|
+
authDecoderImport?: string;
|
|
15
|
+
webAuthn?: boolean;
|
|
16
|
+
webPackages?: string[];
|
|
17
|
+
apiPackages?: string[];
|
|
18
|
+
extraTasks?: (ListrTask<AuthGeneratorCtx> | undefined)[];
|
|
19
|
+
notes?: string[];
|
|
20
|
+
verbose?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* basedir assumes that you must have a templates folder in that directory.
|
|
24
|
+
* See folder structure of auth providers in packages/auth-providers/<provider>/setup/src
|
|
25
|
+
*/
|
|
26
|
+
export declare const standardAuthHandler: ({ basedir, forceArg, provider, authDecoderImport, webAuthn, webPackages, apiPackages, extraTasks, notes, verbose, }: AuthHandlerArgs) => Promise<void>;
|
|
27
|
+
//# sourceMappingURL=setupHelpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setupHelpers.d.ts","sourceRoot":"","sources":["../../../src/auth/setupHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAGvC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAWjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAUtD,YAAY,EAAE,gBAAgB,EAAE,CAAA;AAEhC,eAAO,MAAM,mBAAmB,GAAI,OAAO,IAAI;;;;EAoB9C,CAAA;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,OAAO,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;IACtB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;IACtB,UAAU,CAAC,EAAE,CAAC,SAAS,CAAC,gBAAgB,CAAC,GAAG,SAAS,CAAC,EAAE,CAAA;IACxD,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAChB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AASD;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAAU,qHAWvC,eAAe,kBAiFjB,CAAA"}
|