|
1 | | -# CoCreate-api |
| 1 | +# @cocreate/api |
2 | 2 |
|
3 | | -A simple api helper component in vanilla javascript used by JavaScript developers to create thirdparty api intergrations. CoCreate-api includes the client component and server side for api processing. Thirdparty apis can be accessible using HTML5 attributes and/or JavaScript API. Take it for a spin in our [playground!](https://cocreate.app/docs/api) |
| 3 | +A dynamic, multi-tenant API execution gateway, proxy engine, and webhook orchestration routing layer. It securely manages distributed integration architectures, allowing applications to configure, evaluate, and execute complex third-party API configurations and multi-step macro workflows on the fly. By coupling an Abstract Syntax Tree (AST) evaluation sandbox (`NativeSandbox`) with strict tenant environmental isolation, it transforms declarative configurations into low-latency outbound integrations and secure inbound webhooks without introducing cross-tenant data leaks. |
4 | 4 |
|
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
| 5 | +--- |
11 | 6 |
|
12 | | - |
| 7 | +## Table of Contents |
13 | 8 |
|
14 | | -## [Docs & Demo](https://cocreate.app/docs/api) |
| 9 | +* [Features](https://www.google.com/search?q=%23features) |
| 10 | +* [Dynamic Operations Sandbox](https://www.google.com/search?q=%23dynamic-operations-sandbox) |
| 11 | +* [Installation](https://www.google.com/search?q=%23installation) |
| 12 | +* [Usage](https://www.google.com/search?q=%23usage) |
| 13 | +* [How it Works](https://www.google.com/search?q=%23how-it-works) |
| 14 | +* [Architecture and Payload Specs](https://www.google.com/search?q=%23architecture-and-payload-specs) |
| 15 | +* [Security Implementations](https://www.google.com/search?q=%23security-implementations) |
| 16 | +* [How to Contribute](https://www.google.com/search?q=%23how-to-contribute) |
| 17 | +* [License](https://www.google.com/search?q=%23license) |
15 | 18 |
|
16 | | -For a complete guide and working demo refer to the [doumentation](https://cocreate.app/docs/api) |
| 19 | +--- |
17 | 20 |
|
18 | | -## CDN |
| 21 | +## Features |
19 | 22 |
|
20 | | -```html |
21 | | -<script src="https://cdn.cocreate.app/api/latest/CoCreate-api.min.js"></script> |
22 | | -``` |
| 23 | +* **Abstract Syntax Tree (AST) Micro-Operators:** Evaluates functional configuration contexts inline, supporting expressive syntax tags (like `$data`, `$event`, `$actions`, and `$request`) along with custom business logic operators. |
| 24 | +* **Tenant Environmental Isolation Firewall:** Guarantees cryptographic data partitioning by intercepting execution matrices and forcefully injecting bound `organization_id` and verified `host` values into core operations. |
| 25 | +* **Real-Time WebSocket Integration Matrix:** Seamlessly hooks into live server networks (`wsManager`), listening for incoming `api` and `endpoint` actions and streaming real-time operational state payloads directly back to the client. |
| 26 | +* **Dual Outbound Execution Vectors:** Wire-speeds native, pre-constructed HTTP payloads instantly, or dynamically builds custom multi-step outbound integrations by resolving runtime metadata against persistence layers. |
| 27 | +* **Cryptographic Signatures & JWT Orchestration:** Features native, low-latency hooks to generate JSON Web Tokens (`$jwt`) using HMAC-SHA256, alongside timing-attack-safe webhook signature verification (`verifySignature`). |
| 28 | +* **Sealed AST Runtime Sandbox:** Features a hardened utility matrix containing sandboxed global objects (`JSON`, `Array`, `Math`) and helper methods (like Base64 encoding/decoding and URL encoders), safely wrapping calculations outside the global scope. |
| 29 | +* **Native Edge Stream Inspection:** Inspects active server response buffers automatically, failing back to a clean 200 OK only if macro pipelines didn't forcefully complete or close the stream. |
| 30 | + |
| 31 | +--- |
| 32 | + |
| 33 | +## Dynamic Operations Sandbox |
| 34 | + |
| 35 | +The engine evaluates standard properties and custom functional variables using a predefined sandbox layer. This allows configuration profiles to extract fields safely on the fly: |
| 36 | + |
| 37 | +| Core Operator Scope | Extracted Source Value | |
| 38 | +| --- | --- | |
| 39 | +| **`$data`** | Extracts standard key parameters from the active input execution payload (`data`). | |
| 40 | +| **`$event`** | Parses raw, incoming JSON parameters transmitted via active webhook streams. | |
| 41 | +| **`$actions`** | Exposes an array of historical execution artifacts from previous macro pipeline links. | |
| 42 | +| **`$request` / `$header**` | Exposes underlying HTTP request properties, methods, and incoming network parameters. | |
| 43 | +| **`$jwt`** | Triggers an active cryptographic signing loop, building a secure JWT token from properties. | |
| 44 | + |
| 45 | +--- |
| 46 | + |
| 47 | +## Installation |
| 48 | + |
| 49 | +```bash |
| 50 | +npm install @cocreate/api |
23 | 51 |
|
24 | | -```html |
25 | | -<script src="https://cdn.cocreate.app/api/latest/CoCreate-api.min.css"></script> |
26 | 52 | ``` |
27 | 53 |
|
28 | | -## NPM |
| 54 | +--- |
| 55 | + |
| 56 | +## Usage |
| 57 | + |
| 58 | +### Module Initialization |
| 59 | + |
| 60 | +Bind the API framework directly during the bootstrapping phase of your core `CoCreateServer` application matrix: |
| 61 | + |
| 62 | +```javascript |
| 63 | +import apiGateway from '@cocreate/api'; |
| 64 | +import { CoCreateServer } from '@cocreate/server'; |
| 65 | + |
| 66 | +// Boot the primary application server instance |
| 67 | +const serverContext = await CoCreateServer.start(); |
| 68 | + |
| 69 | +// Initialize the API engine and register WebSocket listeners |
| 70 | +await apiGateway.init(serverContext); |
29 | 71 |
|
30 | | -```shell |
31 | | -$ npm i @cocreate/api |
32 | 72 | ``` |
33 | 73 |
|
34 | | -## yarn |
| 74 | +### Direct Programmatic API Execution |
| 75 | + |
| 76 | +Execute complex third-party outbound macro operations using unified integration objects: |
| 77 | + |
| 78 | +```javascript |
| 79 | +import apiGateway from '@cocreate/api'; |
| 80 | + |
| 81 | +// The method identifies the provider credentials, and the endpoint resolves the data model |
| 82 | +const payload = { |
| 83 | + organization_id: "64b9a32e18f21bc56789abcd", |
| 84 | + method: "stripe", |
| 85 | + endpoint: "POST /v1/customers", |
| 86 | + stripe: { |
| 87 | + email: "$data.userEmail", |
| 88 | + metadata: { |
| 89 | + workspace: "production" |
| 90 | + } |
| 91 | + }, |
| 92 | + userEmail: "developer@cocreate.app" |
| 93 | +}; |
| 94 | + |
| 95 | +const result = await apiGateway.executeApi(payload); |
35 | 96 |
|
36 | | -```shell |
37 | | -$ yarn install @cocreate/api |
38 | 97 | ``` |
39 | 98 |
|
40 | | -# Table of Contents |
| 99 | +--- |
41 | 100 |
|
42 | | -- [Table of Contents](#table-of-contents) |
43 | | -- [Announcements](#announcements) |
44 | | -- [Roadmap](#roadmap) |
45 | | -- [How to Contribute](#how-to-contribute) |
46 | | -- [About](#about) |
47 | | -- [License](#license) |
| 101 | +## How it Works |
48 | 102 |
|
49 | | -<a name="announcements"></a> |
| 103 | +1. **Bootstrap & Event Binding:** During `init()`, the module hooks directly into the server's WebSocket framework (`wsManager`), capturing incoming `api` and `endpoint` event signals to route them to the execution handler. |
| 104 | +2. **Context and Firewall Initialization:** For every outbound execution, the engine evaluates the parameters against a parent context firewall. Security profiles match inbound connections against verified socket bounds, locking `organization_id` and `host` configurations. |
| 105 | +3. **Macro Configuration Resolving:** The engine sends queries through the CRUD synchronization layer to match configuration files against stored endpoints or active integration details inside the database collection. |
| 106 | +4. **AST Matrix Processing:** The router recursively scans headers, parameters, and bodies via `processOperators()`. Found strings matching active variables (e.g., `$` prefixes) are securely compiled in the isolated `NativeSandbox` environment. |
| 107 | +5. **Outbound Network Fetching:** The system builds the options profile, forcefully sets content headers, maps an `AbortController` timeout circuit breaker (15-second cutoff), and runs the task using the system runtime's native `fetch` framework. |
| 108 | +6. **Payload Delivery & Webhook Dispatching:** Webhook targets matching inbound edge rules check security values, run validation rules using timing-safe comparisons, execute steps sequentially, and output structural streams. |
50 | 109 |
|
51 | | -# Announcements |
| 110 | +--- |
52 | 111 |
|
53 | | -All updates to this library are documented in our [CHANGELOG](https://github.com/CoCreate-app/CoCreate-api/blob/master/CHANGELOG.md) and [releases](https://github.com/CoCreate-app/CoCreate-api/releases). You may also subscribe to email for releases and breaking changes. |
| 112 | +## Architecture and Payload Specs |
54 | 113 |
|
55 | | -<a name="roadmap"></a> |
| 114 | +### Unified Payload Object Schema |
56 | 115 |
|
57 | | -# Roadmap |
| 116 | +The data engine relies heavily on structural, flat parameter objects passed down into the execution chain: |
58 | 117 |
|
59 | | -If you are interested in the future direction of this project, please take a look at our open [issues](https://github.com/CoCreate-app/CoCreate-api/issues) and [pull requests](https://github.com/CoCreate-app/CoCreate-api/pulls). We would love to hear your feedback. |
| 118 | +| Field Element | Type | Role | |
| 119 | +| --- | --- | --- | |
| 120 | +| `organization_id` | `String` | **Required.** Targets the root tenant profile partition mapping to execution databases. | |
| 121 | +| `method` | `String` | **Required.** The provider identity string (e.g., `"stripe"`) used to fetch integration credentials. | |
| 122 | +| `endpoint` | `String` | **Required.** The operational HTTP verb and route mapping (e.g., `"POST /v1/customers"`) used to match configurations in the endpoints database. | |
| 123 | +| `[providerName]` | `Object` | The input context object named after your provider (e.g., `stripe: { ... }`) holding parameters processed by the AST engine. | |
60 | 124 |
|
61 | | -<a name="about"></a> |
| 125 | +### Context Engine Parameter Schema |
62 | 126 |
|
63 | | -# About |
| 127 | +The API processing network builds a dedicated execution block on every mutation cycle: |
64 | 128 |
|
65 | | -CoCreate-api is guided and supported by the CoCreate Developer Experience Team. |
| 129 | +| Field Element | Type | Role | |
| 130 | +| --- | --- | --- | |
| 131 | +| `data` | `Object` | Input variable parameters sent down from the parent action payload. | |
| 132 | +| `event` | `Object` | The compiled incoming request body extracted from active webhook pipelines. | |
| 133 | +| `actions` | `Array` | A running chronological memory matrix containing results of completed steps. | |
| 134 | +| `organization_id` | `String` | **Required.** Lockout identifier tracking root workspace context. | |
| 135 | +| `host` | `String` | The edge routing host domain verifying tenant environment isolation boundaries. | |
| 136 | +| `crud` / `wsManager` | `Object` | Bound links to internal database adapters and WebSocket server channels. | |
66 | 137 |
|
67 | | -Please Email the Developer Experience Team [here](mailto:develop@cocreate.app) in case of any queries. |
| 138 | +--- |
68 | 139 |
|
69 | | -CoCreate-api is maintained and funded by CoCreate. The names and logos for CoCreate are trademarks of CoCreate, LLC. |
| 140 | +## Security Implementations |
70 | 141 |
|
71 | | -<a name="contribute"></a> |
| 142 | +> [!WARNING] |
| 143 | +> To prevent config-driven cross-tenant data leaks or privilege escalations, parent context variables and authenticated socket bounds take absolute priority over raw incoming payload attributes. |
72 | 144 |
|
73 | | -# How to Contribute |
| 145 | +### Context Sandboxing |
74 | 146 |
|
75 | | -We encourage contribution to our libraries (you might even score some nifty swag), please see our [CONTRIBUTING](https://github.com/CoCreate-app/CoCreate-api/blob/master/CONTRIBUTING.md) guide for details. |
| 147 | +Local interface methods (such as direct actions on `crud` or `wsManager`) intercept arguments inside the execution layer. Even if a configuration profile passes a malicious tenant parameter inside an AST macro string, the sandbox engine explicitly overwrites the parameters on execution to align with the sealed context of the authenticated user. |
76 | 148 |
|
77 | | -We want this library to be community-driven, and CoCreate led. We need your help to realize this goal. To help make sure we are building the right things in the right order, we ask that you create [issues](https://github.com/CoCreate-app/CoCreate-api/issues) and [pull requests](https://github.com/CoCreate-app/CoCreate-api/pulls) or merely upvote or comment on existing issues or pull requests. |
| 149 | +### Timing-Safe Signature Verification |
78 | 150 |
|
79 | | -We appreciate your continued support, thank you! |
| 151 | +Inbound webhook channels configured with `authenticate` properties execute validation algorithms using a cryptographically secure fixed-time comparison script (`crypto.timingSafeEqual`). This completely mitigates timing-attack vectors targeting system endpoints. |
80 | 152 |
|
81 | | -<a name="license"></a> |
| 153 | +--- |
82 | 154 |
|
83 | | -# License |
| 155 | +## How to Contribute |
84 | 156 |
|
85 | | -This software is dual-licensed under the GNU Affero General Public License version 3 (AGPLv3) and a commercial license. |
| 157 | +We encourage contribution to our libraries (you might even score some nifty swag), please see our [CONTRIBUTING.md](https://cocreatejs.com/docs/api/contributing) guide for details. We want this library to be community-driven, and CoCreate led. We need your help to realize this goal. |
86 | 158 |
|
87 | | -- **Open Source Use**: For open-source projects and non-commercial use, this software is available under the AGPLv3. The AGPLv3 allows you to freely use, modify, and distribute this software, provided that all modifications and derivative works are also licensed under the AGPLv3. For the full license text, see the [LICENSE file](https://github.com/CoCreate-app/CoCreate-api/blob/master/LICENSE). |
| 159 | +--- |
88 | 160 |
|
89 | | -- **Commercial Use**: For-profit companies and individuals intending to use this software for commercial purposes must obtain a commercial license. The commercial license is available when you sign up for an API key on our [website](https://cocreate.app). This license permits proprietary use and modification of the software without the copyleft requirements of the AGPLv3. It is ideal for integrating this software into proprietary commercial products and applications. |
| 161 | +## License |
| 162 | + |
| 163 | +This software is dual-licensed under the GNU Affero General Public License version 3 (AGPLv3) and a commercial license. |
90 | 164 |
|
91 | | -If you have not purchased a commercial license and intend to use this software for commercial purposes, you are required to sign up for an API key on our website. |
| 165 | +* **Open Source Use:** For open-source projects and non-commercial use, this software is available under the AGPLv3. For the full license text, see the LICENSE file. |
| 166 | +* **Commercial Use:** For-profit companies and individuals intending to use this software for commercial purposes must obtain a commercial license. The commercial license is available when you sign up for an API key on our website. |
0 commit comments