@contentful/app-scripts 1.33.0-alpha.0 → 1.33.1

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.
Files changed (52) hide show
  1. package/README.md +0 -40
  2. package/lib/bin.js +11 -13
  3. package/lib/build-functions/build-functions.d.ts +1 -0
  4. package/lib/build-functions/build-functions.js +10 -5
  5. package/lib/generate-function/build-generate-function-settings.d.ts +4 -0
  6. package/lib/generate-function/build-generate-function-settings.js +107 -0
  7. package/lib/generate-function/clone.d.ts +14 -0
  8. package/lib/generate-function/clone.js +140 -0
  9. package/lib/generate-function/constants.d.ts +9 -0
  10. package/lib/generate-function/constants.js +14 -0
  11. package/lib/generate-function/create-function.d.ts +2 -0
  12. package/lib/generate-function/create-function.js +10 -0
  13. package/lib/generate-function/get-github-folder-names.d.ts +1 -0
  14. package/lib/generate-function/get-github-folder-names.js +25 -0
  15. package/lib/generate-function/index.d.ts +5 -0
  16. package/lib/generate-function/index.js +38 -0
  17. package/lib/generate-function/logger.d.ts +8 -0
  18. package/lib/generate-function/logger.js +54 -0
  19. package/lib/generate-function/types.d.ts +7 -0
  20. package/lib/generate-function/types.js +16 -0
  21. package/lib/generate-function/utils/file.d.ts +15 -0
  22. package/lib/generate-function/utils/file.js +51 -0
  23. package/lib/generate-function/utils/package.d.ts +5 -0
  24. package/lib/generate-function/utils/package.js +23 -0
  25. package/lib/index.d.ts +1 -1
  26. package/lib/index.js +3 -3
  27. package/lib/types.d.ts +17 -0
  28. package/lib/upload/build-upload-settings.js +3 -1
  29. package/lib/upload/create-app-bundle.js +2 -1
  30. package/lib/upload/create-zip-from-directory.d.ts +1 -1
  31. package/lib/upload/get-upload-settings-args.js +3 -1
  32. package/lib/upload/validate-bundle.d.ts +1 -1
  33. package/lib/upload/validate-bundle.js +8 -2
  34. package/lib/utils.d.ts +4 -6
  35. package/lib/utils.js +8 -16
  36. package/package.json +6 -3
  37. package/lib/upsert-actions/client.d.ts +0 -4
  38. package/lib/upsert-actions/client.js +0 -37
  39. package/lib/upsert-actions/get-cli-args.d.ts +0 -2
  40. package/lib/upsert-actions/get-cli-args.js +0 -40
  41. package/lib/upsert-actions/index.d.ts +0 -5
  42. package/lib/upsert-actions/index.js +0 -18
  43. package/lib/upsert-actions/make-cma-payload.d.ts +0 -2
  44. package/lib/upsert-actions/make-cma-payload.js +0 -39
  45. package/lib/upsert-actions/prompt-interactive-args.d.ts +0 -2
  46. package/lib/upsert-actions/prompt-interactive-args.js +0 -36
  47. package/lib/upsert-actions/types.d.ts +0 -52
  48. package/lib/upsert-actions/types.js +0 -2
  49. package/lib/upsert-actions/upsert-actions.d.ts +0 -16
  50. package/lib/upsert-actions/upsert-actions.js +0 -80
  51. package/lib/upsert-actions/validation.d.ts +0 -9
  52. package/lib/upsert-actions/validation.js +0 -77
