@knocklabs/cli 1.1.2 → 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.
Files changed (41) hide show
  1. package/README.md +297 -170
  2. package/dist/commands/audience/new.js +2 -2
  3. package/dist/commands/branch/rebase.js +65 -0
  4. package/dist/commands/commit/index.js +15 -11
  5. package/dist/commands/commit/list.js +2 -8
  6. package/dist/commands/guide/get.js +6 -0
  7. package/dist/commands/guide/list.js +6 -0
  8. package/dist/commands/guide/push.js +1 -0
  9. package/dist/commands/layout/push.js +1 -0
  10. package/dist/commands/message-type/push.js +1 -0
  11. package/dist/commands/partial/push.js +1 -0
  12. package/dist/commands/push.js +4 -0
  13. package/dist/commands/schema/pull.js +197 -0
  14. package/dist/commands/schema/push.js +203 -0
  15. package/dist/commands/source/get.js +180 -0
  16. package/dist/commands/source/list.js +96 -0
  17. package/dist/commands/translation/push.js +1 -0
  18. package/dist/commands/whoami.js +8 -2
  19. package/dist/commands/workflow/get.js +6 -0
  20. package/dist/commands/workflow/list.js +6 -0
  21. package/dist/commands/workflow/push.js +1 -0
  22. package/dist/commands/workflow/run.js +6 -0
  23. package/dist/help.js +74 -0
  24. package/dist/lib/api-v1.js +78 -1
  25. package/dist/lib/auth.js +3 -2
  26. package/dist/lib/helpers/flag.js +15 -0
  27. package/dist/lib/marshal/guide/helpers.js +11 -0
  28. package/dist/lib/marshal/schema/helpers.js +142 -0
  29. package/dist/lib/marshal/schema/index.js +21 -0
  30. package/dist/lib/marshal/schema/reader.js +177 -0
  31. package/dist/lib/marshal/schema/types.js +15 -0
  32. package/dist/lib/marshal/schema/writer.js +154 -0
  33. package/dist/lib/marshal/source/helpers.js +28 -0
  34. package/dist/lib/marshal/source/index.js +19 -0
  35. package/dist/lib/marshal/source/types.js +4 -0
  36. package/dist/lib/marshal/workflow/generator.js +11 -8
  37. package/dist/lib/marshal/workflow/helpers.js +10 -6
  38. package/dist/lib/resources.js +11 -0
  39. package/npm-shrinkwrap.json +10698 -0
  40. package/oclif.manifest.json +448 -11
  41. 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
