@kontent-ai/custom-app-sdk 1.0.0

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/.editorconfig ADDED
@@ -0,0 +1,6 @@
1
+ [*]
2
+ charset=utf-8
3
+ end_of_line=lf
4
+ indent_size=2
5
+ indent_style=space
6
+ insert_final_newline=true
package/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ lts/*
@@ -0,0 +1,46 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ ## Our Standards
8
+
9
+ Examples of behavior that contributes to creating a positive environment include:
10
+
11
+ * Using welcoming and inclusive language
12
+ * Being respectful of differing viewpoints and experiences
13
+ * Gracefully accepting constructive criticism
14
+ * Focusing on what is best for the community
15
+ * Showing empathy towards other community members
16
+
17
+ Examples of unacceptable behavior by participants include:
18
+
19
+ * The use of sexualized language or imagery and unwelcome sexual attention or advances
20
+ * Trolling, insulting/derogatory comments, and personal or political attacks
21
+ * Public or private harassment
22
+ * Publishing others' private information, such as a physical or electronic address, without explicit permission
23
+ * Other conduct which could reasonably be considered inappropriate in a professional setting
24
+
25
+ ## Our Responsibilities
26
+
27
+ Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28
+
29
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30
+
31
+ ## Scope
32
+
33
+ This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34
+
35
+ ## Enforcement
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at devrel@kontent.ai. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38
+
39
+ Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40
+
41
+ ## Attribution
42
+
43
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [https://contributor-covenant.org/version/1/4][version]
44
+
45
+ [homepage]: https://contributor-covenant.org
46
+ [version]: https://contributor-covenant.org/version/1/4/
@@ -0,0 +1,67 @@
1
+ # Ways to contribute
2
+ <img align="right" width="100" height="100" src="https://i.imgur.com/PYTV0jP.png">
3
+
4
+ There are many different ways in which you can contribute. One of the easiest ways is simply to use our software and provide us with your feedback through the right channel. You can also help us improve the open-source projects by submitting pull requests with code and documentation changes.
5
+
6
+ ## Where to get support
7
+ Please note that **level of provided support is always determined by the LICENSE** of a given open-source project. Also, always make sure you use the **[latest version](../../releases)** of any given OS project. We can't provide any help for older versions. We don't want to make things complicated so we try to take the same approach in all our repositories.
8
+
9
+ ### I found a bug in a Kontent.ai open-source project
10
+ <img align="right" width="100" height="100" src="https://i.imgur.com/TYIQdpv.png">
11
+
12
+ Sorry to hear that. Just log a new [GitHub issue](../../issues) and someone will take a look at it. Remember, the more information you provide, the easier it will be to fix the issue. If you feel like it, you can also fix the bug on your own and submit a new pull request.
13
+
14
+ ### I need help with using the projects and/or coding
15
+ <img align="right" width="100" height="100" src="https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.svg">
16
+
17
+ To get help with coding and structuring your projects, use [StackOverflow](https://stackoverflow.com/) and tag your questions with [`kontent-ai`](https://stackoverflow.com/questions/tagged/kontent-ai) tag.
18
+
19
+ Our team members and the community monitor these channels on a regular basis.
20
+
21
+ ### I want to report a security bug
22
+ <img align="right" width="100" height="100" src="https://i.imgur.com/z82nnJB.png">
23
+
24
+ Security issues and bugs should be reported privately, via email, to Kontent.ai Security Team [security@kontent.ai](mailto:security@kontent.ai). For more details, check the [Security policy](SECURITY.md).
25
+
26
+ ### I have an idea for a new feature (or feedback on existing functionality)
27
+ <img align="right" width="100" height="100" src="https://i.imgur.com/rUFkyPy.png">
28
+
29
+ Everybody loves new features! You can submit a new [feature request](../../issues) or you can code it on your own and [send us a pull request](#submitting-pull-requests). In either case, don't forget to mention what's the use case and what's the expected output.
30
+
31
+
32
+ ## Submitting pull requests
33
+ <img align="right" width="100" height="100" src="https://i.imgur.com/aSeiliy.png">
34
+
35
+ Unless you're fixing a typo, it's usually a good idea to discuss the feature before you submit a pull request with code changes, so let's start with submitting a new [GitHub issue](../../issues) and discussing the whether it fits the vision of a given project.
36
+ You might also read these two blogs posts on contributing code: [Open Source Contribution Etiquette](http://tirania.org/blog/archive/2010/Dec-31.html) by Miguel de Icaza and [Don't "Push" Your Pull Requests](https://www.igvita.com/2011/12/19/dont-push-your-pull-requests/) by Ilya Grigorik. Note that all code submissions will be rigorously reviewed and tested by Kontent.ai maintainer teams, and only those that meet an high bar for both quality and design/roadmap appropriateness will be merged into the source.
37
+
38
+
39
+ ### Example - process of contribution
40
+ If not stated otherwise, we use [feature branch workflow](https://www.atlassian.com/git/tutorials/comparing-workflows/feature-branch-workflow).
41
+
42
+ To start with coding, fork the repository you want to contribute to, create a new branch, and start coding. Once the functionality is [done](#Definition-of-Done), you can submit a [pull request](https://help.github.com/articles/about-pull-requests/).
43
+
44
+ ### Definition of Done
45
+ <img align="right" width="100" height="100" src="https://i.imgur.com/g82Ohdv.png">
46
+
47
+ - New/fixed code is covered with tests
48
+ - CI can build the code
49
+ - All tests are pass
50
+ - New version number follows [semantic versioning](https://semver.org/)
51
+ - Coding style (spaces, indentation) is in line with the rest of the code in a given repository
52
+ - Documentation is updated (e.g. code examples in README, Wiki pages, etc.)
53
+ - All `public` members are documented (using XML doc, phpdoc, etc.)
54
+ - Code doesn't contain any secrets (private keys, etc.)
55
+ - Commit messages are clear. Please read these articles: [Writing good commit messages](https://github.com/erlang/otp/wiki/Writing-good-commit-messages), [A Note About Git Commit Messages](https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html), [On commit messages](https://who-t.blogspot.com/2009/12/on-commit-messages.html)
56
+
57
+
58
+ ### Feedback
59
+ <img align="right" width="100" height="100" src="https://i.imgur.com/ZQfNzJJ.png">
60
+
61
+ Your pull request will now go through extensive checks by the subject matter experts on our team. Please be patient. Update your pull request according to feedback until it is approved by one of Kontent.ai maintainers. After that, one of our team members may adjust the branch you merge into based on the expected release schedule.
62
+
63
+
64
+ ## Code of Conduct
65
+ <img align="right" width="100" height="100" src="https://i.imgur.com/cObdKQy.png">
66
+
67
+ The Kontent.ai team is committed to fostering a welcoming community, therefore this project has adopted the [Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md). If you have any additional questions or comments, you can contact us directly at devrel@kontent.ai.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Kontent s.r.o.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,99 @@
1
+ # Kontent.ai Custom app SDK JS
2
+
3
+ [![Contributors][contributors-shield]][contributors-url]
4
+ [![Forks][forks-shield]][forks-url]
5
+ [![Stargazers][stars-shield]][stars-url]
6
+ [![Issues][issues-shield]][issues-url]
7
+ [![MIT License][license-shield]][license-url]
8
+
9
+ [![Discord][discussion-shield]][discussion-url]
10
+
11
+ ## About The Project
12
+
13
+ A JavaScript SDK for communicating with the Kontent.ai Custom App API.
14
+ It facilitates the communication between the Kontent.ai app and the custom app providing access to the configuration and context data.
15
+
16
+ ## Getting Started
17
+
18
+ ### Installation
19
+
20
+ ```sh
21
+ npm install @kontent-ai/custom-app-sdk-js
22
+ ```
23
+
24
+ > [!IMPORTANT]
25
+ > The SDK attaches event listeners to communicate with the Kontent.ai app. Make sure to only include the SDK in the browser environment.
26
+
27
+ ## Usage example
28
+
29
+ ```typescript
30
+ import { getCustomAppContext, CustomAppContext } from "@kontent-ai/custom-app-sdk-js";
31
+
32
+ const response: CustomAppContext = await getCustomAppContext();
33
+
34
+ if (response.isError) {
35
+ console.error({ errorCode: response.code, description: response.description});
36
+ } else {
37
+ console.log({ config: response.config, context: response.context });
38
+ }
39
+ ```
40
+
41
+ ## API Reference
42
+
43
+ ### getCustomAppContext
44
+
45
+ Use the `getCustomAppContext` function to retrieve context of the custom app. The function takes no arguments and returns a promise with a value of an object of type `CustomAppContext`.
46
+
47
+ #### CustomAppContext
48
+
49
+ | Property | Type | Description |
50
+ |---------------|------------------------|------------------------------------------------------------------------------|
51
+ | `isError` | boolean | Determines if there was an error while getting the context of the custom app |
52
+ | `code` | ErrorCode enum \| null | The code of the error message |
53
+ | `description` | string \| null | The description of the error message |
54
+ | `context` | object \| null | Contains data provided by the Kontent.ai application |
55
+ | `config` | object \| null | Contains JSON object specified in the custom app configuration |
56
+
57
+ #### Config
58
+ The `config` object is a JSON object that can be defined within the Custom App configuration under Environment settings in the Kontent.ai app.
59
+
60
+ #### Context
61
+ The `context` object contains data provided by the Kontent.ai application that you can leverage in your custom app.
62
+
63
+ | Property | Type | Description |
64
+ |-----------------|-------------------|--------------------------------------------------------------------------|
65
+ | `environmentId` | UUID | The environment's ID |
66
+ | `userId` | string | The current user's ID |
67
+ | `userEmail` | string | The current user's email |
68
+ | `userRoles` | Array of UserRole | An array containing all the roles of the current user in the environment |
69
+
70
+ #### UserRole
71
+
72
+ | Property | Type | Description |
73
+ |------------|--------|----------------------------------------------------------------------|
74
+ | `id` | UUID | The role's ID |
75
+ | `codename` | string | The role's codename - applicable only for the _Project manager_ role |
76
+
77
+ ## Contributing
78
+
79
+ For Contributing please see <a href="./CONTRIBUTING.md">`CONTRIBUTING.md`</a> for more information.
80
+
81
+
82
+
83
+ ## License
84
+
85
+ Distributed under the MIT License. See [`LICENSE.md`](./LICENSE.md) for more information.
86
+
87
+
88
+ [contributors-shield]: https://img.shields.io/github/contributors/kontent-ai/custom-app-sdk-js.svg?style=for-the-badge
89
+ [contributors-url]: https://github.com/kontent-ai/custom-app-sdk-js/graphs/contributors
90
+ [forks-shield]: https://img.shields.io/github/forks/kontent-ai/custom-app-sdk-js.svg?style=for-the-badge
91
+ [forks-url]: https://github.com/kontent-ai/custom-app-sdk-js/network/members
92
+ [stars-shield]: https://img.shields.io/github/stars/kontent-ai/custom-app-sdk-js.svg?style=for-the-badge
93
+ [stars-url]: https://github.com/kontent-ai/custom-app-sdk-js/stargazers
94
+ [issues-shield]: https://img.shields.io/github/issues/kontent-ai/custom-app-sdk-js.svg?style=for-the-badge
95
+ [issues-url]:https://github.com/kontent-ai/custom-app-sdk-js/issues
96
+ [license-shield]: https://img.shields.io/github/license/kontent-ai/custom-app-sdk-js.svg?style=for-the-badge
97
+ [license-url]:https://github.com/kontent-ai/custom-app-sdk-js/blob/master/LICENSE.md
98
+ [discussion-shield]: https://img.shields.io/discord/821885171984891914?color=%237289DA&label=Kontent%2Eai%20Discord&logo=discord&style=for-the-badge
99
+ [discussion-url]: https://discord.com/invite/SKCxwPtevJ
package/SECURITY.md ADDED
@@ -0,0 +1,27 @@
1
+ ## Security
2
+ In [Kontent.ai](http://kontent.ai/), security has always been of great importance. Kontent.ai is committed to working with security researchers to help identify and fix vulnerabilities in our systems and services, which includes all source code repositories managed through our [GitHub organization](https://github.com/kontent-ai).
3
+
4
+ If you believe you have found a security vulnerability in any Kontent.ai-owned repository that meets our [qualification criteria](https://kontent.ai/vulnerability-disclosure-policy/), please report it to us as described below.
5
+
6
+ ## Reporting Security Issues
7
+ **Please do not report security vulnerabilities through public GitHub issues.**
8
+
9
+ Security issues and bugs should be reported privately, via email to [security@kontent.ai](mailto:security@kontent.ai). For secure communication, use our [PGP key](https://app.kontent.ai/pgp-key.txt). If you find multiple issues, please report them separately. We will keep you updated on the progress towards remediation of issues we accept from you, and we ask you not to disclose the issue publicly without Kontent.ai’s prior written permission. Additional information can be found in our [Vulnerability Disclosure Policy](https://kontent.ai/vulnerability-disclosure-policy/).
10
+
11
+ If possible, please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the issue:
12
+
13
+ * Type of issue (e.g. SQL injection, XSS, broken access control…)
14
+ * Full paths of source file(s) related to the manifestation of the issue
15
+ * The location of the affected source code (tag/branch/commit or direct URL)
16
+ * Any special configuration required to reproduce the issue
17
+ * Step-by-step instructions to reproduce the issue
18
+ * Proof-of-concept or exploit code (if possible)
19
+ * Impact of the issue, including how an attacker might exploit the issue
20
+
21
+ This information will help us triage your report more quickly.
22
+
23
+ ## Preferred Languages
24
+ We prefer all communications to be in English.
25
+
26
+ ## Safe harbor
27
+ Kontent.ai will not initiate a lawsuit or law enforcement investigation against you in response to reporting a vulnerability if you fully comply with our [Vulnerability Disclosure Policy](https://kontent.ai/vulnerability-disclosure-policy/).
@@ -0,0 +1 @@
1
+ export declare const createUuid: () => string;
@@ -0,0 +1,2 @@
1
+ export const createUuid = () => globalThis.crypto.randomUUID();
2
+ //# sourceMappingURL=createUuid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createUuid.js","sourceRoot":"","sources":["../src/createUuid.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,GAAW,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC"}
@@ -0,0 +1,21 @@
1
+ export declare enum ErrorCode {
2
+ UnknownMessage = "unknown-message"
3
+ }
4
+ export type CustomAppContext = {
5
+ readonly isError: false;
6
+ readonly context: {
7
+ readonly environmentId: string;
8
+ readonly userId: string;
9
+ readonly userEmail: string;
10
+ readonly userRoles: ReadonlyArray<{
11
+ readonly id: string;
12
+ readonly codename: string | null;
13
+ }>;
14
+ };
15
+ readonly config?: unknown;
16
+ } | {
17
+ readonly isError: true;
18
+ readonly code: ErrorCode;
19
+ readonly description: string;
20
+ };
21
+ export declare const getCustomAppContext: () => Promise<CustomAppContext>;
@@ -0,0 +1,27 @@
1
+ import { sendMessage } from "./iframeMessenger";
2
+ import { ErrorMessage } from "./iframeSchema";
3
+ import { matchesSchema } from "./matchesSchema";
4
+ export var ErrorCode;
5
+ (function (ErrorCode) {
6
+ ErrorCode["UnknownMessage"] = "unknown-message";
7
+ })(ErrorCode || (ErrorCode = {}));
8
+ export const getCustomAppContext = () => new Promise((resolve, reject) => {
9
+ try {
10
+ sendMessage({
11
+ type: "get-context-request",
12
+ version: "1.0.0",
13
+ payload: null,
14
+ }, (response) => {
15
+ if (matchesSchema(ErrorMessage, response)) {
16
+ resolve({ isError: true, code: response.code, description: response.description });
17
+ }
18
+ else {
19
+ resolve({ ...response.payload, isError: false });
20
+ }
21
+ });
22
+ }
23
+ catch (error) {
24
+ reject(error);
25
+ }
26
+ });
27
+ //# sourceMappingURL=customAppSdk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customAppSdk.js","sourceRoot":"","sources":["../src/customAppSdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,CAAN,IAAY,SAEX;AAFD,WAAY,SAAS;IACnB,+CAAkC,CAAA;AACpC,CAAC,EAFW,SAAS,KAAT,SAAS,QAEpB;AAsBD,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAA8B,EAAE,CACjE,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;IAC9B,IAAI,CAAC;QACH,WAAW,CACT;YACE,IAAI,EAAE,qBAAqB;YAC3B,OAAO,EAAE,OAAO;YAChB,OAAO,EAAE,IAAI;SACd,EACD,CAAC,QAAQ,EAAE,EAAE;YACX,IAAI,aAAa,CAAC,YAAY,EAAE,QAAQ,CAAC,EAAE,CAAC;gBAC1C,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;YACrF,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,EAAE,GAAG,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;YACnD,CAAC;QACH,CAAC,CACF,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,CAAC;IAChB,CAAC;AACH,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { Schema } from "./iframeSchema";
2
+ export declare const sendMessage: <TMessageType extends keyof Schema["client"]>(message: Omit<Schema["client"][TMessageType]["request"], "requestId">, callback: (data: Schema["client"][TMessageType]["response"]) => void) => void;
@@ -0,0 +1,18 @@
1
+ import { createUuid } from "./createUuid";
2
+ let callbacks = {};
3
+ export const sendMessage = (message, callback) => {
4
+ const requestId = createUuid();
5
+ callbacks = { ...callbacks, [requestId]: callback };
6
+ window.parent.postMessage({ ...message, requestId }, "*");
7
+ };
8
+ const processMessage = (event) => {
9
+ const message = event.data;
10
+ const callback = callbacks[message.requestId];
11
+ callbacks = Object.fromEntries(Object.entries(callbacks).filter(([requestId]) => requestId !== message.requestId));
12
+ callback?.(message);
13
+ };
14
+ if (window.self === window.top) {
15
+ throw new Error("Custom app is not hosted in an IFrame.");
16
+ }
17
+ window.addEventListener("message", processMessage, true);
18
+ //# sourceMappingURL=iframeMessenger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iframeMessenger.js","sourceRoot":"","sources":["../src/iframeMessenger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAI1C,IAAI,SAAS,GAAsD,EAAE,CAAC;AAEtE,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,OAAqE,EACrE,QAAoE,EAC9D,EAAE;IACR,MAAM,SAAS,GAAG,UAAU,EAAE,CAAC;IAC/B,SAAS,GAAG,EAAE,GAAG,SAAS,EAAE,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAsB,CAAC;IACxE,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,EAAE,GAAG,CAAC,CAAC;AAC5D,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC,KAAuC,EAAQ,EAAE;IACvE,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC;IAC3B,MAAM,QAAQ,GAAG,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC9C,SAAS,GAAG,MAAM,CAAC,WAAW,CAC5B,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,SAAS,KAAK,OAAO,CAAC,SAAS,CAAC,CACnF,CAAC;IACF,QAAQ,EAAE,CAAC,OAAO,CAAC,CAAC;AACtB,CAAC,CAAC;AAEF,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,GAAG,EAAE,CAAC;IAC/B,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;AAC5D,CAAC;AAED,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,cAAc,EAAE,IAAI,CAAC,CAAC"}
@@ -0,0 +1,153 @@
1
+ import { z } from "zod";
2
+ declare enum ErrorCode {
3
+ UnknownMessage = "unknown-message"
4
+ }
5
+ export declare const ErrorMessage: z.ZodReadonly<z.ZodObject<{
6
+ requestId: z.ZodString;
7
+ isError: z.ZodBoolean;
8
+ code: z.ZodNativeEnum<typeof ErrorCode>;
9
+ description: z.ZodString;
10
+ }, "strip", z.ZodTypeAny, {
11
+ requestId: string;
12
+ isError: boolean;
13
+ code: ErrorCode;
14
+ description: string;
15
+ }, {
16
+ requestId: string;
17
+ isError: boolean;
18
+ code: ErrorCode;
19
+ description: string;
20
+ }>>;
21
+ declare const ClientGetContextV1Request: z.ZodReadonly<z.ZodObject<{
22
+ type: z.ZodLiteral<"get-context-request">;
23
+ requestId: z.ZodString;
24
+ version: z.ZodLiteral<"1.0.0">;
25
+ payload: z.ZodNull;
26
+ }, "strip", z.ZodTypeAny, {
27
+ requestId: string;
28
+ type: "get-context-request";
29
+ version: "1.0.0";
30
+ payload: null;
31
+ }, {
32
+ requestId: string;
33
+ type: "get-context-request";
34
+ version: "1.0.0";
35
+ payload: null;
36
+ }>>;
37
+ declare const ClientGetContextV1Response: z.ZodReadonly<z.ZodUnion<[z.ZodObject<{
38
+ type: z.ZodLiteral<"get-context-response">;
39
+ payload: z.ZodReadonly<z.ZodObject<{
40
+ context: z.ZodReadonly<z.ZodObject<{
41
+ environmentId: z.ZodString;
42
+ userId: z.ZodString;
43
+ userEmail: z.ZodString;
44
+ userRoles: z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
45
+ id: z.ZodString;
46
+ codename: z.ZodUnion<[z.ZodString, z.ZodNull]>;
47
+ }, "strip", z.ZodTypeAny, {
48
+ id: string;
49
+ codename: string | null;
50
+ }, {
51
+ id: string;
52
+ codename: string | null;
53
+ }>>, "many">>;
54
+ }, "strip", z.ZodTypeAny, {
55
+ environmentId: string;
56
+ userId: string;
57
+ userEmail: string;
58
+ userRoles: readonly Readonly<{
59
+ id: string;
60
+ codename: string | null;
61
+ }>[];
62
+ }, {
63
+ environmentId: string;
64
+ userId: string;
65
+ userEmail: string;
66
+ userRoles: readonly Readonly<{
67
+ id: string;
68
+ codename: string | null;
69
+ }>[];
70
+ }>>;
71
+ config: z.ZodUnknown;
72
+ }, "strip", z.ZodTypeAny, {
73
+ context: Readonly<{
74
+ environmentId: string;
75
+ userId: string;
76
+ userEmail: string;
77
+ userRoles: readonly Readonly<{
78
+ id: string;
79
+ codename: string | null;
80
+ }>[];
81
+ }>;
82
+ config?: unknown;
83
+ }, {
84
+ context: Readonly<{
85
+ environmentId: string;
86
+ userId: string;
87
+ userEmail: string;
88
+ userRoles: readonly Readonly<{
89
+ id: string;
90
+ codename: string | null;
91
+ }>[];
92
+ }>;
93
+ config?: unknown;
94
+ }>>;
95
+ requestId: z.ZodString;
96
+ version: z.ZodLiteral<"1.0.0">;
97
+ }, "strip", z.ZodTypeAny, {
98
+ requestId: string;
99
+ type: "get-context-response";
100
+ version: "1.0.0";
101
+ payload: Readonly<{
102
+ context: Readonly<{
103
+ environmentId: string;
104
+ userId: string;
105
+ userEmail: string;
106
+ userRoles: readonly Readonly<{
107
+ id: string;
108
+ codename: string | null;
109
+ }>[];
110
+ }>;
111
+ config?: unknown;
112
+ }>;
113
+ }, {
114
+ requestId: string;
115
+ type: "get-context-response";
116
+ version: "1.0.0";
117
+ payload: Readonly<{
118
+ context: Readonly<{
119
+ environmentId: string;
120
+ userId: string;
121
+ userEmail: string;
122
+ userRoles: readonly Readonly<{
123
+ id: string;
124
+ codename: string | null;
125
+ }>[];
126
+ }>;
127
+ config?: unknown;
128
+ }>;
129
+ }>, z.ZodReadonly<z.ZodObject<{
130
+ requestId: z.ZodString;
131
+ isError: z.ZodBoolean;
132
+ code: z.ZodNativeEnum<typeof ErrorCode>;
133
+ description: z.ZodString;
134
+ }, "strip", z.ZodTypeAny, {
135
+ requestId: string;
136
+ isError: boolean;
137
+ code: ErrorCode;
138
+ description: string;
139
+ }, {
140
+ requestId: string;
141
+ isError: boolean;
142
+ code: ErrorCode;
143
+ description: string;
144
+ }>>]>>;
145
+ export type Schema = {
146
+ client: {
147
+ "get-context@1.0.0": {
148
+ request: z.infer<typeof ClientGetContextV1Request>;
149
+ response: z.infer<typeof ClientGetContextV1Response>;
150
+ };
151
+ };
152
+ };
153
+ export {};
@@ -0,0 +1,50 @@
1
+ import { z } from "zod";
2
+ var ErrorCode;
3
+ (function (ErrorCode) {
4
+ ErrorCode["UnknownMessage"] = "unknown-message";
5
+ })(ErrorCode || (ErrorCode = {}));
6
+ export const ErrorMessage = z
7
+ .object({
8
+ requestId: z.string().uuid(),
9
+ isError: z.boolean(),
10
+ code: z.nativeEnum(ErrorCode),
11
+ description: z.string(),
12
+ })
13
+ .readonly();
14
+ const ClientGetContextV1Request = z
15
+ .object({
16
+ type: z.literal("get-context-request"),
17
+ requestId: z.string().uuid(),
18
+ version: z.literal("1.0.0"),
19
+ payload: z.null(),
20
+ })
21
+ .readonly();
22
+ const ClientGetContextV1Response = z
23
+ .object({
24
+ type: z.literal("get-context-response"),
25
+ payload: z
26
+ .object({
27
+ context: z
28
+ .object({
29
+ environmentId: z.string().uuid(),
30
+ userId: z.string(),
31
+ userEmail: z.string().email(),
32
+ userRoles: z
33
+ .array(z
34
+ .object({
35
+ id: z.string().uuid(),
36
+ codename: z.string().or(z.null()),
37
+ })
38
+ .readonly())
39
+ .readonly(),
40
+ })
41
+ .readonly(),
42
+ config: z.unknown(),
43
+ })
44
+ .readonly(),
45
+ requestId: z.string().uuid(),
46
+ version: z.literal("1.0.0"),
47
+ })
48
+ .or(ErrorMessage)
49
+ .readonly();
50
+ //# sourceMappingURL=iframeSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iframeSchema.js","sourceRoot":"","sources":["../src/iframeSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,IAAK,SAEJ;AAFD,WAAK,SAAS;IACZ,+CAAkC,CAAA;AACpC,CAAC,EAFI,SAAS,KAAT,SAAS,QAEb;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC;KAC1B,MAAM,CAAC;IACN,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE;IAC5B,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE;IACpB,IAAI,EAAE,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC;IAC7B,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;CACxB,CAAC;KACD,QAAQ,EAAE,CAAC;AAEd,MAAM,yBAAyB,GAAG,CAAC;KAChC,MAAM,CAAC;IACN,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,qBAAqB,CAAC;IACtC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE;IAC5B,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;IAC3B,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE;CAClB,CAAC;KACD,QAAQ,EAAE,CAAC;AAEd,MAAM,0BAA0B,GAAG,CAAC;KACjC,MAAM,CAAC;IACN,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,sBAAsB,CAAC;IACvC,OAAO,EAAE,CAAC;SACP,MAAM,CAAC;QACN,OAAO,EAAE,CAAC;aACP,MAAM,CAAC;YACN,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE;YAChC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;YAClB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE;YAC7B,SAAS,EAAE,CAAC;iBACT,KAAK,CACJ,CAAC;iBACE,MAAM,CAAC;gBACN,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE;gBACrB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;aAClC,CAAC;iBACD,QAAQ,EAAE,CACd;iBACA,QAAQ,EAAE;SACd,CAAC;aACD,QAAQ,EAAE;QACb,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE;KACpB,CAAC;SACD,QAAQ,EAAE;IACb,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE;IAC5B,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;CAC5B,CAAC;KACD,EAAE,CAAC,YAAY,CAAC;KAChB,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { getCustomAppContext } from "./customAppSdk";
2
+ export { CustomAppContext } from "./customAppSdk";
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { getCustomAppContext } from "./customAppSdk";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { z } from "zod";
2
+ export declare const matchesSchema: <Output>(schema: z.ZodType<Output>, data: unknown) => data is Output;
@@ -0,0 +1,2 @@
1
+ export const matchesSchema = (schema, data) => schema.safeParse(data).success;
2
+ //# sourceMappingURL=matchesSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matchesSchema.js","sourceRoot":"","sources":["../src/matchesSchema.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,aAAa,GAAG,CAAS,MAAyB,EAAE,IAAa,EAAkB,EAAE,CAChG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { Schema } from "./iframeSchema";
2
+ export type AllClientResponses = Schema["client"][keyof Schema["client"]]["response"];
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=utilityTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilityTypes.js","sourceRoot":"","sources":["../src/utilityTypes.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@kontent-ai/custom-app-sdk",
3
+ "version": "1.0.0",
4
+ "description": "The Kontent.ai Custom App SDK enhances the integration of your custom app with the Kontent.ai platform.",
5
+ "license": "MIT",
6
+ "author": "Kontent.ai",
7
+ "keywords": [
8
+ "Kontent.ai",
9
+ "Kontent AI",
10
+ "Kontent Custom App SDK JS"
11
+ ],
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "repository": "https://github.com/kontent-ai/custom-app-sdk-js",
15
+ "type": "module",
16
+ "exports": {
17
+ ".": {
18
+ "import": "./dist/index.js",
19
+ "types": "./dist/index.d.ts"
20
+ }
21
+ },
22
+ "scripts": {
23
+ "build": "tsc",
24
+ "format-check": "npx @biomejs/biome ci ./src",
25
+ "format": "npx @biomejs/biome check --write ./src"
26
+ },
27
+ "dependencies": {
28
+ "zod": "^3.23.8"
29
+ },
30
+ "devDependencies": {
31
+ "@biomejs/biome": "^1.9.4",
32
+ "@types/node": "^22.9.0",
33
+ "typescript": "^5.6.3"
34
+ }
35
+ }