@contentful/app-scripts 1.32.2 → 1.32.3

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
@@ -177,6 +177,16 @@ You can also execute this command without the argument if the environment variab
177
177
  > $ CONTENTFUL_APP_DEF_ID=some-definition-id npx --no-install @contentful/app-scripts open-settings
178
178
  > ```
179
179
 
180
+ **Options:**
181
+
182
+ | Argument | Description | Default value |
183
+ | ----------------- | -------------------------------------------- | -------------------- |
184
+ | |
185
+ | `--definition-id` | The ID of the app to which to add the bundle |
186
+ | `--host` | (optional) Contentful CMA-endpoint to use | `api.contentful.com` |
187
+
188
+ **Note:** You can also pass all arguments in interactive mode to skip being asked for it.
189
+
180
190
  ### Clean up bundles
181
191
 
182
192
  Allows you to clean the list of previous bundles. It fetches the list and deletes all bundles except the 50 newest ones.
@@ -246,6 +256,16 @@ By default, the script will install the app into the default host URL: `app.cont
246
256
  > $ npx --no-install @contentful/app-scripts install --definition-id some-definition-id --host api.eu.contentful.com
247
257
  > ```
248
258
 
259
+ **Options:**
260
+
261
+ | Argument | Description | Default value |
262
+ | ----------------- | -------------------------------------------- | -------------------- |
263
+ | |
264
+ | `--definition-id` | The ID of the app to which to add the bundle |
265
+ | `--host` | (optional) Contentful CMA-endpoint to use | `api.contentful.com` |
266
+
267
+ **Note:** You can also pass all arguments in interactive mode to skip being asked for it.
268
+
249
269
  ### Tracking
250
270
 
251
271
  We gather depersonalized usage data of our CLI tools in order to improve experience. If you do not want your data to be gathered, you can opt out by providing an env variable `DISABLE_ANALYTICS` set to any value:
@@ -286,7 +306,7 @@ When passing the `--ci` argument adding all variables as arguments is required
286
306
  **Options:**
287
307
 
288
308
  Options:
289
- -e, --esbuild-config <path> custom esbuild config file path
290
- -m, --manifest-file <path> Contentful app manifest file path
291
- -w, --watch watch for changes
292
- -h, --help display help for command
309
+ -e, --esbuild-config <path> custom esbuild config file path
310
+ -m, --manifest-file <path> Contentful app manifest file path
311
+ -w, --watch watch for changes
312
+ -h, --help display help for command
@@ -23,11 +23,12 @@ async function buildBundleActivateSettings(options) {
23
23
  default: 'api.contentful.com',
24
24
  });
25
25
  }
26
- const appActivateSettings = await inquirer_1.default.prompt(prompts);
27
- const appInfo = await (0, get_app_info_1.getAppInfo)(options);
26
+ const { host: interactiveHost, ...appActivateSettings } = await inquirer_1.default.prompt(prompts);
27
+ const hostValue = host || interactiveHost;
28
+ const appInfo = await (0, get_app_info_1.getAppInfo)({ ...options, host: hostValue });
28
29
  return {
29
30
  bundleId,
30
- host,
31
+ host: hostValue,
31
32
  ...appActivateSettings,
32
33
  ...appInfo,
33
34
  };
package/lib/bin.js CHANGED
@@ -26,7 +26,7 @@ async function runCommand(command, options) {
26
26
  .option('--token [accessToken]', 'Your content management access token')
27
27
  .option('--comment [comment]', 'Optional comment for the created bundle')
28
28
  .option('--skip-activation', 'A Boolean flag to skip automatic activation')
29
- .option('--host [host]', 'Contentful domain to use')
29
+ .option('--host [host]', 'Contentful subdomain to use, e.g. "api.contentful.com"')
30
30
  .action(async (options) => {
31
31
  await runCommand(index_1.upload, options);
32
32
  });
@@ -37,7 +37,7 @@ async function runCommand(command, options) {
37
37
  .option('--organization-id [orgId]', 'The id of your organization')
38
38
  .option('--definition-id [defId]', 'The id of your apps definition')
39
39
  .option('--token [accessToken]', 'Your content management access token')
40
- .option('--host [host]', 'Contentful domain to use')
40
+ .option('--host [host]', 'Contentful subdomain to use, e.g. "api.contentful.com"')
41
41
  .action(async (options) => {
42
42
  await runCommand(index_1.activate, options);
43
43
  });
@@ -45,6 +45,7 @@ async function runCommand(command, options) {
45
45
  .command('open-settings')
46
46
  .description('Opens the app editor for a given AppDefinition')
47
47
  .option('--definition-id [defId]', 'The id of your apps definition')
48
+ .option('--host [host]', 'Contentful subdomain to use, e.g. "api.contentful.com"')
48
49
  .action(async (options) => {
49
50
  await runCommand(index_1.open, options);
50
51
  });
@@ -55,7 +56,7 @@ async function runCommand(command, options) {
55
56
  .option('--definition-id [defId]', 'The id of your apps definition')
56
57
  .option('--token [accessToken]', 'Your content management access token')
57
58
  .option('--keep [keepAmount]', 'The amount of bundles that should remain')
58
- .option('--host [host]', 'Contentful domain to use')
59
+ .option('--host [host]', 'Contentful subdomain to use, e.g. "api.contentful.com"')
59
60
  .action(async (options) => {
60
61
  await runCommand(index_1.cleanup, options);
61
62
  });
@@ -69,7 +70,7 @@ async function runCommand(command, options) {
69
70
  .command('install')
70
71
  .description('Opens a picker to select the space and environment for installing the app associated with a given AppDefinition')
71
72
  .option('--definition-id [defId]', 'The id of your apps definition')
72
- .option('--host [host]', 'Contentful domain to use')
73
+ .option('--host [host]', 'Contentful subdomain to use, e.g. "api.contentful.com"')
73
74
  .action(async (options) => {
74
75
  await runCommand(index_1.install, options);
75
76
  });
@@ -22,11 +22,12 @@ async function buildCleanUpSettings(options) {
22
22
  default: constants_1.DEFAULT_CONTENTFUL_API_HOST,
23
23
  });
24
24
  }
25
- const appCleanUpSettings = await (0, inquirer_1.prompt)(prompts);
26
- const appInfo = await (0, get_app_info_1.getAppInfo)(options);
25
+ const { host: interactiveHost, ...appCleanUpSettings } = await (0, inquirer_1.prompt)(prompts);
26
+ const hostValue = host || interactiveHost;
27
+ const appInfo = await (0, get_app_info_1.getAppInfo)({ ...options, host: hostValue });
27
28
  return {
28
29
  keep: keep === undefined ? +appCleanUpSettings.keep : +keep,
29
- host,
30
+ host: hostValue,
30
31
  ...appCleanUpSettings,
31
32
  ...appInfo,
32
33
  };
@@ -42,7 +42,8 @@ function assertValidArguments(accessToken, appDefinitionSettings) {
42
42
  }
43
43
  async function createAppDefinition(accessToken, appDefinitionSettings) {
44
44
  assertValidArguments(accessToken, appDefinitionSettings);
45
- const client = (0, contentful_management_1.createClient)({ accessToken, host: appDefinitionSettings.host });
45
+ const host = appDefinitionSettings.host;
46
+ const client = (0, contentful_management_1.createClient)({ accessToken, host });
46
47
  const organizations = await fetchOrganizations(client);
47
48
  const selectedOrg = await (0, utils_1.selectFromList)(organizations, 'Select an organization for your app:', constants_1.ORG_ID_ENV_KEY);
48
49
  const organizationId = selectedOrg.value;
@@ -92,16 +93,17 @@ async function createAppDefinition(accessToken, appDefinitionSettings) {
92
93
  await (0, cache_credential_1.cacheEnvVars)({
93
94
  [constants_1.APP_DEF_ENV_KEY]: createdAppDefinition.sys.id,
94
95
  });
96
+ const webApp = (0, utils_1.getWebAppHostname)(host);
95
97
  console.log(`
