@cocreate/api 2.1.0 → 2.1.2

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/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## [2.1.2](https://github.com/CoCreateJS/api/compare/v2.1.1...v2.1.2) (2026-11-07)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * bump CoCreate dependency versions ([b17916d](https://github.com/CoCreateJS/api/commit/b17916d4ca86702dc6359f1a241e5be6c2ef00d2))
7
+ * consolidate CRUD client and server packages ([87bee2c](https://github.com/CoCreateJS/api/commit/87bee2cd56a55c29cf01c8be36941651b8a1dcb8))
8
+
9
+ ## [2.1.1](https://github.com/CoCreateJS/api/compare/v2.1.0...v2.1.1) (2026-11-07)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * complete unified socket package migration ([3dc2f13](https://github.com/CoCreateJS/api/commit/3dc2f136b9745b4f1b95b65bc477a611ec91c8e0))
15
+ * preserve socket data in API responses ([0668a04](https://github.com/CoCreateJS/api/commit/0668a0477ef1332b2debb374ca175b471dc94503))
16
+ * route API replies through server send ([a092f17](https://github.com/CoCreateJS/api/commit/a092f17cb3cd39a2c9bb05a07175d375b7aae162))
17
+ * route component responses through unified server send ([7bc2168](https://github.com/CoCreateJS/api/commit/7bc2168d79a36eced19bc5d2447e11bab37113a4))
18
+
1
19
  # [2.1.0](https://github.com/CoCreateJS/api/compare/v2.0.0...v2.1.0) (2026-11-05)
2
20
 
3
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/api",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "A secure, multi-tenant API execution gateway and proxy layer that dynamically resolves endpoint actions, processes AST micro-operators, handles webhooks, and manages third-party integrations with strict tenant environment isolation.",
5
5
  "keywords": [
6
6
  "api-orchestration",
@@ -51,14 +51,14 @@
51
51
  }
52
52
  },
53
53
  "dependencies": {
54
- "@cocreate/actions": "^2.0.0",
55
- "@cocreate/crud-client": "^2.0.0",
56
- "@cocreate/element-prototype": "^2.0.0",
57
- "@cocreate/render": "^2.0.0",
58
- "@cocreate/socket-client": "^2.0.0",
59
- "@cocreate/utils": "^2.0.0"
54
+ "@cocreate/actions": "^2.0.1",
55
+ "@cocreate/crud": "^0.0.0-stage",
56
+ "@cocreate/element-prototype": "^2.0.1",
57
+ "@cocreate/render": "^2.0.1",
58
+ "@cocreate/utils": "^2.0.2",
59
+ "@cocreate/socket": "^3.0.0"
60
60
  },
61
61
  "devDependencies": {
62
- "@cocreate/webpack": "^2.0.0"
62
+ "@cocreate/webpack": "^2.0.1"
63
63
  }
64
64
  }
package/src/client.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*globals CustomEvent, config*/
2
2
  import { getValueFromObject, dotNotationToObject } from "@cocreate/utils";
3
3
  import Observer from "@cocreate/observer";
4
- import Socket from "@cocreate/socket-client";
4
+ import { SocketClient as Socket } from "@cocreate/socket";
5
5
  import Actions from "@cocreate/actions";
6
6
  import { render } from "@cocreate/render";
7
7
  import "@cocreate/element-prototype";
package/src/server.js CHANGED
@@ -31,6 +31,11 @@ import {
31
31
  let server = null;
32
32
  let crud = null;
33
33
 
34
+ function sendToServer(data) {
35
+ const envelope = { ...data };
36
+ return server.send(envelope);
37
+ }
38
+
34
39
  const API = {
35
40
  send,
36
41
  http,
@@ -107,7 +112,7 @@ function createTenantProxy(target, orgId, host) {
107
112
  function createSandbox(context) {
108
113
  const isPlatformOrg = server?.organization_id && (context.organization_id === server.organization_id);
109
114
  const secureCrud = createTenantProxy(context.crud, context.organization_id, context.host);
110
- const secureWs = createTenantProxy(context.wsManager, context.organization_id, context.host);
115
+ const secureWs = createTenantProxy({ send: payload => server.send(payload) }, context.organization_id, context.host);
111
116
 
112
117
  const sandbox = {
113
118
  // Provider fields are configuration variables. For example, a
@@ -184,7 +189,6 @@ function createSandbox(context) {
184
189
  * @param {Object} [data.searchParams] - Query parameters appended to the request URL.
185
190
  * @param {Object} [data.headers] - Custom HTTP header directives.
186
191
  * @param {number} [data.timeout=15000] - Request timeout in milliseconds.
187
- * @param {Object} [data.socket] - WebSocket client reference for real-time response emit.
188
192
  * @param {string} [data.organization_id] - Multi-tenant organization identifier.
189
193
  * @param {string} [data.host] - Target host domain.
190
194
  * @param {Object|null} [parentContext=null] - Outer sandbox execution context when nested.
@@ -196,8 +200,8 @@ function createSandbox(context) {
196
200
  export async function send(data, parentContext = null) {
197
201
  try {
198
202
  const wsManager = server?.wsManager;
199
- const orgId = parentContext?.organization_id || data.socket?.organization_id || data.organization_id;
200
- const host = parentContext?.host || data.socket?.host || data.host;
203
+ const orgId = parentContext?.organization_id || data.organization_id;
204
+ const host = parentContext?.host || data.host;
201
205
 
202
206
  const apiName = data.api?.trim() || "";
203
207
  const endpoint = data.endpoint?.trim() || "";
@@ -298,9 +302,7 @@ export async function send(data, parentContext = null) {
298
302
 
299
303
  if (request.resolved) {
300
304
  data.data = request.data
301
- if (data.socket && wsManager) {
302
- wsManager.send(data);
303
- }
305
+ sendToServer(data);
304
306
  return data;
305
307
  }
306
308
 
@@ -343,9 +345,7 @@ export async function send(data, parentContext = null) {
343
345
  const response = await makeHttpRequest(url, options);
344
346
  data.data = await parseResponseData(response);
345
347
 
346
- if (data.socket && wsManager) {
347
- wsManager.send(data);
348
- }
348
+ sendToServer(data);
349
349
  return data;
350
350
  } catch (error) {
351
351
  const wsManager = server?.wsManager;
@@ -359,11 +359,8 @@ export async function send(data, parentContext = null) {
359
359
  data.statusText = error.response.statusText;
360
360
  data.responseData = error.response.data;
361
361
  }
362
- if (data.socket && wsManager) {
363
- wsManager.send(data);
364
- return data;
365
- }
366
- throw error;
362
+ sendToServer(data);
363
+ return data;
367
364
  }
368
365
  }
369
366
 
@@ -0,0 +1,47 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { init, send } from '../src/server.js';
4
+
5
+ test('API responses and errors enter server.send instead of raw socket delivery', async t => {
6
+ const sent = [];
7
+ await init({ organization_id: 'platform', crud: {},
8
+ send: data => { sent.push(data); return data; },
9
+ wsManager: { send() { assert.fail('API must use server.send'); } } });
10
+ t.mock.method(globalThis, 'fetch', async () => new Response('{"ok":true}', { headers: { 'content-type': 'application/json' } }));
11
+ const data = { method: 'get', url: 'https://example.test', organization_id: 'tenant',
12
+ socketId: 'trusted-socket', clientId: 'trusted-client', host: 'tenant.test',
13
+ socket: { organization_id: 'forged-org', host: 'forged.test' } };
14
+ assert.equal(await send(data), data);
15
+ assert.deepEqual(data.data, { ok: true });
16
+ assert.notEqual(sent[0], data);
17
+ assert.equal(sent[0].socket, data.socket);
18
+ assert.equal(sent[0].socketId, 'trusted-socket');
19
+ assert.equal(sent[0].clientId, 'trusted-client');
20
+ const missing = { organization_id: 'tenant', host: 'tenant.test' };
21
+ assert.equal(await send(missing), missing);
22
+ assert.match(missing.error[0], /endpoint.*url/);
23
+ assert.equal(sent[1].socket, undefined);
24
+ assert.equal(sent[1].organization_id, 'tenant');
25
+ });
26
+
27
+ test('API AST socket operators retain tenant scope while entering server.send', async () => {
28
+ const sent = [];
29
+ await init({ organization_id: 'platform',
30
+ crud: { send: async request => ({ object: request.array === 'apis'
31
+ ? [{ _id: 'provider', url: 'https://example.test' }]
32
+ : [{ resolved: true, data: { '$socket.send': { method: 'notification', organization_id: 'forged', host: 'forged' } } }] }) },
33
+ send: data => { sent.push({ ...data }); return data; },
34
+ wsManager: { send() { assert.fail('AST must use server.send'); } } });
35
+ const data = { method: 'post', api: 'provider', endpoint: 'notify', organization_id: 'tenant',
36
+ socketId: 'trusted-socket', clientId: 'trusted-client', host: 'tenant.test',
37
+ socket: { organization_id: 'forged-org', host: 'forged.test' } };
38
+ await send(data);
39
+ assert.equal(data.error, undefined);
40
+ assert.equal(sent[0].method, 'notification');
41
+ assert.equal(sent[0].organization_id, 'tenant');
42
+ assert.equal(sent[0].host, 'tenant.test');
43
+ assert.equal(sent[0].socket, undefined);
44
+ assert.equal(sent[1].socket, data.socket);
45
+ assert.equal(sent[1].socketId, 'trusted-socket');
46
+ assert.equal(sent.length, 2);
47
+ });