@contentful/app-scripts 1.33.0-alpha.0 → 1.33.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 +0 -40
- package/lib/bin.js +12 -13
- package/lib/build-functions/build-functions.d.ts +1 -0
- package/lib/build-functions/build-functions.js +10 -5
- package/lib/generate-function/build-generate-function-settings.d.ts +3 -0
- package/lib/generate-function/build-generate-function-settings.js +153 -0
- package/lib/generate-function/clone.d.ts +14 -0
- package/lib/generate-function/clone.js +144 -0
- package/lib/generate-function/constants.d.ts +9 -0
- package/lib/generate-function/constants.js +14 -0
- package/lib/generate-function/create-function.d.ts +2 -0
- package/lib/generate-function/create-function.js +10 -0
- package/lib/generate-function/get-github-folder-names.d.ts +1 -0
- package/lib/generate-function/get-github-folder-names.js +25 -0
- package/lib/generate-function/index.d.ts +5 -0
- package/lib/generate-function/index.js +17 -0
- package/lib/generate-function/logger.d.ts +8 -0
- package/lib/generate-function/logger.js +54 -0
- package/lib/generate-function/types.d.ts +4 -0
- package/lib/generate-function/types.js +9 -0
- package/lib/generate-function/utils/file.d.ts +15 -0
- package/lib/generate-function/utils/file.js +51 -0
- package/lib/generate-function/utils/package.d.ts +5 -0
- package/lib/generate-function/utils/package.js +23 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +3 -3
- package/lib/types.d.ts +29 -0
- package/lib/upload/build-upload-settings.js +3 -1
- package/lib/upload/create-app-bundle.js +2 -1
- package/lib/upload/create-zip-from-directory.d.ts +1 -1
- package/lib/upload/get-upload-settings-args.js +3 -1
- package/lib/upload/validate-bundle.d.ts +1 -1
- package/lib/upload/validate-bundle.js +8 -2
- package/lib/utils.d.ts +4 -6
- package/lib/utils.js +8 -16
- package/package.json +6 -3
- package/lib/upsert-actions/client.d.ts +0 -4
- package/lib/upsert-actions/client.js +0 -37
- package/lib/upsert-actions/get-cli-args.d.ts +0 -2
- package/lib/upsert-actions/get-cli-args.js +0 -40
- package/lib/upsert-actions/index.d.ts +0 -5
- package/lib/upsert-actions/index.js +0 -18
- package/lib/upsert-actions/make-cma-payload.d.ts +0 -2
- package/lib/upsert-actions/make-cma-payload.js +0 -39
- package/lib/upsert-actions/prompt-interactive-args.d.ts +0 -2
- package/lib/upsert-actions/prompt-interactive-args.js +0 -36
- package/lib/upsert-actions/types.d.ts +0 -52
- package/lib/upsert-actions/types.js +0 -2
- package/lib/upsert-actions/upsert-actions.d.ts +0 -16
- package/lib/upsert-actions/upsert-actions.js +0 -80
- package/lib/upsert-actions/validation.d.ts +0 -9
- package/lib/upsert-actions/validation.js +0 -77
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InvalidTemplateError = exports.HTTPResponseError = void 0;
|
|
4
|
+
class HTTPResponseError extends Error {
|
|
5
|
+
}
|
|
6
|
+
exports.HTTPResponseError = HTTPResponseError;
|
|
7
|
+
class InvalidTemplateError extends Error {
|
|
8
|
+
}
|
|
9
|
+
exports.InvalidTemplateError = InvalidTemplateError;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare function getJsonData(path: string | undefined): Promise<Record<string, any> | undefined>;
|
|
2
|
+
export type MergeJsonIntoFileOptions = {
|
|
3
|
+
destination: string;
|
|
4
|
+
source?: string;
|
|
5
|
+
mergeFn?: (destinationJson?: Record<string, any>, sourceJson?: Record<string, any>) => Record<string, any>;
|
|
6
|
+
};
|
|
7
|
+
export declare function mergeJsonIntoFile({ source, destination, mergeFn, }: MergeJsonIntoFileOptions): Promise<void>;
|
|
8
|
+
export declare function exists(path: string): Promise<boolean>;
|
|
9
|
+
/**
|
|
10
|
+
* Check a directory if two files exist, returning the first one that exists or "None"
|
|
11
|
+
* @param basePath Base path
|
|
12
|
+
* @param paths List of paths, in order of preference
|
|
13
|
+
* @returns First subpath if it exists, otherwise the second if it exists, otherwise "None"
|
|
14
|
+
*/
|
|
15
|
+
export declare function whichExists(basePath: string, paths: string[]): Promise<string>;
|
|
@@ -0,0 +1,51 @@
|
|
|
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.getJsonData = getJsonData;
|
|
7
|
+
exports.mergeJsonIntoFile = mergeJsonIntoFile;
|
|
8
|
+
exports.exists = exists;
|
|
9
|
+
exports.whichExists = whichExists;
|
|
10
|
+
const merge_options_1 = __importDefault(require("merge-options"));
|
|
11
|
+
const promises_1 = require("fs/promises");
|
|
12
|
+
const path_1 = require("path");
|
|
13
|
+
async function getJsonData(path) {
|
|
14
|
+
if (!path) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
const normalizedPath = (0, path_1.resolve)(path);
|
|
18
|
+
if (!(await exists(normalizedPath))) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
return JSON.parse(await (0, promises_1.readFile)(normalizedPath, { encoding: 'utf-8' }));
|
|
22
|
+
}
|
|
23
|
+
async function mergeJsonIntoFile({ source, destination, mergeFn = merge_options_1.default.bind({ concatArrays: false }), }) {
|
|
24
|
+
const sourceJson = await getJsonData(source);
|
|
25
|
+
const destinationJson = await getJsonData(destination);
|
|
26
|
+
const mergedJson = mergeFn(destinationJson, sourceJson);
|
|
27
|
+
await (0, promises_1.writeFile)((0, path_1.resolve)(destination), JSON.stringify(mergedJson, null, ' '));
|
|
28
|
+
}
|
|
29
|
+
function exists(path) {
|
|
30
|
+
return (0, promises_1.access)(path)
|
|
31
|
+
.then(() => true)
|
|
32
|
+
.catch(() => false);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Check a directory if two files exist, returning the first one that exists or "None"
|
|
36
|
+
* @param basePath Base path
|
|
37
|
+
* @param paths List of paths, in order of preference
|
|
38
|
+
* @returns First subpath if it exists, otherwise the second if it exists, otherwise "None"
|
|
39
|
+
*/
|
|
40
|
+
async function whichExists(basePath, paths) {
|
|
41
|
+
for (const path of paths) {
|
|
42
|
+
try {
|
|
43
|
+
await (0, promises_1.access)((0, path_1.join)(basePath, path));
|
|
44
|
+
return path;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
// Ignore and continue checking the next path
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return "None";
|
|
51
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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.getAddBuildCommandFn = getAddBuildCommandFn;
|
|
7
|
+
const merge_options_1 = __importDefault(require("merge-options"));
|
|
8
|
+
function getAddBuildCommandFn({ name, command }) {
|
|
9
|
+
return (packageJson, additionalProperties) => {
|
|
10
|
+
let destBuildCommand = packageJson?.scripts?.build ?? '';
|
|
11
|
+
const sourceBuildCommand = additionalProperties?.scripts?.build ?? command;
|
|
12
|
+
const triggerCommand = `npm run ${name}`;
|
|
13
|
+
if (destBuildCommand === '') {
|
|
14
|
+
destBuildCommand = triggerCommand;
|
|
15
|
+
}
|
|
16
|
+
else if (!destBuildCommand.split(/\s*&+\s*/).includes(triggerCommand)) {
|
|
17
|
+
destBuildCommand += ` && ${triggerCommand}`;
|
|
18
|
+
}
|
|
19
|
+
return (0, merge_options_1.default)({}, packageJson, additionalProperties, {
|
|
20
|
+
scripts: { [name]: sourceBuildCommand, build: destBuildCommand },
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -7,4 +7,4 @@ export { track } from './analytics';
|
|
|
7
7
|
export { feedback } from './feedback';
|
|
8
8
|
export { install } from './install';
|
|
9
9
|
export { buildFunctions } from './build-functions';
|
|
10
|
-
export {
|
|
10
|
+
export { generateFunction } from './generate-function';
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.generateFunction = exports.buildFunctions = exports.install = exports.feedback = exports.track = exports.open = exports.cleanup = exports.activate = exports.upload = exports.createAppDefinition = void 0;
|
|
4
4
|
var create_app_definition_1 = require("./create-app-definition");
|
|
5
5
|
Object.defineProperty(exports, "createAppDefinition", { enumerable: true, get: function () { return create_app_definition_1.createAppDefinition; } });
|
|
6
6
|
var upload_1 = require("./upload");
|
|
@@ -19,5 +19,5 @@ var install_1 = require("./install");
|
|
|
19
19
|
Object.defineProperty(exports, "install", { enumerable: true, get: function () { return install_1.install; } });
|
|
20
20
|
var build_functions_1 = require("./build-functions");
|
|
21
21
|
Object.defineProperty(exports, "buildFunctions", { enumerable: true, get: function () { return build_functions_1.buildFunctions; } });
|
|
22
|
-
var
|
|
23
|
-
Object.defineProperty(exports, "
|
|
22
|
+
var generate_function_1 = require("./generate-function");
|
|
23
|
+
Object.defineProperty(exports, "generateFunction", { enumerable: true, get: function () { return generate_function_1.generateFunction; } });
|
package/lib/types.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { Definition } from './definition-api';
|
|
2
2
|
import { Organization } from './organization-api';
|
|
3
|
+
export interface FunctionAppAction {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
category: 'Custom';
|
|
8
|
+
type: 'function';
|
|
9
|
+
path: string;
|
|
10
|
+
allowNetworks?: string[];
|
|
11
|
+
entryFile?: string;
|
|
12
|
+
}
|
|
3
13
|
export interface ContentfulFunction {
|
|
4
14
|
id: string;
|
|
5
15
|
name: string;
|
|
@@ -64,6 +74,7 @@ export interface UploadSettings {
|
|
|
64
74
|
skipActivation?: boolean;
|
|
65
75
|
userAgentApplication?: string;
|
|
66
76
|
host?: string;
|
|
77
|
+
actions?: FunctionAppAction[];
|
|
67
78
|
functions?: ContentfulFunction[];
|
|
68
79
|
}
|
|
69
80
|
export interface BuildFunctionsOptions {
|
|
@@ -71,3 +82,21 @@ export interface BuildFunctionsOptions {
|
|
|
71
82
|
esbuildConfig?: string;
|
|
72
83
|
watch?: boolean;
|
|
73
84
|
}
|
|
85
|
+
export type SourceType = 'template' | 'example';
|
|
86
|
+
export type Language = 'javascript' | 'typescript';
|
|
87
|
+
export type AcceptedFunctionExamples = 'appevent-handler';
|
|
88
|
+
export type SourceName = Language | AcceptedFunctionExamples;
|
|
89
|
+
export interface GenerateFunctionSettings {
|
|
90
|
+
name: string;
|
|
91
|
+
sourceType: SourceType;
|
|
92
|
+
sourceName: SourceName;
|
|
93
|
+
language: Language;
|
|
94
|
+
}
|
|
95
|
+
export type GenerateFunctionOptions = {
|
|
96
|
+
name: string;
|
|
97
|
+
} & ({
|
|
98
|
+
example: AcceptedFunctionExamples;
|
|
99
|
+
language: Language;
|
|
100
|
+
} | {
|
|
101
|
+
template: Language;
|
|
102
|
+
});
|
|
@@ -7,7 +7,8 @@ const get_app_info_1 = require("../get-app-info");
|
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
8
|
const constants_1 = require("../constants");
|
|
9
9
|
async function buildAppUploadSettings(options) {
|
|
10
|
-
const
|
|
10
|
+
const actionsManifest = (0, utils_1.getEntityFromManifest)('actions');
|
|
11
|
+
const functionManifest = (0, utils_1.getEntityFromManifest)('functions');
|
|
11
12
|
const prompts = [];
|
|
12
13
|
const { bundleDir, comment, skipActivation, host } = options;
|
|
13
14
|
if (!bundleDir) {
|
|
@@ -48,6 +49,7 @@ async function buildAppUploadSettings(options) {
|
|
|
48
49
|
skipActivation: skipActivation === undefined ? !activateBundle : skipActivation,
|
|
49
50
|
comment,
|
|
50
51
|
host: hostValue,
|
|
52
|
+
actions: actionsManifest,
|
|
51
53
|
functions: functionManifest,
|
|
52
54
|
...appUploadSettings,
|
|
53
55
|
...appInfo,
|
|
@@ -11,7 +11,7 @@ const utils_1 = require("../utils");
|
|
|
11
11
|
const contentful_management_1 = require("contentful-management");
|
|
12
12
|
const create_app_upload_1 = require("./create-app-upload");
|
|
13
13
|
async function createAppBundleFromUpload(settings, appUploadId) {
|
|
14
|
-
const { accessToken, host, userAgentApplication, comment, functions } = settings;
|
|
14
|
+
const { accessToken, host, userAgentApplication, comment, actions, functions } = settings;
|
|
15
15
|
const clientSpinner = (0, ora_1.default)('Verifying your upload...').start();
|
|
16
16
|
const client = (0, contentful_management_1.createClient)({
|
|
17
17
|
accessToken,
|
|
@@ -27,6 +27,7 @@ async function createAppBundleFromUpload(settings, appUploadId) {
|
|
|
27
27
|
appBundle = await appDefinition.createAppBundle({
|
|
28
28
|
appUploadId,
|
|
29
29
|
comment: comment && comment.length > 0 ? comment : undefined,
|
|
30
|
+
actions,
|
|
30
31
|
functions,
|
|
31
32
|
});
|
|
32
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function createZipFileFromDirectory(path: string): Promise<Buffer | null>;
|
|
1
|
+
export declare function createZipFileFromDirectory(path: string): Promise<Buffer<ArrayBufferLike> | null>;
|
|
@@ -17,7 +17,8 @@ const requiredOptions = {
|
|
|
17
17
|
};
|
|
18
18
|
async function getUploadSettingsArgs(options) {
|
|
19
19
|
const validateSpinner = (0, ora_1.default)('Validating your input...').start();
|
|
20
|
-
const
|
|
20
|
+
const actionsManifest = (0, utils_1.getEntityFromManifest)('actions');
|
|
21
|
+
const functionManifest = (0, utils_1.getEntityFromManifest)('functions');
|
|
21
22
|
const { bundleDir, comment, skipActivation, host, userAgentApplication } = options;
|
|
22
23
|
try {
|
|
23
24
|
(0, validate_arguments_1.validateArguments)(requiredOptions, options, 'upload');
|
|
@@ -29,6 +30,7 @@ async function getUploadSettingsArgs(options) {
|
|
|
29
30
|
comment,
|
|
30
31
|
host,
|
|
31
32
|
userAgentApplication,
|
|
33
|
+
actions: actionsManifest,
|
|
32
34
|
functions: functionManifest,
|
|
33
35
|
};
|
|
34
36
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { UploadSettings } from '../types';
|
|
2
|
-
export declare const validateBundle: (path: string, { functions }: Pick<UploadSettings, "functions">) => void;
|
|
2
|
+
export declare const validateBundle: (path: string, { functions, actions }: Pick<UploadSettings, "functions" | "actions">) => void;
|
|
@@ -13,11 +13,11 @@ const ABSOLUTE_PATH_REG_EXP = /(src|href)="\/([^/])([^"]*)+"/g;
|
|
|
13
13
|
const fileContainsAbsolutePath = (fileContent) => {
|
|
14
14
|
return [...fileContent.matchAll(ABSOLUTE_PATH_REG_EXP)].length > 0;
|
|
15
15
|
};
|
|
16
|
-
const validateBundle = (path, { functions }) => {
|
|
16
|
+
const validateBundle = (path, { functions, actions }) => {
|
|
17
17
|
const buildFolder = path_1.default.join('./', path);
|
|
18
18
|
const files = fs_1.default.readdirSync(buildFolder, { recursive: true, encoding: 'utf-8' });
|
|
19
19
|
const entry = getEntryFile(files);
|
|
20
|
-
if (!entry && !functions) {
|
|
20
|
+
if (!entry && !functions && !actions) {
|
|
21
21
|
throw new Error('Ensure your bundle includes a valid index.html file in its root folder, or a valid Contentful Function entrypoint (defined in your contentful-app-manifest.json file).');
|
|
22
22
|
}
|
|
23
23
|
if (entry) {
|
|
@@ -34,5 +34,11 @@ const validateBundle = (path, { functions }) => {
|
|
|
34
34
|
throw new Error(`Function "${functionWithoutEntryFile.id}" is missing its entry file at "${path_1.default.join(buildFolder, functionWithoutEntryFile.path)}".`);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
+
if (actions) {
|
|
38
|
+
const actionWithoutEntryFile = actions.find(({ path }) => !files.includes(path));
|
|
39
|
+
if (actionWithoutEntryFile) {
|
|
40
|
+
throw new Error(`Action "${actionWithoutEntryFile.id}" is missing its entry file at "${path_1.default.join(buildFolder, actionWithoutEntryFile.path)}".`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
37
43
|
};
|
|
38
44
|
exports.validateBundle = validateBundle;
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { Definition } from './definition-api';
|
|
2
2
|
import { Organization } from './organization-api';
|
|
3
|
-
import { ContentfulFunction } from './types';
|
|
3
|
+
import { ContentfulFunction, FunctionAppAction } from './types';
|
|
4
4
|
export declare const throwValidationException: (subject: string, message?: string, details?: string) => never;
|
|
5
5
|
export declare const isValidNetwork: (address: string) => boolean;
|
|
6
6
|
export declare const stripProtocol: (url: string) => string;
|
|
7
7
|
export declare const showCreationError: (subject: string, message: string) => void;
|
|
8
8
|
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
|
+
export declare function getEntityFromManifest<Type extends 'actions' | 'functions'>(type: Type): Entities<Type> | undefined;
|
|
11
12
|
export declare function getWebAppHostname(host: string | undefined): string;
|
|
12
|
-
export
|
|
13
|
-
manifestFile?: string;
|
|
14
|
-
}, cwd?: string) => any;
|
|
15
|
-
export declare const ID_REGEX: RegExp;
|
|
13
|
+
export {};
|
package/lib/utils.js
CHANGED
|
@@ -3,15 +3,14 @@ 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.
|
|
7
|
-
exports.
|
|
6
|
+
exports.selectFromList = exports.throwError = exports.showCreationError = exports.stripProtocol = exports.isValidNetwork = exports.throwValidationException = void 0;
|
|
7
|
+
exports.getEntityFromManifest = getEntityFromManifest;
|
|
8
8
|
exports.getWebAppHostname = getWebAppHostname;
|
|
9
9
|
const fs_1 = __importDefault(require("fs"));
|
|
10
10
|
const chalk_1 = __importDefault(require("chalk"));
|
|
11
11
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
12
12
|
const cache_credential_1 = require("./cache-credential");
|
|
13
13
|
const constants_1 = require("./constants");
|
|
14
|
-
const node_path_1 = require("node:path");
|
|
15
14
|
const DEFAULT_MANIFEST_PATH = './contentful-app-manifest.json';
|
|
16
15
|
const functionEvents = {
|
|
17
16
|
appActionCall: 'appaction.call',
|
|
@@ -106,18 +105,18 @@ const selectFromList = async (list, message, cachedOptionEnvVar) => {
|
|
|
106
105
|
}
|
|
107
106
|
};
|
|
108
107
|
exports.selectFromList = selectFromList;
|
|
109
|
-
function
|
|
108
|
+
function getEntityFromManifest(type) {
|
|
110
109
|
const isManifestExists = fs_1.default.existsSync(DEFAULT_MANIFEST_PATH);
|
|
111
110
|
if (!isManifestExists) {
|
|
112
111
|
return;
|
|
113
112
|
}
|
|
114
113
|
try {
|
|
115
114
|
const manifest = JSON.parse(fs_1.default.readFileSync(DEFAULT_MANIFEST_PATH, { encoding: 'utf8' }));
|
|
116
|
-
if (!Array.isArray(manifest[
|
|
115
|
+
if (!Array.isArray(manifest[type]) || manifest[type].length === 0) {
|
|
117
116
|
return;
|
|
118
117
|
}
|
|
119
|
-
logProgress(
|
|
120
|
-
const items = manifest[
|
|
118
|
+
logProgress(`${type === 'actions' ? 'App Actions' : 'functions'} found in ${chalk_1.default.bold(DEFAULT_MANIFEST_PATH)}.`);
|
|
119
|
+
const items = manifest[type].map((item) => {
|
|
121
120
|
const allowNetworks = Array.isArray(item.allowNetworks)
|
|
122
121
|
? item.allowNetworks.map(exports.stripProtocol)
|
|
123
122
|
: [];
|
|
@@ -125,12 +124,12 @@ function getFunctionsFromManifest() {
|
|
|
125
124
|
const hasInvalidEvent = accepts?.some((event) => !Object.values(functionEvents).includes(event));
|
|
126
125
|
const hasInvalidNetwork = allowNetworks.find((netWork) => !(0, exports.isValidNetwork)(netWork));
|
|
127
126
|
if (hasInvalidNetwork) {
|
|
128
|
-
console.log(`${chalk_1.default.red('Error:')} Invalid IP address ${hasInvalidNetwork} found in the allowNetworks array for
|
|
127
|
+
console.log(`${chalk_1.default.red('Error:')} Invalid IP address ${hasInvalidNetwork} found in the allowNetworks array for ${type} "${item.name}".`);
|
|
129
128
|
// eslint-disable-next-line no-process-exit
|
|
130
129
|
process.exit(1);
|
|
131
130
|
}
|
|
132
131
|
if (hasInvalidEvent) {
|
|
133
|
-
console.log(`${chalk_1.default.red('Error:')} Invalid events found in the accepts array for
|
|
132
|
+
console.log(`${chalk_1.default.red('Error:')} Invalid events found in the accepts array for ${type} "${item.name}".`);
|
|
134
133
|
// eslint-disable-next-line no-process-exit
|
|
135
134
|
process.exit(1);
|
|
136
135
|
}
|
|
@@ -154,10 +153,3 @@ function getFunctionsFromManifest() {
|
|
|
154
153
|
function getWebAppHostname(host) {
|
|
155
154
|
return host && host.includes('api') ? host.replace('api', 'app') : constants_1.DEFAULT_CONTENTFUL_APP_HOST;
|
|
156
155
|
}
|
|
157
|
-
const resolveManifestFile = (options, cwd = process.cwd()) => {
|
|
158
|
-
return require(options.manifestFile
|
|
159
|
-
? (0, node_path_1.resolve)(cwd, options.manifestFile)
|
|
160
|
-
: (0, node_path_1.resolve)(cwd, 'contentful-app-manifest.json'));
|
|
161
|
-
};
|
|
162
|
-
exports.resolveManifestFile = resolveManifestFile;
|
|
163
|
-
exports.ID_REGEX = /^[a-zA-Z0-9]+$/;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/app-scripts",
|
|
3
|
-
"version": "1.33.0
|
|
3
|
+
"version": "1.33.0",
|
|
4
4
|
"description": "A collection of scripts for building Contentful Apps",
|
|
5
5
|
"author": "Contentful GmbH",
|
|
6
6
|
"license": "MIT",
|
|
@@ -51,20 +51,23 @@
|
|
|
51
51
|
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
|
|
52
52
|
"@segment/analytics-node": "^2.0.0",
|
|
53
53
|
"adm-zip": "0.5.16",
|
|
54
|
+
"axios": "^1.7.9",
|
|
54
55
|
"bottleneck": "2.19.5",
|
|
55
56
|
"chalk": "4.1.2",
|
|
56
57
|
"commander": "12.1.0",
|
|
57
|
-
"contentful-management": "11.47.
|
|
58
|
+
"contentful-management": "11.47.2",
|
|
58
59
|
"dotenv": "16.4.7",
|
|
59
60
|
"esbuild": "^0.25.0",
|
|
60
61
|
"ignore": "7.0.3",
|
|
61
62
|
"inquirer": "8.2.6",
|
|
62
63
|
"lodash": "4.17.21",
|
|
64
|
+
"merge-options": "^3.0.4",
|
|
63
65
|
"open": "8.4.2",
|
|
64
66
|
"ora": "5.4.1",
|
|
67
|
+
"tiged": "^2.12.7",
|
|
65
68
|
"zod": "^3.24.1"
|
|
66
69
|
},
|
|
67
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "c34e17b5b5023762d190708c19281809eb14734b",
|
|
68
71
|
"devDependencies": {
|
|
69
72
|
"@types/adm-zip": "0.5.7",
|
|
70
73
|
"@types/analytics-node": "3.1.14",
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { AppActionProps, CreateAppActionProps, PlainClientAPI } from 'contentful-management';
|
|
2
|
-
export declare function createAction(client: PlainClientAPI, appDefinitionId: string, payload: CreateAppActionProps): Promise<AppActionProps>;
|
|
3
|
-
export declare function getExistingAction(client: PlainClientAPI, appDefinitionId: string, appActionId: string): Promise<AppActionProps | null>;
|
|
4
|
-
export declare function updateAction(client: PlainClientAPI, appDefinitionId: string, appActionId: string, payload: CreateAppActionProps): Promise<AppActionProps>;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createAction = createAction;
|
|
4
|
-
exports.getExistingAction = getExistingAction;
|
|
5
|
-
exports.updateAction = updateAction;
|
|
6
|
-
const chalk_1 = require("chalk");
|
|
7
|
-
async function createAction(client, appDefinitionId, payload) {
|
|
8
|
-
const action = await client.appAction.create({
|
|
9
|
-
appDefinitionId,
|
|
10
|
-
}, payload);
|
|
11
|
-
console.log(`
|
|
12
|
-
${(0, chalk_1.cyan)('Success!')} Created Action ${(0, chalk_1.cyan)(action.name)} with ID ${(0, chalk_1.cyan)(action.sys.id)} for App ${(0, chalk_1.cyan)(appDefinitionId)}.`);
|
|
13
|
-
return action;
|
|
14
|
-
}
|
|
15
|
-
async function getExistingAction(client, appDefinitionId, appActionId) {
|
|
16
|
-
try {
|
|
17
|
-
return await client.appAction.get({
|
|
18
|
-
appDefinitionId,
|
|
19
|
-
appActionId,
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
catch (err) {
|
|
23
|
-
if (err.name === 'NotFound') {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
throw err;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
async function updateAction(client, appDefinitionId, appActionId, payload) {
|
|
30
|
-
const action = await client.appAction.update({
|
|
31
|
-
appDefinitionId,
|
|
32
|
-
appActionId,
|
|
33
|
-
}, payload);
|
|
34
|
-
console.log(`
|
|
35
|
-
${(0, chalk_1.cyan)('Success!')} Updated Action ${(0, chalk_1.cyan)(action.name)} with ID ${(0, chalk_1.cyan)(appActionId)} for App ${(0, chalk_1.cyan)(appDefinitionId)}.`);
|
|
36
|
-
return action;
|
|
37
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
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.getCreateAppActionsArgs = getCreateAppActionsArgs;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const ora_1 = __importDefault(require("ora"));
|
|
9
|
-
const get_app_info_1 = require("../get-app-info");
|
|
10
|
-
const validate_arguments_1 = require("../validate-arguments");
|
|
11
|
-
const requiredOptions = {
|
|
12
|
-
organizationId: '--organization-id',
|
|
13
|
-
definitionId: '--definition-id',
|
|
14
|
-
token: '--token',
|
|
15
|
-
};
|
|
16
|
-
async function getCreateAppActionsArgs(settings) {
|
|
17
|
-
const validateSpinner = (0, ora_1.default)('Validating your input').start();
|
|
18
|
-
try {
|
|
19
|
-
(0, validate_arguments_1.validateArguments)(requiredOptions, settings, 'upsert-actions');
|
|
20
|
-
const appInfo = await (0, get_app_info_1.getAppInfo)(settings);
|
|
21
|
-
return {
|
|
22
|
-
host: settings.host || 'api.contentful.com',
|
|
23
|
-
manifestFile: settings.manifestFile,
|
|
24
|
-
accessToken: settings.token,
|
|
25
|
-
appDefinitionId: appInfo.definition.value,
|
|
26
|
-
organizationId: appInfo.organization.value,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
catch (err) {
|
|
30
|
-
console.log(`
|
|
31
|
-
${chalk_1.default.red('Validation failed')}
|
|
32
|
-
${err.message}
|
|
33
|
-
`);
|
|
34
|
-
// eslint-disable-next-line no-process-exit
|
|
35
|
-
process.exit(1);
|
|
36
|
-
}
|
|
37
|
-
finally {
|
|
38
|
-
validateSpinner.stop();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.upsertActions = void 0;
|
|
4
|
-
const upsert_actions_1 = require("./upsert-actions");
|
|
5
|
-
const get_cli_args_1 = require("./get-cli-args");
|
|
6
|
-
const prompt_interactive_args_1 = require("./prompt-interactive-args");
|
|
7
|
-
const interactive = async (options) => {
|
|
8
|
-
const settings = await (0, prompt_interactive_args_1.promptCreateAppAction)(options);
|
|
9
|
-
await (0, upsert_actions_1.upsertAppActions)(settings);
|
|
10
|
-
};
|
|
11
|
-
const nonInteractive = async (options) => {
|
|
12
|
-
const settings = await (0, get_cli_args_1.getCreateAppActionsArgs)(options);
|
|
13
|
-
await (0, upsert_actions_1.upsertAppActions)(settings);
|
|
14
|
-
};
|
|
15
|
-
exports.upsertActions = {
|
|
16
|
-
interactive,
|
|
17
|
-
nonInteractive,
|
|
18
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeAppActionCMAPayload = makeAppActionCMAPayload;
|
|
4
|
-
function makeAppActionCMAPayload(action) {
|
|
5
|
-
const baseProps = {
|
|
6
|
-
name: action.name,
|
|
7
|
-
...(action.description && { description: action.description }),
|
|
8
|
-
...(action.id && { id: action.id }),
|
|
9
|
-
};
|
|
10
|
-
const additionalPropsByType = action.type === 'function-invocation'
|
|
11
|
-
? {
|
|
12
|
-
type: action.type,
|
|
13
|
-
function: {
|
|
14
|
-
sys: {
|
|
15
|
-
id: action.functionId,
|
|
16
|
-
linkType: 'Function',
|
|
17
|
-
type: 'Link',
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
}
|
|
21
|
-
: {
|
|
22
|
-
type: action.type,
|
|
23
|
-
url: action.url,
|
|
24
|
-
};
|
|
25
|
-
const additionalPropsByCategory = action.category === 'Custom'
|
|
26
|
-
? {
|
|
27
|
-
category: action.category,
|
|
28
|
-
parameters: action.parameters,
|
|
29
|
-
}
|
|
30
|
-
: {
|
|
31
|
-
category: action.category,
|
|
32
|
-
};
|
|
33
|
-
const payload = {
|
|
34
|
-
...baseProps,
|
|
35
|
-
...additionalPropsByType,
|
|
36
|
-
...additionalPropsByCategory,
|
|
37
|
-
};
|
|
38
|
-
return payload;
|
|
39
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.promptCreateAppAction = promptCreateAppAction;
|
|
4
|
-
const inquirer_1 = require("inquirer");
|
|
5
|
-
const constants_1 = require("../constants");
|
|
6
|
-
const get_app_info_1 = require("../get-app-info");
|
|
7
|
-
async function promptCreateAppAction(options) {
|
|
8
|
-
const { manifestFile, host } = options;
|
|
9
|
-
const prompts = [];
|
|
10
|
-
if (manifestFile === undefined) {
|
|
11
|
-
prompts.push({
|
|
12
|
-
type: 'input',
|
|
13
|
-
name: 'manifestFile',
|
|
14
|
-
message: `Path to your Contentful app manifest file:`,
|
|
15
|
-
default: constants_1.DEFAULT_APP_MANIFEST_PATH,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
if (!host) {
|
|
19
|
-
prompts.push({
|
|
20
|
-
name: 'host',
|
|
21
|
-
message: `Contentful CMA endpoint URL:`,
|
|
22
|
-
default: 'api.contentful.com',
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
const { host: interactiveHost, manifestFile: interactiveManifest } = await (0, inquirer_1.prompt)(prompts);
|
|
26
|
-
const hostValue = host || interactiveHost;
|
|
27
|
-
const manifestFileValue = manifestFile || interactiveManifest;
|
|
28
|
-
const appInfo = await (0, get_app_info_1.getAppInfo)({ ...options, host: hostValue });
|
|
29
|
-
return {
|
|
30
|
-
host: hostValue,
|
|
31
|
-
manifestFile: manifestFileValue,
|
|
32
|
-
appDefinitionId: appInfo.definition.value,
|
|
33
|
-
accessToken: appInfo.accessToken,
|
|
34
|
-
organizationId: appInfo.organization.value,
|
|
35
|
-
};
|
|
36
|
-
}
|