@knocklabs/cli 0.1.8 → 0.1.9
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 +23 -23
- package/dist/isomorphic.js +50 -0
- package/dist/lib/marshal/email-layout/helpers.js +3 -4
- package/dist/lib/marshal/email-layout/index.js +1 -0
- package/dist/lib/marshal/email-layout/processor.isomorphic.js +93 -0
- package/dist/lib/marshal/email-layout/reader.js +3 -2
- package/dist/lib/marshal/email-layout/writer.js +4 -87
- package/dist/lib/marshal/index.isomorphic.js +18 -0
- package/oclif.manifest.json +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ $ npm install -g @knocklabs/cli
|
|
|
16
16
|
$ knock COMMAND
|
|
17
17
|
running command...
|
|
18
18
|
$ knock (--version)
|
|
19
|
-
@knocklabs/cli/0.1.
|
|
19
|
+
@knocklabs/cli/0.1.9 linux-x64 node-v18.19.0
|
|
20
20
|
$ knock --help [COMMAND]
|
|
21
21
|
USAGE
|
|
22
22
|
$ knock COMMAND
|
|
@@ -77,7 +77,7 @@ FLAGS
|
|
|
77
77
|
--service-token=<value> (required) The service token to authenticate with.
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
_See code: [src/commands/commit/index.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.
|
|
80
|
+
_See code: [src/commands/commit/index.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.9/src/commands/commit/index.ts)_
|
|
81
81
|
|
|
82
82
|
## `knock commit get ID`
|
|
83
83
|
|
|
@@ -94,7 +94,7 @@ GLOBAL FLAGS
|
|
|
94
94
|
--json Format output as json.
|
|
95
95
|
```
|
|
96
96
|
|
|
97
|
-
_See code: [src/commands/commit/get.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.
|
|
97
|
+
_See code: [src/commands/commit/get.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.9/src/commands/commit/get.ts)_
|
|
98
98
|
|
|
99
99
|
## `knock commit list`
|
|
100
100
|
|
|
@@ -118,7 +118,7 @@ GLOBAL FLAGS
|
|
|
118
118
|
--json Format output as json.
|
|
119
119
|
```
|
|
120
120
|
|
|
121
|
-
_See code: [src/commands/commit/list.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.
|
|
121
|
+
_See code: [src/commands/commit/list.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.9/src/commands/commit/list.ts)_
|
|
122
122
|
|
|
123
123
|
## `knock commit promote`
|
|
124
124
|
|
|
@@ -135,7 +135,7 @@ FLAGS
|
|
|
135
135
|
--to=<value> The destination environment to promote all changes from the preceding environment.
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
-
_See code: [src/commands/commit/promote.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.
|
|
138
|
+
_See code: [src/commands/commit/promote.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.9/src/commands/commit/promote.ts)_
|
|
139
139
|
|
|
140
140
|
## `knock help [COMMANDS]`
|
|
141
141
|
|
|
@@ -175,7 +175,7 @@ GLOBAL FLAGS
|
|
|
175
175
|
--json Format output as json.
|
|
176
176
|
```
|
|
177
177
|
|
|
178
|
-
_See code: [src/commands/layout/get.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.
|
|
178
|
+
_See code: [src/commands/layout/get.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.9/src/commands/layout/get.ts)_
|
|
179
179
|
|
|
180
180
|
## `knock layout list`
|
|
181
181
|
|
|
@@ -198,7 +198,7 @@ GLOBAL FLAGS
|
|
|
198
198
|
--json Format output as json.
|
|
199
199
|
```
|
|
200
200
|
|
|
201
|
-
_See code: [src/commands/layout/list.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.
|
|
201
|
+
_See code: [src/commands/layout/list.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.9/src/commands/layout/list.ts)_
|
|
202
202
|
|
|
203
203
|
## `knock layout pull [EMAILLAYOUTKEY]`
|
|
204
204
|
|
|
@@ -218,7 +218,7 @@ FLAGS
|
|
|
218
218
|
--service-token=<value> (required) The service token to authenticate with.
|
|
219
219
|
```
|
|
220
220
|
|
|
221
|
-
_See code: [src/commands/layout/pull.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.
|
|
221
|
+
_See code: [src/commands/layout/pull.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.9/src/commands/layout/pull.ts)_
|
|
222
222
|
|
|
223
223
|
## `knock layout push [EMAILLAYOUTKEY]`
|
|
224
224
|
|
|
@@ -240,7 +240,7 @@ FLAGS
|
|
|
240
240
|
--service-token=<value> (required) The service token to authenticate with.
|
|
241
241
|
```
|
|
242
242
|
|
|
243
|
-
_See code: [src/commands/layout/push.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.
|
|
243
|
+
_See code: [src/commands/layout/push.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.9/src/commands/layout/push.ts)_
|
|
244
244
|
|
|
245
245
|
## `knock layout validate [EMAILLAYOUTKEY]`
|
|
246
246
|
|
|
@@ -259,7 +259,7 @@ FLAGS
|
|
|
259
259
|
--service-token=<value> (required) The service token to authenticate with.
|
|
260
260
|
```
|
|
261
261
|
|
|
262
|
-
_See code: [src/commands/layout/validate.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.
|
|
262
|
+
_See code: [src/commands/layout/validate.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.9/src/commands/layout/validate.ts)_
|
|
263
263
|
|
|
264
264
|
## `knock plugins`
|
|
265
265
|
|
|
@@ -531,7 +531,7 @@ GLOBAL FLAGS
|
|
|
531
531
|
--json Format output as json.
|
|
532
532
|
```
|
|
533
533
|
|
|
534
|
-
_See code: [src/commands/translation/get.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.
|
|
534
|
+
_See code: [src/commands/translation/get.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.9/src/commands/translation/get.ts)_
|
|
535
535
|
|
|
536
536
|
## `knock translation list`
|
|
537
537
|
|
|
@@ -554,7 +554,7 @@ GLOBAL FLAGS
|
|
|
554
554
|
--json Format output as json.
|
|
555
555
|
```
|
|
556
556
|
|
|
557
|
-
_See code: [src/commands/translation/list.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.
|
|
557
|
+
_See code: [src/commands/translation/list.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.9/src/commands/translation/list.ts)_
|
|
558
558
|
|
|
559
559
|
## `knock translation pull [TRANSLATIONREF]`
|
|
560
560
|
|
|
@@ -579,7 +579,7 @@ FLAGS
|
|
|
579
579
|
--translations-dir=<value> The target directory path to pull all translations into.
|
|
580
580
|
```
|
|
581
581
|
|
|
582
|
-
_See code: [src/commands/translation/pull.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.
|
|
582
|
+
_See code: [src/commands/translation/pull.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.9/src/commands/translation/pull.ts)_
|
|
583
583
|
|
|
584
584
|
## `knock translation push [TRANSLATIONREF]`
|
|
585
585
|
|
|
@@ -606,7 +606,7 @@ FLAGS
|
|
|
606
606
|
--translations-dir=<value> The target directory path to find all translations to push.
|
|
607
607
|
```
|
|
608
608
|
|
|
609
|
-
_See code: [src/commands/translation/push.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.
|
|
609
|
+
_See code: [src/commands/translation/push.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.9/src/commands/translation/push.ts)_
|
|
610
610
|
|
|
611
611
|
## `knock translation validate [TRANSLATIONREF]`
|
|
612
612
|
|
|
@@ -631,7 +631,7 @@ FLAGS
|
|
|
631
631
|
--translations-dir=<value> The target directory path to find all translations to validate.
|
|
632
632
|
```
|
|
633
633
|
|
|
634
|
-
_See code: [src/commands/translation/validate.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.
|
|
634
|
+
_See code: [src/commands/translation/validate.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.9/src/commands/translation/validate.ts)_
|
|
635
635
|
|
|
636
636
|
## `knock whoami`
|
|
637
637
|
|
|
@@ -648,7 +648,7 @@ GLOBAL FLAGS
|
|
|
648
648
|
--json Format output as json.
|
|
649
649
|
```
|
|
650
650
|
|
|
651
|
-
_See code: [src/commands/whoami.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.
|
|
651
|
+
_See code: [src/commands/whoami.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.9/src/commands/whoami.ts)_
|
|
652
652
|
|
|
653
653
|
## `knock workflow activate WORKFLOWKEY`
|
|
654
654
|
|
|
@@ -675,7 +675,7 @@ DESCRIPTION
|
|
|
675
675
|
with `false` in order to deactivate it.
|
|
676
676
|
```
|
|
677
677
|
|
|
678
|
-
_See code: [src/commands/workflow/activate.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.
|
|
678
|
+
_See code: [src/commands/workflow/activate.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.9/src/commands/workflow/activate.ts)_
|
|
679
679
|
|
|
680
680
|
## `knock workflow get WORKFLOWKEY`
|
|
681
681
|
|
|
@@ -695,7 +695,7 @@ GLOBAL FLAGS
|
|
|
695
695
|
--json Format output as json.
|
|
696
696
|
```
|
|
697
697
|
|
|
698
|
-
_See code: [src/commands/workflow/get.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.
|
|
698
|
+
_See code: [src/commands/workflow/get.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.9/src/commands/workflow/get.ts)_
|
|
699
699
|
|
|
700
700
|
## `knock workflow list`
|
|
701
701
|
|
|
@@ -718,7 +718,7 @@ GLOBAL FLAGS
|
|
|
718
718
|
--json Format output as json.
|
|
719
719
|
```
|
|
720
720
|
|
|
721
|
-
_See code: [src/commands/workflow/list.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.
|
|
721
|
+
_See code: [src/commands/workflow/list.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.9/src/commands/workflow/list.ts)_
|
|
722
722
|
|
|
723
723
|
## `knock workflow pull [WORKFLOWKEY]`
|
|
724
724
|
|
|
@@ -738,7 +738,7 @@ FLAGS
|
|
|
738
738
|
--workflows-dir=<value> The target directory path to pull all workflows into.
|
|
739
739
|
```
|
|
740
740
|
|
|
741
|
-
_See code: [src/commands/workflow/pull.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.
|
|
741
|
+
_See code: [src/commands/workflow/pull.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.9/src/commands/workflow/pull.ts)_
|
|
742
742
|
|
|
743
743
|
## `knock workflow push [WORKFLOWKEY]`
|
|
744
744
|
|
|
@@ -759,7 +759,7 @@ FLAGS
|
|
|
759
759
|
--workflows-dir=<value> The target directory path to find all workflows to push.
|
|
760
760
|
```
|
|
761
761
|
|
|
762
|
-
_See code: [src/commands/workflow/push.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.
|
|
762
|
+
_See code: [src/commands/workflow/push.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.9/src/commands/workflow/push.ts)_
|
|
763
763
|
|
|
764
764
|
## `knock workflow run WORKFLOWKEY`
|
|
765
765
|
|
|
@@ -780,7 +780,7 @@ FLAGS
|
|
|
780
780
|
--tenant=<value> A tenant id for the workflow run.
|
|
781
781
|
```
|
|
782
782
|
|
|
783
|
-
_See code: [src/commands/workflow/run.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.
|
|
783
|
+
_See code: [src/commands/workflow/run.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.9/src/commands/workflow/run.ts)_
|
|
784
784
|
|
|
785
785
|
## `knock workflow validate [WORKFLOWKEY]`
|
|
786
786
|
|
|
@@ -799,5 +799,5 @@ FLAGS
|
|
|
799
799
|
--workflows-dir=<value> The target directory path to find all workflows to validate.
|
|
800
800
|
```
|
|
801
801
|
|
|
802
|
-
_See code: [src/commands/workflow/validate.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.
|
|
802
|
+
_See code: [src/commands/workflow/validate.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.9/src/commands/workflow/validate.ts)_
|
|
803
803
|
<!-- commandsstop -->
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* IMPORTANT: You must only expose exports from isomorphic modules.
|
|
3
|
+
*/ "use strict";
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
Object.defineProperty(exports, "marshal", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: ()=>_indexIsomorphic
|
|
10
|
+
});
|
|
11
|
+
const _indexIsomorphic = /*#__PURE__*/ _interopRequireWildcard(require("./lib/marshal/index.isomorphic"));
|
|
12
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
13
|
+
if (typeof WeakMap !== "function") return null;
|
|
14
|
+
var cacheBabelInterop = new WeakMap();
|
|
15
|
+
var cacheNodeInterop = new WeakMap();
|
|
16
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
17
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
18
|
+
})(nodeInterop);
|
|
19
|
+
}
|
|
20
|
+
function _interopRequireWildcard(obj, nodeInterop) {
|
|
21
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
22
|
+
return obj;
|
|
23
|
+
}
|
|
24
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
25
|
+
return {
|
|
26
|
+
default: obj
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
30
|
+
if (cache && cache.has(obj)) {
|
|
31
|
+
return cache.get(obj);
|
|
32
|
+
}
|
|
33
|
+
var newObj = {};
|
|
34
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
35
|
+
for(var key in obj){
|
|
36
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
37
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
38
|
+
if (desc && (desc.get || desc.set)) {
|
|
39
|
+
Object.defineProperty(newObj, key, desc);
|
|
40
|
+
} else {
|
|
41
|
+
newObj[key] = obj[key];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
newObj.default = obj;
|
|
46
|
+
if (cache) {
|
|
47
|
+
cache.set(obj, newObj);
|
|
48
|
+
}
|
|
49
|
+
return newObj;
|
|
50
|
+
}
|
|
@@ -9,7 +9,6 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
LAYOUT_JSON: ()=>LAYOUT_JSON,
|
|
13
12
|
emailLayoutJsonPath: ()=>emailLayoutJsonPath,
|
|
14
13
|
isEmailLayoutDir: ()=>isEmailLayoutDir,
|
|
15
14
|
lsEmailLayoutJson: ()=>lsEmailLayoutJson,
|
|
@@ -18,6 +17,7 @@ _export(exports, {
|
|
|
18
17
|
const _nodePath = /*#__PURE__*/ _interopRequireWildcard(require("node:path"));
|
|
19
18
|
const _core = require("@oclif/core");
|
|
20
19
|
const _fsExtra = /*#__PURE__*/ _interopRequireWildcard(require("fs-extra"));
|
|
20
|
+
const _processorIsomorphic = require("./processor.isomorphic");
|
|
21
21
|
function _getRequireWildcardCache(nodeInterop) {
|
|
22
22
|
if (typeof WeakMap !== "function") return null;
|
|
23
23
|
var cacheBabelInterop = new WeakMap();
|
|
@@ -57,11 +57,10 @@ function _interopRequireWildcard(obj, nodeInterop) {
|
|
|
57
57
|
}
|
|
58
58
|
return newObj;
|
|
59
59
|
}
|
|
60
|
-
const
|
|
61
|
-
const emailLayoutJsonPath = (layoutDirCtx)=>_nodePath.resolve(layoutDirCtx.abspath, LAYOUT_JSON);
|
|
60
|
+
const emailLayoutJsonPath = (layoutDirCtx)=>_nodePath.resolve(layoutDirCtx.abspath, _processorIsomorphic.LAYOUT_JSON);
|
|
62
61
|
const isEmailLayoutDir = async (dirPath)=>Boolean(await lsEmailLayoutJson(dirPath));
|
|
63
62
|
const lsEmailLayoutJson = async (dirPath)=>{
|
|
64
|
-
const emailLayoutJsonPath = _nodePath.resolve(dirPath, LAYOUT_JSON);
|
|
63
|
+
const emailLayoutJsonPath = _nodePath.resolve(dirPath, _processorIsomorphic.LAYOUT_JSON);
|
|
65
64
|
const exists = await _fsExtra.pathExists(emailLayoutJsonPath);
|
|
66
65
|
return exists ? emailLayoutJsonPath : undefined;
|
|
67
66
|
};
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
_exportStar(require("./helpers"), exports);
|
|
6
|
+
_exportStar(require("./processor.isomorphic"), exports);
|
|
6
7
|
_exportStar(require("./reader"), exports);
|
|
7
8
|
_exportStar(require("./types"), exports);
|
|
8
9
|
_exportStar(require("./writer"), exports);
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
LAYOUT_JSON: ()=>LAYOUT_JSON,
|
|
13
|
+
buildEmailLayoutDirBundle: ()=>buildEmailLayoutDirBundle,
|
|
14
|
+
toEmailLayoutJson: ()=>toEmailLayoutJson
|
|
15
|
+
});
|
|
16
|
+
const _lodash = require("lodash");
|
|
17
|
+
const _objectIsomorphic = require("../../helpers/object.isomorphic");
|
|
18
|
+
const _constIsomorphic = require("../shared/const.isomorphic");
|
|
19
|
+
const LAYOUT_JSON = "layout.json";
|
|
20
|
+
/*
|
|
21
|
+
* Sanitize the email layout content into a format that's appropriate for reading
|
|
22
|
+
* and writing, by stripping out any annotation fields and handling readonly
|
|
23
|
+
* fields.
|
|
24
|
+
*/ const toEmailLayoutJson = (emailLayout)=>{
|
|
25
|
+
var _emailLayout___annotation;
|
|
26
|
+
// Move read only field under the dedicated field "__readonly".
|
|
27
|
+
const readonlyFields = ((_emailLayout___annotation = emailLayout.__annotation) === null || _emailLayout___annotation === void 0 ? void 0 : _emailLayout___annotation.readonly_fields) || [];
|
|
28
|
+
const [readonly, remainder] = (0, _objectIsomorphic.split)(emailLayout, readonlyFields);
|
|
29
|
+
const emailLayoutjson = {
|
|
30
|
+
...remainder,
|
|
31
|
+
__readonly: readonly
|
|
32
|
+
};
|
|
33
|
+
// Strip out all schema annotations, so not to expose them to end users.
|
|
34
|
+
return (0, _objectIsomorphic.omitDeep)(emailLayoutjson, [
|
|
35
|
+
"__annotation"
|
|
36
|
+
]);
|
|
37
|
+
};
|
|
38
|
+
const compileExtractionSettings = (emailLayout)=>{
|
|
39
|
+
const extractableFields = (0, _lodash.get)(emailLayout, [
|
|
40
|
+
"__annotation",
|
|
41
|
+
"extractable_fields"
|
|
42
|
+
], {});
|
|
43
|
+
const map = new Map();
|
|
44
|
+
for (const [key] of Object.entries(emailLayout)){
|
|
45
|
+
// If the field we are on is extractable, then add its extraction
|
|
46
|
+
// settings to the map with the current object path.
|
|
47
|
+
if (key in extractableFields) {
|
|
48
|
+
map.set([
|
|
49
|
+
key
|
|
50
|
+
], extractableFields[key]);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return map;
|
|
54
|
+
};
|
|
55
|
+
const buildEmailLayoutDirBundle = (remoteEmailLayout, localEmailLayout = {})=>{
|
|
56
|
+
const bundle = {};
|
|
57
|
+
const mutRemoteEmailLayout = (0, _lodash.cloneDeep)(remoteEmailLayout);
|
|
58
|
+
// A map of extraction settings of every field in the email layout
|
|
59
|
+
const compiledExtractionSettings = compileExtractionSettings(mutRemoteEmailLayout);
|
|
60
|
+
// Iterate through each extractable field, determine whether we need to
|
|
61
|
+
// extract the field content, and if so, perform the
|
|
62
|
+
// extraction.
|
|
63
|
+
for (const [objPathParts, extractionSettings] of compiledExtractionSettings){
|
|
64
|
+
// If this layout doesn't have this field path, then we don't extract.
|
|
65
|
+
if (!(0, _lodash.has)(mutRemoteEmailLayout, objPathParts)) continue;
|
|
66
|
+
// If the field at this path is extracted in the local layout, then
|
|
67
|
+
// always extract; otherwise extract based on the field settings default.
|
|
68
|
+
const objPathStr = _objectIsomorphic.ObjPath.stringify(objPathParts);
|
|
69
|
+
const extractedFilePath = (0, _lodash.get)(localEmailLayout, `${objPathStr}${_constIsomorphic.FILEPATH_MARKER}`);
|
|
70
|
+
const { default: extractByDefault , file_ext: fileExt } = extractionSettings;
|
|
71
|
+
if (!extractedFilePath && !extractByDefault) continue;
|
|
72
|
+
// By this point, we have a field where we need to extract its content.
|
|
73
|
+
const data = (0, _lodash.get)(mutRemoteEmailLayout, objPathParts);
|
|
74
|
+
const fileName = objPathParts.pop();
|
|
75
|
+
// If we have an extracted file path from the local layout, we use that.
|
|
76
|
+
// In the other case we use the default path.
|
|
77
|
+
const relpath = typeof extractedFilePath === "string" ? extractedFilePath : `${fileName}.${fileExt}`;
|
|
78
|
+
// Perform the extraction by adding the content and its file path to the
|
|
79
|
+
// bundle for writing to the file system later. Then replace the field
|
|
80
|
+
// content with the extracted file path and mark the field as extracted
|
|
81
|
+
// with @ suffix.
|
|
82
|
+
(0, _lodash.set)(bundle, [
|
|
83
|
+
relpath
|
|
84
|
+
], data);
|
|
85
|
+
(0, _lodash.set)(mutRemoteEmailLayout, `${objPathStr}${_constIsomorphic.FILEPATH_MARKER}`, relpath);
|
|
86
|
+
(0, _lodash.unset)(mutRemoteEmailLayout, objPathStr);
|
|
87
|
+
}
|
|
88
|
+
// At this point the bundle contains all extractable files, so we finally add
|
|
89
|
+
// the layout JSON realtive path + the file content.
|
|
90
|
+
return (0, _lodash.set)(bundle, [
|
|
91
|
+
LAYOUT_JSON
|
|
92
|
+
], toEmailLayoutJson(mutRemoteEmailLayout));
|
|
93
|
+
};
|
|
@@ -22,6 +22,7 @@ const _objectIsomorphic = require("../../helpers/object.isomorphic");
|
|
|
22
22
|
const _constIsomorphic = require("../shared/const.isomorphic");
|
|
23
23
|
const _helpers = require("../shared/helpers");
|
|
24
24
|
const _helpers1 = require("./helpers");
|
|
25
|
+
const _processorIsomorphic = require("./processor.isomorphic");
|
|
25
26
|
function _interopRequireDefault(obj) {
|
|
26
27
|
return obj && obj.__esModule ? obj : {
|
|
27
28
|
default: obj
|
|
@@ -111,7 +112,7 @@ const readAllForCommandTarget = async (target, opts = {})=>{
|
|
|
111
112
|
// eslint-disable-next-line no-await-in-loop
|
|
112
113
|
const [layout, readErrors] = await readEmailLayoutDir(layoutDirCtx, opts);
|
|
113
114
|
if (readErrors.length > 0) {
|
|
114
|
-
const layoutJsonPath = _nodePath.default.resolve(layoutDirCtx.abspath,
|
|
115
|
+
const layoutJsonPath = _nodePath.default.resolve(layoutDirCtx.abspath, _processorIsomorphic.LAYOUT_JSON);
|
|
115
116
|
const e = new _error.SourceError((0, _error.formatErrors)(readErrors), layoutJsonPath);
|
|
116
117
|
errors.push(e);
|
|
117
118
|
continue;
|
|
@@ -162,7 +163,7 @@ const readEmailLayoutDir = async (layoutDirCtx, opts = {})=>{
|
|
|
162
163
|
// If there is inlined content present already, then nothing more to do.
|
|
163
164
|
if ((0, _lodash.hasIn)(layoutJson, inlinObjPathStr)) return;
|
|
164
165
|
// Check if the extracted path found at the current field path is valid
|
|
165
|
-
const invalidFilePathError = (0, _helpers.validateExtractedFilePath)(relpath, _nodePath.default.resolve(layoutDirCtx.abspath,
|
|
166
|
+
const invalidFilePathError = (0, _helpers.validateExtractedFilePath)(relpath, _nodePath.default.resolve(layoutDirCtx.abspath, _processorIsomorphic.LAYOUT_JSON), uniqueFilePaths, objPathToFieldStr);
|
|
166
167
|
if (invalidFilePathError) {
|
|
167
168
|
errors.push(invalidFilePathError);
|
|
168
169
|
// Wipe the invalid file path in the node so the final layout json
|
|
@@ -11,18 +11,15 @@ function _export(target, all) {
|
|
|
11
11
|
_export(exports, {
|
|
12
12
|
writeEmailLayoutDirFromData: ()=>writeEmailLayoutDirFromData,
|
|
13
13
|
writeEmailLayoutIndexDir: ()=>writeEmailLayoutIndexDir,
|
|
14
|
-
|
|
15
|
-
pruneLayoutsIndexDir: ()=>pruneLayoutsIndexDir,
|
|
16
|
-
toEmailLayoutJson: ()=>toEmailLayoutJson
|
|
14
|
+
pruneLayoutsIndexDir: ()=>pruneLayoutsIndexDir
|
|
17
15
|
});
|
|
18
16
|
const _nodePath = /*#__PURE__*/ _interopRequireDefault(require("node:path"));
|
|
19
17
|
const _fsExtra = /*#__PURE__*/ _interopRequireWildcard(require("fs-extra"));
|
|
20
18
|
const _lodash = require("lodash");
|
|
21
19
|
const _const = require("../../helpers/const");
|
|
22
20
|
const _json = require("../../helpers/json");
|
|
23
|
-
const _objectIsomorphic = require("../../helpers/object.isomorphic");
|
|
24
|
-
const _constIsomorphic = require("../shared/const.isomorphic");
|
|
25
21
|
const _helpers = require("./helpers");
|
|
22
|
+
const _processorIsomorphic = require("./processor.isomorphic");
|
|
26
23
|
const _reader = require("./reader");
|
|
27
24
|
function _interopRequireDefault(obj) {
|
|
28
25
|
return obj && obj.__esModule ? obj : {
|
|
@@ -68,51 +65,13 @@ function _interopRequireWildcard(obj, nodeInterop) {
|
|
|
68
65
|
}
|
|
69
66
|
return newObj;
|
|
70
67
|
}
|
|
71
|
-
/* Traverse a given email layout data and compile extraction settings of every extractable
|
|
72
|
-
* field into a sorted map.
|
|
73
|
-
*
|
|
74
|
-
* NOTE: Currently we do NOT support content extraction at nested levels for email layouts.
|
|
75
|
-
*/ const compileExtractionSettings = (emailLayout)=>{
|
|
76
|
-
const extractableFields = (0, _lodash.get)(emailLayout, [
|
|
77
|
-
"__annotation",
|
|
78
|
-
"extractable_fields"
|
|
79
|
-
], {});
|
|
80
|
-
const map = new Map();
|
|
81
|
-
for (const [key] of Object.entries(emailLayout)){
|
|
82
|
-
// If the field we are on is extractable, then add its extraction
|
|
83
|
-
// settings to the map with the current object path.
|
|
84
|
-
if (key in extractableFields) {
|
|
85
|
-
map.set([
|
|
86
|
-
key
|
|
87
|
-
], extractableFields[key]);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return map;
|
|
91
|
-
};
|
|
92
|
-
/* Sanitize the email layout content into a format that's appropriate for reading
|
|
93
|
-
* and writing, by stripping out any annotation fields and handling readonly
|
|
94
|
-
* fields.
|
|
95
|
-
*/ const toEmailLayoutJson = (emailLayout)=>{
|
|
96
|
-
var _emailLayout___annotation;
|
|
97
|
-
// Move read only field under the dedicated field "__readonly".
|
|
98
|
-
const readonlyFields = ((_emailLayout___annotation = emailLayout.__annotation) === null || _emailLayout___annotation === void 0 ? void 0 : _emailLayout___annotation.readonly_fields) || [];
|
|
99
|
-
const [readonly, remainder] = (0, _objectIsomorphic.split)(emailLayout, readonlyFields);
|
|
100
|
-
const emailLayoutjson = {
|
|
101
|
-
...remainder,
|
|
102
|
-
__readonly: readonly
|
|
103
|
-
};
|
|
104
|
-
// Strip out all schema annotations, so not to expose them to end users.
|
|
105
|
-
return (0, _objectIsomorphic.omitDeep)(emailLayoutjson, [
|
|
106
|
-
"__annotation"
|
|
107
|
-
]);
|
|
108
|
-
};
|
|
109
68
|
const writeEmailLayoutDirFromData = async (emailLayoutDirCtx, remoteEmailLayout)=>{
|
|
110
69
|
// If the layout directory exists on the file system (i.e. previously
|
|
111
70
|
// pulled before), then read the layout file to use as a reference.
|
|
112
71
|
const [localEmailLayout] = emailLayoutDirCtx.exists ? await (0, _reader.readEmailLayoutDir)(emailLayoutDirCtx, {
|
|
113
72
|
withExtractedFiles: true
|
|
114
73
|
}) : [];
|
|
115
|
-
const bundle = buildEmailLayoutDirBundle(remoteEmailLayout, localEmailLayout);
|
|
74
|
+
const bundle = (0, _processorIsomorphic.buildEmailLayoutDirBundle)(remoteEmailLayout, localEmailLayout);
|
|
116
75
|
const backupDirPath = _nodePath.default.resolve(_const.sandboxDir, (0, _lodash.uniqueId)("backup"));
|
|
117
76
|
try {
|
|
118
77
|
// We store a backup in case there's an error.
|
|
@@ -122,7 +81,7 @@ const writeEmailLayoutDirFromData = async (emailLayoutDirCtx, remoteEmailLayout)
|
|
|
122
81
|
}
|
|
123
82
|
const promises = Object.entries(bundle).map(([relpath, fileContent])=>{
|
|
124
83
|
const filePath = _nodePath.default.resolve(emailLayoutDirCtx.abspath, relpath);
|
|
125
|
-
return relpath ===
|
|
84
|
+
return relpath === _processorIsomorphic.LAYOUT_JSON ? _fsExtra.outputJson(filePath, fileContent, {
|
|
126
85
|
spaces: _json.DOUBLE_SPACES
|
|
127
86
|
}) : _fsExtra.outputFile(filePath, fileContent);
|
|
128
87
|
});
|
|
@@ -142,48 +101,6 @@ const writeEmailLayoutDirFromData = async (emailLayoutDirCtx, remoteEmailLayout)
|
|
|
142
101
|
await _fsExtra.remove(backupDirPath);
|
|
143
102
|
}
|
|
144
103
|
};
|
|
145
|
-
/* For a given email layout payload, this function builds a "email layout directoy bundle".
|
|
146
|
-
* This is an object which contains all the relative paths and its file content.
|
|
147
|
-
* It includes the extractable fields, which are extracted out and added to the bundle as separate files.
|
|
148
|
-
*/ const buildEmailLayoutDirBundle = (remoteEmailLayout, localEmailLayout = {})=>{
|
|
149
|
-
const bundle = {};
|
|
150
|
-
const mutRemoteEmailLayout = (0, _lodash.cloneDeep)(remoteEmailLayout);
|
|
151
|
-
// A map of extraction settings of every field in the email layout
|
|
152
|
-
const compiledExtractionSettings = compileExtractionSettings(mutRemoteEmailLayout);
|
|
153
|
-
// Iterate through each extractable field, determine whether we need to
|
|
154
|
-
// extract the field content, and if so, perform the
|
|
155
|
-
// extraction.
|
|
156
|
-
for (const [objPathParts, extractionSettings] of compiledExtractionSettings){
|
|
157
|
-
// If this layout doesn't have this field path, then we don't extract.
|
|
158
|
-
if (!(0, _lodash.has)(mutRemoteEmailLayout, objPathParts)) continue;
|
|
159
|
-
// If the field at this path is extracted in the local layout, then
|
|
160
|
-
// always extract; otherwise extract based on the field settings default.
|
|
161
|
-
const objPathStr = _objectIsomorphic.ObjPath.stringify(objPathParts);
|
|
162
|
-
const extractedFilePath = (0, _lodash.get)(localEmailLayout, `${objPathStr}${_constIsomorphic.FILEPATH_MARKER}`);
|
|
163
|
-
const { default: extractByDefault , file_ext: fileExt } = extractionSettings;
|
|
164
|
-
if (!extractedFilePath && !extractByDefault) continue;
|
|
165
|
-
// By this point, we have a field where we need to extract its content.
|
|
166
|
-
const data = (0, _lodash.get)(mutRemoteEmailLayout, objPathParts);
|
|
167
|
-
const fileName = objPathParts.pop();
|
|
168
|
-
// If we have an extracted file path from the local layout, we use that. In the other
|
|
169
|
-
// case we use the default path.
|
|
170
|
-
const relpath = typeof extractedFilePath === "string" ? extractedFilePath : `${fileName}.${fileExt}`;
|
|
171
|
-
// Perform the extraction by adding the content and its file path to the
|
|
172
|
-
// bundle for writing to the file system later. Then replace the field
|
|
173
|
-
// content with the extracted file path and mark the field as extracted
|
|
174
|
-
// with @ suffix.
|
|
175
|
-
(0, _lodash.set)(bundle, [
|
|
176
|
-
relpath
|
|
177
|
-
], data);
|
|
178
|
-
(0, _lodash.set)(mutRemoteEmailLayout, `${objPathStr}${_constIsomorphic.FILEPATH_MARKER}`, relpath);
|
|
179
|
-
(0, _lodash.unset)(mutRemoteEmailLayout, objPathStr);
|
|
180
|
-
}
|
|
181
|
-
// At this point the bundle contains all extractable files, so we finally add the layout
|
|
182
|
-
// JSON realtive path + the file content.
|
|
183
|
-
return (0, _lodash.set)(bundle, [
|
|
184
|
-
_helpers.LAYOUT_JSON
|
|
185
|
-
], toEmailLayoutJson(mutRemoteEmailLayout));
|
|
186
|
-
};
|
|
187
104
|
const writeEmailLayoutIndexDir = async (indexDirCtx, remoteEmailLayouts)=>{
|
|
188
105
|
const backupDirPath = _nodePath.default.resolve(_const.sandboxDir, (0, _lodash.uniqueId)("backup"));
|
|
189
106
|
try {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* IMPORTANT: You must only expose exports from isomorphic modules.
|
|
3
|
+
*/ "use strict";
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
function _export(target, all) {
|
|
8
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: all[name]
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
_export(exports, {
|
|
14
|
+
buildEmailLayoutDirBundle: ()=>_processorIsomorphic.buildEmailLayoutDirBundle,
|
|
15
|
+
buildWorkflowDirBundle: ()=>_processorIsomorphic1.buildWorkflowDirBundle
|
|
16
|
+
});
|
|
17
|
+
const _processorIsomorphic = require("./email-layout/processor.isomorphic");
|
|
18
|
+
const _processorIsomorphic1 = require("./workflow/processor.isomorphic");
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knocklabs/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "Knock CLI",
|
|
5
5
|
"author": "@knocklabs",
|
|
6
6
|
"bin": {
|
|
@@ -25,18 +25,18 @@
|
|
|
25
25
|
"date-fns": "^2.30.0",
|
|
26
26
|
"enquirer": "^2.4.1",
|
|
27
27
|
"fs-extra": "^11.1.1",
|
|
28
|
-
"liquidjs": "^10.9.
|
|
28
|
+
"liquidjs": "^10.9.4",
|
|
29
29
|
"locale-codes": "^1.3.1",
|
|
30
30
|
"lodash": "^4.17.21",
|
|
31
31
|
"yup": "^1.3.2"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@oclif/test": "^2.5.6",
|
|
35
|
-
"@swc/cli": "^0.1.
|
|
35
|
+
"@swc/cli": "^0.1.63",
|
|
36
36
|
"@swc/core": "^1.3.37",
|
|
37
37
|
"@swc/helpers": "^0.4.14",
|
|
38
38
|
"@types/chai": "^4",
|
|
39
|
-
"@types/fs-extra": "^11.0.
|
|
39
|
+
"@types/fs-extra": "^11.0.4",
|
|
40
40
|
"@types/mocha": "^10.0.1",
|
|
41
41
|
"@types/node": "^20.9.0",
|
|
42
42
|
"chai": "^4",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"eslint-plugin-prettier": "^4.2.1",
|
|
48
48
|
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
49
49
|
"mocha": "^10",
|
|
50
|
-
"nock": "^13.
|
|
50
|
+
"nock": "^13.4.0",
|
|
51
51
|
"oclif": "^3",
|
|
52
52
|
"prettier": "2.8.8",
|
|
53
53
|
"shx": "^0.3.4",
|