Skip to content

Commit

Permalink
Update Kontent.ai Management SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriLojda committed Jul 1, 2024
1 parent 07a5340 commit f46fe43
Show file tree
Hide file tree
Showing 30 changed files with 1,303 additions and 12,752 deletions.
13,839 changes: 1,170 additions & 12,669 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
},
"dependencies": {
"@kontent-ai/delivery-sdk": "^14.9.0",
"@kontent-ai/management-sdk": "^3.4.0",
"@kontent-ai/management-sdk": "^6.4.0",
"zapier-platform-core": "15.8.0"
},
"devDependencies": {
"@types/jest": "^29.5.12",
"@types/node": "^18.19.39",
"@types/node-fetch": "^2.6.11",
"jest": "^29.7.0",
"nock": "^13.5.4",
"ts-jest": "^29.1.5",
Expand Down
2 changes: 1 addition & 1 deletion src/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const Authentication = {

const checkCmApi = (z: ZObject, bundle: KontentBundle<{}>) =>
createManagementClient(z, bundle)
.projectInformation()
.environmentInformation()
.toPromise()
.then(res => res.data.project);

Expand Down
6 changes: 5 additions & 1 deletion src/test/actions/changeContentItemWorkflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("changeContentItemWorkflow", () => {
});

const client = new ManagementClient({
projectId: bundle.authData.projectId,
environmentId: bundle.authData.projectId,
apiKey: bundle.authData.cmApiKey,
});

Expand Down Expand Up @@ -78,5 +78,9 @@ const rawVariant: LanguageVariantContracts.ILanguageVariantModelContract = {
language: { id: "984efe5c-6898-4d51-8afa-a66b9de51cc0" },
elements: [],
last_modified: createUTCDate(1316, 5, 14).toISOString(),
workflow: {
workflow_identifier: { codename: "default" },
step_identifier: { id: rawWfSteps[0]?.id },
},
workflow_step: { id: rawWfSteps[0]?.id },
};
24 changes: 12 additions & 12 deletions src/test/actions/createContentItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
ElementContracts,
LanguageContracts,
LanguageVariantContracts,
LanguageVariantElements,
languageVariantElementsBuilder,
LanguageVariantElementsBuilder,
ManagementClient,
Expand Down Expand Up @@ -58,7 +57,7 @@ describe("createContentItem", () => {
});

const client = new ManagementClient({
projectId: bundle.authData.projectId,
environmentId: bundle.authData.projectId,
apiKey: bundle.authData.cmApiKey,
});

Expand Down Expand Up @@ -90,24 +89,23 @@ describe("createContentItem", () => {
.upsertLanguageVariant()
.byItemId(itemId)
.byLanguageId(rawLanguage.id)
.withData(buildExpectedElements);
.withData(builder => ({
elements: buildExpectedElements(builder),
}));

nock(expectedCreateVariantRequest.getUrl())
.put(
"",
JSON.stringify({
elements: expectedCreateVariantRequest.data(
languageVariantElementsBuilder
),
})
)
.put("", JSON.stringify(expectedCreateVariantRequest.data(languageVariantElementsBuilder)))
.reply(201, {
item: { id: itemId },
language: { id: rawLanguage.id },
elements: resultElements,
last_modified: createUTCDate(1993, 1, 1).toISOString(),
workflow: {
workflow_identifier: { codename: "default" },
step_identifier: { id: "3ecd7341-ad09-44b1-b457-4257ba3fa73b" },
},
workflow_step: { id: "3ecd7341-ad09-44b1-b457-4257ba3fa73b" },
} as LanguageVariantContracts.IUpsertLanguageVariantResponseContract);
} satisfies LanguageVariantContracts.IUpsertLanguageVariantResponseContract);

const search = App.creates[createContentItem.key].operation.perform;

Expand Down Expand Up @@ -210,6 +208,7 @@ const resultElements: ElementContracts.IContentItemElementContract[] = [
id: "2e460e16-e006-4726-848b-9912c413d947",
},
value: "<p>rich value</p>",
components: [],
},
{
element: {
Expand Down Expand Up @@ -271,6 +270,7 @@ const buildExpectedElements = (builder: LanguageVariantElementsBuilder) => [
builder.richTextElement({
element: { id: "2e460e16-e006-4726-848b-9912c413d947" },
value: "<p>rich value</p>",
components: [],
}),
builder.taxonomyElement({
element: { id: "f870da17-761e-49fe-a546-e52be730b05e" },
Expand Down
6 changes: 5 additions & 1 deletion src/test/actions/deleteLanguageVariant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe("deleteLanguageVariant", () => {
});

const client = new ManagementClient({
projectId: bundle.authData.projectId,
environmentId: bundle.authData.projectId,
apiKey: bundle.authData.cmApiKey,
});

Expand Down Expand Up @@ -197,5 +197,9 @@ const rawVariant: LanguageVariantContracts.ILanguageVariantModelContract = {
language: { id: rawLanguage.id },
elements: [],
last_modified: createUTCDate(1316, 5, 14).toISOString(),
workflow: {
workflow_identifier: { codename: "default" },
step_identifier: { id: "6b7590d5-75e5-4860-8cc0-02c5bffce2dc" },
},
workflow_step: { id: "6b7590d5-75e5-4860-8cc0-02c5bffce2dc" },
};
24 changes: 14 additions & 10 deletions src/test/actions/updateLanguageVariant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("updateLanguageVariant", () => {
});

const client = new ManagementClient({
projectId: bundle.authData.projectId,
environmentId: bundle.authData.projectId,
apiKey: bundle.authData.cmApiKey,
});

Expand Down Expand Up @@ -72,15 +72,15 @@ describe("updateLanguageVariant", () => {
.upsertLanguageVariant()
.byItemId(rawItem.id)
.byLanguageId(rawLanguage.id)
.withData((builder) => [
builder.textElement({
element: { id: rawContentType.elements[0]?.id || "" },
value: newElementValue,
}),
]);
const expectedRawBody = JSON.stringify({
elements: expectedUpdateRequest.data(languageVariantElementsBuilder),
});
.withData((builder) => ({
elements: [
builder.textElement({
element: { id: rawContentType.elements[0]?.id || "" },
value: newElementValue,
}),
]
}));
const expectedRawBody = JSON.stringify(expectedUpdateRequest.data(languageVariantElementsBuilder));
nock(expectedUpdateRequest.getUrl())
.put("", expectedRawBody)
.reply(200, {
Expand Down Expand Up @@ -175,5 +175,9 @@ const rawVariant: LanguageVariantContracts.ILanguageVariantModelContract = {
},
],
last_modified: createUTCDate(1316, 5, 14).toISOString(),
workflow: {
workflow_identifier: { codename: "default" },
step_identifier: { id: rawWfSteps[0]?.id || "" },
},
workflow_step: { id: rawWfSteps[0]?.id || "" },
};
4 changes: 2 additions & 2 deletions src/test/authentication.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ describe("Zapier authentication", () => {
};

const expectedMapiRequest = new ManagementClient({
projectId: authData.projectId,
environmentId: authData.projectId,
apiKey: authData.cmApiKey,
}).projectInformation();
}).environmentInformation();

nock(expectedMapiRequest.getUrl())
.get("")
Expand Down
3 changes: 2 additions & 1 deletion src/test/searches/findAsset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe("findAsset", () => {
};

const client = new ManagementClient({
projectId: bundleById.authData.projectId,
environmentId: bundleById.authData.projectId,
apiKey: bundleById.authData.cmApiKey,
});

Expand All @@ -48,6 +48,7 @@ describe("findAsset", () => {

const expectedRawAsset: AssetContracts.IAssetModelContract = {
id: "d0442642-6e09-44a0-a5d3-1e842030cee6",
codename: "best_asset",
title: "test asset",
url: "https://bestAsset.test",
external_id: expectedAssetExternalId,
Expand Down
13 changes: 7 additions & 6 deletions src/test/searches/findContentItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe("findContentItem", () => {
});

const managementClient = new ManagementClient({
projectId: bundle.authData.projectId,
environmentId: bundle.authData.projectId,
apiKey: bundle.authData.cmApiKey,
});

Expand Down Expand Up @@ -289,10 +289,11 @@ const rawVariant: LanguageVariantContracts.IListLanguageVariantsOfItemResponseCo
item: rawContentItem,
language: rawLanguage,
last_modified: createUTCDate(1230, 12, 15).toISOString(),
workflow_step: {
id: "89205fc8-bf8e-4bc3-9eb2-725c9623ef40",
codename: "draft",
workflow: {
workflow_identifier: { codename: "default" },
step_identifier: { id: "89205fc8-bf8e-4bc3-9eb2-725c9623ef40" },
},
workflow_step: { id: "89205fc8-bf8e-4bc3-9eb2-725c9623ef40" },
elements: [
{
element: {
Expand All @@ -312,8 +313,8 @@ const rawDeliveryItem: Contracts.IContentItemContract = {
name: rawContentItem.name,
language: rawLanguage.codename,
collection: "default",
workflow_step: rawVariant.workflow_step.codename || "",
workflow: null,
workflow_step: rawVariant.workflow_step.id || "",
workflow: rawVariant.workflow.workflow_identifier.codename || "",
last_modified: rawVariant.last_modified,
sitemap_locations: [],
},
Expand Down
14 changes: 7 additions & 7 deletions src/test/searches/findContentItemWithSnippet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("findContentItem", () => {
});

const managementClient = new ManagementClient({
projectId: bundle.authData.projectId,
environmentId: bundle.authData.projectId,
apiKey: bundle.authData.cmApiKey,
});

Expand Down Expand Up @@ -311,15 +311,15 @@ const rawSnippets: ReadonlyArray<ContentTypeSnippetContracts.IContentTypeSnippet
}];


const rawVariant: LanguageVariantContracts.IListLanguageVariantsOfItemResponseContract =
{
const rawVariant: LanguageVariantContracts.IListLanguageVariantsOfItemResponseContract = {
item: rawContentItem,
language: rawLanguage,
last_modified: createUTCDate(1230, 12, 15).toISOString(),
workflow_step: {
id: "89205fc8-bf8e-4bc3-9eb2-725c9623ef40",
codename: "draft",
workflow: {
workflow_identifier: { codename: "default" },
step_identifier: { codename: "89205fc8-bf8e-4bc3-9eb2-725c9623ef40" },
},
workflow_step: { id: "89205fc8-bf8e-4bc3-9eb2-725c9623ef40" },
elements: [
{
element: {
Expand All @@ -346,7 +346,7 @@ const rawDeliveryItem: Contracts.IContentItemContract = {
name: rawContentItem.name,
language: rawLanguage.codename,
collection: "default",
workflow_step: rawVariant.workflow_step.codename || "",
workflow_step: rawVariant.workflow_step.id || "",
workflow: null,
last_modified: rawVariant.last_modified,
sitemap_locations: [],
Expand Down
2 changes: 1 addition & 1 deletion src/test/searches/findLanguage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe("findLanguage", () => {
> = addInputData(mockBundle, { searchPattern: "{0}={1}" });

const client = new ManagementClient({
projectId: bundle.authData.projectId,
environmentId: bundle.authData.projectId,
apiKey: bundle.authData.cmApiKey,
});

Expand Down
4 changes: 2 additions & 2 deletions src/test/searches/findWorkflowStep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("findWorkflowStep", () => {
});

const expectedRequest = new ManagementClient({
projectId: bundle.authData.projectId,
environmentId: bundle.authData.projectId,
apiKey: bundle.authData.cmApiKey,
}).listWorkflowSteps();

Expand Down Expand Up @@ -57,7 +57,7 @@ describe("findWorkflowStep", () => {
});

const expectedRequest = new ManagementClient({
projectId: bundle.authData.projectId,
environmentId: bundle.authData.projectId,
apiKey: bundle.authData.cmApiKey,
}).listWorkflowSteps();

Expand Down
2 changes: 1 addition & 1 deletion src/test/triggers/dropdowns/getContentItems.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe("getContentItems", () => {
});

const expectedLanguagesRequest = new ManagementClient({
projectId: bundle.authData.projectId,
environmentId: bundle.authData.projectId,
apiKey: bundle.authData.cmApiKey,
}).listLanguages();

Expand Down
2 changes: 1 addition & 1 deletion src/test/triggers/dropdowns/getLanguages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('getLanguages', () => {
const bundle = mockBundle;

const expectedRequest = new ManagementClient({
projectId: bundle.authData.projectId,
environmentId: bundle.authData.projectId,
apiKey: bundle.authData.cmApiKey,
}).listLanguages();

Expand Down
2 changes: 1 addition & 1 deletion src/test/triggers/dropdowns/getWorkflowSteps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('getWorkflowSteps', () => {
const bundle = mockBundle;

const expectedRequest = new ManagementClient({
projectId: bundle.authData.projectId,
environmentId: bundle.authData.projectId,
apiKey: bundle.authData.cmApiKey,
}).listWorkflowSteps();

Expand Down
14 changes: 13 additions & 1 deletion src/test/triggers/triggerItemExistenceChanged.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,25 @@ describe("triggerItemExistenceChanged", () => {
const result = await appTester(subscribe, bundle);

expect(result).toMatchInlineSnapshot(`
Webhook {
LegacyWebhook {
"healthStatus": undefined,
"id": "404c8821-d3ba-4794-8cee-853f3952ca99",
"lastModified": 1993-01-01T00:00:00.000Z,
"name": "Simple test name for webhook (Zapier)",
"secret": "sample_secret",
"triggers": {
"deliveryApiContentChanges": [],
"managementApiContentChanges": [
LegacyWebhookManagementApiContentChanges {
"operations": [
"create",
"archive",
"restore",
],
"type": "content_item_variant",
},
],
"previewDeliveryContentChanges": [],
"workflowStepChanges": [],
},
"url": "https://test-url.test",
Expand Down
7 changes: 5 additions & 2 deletions src/test/triggers/triggerItemPublishChanged.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,24 @@ describe("triggerItemPublishChanged", () => {
const result = await appTester(subscribe, bundle);

expect(result).toMatchInlineSnapshot(`
Webhook {
LegacyWebhook {
"healthStatus": undefined,
"id": "404c8821-d3ba-4794-8cee-853f3952ca99",
"lastModified": 1993-01-01T00:00:00.000Z,
"name": "Simple test name for webhook (Zapier)",
"secret": "sample_secret",
"triggers": {
"deliveryApiContentChanges": [
WebhookDeliveryApiContentChanges {
LegacyWebhookDeliveryApiContentChanges {
"operations": [
"publish",
"unpublish",
],
"type": "content_item_variant",
},
],
"managementApiContentChanges": [],
"previewDeliveryContentChanges": [],
"workflowStepChanges": [],
},
"url": "https://test-url.test",
Expand Down
Loading

0 comments on commit f46fe43

Please sign in to comment.