@constructor-io/constructorio-connect-cli 1.6.0 → 1.7.1
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/boilerplate-repo/src/templates/helpers.jsonata +4 -3
- package/boilerplate-repo/src/templates/item/item.jsonata +5 -26
- package/boilerplate-repo/src/templates/item_group/item_group.jsonata +6 -3
- package/boilerplate-repo/src/templates/mapping/mapping.jsonata +7 -31
- package/boilerplate-repo/src/templates/variation/variation.jsonata +5 -25
- package/boilerplate-repo/test/templates/item/item.spec.mjs +6 -82
- package/boilerplate-repo/test/templates/item_group/item_group.spec.mjs +6 -19
- package/boilerplate-repo/test/templates/mapping/mapping.spec.mjs +6 -74
- package/boilerplate-repo/test/templates/variation/variation.spec.mjs +6 -33
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
- package/boilerplate-repo/src/fixtures/item/item.json +0 -39
- package/boilerplate-repo/src/fixtures/item_group/item_group.json +0 -22
- package/boilerplate-repo/src/fixtures/mapping/mapping.json +0 -26
- package/boilerplate-repo/src/fixtures/variation/variation.json +0 -11
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/*
|
|
2
|
+
* This is a file where you can define additional helper functions.
|
|
3
|
+
* @see https://docs.constructor.com/docs/integrating-with-constructor-connect-cli-helper-functions
|
|
4
|
+
*/
|
|
@@ -1,26 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
$name := targetData.name;
|
|
7
|
-
|
|
8
|
-
{
|
|
9
|
-
/* Use the `hello` helper function */
|
|
10
|
-
"item_name": $hello($name),
|
|
11
|
-
|
|
12
|
-
"metadata": [
|
|
13
|
-
{
|
|
14
|
-
"key": "colors",
|
|
15
|
-
"value": targetData.variations.attributes[name = "color"].value
|
|
16
|
-
}
|
|
17
|
-
],
|
|
18
|
-
|
|
19
|
-
"facets": [
|
|
20
|
-
{
|
|
21
|
-
"key": "price_average",
|
|
22
|
-
"value": $average(targetData.variations.price)
|
|
23
|
-
}
|
|
24
|
-
]
|
|
25
|
-
}
|
|
26
|
-
)
|
|
1
|
+
/*
|
|
2
|
+
* This template allows you to customize your item data.
|
|
3
|
+
* @see https://docs.constructor.com/docs/integrating-with-constructor-connect-cli-template-types-transformation-templates#item-template
|
|
4
|
+
*/
|
|
5
|
+
{}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/*
|
|
2
|
+
* This template allows you to customize your item group data.
|
|
3
|
+
* @see https://docs.constructor.com/docs/integrating-with-constructor-connect-cli-template-types-transformation-templates#item-group-template
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
{}
|
|
@@ -1,34 +1,10 @@
|
|
|
1
1
|
/*
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
In this template, you can return three arrays: `items`, `variations`, and `item_groups`.
|
|
6
|
-
Each array can have any structure as defined by you, and you'll be able to use the
|
|
7
|
-
very same structure defined here in the transformation templates.
|
|
8
|
-
|
|
9
|
-
In the example defined below, we only care about mapping the items and item groups,
|
|
10
|
-
since variations are already embedded into each item.
|
|
11
|
-
|
|
12
|
-
If we wanted to ingest only variations (e.g. a partial sync), you'd return the
|
|
13
|
-
`variations` array filled with data instead.
|
|
14
|
-
|
|
15
|
-
Refer to the README for extended documentation on how to use the mapping template.
|
|
2
|
+
* Check out the documentation to see how to change and customize the connector data mapping:
|
|
3
|
+
* @see https://docs.constructor.com/docs/integrating-with-constructor-connect-cli-template-types-mapping-template
|
|
16
4
|
*/
|
|
17
5
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"items": [
|
|
24
|
-
$merge([
|
|
25
|
-
targetData,
|
|
26
|
-
{ "__variations": targetData.colors.{ "color": $ } }
|
|
27
|
-
])
|
|
28
|
-
],
|
|
29
|
-
"variations": [],
|
|
30
|
-
"item_groups": [
|
|
31
|
-
{ "id": targetData.category }
|
|
32
|
-
]
|
|
33
|
-
}
|
|
34
|
-
)
|
|
6
|
+
{
|
|
7
|
+
"items": [],
|
|
8
|
+
"variations": [],
|
|
9
|
+
"item_groups": []
|
|
10
|
+
}
|
|
@@ -1,26 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/*
|
|
2
|
+
* This template allows you to customize your variation data.
|
|
3
|
+
* @see https://docs.constructor.com/docs/integrating-with-constructor-connect-cli-template-types-transformation-templates#variation-template
|
|
4
|
+
*/
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
$name := targetData.name;
|
|
7
|
-
|
|
8
|
-
{
|
|
9
|
-
/* Use the `hello` helper function */
|
|
10
|
-
"item_name": $hello($name),
|
|
11
|
-
|
|
12
|
-
"metadata": [
|
|
13
|
-
{
|
|
14
|
-
"key": "color",
|
|
15
|
-
"value": targetData.attributes[name = "color"].value
|
|
16
|
-
}
|
|
17
|
-
],
|
|
18
|
-
|
|
19
|
-
"facets": [
|
|
20
|
-
{
|
|
21
|
-
"key": "price",
|
|
22
|
-
"value": targetData.price
|
|
23
|
-
}
|
|
24
|
-
]
|
|
25
|
-
}
|
|
26
|
-
)
|
|
6
|
+
{}
|
|
@@ -1,86 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Check out the documentation to see how to write and maintain tests:
|
|
3
|
+
* @see https://docs.constructor.com/docs/integrating-with-constructor-connect-cli-development-flow#step-3-test-your-templates
|
|
4
|
+
*/
|
|
5
5
|
|
|
6
6
|
describe("item", () => {
|
|
7
|
-
it("should
|
|
8
|
-
|
|
9
|
-
* Add a function `executeTemplate` which abstracts all the complexity from
|
|
10
|
-
* running a template and gives you the result back.
|
|
11
|
-
*
|
|
12
|
-
* It will:
|
|
13
|
-
* - Load the template.
|
|
14
|
-
* - Receive the fixture + externalData (optional) as an object.
|
|
15
|
-
* - Automatically load the first `connectionId` to send to the backend.
|
|
16
|
-
* - Execute the template on the backend.
|
|
17
|
-
* - Return an object.
|
|
18
|
-
*
|
|
19
|
-
* In failure:
|
|
20
|
-
* - It will throw an error, not allowing the test to proceed.
|
|
21
|
-
*/
|
|
22
|
-
const result = await executeTemplate({
|
|
23
|
-
// Define the template type: item | variation | item_group | mapping | grouping
|
|
24
|
-
type: "item",
|
|
25
|
-
|
|
26
|
-
// Define the template file name, which will be used to load the test
|
|
27
|
-
name: "item.jsonata",
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Add a function `buildFixture` to load a fixture from a type and file name.
|
|
31
|
-
* It can also receive a second param being an object, which will deep merge into
|
|
32
|
-
* the fixture itself - similarly to how a factory pattern works. This way we can
|
|
33
|
-
* have only one fixture with many tests :)
|
|
34
|
-
*/
|
|
35
|
-
fixture: buildFixture("item", "item.json", {
|
|
36
|
-
name: "other shoes!",
|
|
37
|
-
variations: [
|
|
38
|
-
{
|
|
39
|
-
name: "other shoes (red)",
|
|
40
|
-
price: 130,
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
name: "other shoes (blue)",
|
|
44
|
-
price: 200,
|
|
45
|
-
},
|
|
46
|
-
],
|
|
47
|
-
}),
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
// Alternatively, you can also store the snapshot in a file to reduce clutter.
|
|
51
|
-
// expect(result).toMatchSnapshot();
|
|
52
|
-
|
|
53
|
-
expect(result).toMatchInlineSnapshot(`
|
|
54
|
-
{
|
|
55
|
-
"facets": [
|
|
56
|
-
{
|
|
57
|
-
"key": "price_average",
|
|
58
|
-
"value": 165,
|
|
59
|
-
},
|
|
60
|
-
],
|
|
61
|
-
"item_name": "These are my other shoes!!",
|
|
62
|
-
"metadata": [
|
|
63
|
-
{
|
|
64
|
-
"key": "colors",
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
}
|
|
68
|
-
`);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("should compute the average price", async () => {
|
|
72
|
-
const response = await executeTemplate({
|
|
73
|
-
type: "item",
|
|
74
|
-
name: "item.jsonata",
|
|
75
|
-
fixture: buildFixture("item", "item.json", {
|
|
76
|
-
variations: [{ price: 100 }, { price: 200 }],
|
|
77
|
-
}),
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
const priceFacet = response.facets.find(
|
|
81
|
-
(facet) => facet.key === "price_average",
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
expect(priceFacet.value).toBe(150);
|
|
7
|
+
it("should be defined", async () => {
|
|
8
|
+
expect(true).toBe(true);
|
|
85
9
|
});
|
|
86
10
|
});
|
|
@@ -1,23 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Check out the documentation to see how to write and maintain tests:
|
|
3
|
+
* @see https://docs.constructor.com/docs/integrating-with-constructor-connect-cli-development-flow#step-3-test-your-templates
|
|
4
|
+
*/
|
|
5
5
|
|
|
6
6
|
describe("item_group", () => {
|
|
7
|
-
it("should
|
|
8
|
-
|
|
9
|
-
type: "item_group",
|
|
10
|
-
name: "item_group.jsonata",
|
|
11
|
-
fixture: buildFixture("item_group", "item_group.json", { other: "data" }),
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
// Alternatively, you can also store the snapshot in a file to reduce clutter.
|
|
15
|
-
// expect(result).toMatchSnapshot();
|
|
16
|
-
|
|
17
|
-
expect(result).toMatchInlineSnapshot(`
|
|
18
|
-
{
|
|
19
|
-
"name": "root",
|
|
20
|
-
}
|
|
21
|
-
`);
|
|
7
|
+
it("should be defined", async () => {
|
|
8
|
+
expect(true).toBe(true);
|
|
22
9
|
});
|
|
23
10
|
});
|
|
@@ -1,78 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Check out the documentation to see how to write and maintain tests:
|
|
3
|
+
* @see https://docs.constructor.com/docs/integrating-with-constructor-connect-cli-development-flow#step-3-test-your-templates
|
|
4
|
+
*/
|
|
5
5
|
|
|
6
6
|
describe("mapping", () => {
|
|
7
|
-
it("should
|
|
8
|
-
|
|
9
|
-
type: "mapping",
|
|
10
|
-
name: "mapping.jsonata",
|
|
11
|
-
fixture: buildFixture("mapping", "mapping.json", {
|
|
12
|
-
title: "New Title",
|
|
13
|
-
}),
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
// Alternatively, you can also store the snapshot in a file to reduce clutter.
|
|
17
|
-
// expect(result).toMatchSnapshot();
|
|
18
|
-
|
|
19
|
-
expect(result).toMatchInlineSnapshot(`
|
|
20
|
-
{
|
|
21
|
-
"item_groups": [
|
|
22
|
-
{
|
|
23
|
-
"id": "smartphones",
|
|
24
|
-
},
|
|
25
|
-
],
|
|
26
|
-
"items": [
|
|
27
|
-
{
|
|
28
|
-
"__variations": [
|
|
29
|
-
{
|
|
30
|
-
"color": "midnight-black",
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"color": "fancy-silver",
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
"color": "rich-gold",
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
"color": "sky-blue",
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
"color": "crimson-red",
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
"color": "green-forest",
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
"brand": "Apple",
|
|
49
|
-
"category": "smartphones",
|
|
50
|
-
"colors": [
|
|
51
|
-
"midnight-black",
|
|
52
|
-
"fancy-silver",
|
|
53
|
-
"rich-gold",
|
|
54
|
-
"sky-blue",
|
|
55
|
-
"crimson-red",
|
|
56
|
-
"green-forest",
|
|
57
|
-
],
|
|
58
|
-
"description": "SIM-Free, Model A19211 6.5-inch Super Retina HD display with OLED technology A12 Bionic chip with ...",
|
|
59
|
-
"discountPercentage": 17.94,
|
|
60
|
-
"id": "iphone-x",
|
|
61
|
-
"images": [
|
|
62
|
-
"https://cdn.dummyjson.com/product-images/2/1.jpg",
|
|
63
|
-
"https://cdn.dummyjson.com/product-images/2/2.jpg",
|
|
64
|
-
"https://cdn.dummyjson.com/product-images/2/3.jpg",
|
|
65
|
-
"https://cdn.dummyjson.com/product-images/2/thumbnail.jpg",
|
|
66
|
-
],
|
|
67
|
-
"price": 899,
|
|
68
|
-
"rating": 4.44,
|
|
69
|
-
"stock": 34,
|
|
70
|
-
"thumbnail": "https://cdn.dummyjson.com/product-images/2/thumbnail.jpg",
|
|
71
|
-
"title": "New Title",
|
|
72
|
-
},
|
|
73
|
-
],
|
|
74
|
-
"variations": [],
|
|
75
|
-
}
|
|
76
|
-
`);
|
|
7
|
+
it("should be defined", async () => {
|
|
8
|
+
expect(true).toBe(true);
|
|
77
9
|
});
|
|
78
10
|
});
|
|
@@ -1,37 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Check out the documentation to see how to write and maintain tests:
|
|
3
|
+
* @see https://docs.constructor.com/docs/integrating-with-constructor-connect-cli-development-flow#step-3-test-your-templates
|
|
4
|
+
*/
|
|
5
5
|
|
|
6
6
|
describe("variation", () => {
|
|
7
|
-
it("should
|
|
8
|
-
|
|
9
|
-
type: "variation",
|
|
10
|
-
name: "variation.jsonata",
|
|
11
|
-
fixture: buildFixture("variation", "variation.json", {
|
|
12
|
-
name: "stylish boots",
|
|
13
|
-
}),
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
// Alternatively, you can also store the snapshot in a file to reduce clutter.
|
|
17
|
-
// expect(result).toMatchSnapshot();
|
|
18
|
-
|
|
19
|
-
expect(result).toMatchInlineSnapshot(`
|
|
20
|
-
{
|
|
21
|
-
"facets": [
|
|
22
|
-
{
|
|
23
|
-
"key": "price",
|
|
24
|
-
"value": 50,
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
"item_name": "These are my stylish boots!",
|
|
28
|
-
"metadata": [
|
|
29
|
-
{
|
|
30
|
-
"key": "color",
|
|
31
|
-
"value": "red",
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
}
|
|
35
|
-
`);
|
|
7
|
+
it("should be defined", async () => {
|
|
8
|
+
expect(true).toBe(true);
|
|
36
9
|
});
|
|
37
10
|
});
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"id": 42,
|
|
3
|
-
"name": "Super Shoes",
|
|
4
|
-
"variations": [
|
|
5
|
-
{
|
|
6
|
-
"id": "42-red",
|
|
7
|
-
"name": "Super Shoes (Red)",
|
|
8
|
-
"price": 50,
|
|
9
|
-
"attributes": [
|
|
10
|
-
{
|
|
11
|
-
"name": "color",
|
|
12
|
-
"value": "red"
|
|
13
|
-
}
|
|
14
|
-
]
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
"id": "42-blue",
|
|
18
|
-
"name": "Super Shoes (Blue)",
|
|
19
|
-
"price": 100,
|
|
20
|
-
"attributes": [
|
|
21
|
-
{
|
|
22
|
-
"name": "color",
|
|
23
|
-
"value": "blue"
|
|
24
|
-
}
|
|
25
|
-
]
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
"id": "42-green",
|
|
29
|
-
"name": "Super Shoes (Green)",
|
|
30
|
-
"price": 75,
|
|
31
|
-
"attributes": [
|
|
32
|
-
{
|
|
33
|
-
"name": "color",
|
|
34
|
-
"value": "green"
|
|
35
|
-
}
|
|
36
|
-
]
|
|
37
|
-
}
|
|
38
|
-
]
|
|
39
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"id": "iphone-x",
|
|
3
|
-
"title": "iPhone X",
|
|
4
|
-
"description": "SIM-Free, Model A19211 6.5-inch Super Retina HD display with OLED technology A12 Bionic chip with ...",
|
|
5
|
-
"price": 899,
|
|
6
|
-
"discountPercentage": 17.94,
|
|
7
|
-
"rating": 4.44,
|
|
8
|
-
"stock": 34,
|
|
9
|
-
"brand": "Apple",
|
|
10
|
-
"category": "smartphones",
|
|
11
|
-
"thumbnail": "https://cdn.dummyjson.com/product-images/2/thumbnail.jpg",
|
|
12
|
-
"images": [
|
|
13
|
-
"https://cdn.dummyjson.com/product-images/2/1.jpg",
|
|
14
|
-
"https://cdn.dummyjson.com/product-images/2/2.jpg",
|
|
15
|
-
"https://cdn.dummyjson.com/product-images/2/3.jpg",
|
|
16
|
-
"https://cdn.dummyjson.com/product-images/2/thumbnail.jpg"
|
|
17
|
-
],
|
|
18
|
-
"colors": [
|
|
19
|
-
"midnight-black",
|
|
20
|
-
"fancy-silver",
|
|
21
|
-
"rich-gold",
|
|
22
|
-
"sky-blue",
|
|
23
|
-
"crimson-red",
|
|
24
|
-
"green-forest"
|
|
25
|
-
]
|
|
26
|
-
}
|