Skip to content

Commit c4b65ab

Browse files
committed
feat!: remove hosted app action functionality from app-scripts
BREAKING CHANGE: removes the ability to create hosted app actions from app-scripts
1 parent a8a852b commit c4b65ab

File tree

10 files changed

+34
-224
lines changed

10 files changed

+34
-224
lines changed

packages/contentful--app-scripts/src/types.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
import { Definition } from './definition-api';
22
import { Organization } from './organization-api';
33

4-
export interface FunctionAppAction {
5-
id: string;
6-
name: string;
7-
description: string;
8-
category: 'Custom';
9-
type: 'function';
10-
path: string;
11-
allowNetworks?: string[];
12-
entryFile?: string;
13-
}
14-
154
export interface ContentfulFunction {
165
id: string;
176
name: string;
@@ -84,7 +73,6 @@ export interface UploadSettings {
8473
skipActivation?: boolean;
8574
userAgentApplication?: string;
8675
host?: string;
87-
actions?: FunctionAppAction[];
8876
functions?: ContentfulFunction[];
8977
}
9078

packages/contentful--app-scripts/src/upload/build-upload-settings.test.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import * as utilsModule from '../utils';
1010
describe('buildAppUploadSettings', () => {
1111
let promptStub;
1212
let getAppInfoStub;
13-
let getEntityFromManifestStub;
13+
let getFunctionsFromManifestStub;
1414

1515
beforeEach(() => {
1616
promptStub = sinon.stub(inquirer, 'prompt');
1717
getAppInfoStub = sinon.stub(getAppInfoModule, 'getAppInfo');
18-
getEntityFromManifestStub = sinon.stub(utilsModule, 'getEntityFromManifest');
18+
getFunctionsFromManifestStub = sinon.stub(utilsModule, 'getFunctionsFromManifest');
1919
});
2020

2121
afterEach(() => {
@@ -39,16 +39,14 @@ describe('buildAppUploadSettings', () => {
3939

4040
getAppInfoStub.resolves({ appId: '123', appName: 'Test App' });
4141

42-
getEntityFromManifestStub.withArgs('actions').returns('actionsManifest');
43-
getEntityFromManifestStub.withArgs('functions').returns('functionsManifest');
42+
getFunctionsFromManifestStub.returns('functionsManifest');
4443

4544
const result = await buildAppUploadSettings(options);
4645

4746
assert.strictEqual(result.host, 'api.contentful.com', 'Protocol should be stripped from host');
4847
assert.strictEqual(result.bundleDirectory, './custom-build');
4948
assert.strictEqual(result.comment, 'Test comment');
5049
assert.strictEqual(result.skipActivation, false); // activateBundle is true, so skipActivation should be false
51-
assert.strictEqual(result.actions, 'actionsManifest');
5250
assert.strictEqual(result.functions, 'functionsManifest');
5351
});
5452
}
@@ -64,8 +62,7 @@ describe('buildAppUploadSettings', () => {
6462

6563
promptStub.resolves(prompts);
6664
getAppInfoStub.resolves({ appId: '123', appName: 'Test App' });
67-
getEntityFromManifestStub.withArgs('actions').returns('actionsManifest');
68-
getEntityFromManifestStub.withArgs('functions').returns('functionsManifest');
65+
getFunctionsFromManifestStub.returns('functionsManifest');
6966

7067
const result = await buildAppUploadSettings(options);
7168

@@ -82,8 +79,7 @@ describe('buildAppUploadSettings', () => {
8279

8380
promptStub.resolves({});
8481
getAppInfoStub.resolves({ appId: '123', appName: 'Test App' });
85-
getEntityFromManifestStub.withArgs('actions').returns('actionsManifest');
86-
getEntityFromManifestStub.withArgs('functions').returns('functionsManifest');
82+
getFunctionsFromManifestStub.returns('functionsManifest');
8783

8884
const result = await buildAppUploadSettings(options);
8985

@@ -99,8 +95,7 @@ describe('buildAppUploadSettings', () => {
9995

10096
promptStub.resolves(prompts);
10197
getAppInfoStub.resolves({ appId: '123', appName: 'Test App' });
102-
getEntityFromManifestStub.withArgs('actions').returns('actionsManifest');
103-
getEntityFromManifestStub.withArgs('functions').returns('functionsManifest');
98+
getFunctionsFromManifestStub.returns('functionsManifest');
10499

105100
const result = await buildAppUploadSettings(options);
106101

packages/contentful--app-scripts/src/upload/build-upload-settings.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { prompt } from 'inquirer';
22
import { getAppInfo } from '../get-app-info';
3-
import { getEntityFromManifest } from '../utils';
3+
import { getFunctionsFromManifest } from '../utils';
44
import { DEFAULT_CONTENTFUL_API_HOST } from '../constants';
55
import { UploadOptions, UploadSettings } from '../types';
66

77
export async function buildAppUploadSettings(options: UploadOptions): Promise<UploadSettings> {
8-
const actionsManifest = getEntityFromManifest('actions');
9-
const functionManifest = getEntityFromManifest('functions');
8+
const functionManifest = getFunctionsFromManifest();
109
const prompts = [];
1110
const { bundleDir, comment, skipActivation, host } = options;
1211

@@ -50,7 +49,6 @@ export async function buildAppUploadSettings(options: UploadOptions): Promise<Up
5049
skipActivation: skipActivation === undefined ? !activateBundle : skipActivation,
5150
comment,
5251
host: hostValue,
53-
actions: actionsManifest,
5452
functions: functionManifest,
5553
...appUploadSettings,
5654
...appInfo,

packages/contentful--app-scripts/src/upload/create-app-bundle.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { createAppUpload } from './create-app-upload';
77
import { UploadSettings } from '../types';
88

99
export async function createAppBundleFromUpload(settings: UploadSettings, appUploadId: string) {
10-
const { accessToken, host, userAgentApplication, comment, actions, functions } = settings;
10+
const { accessToken, host, userAgentApplication, comment, functions } = settings;
1111
const clientSpinner = ora('Verifying your upload...').start();
1212
const client = createClient({
1313
accessToken,
@@ -24,7 +24,6 @@ export async function createAppBundleFromUpload(settings: UploadSettings, appUpl
2424
appBundle = await appDefinition.createAppBundle({
2525
appUploadId,
2626
comment: comment && comment.length > 0 ? comment : undefined,
27-
actions,
2827
functions,
2928
});
3029
} catch (err: any) {

packages/contentful--app-scripts/src/upload/get-upload-settings-args.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import chalk from 'chalk';
22
import ora from 'ora';
33
import { getAppInfo } from '../get-app-info';
44
import { validateArguments } from '../validate-arguments';
5-
import { getEntityFromManifest } from '../utils';
5+
import { getFunctionsFromManifest } from '../utils';
66
import { UploadOptions, UploadSettings } from '../types';
77

88
const requiredOptions = {
@@ -14,8 +14,7 @@ const requiredOptions = {
1414

1515
export async function getUploadSettingsArgs(options: UploadOptions): Promise<UploadSettings> {
1616
const validateSpinner = ora('Validating your input...').start();
17-
const actionsManifest = getEntityFromManifest('actions');
18-
const functionManifest = getEntityFromManifest('functions');
17+
const functionManifest = getFunctionsFromManifest();
1918
const { bundleDir, comment, skipActivation, host, userAgentApplication } = options;
2019

2120
try {
@@ -28,7 +27,6 @@ export async function getUploadSettingsArgs(options: UploadOptions): Promise<Upl
2827
comment,
2928
host,
3029
userAgentApplication,
31-
actions: actionsManifest,
3230
functions: functionManifest,
3331
};
3432
} catch (err: any) {

packages/contentful--app-scripts/src/upload/validate-bundle.test.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('validateBundle', () => {
2626
it('does not throw when there is no index.html but a function is defined', () => {
2727
const mockedSettings = {
2828
functions: [{ id: 'myFunc', path: 'functions/myFunc.js' }],
29-
} as Pick<UploadSettings, 'functions' | 'actions'>;
29+
} as Pick<UploadSettings, 'functions'>;
3030
const fsstub = {
3131
readdirSync: () => ['functions', 'functions/myFunc.js'],
3232
};
@@ -60,7 +60,7 @@ describe('validateBundle', () => {
6060
{ id: 'myFunc', path: 'functions/myFunc.js' },
6161
{ id: 'myOtherFunc', path: 'functions/myOtherFunc.js' },
6262
],
63-
} as Pick<UploadSettings, 'functions' | 'actions'>;
63+
} as Pick<UploadSettings, 'functions'>;
6464
const fsstub = {
6565
readdirSync: () => ['index.html', 'functions', 'functions/myFunc.js'],
6666
readFileSync: () => '<html><script src="./relative/path"></script></html>',
@@ -75,26 +75,4 @@ describe('validateBundle', () => {
7575
);
7676
}
7777
});
78-
79-
it('throws when there is no entry point for a function defined in the contentful-app-manifest.json', () => {
80-
const mockedSettings = {
81-
actions: [
82-
{ id: 'myAction', path: 'actions/myAction.js' },
83-
{ id: 'myOtherAction', path: 'actions/myOtherAction.js' },
84-
],
85-
} as Pick<UploadSettings, 'functions' | 'actions'>;
86-
const fsstub = {
87-
readdirSync: () => ['index.html', 'actions', 'actions/myAction.js'],
88-
readFileSync: () => '<html><script src="./relative/path"></script></html>',
89-
};
90-
const { validateBundle } = proxyquire('./validate-bundle', { fs: fsstub });
91-
try {
92-
validateBundle('build', mockedSettings);
93-
} catch (e: any) {
94-
assert.strictEqual(
95-
e.message,
96-
'Action "myOtherAction" is missing its entry file at "build/actions/myOtherAction.js".'
97-
);
98-
}
99-
});
10078
});

packages/contentful--app-scripts/src/upload/validate-bundle.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ const fileContainsAbsolutePath = (fileContent: string) => {
1414

1515
export const validateBundle = (
1616
path: string,
17-
{ functions, actions }: Pick<UploadSettings, 'functions' | 'actions'>
17+
{ functions }: Pick<UploadSettings, 'functions'>
1818
) => {
1919
const buildFolder = Path.join('./', path);
2020
const files = fs.readdirSync(buildFolder, { recursive: true, encoding: 'utf-8' });
2121
const entry = getEntryFile(files);
2222

23-
if (!entry && !functions && !actions) {
23+
if (!entry && !functions) {
2424
throw new Error(
2525
'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).'
2626
);
@@ -51,16 +51,4 @@ export const validateBundle = (
5151
);
5252
}
5353
}
54-
55-
if (actions) {
56-
const actionWithoutEntryFile = actions.find(({ path }) => !files.includes(path));
57-
if (actionWithoutEntryFile) {
58-
throw new Error(
59-
`Action "${actionWithoutEntryFile.id}" is missing its entry file at "${Path.join(
60-
buildFolder,
61-
actionWithoutEntryFile.path
62-
)}".`
63-
);
64-
}
65-
}
6654
};

packages/contentful--app-scripts/src/upsert-actions/validation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import z from 'zod';
2-
import { CreateAppActionOptions } from './types';
2+
import { CreateAppActionOptions as UpsertAppActionOptions } from './types';
33
import { ID_REGEX } from '../utils';
44

55
const parametersSchema = z
@@ -26,7 +26,7 @@ export const validateId = (id: string) => {
2626

2727
export function validateActionsManifest(
2828
manifest: Record<string, any>,
29-
): CreateAppActionOptions['actions'] {
29+
): UpsertAppActionOptions['actions'] {
3030
if (!manifest.actions) {
3131
throw new Error('Invalid App Action manifest: missing "actions" field');
3232
}

0 commit comments

Comments
 (0)