Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ env:
MAILCHIMP_DATACENTER: ${{ fromJson(secrets.TEST_VARIABLES).MAILCHIMP_DATACENTER }}
INTERCOM_TOKEN: ${{ fromJson(secrets.TEST_VARIABLES).INTERCOM_TOKEN }}
ATTIO_TOKEN: ${{ fromJson(secrets.TEST_VARIABLES).ATTIO_TOKEN }}
CONTENTFUL_ACCESS_TOKEN: ${{ fromJson(secrets.TEST_VARIABLES).CONTENTFUL_ACCESS_TOKEN }}
CONTENTFUL_SPACE_ID: ${{ fromJson(secrets.TEST_VARIABLES).CONTENTFUL_SPACE_ID }}
GOOGLE_SHEETS_REFRESH_TOKEN: ${{ fromJson(secrets.TEST_VARIABLES).GOOGLE_SHEETS_REFRESH_TOKEN }}
GOOGLE_SHEETS_CLIENT_ID: ${{ fromJson(secrets.TEST_VARIABLES).GOOGLE_SHEETS_CLIENT_ID }}
GOOGLE_SHEETS_CLIENT_SECRET: ${{ fromJson(secrets.TEST_VARIABLES).GOOGLE_SHEETS_CLIENT_SECRET }}
Expand Down Expand Up @@ -355,6 +357,7 @@ jobs:
uuid-dev \
libeigen3-dev \
libprotobuf-dev \
libprotoc-dev \
protobuf-compiler

