@intelligence-cloud/sdk 0.1.1 → 0.3.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/CHANGELOG.md CHANGED
@@ -1,5 +1,93 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0 (2026-12-01)
4
+
5
+ The TypeScript SDK matches the Python reference for 0.3.0.
6
+
7
+ ### What changed for callers
8
+
9
+ - **Bad input never reaches the network.** Every helper of `client.accounts` and `client.conversations` checks its arguments, types included, before it signs in or sends anything. A 40-day window, `limit: 500` or `alerts({ status })` throw `InvalidRequestError` with no request made, even with the network down, and cost no sign-in. `teams`, `userIds` and `phrases` may be any iterable and are read once.
10
+ - **Token renewal never resends a refresh token that may have been used.** It is sent again only after a 429 or a failure where the request provably never left this machine; after a 5xx, a failure after the request left, or an unreadable answer the client signs in instead. Sending a used refresh token ends every session of the login. Which `fetch` failures count as "never left" is written in the README ("Retries"): the codes `ENOTFOUND`, `EAI_AGAIN`, `ECONNREFUSED`, `ENETUNREACH`, `EHOSTUNREACH`, `UND_ERR_CONNECT_TIMEOUT`, `ERR_INVALID_URL` and the TLS certificate refusals; everything else may have left.
11
+ - **`new Client({ deadline: 120 })`** bounds one API request, with its sign-in, renewal, retries and waits; when the time left cannot cover the next wait it stops at once (`RateLimitError`, `NetworkError` kind `"timeout"`, or the last 5xx). Each attempt is aborted after `timeout` or the time left. `clock` and `sleep` replace the clock and the wait in tests.
12
+ - **One retry policy, written down** (README "Retries"). 0.2.0 did not retry sign-in at all: network failures and 5xx are now retried on sign-in too, and on token renewal when the request never left. A 429 whose `Retry-After` is longer than the wait limit throws `RateLimitError` at once with `retryAfter` (a sign-in 429 with `Retry-After: 120` used to wait 60 seconds and then fail). User creation keeps retrying with its idempotency key.
13
+ - **One error tree in every SDK language** (README "Errors"). New `NetworkError` (an `ApiError` with status 0; `kind`, `requestSent`; the underlying error is not attached). `ConnectorTimeoutError` is a `ConnectorError`; `FrontlineRequiredError` is a `WrongLoginError`. `AccountError.find(ErrorClass)` returns the first error of that class in the cause chain: a clashing line is `AccountError` → `ExtensionMappingError` → `ConflictError`. `AccountError<T>` carries the helper's result type.
14
+ - **Events: store by call id and upsert.** A later After Call delivery for the same call can carry newer data. `Deduplicator.seen(event)` only checks whether this exact delivery (event type, location, call id and the SHA-256 of the canonical JSON body) was remembered; `Deduplicator.remember(event)` records it and is called after your durable write, so a delivery whose storage failed is processed when it is retried. Both take an event, a parsed body or the raw body; a plain id is refused. `upsertKey(event)` (also `Deduplicator.upsertKey`) returns the call id (or alert id) to store under. The keys are the same text as the Python SDK's for the same event. The README receiver sections and the Next.js examples follow this order: parse, answer 2xx if seen, upsert, remember, answer 2xx; on a storage failure answer 5xx without remembering.
15
+ - **First Alert payload is not final.** `parseFirstAlertEvent` accepts any id of letters, digits, `-` and `_` up to 128 characters, kept as sent (it used to accept only UUIDs and lower-case them); the first of `alert_id`, `alert.id`, `id` that is present decides, and a top-level `alert_id` that is not a string is an error; `raw` holds the whole payload.
16
+ - **`@intelligence-cloud/sdk/testing`**: a supported fake API for your tests and CI (ESM and CommonJS, with types; not part of the main bundle). `FakeAPI.client({ role })`, fictional seed data (`seedCustomer`, `seedCalls`), failure knobs (`connectorOutcome`, `failNext` for each HTTP and network failure, `failWrite`, `networkDown`, `rateLimit`, `expireAccessTokens`), a request log and `authLog`, refresh-token reuse that ends every session as on the platform, and strict refusal of requests the published spec does not define, including query value types, enums and formats, and the JSON types of top-level body fields. README "Testing your code" lists the whole supported surface and its examples run as a test.
17
+ - **Review round: stricter and safer.** A path argument of `..`, `.` or one with `/`, `\\`, `?`, `#`, `%`, whitespace or a control character, or over 128 characters, is refused before any request (a `..` used to rewrite the URL). Free text and numbers must be real strings of at most 200 characters. Delivery keys hash the RFC 8785 (JSON Canonicalization Scheme) text of the projected event; lone surrogates, repeated object keys, non-UTF-8 bytes and non-finite numbers are refused (also by both parsers); integers beyond 2^53 collapse by rule. The After Call parser refuses exactly a missing or wrongly typed required field. Retry-After counts only as `[0-9]{1,9}(.[0-9]+)?` seconds. A failed `fetch` counts as "never left" only when its errno code comes with `syscall` `connect` or `getaddrinfo`. Account helpers refuse a bad argument before they join the write queue. A Customer object is checked against one live read of the company's locations (and re-read in full, in place, when it differs), group and rule ids come from a live listing of each team a helper uses them on, a Customer carrying another company's location is refused, and `Customer.refreshedAt` says when it was last checked. Every error class carries a `Symbol.for` brand, so `instanceof` works between the ESM and CommonJS copies of the package. `@intelligence-cloud/sdk/testing` type-checks under `moduleResolution` node, node16 and bundler (`typesVersions`). The fake: formats and enums are checked as the spec states them (`netsapiens` is the only connector type), `failNext` answers before the platform acts unless `afterProcessing: true`, the request log and every printed form mask keys and passwords. Request counts for a Customer object grow by the live reads (the table in the README).
18
+ - **Final check.** Helpers that write check for the groups they need on a live listing before their first write (`addBaseManager`, `addIntegrationUser`, `changeLicense` to a Base Manager, `moveUser` of a manager, `setAlerts`), as in Python: a missing group is an `InvalidRequestError` with no write. Unknown events are keyed `unknown:<hash>`. Bodies nested more than 64 levels, and `call.id`, `location_id` and alert ids that are not plain ids, are refused (nothing is trimmed). The path pattern refuses C1 controls and U+FEFF and counts code points. Every top-level body field is type-checked against the spec before sending (enums are left to the API, so a new connector type needs no SDK release). Sign-in is not retried after a failure that may have left. A deadline with less than 5 ms left stops before sending. The fake masks webhook paths in its log and reads `2.5e1` as a float.
19
+ - **Closing round.** Request counts equal the Python SDK's in every row (no connector-type list read before a connector write, a team read in the same call is not listed again, `licenseReport` reads the location list once); a connector type no list names is passed to the API, which judges it. Shared vectors version 3 (six files) are asserted entry by entry, including path arguments; a body that carries a bad `alert_id` is refused, not treated as an unknown event.
20
+ - **Connect failures.** A refused connection to `localhost` (Node's AggregateError, whose attempts carry the syscall) is now read as "never left": `requestSent` is false, sign-in is retried and a refresh token is sent again. The fake's `failNext({ network })` kinds produce the error shapes Node's fetch gives (connect: ECONNREFUSED with syscall connect; read_timeout: HeadersTimeoutError; write_timeout: SocketError; new `reset`: ECONNRESET). The README says the samples use top-level `await`.
21
+ - **Developer round (ported from the Python SDK).** Testing module: `client({ asUser })` signs in as a seeded person (calls, alerts, tasks and Insights Hub follow their license and teams; two clients for one login share its sessions), `seedCustomer()` returns `people`, `seedCalls({ recording, topics })`, `connectorOutcome` applies to connection attempts made after it is set, `settleConnector`, `failNext({ signIn })`, `requests` logs every request with its `answer`, `authLog` logs every sign-in and renewal attempt, non-strict mode lets an unlisted connector type through. Lines must be the whole value `\+?[0-9*#]{1,32}`. `addBaseUser` and `addBaseManager` report all of the person's teams. `conversations.teams()` lists teams first (name order) and Management last. `isOlder(event, stored)` and the receiver flow parse, seen, compare, upsert, remember (equal timestamps: the later arrival wins). A connector found still settling when a helper runs again is checked again and restarted once. The result types are also exported under the Python names (`AlertActivation`, `NoManagerTeam`, `LineSyncReport`, `TeamLines`, `LineDiff`, `RemovalSummary`, `OffboardSummary`). README: "Upgrading from 0.2", `sleep` and `clock` as test hooks, `setAlerts` and the ten-team total in the request table. Shared vectors version 4: `fake_behaviour_vectors.json` (21 scenarios) and `line_vectors.json`.
22
+ - Connector waits count the check intervals as well as the clock, so a replaced `sleep` (tests) cannot spin for the whole timeout.
23
+ - README: "Retries" with worst-case blocking time and the fetch failure mapping, "Testing your code", "Running helpers from more than one process" (with Node recipes), "How many requests" (pinned by a test, the same numbers as the Python SDK), the error tree, the examples table. SDK documentation links point to the SDK pages (https://docs.intelligence.cloud/sdk/, /sdk/quick-start, /sdk/reference, /sdk/events, /sdk/configuration, /sdk/downloads, /sdk/testing); API links stay https://docs.intelligence.cloud/api and https://docs.intelligence.cloud/reference. The examples ship in the source download, not the npm package, and the README says so.
24
+ - Examples use one fictional customer, Riverbend Auto Group, and the variables `IC_ADMIN_EMAIL` / `IC_ADMIN_PASSWORD` and `IC_USER_EMAIL` / `IC_USER_PASSWORD`. `examples/node/create-customer.mjs` read a result field that does not exist (`skipped`); it now reads `noManager`.
25
+ - `Conversations.window()` is marked internal.
26
+
27
+ ### Breaking changes
28
+
29
+ | 0.2.0 | 0.3.0 |
30
+ |---|---|
31
+ | `Deduplicator.isDuplicate(id)` (and `seen(id)`) checked and recorded in one call, keyed on the call id | Removed, with no alias: `seen(event)` checks, `remember(event)` records after your write. A plain id throws `InvalidRequestError` |
32
+ | A custom `DedupStore` had `checkAndAdd(key)` | It needs `has(key)` and `add(key)` (both may be async) |
33
+ | `ConnectorTimeoutError` was not a `ConnectorError` | It is: a `catch` on `ConnectorError` now catches timeouts too (test `ConnectorTimeoutError` first to tell them apart) |
34
+ | `FrontlineRequiredError` derived from `IntelligenceCloudError` only | It is a `WrongLoginError` |
35
+ | A network failure threw `ApiError` (status 0) holding the underlying error as `cause` | It throws `NetworkError` (still an `ApiError`, status 0) with no `cause` |
36
+ | Sign-in was not retried | Network failures and 5xx are retried on sign-in |
37
+ | No overall time limit | `deadline: 120` seconds per API request (sign-in, renewal, retries and waits included); raise it for long Retry-After waits |
38
+ | A sign-in 429 always waited `loginRateLimitWait` once | It waits only when `Retry-After` fits in that limit; otherwise it throws at once |
39
+ | A refresh was retried after a 5xx or any network failure | Only after a 429 or a failure where the request never left |
40
+ | A path argument could be any string (`..` rewrote the URL) | Ids of at most 128 characters without `/`, `?`, `#`, `%`, whitespace, and not `.` or `..` |
41
+ | Delivery keys hashed a JavaScript-specific canonical text | The RFC 8785 text of the projected event (the same key in every SDK language); non-I-JSON bodies are refused |
42
+ | `Retry-After` accepted any number or a date | Only `[0-9]{1,9}(.[0-9]+)?` seconds; anything else is absent |
43
+ | The After Call parser required `call.id`, `location_id` and a `1.` version | It refuses exactly a missing or wrongly typed required field; a string `call_date` or `timestamp` that is not a date is accepted |
44
+ | An id inside an app link could be any string | Links carry only ids of letters, digits, `-` and `_`; `reference()` refuses others and briefs with such an id get `link: null` |
45
+ | `parseFirstAlertEvent` refused non-UUID ids and lower-cased ids | Ids of letters, digits, `-` and `_` (at most 128), kept as sent |
46
+ | Conversation and account helpers signed in before checking arguments | They check first; with a bad argument no request is sent (your mocks may see fewer requests) |
47
+ | `AccountError.result` was `unknown` | `AccountError<T>`: typed as the helper's result |
48
+ | The examples read `IC_DATA_EMAIL` and `IC_DATA_PASSWORD` | `IC_USER_EMAIL` and `IC_USER_PASSWORD` |
49
+
50
+ ## 0.2.0 (2026-11-29)
51
+
52
+ Two new layers. `client.accounts` replaces `client.workflows`; `client.conversations` is new. Every generated resource method and every `client.intelligence` helper keeps its name and behaviour. The TypeScript SDK now matches the Python reference.
53
+
54
+ - **Account layer, `client.accounts`** (administrator login): create and maintain a customer on Base User and Base Manager licenses. A customer is a company with teams and a `<Company> - Management` location. Each team gets its own connector, five groups (Customer Threats, Upset Customers, Low Sentiment Calls, Insights Hub Access, Insights Hub Weekly Reports) and three alerts (Customer Threat, Upset Customer, Low Sentiment), each routed to its group. Management gets its own connector, which captures the managers' own lines, and the weekly reports group; it has no alerts. Helpers: `createCustomer`, `getCustomer`, `addTeam`, `setAlerts`, `setConnector`, `addBaseUser`, `addBaseManager`, `addIntegrationUser`, `changeLicense`, `moveUser`, `changeLine`, `removeUser`, `activateAlerts`, `sendInvitations`, `listMembers`, `licenseReport`, `syncLines`, `offboardCustomer`. Optional settings go in one options object as the last argument. Types are exported for every spec and result (`CustomerSpec`, `TeamSpec`, `ConnectorSpec`, `PersonSpec`, `AlertSetting`, `AlertSettings`, `Customer`, `Team`, `Member`, ...).
55
+ - Every account helper finds what exists before it writes: a second run with the same input writes nothing. A helper that stops part-way throws `AccountError` with the step, the result so far and the cause (it replaces `WorkflowError`).
56
+ - A customer can be created without the phrase lists: Low Sentiment and every group are created, `Customer.pending` lists the two phrase alerts, and `setAlerts` creates them when the lists arrive. `AlertSettings` sets the phrases and the sentiment level of each alert; leaving one out keeps what is there. Alerts are created switched off; `activateAlerts` switches them on for every team and lists teams with no Base Manager under `noManager`.
57
+ - Alert email is off for every person the helpers create, managers included (0.1.x switched it on for managers). Insights Hub "monitor all numbers" stays off.
58
+ - `new ConnectorSpec(type, config, { name, timeout })` takes any connector type the API accepts with that type's own settings; `ConnectorSpec.netsapiens(apiUrl, domain, apiKey)` is the shortcut for the documented one. Values whose names contain key, secret, token, password, passwd, pwd, credential or auth are hidden, at any depth, from `JSON.stringify`, `console.log` / `util.inspect` and `String()`, and never appear in an error message. `addTeam` requires a connector; `setConnector` attaches one to a customer created without it.
59
+ - **Conversation layer, `client.conversations`** (the person's own login): `me`, `teams`, `calls`, `brief`, `transcript`, `recordingLink`, `callerHistory`, `openTasks`, `alerts`, `alert`, `teamView`, `topics`, `reference`, `parseFirstAlertEvent`. Caller numbers are masked to their last four digits, and digit runs of five or more inside names too, unless the client is created with `maskNumbers: false`. Windows are at most 31 days and lists at most 200 (`callerHistory` 50), checked before any request. "Today" is worked out per date in the local time zone. Printing a `CallBrief` or `AlertBrief` (`String()`, `console.log`) shows only its id and time. `RecordingLink` hides its URL the same way.
60
+ - `CallBrief.link`, `AlertBrief.link` and `reference()` give the call or alert page in the app. `new Client({ appUrl })` sets the app address (https only; default `https://app.intelligence.cloud`).
61
+ - A connector that does not become running stops `createCustomer`, `addTeam` and `setConnector` with `AccountError` (step `"connectors"`, cause `ConnectorTimeoutError` or `ConnectorError`) once everything else is built; run again to finish. A connector that reports `connected` counts as running, as `active` does; `connectors.createConnector`, `reactivateConnector` and `updateConnector` wait for either.
62
+ - `addBaseUser`, `addBaseManager` and `addIntegrationUser` refuse a person already set up with another license; `changeLicense` converts. `changeLicense` and `moveUser` continue from where an earlier run stopped.
63
+ - `parseFirstAlertEvent` and `FirstAlertEvent` parse the First Alert webhook, beside `parseAfterCallEvent`.
64
+ - New errors: `AccountError`, `WrongLoginError` (an account helper with a user login, or a conversation helper with an administrator login) and `ConnectorTimeoutError` (a connector that did not settle in time used to be a `ConnectorError`). `InvalidRequestError` is the one name for input refused before sending; `FilterError` stays as an alias.
65
+ - `ConnectorError` carries `connectorId`, `status`, `stateReason`, `statusMessage` and `connector`.
66
+ - The generated types and operation table are regenerated from the current `openapi.yaml`.
67
+ - Examples: `examples/node/create-customer.mjs` replaces the provisioning example; `examples/node/my-day.mjs` shows the conversation layer.
68
+
69
+ Removed in 0.2.0, with no aliases:
70
+
71
+ | 0.1.x | 0.2.0 |
72
+ |---|---|
73
+ | `client.workflows`, and the workflow shortcuts on the client | `client.accounts` |
74
+ | the 0.1.x provisioning helper, its spec and result types | `createCustomer`, `CustomerSpec`, `Customer` |
75
+ | `ConnectorSpec` as `{ apiUrl, domain, apiKey }` | `ConnectorSpec.netsapiens(apiUrl, domain, apiKey)`, or `new ConnectorSpec(type, config)` |
76
+ | `threatPhrases` | `alerts` (`AlertSettings`: phrases and sentiment level per alert) |
77
+ | the 0.1.x customer read-back helper | `getCustomer` |
78
+ | `addFrontlineUser` | `addBaseUser` |
79
+ | `addManager` | `addBaseManager` (own line now captured at Management; alert email now off) |
80
+ | the 0.1.x alert activation helper | `activateAlerts` |
81
+ | `changeUserExtension` | `changeLine` |
82
+ | `listFrontlineUsers`, `listManagers`, `listIntegrationUsers` | `listMembers({ license })` |
83
+ | `syncNumbers` | `syncLines` |
84
+ | `WorkflowError` | `AccountError` |
85
+ | the 0.1.x user result and spec types | `Member`, `PersonSpec`, `TeamSpec` |
86
+ | `upsetCustomerRule`, `customerThreatRule`, `THREAT_PHRASES_MISSING`, `MANAGER_ALERTS_GROUP` and the other workflow constants | none; defaults are internal |
87
+ | "Manager Alerts" group, two rules | Three groups and three rules per team |
88
+
89
+ A customer built with 0.1.x is not converted automatically: `getCustomer` lists what its layout is missing in `Customer.pending`.
90
+
3
91
  ## 0.1.1 (2026-11-29)
4
92
 
5
93
  - Insights Hub "monitor all numbers" is never switched on. `provisionSeatCustomer` used to set `monitor_all_numbers` to true; it now leaves it off and switches it off where an earlier run switched it on. Insights Hub covers the lines listed for the location, which `addFrontlineUser` already adds. Re-run `provisionSeatCustomer` for customers set up with 0.1.0.