@@ -1,80 +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.doUpsert = doUpsert;
7
- exports.syncUpsertToManifest = syncUpsertToManifest;
8
- exports.processActionManifests = processActionManifests;
9
- exports.upsertAppActions = upsertAppActions;
10
- const chalk_1 = require("chalk");
11
- const contentful_management_1 = require("contentful-management");
12
- const node_fs_1 = __importDefault(require("node:fs"));
13
- const ora_1 = __importDefault(require("ora"));
14
- const utils_1 = require("../utils");
15
- const client_1 = require("./client");
16
- const make_cma_payload_1 = require("./make-cma-payload");
17
- const validation_1 = require("./validation");
18
- async function doUpsert(client, appDefinitionId, payload) {
19
- if (payload.id) {
20
- const existingAction = await (0, client_1.getExistingAction)(client, appDefinitionId, payload.id);
21
- if (existingAction) {
22
- const { id, ...update } = payload;
23
- return (0, client_1.updateAction)(client, appDefinitionId, id, update);
24
- }
25
- else if (!existingAction && payload.type === 'endpoint') {
26
- throw new Error(`Action with id ${payload.id} not found. Endpoint actions may not set a custom ID.`);
27
- }
28
- }
29
- return (0, client_1.createAction)(client, appDefinitionId, payload);
30
- }
31
- function syncUpsertToManifest(manifestActions, actionsToSync, manifest, manifestFile) {
32
- const actions = manifestActions.map((action, i) => {
33
- const syncedAction = actionsToSync[i];
34
- return syncedAction || action;
35
- });
36
- node_fs_1.default.writeFileSync(manifestFile, JSON.stringify({ ...manifest, actions }, null, 2));
37
- console.log(`Remote updates synced to your manifest file at ${(0, chalk_1.yellow)(manifestFile)}.`);
38
- }
39
- async function processActionManifests(actions, doUpsert) {
40
- const actionsToSync = {};
41
- const errors = [];
42
- for (const i in actions) {
43
- const action = actions[i];
44
- const payload = (0, make_cma_payload_1.makeAppActionCMAPayload)(action);
45
- try {
46
- const appAction = await doUpsert(payload);
47
- actionsToSync[i] = {
48
- ...action,
49
- id: appAction.sys.id,
50
- };
51
- }
52
- catch (err) {
53
- errors.push({ details: err, path: ['actions', i] });
54
- }
55
- }
56
- return { actionsToSync, errors };
57
- }
58
- async function upsertAppActions(settings) {
59
- const { accessToken, appDefinitionId, host, organizationId, manifestFile } = settings;
60
- const manifest = await (0, utils_1.resolveManifestFile)({ manifestFile });
61
- const actions = (0, validation_1.validateActionsManifest)(manifest);
62
- const spinner = (0, ora_1.default)('Creating your app action(s)').start();
63
- const client = (0, contentful_management_1.createClient)({
64
- accessToken,
65
- host,
66
- }, {
67
- type: 'plain',
68
- defaults: {
69
- organizationId,
70
- },
71
- });
72
- const { actionsToSync, errors } = await processActionManifests(actions, async (payload) => doUpsert(client, appDefinitionId, payload));
73
- syncUpsertToManifest(actions, actionsToSync, manifest, manifestFile);
74
- if (errors.length) {
75
- const error = new Error(`Failed to upsert actions`);
76
- Object.assign(error, { details: errors.map(({ details }) => details) });
77
- (0, utils_1.throwError)(error, 'Failed to upsert actions');
78
- }
79
- spinner.stop();
80
- }
@@ -1,9 +0,0 @@
1
- import { CreateAppActionOptions as UpsertAppActionOptions } from './types';
2
- export declare const validateId: (id: string) => {
3
- ok: boolean;
4
- message: string;
5
- } | {
6
- ok: boolean;
7
- message?: undefined;
8
- };
9
- export declare function validateActionsManifest(manifest: Record<string, any>): UpsertAppActionOptions['actions'];
@@ -1,77 +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.validateId = void 0;
7
- exports.validateActionsManifest = validateActionsManifest;
8
- const zod_1 = __importDefault(require("zod"));
9
- const utils_1 = require("../utils");
10
- const parametersSchema = zod_1.default
11
- .array(zod_1.default.object({
12
- id: zod_1.default.string(),
13
- name: zod_1.default.string(),
14
- description: zod_1.default.string().optional(),
15
- type: zod_1.default.enum(['Symbol', 'Enum', 'Number', 'Boolean']),
16
- required: zod_1.default.boolean(),
17
- default: zod_1.default.union([zod_1.default.string(), zod_1.default.number(), zod_1.default.boolean()]).optional(),
18
- }));
19
- const validateId = (id) => {
20
- if (!utils_1.ID_REGEX.test(id)) {
21
- return {
22
- ok: false,
23
- message: `Invalid "id" (must only contain alphanumeric characters). Received: ${id}.`,
24
- };
25
- }
26
- return { ok: true };
27
- };
28
- exports.validateId = validateId;
29
- function validateActionsManifest(manifest) {
30
- if (!manifest.actions) {
31
- throw new Error('Invalid App Action manifest: missing "actions" field');
32
- }
33
- const { actions } = manifest;
34
- if (!Array.isArray(actions)) {
35
- throw new Error('Invalid App Action manifest: "actions" must be an array');
36
- }
37
- const errors = actions.reduce((acc, action) => {
38
- if (!action.name) {
39
- acc.push(new Error('Invalid App Action manifest: Actions must define a "name".'));
40
- }
41
- if (!action.type) {
42
- acc.push(new Error('Invalid App Action manifest: Actions must define a "type".'));
43
- }
44
- if (!action.category) {
45
- acc.push(new Error('Invalid App Action manifest: Actions must define a "category".'));
46
- }
47
- if (action.type === 'function-invocation' && (!action.functionId || action.url)) {
48
- acc.push(new Error('Invalid App Action manifest: "function-invocation" Actions must define a "functionId" and may not target a "url".'));
49
- }
50
- if (action.type === 'endpoint' && (!action.url || action.functionId)) {
51
- acc.push(new Error('Invalid App Action manifest: "endpoint" Actions must define a "url" and may not target a "functionId".'));
52
- }
53
- if (action.id) {
54
- const { ok, message } = (0, exports.validateId)(action.id);
55
- if (!ok) {
56
- acc.push(new Error(`Invalid App Action manifest: ${message}`));
57
- }
58
- }
59
- if (action.category !== 'Custom' && action.parameters) {
60
- acc.push(new Error('Invalid App Action manifest: native Action categories may not define "parameters"'));
61
- }
62
- if (action.category === 'Custom' && !action.parameters) {
63
- acc.push(new Error('Invalid App Action manifest: "Custom" Action categories must define "parameters"'));
64
- }
65
- if (action.category === 'Custom' && action.parameters) {
66
- const parametersValidationResult = parametersSchema.safeParse(action.parameters);
67
- if (!parametersValidationResult.success) {
68
- acc.push(new Error(`Invalid App Action manifest: invalid "parameters" - ${JSON.stringify(parametersValidationResult.error.errors)}`));
69
- }
70
- }
71
- return acc;
72
- }, []);
73
- if (errors.length) {
74
- throw new Error(errors.map((error) => error.message).join('\n'));
75
- }
76
- return actions;
77
- }