# Install OpenSSL 3.5+ with native QUIC support (SSL_set_quic_tls_cbs)
Expand Down
1 change: 1 addition & 0 deletions ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"axios": "^1.12.0",
"azure-devops-node-api": "^15.1.1",
"brace-expansion": "^4.0.1",
"contentful-management": "^11.74.0",
"dayjs": "^1.11.18",
"dotenv": "^17.2.2",
"facebook-nodejs-business-sdk": "^24.0.0",
Expand Down
2 changes: 2 additions & 0 deletions ts/src/ActionsCatalogue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import canva from '../apps/canva';
import claude from '../apps/claude';
import clickup from '../apps/clickup';
import confluence from '../apps/confluence';
import contentful from '../apps/contentful';
import coppercrm from '../apps/coppercrm';
import craft from '../apps/craft';
import dropbox from '../apps/dropbox';
Expand Down Expand Up @@ -153,6 +154,7 @@ const NEW_APPS = {
claude,
clickup,
confluence,
contentful,
coppercrm,
craft,
dropbox,
Expand Down
63 changes: 63 additions & 0 deletions ts/src/apps/contentful/actions/assets/archive-asset.action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { EQoreAppActionCode, QoreAppCreator, TQoreOptions } from '@qoretechnologies/ts-toolkit';
import { getQoreContextRequiredValues } from '../../../../global/helpers';
import { getContentfulScopedClient } from '../../client';
import { CONTENTFUL_APP_NAME, ContentfulError } from '../../constants';
import { contentfulBaseOptions } from '../../helpers/shared-options';
import { getContentfulAssetAllowedValues } from '../../helpers/get-asset-allowed-values';

const action = 'archive_asset';

const options = {
...contentfulBaseOptions,
asset_id: {
type: 'string',
required: true,
get_allowed_values: getContentfulAssetAllowedValues,
},
archive: {
type: 'bool',
required: true,
default_value: true,
},
} satisfies TQoreOptions;

const ArchiveAsset = QoreAppCreator.createLocalizedAction<typeof options>({
app: CONTENTFUL_APP_NAME,
action,
action_code: EQoreAppActionCode.ACTION,
options,
response_type: {
type: 'hash',
fields: {
id: { type: 'string', short_desc: 'Asset ID' },
archived: { type: 'bool', short_desc: 'Whether the asset is archived' },
},
},
api_function: async (obj, _opts, context) => {
const { space_id, asset_id } = getQoreContextRequiredValues({
context: { ...context, opts: obj },
optionFields: ['space_id', 'asset_id'],
ErrorClass: ContentfulError,
});

const environmentId = obj?.environment_id || 'master';
const shouldArchive = obj?.archive !== false;

try {
const client = getContentfulScopedClient(context, space_id, environmentId);

if (shouldArchive) {
await client.asset.archive({ assetId: asset_id });
} else {
await client.asset.unarchive({ assetId: asset_id });
}

return { id: asset_id, archived: shouldArchive };
} catch (error) {
const operation = shouldArchive ? 'archive' : 'unarchive';
throw new ContentfulError(`Failed to ${operation} asset: ${error}`);
}
},
});

export default ArchiveAsset;
120 changes: 120 additions & 0 deletions ts/src/apps/contentful/actions/assets/create-asset.action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { EQoreAppActionCode, QoreAppCreator, TQoreOptions } from '@qoretechnologies/ts-toolkit';
import { getQoreContextRequiredValues } from '../../../../global/helpers';
import { getContentfulScopedClient } from '../../client';
import { CONTENTFUL_APP_NAME, ContentfulError } from '../../constants';
import { contentfulBaseOptions } from '../../helpers/shared-options';
import { flattenAsset, getDefaultLocale } from '../../helpers/contentful-type-mapping';
import { ContentfulAssetResponseType } from '../../response-types';

const action = 'create_asset';

const options = {
...contentfulBaseOptions,
title: {
type: 'string',
required: true,
},
description: {
type: 'string',
required: false,
},
file_name: {
type: 'string',
required: true,
},
file_url: {
type: 'string',
required: true,
},
content_type: {
type: 'string',
required: true,
allowed_values: [
{ value: 'image/jpeg', display_name: 'JPEG Image' },
{ value: 'image/png', display_name: 'PNG Image' },
{ value: 'image/gif', display_name: 'GIF Image' },
{ value: 'image/svg+xml', display_name: 'SVG Image' },
{ value: 'image/webp', display_name: 'WebP Image' },
{ value: 'application/pdf', display_name: 'PDF Document' },
{ value: 'video/mp4', display_name: 'MP4 Video' },
{ value: 'audio/mpeg', display_name: 'MP3 Audio' },
{ value: 'application/json', display_name: 'JSON' },
{ value: 'text/plain', display_name: 'Plain Text' },
{ value: 'text/html', display_name: 'HTML' },
{ value: 'text/csv', display_name: 'CSV' },
],
allowed_values_creatable: true,
},
publish: {
type: 'bool',
required: false,
default_value: false,
},
} satisfies TQoreOptions;

const CreateAsset = QoreAppCreator.createLocalizedAction<typeof options>({
app: CONTENTFUL_APP_NAME,
action,
action_code: EQoreAppActionCode.ACTION,
options,
response_type: ContentfulAssetResponseType,
api_function: async (obj, _opts, context) => {
const { space_id, title, file_name, file_url, content_type } = getQoreContextRequiredValues({
context: { ...context, opts: obj },
optionFields: ['space_id', 'title', 'file_name', 'file_url', 'content_type'],
ErrorClass: ContentfulError,
});

const environmentId = obj?.environment_id || 'master';
const description = obj?.description as string | undefined;
const shouldPublish = obj?.publish === true;

try {
const client = getContentfulScopedClient(context, space_id, environmentId);
const defaultLocale = await getDefaultLocale(client, space_id);

let asset = await client.asset.create(
{},
{
fields: {
title: { [defaultLocale]: title },
description: description ? { [defaultLocale]: description } : undefined,
file: {
[defaultLocale]: {
contentType: content_type,
fileName: file_name,
upload: file_url,
},
},
} as any,
}
);

// Trigger asset processing and poll until complete
try {
await client.asset.processForLocale(
{} as any, asset, defaultLocale,
{ processingCheckWait: 3000, processingCheckRetries: 10 }
);
} catch {
// Processing may time out but still succeed — check below
}

// Fetch the asset to check if processing completed
asset = await client.asset.get({ assetId: asset.sys.id });

if (shouldPublish) {
asset = await client.asset.publish(
{ assetId: asset.sys.id },
{ sys: { version: asset.sys.version } } as any
) as any;
}

return flattenAsset(asset, defaultLocale);
} catch (error) {
throw new ContentfulError(`Failed to create asset: ${error}`);
}
},
});

export default CreateAsset;
62 changes: 62 additions & 0 deletions ts/src/apps/contentful/actions/assets/delete-asset.action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { EQoreAppActionCode, QoreAppCreator, TQoreOptions } from '@qoretechnologies/ts-toolkit';
import { getQoreContextRequiredValues } from '../../../../global/helpers';
import { getContentfulScopedClient } from '../../client';
import { CONTENTFUL_APP_NAME, ContentfulError } from '../../constants';
import { contentfulBaseOptions } from '../../helpers/shared-options';
import { getContentfulAssetAllowedValues } from '../../helpers/get-asset-allowed-values';

const action = 'delete_asset';

const options = {
...contentfulBaseOptions,
asset_id: {
type: 'string',
required: true,
get_allowed_values: getContentfulAssetAllowedValues,
},
} satisfies TQoreOptions;

const DeleteAsset = QoreAppCreator.createLocalizedAction<typeof options>({
app: CONTENTFUL_APP_NAME,
action,
action_code: EQoreAppActionCode.ACTION,
options,
response_type: {
type: 'hash',
fields: {
id: { type: 'string', short_desc: 'Deleted asset ID' },
deleted: { type: 'bool', short_desc: 'Whether the asset was successfully deleted' },
},
},
api_function: async (obj, _opts, context) => {
const { space_id, asset_id } = getQoreContextRequiredValues({
context: { ...context, opts: obj },
optionFields: ['space_id', 'asset_id'],
ErrorClass: ContentfulError,
});

const environmentId = obj?.environment_id || 'master';

try {
const client = getContentfulScopedClient(context, space_id, environmentId);

// Unpublish if published before deleting
try {
const asset = await client.asset.get({ assetId: asset_id });
if ((asset.sys as any).publishedVersion) {
await client.asset.unpublish({ assetId: asset_id });
}
} catch {
// Asset may already be unpublished
}

await client.asset.delete({ assetId: asset_id });

return { id: asset_id, deleted: true };
} catch (error) {
throw new ContentfulError(`Failed to delete asset: ${error}`);
}
},
});

export default DeleteAsset;
48 changes: 48 additions & 0 deletions ts/src/apps/contentful/actions/assets/get-asset.action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { EQoreAppActionCode, QoreAppCreator, TQoreOptions } from '@qoretechnologies/ts-toolkit';
import { getQoreContextRequiredValues } from '../../../../global/helpers';
import { getContentfulScopedClient } from '../../client';
import { CONTENTFUL_APP_NAME, ContentfulError } from '../../constants';
import { contentfulBaseOptions } from '../../helpers/shared-options';
import { getContentfulAssetAllowedValues } from '../../helpers/get-asset-allowed-values';
import { flattenAsset, getDefaultLocale } from '../../helpers/contentful-type-mapping';
import { ContentfulAssetResponseType } from '../../response-types';

const action = 'get_asset';

const options = {
...contentfulBaseOptions,
asset_id: {
type: 'string',
required: true,
get_allowed_values: getContentfulAssetAllowedValues,
},
} satisfies TQoreOptions;

const GetAsset = QoreAppCreator.createLocalizedAction<typeof options>({
app: CONTENTFUL_APP_NAME,
action,
action_code: EQoreAppActionCode.ACTION,
options,
response_type: ContentfulAssetResponseType,
api_function: async (obj, _opts, context) => {
const { space_id, asset_id } = getQoreContextRequiredValues({
context: { ...context, opts: obj },
optionFields: ['space_id', 'asset_id'],
ErrorClass: ContentfulError,
});

const environmentId = obj?.environment_id || 'master';

try {
const client = getContentfulScopedClient(context, space_id, environmentId);
const defaultLocale = await getDefaultLocale(client, space_id);
const asset = await client.asset.get({ assetId: asset_id });

return flattenAsset(asset, defaultLocale);
} catch (error) {
throw new ContentfulError(`Failed to get asset: ${error}`);
}
},
});

export default GetAsset;
55 changes: 55 additions & 0 deletions ts/src/apps/contentful/actions/assets/publish-asset.action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { EQoreAppActionCode, QoreAppCreator, TQoreOptions } from '@qoretechnologies/ts-toolkit';
import { getQoreContextRequiredValues } from '../../../../global/helpers';
import { getContentfulScopedClient } from '../../client';
import { CONTENTFUL_APP_NAME, ContentfulError } from '../../constants';
import { contentfulBaseOptions } from '../../helpers/shared-options';
import { getContentfulAssetAllowedValues } from '../../helpers/get-asset-allowed-values';
import { ContentfulPublishResponseType } from '../../response-types';

const action = 'publish_asset';

const options = {
...contentfulBaseOptions,
asset_id: {
type: 'string',
required: true,
get_allowed_values: getContentfulAssetAllowedValues,
},
} satisfies TQoreOptions;

const PublishAsset = QoreAppCreator.createLocalizedAction<typeof options>({
app: CONTENTFUL_APP_NAME,
action,
action_code: EQoreAppActionCode.ACTION,
options,
response_type: ContentfulPublishResponseType,
api_function: async (obj, _opts, context) => {
const { space_id, asset_id } = getQoreContextRequiredValues({
context: { ...context, opts: obj },
optionFields: ['space_id', 'asset_id'],
ErrorClass: ContentfulError,
});

const environmentId = obj?.environment_id || 'master';

try {
const client = getContentfulScopedClient(context, space_id, environmentId);
const asset = await client.asset.get({ assetId: asset_id });

const published = await client.asset.publish(
{ assetId: asset_id },
{ sys: { version: asset.sys.version } } as any
);

return {
id: published.sys.id,
version: published.sys.version,
published_at: (published.sys as any).publishedAt,
};
} catch (error) {
throw new ContentfulError(`Failed to publish asset: ${error}`);
}
},
});

export default PublishAsset;
Loading
Loading