@knocklabs/cli 1.1.1 → 1.2.2
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 +297 -170
- package/dist/commands/audience/new.js +2 -2
- package/dist/commands/branch/rebase.js +65 -0
- package/dist/commands/commit/index.js +15 -11
- package/dist/commands/commit/list.js +2 -8
- package/dist/commands/guide/get.js +6 -0
- package/dist/commands/guide/list.js +6 -0
- package/dist/commands/guide/push.js +1 -0
- package/dist/commands/layout/push.js +1 -0
- package/dist/commands/message-type/push.js +1 -0
- package/dist/commands/partial/push.js +1 -0
- package/dist/commands/push.js +4 -0
- package/dist/commands/schema/pull.js +197 -0
- package/dist/commands/schema/push.js +203 -0
- package/dist/commands/source/get.js +180 -0
- package/dist/commands/source/list.js +96 -0
- package/dist/commands/translation/push.js +1 -0
- package/dist/commands/whoami.js +8 -2
- package/dist/commands/workflow/get.js +6 -0
- package/dist/commands/workflow/list.js +6 -0
- package/dist/commands/workflow/push.js +1 -0
- package/dist/commands/workflow/run.js +6 -0
- package/dist/help.js +74 -0
- package/dist/lib/api-v1.js +78 -1
- package/dist/lib/auth.js +3 -2
- package/dist/lib/helpers/flag.js +15 -0
- package/dist/lib/marshal/guide/helpers.js +11 -0
- package/dist/lib/marshal/schema/helpers.js +142 -0
- package/dist/lib/marshal/schema/index.js +21 -0
- package/dist/lib/marshal/schema/reader.js +177 -0
- package/dist/lib/marshal/schema/types.js +15 -0
- package/dist/lib/marshal/schema/writer.js +154 -0
- package/dist/lib/marshal/shared/helpers.js +30 -14
- package/dist/lib/marshal/source/helpers.js +28 -0
- package/dist/lib/marshal/source/index.js +19 -0
- package/dist/lib/marshal/source/types.js +4 -0
- package/dist/lib/marshal/workflow/generator.js +11 -8
- package/dist/lib/marshal/workflow/helpers.js +10 -6
- package/dist/lib/resources.js +11 -0
- package/npm-shrinkwrap.json +10698 -0
- package/oclif.manifest.json +448 -11
- package/package.json +22 -15
|
@@ -0,0 +1,142 @@
|
|
|
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: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get SCHEMA_FILE_SCHEMA () {
|
|
13
|
+
return SCHEMA_FILE_SCHEMA;
|
|
14
|
+
},
|
|
15
|
+
get isSchemaItemType () {
|
|
16
|
+
return isSchemaItemType;
|
|
17
|
+
},
|
|
18
|
+
get resolveSchemasDir () {
|
|
19
|
+
return resolveSchemasDir;
|
|
20
|
+
},
|
|
21
|
+
get schemaFileContext () {
|
|
22
|
+
return schemaFileContext;
|
|
23
|
+
},
|
|
24
|
+
get schemaFilePath () {
|
|
25
|
+
return schemaFilePath;
|
|
26
|
+
},
|
|
27
|
+
get schemaTargetFromData () {
|
|
28
|
+
return schemaTargetFromData;
|
|
29
|
+
},
|
|
30
|
+
get validateSchemaCollection () {
|
|
31
|
+
return validateSchemaCollection;
|
|
32
|
+
},
|
|
33
|
+
get validateSchemaItemType () {
|
|
34
|
+
return validateSchemaItemType;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
|
|
38
|
+
const _fsextra = /*#__PURE__*/ _interop_require_wildcard(require("fs-extra"));
|
|
39
|
+
const _types = require("./types");
|
|
40
|
+
function _interop_require_default(obj) {
|
|
41
|
+
return obj && obj.__esModule ? obj : {
|
|
42
|
+
default: obj
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
46
|
+
if (typeof WeakMap !== "function") return null;
|
|
47
|
+
var cacheBabelInterop = new WeakMap();
|
|
48
|
+
var cacheNodeInterop = new WeakMap();
|
|
49
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
50
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
51
|
+
})(nodeInterop);
|
|
52
|
+
}
|
|
53
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
54
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
55
|
+
return obj;
|
|
56
|
+
}
|
|
57
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
58
|
+
return {
|
|
59
|
+
default: obj
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
63
|
+
if (cache && cache.has(obj)) {
|
|
64
|
+
return cache.get(obj);
|
|
65
|
+
}
|
|
66
|
+
var newObj = {
|
|
67
|
+
__proto__: null
|
|
68
|
+
};
|
|
69
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
70
|
+
for(var key in obj){
|
|
71
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
72
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
73
|
+
if (desc && (desc.get || desc.set)) {
|
|
74
|
+
Object.defineProperty(newObj, key, desc);
|
|
75
|
+
} else {
|
|
76
|
+
newObj[key] = obj[key];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
newObj.default = obj;
|
|
81
|
+
if (cache) {
|
|
82
|
+
cache.set(obj, newObj);
|
|
83
|
+
}
|
|
84
|
+
return newObj;
|
|
85
|
+
}
|
|
86
|
+
const SCHEMA_FILE_SCHEMA = "https://schemas.knock.app/cli/schema.json";
|
|
87
|
+
const isSchemaItemType = (value)=>_types.SCHEMA_ITEM_TYPES.includes(value);
|
|
88
|
+
const validateSchemaItemType = (value)=>{
|
|
89
|
+
if (!isSchemaItemType(value)) {
|
|
90
|
+
throw new Error(`Invalid item type \`${value}\`. Must be one of: ${_types.SCHEMA_ITEM_TYPES.join(", ")}`);
|
|
91
|
+
}
|
|
92
|
+
return value;
|
|
93
|
+
};
|
|
94
|
+
const validateSchemaCollection = (collection)=>{
|
|
95
|
+
if (!collection || collection.includes("/") || collection.includes("\\") || collection === "." || collection === "..") {
|
|
96
|
+
throw new Error(`Invalid object collection \`${collection}\``);
|
|
97
|
+
}
|
|
98
|
+
return collection;
|
|
99
|
+
};
|
|
100
|
+
const resolveSchemasDir = async (projectConfig, basePath)=>{
|
|
101
|
+
const schemasDirPath = projectConfig ? _nodepath.default.resolve(_nodepath.default.isAbsolute(projectConfig.knockDir) ? projectConfig.knockDir : _nodepath.default.resolve(basePath, projectConfig.knockDir), "schemas") : _nodepath.default.resolve(basePath, "schemas");
|
|
102
|
+
const exists = await _fsextra.pathExists(schemasDirPath);
|
|
103
|
+
if (exists && !(await _fsextra.lstat(schemasDirPath)).isDirectory()) {
|
|
104
|
+
throw new Error(`${schemasDirPath} is not a directory`);
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
abspath: schemasDirPath,
|
|
108
|
+
exists
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
const schemaFilePath = (schemasDirPath, itemType, collection)=>{
|
|
112
|
+
if (itemType === "object") {
|
|
113
|
+
return _nodepath.default.resolve(schemasDirPath, "objects", `${validateSchemaCollection(collection !== null && collection !== void 0 ? collection : "")}.json`);
|
|
114
|
+
}
|
|
115
|
+
return _nodepath.default.resolve(schemasDirPath, `${itemType}.json`);
|
|
116
|
+
};
|
|
117
|
+
const schemaFileContext = async (schemasDirPath, itemType, collection)=>{
|
|
118
|
+
const abspath = schemaFilePath(schemasDirPath, itemType, collection);
|
|
119
|
+
const exists = await _fsextra.pathExists(abspath);
|
|
120
|
+
if (exists && !(await _fsextra.lstat(abspath)).isFile()) {
|
|
121
|
+
throw new Error(`${abspath} is not a file`);
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
itemType,
|
|
125
|
+
collection,
|
|
126
|
+
abspath,
|
|
127
|
+
exists
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
const schemaTargetFromData = (schema)=>{
|
|
131
|
+
const itemType = validateSchemaItemType(schema.item_type);
|
|
132
|
+
if (itemType === "object") {
|
|
133
|
+
var _schema_item_id;
|
|
134
|
+
return {
|
|
135
|
+
itemType,
|
|
136
|
+
collection: validateSchemaCollection((_schema_item_id = schema.item_id) !== null && _schema_item_id !== void 0 ? _schema_item_id : "")
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
itemType
|
|
141
|
+
};
|
|
142
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./helpers"), exports);
|
|
6
|
+
_export_star(require("./reader"), exports);
|
|
7
|
+
_export_star(require("./types"), exports);
|
|
8
|
+
_export_star(require("./writer"), exports);
|
|
9
|
+
function _export_star(from, to) {
|
|
10
|
+
Object.keys(from).forEach(function(k) {
|
|
11
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
12
|
+
Object.defineProperty(to, k, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function() {
|
|
15
|
+
return from[k];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return from;
|
|
21
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
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: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get readAllSchemaFiles () {
|
|
13
|
+
return readAllSchemaFiles;
|
|
14
|
+
},
|
|
15
|
+
get readSchemaFile () {
|
|
16
|
+
return readSchemaFile;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
|
|
20
|
+
const _fsextra = /*#__PURE__*/ _interop_require_wildcard(require("fs-extra"));
|
|
21
|
+
const _error = require("../../helpers/error");
|
|
22
|
+
const _json = require("../../helpers/json");
|
|
23
|
+
const _objectisomorphic = require("../../helpers/object.isomorphic");
|
|
24
|
+
const _helpers = require("./helpers");
|
|
25
|
+
function _interop_require_default(obj) {
|
|
26
|
+
return obj && obj.__esModule ? obj : {
|
|
27
|
+
default: obj
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
31
|
+
if (typeof WeakMap !== "function") return null;
|
|
32
|
+
var cacheBabelInterop = new WeakMap();
|
|
33
|
+
var cacheNodeInterop = new WeakMap();
|
|
34
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
35
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
36
|
+
})(nodeInterop);
|
|
37
|
+
}
|
|
38
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
39
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
40
|
+
return obj;
|
|
41
|
+
}
|
|
42
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
43
|
+
return {
|
|
44
|
+
default: obj
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
48
|
+
if (cache && cache.has(obj)) {
|
|
49
|
+
return cache.get(obj);
|
|
50
|
+
}
|
|
51
|
+
var newObj = {
|
|
52
|
+
__proto__: null
|
|
53
|
+
};
|
|
54
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
55
|
+
for(var key in obj){
|
|
56
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
57
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
58
|
+
if (desc && (desc.get || desc.set)) {
|
|
59
|
+
Object.defineProperty(newObj, key, desc);
|
|
60
|
+
} else {
|
|
61
|
+
newObj[key] = obj[key];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
newObj.default = obj;
|
|
66
|
+
if (cache) {
|
|
67
|
+
cache.set(obj, newObj);
|
|
68
|
+
}
|
|
69
|
+
return newObj;
|
|
70
|
+
}
|
|
71
|
+
const readSchemaFile = async (schemaFileCtx)=>{
|
|
72
|
+
if (!schemaFileCtx.exists) {
|
|
73
|
+
throw new Error(`Cannot locate schema file at \`${schemaFileCtx.abspath}\``);
|
|
74
|
+
}
|
|
75
|
+
const [schemaJson, readErrors] = await (0, _json.readJson)(schemaFileCtx.abspath);
|
|
76
|
+
if (!schemaJson) {
|
|
77
|
+
return [
|
|
78
|
+
undefined,
|
|
79
|
+
[
|
|
80
|
+
new _error.SourceError((0, _error.formatErrors)(readErrors), schemaFileCtx.abspath)
|
|
81
|
+
]
|
|
82
|
+
];
|
|
83
|
+
}
|
|
84
|
+
const schema = (0, _objectisomorphic.omitDeep)(schemaJson, [
|
|
85
|
+
"$schema",
|
|
86
|
+
"__readonly"
|
|
87
|
+
]);
|
|
88
|
+
return [
|
|
89
|
+
schema,
|
|
90
|
+
[]
|
|
91
|
+
];
|
|
92
|
+
};
|
|
93
|
+
const readAllSchemaFiles = async (schemasDirPath)=>{
|
|
94
|
+
if (!await _fsextra.pathExists(schemasDirPath)) {
|
|
95
|
+
throw new Error(`Cannot locate schema files in \`${schemasDirPath}\``);
|
|
96
|
+
}
|
|
97
|
+
const schemas = [];
|
|
98
|
+
const errors = [];
|
|
99
|
+
for (const itemType of [
|
|
100
|
+
"user",
|
|
101
|
+
"tenant"
|
|
102
|
+
]){
|
|
103
|
+
// eslint-disable-next-line no-await-in-loop
|
|
104
|
+
const ctx = await (0, _helpers.schemaFileContext)(schemasDirPath, itemType);
|
|
105
|
+
if (!ctx.exists) continue;
|
|
106
|
+
// eslint-disable-next-line no-await-in-loop
|
|
107
|
+
const [content, readErrors] = await readSchemaFile(ctx);
|
|
108
|
+
if (readErrors.length > 0) {
|
|
109
|
+
errors.push(...readErrors);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
schemas.push({
|
|
113
|
+
...ctx,
|
|
114
|
+
content: content
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
const objectsDirPath = _nodepath.default.resolve(schemasDirPath, "objects");
|
|
118
|
+
if (await _fsextra.pathExists(objectsDirPath)) {
|
|
119
|
+
const dirents = await _fsextra.readdir(objectsDirPath, {
|
|
120
|
+
withFileTypes: true
|
|
121
|
+
});
|
|
122
|
+
for (const dirent of dirents){
|
|
123
|
+
if (!dirent.isFile() || !dirent.name.endsWith(".json")) continue;
|
|
124
|
+
const collection = _nodepath.default.basename(dirent.name, ".json");
|
|
125
|
+
// An invalid filename (e.g. `..json`) fails collection validation;
|
|
126
|
+
// collect it like any other read error instead of aborting the run.
|
|
127
|
+
let ctx;
|
|
128
|
+
try {
|
|
129
|
+
// eslint-disable-next-line no-await-in-loop
|
|
130
|
+
ctx = await (0, _helpers.schemaFileContext)(schemasDirPath, "object", collection);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
errors.push(new _error.SourceError(error.message, _nodepath.default.resolve(objectsDirPath, dirent.name), "ReadError"));
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
// eslint-disable-next-line no-await-in-loop
|
|
136
|
+
const [content, readErrors] = await readSchemaFile(ctx);
|
|
137
|
+
if (readErrors.length > 0) {
|
|
138
|
+
errors.push(...readErrors);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
schemas.push({
|
|
142
|
+
...ctx,
|
|
143
|
+
content: content
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const validated = [];
|
|
148
|
+
for (const schema of schemas){
|
|
149
|
+
try {
|
|
150
|
+
const itemType = (0, _helpers.validateSchemaItemType)(schema.content.item_type);
|
|
151
|
+
// The file path determines where a schema is pushed, so a file that
|
|
152
|
+
// declares a different item_type is ambiguous. Error instead of silently
|
|
153
|
+
// reinterpreting it.
|
|
154
|
+
if (itemType !== schema.itemType) {
|
|
155
|
+
throw new Error(`Schema file declares item_type \`${itemType}\` but its file path implies \`${schema.itemType}\``);
|
|
156
|
+
}
|
|
157
|
+
// Same for an object schema whose declared item_id disagrees with its
|
|
158
|
+
// objects/<collection>.json path.
|
|
159
|
+
if (itemType === "object" && schema.content.item_id && schema.content.item_id !== schema.collection) {
|
|
160
|
+
throw new Error(`Schema file declares item_id \`${schema.content.item_id}\` but its file path implies \`${schema.collection}\``);
|
|
161
|
+
}
|
|
162
|
+
validated.push({
|
|
163
|
+
...schema,
|
|
164
|
+
content: {
|
|
165
|
+
...schema.content,
|
|
166
|
+
item_type: itemType
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
} catch (error) {
|
|
170
|
+
errors.push(new _error.SourceError(error.message, schema.abspath, "ReadError"));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return [
|
|
174
|
+
validated,
|
|
175
|
+
errors
|
|
176
|
+
];
|
|
177
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "SCHEMA_ITEM_TYPES", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return SCHEMA_ITEM_TYPES;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const SCHEMA_ITEM_TYPES = [
|
|
12
|
+
"user",
|
|
13
|
+
"tenant",
|
|
14
|
+
"object"
|
|
15
|
+
];
|
|
@@ -0,0 +1,154 @@
|
|
|
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: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get schemaJsonForWrite () {
|
|
13
|
+
return schemaJsonForWrite;
|
|
14
|
+
},
|
|
15
|
+
get writeSchemaFileFromData () {
|
|
16
|
+
return writeSchemaFileFromData;
|
|
17
|
+
},
|
|
18
|
+
get writeSchemasIndexDir () {
|
|
19
|
+
return writeSchemasIndexDir;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
|
|
23
|
+
const _fsextra = /*#__PURE__*/ _interop_require_wildcard(require("fs-extra"));
|
|
24
|
+
const _lodash = require("lodash");
|
|
25
|
+
const _const = require("../../helpers/const");
|
|
26
|
+
const _json = require("../../helpers/json");
|
|
27
|
+
const _helpers = require("./helpers");
|
|
28
|
+
function _interop_require_default(obj) {
|
|
29
|
+
return obj && obj.__esModule ? obj : {
|
|
30
|
+
default: obj
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
34
|
+
if (typeof WeakMap !== "function") return null;
|
|
35
|
+
var cacheBabelInterop = new WeakMap();
|
|
36
|
+
var cacheNodeInterop = new WeakMap();
|
|
37
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
38
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
39
|
+
})(nodeInterop);
|
|
40
|
+
}
|
|
41
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
42
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
43
|
+
return obj;
|
|
44
|
+
}
|
|
45
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
46
|
+
return {
|
|
47
|
+
default: obj
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
51
|
+
if (cache && cache.has(obj)) {
|
|
52
|
+
return cache.get(obj);
|
|
53
|
+
}
|
|
54
|
+
var newObj = {
|
|
55
|
+
__proto__: null
|
|
56
|
+
};
|
|
57
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
58
|
+
for(var key in obj){
|
|
59
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
60
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
61
|
+
if (desc && (desc.get || desc.set)) {
|
|
62
|
+
Object.defineProperty(newObj, key, desc);
|
|
63
|
+
} else {
|
|
64
|
+
newObj[key] = obj[key];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
newObj.default = obj;
|
|
69
|
+
if (cache) {
|
|
70
|
+
cache.set(obj, newObj);
|
|
71
|
+
}
|
|
72
|
+
return newObj;
|
|
73
|
+
}
|
|
74
|
+
const schemaJsonForWrite = (schema)=>{
|
|
75
|
+
var _schema_item_id, _schema_item_id1;
|
|
76
|
+
return {
|
|
77
|
+
$schema: _helpers.SCHEMA_FILE_SCHEMA,
|
|
78
|
+
item_type: schema.item_type,
|
|
79
|
+
item_id: (_schema_item_id = schema.item_id) !== null && _schema_item_id !== void 0 ? _schema_item_id : null,
|
|
80
|
+
properties: schema.properties,
|
|
81
|
+
__readonly: {
|
|
82
|
+
item_type: schema.item_type,
|
|
83
|
+
item_id: (_schema_item_id1 = schema.item_id) !== null && _schema_item_id1 !== void 0 ? _schema_item_id1 : null
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
const writeSchemaFileFromData = async (schemaFileCtx, schema)=>{
|
|
88
|
+
await _fsextra.outputJson(schemaFileCtx.abspath, schemaJsonForWrite(schema), {
|
|
89
|
+
spaces: _json.DOUBLE_SPACES
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
/*
|
|
93
|
+
* Prunes schema files that are no longer present in the remote set, so a later
|
|
94
|
+
* `schema push --all` cannot push stale schemas back into the environment.
|
|
95
|
+
* Only removes the file shapes push reads (user.json, tenant.json, and
|
|
96
|
+
* objects/<collection>.json); anything else in the directory is left alone.
|
|
97
|
+
*/ const pruneSchemasIndexDir = async (schemasDirPath, remoteSchemas)=>{
|
|
98
|
+
const expectedPaths = new Set(remoteSchemas.map((schema)=>{
|
|
99
|
+
const { itemType, collection } = (0, _helpers.schemaTargetFromData)(schema);
|
|
100
|
+
return (0, _helpers.schemaFilePath)(schemasDirPath, itemType, collection);
|
|
101
|
+
}));
|
|
102
|
+
const candidatePaths = [
|
|
103
|
+
_nodepath.default.resolve(schemasDirPath, "user.json"),
|
|
104
|
+
_nodepath.default.resolve(schemasDirPath, "tenant.json")
|
|
105
|
+
];
|
|
106
|
+
const objectsDirPath = _nodepath.default.resolve(schemasDirPath, "objects");
|
|
107
|
+
if (await _fsextra.pathExists(objectsDirPath)) {
|
|
108
|
+
const dirents = await _fsextra.readdir(objectsDirPath, {
|
|
109
|
+
withFileTypes: true
|
|
110
|
+
});
|
|
111
|
+
for (const dirent of dirents){
|
|
112
|
+
if (dirent.isFile() && dirent.name.endsWith(".json")) {
|
|
113
|
+
candidatePaths.push(_nodepath.default.resolve(objectsDirPath, dirent.name));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
await Promise.all(candidatePaths.filter((abspath)=>!expectedPaths.has(abspath)).map((abspath)=>_fsextra.remove(abspath)));
|
|
118
|
+
};
|
|
119
|
+
const writeSchemasIndexDir = async (schemasDirPath, schemas)=>{
|
|
120
|
+
const dirExists = await _fsextra.pathExists(schemasDirPath);
|
|
121
|
+
const backupDirPath = _nodepath.default.resolve(_const.sandboxDir, (0, _lodash.uniqueId)("backup"));
|
|
122
|
+
let backedUp = false;
|
|
123
|
+
try {
|
|
124
|
+
// If the schemas directory already exists, back it up in the temp sandbox
|
|
125
|
+
// before pruning stale files, so a failed write can restore it.
|
|
126
|
+
if (dirExists) {
|
|
127
|
+
await _fsextra.copy(schemasDirPath, backupDirPath);
|
|
128
|
+
backedUp = true;
|
|
129
|
+
await pruneSchemasIndexDir(schemasDirPath, schemas);
|
|
130
|
+
}
|
|
131
|
+
for (const schema of schemas){
|
|
132
|
+
const { itemType, collection } = (0, _helpers.schemaTargetFromData)(schema);
|
|
133
|
+
// eslint-disable-next-line no-await-in-loop
|
|
134
|
+
const ctx = await (0, _helpers.schemaFileContext)(schemasDirPath, itemType, collection);
|
|
135
|
+
// eslint-disable-next-line no-await-in-loop
|
|
136
|
+
await writeSchemaFileFromData(ctx, schema);
|
|
137
|
+
}
|
|
138
|
+
} catch (error) {
|
|
139
|
+
// In case of any error, wipe the schemas directory that is likely in a bad
|
|
140
|
+
// state then restore the backup, but only when the backup completed. If
|
|
141
|
+
// the backup copy itself failed, nothing has touched the original tree, so
|
|
142
|
+
// leave it alone.
|
|
143
|
+
if (dirExists && backedUp) {
|
|
144
|
+
await _fsextra.emptyDir(schemasDirPath);
|
|
145
|
+
await _fsextra.copy(backupDirPath, schemasDirPath);
|
|
146
|
+
} else if (!dirExists) {
|
|
147
|
+
await _fsextra.remove(schemasDirPath);
|
|
148
|
+
}
|
|
149
|
+
throw error;
|
|
150
|
+
} finally{
|
|
151
|
+
// Always clean up the backup directory in the temp sandbox.
|
|
152
|
+
await _fsextra.remove(backupDirPath);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
@@ -71,6 +71,21 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
71
71
|
const DECODABLE_JSON_FILES = new Set([
|
|
72
72
|
_workflow.VISUAL_BLOCKS_JSON
|
|
73
73
|
]);
|
|
74
|
+
const validateLiquidSyntaxDeep = (content)=>{
|
|
75
|
+
if (typeof content === "string") return (0, _liquid.validateLiquidSyntax)(content);
|
|
76
|
+
if (Array.isArray(content)) {
|
|
77
|
+
for (const item of content){
|
|
78
|
+
const liquidParseError = validateLiquidSyntaxDeep(item);
|
|
79
|
+
if (liquidParseError) return liquidParseError;
|
|
80
|
+
}
|
|
81
|
+
} else if (content && typeof content === "object") {
|
|
82
|
+
for (const value of Object.values(content)){
|
|
83
|
+
const liquidParseError = validateLiquidSyntaxDeep(value);
|
|
84
|
+
if (liquidParseError) return liquidParseError;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return undefined;
|
|
88
|
+
};
|
|
74
89
|
const readExtractedFileSync = (relpath, dirCtx, objPathToFieldStr = "")=>{
|
|
75
90
|
// Check if the file actually exists at the given file path.
|
|
76
91
|
const abspath = _nodepath.resolve(dirCtx.abspath, relpath);
|
|
@@ -85,22 +100,11 @@ const readExtractedFileSync = (relpath, dirCtx, objPathToFieldStr = "")=>{
|
|
|
85
100
|
// Read the file and check for valid liquid syntax given it is supported
|
|
86
101
|
// across all message templates and file extensions.
|
|
87
102
|
const contentStr = _fsextra.readFileSync(abspath, "utf8");
|
|
88
|
-
const liquidParseError = (0, _liquid.validateLiquidSyntax)(contentStr);
|
|
89
|
-
if (liquidParseError) {
|
|
90
|
-
const error = new _error.JsonDataError(`points to a file that contains invalid liquid syntax (${relpath})\n\n` + (0, _error.formatErrors)([
|
|
91
|
-
liquidParseError
|
|
92
|
-
], {
|
|
93
|
-
indentBy: 2
|
|
94
|
-
}), objPathToFieldStr);
|
|
95
|
-
return [
|
|
96
|
-
undefined,
|
|
97
|
-
error
|
|
98
|
-
];
|
|
99
|
-
}
|
|
100
|
-
// If the file is expected to contain decodable json, then parse the contentStr
|
|
101
|
-
// as such.
|
|
102
103
|
const fileName = _nodepath.basename(abspath.toLowerCase());
|
|
103
104
|
const decodable = DECODABLE_JSON_FILES.has(fileName);
|
|
105
|
+
// If the file is expected to contain decodable json, parse the contentStr
|
|
106
|
+
// first so Liquid inside JSON string values is validated after JSON unescapes
|
|
107
|
+
// string delimiters (e.g. \"Doc\" -> "Doc").
|
|
104
108
|
const [content, jsonParseErrors] = decodable ? (0, _json.parseJson)(contentStr) : [
|
|
105
109
|
contentStr,
|
|
106
110
|
[]
|
|
@@ -114,6 +118,18 @@ const readExtractedFileSync = (relpath, dirCtx, objPathToFieldStr = "")=>{
|
|
|
114
118
|
error
|
|
115
119
|
];
|
|
116
120
|
}
|
|
121
|
+
const liquidParseError = decodable ? validateLiquidSyntaxDeep(content) : (0, _liquid.validateLiquidSyntax)(contentStr);
|
|
122
|
+
if (liquidParseError) {
|
|
123
|
+
const error = new _error.JsonDataError(`points to a file that contains invalid liquid syntax (${relpath})\n\n` + (0, _error.formatErrors)([
|
|
124
|
+
liquidParseError
|
|
125
|
+
], {
|
|
126
|
+
indentBy: 2
|
|
127
|
+
}), objPathToFieldStr);
|
|
128
|
+
return [
|
|
129
|
+
undefined,
|
|
130
|
+
error
|
|
131
|
+
];
|
|
132
|
+
}
|
|
117
133
|
return [
|
|
118
134
|
content,
|
|
119
135
|
undefined
|
|
@@ -0,0 +1,28 @@
|
|
|
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: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get formatMappingStatus () {
|
|
13
|
+
return formatMappingStatus;
|
|
14
|
+
},
|
|
15
|
+
get formatPreprocessScript () {
|
|
16
|
+
return formatPreprocessScript;
|
|
17
|
+
},
|
|
18
|
+
get formatSettingValue () {
|
|
19
|
+
return formatSettingValue;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const formatSettingValue = (value)=>{
|
|
23
|
+
if (value === undefined || value === null || value === "") return "-";
|
|
24
|
+
if (typeof value === "boolean") return value ? "Yes" : "No";
|
|
25
|
+
return String(value);
|
|
26
|
+
};
|
|
27
|
+
const formatPreprocessScript = (settings)=>settings.preprocess_script ? settings.preprocess_script.language : "-";
|
|
28
|
+
const formatMappingStatus = (mapping)=>mapping.active ? "Active" : "Inactive";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./helpers"), exports);
|
|
6
|
+
_export_star(require("./types"), exports);
|
|
7
|
+
function _export_star(from, to) {
|
|
8
|
+
Object.keys(from).forEach(function(k) {
|
|
9
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
10
|
+
Object.defineProperty(to, k, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function() {
|
|
13
|
+
return from[k];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return from;
|
|
19
|
+
}
|