@orvlabs/iris 0.1.1 → 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,6 +1,6 @@
1
1
  # @orvlabs/iris
2
2
 
3
- Typed client for the [Iris API](https://iris.orvlabs.com/docs). Types come from the OpenAPI document, so every route, body and error is checked at compile time. A new version is published, with npm provenance, whenever the API changes.
3
+ Typed client for the [Iris API](https://iris.orvlabs.com/docs). Types come from the OpenAPI document, so every body, query and answer is checked at compile time. A new version is published, with npm provenance, whenever the API changes.
4
4
 
5
5
  Server only (Node 20.19+): never ship your API key to a browser.
6
6
 
@@ -8,15 +8,97 @@ Server only (Node 20.19+): never ship your API key to a browser.
8
8
  npm install @orvlabs/iris
9
9
  ```
10
10
 
11
+ ## Send an email
12
+
11
13
  ```ts
12
- import { createIris } from '@orvlabs/iris';
14
+ import { createIris, IrisError } from '@orvlabs/iris';
13
15
 
14
16
  const iris = createIris({ apiKey: process.env.IRIS_API_KEY! });
15
17
 
16
- const { data, error } = await iris.POST('/v3/smtp/email', {
17
- body: { sender: { email: 'no-reply@example.sn' }, to: [{ email: 'awa@example.sn' }], subject: 'Hello', htmlContent: '<p>Hi</p>' },
18
+ const { id } = await iris.sendEmail(
19
+ {
20
+ from: 'Boutique <commandes@boutique.sn>',
21
+ to: 'Awa <awa@example.sn>',
22
+ subject: 'Votre commande',
23
+ html: '<p>Merci {{params.prenom}} !</p>',
24
+ data: { prenom: 'Awa' },
25
+ },
26
+ { idempotencyKey: 'commande-CMD-2041' },
27
+ );
28
+ ```
29
+
30
+ With the same `idempotencyKey` (an order number, for example), a retry after a network timeout does not send the email twice. The key is kept 24 hours; reusing it with another body throws `idempotency_key_reused`.
31
+
32
+ Use a test key (`iris_test_…`) while you build: it is checked exactly like a real one, but nothing is delivered and no units are used.
33
+
34
+ ## Ask for a payment
35
+
36
+ ```ts
37
+ await iris.sendEmail({
38
+ from: 'factures@boutique.sn',
39
+ to: 'awa@example.sn',
40
+ subject: 'Votre facture',
41
+ html: '<p>Votre facture est prête.</p>{{bloc_paiement}}',
42
+ payment: { amount_xof: 15000, reference: 'FAC-2026-0042', description: 'Facture FAC-2026-0042', methods: ['wave', 'orange_money'] },
43
+ });
44
+ ```
45
+
46
+ Amounts are whole CFA francs. The same reference and amount reuse the same 221 Pay link; link your merchant account in the console first.
47
+
48
+ ## Handle errors
49
+
50
+ Every method throws an `IrisError` on an answer other than 2xx.
51
+
52
+ ```ts
53
+ try {
54
+ await iris.sendEmail(email);
55
+ } catch (e) {
56
+ if (!(e instanceof IrisError)) throw e; // network failure
57
+ console.error(e.status, e.code, e.message, e.fix, e.docs);
58
+ if ([429, 502, 503].includes(e.status)) {
59
+ // retry later, with an increasing delay and the same idempotencyKey
60
+ }
61
+ }
62
+ ```
63
+
64
+ Branch on `status` and `code`; `message` and `fix` are readable French that may change, `docs` links the page of the code.
65
+
66
+ ## Lists
67
+
68
+ `listEmails`, `listEvents` and `listSuppressions` fetch the next page as you iterate.
69
+
70
+ ```ts
71
+ for await (const email of iris.listEmails({ to: 'awa@example.sn' })) {
72
+ console.log(email.id, email.status);
73
+ }
74
+
75
+ for await (const event of iris.listEvents({ type: 'email.bounced' })) {
76
+ console.log(event.email_id, event.recipient);
77
+ }
78
+ ```
79
+
80
+ ## Other routes
81
+
82
+ | Method | Route |
83
+ | --- | --- |
84
+ | `getEmail(id)` | `GET /api/emails/{id}` |
85
+ | `cancelEmail(id)` | `POST /api/emails/{id}/cancel`, a scheduled email or its `batch_id` |
86
+ | `checkEmailAddresses({ emails })` | `POST /api/emails/check` |
87
+ | `getStats({ from, to })` | `GET /api/stats`, `YYYY-MM-DD`, UTC, both included |
88
+ | `deleteSuppression(email)` | `DELETE /api/suppressions/{email}` |
89
+ | `revokeSecret(id)` | `POST /api/secrets/{id}/revoke` |
90
+ | `getInboundAttachment(delivery, index)` | `GET /api/inbound/{delivery}/attachments/{index}`, a `Blob` |
91
+ | `createVerification`, `checkVerification`, `cancelVerification`, `resendVerification` | `/v1/verify` |
92
+
93
+ ## Options
94
+
95
+ ```ts
96
+ createIris({
97
+ apiKey: process.env.IRIS_API_KEY!,
98
+ version: '2026-11-23', // Iris-Version; defaults to the version these types describe (API_VERSION)
99
+ baseUrl: 'https://iris.orvlabs.com',
100
+ fetch, // your own fetch, for a proxy or tests
18
101
  });
19
- if (error) console.error(error.code, error.message);
20
102
  ```
21
103
 
22
104
  ## Webhooks
@@ -35,3 +117,5 @@ const ok = verifyPaymentWebhook(secret, rawBody, headers['x-iris-timestamp'], he
35
117
  ```
36
118
 
37
119
  Deduplicate on the event `id`: retries carry the same one.
120
+
121
+ Every route, field and error code is in the [API reference](https://iris.orvlabs.com/docs).