96
98
  ${chalk_1.default.greenBright('Success!')} Created an app definition for ${chalk_1.default.bold(appName)} in ${chalk_1.default.bold(selectedOrg.name)}.
97
99
 
98
- ${chalk_1.default.dim(`NOTE: You can update this app definition in your organization settings:
99
- ${chalk_1.default.underline(`https://app.contentful.com/deeplink?link=org`)}`)}
100
+ ${chalk_1.default.dim(`NOTE: You can update this app definition in your apps settings:
101
+ ${chalk_1.default.underline(`https://${webApp}/deeplink?link=app-definition-list`)}`)}
100
102
 
101
103
  ${chalk_1.default.bold('Next steps:')}
102
104
  1. Run your app with ${chalk_1.default.cyan('`npm start`')} inside of your app folder.
103
105
  2. Install this app definition to one of your spaces by opening:
104
- ${chalk_1.default.underline(`https://app.contentful.com/deeplink?link=apps&id=${createdAppDefinition.sys.id}`)}
106
+ ${chalk_1.default.underline(`https://${webApp}/deeplink?link=apps&id=${createdAppDefinition.sys.id}`)}
105
107
  3. Learn how to build your first Contentful app:
106
108
  ${chalk_1.default.underline(`https://ctfl.io/app-tutorial`)}
107
109
  `);
@@ -8,8 +8,10 @@ const open_1 = __importDefault(require("open"));
8
8
  const chalk_1 = __importDefault(require("chalk"));
9
9
  const inquirer_1 = __importDefault(require("inquirer"));
10
10
  const constants_1 = require("../constants");
11
+ const utils_1 = require("../utils");
11
12
  async function installToEnvironment(options) {
12
13
  let definitionId;
14
+ const prompts = [];
13
15
  if (options.definitionId) {
14
16
  definitionId = options.definitionId;
15
17
  }
@@ -17,15 +19,22 @@ async function installToEnvironment(options) {
17
19
  definitionId = process.env[constants_1.APP_DEF_ENV_KEY];
18
20
  }
19
21
  else {
20
- const prompts = await inquirer_1.default.prompt([
21
- {
22
- name: 'definitionId',
23
- message: `The id of the app:`,
24
- },
25
- ]);
26
- definitionId = prompts.definitionId;
22
+ prompts.push({
23
+ name: 'definitionId',
24
+ message: `The id of the app:`,
25
+ });
27
26
  }
28
- if (!definitionId) {
27
+ if (!options.host) {
28
+ prompts.push({
29
+ name: 'host',
30
+ message: `Contentful CMA endpoint URL:`,
31
+ default: constants_1.DEFAULT_CONTENTFUL_API_HOST,
32
+ });
33
+ }
34
+ const openSettingsOptions = await inquirer_1.default.prompt(prompts);
35
+ const hostValue = options.host || openSettingsOptions?.host;
36
+ const appDefinitionIdValue = definitionId || openSettingsOptions?.definitionId;
37
+ if (!appDefinitionIdValue) {
29
38
  console.log(`
30
39
  ${chalk_1.default.red('Error:')} There was no app-definition defined.
31
40
 
@@ -34,8 +43,8 @@ async function installToEnvironment(options) {
34
43
  `);
35
44
  throw new Error('No app-definition-id');
36
45
  }
37
- const host = options.host || constants_1.DEFAULT_CONTENTFUL_APP_HOST;
38
- const redirectUrl = `https://${host}/deeplink?link=apps`;
46
+ const webApp = (0, utils_1.getWebAppHostname)(hostValue);
47
+ const redirectUrl = `https://${webApp}/deeplink?link=apps`;
39
48
  try {
40
49
  (0, open_1.default)(`${redirectUrl}&id=${definitionId}`);
41
50
  }
@@ -1,3 +1,2 @@
1
1
  import { OpenSettingsOptions } from '../types';
2
- export declare const REDIRECT_URL = "https://app.contentful.com/deeplink?link=app-definition";
3
2
  export declare function openSettings(options: OpenSettingsOptions): Promise<void>;
@@ -3,15 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.REDIRECT_URL = void 0;
7
6
  exports.openSettings = openSettings;
8
7
  const open_1 = __importDefault(require("open"));
9
8
  const chalk_1 = __importDefault(require("chalk"));
10
9
  const inquirer_1 = __importDefault(require("inquirer"));
11
10
  const constants_1 = require("../constants");
12
- exports.REDIRECT_URL = 'https://app.contentful.com/deeplink?link=app-definition';
11
+ const utils_1 = require("../utils");
13
12
  async function openSettings(options) {
14
13
  let definitionId;
14
+ const prompts = [];
15
15
  if (options.definitionId) {
16
16
  definitionId = options.definitionId;
17
17
  }
@@ -19,15 +19,22 @@ async function openSettings(options) {
19
19
  definitionId = process.env[constants_1.APP_DEF_ENV_KEY];
20
20
  }
21
21
  else {
22
- const prompts = await inquirer_1.default.prompt([
23
- {
24
- name: 'definitionId',
25
- message: `The id of the app:`,
26
- },
27
- ]);
28
- definitionId = prompts.definitionId;
22
+ prompts.push({
23
+ name: 'definitionId',
24
+ message: `The id of the app:`,
25
+ });
29
26
  }
30
- if (!definitionId) {
27
+ if (!options.host) {
28
+ prompts.push({
29
+ name: 'host',
30
+ message: `Contentful CMA endpoint URL:`,
31
+ default: constants_1.DEFAULT_CONTENTFUL_API_HOST,
32
+ });
33
+ }
34
+ const openSettingsOptions = await inquirer_1.default.prompt(prompts);
35
+ const hostValue = options.host || openSettingsOptions?.host;
36
+ const appDefinitionIdValue = definitionId || openSettingsOptions?.definitionId;
37
+ if (!appDefinitionIdValue) {
31
38
  console.log(`
32
39
  ${chalk_1.default.red('Error:')} There was no app-definition defined.
33
40
 
@@ -36,8 +43,10 @@ async function openSettings(options) {
36
43
  `);
37
44
  throw new Error('No app-definition-id');
38
45
  }
46
+ const webApp = (0, utils_1.getWebAppHostname)(hostValue);
47
+ const redirectUrl = `https://${webApp}/deeplink?link=app-definition`;
39
48
  try {
40
- (0, open_1.default)(`${exports.REDIRECT_URL}&id=${definitionId}`);
49
+ (0, open_1.default)(`${redirectUrl}&id=${appDefinitionIdValue}`);
41
50
  }
42
51
  catch (err) {
43
52
  console.log(`${chalk_1.default.red('Error:')} Failed to open browser`);
package/lib/types.d.ts CHANGED
@@ -49,6 +49,7 @@ export interface CleanupSettings {
49
49
  }
50
50
  export interface OpenSettingsOptions {
51
51
  definitionId?: string;
52
+ host?: string;
52
53
  }
53
54
  export interface InstallOptions {
54
55
  definitionId?: string;
@@ -41,13 +41,14 @@ async function buildAppUploadSettings(options) {
41
41
  filter: hostProtocolFilter,
42
42
  });
43
43
  }
44
- const { activateBundle, ...appUploadSettings } = await (0, inquirer_1.prompt)(prompts);
45
- const appInfo = await (0, get_app_info_1.getAppInfo)(options);
44
+ const { activateBundle, host: interactiveHost, ...appUploadSettings } = await (0, inquirer_1.prompt)(prompts);
45
+ const hostValue = host || interactiveHost;
46
+ const appInfo = await (0, get_app_info_1.getAppInfo)({ ...options, host: hostValue });
46
47
  return {
47
48
  bundleDirectory: bundleDir,
48
49
  skipActivation: skipActivation === undefined ? !activateBundle : skipActivation,
49
50
  comment,
50
- host,
51
+ host: hostValue,
51
52
  actions: actionsManifest,
52
53
  functions: functionManifest,
53
54
  ...appUploadSettings,
@@ -59,13 +59,14 @@ async function createAppBundleFromSettings(settings) {
59
59
 
60
60
  Bundle Id: ${chalk_1.default.yellow(appBundle.sys.id)}
61
61
  `);
62
+ const webApp = (0, utils_1.getWebAppHostname)(settings.host);
62
63
  if (settings.skipActivation) {
63
64
  console.log(`
64
65
  ${chalk_1.default.green(`NEXT STEPS:`)}
65
66
 
66
67
  ${chalk_1.default.bold('You can activate this app bundle in your apps settings:')}
67
68
 
68
- ${chalk_1.default.underline('https://app.contentful.com/deeplink?link=app-definition-list')}
69
+ ${chalk_1.default.underline(`https://${webApp}/deeplink?link=app-definition-list`)}
69
70
 
70
71
  ${chalk_1.default.bold('or by simply running the cli command:')}
71
72
 
package/lib/utils.d.ts CHANGED
@@ -9,4 +9,5 @@ export declare const throwError: (err: Error, message: string) => never;
9
9
  export declare const selectFromList: <T extends Definition | Organization>(list: T[], message: string, cachedOptionEnvVar: string) => Promise<T>;
10
10
  type Entities<Type> = Type extends 'actions' ? Omit<FunctionAppAction, 'entryFile'>[] : Omit<ContentfulFunction, 'entryFile'>[];
11
11
  export declare function getEntityFromManifest<Type extends 'actions' | 'functions'>(type: Type): Entities<Type> | undefined;
12
+ export declare function getWebAppHostname(host: string | undefined): string;
12
13
  export {};
package/lib/utils.js CHANGED
@@ -5,10 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.selectFromList = exports.throwError = exports.showCreationError = exports.stripProtocol = exports.isValidNetwork = exports.throwValidationException = void 0;
7
7
  exports.getEntityFromManifest = getEntityFromManifest;
8
+ exports.getWebAppHostname = getWebAppHostname;
8
9
  const fs_1 = __importDefault(require("fs"));
9
10
  const chalk_1 = __importDefault(require("chalk"));
10
11
  const inquirer_1 = __importDefault(require("inquirer"));
11
12
  const cache_credential_1 = require("./cache-credential");
13
+ const constants_1 = require("./constants");
12
14
  const DEFAULT_MANIFEST_PATH = './contentful-app-manifest.json';
13
15
  const functionEvents = {
14
16
  appActionCall: 'appaction.call',
@@ -19,7 +21,7 @@ const functionEvents = {
19
21
  resourceTypeMappingEvent: 'graphql.resourcetype.mapping',
20
22
  queryEvent: 'graphql.query',
21
23
  resourceLinksSearchEvent: 'resources.search',
22
- resourceLinksLookupEvent: 'resources.lookup'
24
+ resourceLinksLookupEvent: 'resources.lookup',
23
25
  };
24
26
  const throwValidationException = (subject, message, details) => {
25
27
  console.log(`${chalk_1.default.red('Validation Error:')} Missing or invalid ${subject}.`);
@@ -148,3 +150,6 @@ function getEntityFromManifest(type) {
148
150
  process.exit(1);
149
151
  }
150
152
  }
153
+ function getWebAppHostname(host) {
154
+ return host && host.includes('api') ? host.replace('api', 'app') : constants_1.DEFAULT_CONTENTFUL_APP_HOST;
155
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/app-scripts",
3
- "version": "1.32.2",
3
+ "version": "1.32.3",
4
4
  "description": "A collection of scripts for building Contentful Apps",
5
5
  "author": "Contentful GmbH",
6
6
  "license": "MIT",
@@ -54,23 +54,23 @@
54
54
  "bottleneck": "2.19.5",
55
55
  "chalk": "4.1.2",
56
56
  "commander": "12.1.0",
57
- "contentful-management": "11.40.3",
57
+ "contentful-management": "11.47.1",
58
58
  "dotenv": "16.4.7",
59
59
  "esbuild": "^0.24.0",
60
- "ignore": "7.0.0",
60
+ "ignore": "7.0.3",
61
61
  "inquirer": "8.2.6",
62
62
  "lodash": "4.17.21",
63
63
  "open": "8.4.2",
64
64
  "ora": "5.4.1",
65
65
  "zod": "^3.24.1"
66
66
  },
67
- "gitHead": "5bc6d159d2a14c8df1fc67f5fb30829094146a6b",
67
+ "gitHead": "0164f4178143298b7b042452670f591830b15968",
68
68
  "devDependencies": {
69
69
  "@types/adm-zip": "0.5.7",
70
70
  "@types/analytics-node": "3.1.14",
71
71
  "@types/chai": "4.3.16",
72
72
  "@types/inquirer": "8.2.1",
73
- "@types/lodash": "4.17.13",
73
+ "@types/lodash": "4.17.15",
74
74
  "@types/mocha": "10.0.10",
75
75
  "@types/proxyquire": "1.3.31",
76
76
  "@types/sinon": "17.0.3",