@knocklabs/cli 1.0.0 → 1.0.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 +252 -69
- package/dist/commands/audience/archive.js +120 -0
- package/dist/commands/audience/get.js +169 -0
- package/dist/commands/audience/list.js +159 -0
- package/dist/commands/audience/new.js +243 -0
- package/dist/commands/audience/open.js +106 -0
- package/dist/commands/audience/pull.js +214 -0
- package/dist/commands/audience/push.js +167 -0
- package/dist/commands/audience/validate.js +147 -0
- package/dist/commands/branch/create.js +40 -3
- package/dist/commands/branch/list.js +14 -9
- package/dist/commands/branch/switch.js +7 -2
- package/dist/commands/pull.js +19 -12
- package/dist/commands/push.js +19 -12
- package/dist/lib/helpers/git.js +22 -3
- package/dist/lib/helpers/project-config.js +1 -0
- package/dist/lib/marshal/audience/generator.js +38 -0
- package/dist/lib/marshal/audience/helpers.js +142 -0
- package/dist/lib/marshal/audience/index.js +23 -0
- package/dist/lib/marshal/audience/processor.isomorphic.js +25 -0
- package/dist/lib/marshal/audience/reader.js +149 -0
- package/dist/lib/marshal/audience/types.js +15 -0
- package/dist/lib/marshal/audience/writer.js +177 -0
- package/dist/lib/marshal/index.isomorphic.js +18 -14
- package/dist/lib/resources.js +3 -0
- package/dist/lib/run-context/loader.js +12 -20
- package/dist/lib/urls.js +4 -0
- package/oclif.manifest.json +737 -94
- package/package.json +10 -10
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return AudienceArchive;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _core = require("@oclif/core");
|
|
12
|
+
const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
|
|
13
|
+
const _error = require("../../lib/helpers/error");
|
|
14
|
+
const _flag = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/helpers/flag"));
|
|
15
|
+
const _ux = require("../../lib/helpers/ux");
|
|
16
|
+
function _define_property(obj, key, value) {
|
|
17
|
+
if (key in obj) {
|
|
18
|
+
Object.defineProperty(obj, key, {
|
|
19
|
+
value: value,
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true
|
|
23
|
+
});
|
|
24
|
+
} else {
|
|
25
|
+
obj[key] = value;
|
|
26
|
+
}
|
|
27
|
+
return obj;
|
|
28
|
+
}
|
|
29
|
+
function _interop_require_default(obj) {
|
|
30
|
+
return obj && obj.__esModule ? obj : {
|
|
31
|
+
default: obj
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
35
|
+
if (typeof WeakMap !== "function") return null;
|
|
36
|
+
var cacheBabelInterop = new WeakMap();
|
|
37
|
+
var cacheNodeInterop = new WeakMap();
|
|
38
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
39
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
40
|
+
})(nodeInterop);
|
|
41
|
+
}
|
|
42
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
43
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
44
|
+
return obj;
|
|
45
|
+
}
|
|
46
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
47
|
+
return {
|
|
48
|
+
default: obj
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
52
|
+
if (cache && cache.has(obj)) {
|
|
53
|
+
return cache.get(obj);
|
|
54
|
+
}
|
|
55
|
+
var newObj = {
|
|
56
|
+
__proto__: null
|
|
57
|
+
};
|
|
58
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
59
|
+
for(var key in obj){
|
|
60
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
61
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
62
|
+
if (desc && (desc.get || desc.set)) {
|
|
63
|
+
Object.defineProperty(newObj, key, desc);
|
|
64
|
+
} else {
|
|
65
|
+
newObj[key] = obj[key];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
newObj.default = obj;
|
|
70
|
+
if (cache) {
|
|
71
|
+
cache.set(obj, newObj);
|
|
72
|
+
}
|
|
73
|
+
return newObj;
|
|
74
|
+
}
|
|
75
|
+
class AudienceArchive extends _basecommand.default {
|
|
76
|
+
async run() {
|
|
77
|
+
const { audienceKey } = this.props.args;
|
|
78
|
+
const { force, environment } = this.props.flags;
|
|
79
|
+
// Confirm before archiving since this affects all environments
|
|
80
|
+
if (!force) {
|
|
81
|
+
const confirmed = await (0, _ux.promptToConfirm)(`WARNING: Archiving audience \`${audienceKey}\` will affect ALL environments.\n` + `This action cannot be undone. Continue?`);
|
|
82
|
+
if (!confirmed) {
|
|
83
|
+
this.log("Archive cancelled.");
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
_ux.spinner.start(`‣ Archiving audience \`${audienceKey}\``);
|
|
88
|
+
try {
|
|
89
|
+
await this.apiV1.mgmtClient.audiences.archive(audienceKey, {
|
|
90
|
+
environment
|
|
91
|
+
});
|
|
92
|
+
_ux.spinner.stop();
|
|
93
|
+
this.log(`‣ Successfully archived audience \`${audienceKey}\` across all environments.`);
|
|
94
|
+
} catch (error) {
|
|
95
|
+
_ux.spinner.stop();
|
|
96
|
+
_core.ux.error(new _error.ApiError(error.message));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
_define_property(AudienceArchive, "summary", "Archive an audience (affects ALL environments).");
|
|
101
|
+
_define_property(AudienceArchive, "description", `
|
|
102
|
+
WARNING: Archiving an audience affects ALL environments and cannot be undone.
|
|
103
|
+
Use this command with caution.
|
|
104
|
+
`);
|
|
105
|
+
_define_property(AudienceArchive, "flags", {
|
|
106
|
+
environment: _core.Flags.string({
|
|
107
|
+
required: true,
|
|
108
|
+
summary: "The environment to use."
|
|
109
|
+
}),
|
|
110
|
+
branch: _flag.branch,
|
|
111
|
+
force: _core.Flags.boolean({
|
|
112
|
+
summary: "Skip confirmation prompt."
|
|
113
|
+
})
|
|
114
|
+
});
|
|
115
|
+
_define_property(AudienceArchive, "args", {
|
|
116
|
+
audienceKey: _core.Args.string({
|
|
117
|
+
required: true,
|
|
118
|
+
description: "The key of the audience to archive."
|
|
119
|
+
})
|
|
120
|
+
});
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return AudienceGet;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _core = require("@oclif/core");
|
|
12
|
+
const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
|
|
13
|
+
const _command = require("../../lib/helpers/command");
|
|
14
|
+
const _date = require("../../lib/helpers/date");
|
|
15
|
+
const _error = require("../../lib/helpers/error");
|
|
16
|
+
const _flag = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/helpers/flag"));
|
|
17
|
+
const _ux = require("../../lib/helpers/ux");
|
|
18
|
+
function _define_property(obj, key, value) {
|
|
19
|
+
if (key in obj) {
|
|
20
|
+
Object.defineProperty(obj, key, {
|
|
21
|
+
value: value,
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true
|
|
25
|
+
});
|
|
26
|
+
} else {
|
|
27
|
+
obj[key] = value;
|
|
28
|
+
}
|
|
29
|
+
return obj;
|
|
30
|
+
}
|
|
31
|
+
function _interop_require_default(obj) {
|
|
32
|
+
return obj && obj.__esModule ? obj : {
|
|
33
|
+
default: obj
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
37
|
+
if (typeof WeakMap !== "function") return null;
|
|
38
|
+
var cacheBabelInterop = new WeakMap();
|
|
39
|
+
var cacheNodeInterop = new WeakMap();
|
|
40
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
41
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
42
|
+
})(nodeInterop);
|
|
43
|
+
}
|
|
44
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
45
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
46
|
+
return obj;
|
|
47
|
+
}
|
|
48
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
49
|
+
return {
|
|
50
|
+
default: obj
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
54
|
+
if (cache && cache.has(obj)) {
|
|
55
|
+
return cache.get(obj);
|
|
56
|
+
}
|
|
57
|
+
var newObj = {
|
|
58
|
+
__proto__: null
|
|
59
|
+
};
|
|
60
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
61
|
+
for(var key in obj){
|
|
62
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
63
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
64
|
+
if (desc && (desc.get || desc.set)) {
|
|
65
|
+
Object.defineProperty(newObj, key, desc);
|
|
66
|
+
} else {
|
|
67
|
+
newObj[key] = obj[key];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
newObj.default = obj;
|
|
72
|
+
if (cache) {
|
|
73
|
+
cache.set(obj, newObj);
|
|
74
|
+
}
|
|
75
|
+
return newObj;
|
|
76
|
+
}
|
|
77
|
+
class AudienceGet extends _basecommand.default {
|
|
78
|
+
async run() {
|
|
79
|
+
_ux.spinner.start("‣ Loading");
|
|
80
|
+
const { audience } = await this.loadAudience();
|
|
81
|
+
_ux.spinner.stop();
|
|
82
|
+
const { flags } = this.props;
|
|
83
|
+
if (flags.json) return audience;
|
|
84
|
+
this.render(audience);
|
|
85
|
+
}
|
|
86
|
+
async loadAudience() {
|
|
87
|
+
const { audienceKey } = this.props.args;
|
|
88
|
+
const { flags } = this.props;
|
|
89
|
+
try {
|
|
90
|
+
const audience = await this.apiV1.mgmtClient.audiences.retrieve(audienceKey, {
|
|
91
|
+
environment: flags.environment,
|
|
92
|
+
branch: flags.branch,
|
|
93
|
+
hide_uncommitted_changes: flags["hide-uncommitted-changes"]
|
|
94
|
+
});
|
|
95
|
+
return {
|
|
96
|
+
audience
|
|
97
|
+
};
|
|
98
|
+
} catch (error) {
|
|
99
|
+
_core.ux.error(new _error.ApiError(error.message));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
render(audience) {
|
|
103
|
+
const { audienceKey } = this.props.args;
|
|
104
|
+
const { environment: env, "hide-uncommitted-changes": committedOnly } = this.props.flags;
|
|
105
|
+
const qualifier = env === "development" && !committedOnly ? "(including uncommitted)" : "";
|
|
106
|
+
const scope = (0, _command.formatCommandScope)(this.props.flags);
|
|
107
|
+
this.log(`‣ Showing audience \`${audienceKey}\` in ${scope} ${qualifier}\n`);
|
|
108
|
+
/*
|
|
109
|
+
* Audience table
|
|
110
|
+
*/ const rows = [
|
|
111
|
+
{
|
|
112
|
+
key: "Name",
|
|
113
|
+
value: audience.name
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
key: "Key",
|
|
117
|
+
value: audience.key
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
key: "Type",
|
|
121
|
+
value: audience.type
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
key: "Description",
|
|
125
|
+
value: audience.description || "-"
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
key: "Created at",
|
|
129
|
+
value: (0, _date.formatDateTime)(audience.created_at)
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
key: "Updated at",
|
|
133
|
+
value: (0, _date.formatDateTime)(audience.updated_at)
|
|
134
|
+
}
|
|
135
|
+
];
|
|
136
|
+
_core.ux.table(rows, {
|
|
137
|
+
key: {
|
|
138
|
+
header: "Audience",
|
|
139
|
+
minWidth: 24
|
|
140
|
+
},
|
|
141
|
+
value: {
|
|
142
|
+
header: "",
|
|
143
|
+
minWidth: 24
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
// Show segments for dynamic audiences
|
|
147
|
+
if (audience.type === "dynamic" && audience.segments) {
|
|
148
|
+
this.log("\nSegments:");
|
|
149
|
+
this.log(JSON.stringify(audience.segments, null, 2));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
_define_property(AudienceGet, "summary", "Display a single audience from an environment.");
|
|
154
|
+
_define_property(AudienceGet, "flags", {
|
|
155
|
+
environment: _core.Flags.string({
|
|
156
|
+
default: "development",
|
|
157
|
+
summary: "The environment to use."
|
|
158
|
+
}),
|
|
159
|
+
branch: _flag.branch,
|
|
160
|
+
"hide-uncommitted-changes": _core.Flags.boolean({
|
|
161
|
+
summary: "Hide any uncommitted changes."
|
|
162
|
+
})
|
|
163
|
+
});
|
|
164
|
+
_define_property(AudienceGet, "args", {
|
|
165
|
+
audienceKey: _core.Args.string({
|
|
166
|
+
required: true
|
|
167
|
+
})
|
|
168
|
+
});
|
|
169
|
+
_define_property(AudienceGet, "enableJsonFlag", true);
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return AudienceList;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _core = require("@oclif/core");
|
|
12
|
+
const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
|
|
13
|
+
const _command = require("../../lib/helpers/command");
|
|
14
|
+
const _date = require("../../lib/helpers/date");
|
|
15
|
+
const _error = require("../../lib/helpers/error");
|
|
16
|
+
const _flag = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/helpers/flag"));
|
|
17
|
+
const _page = require("../../lib/helpers/page");
|
|
18
|
+
const _ux = require("../../lib/helpers/ux");
|
|
19
|
+
function _define_property(obj, key, value) {
|
|
20
|
+
if (key in obj) {
|
|
21
|
+
Object.defineProperty(obj, key, {
|
|
22
|
+
value: value,
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true
|
|
26
|
+
});
|
|
27
|
+
} else {
|
|
28
|
+
obj[key] = value;
|
|
29
|
+
}
|
|
30
|
+
return obj;
|
|
31
|
+
}
|
|
32
|
+
function _interop_require_default(obj) {
|
|
33
|
+
return obj && obj.__esModule ? obj : {
|
|
34
|
+
default: obj
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
38
|
+
if (typeof WeakMap !== "function") return null;
|
|
39
|
+
var cacheBabelInterop = new WeakMap();
|
|
40
|
+
var cacheNodeInterop = new WeakMap();
|
|
41
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
42
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
43
|
+
})(nodeInterop);
|
|
44
|
+
}
|
|
45
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
46
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
47
|
+
return obj;
|
|
48
|
+
}
|
|
49
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
50
|
+
return {
|
|
51
|
+
default: obj
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
55
|
+
if (cache && cache.has(obj)) {
|
|
56
|
+
return cache.get(obj);
|
|
57
|
+
}
|
|
58
|
+
var newObj = {
|
|
59
|
+
__proto__: null
|
|
60
|
+
};
|
|
61
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
62
|
+
for(var key in obj){
|
|
63
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
64
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
65
|
+
if (desc && (desc.get || desc.set)) {
|
|
66
|
+
Object.defineProperty(newObj, key, desc);
|
|
67
|
+
} else {
|
|
68
|
+
newObj[key] = obj[key];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
newObj.default = obj;
|
|
73
|
+
if (cache) {
|
|
74
|
+
cache.set(obj, newObj);
|
|
75
|
+
}
|
|
76
|
+
return newObj;
|
|
77
|
+
}
|
|
78
|
+
class AudienceList extends _basecommand.default {
|
|
79
|
+
async run() {
|
|
80
|
+
const data = await this.request();
|
|
81
|
+
const { flags } = this.props;
|
|
82
|
+
if (flags.json) return data;
|
|
83
|
+
return this.render(data);
|
|
84
|
+
}
|
|
85
|
+
async request(pageParams = {}) {
|
|
86
|
+
const { flags } = this.props;
|
|
87
|
+
_ux.spinner.start("‣ Loading");
|
|
88
|
+
try {
|
|
89
|
+
var _pageParams_after, _pageParams_before;
|
|
90
|
+
const page = await this.apiV1.mgmtClient.audiences.list({
|
|
91
|
+
environment: flags.environment,
|
|
92
|
+
branch: flags.branch,
|
|
93
|
+
hide_uncommitted_changes: flags["hide-uncommitted-changes"],
|
|
94
|
+
limit: flags.limit,
|
|
95
|
+
after: (_pageParams_after = pageParams.after) !== null && _pageParams_after !== void 0 ? _pageParams_after : flags.after,
|
|
96
|
+
before: (_pageParams_before = pageParams.before) !== null && _pageParams_before !== void 0 ? _pageParams_before : flags.before
|
|
97
|
+
});
|
|
98
|
+
_ux.spinner.stop();
|
|
99
|
+
return {
|
|
100
|
+
entries: page.entries,
|
|
101
|
+
page_info: page.page_info
|
|
102
|
+
};
|
|
103
|
+
} catch (error) {
|
|
104
|
+
_ux.spinner.stop();
|
|
105
|
+
throw new _error.ApiError(error.message);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async render(data) {
|
|
109
|
+
const { entries } = data;
|
|
110
|
+
const { environment: env, "hide-uncommitted-changes": committedOnly } = this.props.flags;
|
|
111
|
+
const qualifier = env === "development" && !committedOnly ? "(including uncommitted)" : "";
|
|
112
|
+
const scope = (0, _command.formatCommandScope)(this.props.flags);
|
|
113
|
+
this.log(`‣ Showing ${entries.length} audiences in ${scope} ${qualifier}\n`);
|
|
114
|
+
/*
|
|
115
|
+
* Audiences list table
|
|
116
|
+
*/ _core.ux.table(entries, {
|
|
117
|
+
key: {
|
|
118
|
+
header: "Key"
|
|
119
|
+
},
|
|
120
|
+
name: {
|
|
121
|
+
header: "Name"
|
|
122
|
+
},
|
|
123
|
+
description: {
|
|
124
|
+
header: "Description"
|
|
125
|
+
},
|
|
126
|
+
type: {
|
|
127
|
+
header: "Type"
|
|
128
|
+
},
|
|
129
|
+
updated_at: {
|
|
130
|
+
header: "Updated at",
|
|
131
|
+
get: (entry)=>(0, _date.formatDate)(entry.updated_at)
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
return this.prompt(data);
|
|
135
|
+
}
|
|
136
|
+
async prompt(data) {
|
|
137
|
+
const { page_info } = data;
|
|
138
|
+
const pageAction = await (0, _page.maybePromptPageAction)(page_info);
|
|
139
|
+
const pageParams = pageAction && (0, _page.paramsForPageAction)(pageAction, page_info);
|
|
140
|
+
if (pageParams) {
|
|
141
|
+
this.log("\n");
|
|
142
|
+
const nextData = await this.request(pageParams);
|
|
143
|
+
return this.render(nextData);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
_define_property(AudienceList, "summary", "Display all audiences for an environment.");
|
|
148
|
+
_define_property(AudienceList, "flags", {
|
|
149
|
+
environment: _core.Flags.string({
|
|
150
|
+
default: "development",
|
|
151
|
+
summary: "The environment to use."
|
|
152
|
+
}),
|
|
153
|
+
branch: _flag.branch,
|
|
154
|
+
"hide-uncommitted-changes": _core.Flags.boolean({
|
|
155
|
+
summary: "Hide any uncommitted changes."
|
|
156
|
+
}),
|
|
157
|
+
..._page.pageFlags
|
|
158
|
+
});
|
|
159
|
+
_define_property(AudienceList, "enableJsonFlag", true);
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return AudienceNew;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _nodepath = /*#__PURE__*/ _interop_require_wildcard(require("node:path"));
|
|
12
|
+
const _core = require("@oclif/core");
|
|
13
|
+
const _enquirer = require("enquirer");
|
|
14
|
+
const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
|
|
15
|
+
const _const = require("../../lib/helpers/const");
|
|
16
|
+
const _flag = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/helpers/flag"));
|
|
17
|
+
const _projectconfig = require("../../lib/helpers/project-config");
|
|
18
|
+
const _string = require("../../lib/helpers/string");
|
|
19
|
+
const _ux = require("../../lib/helpers/ux");
|
|
20
|
+
const _audience = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/marshal/audience"));
|
|
21
|
+
const _push = /*#__PURE__*/ _interop_require_default(require("./push"));
|
|
22
|
+
function _define_property(obj, key, value) {
|
|
23
|
+
if (key in obj) {
|
|
24
|
+
Object.defineProperty(obj, key, {
|
|
25
|
+
value: value,
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true
|
|
29
|
+
});
|
|
30
|
+
} else {
|
|
31
|
+
obj[key] = value;
|
|
32
|
+
}
|
|
33
|
+
return obj;
|
|
34
|
+
}
|
|
35
|
+
function _interop_require_default(obj) {
|
|
36
|
+
return obj && obj.__esModule ? obj : {
|
|
37
|
+
default: obj
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
41
|
+
if (typeof WeakMap !== "function") return null;
|
|
42
|
+
var cacheBabelInterop = new WeakMap();
|
|
43
|
+
var cacheNodeInterop = new WeakMap();
|
|
44
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
45
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
46
|
+
})(nodeInterop);
|
|
47
|
+
}
|
|
48
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
49
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
50
|
+
return obj;
|
|
51
|
+
}
|
|
52
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
53
|
+
return {
|
|
54
|
+
default: obj
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
58
|
+
if (cache && cache.has(obj)) {
|
|
59
|
+
return cache.get(obj);
|
|
60
|
+
}
|
|
61
|
+
var newObj = {
|
|
62
|
+
__proto__: null
|
|
63
|
+
};
|
|
64
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
65
|
+
for(var key in obj){
|
|
66
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
67
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
68
|
+
if (desc && (desc.get || desc.set)) {
|
|
69
|
+
Object.defineProperty(newObj, key, desc);
|
|
70
|
+
} else {
|
|
71
|
+
newObj[key] = obj[key];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
newObj.default = obj;
|
|
76
|
+
if (cache) {
|
|
77
|
+
cache.set(obj, newObj);
|
|
78
|
+
}
|
|
79
|
+
return newObj;
|
|
80
|
+
}
|
|
81
|
+
const AUDIENCE_TYPE_CHOICES = [
|
|
82
|
+
{
|
|
83
|
+
name: _audience.AudienceType.Static,
|
|
84
|
+
message: "Static (manual membership)"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: _audience.AudienceType.Dynamic,
|
|
88
|
+
message: "Dynamic (rule-based membership) [Beta - requires access]"
|
|
89
|
+
}
|
|
90
|
+
];
|
|
91
|
+
class AudienceNew extends _basecommand.default {
|
|
92
|
+
async run() {
|
|
93
|
+
const { flags } = this.props;
|
|
94
|
+
const { resourceDir } = this.runContext;
|
|
95
|
+
// 1. Ensure we aren't in any existing resource directory already.
|
|
96
|
+
if (resourceDir) {
|
|
97
|
+
return this.error(`Cannot create a new audience inside an existing ${resourceDir.type} directory`);
|
|
98
|
+
}
|
|
99
|
+
// 2. Prompt for name and key if not provided
|
|
100
|
+
let name = flags.name;
|
|
101
|
+
let key = flags.key;
|
|
102
|
+
if (!name) {
|
|
103
|
+
const nameResponse = await (0, _enquirer.prompt)({
|
|
104
|
+
type: "input",
|
|
105
|
+
name: "name",
|
|
106
|
+
message: "Audience name",
|
|
107
|
+
validate: (value)=>{
|
|
108
|
+
if (!value || value.trim().length === 0) {
|
|
109
|
+
return "Audience name is required";
|
|
110
|
+
}
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
name = nameResponse.name;
|
|
115
|
+
}
|
|
116
|
+
if (!key) {
|
|
117
|
+
const keyResponse = await (0, _enquirer.prompt)({
|
|
118
|
+
type: "input",
|
|
119
|
+
name: "key",
|
|
120
|
+
message: "Audience key (immutable slug)",
|
|
121
|
+
initial: (0, _string.slugify)(name),
|
|
122
|
+
validate: (value)=>{
|
|
123
|
+
if (!value || value.trim().length === 0) {
|
|
124
|
+
return "Audience key is required";
|
|
125
|
+
}
|
|
126
|
+
const keyError = _audience.validateAudienceKey(value);
|
|
127
|
+
if (keyError) {
|
|
128
|
+
return `Invalid audience key: ${keyError}`;
|
|
129
|
+
}
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
key = keyResponse.key;
|
|
134
|
+
}
|
|
135
|
+
// Validate the audience key
|
|
136
|
+
const audienceKeyError = _audience.validateAudienceKey(key);
|
|
137
|
+
if (audienceKeyError) {
|
|
138
|
+
return this.error(`Invalid audience key \`${key}\` (${audienceKeyError})`);
|
|
139
|
+
}
|
|
140
|
+
const audienceDirCtx = await this.getAudienceDirContext(key);
|
|
141
|
+
const promptMessage = audienceDirCtx.exists ? `Found \`${audienceDirCtx.key}\` at ${audienceDirCtx.abspath}, overwrite?` : `Create a new audience directory \`${audienceDirCtx.key}\` at ${audienceDirCtx.abspath}?`;
|
|
142
|
+
// Check if the audience directory already exists, and prompt to confirm if not.
|
|
143
|
+
const input = flags.force || await (0, _ux.promptToConfirm)(promptMessage);
|
|
144
|
+
if (!input) return;
|
|
145
|
+
// 3. Prompt for type if not provided
|
|
146
|
+
let audienceType;
|
|
147
|
+
if (flags.type) {
|
|
148
|
+
audienceType = flags.type;
|
|
149
|
+
} else {
|
|
150
|
+
const typeResponse = await (0, _enquirer.prompt)({
|
|
151
|
+
type: "select",
|
|
152
|
+
name: "type",
|
|
153
|
+
message: "Select audience type",
|
|
154
|
+
choices: AUDIENCE_TYPE_CHOICES.map((choice)=>({
|
|
155
|
+
name: choice.name,
|
|
156
|
+
message: choice.message
|
|
157
|
+
}))
|
|
158
|
+
});
|
|
159
|
+
audienceType = typeResponse.type;
|
|
160
|
+
}
|
|
161
|
+
// Generate the audience directory with scaffolded content
|
|
162
|
+
await _audience.generateAudienceDir(audienceDirCtx, {
|
|
163
|
+
name,
|
|
164
|
+
type: audienceType,
|
|
165
|
+
description: flags.description
|
|
166
|
+
});
|
|
167
|
+
if (flags.push) {
|
|
168
|
+
_ux.spinner.start("‣ Pushing audience to Knock");
|
|
169
|
+
const pushArgs = [
|
|
170
|
+
key,
|
|
171
|
+
"--environment",
|
|
172
|
+
flags.environment
|
|
173
|
+
];
|
|
174
|
+
if (flags.branch) {
|
|
175
|
+
pushArgs.push("--branch", flags.branch);
|
|
176
|
+
}
|
|
177
|
+
try {
|
|
178
|
+
await _push.default.run(pushArgs);
|
|
179
|
+
} catch (error) {
|
|
180
|
+
this.error(`Failed to push audience to Knock: ${error}`);
|
|
181
|
+
} finally{
|
|
182
|
+
_ux.spinner.stop();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
this.log(`‣ Successfully created audience \`${key}\``);
|
|
186
|
+
}
|
|
187
|
+
async getAudienceDirContext(audienceKey) {
|
|
188
|
+
const { cwd: runCwd } = this.runContext;
|
|
189
|
+
// Default to knock project config first if present, otherwise cwd.
|
|
190
|
+
const dirCtx = await (0, _projectconfig.resolveResourceDir)(this.projectConfig, "audience", runCwd);
|
|
191
|
+
// Not inside any existing audience directory, which means either create a
|
|
192
|
+
// new audience directory in the cwd, or update it if there is one already.
|
|
193
|
+
if (audienceKey) {
|
|
194
|
+
const dirPath = _nodepath.resolve(dirCtx.abspath, audienceKey);
|
|
195
|
+
const exists = await _audience.isAudienceDir(dirPath);
|
|
196
|
+
return {
|
|
197
|
+
type: "audience",
|
|
198
|
+
key: audienceKey,
|
|
199
|
+
abspath: dirPath,
|
|
200
|
+
exists
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
// Not in any audience directory, nor an audience key arg was given so error.
|
|
204
|
+
return this.error("Missing 1 required arg:\naudienceKey");
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
_define_property(AudienceNew, "summary", "Create a new audience with a minimal configuration.");
|
|
208
|
+
_define_property(AudienceNew, "flags", {
|
|
209
|
+
name: _core.Flags.string({
|
|
210
|
+
summary: "The name of the audience",
|
|
211
|
+
char: "n"
|
|
212
|
+
}),
|
|
213
|
+
key: _core.Flags.string({
|
|
214
|
+
summary: "The key of the audience",
|
|
215
|
+
char: "k"
|
|
216
|
+
}),
|
|
217
|
+
type: _core.Flags.string({
|
|
218
|
+
summary: "The type of the audience (static, dynamic). Note: dynamic is in beta and requires access.",
|
|
219
|
+
char: "t",
|
|
220
|
+
options: [
|
|
221
|
+
_audience.AudienceType.Static,
|
|
222
|
+
_audience.AudienceType.Dynamic
|
|
223
|
+
]
|
|
224
|
+
}),
|
|
225
|
+
description: _core.Flags.string({
|
|
226
|
+
summary: "The description of the audience",
|
|
227
|
+
char: "d"
|
|
228
|
+
}),
|
|
229
|
+
environment: _core.Flags.string({
|
|
230
|
+
summary: "The environment to create the audience in. Defaults to development.",
|
|
231
|
+
default: _const.KnockEnv.Development
|
|
232
|
+
}),
|
|
233
|
+
branch: _flag.branch,
|
|
234
|
+
force: _core.Flags.boolean({
|
|
235
|
+
summary: "Force the creation of the audience directory without confirmation."
|
|
236
|
+
}),
|
|
237
|
+
push: _core.Flags.boolean({
|
|
238
|
+
summary: "Whether or not to push the audience to Knock after creation.",
|
|
239
|
+
default: false,
|
|
240
|
+
char: "p"
|
|
241
|
+
})
|
|
242
|
+
});
|
|
243
|
+
_define_property(AudienceNew, "args", {});
|