@kontent-ai/custom-app-sdk 2.1.0 → 2.1.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.
package/README.md CHANGED
@@ -18,6 +18,8 @@ It facilitates the communication between the Kontent.ai app and the custom app p
18
18
  ### Installation
19
19
 
20
20
  ```sh
21
+ pnpm add @kontent-ai/custom-app-sdk
22
+ # or
21
23
  npm install @kontent-ai/custom-app-sdk
22
24
  ```
23
25
 
@@ -1,19 +1,24 @@
1
1
  import type { CustomAppContextProperties } from "./iframeSchema";
2
+ type MakeOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
2
3
  declare const itemEditorContextProperties: readonly ["path", "pageTitle", "environmentId", "userId", "userEmail", "userRoles", "appConfig", "contentItemId", "languageId", "validationErrors", "currentPage"];
4
+ declare const optionalProperties: readonly ["appConfig"];
3
5
  type RawItemEditorContext = Pick<CustomAppContextProperties, (typeof itemEditorContextProperties)[number]>;
4
- export type ItemEditorContext = Required<WithSpecificPage<CustomAppContextProperties, "itemEditor">>;
6
+ export type ItemEditorContext = MakeOptional<Required<RawItemEditorContext>, (typeof optionalProperties)[number]> & {
7
+ readonly currentPage: "itemEditor";
8
+ };
5
9
  export declare const isItemEditorContext: (context: RawItemEditorContext) => context is ItemEditorContext;
6
10
  declare const itemListingContextProperties: readonly ["path", "pageTitle", "environmentId", "userId", "userEmail", "userRoles", "appConfig", "languageId", "itemListingFilter", "itemListingSelection", "currentPage"];
7
11
  type RawItemListingContext = Pick<CustomAppContextProperties, (typeof itemListingContextProperties)[number]>;
8
- export type ItemListingContext = Required<WithSpecificPage<CustomAppContextProperties, "contentInventory">>;
12
+ export type ItemListingContext = MakeOptional<Required<RawItemListingContext>, (typeof optionalProperties)[number]> & {
13
+ readonly currentPage: "contentInventory";
14
+ };
9
15
  export declare const isItemListingContext: (context: RawItemListingContext) => context is ItemListingContext;
10
16
  declare const otherContextProperties: readonly ["path", "pageTitle", "environmentId", "userId", "userEmail", "userRoles", "appConfig", "currentPage"];
11
17
  type RawOtherContext = Pick<CustomAppContextProperties, (typeof otherContextProperties)[number]>;
12
- export type OtherContext = Required<WithSpecificPage<CustomAppContextProperties, "other">>;
18
+ export type OtherContext = MakeOptional<Required<RawOtherContext>, (typeof optionalProperties)[number]> & {
19
+ readonly currentPage: "other";
20
+ };
13
21
  export declare const isOtherContext: (context: RawOtherContext) => context is OtherContext;
14
22
  export type Context = ItemEditorContext | ItemListingContext | OtherContext;
15
- type WithSpecificPage<T extends CustomAppContextProperties, Page extends Context["currentPage"]> = T & {
16
- readonly currentPage: Page;
17
- };
18
23
  export declare const getContextPropertiesForPage: (currentPage: Context["currentPage"] | undefined) => ReadonlyArray<keyof CustomAppContextProperties>;
19
24
  export {};
package/dist/contexts.js CHANGED
@@ -14,13 +14,12 @@ const itemEditorContextProperties = [
14
14
  "validationErrors",
15
15
  "currentPage",
16
16
  ];
17
- const optionalProperties = [
18
- "appConfig",
19
- ];
17
+ const optionalProperties = ["appConfig"];
18
+ const isOptionalProperty = (property) => !optionalProperties.includes(property);
20
19
  export const isItemEditorContext = (context) => {
21
20
  return (context.currentPage === "itemEditor" &&
22
21
  itemEditorContextProperties
23
- .filter((property) => !optionalProperties.includes(property))
22
+ .filter(isOptionalProperty)
24
23
  .every((property) => property in context && context[property] !== undefined));
25
24
  };
