@contentful/app-scripts 1.11.0 → 1.13.0
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 +4 -4
- package/lib/activate/activate-bundle.d.ts +2 -0
- package/lib/activate/activate-bundle.js +45 -58
- package/lib/activate/build-bundle-activate-settings.d.ts +2 -0
- package/lib/activate/build-bundle-activate-settings.js +32 -34
- package/lib/activate/get-activate-args.d.ts +2 -0
- package/lib/activate/get-activate-args.js +33 -30
- package/lib/activate/index.d.ts +5 -0
- package/lib/activate/index.js +17 -13
- package/lib/analytics.d.ts +11 -0
- package/lib/analytics.js +42 -0
- package/lib/bin.d.ts +2 -0
- package/lib/bin.js +69 -0
- package/lib/cache-credential/index.d.ts +1 -0
- package/lib/cache-credential/index.js +74 -0
- package/lib/clean-up/build-clean-up-settings.d.ts +2 -0
- package/lib/clean-up/build-clean-up-settings.js +32 -36
- package/lib/clean-up/clean-up-bundles.d.ts +2 -0
- package/lib/clean-up/clean-up-bundles.js +91 -118
- package/lib/clean-up/get-clean-up-settings.d.ts +2 -0
- package/lib/clean-up/get-clean-up-settings.js +34 -32
- package/lib/clean-up/index.d.ts +5 -0
- package/lib/clean-up/index.js +17 -13
- package/lib/constants.d.ts +8 -0
- package/lib/constants.js +11 -0
- package/lib/create-app-definition/build-app-definition-settings.d.ts +7 -0
- package/lib/create-app-definition/build-app-definition-settings.js +73 -77
- package/lib/create-app-definition/create-app-definition.d.ts +2 -0
- package/lib/create-app-definition/create-app-definition.js +80 -112
- package/lib/create-app-definition/index.d.ts +4 -0
- package/lib/create-app-definition/index.js +18 -15
- package/lib/definition-api.d.ts +7 -0
- package/lib/definition-api.js +37 -44
- package/lib/get-app-info.d.ts +10 -0
- package/lib/get-app-info.js +22 -27
- package/lib/get-management-token.d.ts +1 -0
- package/lib/get-management-token.js +53 -60
- package/lib/index.d.ts +6 -0
- package/lib/index.js +15 -15
- package/lib/open/index.d.ts +5 -0
- package/lib/open/index.js +12 -8
- package/lib/open/open-settings.d.ts +3 -0
- package/lib/open/open-settings.js +46 -46
- package/lib/organization-api.d.ts +7 -0
- package/lib/organization-api.js +39 -51
- package/lib/types.d.ts +73 -0
- package/lib/types.js +2 -0
- package/lib/upload/build-upload-settings.d.ts +2 -0
- package/lib/upload/build-upload-settings.js +53 -57
- package/lib/upload/create-app-bundle.d.ts +3 -0
- package/lib/upload/create-app-bundle.js +64 -70
- package/lib/upload/create-app-upload.d.ts +2 -0
- package/lib/upload/create-app-upload.js +31 -36
- package/lib/upload/create-zip-from-directory.d.ts +2 -0
- package/lib/upload/create-zip-from-directory.js +23 -21
- package/lib/upload/get-upload-settings-args.d.ts +2 -0
- package/lib/upload/get-upload-settings-args.js +43 -39
- package/lib/upload/index.d.ts +5 -0
- package/lib/upload/index.js +20 -18
- package/lib/upload/validate-bundle.d.ts +1 -0
- package/lib/upload/validate-bundle.js +26 -33
- package/lib/utils.d.ts +12 -0
- package/lib/utils.js +92 -120
- package/lib/validate-arguments.d.ts +1 -0
- package/lib/validate-arguments.js +20 -14
- package/package.json +24 -12
- package/bin/app-scripts +0 -78
- package/lib/activate/activate-bundle.test.js +0 -69
- package/lib/clean-up/clean-up-bundles.test.js +0 -118
- package/lib/create-app-definition/create-app-definition.test.js +0 -87
- package/lib/get-app-info.test.js +0 -57
- package/lib/get-management-token.test.js +0 -82
- package/lib/open/open-settings.test.js +0 -45
- package/lib/upload/create-app-bundle.test.js +0 -110
- package/lib/upload/create-app-upload.test.js +0 -50
- package/lib/upload/validate-bundle.test.js +0 -45
- package/lib/utils.test.js +0 -198
- package/lib/validate-arguments.test.js +0 -33
- package/utils/analytics.js +0 -36
- package/utils/cache-credential/index.js +0 -81
- package/utils/cache-credential/index.test.js +0 -73
- package/utils/constants.js +0 -21
|
@@ -1,127 +1,95 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createAppDefinition = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const contentful_management_1 = require("contentful-management");
|
|
9
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
+
const lodash_1 = require("lodash");
|
|
11
|
+
const utils_1 = require("../utils");
|
|
12
|
+
const cache_credential_1 = require("../cache-credential");
|
|
13
|
+
const constants_1 = require("../constants");
|
|
11
14
|
async function fetchOrganizations(client) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
${
|
|
22
|
-
'Error:'
|
|
23
|
-
)} Could not fetch your organizations. Make sure you provided a valid access token.
|
|
15
|
+
try {
|
|
16
|
+
const orgs = await client.getOrganizations();
|
|
17
|
+
return orgs.items.map((org) => ({
|
|
18
|
+
name: org.name,
|
|
19
|
+
value: org.sys.id,
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
console.log(`
|
|
24
|
+
${chalk_1.default.red('Error:')} Could not fetch your organizations. Make sure you provided a valid access token.
|
|
24
25
|
|
|
25
26
|
${err.message}
|
|
26
27
|
`);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
28
|
+
throw err;
|
|
29
|
+
}
|
|
30
30
|
}
|
|
31
|
-
|
|
32
31
|
function assertValidArguments(accessToken, appDefinitionSettings) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
2
|
|
44
|
-
)}`,
|
|
45
|
-
`Example: ${JSON.stringify(
|
|
46
|
-
{
|
|
47
|
-
name: 'app-name',
|
|
48
|
-
locations: ['entry-field'],
|
|
49
|
-
fields: [{ type: 'Boolean' }],
|
|
50
|
-
},
|
|
51
|
-
null,
|
|
52
|
-
2
|
|
53
|
-
)}`
|
|
54
|
-
);
|
|
55
|
-
}
|
|
32
|
+
if (!(0, lodash_1.isString)(accessToken)) {
|
|
33
|
+
(0, utils_1.throwValidationException)('AccessToken', `Expected string got ${typeof accessToken}`);
|
|
34
|
+
}
|
|
35
|
+
if (!(0, lodash_1.isPlainObject)(appDefinitionSettings) || !(0, lodash_1.has)(appDefinitionSettings, 'locations')) {
|
|
36
|
+
(0, utils_1.throwValidationException)('AppDefinitionSettings', `Expected plain object with 'location' property, got ${JSON.stringify(appDefinitionSettings, null, 2)}`, `Example: ${JSON.stringify({
|
|
37
|
+
name: 'app-name',
|
|
38
|
+
locations: ['entry-field'],
|
|
39
|
+
fields: [{ type: 'Boolean' }],
|
|
40
|
+
}, null, 2)}`);
|
|
41
|
+
}
|
|
56
42
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
[APP_DEF_ENV_KEY]: createdAppDefinition.sys.id,
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
console.log(`
|
|
97
|
-
${chalk.greenBright('Success!')} Created an app definition for ${chalk.bold(appName)} in ${chalk.bold(
|
|
98
|
-
selectedOrg.name
|
|
99
|
-
)}.
|
|
100
|
-
|
|
101
|
-
${chalk.dim(`NOTE: You can update this app definition in your organization settings:
|
|
102
|
-
${chalk.underline(`https://app.contentful.com/deeplink?link=org`)}`)}
|
|
103
|
-
|
|
104
|
-
${chalk.bold('Next steps:')}
|
|
105
|
-
1. Run your app with ${chalk.cyan('`npm start`')} inside of your app folder.
|
|
43
|
+
async function createAppDefinition(accessToken, appDefinitionSettings) {
|
|
44
|
+
assertValidArguments(accessToken, appDefinitionSettings);
|
|
45
|
+
const client = (0, contentful_management_1.createClient)({ accessToken });
|
|
46
|
+
const organizations = await fetchOrganizations(client);
|
|
47
|
+
const selectedOrg = await (0, utils_1.selectFromList)(organizations, 'Select an organization for your app:', constants_1.ORG_ID_ENV_KEY);
|
|
48
|
+
const organizationId = selectedOrg.value;
|
|
49
|
+
const appName = appDefinitionSettings.name || path_1.default.basename(process.cwd());
|
|
50
|
+
const body = {
|
|
51
|
+
name: appName,
|
|
52
|
+
src: 'http://localhost:3000',
|
|
53
|
+
locations: appDefinitionSettings.locations.map((location) => {
|
|
54
|
+
if (location === 'entry-field') {
|
|
55
|
+
return {
|
|
56
|
+
location,
|
|
57
|
+
fieldTypes: appDefinitionSettings.fields || [],
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
location,
|
|
62
|
+
};
|
|
63
|
+
}),
|
|
64
|
+
};
|
|
65
|
+
try {
|
|
66
|
+
const organization = await client.getOrganization(organizationId);
|
|
67
|
+
const createdAppDefinition = await organization.createAppDefinition(body);
|
|
68
|
+
await (0, cache_credential_1.cacheEnvVars)({
|
|
69
|
+
[constants_1.APP_DEF_ENV_KEY]: createdAppDefinition.sys.id,
|
|
70
|
+
});
|
|
71
|
+
console.log(`
|
|
72
|
+
${chalk_1.default.greenBright('Success!')} Created an app definition for ${chalk_1.default.bold(appName)} in ${chalk_1.default.bold(selectedOrg.name)}.
|
|
73
|
+
|
|
74
|
+
${chalk_1.default.dim(`NOTE: You can update this app definition in your organization settings:
|
|
75
|
+
${chalk_1.default.underline(`https://app.contentful.com/deeplink?link=org`)}`)}
|
|
76
|
+
|
|
77
|
+
${chalk_1.default.bold('Next steps:')}
|
|
78
|
+
1. Run your app with ${chalk_1.default.cyan('`npm start`')} inside of your app folder.
|
|
106
79
|
2. Install this app definition to one of your spaces by opening:
|
|
107
|
-
${
|
|
108
|
-
`https://app.contentful.com/deeplink?link=apps&id=${createdAppDefinition.sys.id}`
|
|
109
|
-
)}
|
|
80
|
+
${chalk_1.default.underline(`https://app.contentful.com/deeplink?link=apps&id=${createdAppDefinition.sys.id}`)}
|
|
110
81
|
3. Learn how to build your first Contentful app:
|
|
111
|
-
${
|
|
82
|
+
${chalk_1.default.underline(`https://ctfl.io/app-tutorial`)}
|
|
112
83
|
`);
|
|
113
|
-
|
|
114
|
-
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
console.log(`
|
|
115
87
|
Something went wrong while creating the app definition.
|
|
116
|
-
Run ${
|
|
88
|
+
Run ${chalk_1.default.cyan('`npx @contentful/app-scripts create-app-definition`')} to try again.
|
|
117
89
|
|
|
118
90
|
${err.message}
|
|
119
91
|
`);
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
92
|
+
throw err;
|
|
93
|
+
}
|
|
123
94
|
}
|
|
124
|
-
|
|
125
|
-
module.exports = {
|
|
126
|
-
createAppDefinition,
|
|
127
|
-
};
|
|
95
|
+
exports.createAppDefinition = createAppDefinition;
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
return createAppDefinition(managementToken, appDefinitionSettings);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
throw new Error(`"create-app-definition" is not available in non-interactive mode`)
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAppDefinition = void 0;
|
|
4
|
+
const build_app_definition_settings_1 = require("./build-app-definition-settings");
|
|
5
|
+
const create_app_definition_1 = require("./create-app-definition");
|
|
6
|
+
const get_management_token_1 = require("../get-management-token");
|
|
7
|
+
const interactive = async () => {
|
|
8
|
+
const appDefinitionSettings = await (0, build_app_definition_settings_1.buildAppDefinitionSettings)();
|
|
9
|
+
const managementToken = await (0, get_management_token_1.getManagementToken)();
|
|
10
|
+
return (0, create_app_definition_1.createAppDefinition)(managementToken, appDefinitionSettings);
|
|
11
|
+
};
|
|
12
|
+
const nonInteractive = async () => {
|
|
13
|
+
throw new Error(`"create-app-definition" is not available in non-interactive mode`);
|
|
14
|
+
};
|
|
15
|
+
exports.createAppDefinition = {
|
|
16
|
+
interactive,
|
|
17
|
+
nonInteractive,
|
|
18
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ClientAPI } from 'contentful-management';
|
|
2
|
+
export interface Definition {
|
|
3
|
+
name: string;
|
|
4
|
+
value: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function selectDefinition(client: ClientAPI, orgId: string): Promise<Definition>;
|
|
7
|
+
export declare function getDefinitionById(client: ClientAPI, orgId: string, defId: string): Promise<Definition>;
|
package/lib/definition-api.js
CHANGED
|
@@ -1,50 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getDefinitionById = exports.selectDefinition = void 0;
|
|
7
|
+
const ora_1 = __importDefault(require("ora"));
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
const constants_1 = require("./constants");
|
|
6
10
|
async function fetchDefinitions(client, orgId) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
);
|
|
19
|
-
}
|
|
11
|
+
try {
|
|
12
|
+
const organization = await client.getOrganization(orgId);
|
|
13
|
+
const definitions = await organization.getAppDefinitions();
|
|
14
|
+
return definitions.items.map((def) => ({
|
|
15
|
+
name: def.name,
|
|
16
|
+
value: def.sys.id,
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
return (0, utils_1.throwError)(err, 'Could not fetch your app-definitions. Make sure you provided a valid access token.');
|
|
21
|
+
}
|
|
20
22
|
}
|
|
21
|
-
|
|
22
23
|
async function selectDefinition(client, orgId) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return await selectFromList(definitions, 'Select an app:', APP_DEF_ENV_KEY);
|
|
24
|
+
const defSpinner = (0, ora_1.default)('Fetching all definitions...').start();
|
|
25
|
+
const definitions = await fetchDefinitions(client, orgId);
|
|
26
|
+
defSpinner.stop();
|
|
27
|
+
return await (0, utils_1.selectFromList)(definitions, 'Select an app:', constants_1.APP_DEF_ENV_KEY);
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
exports.selectDefinition = selectDefinition;
|
|
30
30
|
async function getDefinitionById(client, orgId, defId) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
);
|
|
43
|
-
throw err;
|
|
44
|
-
}
|
|
31
|
+
try {
|
|
32
|
+
const organization = await client.getOrganization(orgId);
|
|
33
|
+
const definition = await organization.getAppDefinition(defId);
|
|
34
|
+
return {
|
|
35
|
+
name: definition.name,
|
|
36
|
+
value: definition.sys.id,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
return (0, utils_1.throwError)(err, 'Could not fetch your app-definition. Make sure you provided a valid definition id or access token.');
|
|
41
|
+
}
|
|
45
42
|
}
|
|
46
|
-
|
|
47
|
-
module.exports = {
|
|
48
|
-
selectDefinition,
|
|
49
|
-
getDefinitionById,
|
|
50
|
-
};
|
|
43
|
+
exports.getDefinitionById = getDefinitionById;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const getAppInfo: ({ organizationId, definitionId, token, host, }: {
|
|
2
|
+
organizationId?: string | undefined;
|
|
3
|
+
definitionId?: string | undefined;
|
|
4
|
+
token?: string | undefined;
|
|
5
|
+
host?: string | undefined;
|
|
6
|
+
}) => Promise<{
|
|
7
|
+
accessToken: string;
|
|
8
|
+
organization: import("./organization-api").Organization;
|
|
9
|
+
definition: import("./definition-api").Definition;
|
|
10
|
+
}>;
|
package/lib/get-app-info.js
CHANGED
|
@@ -1,28 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
definition,
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
module.exports = {
|
|
27
|
-
getAppInfo,
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAppInfo = void 0;
|
|
4
|
+
const definition_api_1 = require("./definition-api");
|
|
5
|
+
const organization_api_1 = require("./organization-api");
|
|
6
|
+
const contentful_management_1 = require("contentful-management");
|
|
7
|
+
const get_management_token_1 = require("./get-management-token");
|
|
8
|
+
const getAppInfo = async ({ organizationId, definitionId, token, host, }) => {
|
|
9
|
+
const accessToken = token || (await (0, get_management_token_1.getManagementToken)(host));
|
|
10
|
+
const client = (0, contentful_management_1.createClient)({ accessToken, host });
|
|
11
|
+
const organization = organizationId
|
|
12
|
+
? await (0, organization_api_1.getOrganizationById)(client, organizationId)
|
|
13
|
+
: await (0, organization_api_1.selectOrganization)(client);
|
|
14
|
+
const definition = definitionId
|
|
15
|
+
? await (0, definition_api_1.getDefinitionById)(client, organization.value, definitionId)
|
|
16
|
+
: await (0, definition_api_1.selectDefinition)(client, organization.value);
|
|
17
|
+
return {
|
|
18
|
+
accessToken,
|
|
19
|
+
organization,
|
|
20
|
+
definition,
|
|
21
|
+
};
|
|
28
22
|
};
|
|
23
|
+
exports.getAppInfo = getAppInfo;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getManagementToken(host?: string): Promise<string>;
|
|
@@ -1,64 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/* eslint-disable no-console, no-process-exit */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const open = require('open');
|
|
5
|
-
const inquirer = require('inquirer');
|
|
6
|
-
const { cacheEnvVars } = require('../utils/cache-credential');
|
|
7
|
-
const { createClient } = require('contentful-management');
|
|
8
|
-
const { ACCESS_TOKEN_ENV_KEY } = require('../utils/constants');
|
|
9
|
-
|
|
10
|
-
const checkTokenValidity = async (accessToken, host) => {
|
|
11
|
-
try {
|
|
12
|
-
const client = createClient({ accessToken, host });
|
|
13
|
-
await client.getCurrentUser();
|
|
14
|
-
return true;
|
|
15
|
-
} catch (err) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
5
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return cachedAccessToken;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
open(oauthUrl);
|
|
36
|
-
} catch (err) {
|
|
37
|
-
console.log(`${chalk.red('Error:')} Failed to open browser`);
|
|
38
|
-
console.log(err.message);
|
|
39
|
-
throw err;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const { mgmtToken } = await inquirer.prompt([
|
|
43
|
-
{
|
|
44
|
-
name: 'mgmtToken',
|
|
45
|
-
message: 'Please paste your access token:',
|
|
46
|
-
type: 'password',
|
|
47
|
-
validate(answer) {
|
|
48
|
-
if (!answer) {
|
|
49
|
-
return `${chalk.red('Error:')} Failed to login into Contentful.`;
|
|
50
|
-
}
|
|
51
|
-
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getManagementToken = void 0;
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const open_1 = __importDefault(require("open"));
|
|
10
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
11
|
+
const cache_credential_1 = require("./cache-credential");
|
|
12
|
+
const contentful_management_1 = require("contentful-management");
|
|
13
|
+
const constants_1 = require("./constants");
|
|
14
|
+
const checkTokenValidity = async (accessToken = '', host) => {
|
|
15
|
+
try {
|
|
16
|
+
const client = (0, contentful_management_1.createClient)({ accessToken, host });
|
|
17
|
+
await client.getCurrentUser();
|
|
52
18
|
return true;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
await cacheEnvVars({ [ACCESS_TOKEN_ENV_KEY]: mgmtToken });
|
|
58
|
-
|
|
59
|
-
return mgmtToken;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
module.exports = {
|
|
63
|
-
getManagementToken,
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
64
23
|
};
|
|
24
|
+
async function getManagementToken(host) {
|
|
25
|
+
const redirectUrl = 'https://www.contentful.com/developers/cli-oauth-page/';
|
|
26
|
+
const CLIENT_ID = '9f86a1d54f3d6f85c159468f5919d6e5d27716b3ed68fd01bd534e3dea2df864';
|
|
27
|
+
const oauthUrl = `https://be.contentful.com/oauth/authorize?response_type=token&scope=content_management_manage&client_id=${CLIENT_ID}&&redirect_uri=${encodeURIComponent(redirectUrl)}`;
|
|
28
|
+
const cachedAccessToken = process.env[constants_1.ACCESS_TOKEN_ENV_KEY];
|
|
29
|
+
const cachedTokenValid = await checkTokenValidity(cachedAccessToken, host);
|
|
30
|
+
if (cachedTokenValid) {
|
|
31
|
+
return cachedAccessToken;
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
(0, open_1.default)(oauthUrl);
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
console.log(`${chalk_1.default.red('Error:')} Failed to open browser`);
|
|
38
|
+
console.log(err.message);
|
|
39
|
+
throw err;
|
|
40
|
+
}
|
|
41
|
+
const { mgmtToken } = await inquirer_1.default.prompt([
|
|
42
|
+
{
|
|
43
|
+
name: 'mgmtToken',
|
|
44
|
+
message: 'Please paste your access token:',
|
|
45
|
+
type: 'password',
|
|
46
|
+
validate(answer) {
|
|
47
|
+
if (!answer) {
|
|
48
|
+
return `${chalk_1.default.red('Error:')} Failed to login into Contentful.`;
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
]);
|
|
54
|
+
await (0, cache_credential_1.cacheEnvVars)({ [constants_1.ACCESS_TOKEN_ENV_KEY]: mgmtToken });
|
|
55
|
+
return mgmtToken;
|
|
56
|
+
}
|
|
57
|
+
exports.getManagementToken = getManagementToken;
|
package/lib/index.d.ts
ADDED
package/lib/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.track = exports.open = exports.cleanup = exports.activate = exports.upload = exports.createAppDefinition = void 0;
|
|
4
|
+
var create_app_definition_1 = require("./create-app-definition");
|
|
5
|
+
Object.defineProperty(exports, "createAppDefinition", { enumerable: true, get: function () { return create_app_definition_1.createAppDefinition; } });
|
|
6
|
+
var upload_1 = require("./upload");
|
|
7
|
+
Object.defineProperty(exports, "upload", { enumerable: true, get: function () { return upload_1.upload; } });
|
|
8
|
+
var activate_1 = require("./activate");
|
|
9
|
+
Object.defineProperty(exports, "activate", { enumerable: true, get: function () { return activate_1.activate; } });
|
|
10
|
+
var clean_up_1 = require("./clean-up");
|
|
11
|
+
Object.defineProperty(exports, "cleanup", { enumerable: true, get: function () { return clean_up_1.cleanup; } });
|
|
12
|
+
var open_1 = require("./open");
|
|
13
|
+
Object.defineProperty(exports, "open", { enumerable: true, get: function () { return open_1.open; } });
|
|
14
|
+
var analytics_1 = require("./analytics");
|
|
15
|
+
Object.defineProperty(exports, "track", { enumerable: true, get: function () { return analytics_1.track; } });
|
package/lib/open/index.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.open = void 0;
|
|
4
|
+
const open_settings_1 = require("./open-settings");
|
|
5
|
+
const interactive = async (options) => {
|
|
6
|
+
(0, open_settings_1.openSettings)(options);
|
|
7
|
+
};
|
|
8
|
+
const nonInteractive = async () => {
|
|
8
9
|
throw new Error(`"open-settings" is not available in non-interactive mode`);
|
|
9
|
-
|
|
10
|
+
};
|
|
11
|
+
exports.open = {
|
|
12
|
+
interactive,
|
|
13
|
+
nonInteractive,
|
|
10
14
|
};
|