@constructor-io/constructorio-connect-cli 1.1.2 → 1.3.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 +26 -0
- package/boilerplate-repo/README.md +29 -0
- package/boilerplate-repo/package.json +2 -1
- package/dist/commands/execute.d.ts.map +1 -1
- package/dist/commands/execute.js +7 -1
- package/dist/commands/generate-fixture.d.ts +9 -0
- package/dist/commands/generate-fixture.d.ts.map +1 -0
- package/dist/commands/generate-fixture.js +77 -0
- package/dist/helpers/file-exists.d.ts +7 -0
- package/dist/helpers/file-exists.d.ts.map +1 -0
- package/dist/helpers/file-exists.js +20 -0
- package/dist/helpers/file-loaders.d.ts +0 -3
- package/dist/helpers/file-loaders.d.ts.map +1 -1
- package/dist/helpers/file-loaders.js +1 -5
- package/dist/http/get-fixture.d.ts +11 -0
- package/dist/http/get-fixture.d.ts.map +1 -0
- package/dist/http/get-fixture.js +29 -0
- package/dist/prompt-data/get-candidate-fixtures.d.ts.map +1 -1
- package/dist/prompt-data/get-candidate-fixtures.js +13 -3
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +9 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/oclif.manifest.json +24 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -25,6 +25,7 @@ This package can be installed via npm: `npm i @constructor-io/constructorio-conn
|
|
|
25
25
|
<!-- commands -->
|
|
26
26
|
* [`constructorio-connect-cli deploy ENV`](#constructorio-connect-cli-deploy-env)
|
|
27
27
|
* [`constructorio-connect-cli execute`](#constructorio-connect-cli-execute)
|
|
28
|
+
* [`constructorio-connect-cli generate-fixture`](#constructorio-connect-cli-generate-fixture)
|
|
28
29
|
* [`constructorio-connect-cli help [COMMAND]`](#constructorio-connect-cli-help-command)
|
|
29
30
|
* [`constructorio-connect-cli init NAME`](#constructorio-connect-cli-init-name)
|
|
30
31
|
|
|
@@ -90,6 +91,31 @@ EXAMPLES
|
|
|
90
91
|
```
|
|
91
92
|
|
|
92
93
|
|
|
94
|
+
## `constructorio-connect-cli generate-fixture`
|
|
95
|
+
|
|
96
|
+
This command will fetch one fixture from the server and save it into a specified file. This fixture file will be an example of how the data would be passed to the connector when executing the templates.
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
USAGE
|
|
100
|
+
$ constructorio-connect-cli generate-fixture
|
|
101
|
+
|
|
102
|
+
DESCRIPTION
|
|
103
|
+
|
|
104
|
+
This command will fetch one fixture from the server and save it into a specified file. This fixture file will be an
|
|
105
|
+
example of how the data would be passed to the connector when executing the templates.
|
|
106
|
+
|
|
107
|
+
You are expected to customize this file to match the data you expect to cover in a template execution (e.g. an item
|
|
108
|
+
with stock, a variation with missing data), etc. Note that you can have multiple fixtures of the same type to cover
|
|
109
|
+
different scenarios.
|
|
110
|
+
|
|
111
|
+
Finally, if the file already exists you'll be prompted to overwrite it.
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
EXAMPLES
|
|
115
|
+
$ constructorio-connect-cli generate-fixture
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
|
|
93
119
|
## `constructorio-connect-cli help [COMMAND]`
|
|
94
120
|
|
|
95
121
|
Display help for constructorio-connect-cli.
|
|
@@ -54,6 +54,35 @@ With that configured, visit the `connectrc.js` file. This is where you can descr
|
|
|
54
54
|
|
|
55
55
|
An example with a single placeholder connection ID is provided in the `connectrc.js` by default. Replacing the example with your connection ID(s) and adjusting the example template source code according to your needs is the quickest way to get a set of working templates.
|
|
56
56
|
|
|
57
|
+
# Generate Fixture
|
|
58
|
+
|
|
59
|
+
Once you have written some templates and you would like to quickly test their output, you can use the `generate-fixture` command. This command will create a new fixture file based in your connection and the type.
|
|
60
|
+
|
|
61
|
+
This file serves as an example of how the data would be passed to the connector when executing the templates. You're expected to customize this file to match the data you expect to cover in a template execution. If the file already exists, you'll be prompted to overwrite it.
|
|
62
|
+
|
|
63
|
+
In summary, this command is a crucial part of testing your templates on the Constructor Connect platform. It allows you to generate test data, customize it to your needs, and see how your templates will handle it.
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
## `npm run generate-fixture`
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
USAGE
|
|
70
|
+
$ constructorio-connect-cli generate-fixture
|
|
71
|
+
|
|
72
|
+
DESCRIPTION
|
|
73
|
+
|
|
74
|
+
This command will fetch one fixture from the server and save it into a specified file. This fixture file will be an example of how the data would be passed to the connector when executing the templates.
|
|
75
|
+
|
|
76
|
+
You are expected to customize this file to match the data you expect to cover in a template execution (e.g. an item with stock, a variation with missing data), etc. Note that you can have multiple fixtures of the same type to cover different
|
|
77
|
+
scenarios.
|
|
78
|
+
|
|
79
|
+
Finally, if the file already exists you'll be prompted to overwrite it.
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
EXAMPLES
|
|
83
|
+
$ constructorio-connect-cli generate-fixtures
|
|
84
|
+
```
|
|
85
|
+
|
|
57
86
|
# Executing Templates
|
|
58
87
|
|
|
59
88
|
Once you have written some templates and you would like to quickly test their output, you can use the `execute` command. This command will allow you to see the result of executing your template against a specific fixture of JSON catalog data.
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
"lint": "eslint . --ext .js",
|
|
8
8
|
"lint:fix": "eslint . --ext .js --fix",
|
|
9
9
|
"execute": "constructorio-connect-cli execute",
|
|
10
|
-
"deploy": "constructorio-connect-cli deploy"
|
|
10
|
+
"deploy": "constructorio-connect-cli deploy",
|
|
11
|
+
"generate-fixture": "constructorio-connect-cli generate-fixture"
|
|
11
12
|
},
|
|
12
13
|
"devDependencies": {
|
|
13
14
|
"eslint": "^8.47.0",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../src/commands/execute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,OAAO,EAAM,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../src/commands/execute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,OAAO,EAAM,MAAM,aAAa,CAAC;AA6BjD,eAAO,MAAM,qBAAqB;;;;;CAKxB,CAAC;AAEX;;;GAGG;AACH,UAAU,iBAAiB;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAYD,qBAAa,OAAQ,SAAQ,OAAO;IAClC,MAAM,CAAC,KAAK;;;;;MAgBV;IAEF,MAAM,CAAC,WAAW,SACkK;IAEpL,MAAM,CAAC,QAAQ,WAOb;IAEF,KAAK,EAAE,iBAAiB,CAAM;IAExB,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;YAoCZ,UAAU;YAsBV,oBAAoB;YA6CpB,qBAAqB;YA0BrB,wBAAwB;CAevC"}
|
package/dist/commands/execute.js
CHANGED
|
@@ -14,6 +14,9 @@ const render_prompt_1 = require("../prompt-data/render-prompt");
|
|
|
14
14
|
const render_repeat_input_1 = require("../rendering/render-repeat-input");
|
|
15
15
|
const render_template_result_1 = require("../rendering/render-template-result");
|
|
16
16
|
const path_1 = require("../customer/path");
|
|
17
|
+
const config_1 = require("../customer/config");
|
|
18
|
+
const template_source_code_1 = require("../customer/template-source-code");
|
|
19
|
+
const ux_action_1 = require("../helpers/ux-action");
|
|
17
20
|
exports.executePromptMessages = {
|
|
18
21
|
template: "Select a template to execute",
|
|
19
22
|
fixture: "Select a catalog fixture to run the template against",
|
|
@@ -49,10 +52,13 @@ class Execute extends core_1.Command {
|
|
|
49
52
|
let result = null;
|
|
50
53
|
try {
|
|
51
54
|
const templateInput = await this.getTemplateExecInput();
|
|
55
|
+
const config = await (0, ux_action_1.uxAction)("📡 Reading your config", async () => {
|
|
56
|
+
return await (0, config_1.getRepositoryConfigFile)();
|
|
57
|
+
})();
|
|
52
58
|
core_1.ux.log("\n");
|
|
53
59
|
result = await (0, execute_templates_request_1.executeTemplates)({
|
|
54
60
|
template: (0, file_loaders_1.getJSONataTemplate)(templateInput.templatePath, "utf-8").toString(),
|
|
55
|
-
helpers: (0,
|
|
61
|
+
helpers: (await (0, template_source_code_1.getHelpersSourceCode)(config.helpers)) ?? "",
|
|
56
62
|
targetData: (0, file_loaders_1.getCatalogFixture)(templateInput.fixturePath),
|
|
57
63
|
externalData: templateInput.externalDataPath
|
|
58
64
|
? (0, file_loaders_1.getExternalDataFixture)(templateInput.externalDataPath)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
export default class GenerateFixture extends Command {
|
|
3
|
+
static args: {};
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
run(): Promise<any>;
|
|
7
|
+
getFixturePath(type: string, filename: string): string;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=generate-fixture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-fixture.d.ts","sourceRoot":"","sources":["../../src/commands/generate-fixture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAM,MAAM,aAAa,CAAC;AAa1C,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,OAAO;IAClD,MAAM,CAAC,IAAI,KAAM;IAEjB,MAAM,CAAC,WAAW,SAIhB;IAEF,MAAM,CAAC,QAAQ,WAA4C;IAErD,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC;IA6DzB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAK9C"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
|
+
const fs_extra_1 = require("fs-extra");
|
|
5
|
+
const prompts_1 = require("@inquirer/prompts");
|
|
6
|
+
const ux_action_1 = require("../helpers/ux-action");
|
|
7
|
+
const render_tip_1 = require("../rendering/render-tip");
|
|
8
|
+
const render_prompt_1 = require("../prompt-data/render-prompt");
|
|
9
|
+
const types_1 = require("../types");
|
|
10
|
+
const get_fixture_1 = require("../http/get-fixture");
|
|
11
|
+
const get_connections_request_1 = require("../http/get-connections-request");
|
|
12
|
+
const file_exists_1 = require("../helpers/file-exists");
|
|
13
|
+
const path_1 = require("../customer/path");
|
|
14
|
+
class GenerateFixture extends core_1.Command {
|
|
15
|
+
static args = {};
|
|
16
|
+
static description = `
|
|
17
|
+
This command will fetch one fixture from the server and save it into a specified file. This fixture file will be an example of how the data would be passed to the connector when executing the templates.\n
|
|
18
|
+
You are expected to customize this file to match the data you expect to cover in a template execution (e.g. an item with stock, a variation with missing data), etc. Note that you can have multiple fixtures of the same type to cover different scenarios.\n
|
|
19
|
+
Finally, if the file already exists you'll be prompted to overwrite it.
|
|
20
|
+
`;
|
|
21
|
+
static examples = ["$ <%= config.bin %> generate-fixture"];
|
|
22
|
+
async run() {
|
|
23
|
+
const connections = await (0, ux_action_1.uxAction)("📡 Reading your connections...", async () => {
|
|
24
|
+
return await (0, get_connections_request_1.getConnectionsForCompany)();
|
|
25
|
+
})();
|
|
26
|
+
const connectionId = await (0, render_prompt_1.renderPrompt)({
|
|
27
|
+
promptMessage: "Choose the connection to generate the fixture for",
|
|
28
|
+
choices: connections.map((connection) => ({
|
|
29
|
+
name: `[${connection.environment}] - ${connection.name} `,
|
|
30
|
+
value: connection.id,
|
|
31
|
+
})),
|
|
32
|
+
});
|
|
33
|
+
const type = await (0, render_prompt_1.renderPrompt)({
|
|
34
|
+
promptMessage: "Choose the type of fixture you want to generate",
|
|
35
|
+
choices: Object.keys(types_1.CatalogFixtureType).map((catalogFixtureType) => ({
|
|
36
|
+
name: catalogFixtureType,
|
|
37
|
+
value: Object(types_1.CatalogFixtureType)[catalogFixtureType],
|
|
38
|
+
})),
|
|
39
|
+
});
|
|
40
|
+
const filename = await (0, prompts_1.input)({
|
|
41
|
+
message: "Enter the filename",
|
|
42
|
+
default: `${type}.json`,
|
|
43
|
+
});
|
|
44
|
+
const filepath = this.getFixturePath(type, filename);
|
|
45
|
+
const shouldAskReplace = (0, file_exists_1.fileExists)(filepath, true);
|
|
46
|
+
if (shouldAskReplace) {
|
|
47
|
+
const shouldRefresh = await (0, prompts_1.confirm)({
|
|
48
|
+
message: `This fixture already exists. Do you want to refresh it?`,
|
|
49
|
+
default: false,
|
|
50
|
+
});
|
|
51
|
+
if (!shouldRefresh) {
|
|
52
|
+
(0, render_tip_1.renderTip)([
|
|
53
|
+
"Your file was not refreshed!",
|
|
54
|
+
"If you want to generate the fixture, please execute the command again",
|
|
55
|
+
]);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
await (0, ux_action_1.uxAction)("🧶 Generating fixtures...", async () => {
|
|
61
|
+
const response = await (0, get_fixture_1.getFixture)({
|
|
62
|
+
connectionId,
|
|
63
|
+
type: type,
|
|
64
|
+
});
|
|
65
|
+
await (0, fs_extra_1.outputFile)(filepath, JSON.stringify(response.data, null, 2));
|
|
66
|
+
})();
|
|
67
|
+
core_1.ux.info(`🎉 ${type} fixture generated at ${filepath}`);
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
core_1.ux.error(`🙈 ${err.message}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
getFixturePath(type, filename) {
|
|
74
|
+
return (0, path_1.getCustomerPath)(`src/fixtures/${type}/${filename.replace(/\.[^/.]+$/, "")}.json`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.default = GenerateFixture;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns true if the file exists, false otherwise
|
|
3
|
+
* @param filepath The path of the file you want to check
|
|
4
|
+
* @returns boolean
|
|
5
|
+
*/
|
|
6
|
+
export declare function fileExists(filepath: string, isCustomerPath?: boolean): boolean;
|
|
7
|
+
//# sourceMappingURL=file-exists.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-exists.d.ts","sourceRoot":"","sources":["../../src/helpers/file-exists.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,UAAQ,GAAG,OAAO,CAO5E"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fileExists = void 0;
|
|
4
|
+
const fs_extra_1 = require("fs-extra");
|
|
5
|
+
const path_1 = require("../customer/path");
|
|
6
|
+
/**
|
|
7
|
+
* Returns true if the file exists, false otherwise
|
|
8
|
+
* @param filepath The path of the file you want to check
|
|
9
|
+
* @returns boolean
|
|
10
|
+
*/
|
|
11
|
+
function fileExists(filepath, isCustomerPath = false) {
|
|
12
|
+
const fullpath = isCustomerPath ? filepath : (0, path_1.getCustomerPath)(filepath);
|
|
13
|
+
try {
|
|
14
|
+
return (0, fs_extra_1.existsSync)(fullpath);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.fileExists = fileExists;
|
|
@@ -6,9 +6,6 @@ export declare const getExternalDataFixture: (name: string, options?: fs.JsonRea
|
|
|
6
6
|
export declare const getJSONataTemplate: (name: string, options?: BufferEncoding | (fs.ObjectEncodingOptions & {
|
|
7
7
|
flag?: string | undefined;
|
|
8
8
|
}) | null | undefined) => string | Buffer;
|
|
9
|
-
export declare const getTemplateHelpers: (name: string, options?: BufferEncoding | (fs.ObjectEncodingOptions & {
|
|
10
|
-
flag?: string | undefined;
|
|
11
|
-
}) | null | undefined) => string | Buffer;
|
|
12
9
|
export declare function createFileLoader<T, S extends any[]>({ prefix, fileLoader, suggestions, }: Args<T, S>): (name: string, ...args: S) => T;
|
|
13
10
|
interface Args<T, S extends any[]> {
|
|
14
11
|
prefix: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-loaders.d.ts","sourceRoot":"","sources":["../../src/helpers/file-loaders.ts"],"names":[],"mappings":";;AAGA,OAAO,EAAE,MAAM,UAAU,CAAC;AAI1B,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"file-loaders.d.ts","sourceRoot":"","sources":["../../src/helpers/file-loaders.ts"],"names":[],"mappings":";;AAGA,OAAO,EAAE,MAAM,UAAU,CAAC;AAI1B,eAAO,MAAM,iBAAiB,SAqBP,MAAM,sCAjB3B,CAAC;AAEH,eAAO,MAAM,sBAAsB,SAeZ,MAAM,sCAX3B,CAAC;AAEH,eAAO,MAAM,kBAAkB,SASR,MAAM;;yCAN3B,CAAC;AAEH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,CAAC,SAAS,GAAG,EAAE,EAAE,EACnD,MAAM,EACN,UAAU,EACV,WAAgB,GACjB,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,CAc9C;AAED,UAAU,IAAI,CAAC,CAAC,EAAE,CAAC,SAAS,GAAG,EAAE;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC;IAC9C,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB"}
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createFileLoader = exports.
|
|
6
|
+
exports.createFileLoader = exports.getJSONataTemplate = exports.getExternalDataFixture = exports.getCatalogFixture = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const errors_1 = require("@oclif/core/lib/errors");
|
|
9
9
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
@@ -22,10 +22,6 @@ exports.getJSONataTemplate = createFileLoader({
|
|
|
22
22
|
prefix: "src/templates",
|
|
23
23
|
fileLoader: fs_extra_1.default.readFileSync,
|
|
24
24
|
});
|
|
25
|
-
exports.getTemplateHelpers = createFileLoader({
|
|
26
|
-
prefix: "src/templates",
|
|
27
|
-
fileLoader: fs_extra_1.default.readFileSync,
|
|
28
|
-
});
|
|
29
25
|
function createFileLoader({ prefix, fileLoader, suggestions = [], }) {
|
|
30
26
|
return function (name, ...args) {
|
|
31
27
|
const filePath = (0, path_2.getCustomerPath)(path_1.default.join(prefix, name));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type CatalogFixtureType } from "../types";
|
|
2
|
+
export declare function getFixture(args: GetFixturesArgs): Promise<GetFixtureResponseDto>;
|
|
3
|
+
interface GetFixturesArgs {
|
|
4
|
+
connectionId: string;
|
|
5
|
+
type: CatalogFixtureType;
|
|
6
|
+
}
|
|
7
|
+
export interface GetFixtureResponseDto {
|
|
8
|
+
data: any;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=get-fixture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-fixture.d.ts","sourceRoot":"","sources":["../../src/http/get-fixture.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAInD,wBAAsB,UAAU,CAC9B,IAAI,EAAE,eAAe,GACpB,OAAO,CAAC,qBAAqB,CAAC,CAuBhC;AAED,UAAU,eAAe;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,kBAAkB,CAAC;CAC1B;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,GAAG,CAAC;CACX"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFixture = void 0;
|
|
4
|
+
const axios_1 = require("axios");
|
|
5
|
+
const errors_1 = require("@oclif/core/lib/errors");
|
|
6
|
+
const ux_action_1 = require("../helpers/ux-action");
|
|
7
|
+
const http_client_1 = require("./http-client");
|
|
8
|
+
async function getFixture(args) {
|
|
9
|
+
const client = await (0, http_client_1.getHttpClient)();
|
|
10
|
+
try {
|
|
11
|
+
const response = await (0, ux_action_1.uxAction)("📡 Fetching fixtures", async () => {
|
|
12
|
+
return await client.get(`/templates/catalog_fixture`, {
|
|
13
|
+
params: {
|
|
14
|
+
connection_id: args.connectionId,
|
|
15
|
+
type: args.type,
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
})();
|
|
19
|
+
return response.data;
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
if ((0, axios_1.isAxiosError)(error) && error.response) {
|
|
23
|
+
throw new errors_1.CLIError("Something went wrong while fetching fixtures: \n" +
|
|
24
|
+
error.response.data.message);
|
|
25
|
+
}
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.getFixture = getFixture;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-candidate-fixtures.d.ts","sourceRoot":"","sources":["../../src/prompt-data/get-candidate-fixtures.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAI9C,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,MAAM,GACnB,aAAa,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"get-candidate-fixtures.d.ts","sourceRoot":"","sources":["../../src/prompt-data/get-candidate-fixtures.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAI9C,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,MAAM,GACnB,aAAa,CAAC,MAAM,CAAC,CA+CvB"}
|
|
@@ -9,9 +9,9 @@ const errors_1 = require("@oclif/core/lib/errors");
|
|
|
9
9
|
const find_deep_files_1 = require("../helpers/find-deep-files");
|
|
10
10
|
const get_template_files_1 = require("./get-template-files");
|
|
11
11
|
function getCandidateFixtures(templatePath) {
|
|
12
|
-
const templateType = templatePath
|
|
13
|
-
if (!
|
|
14
|
-
throw new errors_1.CLIError(`
|
|
12
|
+
const templateType = extractTemplateType(templatePath);
|
|
13
|
+
if (!templateType) {
|
|
14
|
+
throw new errors_1.CLIError(`Couldn't find the template type by looking at its path: ${templatePath}`, {
|
|
15
15
|
suggestions: [
|
|
16
16
|
"Check that the template file path is correct",
|
|
17
17
|
"Check that your templates are in the correctly named directory for their type (e.g. 'item.jsonata' in the 'templates/item' directory",
|
|
@@ -47,3 +47,13 @@ function getCandidateFixtures(templatePath) {
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
exports.getCandidateFixtures = getCandidateFixtures;
|
|
50
|
+
/**
|
|
51
|
+
* Checks for any nested folder that matches a known template type.
|
|
52
|
+
*/
|
|
53
|
+
function extractTemplateType(templatePath) {
|
|
54
|
+
for (const type of get_template_files_1.templateTypes) {
|
|
55
|
+
if (templatePath.includes(`${type}/`)) {
|
|
56
|
+
return type;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -36,5 +36,12 @@ export interface TemplateExecutionErrorResponse {
|
|
|
36
36
|
success: false;
|
|
37
37
|
error: TemplateError;
|
|
38
38
|
}
|
|
39
|
+
export declare enum CatalogFixtureType {
|
|
40
|
+
ITEM = "item",
|
|
41
|
+
VARIATION = "variation",
|
|
42
|
+
ITEM_GROUP = "item_group",
|
|
43
|
+
EXTERNAL_DATA = "external_data",
|
|
44
|
+
MAPPING = "mapping"
|
|
45
|
+
}
|
|
39
46
|
export {};
|
|
40
47
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACrB,2BAA2B,EAAE,OAAO,CAAC;IACrC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,YAAY,EAAE,KAAK,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;QACpB,SAAS,EAAE,KAAK,CAAC;YACf,KAAK,EAAE;gBACL,IAAI,CAAC,EAAE,MAAM,CAAC;gBACd,SAAS,CAAC,EAAE,MAAM,CAAC;gBACnB,UAAU,CAAC,EAAE,MAAM,CAAC;gBACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;gBAClB,OAAO,CAAC,EAAE,MAAM,CAAC;aAClB,CAAC;YACF,cAAc,EAAE,MAAM,EAAE,CAAC;SAC1B,CAAC,CAAC;KACJ,CAAC,CAAC;CACJ;AAED,MAAM,MAAM,oBAAoB,GAAG,MAAM,CACvC,MAAM,EACN;IACE,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB,CACF,CAAC;AAEF,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC;AAEjE,UAAU,aAAa;IACrB,IAAI,EAAE,gBAAgB,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,8BAA8B;IAC7C,OAAO,EAAE,KAAK,CAAC;IACf,KAAK,EAAE,aAAa,CAAC;CACtB"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACrB,2BAA2B,EAAE,OAAO,CAAC;IACrC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,YAAY,EAAE,KAAK,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;QACpB,SAAS,EAAE,KAAK,CAAC;YACf,KAAK,EAAE;gBACL,IAAI,CAAC,EAAE,MAAM,CAAC;gBACd,SAAS,CAAC,EAAE,MAAM,CAAC;gBACnB,UAAU,CAAC,EAAE,MAAM,CAAC;gBACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;gBAClB,OAAO,CAAC,EAAE,MAAM,CAAC;aAClB,CAAC;YACF,cAAc,EAAE,MAAM,EAAE,CAAC;SAC1B,CAAC,CAAC;KACJ,CAAC,CAAC;CACJ;AAED,MAAM,MAAM,oBAAoB,GAAG,MAAM,CACvC,MAAM,EACN;IACE,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB,CACF,CAAC;AAEF,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC;AAEjE,UAAU,aAAa;IACrB,IAAI,EAAE,gBAAgB,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,8BAA8B;IAC7C,OAAO,EAAE,KAAK,CAAC;IACf,KAAK,EAAE,aAAa,CAAC;CACtB;AAED,oBAAY,kBAAkB;IAC5B,IAAI,SAAS;IACb,SAAS,cAAc;IACvB,UAAU,eAAe;IACzB,aAAa,kBAAkB;IAC/B,OAAO,YAAY;CACpB"}
|
package/dist/types.js
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CatalogFixtureType = void 0;
|
|
4
|
+
var CatalogFixtureType;
|
|
5
|
+
(function (CatalogFixtureType) {
|
|
6
|
+
CatalogFixtureType["ITEM"] = "item";
|
|
7
|
+
CatalogFixtureType["VARIATION"] = "variation";
|
|
8
|
+
CatalogFixtureType["ITEM_GROUP"] = "item_group";
|
|
9
|
+
CatalogFixtureType["EXTERNAL_DATA"] = "external_data";
|
|
10
|
+
CatalogFixtureType["MAPPING"] = "mapping";
|
|
11
|
+
})(CatalogFixtureType || (exports.CatalogFixtureType = CatalogFixtureType = {}));
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/oclif.manifest.json
CHANGED
|
@@ -94,6 +94,29 @@
|
|
|
94
94
|
"execute.js"
|
|
95
95
|
]
|
|
96
96
|
},
|
|
97
|
+
"generate-fixture": {
|
|
98
|
+
"aliases": [],
|
|
99
|
+
"args": {},
|
|
100
|
+
"description": "\nThis command will fetch one fixture from the server and save it into a specified file. This fixture file will be an example of how the data would be passed to the connector when executing the templates.\n\nYou are expected to customize this file to match the data you expect to cover in a template execution (e.g. an item with stock, a variation with missing data), etc. Note that you can have multiple fixtures of the same type to cover different scenarios.\n\nFinally, if the file already exists you'll be prompted to overwrite it.\n ",
|
|
101
|
+
"examples": [
|
|
102
|
+
"$ <%= config.bin %> generate-fixture"
|
|
103
|
+
],
|
|
104
|
+
"flags": {},
|
|
105
|
+
"hasDynamicHelp": false,
|
|
106
|
+
"hiddenAliases": [],
|
|
107
|
+
"id": "generate-fixture",
|
|
108
|
+
"pluginAlias": "@constructor-io/constructorio-connect-cli",
|
|
109
|
+
"pluginName": "@constructor-io/constructorio-connect-cli",
|
|
110
|
+
"pluginType": "core",
|
|
111
|
+
"strict": true,
|
|
112
|
+
"enableJsonFlag": false,
|
|
113
|
+
"isESM": false,
|
|
114
|
+
"relativePath": [
|
|
115
|
+
"dist",
|
|
116
|
+
"commands",
|
|
117
|
+
"generate-fixture.js"
|
|
118
|
+
]
|
|
119
|
+
},
|
|
97
120
|
"init": {
|
|
98
121
|
"aliases": [],
|
|
99
122
|
"args": {
|
|
@@ -125,5 +148,5 @@
|
|
|
125
148
|
]
|
|
126
149
|
}
|
|
127
150
|
},
|
|
128
|
-
"version": "1.
|
|
151
|
+
"version": "1.3.0"
|
|
129
152
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructor-io/constructorio-connect-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "CLI tool to enable users to interface with the Constructor Connect Ecosystem",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"build": "tsc --project tsconfig.production.json",
|
|
24
24
|
"prebuild": "shx rm -rf dist",
|
|
25
25
|
"type-check": "tsc --noemit",
|
|
26
|
-
"test": "TZ=UTC jest",
|
|
26
|
+
"test": "TZ=UTC node --trace-warnings node_modules/.bin/jest",
|
|
27
|
+
"test:verbose": "TZ=UTC VERBOSE=true jest",
|
|
27
28
|
"test:debug": "TZ=UTC node --inspect-brk -r ts-node/register node_modules/.bin/jest --runInBand",
|
|
28
29
|
"test:watch": "TZ=UTC jest --watch",
|
|
29
30
|
"test:cov": "TZ=UTC jest --coverage",
|