@inboxychat/sdk 0.1.0 → 0.2.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/README.md CHANGED
@@ -1,10 +1,29 @@
1
- # @inboxychat/sdk — read-only client for the Inboxy public API v1
1
+ # @inboxychat/sdk — scoped Inboxy client
2
2
 
3
- Used by `@inboxychat/mcp` and `@inboxychat/cli`. Local package, not published.
3
+ Published on npm as [`@inboxychat/sdk`](https://www.npmjs.com/package/@inboxychat/sdk); also used by
4
+ `@inboxychat/mcp` and `@inboxychat/cli`. Full guide (English and Arabic):
5
+ https://inboxy.chat/developers/sdk
6
+
7
+ ```bash
8
+ npm i @inboxychat/sdk # Node.js 20.3+, ESM only
9
+ ```
10
+
11
+ ```ts
12
+ import { InboxyClient, collectPages } from '@inboxychat/sdk';
13
+
14
+ const inboxy = new InboxyClient({ apiKey: process.env.INBOXY_API_KEY! });
15
+ const { data: me } = await inboxy.getCompany();
16
+ const orders = await inboxy.listOrders({ status: 'pending', limit: 5 });
17
+ const { items } = await collectPages((q) => inboxy.listContacts(q), { limit: 100 }, 20);
18
+ ```
19
+
20
+ Create the key in the Inboxy dashboard as a company admin (Developers → API,
21
+ `/developer-center/api`), with only the scopes you need. Keep it on the server; never ship
22
+ it to a browser.
4
23
 
5
24
  - `InboxyClient`: one GET method per route in `PUBLIC_ROUTES` (the same list as
6
25
  `PUBLIC_API_V1_ROUTES` in `apps/api/src/modules/api-public/api-public.contract.ts`).
7
- No write methods, no company parameter, HTTPS only (http for localhost),
26
+ No company parameter, HTTPS only (http for localhost),
8
27
  redirects refused, per-request timeout and `AbortSignal`.
9
28
  - `InboxyError`: `kind` (`auth`, `forbidden`, `not_found`, `rate_limited`,
10
29
  `invalid_request`, `server`, `timeout`, `cancelled`, `network`,
@@ -21,3 +40,73 @@ against them, so a change on either side fails a test.
21
40
  ```bash
22
41
  pnpm --filter @inboxychat/sdk test
23
42
  ```
43
+
44
+ ## Audited operation adapters
45
+
46
+ This source version adds 80 operations through `describeOperations()`,
47
+ `prepareOperation(id, input, idempotencyKey)` and `client.executeOperation(...)`.
48
+ The eleven public read methods remain compatible. The operation catalog covers
49
+ contact create/update; task list/get/create/update/assign/complete; ticket
50
+ list/get/create/update/assign/close/internal-note; AI employee list/get/draft,
51
+ configuration/test/readiness/explicit publication; campaign list/get/draft.
52
+
53
+ ```ts
54
+ import { prepareOperation } from '@inboxychat/sdk';
55
+ const input = { body: { title: 'Call customer tomorrow' } };
56
+ const idempotencyKey = crypto.randomUUID();
57
+ const preview = prepareOperation('tasks.create', input, idempotencyKey);
58
+ // Display preview (including warnings) and obtain the user's explicit approval.
59
+ const result = await inboxy.executeOperation('tasks.create', input, {
60
+ idempotencyKey, confirmation: preview.confirmation,
61
+ });
62
+ ```
63
+
64
+ Every mutation requires its exact normalized preview hash and an idempotency key.
65
+ The hash binds the operation, fields and key; it is a consistency guard, not proof
66
+ of human consent. The caller must collect approval. A changed request requires a
67
+ new preview. Retain the key when recovering an uncertain outcome; never create a
68
+ new key merely because a request timed out. There are no automatic retries.
69
+ Server scope, tenant, current role, plan and feature gates remain authoritative.
70
+ AI tests may use credits; publication enables live replies and may replace the
71
+ employee on selected channels. Campaign creation omits all scheduling fields and
72
+ creates a draft. Ticket notes are forced internal. No arbitrary URL/body proxy, company override, entity deletion, billing or admin operation is exposed. One text send is available only through explicit recipient/channel/content approval.
73
+
74
+ `API_ROUTE_INVENTORY` is generated discovery metadata for 553 API-token routes;
75
+ it does not make those routes executable. Actual full UI parity is **not** claimed.
76
+ Remaining adapter classes include media/template/bulk sends, channel OAuth, order
77
+ cancellation/refunds, advanced commerce/catalog operations, flows/automation, URL/file
78
+ knowledge ingestion, expanded analytics, webhook/token management, billing and admin.
79
+ They need separate schemas, consent/effect review and tests.
80
+
81
+ After intentional server/catalog changes, run
82
+ `node packages/inboxy-sdk/scripts/generate-operations.mjs` from the repository root.
83
+ The contract test checks method/path/scope and generated-file drift. This is source
84
+ implementation, not evidence that the npm release or hosted service is deployed.
85
+
86
+
87
+ ### Expanded operation coverage
88
+
89
+ The source catalog now has 80 operations (553 discovery routes). Added inbox
90
+ assignment/status/labels/internal notes; separate one-message text sending;
91
+ reviewed AI text knowledge and channel assignments; manual orders, state/payment/
92
+ fulfillment records; product/category creation and updates. Inspect the catalog
93
+ for exact schemas. Media/templates/bulk sends, scheduling, order cancellation/
94
+ refunds, URL/file knowledge ingestion and complete automation coverage remain out
95
+ of scope. Orders may trigger configured automation; payment-record changes do not
96
+ charge a payment provider.
97
+
98
+ For a send, preview `inbox.message.send` with `conversationId`, `target` containing
99
+ `contactId`, `channelId`, `channelType` (uppercase enum), and `body.content`.
100
+ Inspect the conversation first and approve the exact recipient, channel and full
101
+ text. CLI uses `messages send --input <same-json> --idempotency-key <same-key>
102
+ --confirm <hash>`; MCP uses the separate `message_send` tool with identical input,
103
+ idempotencyKey and confirmation. Generic operation execution in CLI/MCP refuses
104
+ sends. The SDK dispatch includes a confirmed-target header, validated against the
105
+ current tenant conversation before send; a mismatch requires a new inspection and
106
+ approval. Stable clientMessageId supplements the existing idempotency middleware.
107
+
108
+ The lifecycle slice adds contact status/stage/assignment/internal notes, tag management and bounded flat custom-field replacement. It adds automation graph/run inspection, inactive draft creation and pause, plus campaign audience estimation, pause and cancel. Tag changes may trigger configured automations. Automation graph editing/publish remain unavailable; a preview estimate does not authorize scheduling.
109
+
110
+ Workflow activation: first execute `automations.activation.preview`, show the entire returned preview, then pass it unchanged as `body.approval` to `automations.activate` with an exact confirmation and idempotency key. The server rechecks tenant, published version/hash, complete preview and workflow revision in a transaction. MCP uses `lifecycle_activate`; CLI uses `lifecycle activate <operation>`. The generic operation runner refuses activate effects, including AI publish/channel changes. `automations.simulate` uses existing dry services and skips external side effects.
111
+
112
+ Campaign delivery uses `campaigns.approval` to resolve a complete snapshot (audience, sender, template/content, limits and exact time). Pass that unchanged in `body.approval` to `campaigns.send`, `campaigns.resume` or `campaigns.schedule`, preview locally, then obtain explicit approval. MCP requires `campaign_send` or `campaign_schedule`; CLI requires `campaigns send <operation>` or `campaigns schedule`. The server freezes approval and checks it again before delivery. These actions can send real customer messages and consume budget. Keep the same idempotency key for recovery. Version 0.2.0 is prepared locally; publication and API deployment are separate release steps.