@cedarjs/cli-helpers 7.0.0-canary.3073 → 7.0.0-canary.3075
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/authFiles.d.ts +9 -1
- package/dist/auth/authFiles.d.ts.map +1 -1
- package/dist/auth/authFiles.js +44 -22
- package/dist/auth/authTasks.d.ts +1 -1
- package/dist/auth/authTasks.d.ts.map +1 -1
- package/dist/auth/authTasks.js +2 -2
- package/dist/auth/setupHelpers.d.ts +2 -1
- package/dist/auth/setupHelpers.d.ts.map +1 -1
- package/dist/auth/setupHelpers.js +2 -1
- package/package.json +4 -4
package/dist/auth/authFiles.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
interface FilesArgs {
|
|
2
2
|
basedir: string;
|
|
3
3
|
webAuthn: boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Selects the `*.oauth.*` template variant, the same way `webAuthn` selects
|
|
6
|
+
* the `*.webAuthn.*` variant. When both are true, the most specific
|
|
7
|
+
* template available is preferred (`*.webAuthn.oauth.*`), falling back to
|
|
8
|
+
* a single-variant or the base template when a more specific one doesn't
|
|
9
|
+
* exist for a given template file.
|
|
10
|
+
*/
|
|
11
|
+
oauth?: boolean;
|
|
4
12
|
}
|
|
5
13
|
/**
|
|
6
14
|
* Get the api side file paths and file contents to write
|
|
@@ -14,7 +22,7 @@ interface FilesArgs {
|
|
|
14
22
|
* }
|
|
15
23
|
* ```
|
|
16
24
|
*/
|
|
17
|
-
export declare const apiSideFiles: ({ basedir, webAuthn }: FilesArgs) => Promise<Record<string, string>>;
|
|
25
|
+
export declare const apiSideFiles: ({ basedir, webAuthn, oauth, }: FilesArgs) => Promise<Record<string, string>>;
|
|
18
26
|
/**
|
|
19
27
|
* Loops through the keys in `filesRecord` and generates unique file paths if
|
|
20
28
|
* they conflict with existing files
|
|
@@ -1 +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;
|
|
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;IACjB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AA+DD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY,GAAU,+BAIhC,SAAS,oCA4CX,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACnC,QAAQ,EAAE,MAAM,0BAwCjB"}
|
package/dist/auth/authFiles.js
CHANGED
|
@@ -4,37 +4,59 @@ import pascalcase from "pascalcase";
|
|
|
4
4
|
import { transformTSToJS } from "../lib/index.js";
|
|
5
5
|
import { getPaths } from "../lib/paths.js";
|
|
6
6
|
import { isTypeScriptProject } from "../lib/project.js";
|
|
7
|
-
const
|
|
7
|
+
const VARIANT_TAGS = ["webAuthn", "oauth"];
|
|
8
|
+
function parseTemplateFileName(fileName) {
|
|
9
|
+
const parts = fileName.split(".");
|
|
10
|
+
const baseName = parts[0];
|
|
11
|
+
const ext = parts.at(-2);
|
|
12
|
+
const tags = parts.slice(1, -2).filter((part) => VARIANT_TAGS.includes(part));
|
|
13
|
+
return { baseName, tags, ext };
|
|
14
|
+
}
|
|
15
|
+
function pickTemplateVariants(templateFiles, activeTags) {
|
|
16
|
+
const candidatesByKey = /* @__PURE__ */ new Map();
|
|
17
|
+
for (const fileName of templateFiles) {
|
|
18
|
+
const { baseName, tags, ext } = parseTemplateFileName(fileName);
|
|
19
|
+
const key = `${baseName}.${ext}`;
|
|
20
|
+
const candidates = candidatesByKey.get(key) ?? [];
|
|
21
|
+
candidates.push({ fileName, tags });
|
|
22
|
+
candidatesByKey.set(key, candidates);
|
|
23
|
+
}
|
|
24
|
+
const picked = [];
|
|
25
|
+
for (const candidates of candidatesByKey.values()) {
|
|
26
|
+
const applicable = candidates.filter(
|
|
27
|
+
(candidate) => candidate.tags.every((tag) => activeTags.includes(tag))
|
|
28
|
+
);
|
|
29
|
+
const mostSpecific = applicable.reduce(
|
|
30
|
+
(best, candidate) => candidate.tags.length > best.tags.length ? candidate : best
|
|
31
|
+
);
|
|
32
|
+
picked.push(mostSpecific);
|
|
33
|
+
}
|
|
34
|
+
return picked;
|
|
35
|
+
}
|
|
36
|
+
const apiSideFiles = async ({
|
|
37
|
+
basedir,
|
|
38
|
+
webAuthn,
|
|
39
|
+
oauth = false
|
|
40
|
+
}) => {
|
|
8
41
|
const apiSrcPath = getPaths().api.src;
|
|
9
42
|
const apiBaseTemplatePath = path.join(basedir, "templates", "api");
|
|
10
43
|
const templateDirectories = fs.readdirSync(apiBaseTemplatePath);
|
|
11
44
|
let filesRecord = {};
|
|
45
|
+
const activeTags = [
|
|
46
|
+
...webAuthn ? ["webAuthn"] : [],
|
|
47
|
+
...oauth ? ["oauth"] : []
|
|
48
|
+
];
|
|
12
49
|
for (const dir of templateDirectories) {
|
|
13
50
|
const templateFiles = fs.readdirSync(path.join(apiBaseTemplatePath, dir));
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
let outputFileName = fileName.replace(/\.template$/, "");
|
|
51
|
+
const pickedVariants = pickTemplateVariants(templateFiles, activeTags);
|
|
52
|
+
const filePaths = pickedVariants.map(({ fileName }) => {
|
|
53
|
+
const { baseName, ext } = parseTemplateFileName(fileName);
|
|
54
|
+
let outputFileName = `${baseName}.${ext}`;
|
|
19
55
|
if (!isTypeScriptProject()) {
|
|
20
56
|
outputFileName = outputFileName.replace(/\.ts(x?)$/, ".js$1");
|
|
21
57
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
const webAuthnFileName = fileName.split(".").reverse().map((part, i) => i === 1 ? "webAuthn." + part : part).reverse().join(".");
|
|
26
|
-
if (templateFiles.includes(webAuthnFileName)) {
|
|
27
|
-
return { templateFileName: webAuthnFileName, outputFileName };
|
|
28
|
-
} else {
|
|
29
|
-
return { templateFileName: fileName, outputFileName };
|
|
30
|
-
}
|
|
31
|
-
}).map((f) => {
|
|
32
|
-
const templateFilePath = path.join(
|
|
33
|
-
apiBaseTemplatePath,
|
|
34
|
-
dir,
|
|
35
|
-
f.templateFileName
|
|
36
|
-
);
|
|
37
|
-
const outputFilePath = path.join(apiSrcPath, dir, f.outputFileName);
|
|
58
|
+
const templateFilePath = path.join(apiBaseTemplatePath, dir, fileName);
|
|
59
|
+
const outputFilePath = path.join(apiSrcPath, dir, outputFileName);
|
|
38
60
|
return { templateFilePath, outputFilePath };
|
|
39
61
|
});
|
|
40
62
|
for (const paths of filePaths) {
|
package/dist/auth/authTasks.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export declare const addConfigToRoutes: () => {
|
|
|
31
31
|
*
|
|
32
32
|
* @returns Listr task
|
|
33
33
|
*/
|
|
34
|
-
export declare const generateAuthApiFiles: <Renderer extends typeof ListrRenderer>(basedir: string, webAuthn: boolean) => ListrTask<AuthGeneratorCtx, Renderer>;
|
|
34
|
+
export declare const generateAuthApiFiles: <Renderer extends typeof ListrRenderer>(basedir: string, webAuthn: boolean, oauth?: boolean) => ListrTask<AuthGeneratorCtx, Renderer>;
|
|
35
35
|
export declare const addAuthConfigToGqlApi: <Renderer extends typeof ListrRenderer, FallbackRenderer extends typeof ListrRenderer>(authDecoderImport?: string) => {
|
|
36
36
|
title: string;
|
|
37
37
|
task: (ctx: AuthGeneratorCtx, _task: ListrTaskWrapper<AuthGeneratorCtx, Renderer, FallbackRenderer>) => void;
|
|
@@ -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;AA2BxE,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;AAuED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,SAAS,OAAO,aAAa,OAClC,SAAS,CAAC,gBAAgB,EAAE,QAAQ,CA8CxC,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,
|
|
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;AA2BxE,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,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
267
|
+
const generateAuthApiFiles = (basedir, webAuthn, oauth = false) => {
|
|
268
268
|
return {
|
|
269
269
|
title: "Generating auth api side files...",
|
|
270
270
|
task: async (ctx, task) => {
|
|
@@ -273,7 +273,7 @@ const generateAuthApiFiles = (basedir, webAuthn) => {
|
|
|
273
273
|
"Could not find api/src directory. Cannot continue setup!"
|
|
274
274
|
);
|
|
275
275
|
}
|
|
276
|
-
let filesRecord = await apiSideFiles({ basedir, webAuthn });
|
|
276
|
+
let filesRecord = await apiSideFiles({ basedir, webAuthn, oauth });
|
|
277
277
|
let existingFiles = "FAIL";
|
|
278
278
|
if (ctx.setupMode === "FORCE") {
|
|
279
279
|
existingFiles = "OVERWRITE";
|
|
@@ -13,6 +13,7 @@ export interface AuthHandlerArgs {
|
|
|
13
13
|
provider: string;
|
|
14
14
|
authDecoderImport?: string;
|
|
15
15
|
webAuthn?: boolean;
|
|
16
|
+
oauth?: boolean;
|
|
16
17
|
webPackages?: string[];
|
|
17
18
|
apiPackages?: string[];
|
|
18
19
|
extraTasks?: (ListrTask<AuthGeneratorCtx> | undefined)[];
|
|
@@ -23,5 +24,5 @@ export interface AuthHandlerArgs {
|
|
|
23
24
|
* basedir assumes that you must have a templates folder in that directory.
|
|
24
25
|
* See folder structure of auth providers in packages/auth-providers/<provider>/setup/src
|
|
25
26
|
*/
|
|
26
|
-
export declare const standardAuthHandler: ({ basedir, forceArg, provider, authDecoderImport, webAuthn, webPackages, apiPackages, extraTasks, notes, verbose, }: AuthHandlerArgs) => Promise<void>;
|
|
27
|
+
export declare const standardAuthHandler: ({ basedir, forceArg, provider, authDecoderImport, webAuthn, oauth, webPackages, apiPackages, extraTasks, notes, verbose, }: AuthHandlerArgs) => Promise<void>;
|
|
27
28
|
//# sourceMappingURL=setupHelpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupHelpers.d.ts","sourceRoot":"","sources":["../../src/auth/setupHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,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A;IAChB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,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,4HAYvC,eAAe,kBAiFjB,CAAA"}
|
|
@@ -42,6 +42,7 @@ const standardAuthHandler = async ({
|
|
|
42
42
|
provider,
|
|
43
43
|
authDecoderImport,
|
|
44
44
|
webAuthn = false,
|
|
45
|
+
oauth = false,
|
|
45
46
|
webPackages = [],
|
|
46
47
|
apiPackages = [],
|
|
47
48
|
extraTasks,
|
|
@@ -51,7 +52,7 @@ const standardAuthHandler = async ({
|
|
|
51
52
|
const tasks = new Listr(
|
|
52
53
|
[
|
|
53
54
|
setAuthSetupMode(forceArg),
|
|
54
|
-
generateAuthApiFiles(basedir, webAuthn),
|
|
55
|
+
generateAuthApiFiles(basedir, webAuthn, oauth),
|
|
55
56
|
addConfigToWebApp(),
|
|
56
57
|
createWebAuth(basedir, webAuthn),
|
|
57
58
|
addConfigToRoutes(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/cli-helpers",
|
|
3
|
-
"version": "7.0.0-canary.
|
|
3
|
+
"version": "7.0.0-canary.3075",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -72,8 +72,8 @@
|
|
|
72
72
|
"test:watch": "vitest watch"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@cedarjs/project-config": "7.0.0-canary.
|
|
76
|
-
"@cedarjs/telemetry": "7.0.0-canary.
|
|
75
|
+
"@cedarjs/project-config": "7.0.0-canary.3075",
|
|
76
|
+
"@cedarjs/telemetry": "7.0.0-canary.3075",
|
|
77
77
|
"@listr2/prompt-adapter-enquirer": "4.3.1",
|
|
78
78
|
"@opentelemetry/api": "1.9.1",
|
|
79
79
|
"ansis": "4.3.1",
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"yargs-parser": "21.1.1"
|
|
94
94
|
},
|
|
95
95
|
"devDependencies": {
|
|
96
|
-
"@cedarjs/framework-tools": "7.0.0-canary.
|
|
96
|
+
"@cedarjs/framework-tools": "7.0.0-canary.3075",
|
|
97
97
|
"@types/dotenv-defaults": "^5.0.0",
|
|
98
98
|
"@types/lodash": "4.17.25",
|
|
99
99
|
"@types/pascalcase": "1.0.3",
|