@atom8n/node-cli 0.17.0
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/README.md +289 -0
- package/bin/n8n-node.mjs +5 -0
- package/dist/build.tsbuildinfo +1 -0
- package/dist/commands/build.d.ts +8 -0
- package/dist/commands/build.js +61 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/cloud-support.d.ts +14 -0
- package/dist/commands/cloud-support.js +136 -0
- package/dist/commands/cloud-support.js.map +1 -0
- package/dist/commands/dev/index.d.ts +10 -0
- package/dist/commands/dev/index.js +103 -0
- package/dist/commands/dev/index.js.map +1 -0
- package/dist/commands/dev/utils.d.ts +27 -0
- package/dist/commands/dev/utils.js +462 -0
- package/dist/commands/dev/utils.js.map +1 -0
- package/dist/commands/lint.d.ts +13 -0
- package/dist/commands/lint.js +124 -0
- package/dist/commands/lint.js.map +1 -0
- package/dist/commands/new/index.d.ts +14 -0
- package/dist/commands/new/index.js +141 -0
- package/dist/commands/new/index.js.map +1 -0
- package/dist/commands/new/prompts.d.ts +3 -0
- package/dist/commands/new/prompts.js +42 -0
- package/dist/commands/new/prompts.js.map +1 -0
- package/dist/commands/new/utils.d.ts +1 -0
- package/dist/commands/new/utils.js +13 -0
- package/dist/commands/new/utils.js.map +1 -0
- package/dist/commands/prerelease.d.ts +8 -0
- package/dist/commands/prerelease.js +20 -0
- package/dist/commands/prerelease.js.map +1 -0
- package/dist/commands/release.d.ts +7 -0
- package/dist/commands/release.js +52 -0
- package/dist/commands/release.js.map +1 -0
- package/dist/configs/eslint.d.ts +3 -0
- package/dist/configs/eslint.js +65 -0
- package/dist/configs/eslint.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/template/core.d.ts +29 -0
- package/dist/template/core.js +55 -0
- package/dist/template/core.js.map +1 -0
- package/dist/template/templates/declarative/custom/ast.d.ts +17 -0
- package/dist/template/templates/declarative/custom/ast.js +110 -0
- package/dist/template/templates/declarative/custom/ast.js.map +1 -0
- package/dist/template/templates/declarative/custom/ast.ts +161 -0
- package/dist/template/templates/declarative/custom/prompts.d.ts +3 -0
- package/dist/template/templates/declarative/custom/prompts.js +80 -0
- package/dist/template/templates/declarative/custom/prompts.js.map +1 -0
- package/dist/template/templates/declarative/custom/prompts.ts +87 -0
- package/dist/template/templates/declarative/custom/template/README.md +46 -0
- package/dist/template/templates/declarative/custom/template/nodes/Example/Example.node.json +18 -0
- package/dist/template/templates/declarative/custom/template/nodes/Example/Example.node.ts +50 -0
- package/dist/template/templates/declarative/custom/template/nodes/Example/example.dark.svg +13 -0
- package/dist/template/templates/declarative/custom/template/nodes/Example/example.svg +13 -0
- package/dist/template/templates/declarative/custom/template/nodes/Example/resources/company/getAll.ts +61 -0
- package/dist/template/templates/declarative/custom/template/nodes/Example/resources/company/index.ts +34 -0
- package/dist/template/templates/declarative/custom/template/nodes/Example/resources/user/create.ts +26 -0
- package/dist/template/templates/declarative/custom/template/nodes/Example/resources/user/get.ts +17 -0
- package/dist/template/templates/declarative/custom/template/nodes/Example/resources/user/index.ts +60 -0
- package/dist/template/templates/declarative/custom/template/package.json +48 -0
- package/dist/template/templates/declarative/custom/template/tsconfig.json +25 -0
- package/dist/template/templates/declarative/custom/template.d.ts +2 -0
- package/dist/template/templates/declarative/custom/template.js +83 -0
- package/dist/template/templates/declarative/custom/template.js.map +1 -0
- package/dist/template/templates/declarative/custom/template.ts +121 -0
- package/dist/template/templates/declarative/custom/types.d.ts +9 -0
- package/dist/template/templates/declarative/custom/types.js +3 -0
- package/dist/template/templates/declarative/custom/types.js.map +1 -0
- package/dist/template/templates/declarative/custom/types.ts +8 -0
- package/dist/template/templates/declarative/github-issues/template/README.md +73 -0
- package/dist/template/templates/declarative/github-issues/template/credentials/GithubIssuesApi.credentials.ts +45 -0
- package/dist/template/templates/declarative/github-issues/template/credentials/GithubIssuesOAuth2Api.credentials.ts +54 -0
- package/dist/template/templates/declarative/github-issues/template/icons/github.dark.svg +3 -0
- package/dist/template/templates/declarative/github-issues/template/icons/github.svg +3 -0
- package/dist/template/templates/declarative/github-issues/template/nodes/GithubIssues/GithubIssues.node.json +18 -0
- package/dist/template/templates/declarative/github-issues/template/nodes/GithubIssues/GithubIssues.node.ts +96 -0
- package/dist/template/templates/declarative/github-issues/template/nodes/GithubIssues/listSearch/getIssues.ts +49 -0
- package/dist/template/templates/declarative/github-issues/template/nodes/GithubIssues/listSearch/getRepositories.ts +50 -0
- package/dist/template/templates/declarative/github-issues/template/nodes/GithubIssues/listSearch/getUsers.ts +49 -0
- package/dist/template/templates/declarative/github-issues/template/nodes/GithubIssues/resources/issue/create.ts +74 -0
- package/dist/template/templates/declarative/github-issues/template/nodes/GithubIssues/resources/issue/get.ts +14 -0
- package/dist/template/templates/declarative/github-issues/template/nodes/GithubIssues/resources/issue/getAll.ts +124 -0
- package/dist/template/templates/declarative/github-issues/template/nodes/GithubIssues/resources/issue/index.ts +75 -0
- package/dist/template/templates/declarative/github-issues/template/nodes/GithubIssues/resources/issueComment/getAll.ts +65 -0
- package/dist/template/templates/declarative/github-issues/template/nodes/GithubIssues/resources/issueComment/index.ts +47 -0
- package/dist/template/templates/declarative/github-issues/template/nodes/GithubIssues/shared/descriptions.ts +151 -0
- package/dist/template/templates/declarative/github-issues/template/nodes/GithubIssues/shared/transport.ts +32 -0
- package/dist/template/templates/declarative/github-issues/template/nodes/GithubIssues/shared/utils.ts +14 -0
- package/dist/template/templates/declarative/github-issues/template/package.json +51 -0
- package/dist/template/templates/declarative/github-issues/template/tsconfig.json +25 -0
- package/dist/template/templates/declarative/github-issues/template.d.ts +1 -0
- package/dist/template/templates/declarative/github-issues/template.js +14 -0
- package/dist/template/templates/declarative/github-issues/template.js.map +1 -0
- package/dist/template/templates/declarative/github-issues/template.ts +9 -0
- package/dist/template/templates/index.d.ts +15 -0
- package/dist/template/templates/index.js +28 -0
- package/dist/template/templates/index.js.map +1 -0
- package/dist/template/templates/index.ts +35 -0
- package/dist/template/templates/programmatic/example/template/README.md +46 -0
- package/dist/template/templates/programmatic/example/template/nodes/Example/Example.node.json +18 -0
- package/dist/template/templates/programmatic/example/template/nodes/Example/Example.node.ts +78 -0
- package/dist/template/templates/programmatic/example/template/nodes/Example/example.dark.svg +13 -0
- package/dist/template/templates/programmatic/example/template/nodes/Example/example.svg +13 -0
- package/dist/template/templates/programmatic/example/template/package.json +48 -0
- package/dist/template/templates/programmatic/example/template/tsconfig.json +25 -0
- package/dist/template/templates/programmatic/example/template.d.ts +1 -0
- package/dist/template/templates/programmatic/example/template.js +14 -0
- package/dist/template/templates/programmatic/example/template.js.map +1 -0
- package/dist/template/templates/programmatic/example/template.ts +9 -0
- package/dist/template/templates/shared/credentials/apiKey.credentials.ts +42 -0
- package/dist/template/templates/shared/credentials/basicAuth.credentials.ts +50 -0
- package/dist/template/templates/shared/credentials/bearer.credentials.ts +42 -0
- package/dist/template/templates/shared/credentials/custom.credentials.ts +48 -0
- package/dist/template/templates/shared/credentials/oauth2AuthorizationCode.credentials.ts +51 -0
- package/dist/template/templates/shared/credentials/oauth2ClientCredentials.credentials.ts +45 -0
- package/dist/template/templates/shared/default/.github/workflows/ci.yml +28 -0
- package/dist/template/templates/shared/default/.prettierrc.js +51 -0
- package/dist/template/templates/shared/default/.vscode/launch.json +12 -0
- package/dist/template/templates/shared/default/CHANGELOG.md +0 -0
- package/dist/template/templates/shared/default/eslint.config.mjs +3 -0
- package/dist/utils/ast.d.ts +11 -0
- package/dist/utils/ast.js +32 -0
- package/dist/utils/ast.js.map +1 -0
- package/dist/utils/child-process.d.ts +17 -0
- package/dist/utils/child-process.js +65 -0
- package/dist/utils/child-process.js.map +1 -0
- package/dist/utils/command-suggestions.d.ts +6 -0
- package/dist/utils/command-suggestions.js +30 -0
- package/dist/utils/command-suggestions.js.map +1 -0
- package/dist/utils/filesystem.d.ts +12 -0
- package/dist/utils/filesystem.js +105 -0
- package/dist/utils/filesystem.js.map +1 -0
- package/dist/utils/git.d.ts +7 -0
- package/dist/utils/git.js +36 -0
- package/dist/utils/git.js.map +1 -0
- package/dist/utils/json.d.ts +1 -0
- package/dist/utils/json.js +12 -0
- package/dist/utils/json.js.map +1 -0
- package/dist/utils/package-manager.d.ts +4 -0
- package/dist/utils/package-manager.js +48 -0
- package/dist/utils/package-manager.js.map +1 -0
- package/dist/utils/package.d.ts +15 -0
- package/dist/utils/package.js +53 -0
- package/dist/utils/package.js.map +1 -0
- package/dist/utils/prompts.d.ts +5 -0
- package/dist/utils/prompts.js +65 -0
- package/dist/utils/prompts.js.map +1 -0
- package/dist/utils/validation.d.ts +3 -0
- package/dist/utils/validation.js +23 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.copyTemplateFilesToDestination = copyTemplateFilesToDestination;
|
|
7
|
+
exports.copyDefaultTemplateFilesToDestination = copyDefaultTemplateFilesToDestination;
|
|
8
|
+
exports.templateStaticFiles = templateStaticFiles;
|
|
9
|
+
exports.createTemplate = createTemplate;
|
|
10
|
+
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
11
|
+
const handlebars_1 = __importDefault(require("handlebars"));
|
|
12
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
13
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
14
|
+
const filesystem_1 = require("../utils/filesystem");
|
|
15
|
+
async function copyTemplateFilesToDestination(template, data) {
|
|
16
|
+
await (0, filesystem_1.copyFolder)({
|
|
17
|
+
source: template.path,
|
|
18
|
+
destination: data.destinationPath,
|
|
19
|
+
ignore: ['dist', 'node_modules'],
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
async function copyDefaultTemplateFilesToDestination(data) {
|
|
23
|
+
await (0, filesystem_1.copyFolder)({
|
|
24
|
+
source: node_path_1.default.resolve(__dirname, 'templates/shared/default'),
|
|
25
|
+
destination: data.destinationPath,
|
|
26
|
+
ignore: ['dist', 'node_modules'],
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async function templateStaticFiles(data) {
|
|
30
|
+
const files = await (0, fast_glob_1.default)('**/*.{md,json,yml}', {
|
|
31
|
+
ignore: ['tsconfig.json', 'tsconfig.build.json'],
|
|
32
|
+
cwd: data.destinationPath,
|
|
33
|
+
absolute: true,
|
|
34
|
+
dot: true,
|
|
35
|
+
});
|
|
36
|
+
await Promise.all(files.map(async (file) => {
|
|
37
|
+
const content = await promises_1.default.readFile(file, 'utf-8');
|
|
38
|
+
const newContent = handlebars_1.default.compile(content, { noEscape: true })(data);
|
|
39
|
+
if (newContent !== content) {
|
|
40
|
+
await promises_1.default.writeFile(file, newContent);
|
|
41
|
+
}
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
function createTemplate(template) {
|
|
45
|
+
return {
|
|
46
|
+
...template,
|
|
47
|
+
run: async (data) => {
|
|
48
|
+
await copyDefaultTemplateFilesToDestination(data);
|
|
49
|
+
await copyTemplateFilesToDestination(template, data);
|
|
50
|
+
await templateStaticFiles(data);
|
|
51
|
+
await template.run?.(data);
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/template/core.ts"],"names":[],"mappings":";;;;;AAgCA,wEASC;AAED,sFAMC;AAED,kDAkBC;AAED,wCAYC;AAnFD,0DAA6B;AAC7B,4DAAoC;AACpC,gEAAkC;AAClC,0DAA6B;AAE7B,oDAAiD;AA2B1C,KAAK,UAAU,8BAA8B,CACnD,QAA0B,EAC1B,IAAkB;IAElB,MAAM,IAAA,uBAAU,EAAC;QAChB,MA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ACnB,MAAM,qCAAqC,CAAC,IAAI,CAAC,CAAC;YAClD,MAAM,8BAA8B,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YACrD,MAAM,mBAAmB,CAAC,IAAI,CAAC,CAAC;YAChC,MAAM,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;QAC5B,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare function updateNodeAst({ nodePath, className, baseUrl, }: {
|
|
2
|
+
nodePath: string;
|
|
3
|
+
className: string;
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
}): import("ts-morph").SourceFile;
|
|
6
|
+
export declare function updateCredentialAst({ repoName, baseUrl, credentialPath, credentialName, credentialDisplayName, credentialClassName, }: {
|
|
7
|
+
repoName: string;
|
|
8
|
+
credentialPath: string;
|
|
9
|
+
credentialName: string;
|
|
10
|
+
credentialDisplayName: string;
|
|
11
|
+
credentialClassName: string;
|
|
12
|
+
baseUrl: string;
|
|
13
|
+
}): import("ts-morph").SourceFile;
|
|
14
|
+
export declare function addCredentialToNode({ nodePath, credentialName, }: {
|
|
15
|
+
nodePath: string;
|
|
16
|
+
credentialName: string;
|
|
17
|
+
}): import("ts-morph").SourceFile;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateNodeAst = updateNodeAst;
|
|
4
|
+
exports.updateCredentialAst = updateCredentialAst;
|
|
5
|
+
exports.addCredentialToNode = addCredentialToNode;
|
|
6
|
+
const change_case_1 = require("change-case");
|
|
7
|
+
const ts_morph_1 = require("ts-morph");
|
|
8
|
+
const ast_1 = require("../../../../utils/ast");
|
|
9
|
+
function updateNodeAst({ nodePath, className, baseUrl, }) {
|
|
10
|
+
const sourceFile = (0, ast_1.loadSingleSourceFile)(nodePath);
|
|
11
|
+
const classDecl = sourceFile.getClasses()[0];
|
|
12
|
+
classDecl.rename(className);
|
|
13
|
+
const nodeDescriptionObj = classDecl
|
|
14
|
+
.getPropertyOrThrow('description')
|
|
15
|
+
.getInitializerIfKindOrThrow(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
|
|
16
|
+
(0, ast_1.updateStringProperty)({
|
|
17
|
+
obj: nodeDescriptionObj,
|
|
18
|
+
key: 'displayName',
|
|
19
|
+
value: (0, change_case_1.capitalCase)(className),
|
|
20
|
+
});
|
|
21
|
+
(0, ast_1.updateStringProperty)({
|
|
22
|
+
obj: nodeDescriptionObj,
|
|
23
|
+
key: 'name',
|
|
24
|
+
value: (0, change_case_1.camelCase)(className),
|
|
25
|
+
});
|
|
26
|
+
(0, ast_1.updateStringProperty)({
|
|
27
|
+
obj: nodeDescriptionObj,
|
|
28
|
+
key: 'description',
|
|
29
|
+
value: `Interact with the ${(0, change_case_1.capitalCase)(className)} API`,
|
|
30
|
+
});
|
|
31
|
+
const icon = (0, ast_1.getChildObjectLiteral)({ obj: nodeDescriptionObj, key: 'icon' });
|
|
32
|
+
(0, ast_1.updateStringProperty)({
|
|
33
|
+
obj: icon,
|
|
34
|
+
key: 'light',
|
|
35
|
+
value: `file:${(0, change_case_1.camelCase)(className)}.svg`,
|
|
36
|
+
});
|
|
37
|
+
(0, ast_1.updateStringProperty)({
|
|
38
|
+
obj: icon,
|
|
39
|
+
key: 'dark',
|
|
40
|
+
value: `file:${(0, change_case_1.camelCase)(className)}.dark.svg`,
|
|
41
|
+
});
|
|
42
|
+
const requestDefaults = (0, ast_1.getChildObjectLiteral)({
|
|
43
|
+
obj: nodeDescriptionObj,
|
|
44
|
+
key: 'requestDefaults',
|
|
45
|
+
});
|
|
46
|
+
(0, ast_1.updateStringProperty)({
|
|
47
|
+
obj: requestDefaults,
|
|
48
|
+
key: 'baseURL',
|
|
49
|
+
value: baseUrl,
|
|
50
|
+
});
|
|
51
|
+
const defaults = (0, ast_1.getChildObjectLiteral)({
|
|
52
|
+
obj: nodeDescriptionObj,
|
|
53
|
+
key: 'defaults',
|
|
54
|
+
});
|
|
55
|
+
(0, ast_1.updateStringProperty)({ obj: defaults, key: 'name', value: (0, change_case_1.capitalCase)(className) });
|
|
56
|
+
return sourceFile;
|
|
57
|
+
}
|
|
58
|
+
function updateCredentialAst({ repoName, baseUrl, credentialPath, credentialName, credentialDisplayName, credentialClassName, }) {
|
|
59
|
+
const sourceFile = (0, ast_1.loadSingleSourceFile)(credentialPath);
|
|
60
|
+
const classDecl = sourceFile.getClasses()[0];
|
|
61
|
+
classDecl.rename(credentialClassName);
|
|
62
|
+
(0, ast_1.updateStringProperty)({
|
|
63
|
+
obj: classDecl,
|
|
64
|
+
key: 'displayName',
|
|
65
|
+
value: credentialDisplayName,
|
|
66
|
+
});
|
|
67
|
+
(0, ast_1.updateStringProperty)({
|
|
68
|
+
obj: classDecl,
|
|
69
|
+
key: 'name',
|
|
70
|
+
value: credentialName,
|
|
71
|
+
});
|
|
72
|
+
const docUrlProp = classDecl.getProperty('documentationUrl');
|
|
73
|
+
if (docUrlProp) {
|
|
74
|
+
const initializer = docUrlProp.getInitializerIfKindOrThrow(ts_morph_1.SyntaxKind.StringLiteral);
|
|
75
|
+
const newUrl = initializer.getLiteralText().replace('/repo', `/${repoName}`);
|
|
76
|
+
initializer.setLiteralValue(newUrl);
|
|
77
|
+
}
|
|
78
|
+
const testProperty = classDecl.getProperty('test');
|
|
79
|
+
if (testProperty) {
|
|
80
|
+
const testRequest = testProperty
|
|
81
|
+
.getInitializerIfKindOrThrow(ts_morph_1.SyntaxKind.ObjectLiteralExpression)
|
|
82
|
+
.getPropertyOrThrow('request')
|
|
83
|
+
.asKindOrThrow(ts_morph_1.SyntaxKind.PropertyAssignment)
|
|
84
|
+
.getInitializerIfKindOrThrow(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
|
|
85
|
+
(0, ast_1.updateStringProperty)({
|
|
86
|
+
obj: testRequest,
|
|
87
|
+
key: 'baseURL',
|
|
88
|
+
value: baseUrl,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return sourceFile;
|
|
92
|
+
}
|
|
93
|
+
function addCredentialToNode({ nodePath, credentialName, }) {
|
|
94
|
+
const sourceFile = (0, ast_1.loadSingleSourceFile)(nodePath);
|
|
95
|
+
const classDecl = sourceFile.getClasses()[0];
|
|
96
|
+
const descriptionProp = classDecl
|
|
97
|
+
.getPropertyOrThrow('description')
|
|
98
|
+
.getInitializerIfKindOrThrow(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
|
|
99
|
+
const credentialsProp = descriptionProp.getPropertyOrThrow('credentials');
|
|
100
|
+
if (credentialsProp.getKind() === ts_morph_1.SyntaxKind.PropertyAssignment) {
|
|
101
|
+
const initializer = credentialsProp.getFirstDescendantByKindOrThrow(ts_morph_1.SyntaxKind.ArrayLiteralExpression);
|
|
102
|
+
const credentialObject = ts_morph_1.ts.factory.createObjectLiteralExpression([
|
|
103
|
+
ts_morph_1.ts.factory.createPropertyAssignment(ts_morph_1.ts.factory.createIdentifier('name'), ts_morph_1.ts.factory.createStringLiteral(credentialName, true)),
|
|
104
|
+
ts_morph_1.ts.factory.createPropertyAssignment(ts_morph_1.ts.factory.createIdentifier('required'), ts_morph_1.ts.factory.createTrue()),
|
|
105
|
+
]);
|
|
106
|
+
initializer.addElement((0, ts_morph_1.printNode)(credentialObject));
|
|
107
|
+
}
|
|
108
|
+
return sourceFile;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=ast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.js","sourceRoot":"","sources":["../../../../../src/template/templates/declarative/custom/ast.ts"],"names":[],"mappings":";;AASA,sCA4DC;AAED,kDAwDC;AAED,kDA+BC;AAhKD,6CAAqD;AACrD,uCAAqD;AAErD,+CAI+B;AAE/B,SAAgB,aAAa,CAAC,EAC7B,QAAQ,EACR,SAAS,EACT,OAAO,GACmD;IAC1D,MAAM,UAAU,GAAG,IAAA,0BAAoB,EAAC,QAAQ,CAAC,CA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,aAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC,cAAc,EAAE,IAAI,CAAC,CACpD;YACD,aAAE,CAAC,OAAO,CAAC,wBAAwB,CAClC,aAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,UAAU,CAAC,EACvC,aAAE,CAAC,OAAO,CAAC,UAAU,EAAE,CACvB;SACD,CAAC,CAAC;QACH,WAAW,CAAC,UAAU,CAAC,IAAA,oBAAS,EAAC,gBAAgB,CAAC,CAAC,CAAC;IACrD,CAAC;IAED,OAAO,UAAU,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { camelCase, capitalCase } from 'change-case';
|
|
2
|
+
import { ts, SyntaxKind, printNode } from 'ts-morph';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
getChildObjectLiteral,
|
|
6
|
+
loadSingleSourceFile,
|
|
7
|
+
updateStringProperty,
|
|
8
|
+
} from '../../../../utils/ast';
|
|
9
|
+
|
|
10
|
+
export function updateNodeAst({
|
|
11
|
+
nodePath,
|
|
12
|
+
className,
|
|
13
|
+
baseUrl,
|
|
14
|
+
}: { nodePath: string; className: string; baseUrl: string }) {
|
|
15
|
+
const sourceFile = loadSingleSourceFile(nodePath);
|
|
16
|
+
const classDecl = sourceFile.getClasses()[0];
|
|
17
|
+
|
|
18
|
+
classDecl.rename(className);
|
|
19
|
+
const nodeDescriptionObj = classDecl
|
|
20
|
+
.getPropertyOrThrow('description')
|
|
21
|
+
.getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression);
|
|
22
|
+
|
|
23
|
+
updateStringProperty({
|
|
24
|
+
obj: nodeDescriptionObj,
|
|
25
|
+
key: 'displayName',
|
|
26
|
+
value: capitalCase(className),
|
|
27
|
+
});
|
|
28
|
+
updateStringProperty({
|
|
29
|
+
obj: nodeDescriptionObj,
|
|
30
|
+
key: 'name',
|
|
31
|
+
value: camelCase(className),
|
|
32
|
+
});
|
|
33
|
+
updateStringProperty({
|
|
34
|
+
obj: nodeDescriptionObj,
|
|
35
|
+
key: 'description',
|
|
36
|
+
value: `Interact with the ${capitalCase(className)} API`,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const icon = getChildObjectLiteral({ obj: nodeDescriptionObj, key: 'icon' });
|
|
40
|
+
updateStringProperty({
|
|
41
|
+
obj: icon,
|
|
42
|
+
key: 'light',
|
|
43
|
+
value: `file:${camelCase(className)}.svg`,
|
|
44
|
+
});
|
|
45
|
+
updateStringProperty({
|
|
46
|
+
obj: icon,
|
|
47
|
+
key: 'dark',
|
|
48
|
+
value: `file:${camelCase(className)}.dark.svg`,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const requestDefaults = getChildObjectLiteral({
|
|
52
|
+
obj: nodeDescriptionObj,
|
|
53
|
+
key: 'requestDefaults',
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
updateStringProperty({
|
|
57
|
+
obj: requestDefaults,
|
|
58
|
+
key: 'baseURL',
|
|
59
|
+
value: baseUrl,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const defaults = getChildObjectLiteral({
|
|
63
|
+
obj: nodeDescriptionObj,
|
|
64
|
+
key: 'defaults',
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
updateStringProperty({ obj: defaults, key: 'name', value: capitalCase(className) });
|
|
68
|
+
|
|
69
|
+
return sourceFile;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function updateCredentialAst({
|
|
73
|
+
repoName,
|
|
74
|
+
baseUrl,
|
|
75
|
+
credentialPath,
|
|
76
|
+
credentialName,
|
|
77
|
+
credentialDisplayName,
|
|
78
|
+
credentialClassName,
|
|
79
|
+
}: {
|
|
80
|
+
repoName: string;
|
|
81
|
+
credentialPath: string;
|
|
82
|
+
credentialName: string;
|
|
83
|
+
credentialDisplayName: string;
|
|
84
|
+
credentialClassName: string;
|
|
85
|
+
baseUrl: string;
|
|
86
|
+
}) {
|
|
87
|
+
const sourceFile = loadSingleSourceFile(credentialPath);
|
|
88
|
+
const classDecl = sourceFile.getClasses()[0];
|
|
89
|
+
|
|
90
|
+
classDecl.rename(credentialClassName);
|
|
91
|
+
|
|
92
|
+
updateStringProperty({
|
|
93
|
+
obj: classDecl,
|
|
94
|
+
key: 'displayName',
|
|
95
|
+
value: credentialDisplayName,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
updateStringProperty({
|
|
99
|
+
obj: classDecl,
|
|
100
|
+
key: 'name',
|
|
101
|
+
value: credentialName,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const docUrlProp = classDecl.getProperty('documentationUrl');
|
|
105
|
+
if (docUrlProp) {
|
|
106
|
+
const initializer = docUrlProp.getInitializerIfKindOrThrow(SyntaxKind.StringLiteral);
|
|
107
|
+
const newUrl = initializer.getLiteralText().replace('/repo', `/${repoName}`);
|
|
108
|
+
initializer.setLiteralValue(newUrl);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const testProperty = classDecl.getProperty('test');
|
|
112
|
+
|
|
113
|
+
if (testProperty) {
|
|
114
|
+
const testRequest = testProperty
|
|
115
|
+
.getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression)
|
|
116
|
+
.getPropertyOrThrow('request')
|
|
117
|
+
.asKindOrThrow(SyntaxKind.PropertyAssignment)
|
|
118
|
+
.getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression);
|
|
119
|
+
|
|
120
|
+
updateStringProperty({
|
|
121
|
+
obj: testRequest,
|
|
122
|
+
key: 'baseURL',
|
|
123
|
+
value: baseUrl,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return sourceFile;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function addCredentialToNode({
|
|
131
|
+
nodePath,
|
|
132
|
+
credentialName,
|
|
133
|
+
}: { nodePath: string; credentialName: string }) {
|
|
134
|
+
const sourceFile = loadSingleSourceFile(nodePath);
|
|
135
|
+
const classDecl = sourceFile.getClasses()[0];
|
|
136
|
+
|
|
137
|
+
const descriptionProp = classDecl
|
|
138
|
+
.getPropertyOrThrow('description')
|
|
139
|
+
.getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression);
|
|
140
|
+
|
|
141
|
+
const credentialsProp = descriptionProp.getPropertyOrThrow('credentials');
|
|
142
|
+
|
|
143
|
+
if (credentialsProp.getKind() === SyntaxKind.PropertyAssignment) {
|
|
144
|
+
const initializer = credentialsProp.getFirstDescendantByKindOrThrow(
|
|
145
|
+
SyntaxKind.ArrayLiteralExpression,
|
|
146
|
+
);
|
|
147
|
+
const credentialObject = ts.factory.createObjectLiteralExpression([
|
|
148
|
+
ts.factory.createPropertyAssignment(
|
|
149
|
+
ts.factory.createIdentifier('name'),
|
|
150
|
+
ts.factory.createStringLiteral(credentialName, true),
|
|
151
|
+
),
|
|
152
|
+
ts.factory.createPropertyAssignment(
|
|
153
|
+
ts.factory.createIdentifier('required'),
|
|
154
|
+
ts.factory.createTrue(),
|
|
155
|
+
),
|
|
156
|
+
]);
|
|
157
|
+
initializer.addElement(printNode(credentialObject));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return sourceFile;
|
|
161
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const credentialTypePrompt: () => Promise<"custom" | "apiKey" | "bearer" | "basicAuth" | "none" | "oauth2">;
|
|
2
|
+
export declare const baseUrlPrompt: () => Promise<string>;
|
|
3
|
+
export declare const oauthFlowPrompt: () => Promise<"clientCredentials" | "authorizationCode">;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.oauthFlowPrompt = exports.baseUrlPrompt = exports.credentialTypePrompt = void 0;
|
|
4
|
+
const prompts_1 = require("@clack/prompts");
|
|
5
|
+
const prompts_2 = require("../../../../utils/prompts");
|
|
6
|
+
const credentialTypePrompt = async () => await (0, prompts_2.withCancelHandler)((0, prompts_1.select)({
|
|
7
|
+
message: 'What type of authentication does your API use?',
|
|
8
|
+
options: [
|
|
9
|
+
{
|
|
10
|
+
label: 'API Key',
|
|
11
|
+
value: 'apiKey',
|
|
12
|
+
hint: 'Send a secret key via headers, query, or body',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
label: 'Bearer Token',
|
|
16
|
+
value: 'bearer',
|
|
17
|
+
hint: 'Send a token via Authorization header (Authorization: Bearer <token>)',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
label: 'OAuth2',
|
|
21
|
+
value: 'oauth2',
|
|
22
|
+
hint: 'Use an OAuth 2.0 flow to obtain access tokens on behalf of a user or app',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
label: 'Basic Auth',
|
|
26
|
+
value: 'basicAuth',
|
|
27
|
+
hint: 'Send username and password encoded in base64 via the Authorization header',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
label: 'Custom',
|
|
31
|
+
value: 'custom',
|
|
32
|
+
hint: 'Create your own credential logic; an empty credential class will be scaffolded for you',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
label: 'None',
|
|
36
|
+
value: 'none',
|
|
37
|
+
hint: 'No authentication; no credential class will be generated',
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
initialValue: 'apiKey',
|
|
41
|
+
}));
|
|
42
|
+
exports.credentialTypePrompt = credentialTypePrompt;
|
|
43
|
+
const baseUrlPrompt = async () => await (0, prompts_2.withCancelHandler)((0, prompts_1.text)({
|
|
44
|
+
message: "What's the base URL of the API?",
|
|
45
|
+
placeholder: 'https://api.example.com/v2',
|
|
46
|
+
defaultValue: 'https://api.example.com/v2',
|
|
47
|
+
validate: (value) => {
|
|
48
|
+
if (!value)
|
|
49
|
+
return;
|
|
50
|
+
if (!value.startsWith('https://') && !value.startsWith('http://')) {
|
|
51
|
+
return 'Base URL must start with http(s)://';
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
new URL(value);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
return 'Must be a valid URL';
|
|
58
|
+
}
|
|
59
|
+
return;
|
|
60
|
+
},
|
|
61
|
+
}));
|
|
62
|
+
exports.baseUrlPrompt = baseUrlPrompt;
|
|
63
|
+
const oauthFlowPrompt = async () => await (0, prompts_2.withCancelHandler)((0, prompts_1.select)({
|
|
64
|
+
message: 'What OAuth2 flow does your API use?',
|
|
65
|
+
options: [
|
|
66
|
+
{
|
|
67
|
+
label: 'Authorization code',
|
|
68
|
+
value: 'authorizationCode',
|
|
69
|
+
hint: 'Users log in and approve access (use this if unsure)',
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
label: 'Client credentials',
|
|
73
|
+
value: 'clientCredentials',
|
|
74
|
+
hint: 'Server-to-server auth without user interaction',
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
initialValue: 'authorizationCode',
|
|
78
|
+
}));
|
|
79
|
+
exports.oauthFlowPrompt = oauthFlowPrompt;
|
|
80
|
+
//# sourceMappingURL=prompts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../../../../src/template/templates/declarative/custom/prompts.ts"],"names":[],"mappings":";;;AAAA,4CAA8C;AAG9C,uDAA8D;AAEvD,MAAM,oBAAoB,GAAG,KAAK,IAAI,EAAE,CAC9C,MAAM,IAAA,2BAAiB,EACtB,IAAA,gBAAM,EAAiB;IACtB,OAAO,EAAE,gDAAgD;IACzD,OAAO,EAAE;QACR;YACC,KAAK,EAAE,SAAS;YAChB,KAAK,EAAE,QAAQ;YACf,IAAI,EAAE,+CAA+C;SACrD;QACD;YACC,KAAK,EAAE,cAAc;YACrB,KAAK,EAAE,QAAQ;YACf,IAAI,EAAE,uEAAuE;SAC7E;QACD;YACC,KAAK,EAAE,QAAQ;YACf,KAAK,EAAE,QAAQ;YACf,IAAI,EAAE,0EAA0E;SAChF;QACD;YACC,KAA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;YAC1B,IAAI,EAAE,gDAAgD;SACtD;KACD;IACD,YAAY,EAAE,mBAAmB;CACjC,CAAC,CACF,CAAC;AAlBU,QAAA,eAAe,mBAkBzB"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { select, text } from '@clack/prompts';
|
|
2
|
+
|
|
3
|
+
import type { CredentialType } from './types';
|
|
4
|
+
import { withCancelHandler } from '../../../../utils/prompts';
|
|
5
|
+
|
|
6
|
+
export const credentialTypePrompt = async () =>
|
|
7
|
+
await withCancelHandler(
|
|
8
|
+
select<CredentialType>({
|
|
9
|
+
message: 'What type of authentication does your API use?',
|
|
10
|
+
options: [
|
|
11
|
+
{
|
|
12
|
+
label: 'API Key',
|
|
13
|
+
value: 'apiKey',
|
|
14
|
+
hint: 'Send a secret key via headers, query, or body',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
label: 'Bearer Token',
|
|
18
|
+
value: 'bearer',
|
|
19
|
+
hint: 'Send a token via Authorization header (Authorization: Bearer <token>)',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
label: 'OAuth2',
|
|
23
|
+
value: 'oauth2',
|
|
24
|
+
hint: 'Use an OAuth 2.0 flow to obtain access tokens on behalf of a user or app',
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
label: 'Basic Auth',
|
|
28
|
+
value: 'basicAuth',
|
|
29
|
+
hint: 'Send username and password encoded in base64 via the Authorization header',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
label: 'Custom',
|
|
33
|
+
value: 'custom',
|
|
34
|
+
hint: 'Create your own credential logic; an empty credential class will be scaffolded for you',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
label: 'None',
|
|
38
|
+
value: 'none',
|
|
39
|
+
hint: 'No authentication; no credential class will be generated',
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
initialValue: 'apiKey',
|
|
43
|
+
}),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
export const baseUrlPrompt = async () =>
|
|
47
|
+
await withCancelHandler(
|
|
48
|
+
text({
|
|
49
|
+
message: "What's the base URL of the API?",
|
|
50
|
+
placeholder: 'https://api.example.com/v2',
|
|
51
|
+
defaultValue: 'https://api.example.com/v2',
|
|
52
|
+
validate: (value) => {
|
|
53
|
+
if (!value) return;
|
|
54
|
+
|
|
55
|
+
if (!value.startsWith('https://') && !value.startsWith('http://')) {
|
|
56
|
+
return 'Base URL must start with http(s)://';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
new URL(value);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
return 'Must be a valid URL';
|
|
63
|
+
}
|
|
64
|
+
return;
|
|
65
|
+
},
|
|
66
|
+
}),
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
export const oauthFlowPrompt = async () =>
|
|
70
|
+
await withCancelHandler(
|
|
71
|
+
select<'clientCredentials' | 'authorizationCode'>({
|
|
72
|
+
message: 'What OAuth2 flow does your API use?',
|
|
73
|
+
options: [
|
|
74
|
+
{
|
|
75
|
+
label: 'Authorization code',
|
|
76
|
+
value: 'authorizationCode',
|
|
77
|
+
hint: 'Users log in and approve access (use this if unsure)',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
label: 'Client credentials',
|
|
81
|
+
value: 'clientCredentials',
|
|
82
|
+
hint: 'Server-to-server auth without user interaction',
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
initialValue: 'authorizationCode',
|
|
86
|
+
}),
|
|
87
|
+
);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# {{nodePackageName}}
|
|
2
|
+
|
|
3
|
+
This is an n8n community node. It lets you use _app/service name_ in your n8n workflows.
|
|
4
|
+
|
|
5
|
+
_App/service name_ is _one or two sentences describing the service this node integrates with_.
|
|
6
|
+
|
|
7
|
+
[n8n](https://n8n.io/) is a [fair-code licensed](https://docs.n8n.io/sustainable-use-license/) workflow automation platform.
|
|
8
|
+
|
|
9
|
+
[Installation](#installation)
|
|
10
|
+
[Operations](#operations)
|
|
11
|
+
[Credentials](#credentials)
|
|
12
|
+
[Compatibility](#compatibility)
|
|
13
|
+
[Usage](#usage)
|
|
14
|
+
[Resources](#resources)
|
|
15
|
+
[Version history](#version-history)
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Follow the [installation guide](https://docs.n8n.io/integrations/community-nodes/installation/) in the n8n community nodes documentation.
|
|
20
|
+
|
|
21
|
+
## Operations
|
|
22
|
+
|
|
23
|
+
_List the operations supported by your node._
|
|
24
|
+
|
|
25
|
+
## Credentials
|
|
26
|
+
|
|
27
|
+
_If users need to authenticate with the app/service, provide details here. You should include prerequisites (such as signing up with the service), available authentication methods, and how to set them up._
|
|
28
|
+
|
|
29
|
+
## Compatibility
|
|
30
|
+
|
|
31
|
+
_State the minimum n8n version, as well as which versions you test against. You can also include any known version incompatibility issues._
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
_This is an optional section. Use it to help users with any difficult or confusing aspects of the node._
|
|
36
|
+
|
|
37
|
+
_By the time users are looking for community nodes, they probably already know n8n basics. But if you expect new users, you can link to the [Try it out](https://docs.n8n.io/try-it-out/) documentation to help them get started._
|
|
38
|
+
|
|
39
|
+
## Resources
|
|
40
|
+
|
|
41
|
+
* [n8n community nodes documentation](https://docs.n8n.io/integrations/#community-nodes)
|
|
42
|
+
* _Link to app/service documentation._
|
|
43
|
+
|
|
44
|
+
## Version history
|
|
45
|
+
|
|
46
|
+
_This is another optional section. If your node has multiple versions, include a short description of available versions and what changed, as well as any compatibility impact._
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"node": "{{nodePackageName}}",
|
|
3
|
+
"nodeVersion": "1.0",
|
|
4
|
+
"codexVersion": "1.0",
|
|
5
|
+
"categories": ["Development", "Developer Tools"],
|
|
6
|
+
"resources": {
|
|
7
|
+
"credentialDocumentation": [
|
|
8
|
+
{
|
|
9
|
+
"url": "https://github.com/org/repo?tab=readme-ov-file#credentials"
|
|
10
|
+
}
|
|
11
|
+
],
|
|
12
|
+
"primaryDocumentation": [
|
|
13
|
+
{
|
|
14
|
+
"url": "https://github.com/org/repo?tab=readme-ov-file"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { NodeConnectionTypes, type INodeType, type INodeTypeDescription } from 'n8n-workflow';
|
|
2
|
+
import { userDescription } from './resources/user';
|
|
3
|
+
import { companyDescription } from './resources/company';
|
|
4
|
+
|
|
5
|
+
export class Example implements INodeType {
|
|
6
|
+
description: INodeTypeDescription = {
|
|
7
|
+
displayName: 'Example',
|
|
8
|
+
name: 'example',
|
|
9
|
+
icon: { light: 'file:example.svg', dark: 'file:example.dark.svg' },
|
|
10
|
+
group: ['transform'],
|
|
11
|
+
version: 1,
|
|
12
|
+
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
13
|
+
description: 'Interact with the Example API',
|
|
14
|
+
defaults: {
|
|
15
|
+
name: 'Example',
|
|
16
|
+
},
|
|
17
|
+
usableAsTool: true,
|
|
18
|
+
inputs: [NodeConnectionTypes.Main],
|
|
19
|
+
outputs: [NodeConnectionTypes.Main],
|
|
20
|
+
credentials: [],
|
|
21
|
+
requestDefaults: {
|
|
22
|
+
baseURL: 'https://api.example.com',
|
|
23
|
+
headers: {
|
|
24
|
+
Accept: 'application/json',
|
|
25
|
+
'Content-Type': 'application/json',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
properties: [
|
|
29
|
+
{
|
|
30
|
+
displayName: 'Resource',
|
|
31
|
+
name: 'resource',
|
|
32
|
+
type: 'options',
|
|
33
|
+
noDataExpression: true,
|
|
34
|
+
options: [
|
|
35
|
+
{
|
|
36
|
+
name: 'User',
|
|
37
|
+
value: 'user',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'Company',
|
|
41
|
+
value: 'company',
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
default: 'user',
|
|
45
|
+
},
|
|
46
|
+
...userDescription,
|
|
47
|
+
...companyDescription,
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="aquamarine"
|
|
2
|
+
stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-cpu">
|
|
3
|
+
<rect x="4" y="4" width="16" height="16" rx="2" ry="2"></rect>
|
|
4
|
+
<rect x="9" y="9" width="6" height="6"></rect>
|
|
5
|
+
<line x1="9" y1="1" x2="9" y2="4"></line>
|
|
6
|
+
<line x1="15" y1="1" x2="15" y2="4"></line>
|
|
7
|
+
<line x1="9" y1="20" x2="9" y2="23"></line>
|
|
8
|
+
<line x1="15" y1="20" x2="15" y2="23"></line>
|
|
9
|
+
<line x1="20" y1="9" x2="23" y2="9"></line>
|
|
10
|
+
<line x1="20" y1="14" x2="23" y2="14"></line>
|
|
11
|
+
<line x1="1" y1="9" x2="4" y2="9"></line>
|
|
12
|
+
<line x1="1" y1="14" x2="4" y2="14"></line>
|
|
13
|
+
</svg>
|