@contentstack/cli-cm-seed 1.7.6 → 1.7.8
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
CHANGED
|
@@ -10,16 +10,17 @@ To import content to your stack, you can choose from the following two sources:
|
|
|
10
10
|
<!-- usagestop -->
|
|
11
11
|
## Commands
|
|
12
12
|
<!-- commands -->
|
|
13
|
-
* [`csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>]`](#csdx-cmstacksseed---repo-value---org-value--k-value--n-value--y-value--s-value)
|
|
14
|
-
* [`csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>]`](#csdx-cmstacksseed---repo-value---org-value--k-value--n-value--y-value--s-value-1)
|
|
13
|
+
* [`csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>] [--locale <value>]`](#csdx-cmstacksseed---repo-value---org-value--k-value--n-value--y-value--s-value---locale-value)
|
|
14
|
+
* [`csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>] [--locale <value>]`](#csdx-cmstacksseed---repo-value---org-value--k-value--n-value--y-value--s-value---locale-value-1)
|
|
15
15
|
|
|
16
|
-
## `csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>]`
|
|
16
|
+
## `csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>] [--locale <value>]`
|
|
17
17
|
|
|
18
18
|
Create a stack from existing content types, entries, assets, etc
|
|
19
19
|
|
|
20
20
|
```
|
|
21
21
|
USAGE
|
|
22
|
-
$ csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>]
|
|
22
|
+
$ csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>] [--locale
|
|
23
|
+
<value>]
|
|
23
24
|
|
|
24
25
|
FLAGS
|
|
25
26
|
-a, --alias=<value> Alias of the management token
|
|
@@ -48,13 +49,14 @@ EXAMPLES
|
|
|
48
49
|
$ csdx cm:stacks:seed --repo "account/repository" --org "your-org-uid" --stack-name "stack-name" //create a new stack in given org uid
|
|
49
50
|
```
|
|
50
51
|
|
|
51
|
-
## `csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>]`
|
|
52
|
+
## `csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>] [--locale <value>]`
|
|
52
53
|
|
|
53
54
|
Create a stack from existing content types, entries, assets, etc
|
|
54
55
|
|
|
55
56
|
```
|
|
56
57
|
USAGE
|
|
57
|
-
$ csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>]
|
|
58
|
+
$ csdx cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>] [--locale
|
|
59
|
+
<value>]
|
|
58
60
|
|
|
59
61
|
FLAGS
|
|
60
62
|
-a, --alias=<value> Alias of the management token
|
|
@@ -26,6 +26,7 @@ class SeedCommand extends cli_command_1.Command {
|
|
|
26
26
|
skipStackConfirmation: seedFlags['yes'],
|
|
27
27
|
isAuthenticated: (0, cli_utilities_1.isAuthenticated)(),
|
|
28
28
|
alias: managementTokenAlias,
|
|
29
|
+
master_locale: seedFlags['locale'],
|
|
29
30
|
};
|
|
30
31
|
const listOfTokens = cli_utilities_1.configHandler.get('tokens');
|
|
31
32
|
if (managementTokenAlias && listOfTokens[managementTokenAlias]) {
|
|
@@ -56,7 +57,7 @@ SeedCommand.examples = [
|
|
|
56
57
|
'$ csdx cm:stacks:seed --repo "account/repository" --stack-api-key "stack-api-key" //seed content into specific stack',
|
|
57
58
|
'$ csdx cm:stacks:seed --repo "account/repository" --org "your-org-uid" --stack-name "stack-name" //create a new stack in given org uid',
|
|
58
59
|
];
|
|
59
|
-
SeedCommand.usage = 'cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>]';
|
|
60
|
+
SeedCommand.usage = 'cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>] [--locale <value>]';
|
|
60
61
|
SeedCommand.flags = {
|
|
61
62
|
repo: cli_utilities_1.flags.string({
|
|
62
63
|
char: 'r',
|
|
@@ -112,5 +113,9 @@ SeedCommand.flags = {
|
|
|
112
113
|
char: 'a',
|
|
113
114
|
description: 'Alias of the management token',
|
|
114
115
|
}),
|
|
116
|
+
locale: cli_utilities_1.flags.string({
|
|
117
|
+
description: 'Master Locale of the stack',
|
|
118
|
+
hidden: true,
|
|
119
|
+
}),
|
|
115
120
|
};
|
|
116
121
|
SeedCommand.aliases = ['cm:seed'];
|
|
@@ -11,12 +11,29 @@ export interface Stack {
|
|
|
11
11
|
api_key: string;
|
|
12
12
|
org_uid: string;
|
|
13
13
|
}
|
|
14
|
+
export interface ManagementToken {
|
|
15
|
+
response_code: string;
|
|
16
|
+
response_message: string;
|
|
17
|
+
}
|
|
14
18
|
export interface CreateStackOptions {
|
|
15
19
|
name: string;
|
|
16
20
|
description: string;
|
|
17
21
|
master_locale: string;
|
|
18
22
|
org_uid: string;
|
|
19
23
|
}
|
|
24
|
+
export interface createManagementTokenOptions {
|
|
25
|
+
name: string;
|
|
26
|
+
description: string;
|
|
27
|
+
expires_on: string;
|
|
28
|
+
scope: {
|
|
29
|
+
module: string;
|
|
30
|
+
acl: {
|
|
31
|
+
read: boolean;
|
|
32
|
+
write?: boolean;
|
|
33
|
+
};
|
|
34
|
+
branches?: string[];
|
|
35
|
+
}[];
|
|
36
|
+
}
|
|
20
37
|
export default class ContentstackClient {
|
|
21
38
|
instance: Promise<ContentstackManagementSDK.ContentstackClient>;
|
|
22
39
|
limit: number;
|
|
@@ -28,5 +45,6 @@ export default class ContentstackClient {
|
|
|
28
45
|
getStacks(org_uid: string, skip?: number, stacks?: Stack[]): Promise<Stack[]>;
|
|
29
46
|
getContentTypeCount(api_key: string, managementToken?: string): Promise<number>;
|
|
30
47
|
createStack(options: CreateStackOptions): Promise<Stack>;
|
|
48
|
+
createManagementToken(api_key: string, managementToken: any, options: createManagementTokenOptions): Promise<ManagementToken>;
|
|
31
49
|
private buildError;
|
|
32
50
|
}
|
|
@@ -135,6 +135,34 @@ class ContentstackClient {
|
|
|
135
135
|
throw this.buildError(error);
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
+
async createManagementToken(api_key, managementToken, options) {
|
|
139
|
+
try {
|
|
140
|
+
const client = await this.instance;
|
|
141
|
+
const body = {
|
|
142
|
+
token: {
|
|
143
|
+
name: options.name,
|
|
144
|
+
description: options.description,
|
|
145
|
+
scope: options.scope,
|
|
146
|
+
expires_on: options.expires_on,
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
const response = await client.stack({ api_key: api_key, management_token: managementToken }).managementToken().create(body);
|
|
150
|
+
return {
|
|
151
|
+
response_code: response.errorCode,
|
|
152
|
+
response_message: response.errorMessage
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
const typedError = error;
|
|
157
|
+
if (typedError.errorCode === '401') {
|
|
158
|
+
return {
|
|
159
|
+
response_code: '401',
|
|
160
|
+
response_message: 'You do not have access to create management tokens. Please try again or ask an Administrator for assistance.'
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
throw this.buildError(typedError);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
138
166
|
buildError(error) {
|
|
139
167
|
var _a;
|
|
140
168
|
const message = error.errorMessage || ((_a = error.response.data) === null || _a === void 0 ? void 0 : _a.errorMessage) || error.response.statusText;
|
package/lib/seed/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export interface ContentModelSeederOptions {
|
|
|
14
14
|
isAuthenticated: boolean | false;
|
|
15
15
|
managementToken?: string | undefined;
|
|
16
16
|
alias?: string | undefined;
|
|
17
|
+
master_locale?: string | undefined;
|
|
17
18
|
}
|
|
18
19
|
export default class ContentModelSeeder {
|
|
19
20
|
options: ContentModelSeederOptions;
|
package/lib/seed/index.js
CHANGED
|
@@ -49,7 +49,7 @@ class ContentModelSeeder {
|
|
|
49
49
|
api_key: api_key,
|
|
50
50
|
cdaHost: this.options.cdaHost,
|
|
51
51
|
cmaHost: this.options.cmaHost,
|
|
52
|
-
master_locale: exports.ENGLISH_LOCALE,
|
|
52
|
+
master_locale: this.options.master_locale || exports.ENGLISH_LOCALE,
|
|
53
53
|
tmpPath: tmpPath,
|
|
54
54
|
isAuthenticated: this.options.isAuthenticated,
|
|
55
55
|
alias: this.options.alias,
|
|
@@ -120,7 +120,7 @@ class ContentModelSeeder {
|
|
|
120
120
|
const newStack = await this.csClient.createStack({
|
|
121
121
|
name: stackName,
|
|
122
122
|
description: '',
|
|
123
|
-
master_locale: exports.ENGLISH_LOCALE,
|
|
123
|
+
master_locale: this.options.master_locale || exports.ENGLISH_LOCALE,
|
|
124
124
|
org_uid: organization.uid,
|
|
125
125
|
});
|
|
126
126
|
cli_utilities_1.cliux.loader();
|
|
@@ -128,6 +128,45 @@ class ContentModelSeeder {
|
|
|
128
128
|
}
|
|
129
129
|
async shouldProceed(api_key) {
|
|
130
130
|
let count;
|
|
131
|
+
const stack_details = await this.csClient.getStack(api_key);
|
|
132
|
+
if (this.options.master_locale != stack_details.master_locale) {
|
|
133
|
+
cli_utilities_1.cliux.print(`Compass app requires the master locale to be set to English (en).`, {
|
|
134
|
+
color: "yellow",
|
|
135
|
+
bold: true,
|
|
136
|
+
});
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
const managementBody = {
|
|
140
|
+
"name": "Checking roles for creating management token",
|
|
141
|
+
"description": "This is a compass app management token.",
|
|
142
|
+
"scope": [
|
|
143
|
+
{
|
|
144
|
+
"module": "content_type",
|
|
145
|
+
"acl": {
|
|
146
|
+
"read": true,
|
|
147
|
+
"write": true
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"module": "branch",
|
|
152
|
+
"branches": [
|
|
153
|
+
"main"
|
|
154
|
+
],
|
|
155
|
+
"acl": {
|
|
156
|
+
"read": true
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
],
|
|
160
|
+
"expires_on": "3000-01-01",
|
|
161
|
+
"is_email_notification_enabled": false
|
|
162
|
+
};
|
|
163
|
+
let managementTokenResult = await this.csClient.createManagementToken(api_key, this.managementToken, managementBody);
|
|
164
|
+
if ((managementTokenResult === null || managementTokenResult === void 0 ? void 0 : managementTokenResult.response_code) == "161" || (managementTokenResult === null || managementTokenResult === void 0 ? void 0 : managementTokenResult.response_code) == "401") {
|
|
165
|
+
cli_utilities_1.cliux.print(`Info: Failed to generate a management token.\nNote: Management token is not available in your plan. Please contact the admin for support.`, {
|
|
166
|
+
color: 'red',
|
|
167
|
+
});
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
131
170
|
count = await this.csClient.getContentTypeCount(api_key, this.managementToken);
|
|
132
171
|
if (count > 0 && this._options.skipStackConfirmation !== 'yes') {
|
|
133
172
|
const proceed = await (0, interactive_1.inquireProceed)();
|
package/oclif.manifest.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.7.
|
|
2
|
+
"version": "1.7.8",
|
|
3
3
|
"commands": {
|
|
4
4
|
"cm:stacks:seed": {
|
|
5
5
|
"id": "cm:stacks:seed",
|
|
6
6
|
"description": "Create a stack from existing content types, entries, assets, etc",
|
|
7
7
|
"strict": true,
|
|
8
|
-
"usage": "cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>]",
|
|
8
|
+
"usage": "cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>] [--locale <value>]",
|
|
9
9
|
"pluginName": "@contentstack/cli-cm-seed",
|
|
10
10
|
"pluginAlias": "@contentstack/cli-cm-seed",
|
|
11
11
|
"pluginType": "core",
|
|
@@ -97,6 +97,13 @@
|
|
|
97
97
|
"char": "a",
|
|
98
98
|
"description": "Alias of the management token",
|
|
99
99
|
"multiple": false
|
|
100
|
+
},
|
|
101
|
+
"locale": {
|
|
102
|
+
"name": "locale",
|
|
103
|
+
"type": "option",
|
|
104
|
+
"description": "Master Locale of the stack",
|
|
105
|
+
"hidden": true,
|
|
106
|
+
"multiple": false
|
|
100
107
|
}
|
|
101
108
|
},
|
|
102
109
|
"args": {}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-seed",
|
|
3
3
|
"description": "create a Stack from existing content types, entries, assets, etc.",
|
|
4
|
-
"version": "1.7.
|
|
4
|
+
"version": "1.7.8",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@contentstack/cli-cm-import": "~1.16.
|
|
9
|
-
"@contentstack/cli-command": "~1.2.
|
|
10
|
-
"@contentstack/cli-utilities": "~1.
|
|
8
|
+
"@contentstack/cli-cm-import": "~1.16.5",
|
|
9
|
+
"@contentstack/cli-command": "~1.2.19",
|
|
10
|
+
"@contentstack/cli-utilities": "~1.7.1",
|
|
11
11
|
"inquirer": "8.2.4",
|
|
12
12
|
"mkdirp": "^1.0.4",
|
|
13
13
|
"tar": "^6.1.13",
|