+ };
@@ -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
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
@@ -157,7 +157,7 @@ const scaffoldInAppFeedChannelStep = (refSuffix, channels)=>{
157
157
  const scaffoldedStep = {
158
158
  ref: stepRef,
159
159
  type: _types.StepType.Channel,
160
- channel_key: firstChannel ? firstChannel.key : "<IN-APP-FEED CHANNEL KEY>",
160
+ channel_key: firstChannel ? firstChannel.key : "<IN_APP_FEED CHANNEL KEY>",
161
161
  template: {
162
162
  action_url: "{{ vars.app_url }}",
163
163
  ["markdown_body" + _constisomorphic.FILEPATH_MARKER]: templateFilePath
@@ -239,7 +239,7 @@ const STEP_TAGS = [
239
239
  "batch",
240
240
  "fetch",
241
241
  "email",
242
- "in-app-feed",
242
+ "in_app_feed",
243
243
  "sms",
244
244
  "push",
245
245
  "chat"
@@ -249,7 +249,7 @@ const StepTagChoices = {
249
249
  batch: "Batch step",
250
250
  fetch: "HTTP Fetch step",
251
251
  email: "Email channel step",
252
- "in-app-feed": "In-app feed channel step",
252
+ in_app_feed: "In-app feed channel step",
253
253
  sms: "SMS channel step",
254
254
  push: "Push channel step",
255
255
  chat: "Chat channel step"
@@ -261,13 +261,16 @@ const stepScaffoldFuncs = {
261
261
  fetch: scaffoldHttpFetchStep,
262
262
  // Channel steps
263
263
  email: scaffoldEmailChannelStep,
264
- "in-app-feed": scaffoldInAppFeedChannelStep,
264
+ in_app_feed: scaffoldInAppFeedChannelStep,
265
265
  sms: scaffoldSmsChannelStep,
266
266
  push: scaffoldPushChannelStep,
267
267
  chat: scaffoldChatChannelStep
268
268
  };
269
+ // Accept "in-app-feed" for backward compatibility, but normalize to the snake
270
+ // case one as the canonical tag.
271
+ const normalizeStepTag = (tag)=>tag === "in-app-feed" ? "in_app_feed" : tag;
269
272
  const parseStepsInput = (input, availableStepTypes)=>{
270
- const tags = input.split(",").filter((x)=>x);
273
+ const tags = input.split(",").filter((x)=>x).map((tag)=>normalizeStepTag(tag));
271
274
  const invalidTags = tags.filter((tag)=>!availableStepTypes.includes(tag));
272
275
  if (invalidTags.length > 0) {
273
276
  return [
@@ -286,7 +289,7 @@ const getAvailableStepTypes = (channelTypes)=>{
286
289
  switch(stepTag){
287
290
  case "email":
288
291
  return channelTypes.includes("email");
289
- case "in-app-feed":
292
+ case "in_app_feed":
290
293
  return channelTypes.includes("in_app_feed");
291
294
  case "sms":
292
295
  return channelTypes.includes("sms");
@@ -310,12 +313,11 @@ const scaffoldWorkflowDirBundle = (attrs, channelsByType)=>{
310
313
  const stepCount = ++stepCountByTag[tag];
311
314
  switch(tag){
312
315
  case "email":
316
+ case "in_app_feed":
313
317
  case "sms":
314
318
  case "push":
315
319
  case "chat":
316
320
  return stepScaffoldFuncs[tag](stepCount, (0, _lodash.get)(channelsByType, tag, []));
317
- case "in-app-feed":
318
- return stepScaffoldFuncs[tag](stepCount, (0, _lodash.get)(channelsByType, "in_app_feed", []));
319
321
  default:
320
322
  return stepScaffoldFuncs[tag](stepCount);
321
323
  }
@@ -348,6 +350,7 @@ function swapChannelReferences(step, channelsByType) {
348
350
  ...step,
349
351
  channel_key: (_channelsByType_email_ = channelsByType.email[0]) === null || _channelsByType_email_ === void 0 ? void 0 : _channelsByType_email_.key
350
352
  };
353
+ case "in_app_feed":
351
354
  case "in-app-feed":
352
355
  case "knock-in-app-feed":
353
356
  case "knock-feed":
@@ -24,6 +24,9 @@ _export(exports, {
24
24
  get formatStepSummary () {
25
25
  return formatStepSummary;
26
26
  },
27
+ get formatTags () {
28
+ return formatTags;
29
+ },
27
30
  get generateWorkflowTypes () {
28
31
  return generateWorkflowTypes;
29
32
  },
@@ -106,13 +109,14 @@ const lsWorkflowJson = async (dirPath)=>{
106
109
  return exists ? workflowJsonPath : undefined;
107
110
  };
108
111
  const isWorkflowDir = async (dirPath)=>Boolean(await lsWorkflowJson(dirPath));
109
- const formatCategories = (workflow, opts = {})=>{
110
- const { categories } = workflow;
112
+ const formatCategories = (workflow, opts = {})=>formatStringList(workflow.categories, opts);
113
+ const formatTags = (workflow, opts = {})=>formatStringList(workflow.tags, opts);
114
+ const formatStringList = (items, opts = {})=>{
111
115
  const { truncateAfter: limit, emptyDisplay = "" } = opts;
112
- if (!categories) return emptyDisplay;
113
- const count = categories.length;
114
- if (!limit || limit >= count) return categories.join(", ");
115
- return (0, _lodash.take)(categories, limit).join(", ") + ` (+ ${count - limit} more)`;
116
+ if (!items) return emptyDisplay;
117
+ const count = items.length;
118
+ if (!limit || limit >= count) return items.join(", ");
119
+ return (0, _lodash.take)(items, limit).join(", ") + ` (+ ${count - limit} more)`;
116
120
  };
117
121
  /*
118
122
  * Returns a formatted string of workflow steps.