Skip to content

Commit

Permalink
Add custom apps API
Browse files Browse the repository at this point in the history
* Add custom apps API

* Update build and release

* Update schema to be up to date

* Update format settings

* Rename initCustomApp to getCustomAppContext

---------

Co-authored-by: Daniel Pokorny <[email protected]>
  • Loading branch information
matus12 and pokornyd authored Dec 4, 2024
1 parent 3a8b647 commit 1ae17b7
Show file tree
Hide file tree
Showing 24 changed files with 687 additions and 103 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[*]
charset=utf-8
end_of_line=lf
indent_size=2
indent_style=space
insert_final_newline=true
7 changes: 1 addition & 6 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
# Users referenced in this file will automatically be requested as reviewers for PRs that modify the given paths.
# See https://help.github.com/articles/about-code-owners/

# Format: <Path> <Maintainer Team name from: https://kontent-ai.github.io/Guidelines-for-GitHub-permissions-in-Kontent-ai-organization>
# Example: * @kontent-ai/developer-relations
*
* @JiriLojda @kontent-ai/developer-relations
31 changes: 18 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# For more information do to https://kontent-ai.github.io/ci-and-automation/ci-and-automation
name: Lint & Build

name: "Build" # Represents the name of the whole action.
on: # Specifies the section where we describe our build triggers.
push: # The action runs with push.
pull_request: # The action runs with a pull request.
schedule: # Specifies the section where we describe the schedule of running the action.
- cron: '0 18 * * 1' # The CRON expression describes when to run the action.
jobs: # Specifies the section where we describe our jobs.
Build: # Specific job section.
runs-on: ubuntu-latest # Describes the environment.
steps: # Specifies the section where we describe the job's steps.
- name: Output some string
run: echo "Set some actual CI steps"
on:
push:
branches: [main]
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js from .nvmrc file
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
- run: npm ci
- run: npm run format-check
- run: npm run build
28 changes: 28 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
on:
release:
types: [published]

name: publish-to-npm
jobs:
publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
registry-url: 'https://registry.npmjs.org'

- run: npm ci
- run: npm run build

- run: npm publish --access=public
if: ${{!github.event.release.prerelease}}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_API_KEY }}
- run: npm publish --tag prerelease
if: ${{github.event.release.prerelease}}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_API_KEY }}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
.history
.idea
.vscode/settings.json
dist/
node_modules/
28 changes: 28 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# repo metadata
.github/**

# tests
tests/**
jest.config.cjs
tsconfig.test.json

# source
src/**
index.ts

# docs
media/**
docs/**
showcase/**

# misc
/.gitignore
/.npmignore
/tsconfig.json
/.eslintrc
/node_modules
.idea/
.vscode/
logos/
profile/
biome.json
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/*
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"biomejs.biome"
]
}
14 changes: 14 additions & 0 deletions .vscode/settings.example.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// Code formatting
"editor.codeActionsOnSave": {
"quickfix.biome": "explicit",
"source.organizeImports.biome": "explicit"
},
"editor.defaultFormatter": "biomejs.biome",
"editor.formatOnSave": true,

// Directories excluded from search
"search.exclude": {
"**/.history": true
}
}
12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Ways to contribute
# Ways to contribute
<img align="right" width="100" height="100" src="https://i.imgur.com/PYTV0jP.png">

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.

## Where to get support
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.
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.

### I found a bug in a Kontent.ai open-source project
<img align="right" width="100" height="100" src="https://i.imgur.com/TYIQdpv.png">
Expand All @@ -21,7 +21,7 @@ Our team members and the community monitor these channels on a regular basis.
### I want to report a security bug
<img align="right" width="100" height="100" src="https://i.imgur.com/z82nnJB.png">

Security issues and bugs should be reported privately, via email, to Kontent.ai Security Team [[email protected]](mailto:[email protected]). For more details, check the [Security policy](SECURITY.md).
Security issues and bugs should be reported privately, via email, to Kontent.ai Security Team [[email protected]](mailto:[email protected]). For more details, check the [Security policy](SECURITY.md).

### I have an idea for a new feature (or feedback on existing functionality)
<img align="right" width="100" height="100" src="https://i.imgur.com/rUFkyPy.png">
Expand All @@ -37,9 +37,9 @@ You might also read these two blogs posts on contributing code: [Open Source Con


### Example - process of contribution
If not stated otherwise, we use [feature branch workflow](https://www.atlassian.com/git/tutorials/comparing-workflows/feature-branch-workflow).
If not stated otherwise, we use [feature branch workflow](https://www.atlassian.com/git/tutorials/comparing-workflows/feature-branch-workflow).

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/).
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/).

### Definition of Done
<img align="right" width="100" height="100" src="https://i.imgur.com/g82Ohdv.png">
Expand All @@ -64,4 +64,4 @@ Your pull request will now go through extensive checks by the subject matter exp
## Code of Conduct
<img align="right" width="100" height="100" src="https://i.imgur.com/cObdKQy.png">

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 [email protected].
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 [email protected].
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) [Current year here] Kontent s.r.o.
Copyright (c) 2024 Kontent s.r.o.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
77 changes: 0 additions & 77 deletions README-TEMPLATE.md

