@labyrinthe/connect 0.0.0-stage → 1.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/CHANGELOG.md ADDED
@@ -0,0 +1,101 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@labyrinthe/connect` are documented here. This project follows
4
+ [Semantic Versioning](https://semver.org/) and the format of [Keep a Changelog](https://keepachangelog.com/).
5
+
6
+ ## [Unreleased]
7
+
8
+ ## [1.2.0] - 2026-11-06
9
+
10
+ Built against the API specification 1.3.0. Backward compatible with 1.1.x.
11
+
12
+ ### Added
13
+ - `FeatureDisabledError` (503 `FEATURE_DISABLED`, extends `ServiceUnavailableError`): a platform administrator
14
+ temporarily shut down the whole API (`blockedBy` = `"api"`) or one function (`"api.sms_send"`, `"api.otp_send"`,
15
+ `"api.otp_verify"`). Nothing was done. Read-only `feature`, `blockedBy`, `adminMessage` (`details.message`), `until`
16
+ (`Date`, `null` when unknown or invalid), `retryAfter` (seconds, from `Retry-After`) and `retryAfterMs`. Missing or
17
+ malformed `details` are tolerated (`null`). `FEATURE_DISABLED` added to `ApiErrorCode`.
18
+
19
+ ### Changed
20
+ - 503 `OTP_SERVICE_DISABLED` (whole OTP service off) is now thrown as `FeatureDisabledError` too (still an
21
+ `instanceof ServiceUnavailableError`), with the same details (`feature` = `blockedBy` = `"otp"`).
22
+ - `FEATURE_DISABLED` and `OTP_SERVICE_DISABLED` are never retried with exponential backoff: they are retried, for
23
+ every call including `otp.verify()` (refused before processing), only when the API sends `Retry-After` (automatic
24
+ re-enable scheduled) no longer than `maxRetryWaitMs`, after exactly that delay; otherwise thrown at once. Other
25
+ 5xx keep the previous behaviour.
26
+
27
+ ## [1.1.1] - 2026-11-06
28
+
29
+ ### Added
30
+ - `IdempotencyKeyUnresolvedError` (409 `IDEMPOTENCY_KEY_UNRESOLVED`, `sms.send()`, `sms.sendMany()`, `otp.send()`):
31
+ the original request with this Idempotency-Key failed unexpectedly and its outcome is unknown (an SMS may have been
32
+ sent). Never retried by the SDK; check (`sms.list({ reference })` or with the user), then send again with a new key.
33
+
34
+ ### Fixed
35
+ - Phone numbers are sent to the API in E.164 with "+" (`recipient`, `recipients[]`, `estimate()` recipients, OTP
36
+ `phone` and the `recipient` filter of `sms.list()`). Without it, the API read a short foreign number (10 digits or
37
+ less) as a local DR Congo number: `+2481234567` (Seychelles) was sent as `2481234567` and became `2432481234567`.
38
+ `PhoneNumber.normalize()` still returns digits without "+", the format of API responses. Requires no code change.
39
+
40
+ ## [1.1.0] - 2026-11-06
41
+
42
+ Built against the API specification 1.2.0. Backward compatible with 1.0.0, except that `OtpVerifyResult` gains
43
+ `attemptsRemaining` (deep-equality checks on the whole result must include it).
44
+
45
+ ### Added
46
+ - `X-Request-Id`: per-call `requestId` option (sent on every retry of the call, validated locally), `requestId` and
47
+ `apiVersion` (`X-Api-Version`) on every `ApiError`, `requestId` on `MessageBatch` and `OtpSendResult`, and an
48
+ `onResponse` option receiving `{ status, requestId, apiVersion, replayed, rateLimit, headers }`. Logged with each
49
+ response and error.
50
+ - `otp.send()` is idempotent: an `Idempotency-Key` is always sent (generated, or your `idempotencyKey`) and reused by
51
+ retries; `replayed` and `idempotencyKey` on the result.
52
+ - `otp.send()` returns `codeLength`, `codeType` (`OtpCodeType`: `numeric` | `alphanumeric`) and
53
+ `resendAfterSeconds`; accepts `webOtpDomain` (Web OTP API, validated against the spec pattern, lower-cased) and
54
+ `stripAccents`.
55
+ - `otp.verify()` returns `attemptsRemaining` (`number | null`).
56
+ - `stripAccents` on `sms.send()`, `sms.sendMany()` and `sms.estimate()`.
57
+ - `AccountSuspendedError` (403 `ACCOUNT_SUSPENDED`, extends `PermissionError`) and
58
+ `IdempotencyRequestInProgressError` (409 `IDEMPOTENCY_REQUEST_IN_PROGRESS`, `retryAfterMs`).
59
+ - Webhooks: `message.status_changed` gains `reference`, `errorCode`, `errorMessage`; new `otp.verified` and
60
+ `otp.failed` events in the `WebhookEvent` union (`OtpVerifiedEvent`, `OtpFailedEvent`, `OtpWebhookData`,
61
+ `OtpVerificationStatus`); `WebhookEventType.OtpVerified` / `OtpFailed`. The Express and Next.js helpers receive
62
+ them typed.
63
+
64
+ ### Changed
65
+ - Retries: `otp.send()` is now retried like SMS sends (network error, timeout, 5xx, 429 `TOO_MANY_REQUESTS`), always
66
+ with the same key; `409 IDEMPOTENCY_REQUEST_IN_PROGRESS` is retried after `Retry-After` with the same key for
67
+ `sms.send()`, `sms.sendMany()` and `otp.send()`. `otp.verify()` is still retried only on 429
68
+ `TOO_MANY_REQUESTS`; `OTP_RESEND_TOO_SOON` and `OTP_RATE_LIMITED` are never retried.
69
+ - `retryAfterMs` reads the `Retry-After` header (seconds or HTTP date) now sent with `OTP_RESEND_TOO_SOON` and
70
+ `OTP_RATE_LIMITED`, then `details.retry_after_seconds`.
71
+ - Phone numbers, aligned with the API: without "+", 11 digits or more not starting with 0 are already international
72
+ (`33612345678` stays `33612345678` instead of becoming `24333612345678`). DR Congo formats are unchanged.
73
+ - The 1.2.0 response fields are read tolerantly (`null` when an older backend omits them); `error.details` `[]` and
74
+ `Z` dates are still accepted.
75
+
76
+ ## [1.0.0] - 2026-11-06
77
+
78
+ First stable release, built against the API specification 1.1.0.
79
+
80
+ ### Added
81
+ - `new Labyrinthe({ apiKey, baseUrl, timeoutMs, maxRetries, maxRetryWaitMs, defaultCountryCode, defaultSender, fetch, logger })`,
82
+ `LABYRINTHE_API_KEY` / `LABYRINTHE_BASE_URL` read from the environment, `isTestMode` / `isLiveMode`.
83
+ - SMS: `send()`, `sendMany()` (all or nothing, `replayed`), `estimate()`, `get()`, `list()` with filters; awaitable
84
+ for one page, async-iterable over every page (`for await`).
85
+ - Balance and approved Sender IDs.
86
+ - OTP: `send()` (with `testCode` in test mode, hidden from logs and JSON) and `verify()` (discriminated result).
87
+ - Automatic `Idempotency-Key` (`crypto.randomUUID()`) on every SMS send, reused across retries.
88
+ - Retries with exponential backoff and jitter, only when safe (GET, estimate, SMS send; OTP only on
89
+ 429 `TOO_MANY_REQUESTS`); `Retry-After` support capped by `maxRetryWaitMs`; per-call `signal` and `timeoutMs`.
90
+ - Typed errors for every documented error code (`LabyrintheError` → `ApiError` → …), `ConnectionError`,
91
+ `TimeoutError`, `RequestAbortedError`, `InvalidArgumentError`.
92
+ - `Webhooks.constructEvent()` with Web Crypto: constant-time HMAC-SHA256 verification on the raw body, timestamp
93
+ tolerance, discriminated union on `event`; `Webhooks.sign()` and `verifySignature()`.
94
+ - `@labyrinthe/connect/express` (middleware) and `@labyrinthe/connect/next` (App Router route handler).
95
+ - `PhoneNumber` helpers (normalisation identical to the API, validation, masking).
96
+ - ESM + CommonJS + types; zero runtime dependency; Node.js 18+, edge runtimes, Deno and Bun.
97
+
98
+ [Unreleased]: https://github.com/Labyrinthe-Team/labyrinthe-connect-sdks/compare/node-v1.1.1...HEAD
99
+ [1.1.1]: https://github.com/Labyrinthe-Team/labyrinthe-connect-sdks/compare/node-v1.1.0...node-v1.1.1
100
+ [1.1.0]: https://github.com/Labyrinthe-Team/labyrinthe-connect-sdks/compare/node-v1.0.0...node-v1.1.0
101
+ [1.0.0]: https://github.com/Labyrinthe-Team/labyrinthe-connect-sdks/releases/tag/node-v1.0.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Labyrinthe Connect
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.