26
25
  const itemListingContextProperties = [
@@ -33,7 +32,7 @@ const itemListingContextProperties = [
33
32
  export const isItemListingContext = (context) => {
34
33
  return (context.currentPage === "contentInventory" &&
35
34
  itemListingContextProperties
36
- .filter((property) => !optionalProperties.includes(property))
35
+ .filter(isOptionalProperty)
37
36
  .every((property) => property in context && context[property] !== undefined));
38
37
  };
39
38
  const otherContextProperties = [
@@ -43,7 +42,7 @@ const otherContextProperties = [
43
42
  export const isOtherContext = (context) => {
44
43
  return (context.currentPage === "other" &&
45
44
  otherContextProperties
46
- .filter((property) => !optionalProperties.includes(property))
45
+ .filter(isOptionalProperty)
47
46
  .every((property) => property in context && context[property] !== undefined));
48
47
  };
49
48
  export const getContextPropertiesForPage = (currentPage) => {
@@ -1 +1 @@
1
- {"version":3,"file":"contexts.js","sourceRoot":"","sources":["../src/contexts.ts"],"names":[],"mappings":"AAEA,MAAM,uBAAuB,GAAG;IAC9B,MAAM;IACN,WAAW;IACX,eAAe;IACf,QAAQ;IACR,WAAW;IACX,WAAW;IACX,WAAW;CACuD,CAAC;AAErE,MAAM,2BAA2B,GAAG;IAClC,GAAG,uBAAuB;IAC1B,eAAe;IACf,YAAY;IACZ,kBAAkB;IAClB,aAAa;CACqD,CAAC;AAErE,MAAM,kBAAkB,GAAoD;IAC1E,WAAW;CACuD,CAAC;AAWrE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,OAA6B,EACC,EAAE;IAChC,OAAO,CACL,OAAO,CAAC,WAAW,KAAK,YAAY;QACpC,2BAA2B;aACxB,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,kBAAkB,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;aAC5D,KAAK,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,IAAI,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,SAAS,CAAC,CAC/E,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,4BAA4B,GAAG;IACnC,GAAG,uBAAuB;IAC1B,YAAY;IACZ,mBAAmB;IACnB,sBAAsB;IACtB,aAAa;CACqD,CAAC;AAWrE,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,OAA8B,EACC,EAAE;IACjC,OAAO,CACL,OAAO,CAAC,WAAW,KAAK,kBAAkB;QAC1C,4BAA4B;aACzB,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,kBAAkB,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;aAC5D,KAAK,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,IAAI,OAAO,IAAI,OAAO,CA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AAW,EAAE,CAAC;QACpB,KAAK,YAAY;YACf,OAAO,2BAA2B,CAAC;QACrC,KAAK,kBAAkB;YACrB,OAAO,4BAA4B,CAAC;QACtC,KAAK,OAAO;YACV,OAAO,sBAAsB,CAAC;QAChC,KAAK,SAAS;YACZ,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ import { describe, expectTypeOf, test } from "vitest";
2
+ describe("Context types have correct properties", () => {
3
+ test("ItemEditorContext has only item editor properties", () => {
4
+ expectTypeOf().toBeNullable();
5
+ expectTypeOf().toEqualTypeOf();
6
+ });
7
+ test("ItemListingContext has only item listing properties", () => {
8
+ expectTypeOf().toEqualTypeOf();
9
+ });
10
+ test("OtherContext has only shared properties", () => {
11
+ expectTypeOf().toEqualTypeOf();
12
+ });
13
+ test("Context is a discriminated union by currentPage", () => {
14
+ expectTypeOf().toEqualTypeOf();
15
+ });
16
+ test("ItemEditorContext has literal currentPage", () => {
17
+ expectTypeOf().toEqualTypeOf();
18
+ });
19
+ test("ItemListingContext has literal currentPage", () => {
20
+ expectTypeOf().toEqualTypeOf();
21
+ });
22
+ test("OtherContext has literal currentPage", () => {
23
+ expectTypeOf().toEqualTypeOf();
24
+ });
25
+ });
26
+ //# sourceMappingURL=contexts.test-d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contexts.test-d.js","sourceRoot":"","sources":["../src/contexts.test-d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAGtD,QAAQ,CAAC,uCAAuC,EAAE,GAAG,EAAE;IACrD,IAAI,CAAC,mDAAmD,EAAE,GAAG,EAAE;QAC7D,YAAY,EAAkC,CAAC,YAAY,EAAE,CAAC;QAC9D,YAAY,EAA2B,CAAC,aAAa,EAYlD,CAAC;IACN,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,qDAAqD,EAAE,GAAG,EAAE;QAC/D,YAAY,EAA4B,CAAC,aAAa,EAYnD,CAAC;IACN,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,yCAAyC,EAAE,GAAG,EAAE;QACnD,YAAY,EAAsB,CAAC,aAAa,EAS7C,CAAC;IACN,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,iDAAiD,EAAE,GAAG,EAAE;QAC3D,YAAY,EAA0B,CAAC,aAAa,EAEjD,CAAC;IACN,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACrD,YAAY,EAAoC,CAAC,aAAa,EAAgB,CAAC;IACjF,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,4CAA4C,EAAE,GAAG,EAAE;QACtD,YAAY,EAAqC,CAAC,aAAa,EAAsB,CAAC;IACxF,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,sCAAsC,EAAE,GAAG,EAAE;QAChD,YAAY,EAA+B,CAAC,aAAa,EAAW,CAAC;IACvE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kontent-ai/custom-app-sdk",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "The Kontent.ai Custom App SDK enhances the integration of your custom app with the Kontent.ai platform.",
5
5
  "license": "MIT",
6
6
  "author": "Kontent.ai",
@@ -19,17 +19,19 @@
19
19
  "types": "./dist/index.d.ts"
20
20
  }
21
21
  },
22
- "scripts": {
23
- "build": "tsc",
24
- "format-check": "npx @biomejs/biome ci ./src",
25
- "format": "npx @biomejs/biome check --write ./src"
26
- },
27
22
  "dependencies": {
28
23
  "zod": "^4.1.11"
29
24
  },
30
25
  "devDependencies": {
31
26
  "@biomejs/biome": "^2.2.4",
32
27
  "@types/node": "^22.9.0",
33
- "typescript": "^5.9.2"
28
+ "typescript": "^5.9.2",
29
+ "vitest": "^4.0.15"
30
+ },
31
+ "scripts": {
32
+ "build": "tsc",
33
+ "format-check": "biome ci ./src",
34
+ "format": "biome check --write ./src",
35
+ "test": "vitest run --typecheck"
34
36
  }
35
- }
37
+ }
@@ -0,0 +1,11 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ include: ["**/*.test.ts"],
6
+ typecheck: {
7
+ enabled: true,
8
+ include: ["**/*.test-d.ts"],
9
+ },
10
+ },
11
+ });