This file was deleted.

97 changes: 97 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Kontent.ai Custom app SDK JS

[![Contributors][contributors-shield]][contributors-url]
[![Forks][forks-shield]][forks-url]
[![Stargazers][stars-shield]][stars-url]
[![Issues][issues-shield]][issues-url]
[![MIT License][license-shield]][license-url]

[![Discord][discussion-shield]][discussion-url]

<!-- ABOUT THE PROJECT -->
## About The Project

The Kontent.ai Custom App SDK enhances the integration of your custom app with the Kontent.ai platform.
<!-- GETTING STARTED -->
## Getting Started
### Installation
```sh
npm install @kontent-ai/custom-app-sdk-js
```

<!-- USAGE EXAMPLES -->
## Usage

```javascript
import { getCustomAppContext, CustomAppContext } from "@kontent-ai/custom-app-sdk-js";

const response: CustomAppContext = await getCustomAppContext();

if (response.isError) {
console.error({ errorCode: response.code, description: response.description});
} else {
console.log({ config: response.config, context: response.context });
}
```

### getCustomAppContext function

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`.

### CustomAppContext

| Property | Type | Description |
|---------------|------------------------|------------------------------------------------------------------------------|
| `isError` | boolean | Determines if there was an error while getting the context of the custom app |
| `code` | ErrorCode enum \| null | The code of the error message |
| `description` | string \| null | The description of the error message |
| `context` | object \| null | Contains data provided by the Kontent.ai application |
| `config` | object \| null | Contains JSON object specified in the custom app configuration |

### Config object
The `config` object is a JSON object that can be defined within the Custom App configuration under Environment settings in the Kontent.ai app.

### Context object
The `context` object contains data provided by the Kontent.ai application that you can leverage in your custom app.

| Property | Type | Description |
|-----------------|-------------------|--------------------------------------------------------------------------|
| `environmentId` | UUID | The environment's ID |
| `userId` | string | The current user's ID |
| `userEmail` | string | The current user's email |
| `userRoles` | Array of UserRole | An array containing all the roles of the current user in the environment |

#### UserRole object

| Property | Type | Description |
|------------|--------|----------------------------------------------------------------------|
| `id` | UUID | The role's ID |
| `codename` | string | The role's codename - applicable only for the _Project manager_ role |

<!-- CONTRIBUTING -->
## Contributing

For Contributing please see <a href="./CONTRIBUTING.md">`CONTRIBUTING.md`</a> for more information.



<!-- LICENSE -->
## License

Distributed under the MIT License. See [`LICENSE.md`](./LICENSE.md) for more information.


<!-- MARKDOWN LINKS & IMAGES -->
<!-- https://github.com/kontent-ai/Home/wiki/Checklist-for-publishing-a-new-OS-project#badges-->
[contributors-shield]: https://img.shields.io/github/contributors/kontent-ai/custom-app-sdk-js.svg?style=for-the-badge
[contributors-url]: https://github.com/kontent-ai/custom-app-sdk-js/graphs/contributors
[forks-shield]: https://img.shields.io/github/forks/kontent-ai/custom-app-sdk-js.svg?style=for-the-badge
[forks-url]: https://github.com/kontent-ai/custom-app-sdk-js/network/members
[stars-shield]: https://img.shields.io/github/stars/kontent-ai/custom-app-sdk-js.svg?style=for-the-badge
[stars-url]: https://github.com/kontent-ai/custom-app-sdk-js/stargazers
[issues-shield]: https://img.shields.io/github/issues/kontent-ai/custom-app-sdk-js.svg?style=for-the-badge
[issues-url]:https://github.com/kontent-ai/custom-app-sdk-js/issues
[license-shield]: https://img.shields.io/github/license/kontent-ai/custom-app-sdk-js.svg?style=for-the-badge
[license-url]:https://github.com/kontent-ai/custom-app-sdk-js/blob/master/LICENSE.md
[discussion-shield]: https://img.shields.io/discord/821885171984891914?color=%237289DA&label=Kontent%2Eai%20Discord&logo=discord&style=for-the-badge
[discussion-url]: https://discord.com/invite/SKCxwPtevJ
32 changes: 32 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"organizeImports": {
"enabled": true
},
"formatter": {
"indentStyle": "space",
"lineWidth": 100
},
"javascript": {
"formatter": {
"quoteStyle": "double",
"indentStyle": "space",
"lineWidth": 100
}
},
"json": {
"formatter": {
"indentStyle": "space"
}
},
"files": {
"ignore": [
"**/*-lock.json",
"**/.DS_Store",
".idea/**",
".vscode/**",
".history/**",
"node_modules/**"
]
}
}
Loading

0 comments on commit 1ae17b7

Please sign in to comment.