@cocreate/api 1.34.0 → 2.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/.github/FUNDING.yml +1 -1
- package/.github/workflows/automated.yml +18 -7
- package/CHANGELOG.md +635 -595
- package/CONTRIBUTING.md +6 -6
- package/README.md +6 -6
- package/demo/index.html +1 -1
- package/docs/form.html +7 -7
- package/docs/index.html +8 -8
- package/docs/module.html +6 -6
- package/docs/server.html +7 -7
- package/package.json +5 -5
- package/src/client.js +197 -0
- package/src/server.js +32 -0
package/src/server.js
CHANGED
|
@@ -44,6 +44,8 @@ const API = {
|
|
|
44
44
|
* @param {Object} Server - Core server instance containing CRUD and, later, a socket manager on workers.
|
|
45
45
|
* @param {Object} Server.crud - Database CRUD service operator.
|
|
46
46
|
* @returns {Promise<Object>} Exported API interface.
|
|
47
|
+
* @public
|
|
48
|
+
* @environment server
|
|
47
49
|
*/
|
|
48
50
|
export async function init(Server) {
|
|
49
51
|
server = Server;
|
|
@@ -59,6 +61,8 @@ export async function init(Server) {
|
|
|
59
61
|
* @param {string} orgId - Multi-tenant organization identifier.
|
|
60
62
|
* @param {string} host - Host domain identifier.
|
|
61
63
|
* @returns {Proxy|undefined} Proxied target service with auto-injected tenant parameters, or undefined if target is falsy.
|
|
64
|
+
* @private
|
|
65
|
+
* @environment server
|
|
62
66
|
*/
|
|
63
67
|
function createTenantProxy(target, orgId, host) {
|
|
64
68
|
if (!target) return undefined;
|
|
@@ -96,6 +100,8 @@ function createTenantProxy(target, orgId, host) {
|
|
|
96
100
|
* @param {string} context.organization_id - Target multi-tenant organization ID.
|
|
97
101
|
* @param {string} context.host - Target host domain.
|
|
98
102
|
* @returns {Object} Secure AST execution sandbox object containing firewalled utilities.
|
|
103
|
+
* @private
|
|
104
|
+
* @environment server
|
|
99
105
|
*/
|
|
100
106
|
function createSandbox(context) {
|
|
101
107
|
const isPlatformOrg = server?.organization_id && (context.organization_id === server.organization_id);
|
|
@@ -129,6 +135,11 @@ function createSandbox(context) {
|
|
|
129
135
|
host: context.host,
|
|
130
136
|
|
|
131
137
|
api: {
|
|
138
|
+
/**
|
|
139
|
+
*
|
|
140
|
+
* @public
|
|
141
|
+
* @environment server
|
|
142
|
+
*/
|
|
132
143
|
send: (apiData) => send(apiData, context)
|
|
133
144
|
}
|
|
134
145
|
};
|
|
@@ -178,6 +189,8 @@ function createSandbox(context) {
|
|
|
178
189
|
* @param {Object|null} [parentContext=null] - Outer sandbox execution context when nested.
|
|
179
190
|
* @returns {Promise<Object>} The mutated execution envelope, with response content assigned to `data.data`.
|
|
180
191
|
* @throws {Error} If required directives are missing, provider configuration is invalid, or HTTP dispatch fails.
|
|
192
|
+
* @public
|
|
193
|
+
* @environment server
|
|
181
194
|
*/
|
|
182
195
|
export async function send(data, parentContext = null) {
|
|
183
196
|
try {
|
|
@@ -360,6 +373,8 @@ export async function send(data, parentContext = null) {
|
|
|
360
373
|
* @param {Object} req - Native Node.js HTTP incoming request stream.
|
|
361
374
|
* @param {Object} res - Native Node.js HTTP server response stream.
|
|
362
375
|
* @returns {Promise<void>}
|
|
376
|
+
* @public
|
|
377
|
+
* @environment server
|
|
363
378
|
*/
|
|
364
379
|
export async function webhook(req, res) {
|
|
365
380
|
try {
|
|
@@ -453,6 +468,8 @@ export async function webhook(req, res) {
|
|
|
453
468
|
* @param {number} [options.timeout=15000] - Timeout threshold in milliseconds before aborting.
|
|
454
469
|
* @returns {Promise<Response>} Native fetch Response instance.
|
|
455
470
|
* @throws {Error} Throws HTTP error status or network timeout error.
|
|
471
|
+
* @public
|
|
472
|
+
* @environment server
|
|
456
473
|
*/
|
|
457
474
|
export async function makeHttpRequest(url, options) {
|
|
458
475
|
const controller = new AbortController();
|
|
@@ -543,6 +560,8 @@ async function parseResponseData(response) {
|
|
|
543
560
|
* @param {string} name - API provider identifier (e.g., 'stripe', 'openai', 'twilio').
|
|
544
561
|
* @returns {Promise<Object>} Standardized API configuration object containing key, url, and headers.
|
|
545
562
|
* @throws {Error} If organization mapping fails or integration settings do not exist.
|
|
563
|
+
* @public
|
|
564
|
+
* @environment server
|
|
546
565
|
*/
|
|
547
566
|
export async function getApiConfig(data, name) {
|
|
548
567
|
let { organization_id: orgId, host } = data || {};
|
|
@@ -577,3 +596,16 @@ export async function getApiConfig(data, name) {
|
|
|
577
596
|
export default {
|
|
578
597
|
init
|
|
579
598
|
};
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Default export contract for this module.
|
|
602
|
+
*
|
|
603
|
+
* @name api-default-export
|
|
604
|
+
* @kind member
|
|
605
|
+
* @default-export
|
|
606
|
+
* @environment server
|
|
607
|
+
* @example
|
|
608
|
+
* ```json
|
|
609
|
+
* "{ init }"
|
|
610
|
+
* ```
|
|
611
|
+
*/
|