@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 +89 -5
- package/dist/generated/api.d.ts +537 -512
- package/dist/index.d.ts +147 -6
- package/dist/index.js +63 -3
- package/package.json +2 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,158 @@
|
|
|
1
1
|
import { type ClientOptions } from 'openapi-fetch';
|
|
2
2
|
import type { components, paths } from './generated/api.js';
|
|
3
3
|
export type { components, paths } from './generated/api.js';
|
|
4
|
+
type Schemas = components['schemas'];
|
|
5
|
+
export type SendEmailRequest = Schemas['SendEmailRequest'];
|
|
6
|
+
export type SendEmailResponse = Schemas['SendEmailResponse'];
|
|
7
|
+
export type Email = Schemas['Email'];
|
|
8
|
+
export type Event = Schemas['Event'];
|
|
9
|
+
export type Stats = Schemas['Stats'];
|
|
10
|
+
export type Suppression = Schemas['Suppression'];
|
|
11
|
+
export type AddressCheckRequest = Schemas['AddressCheckRequest'];
|
|
12
|
+
export type AddressCheck = Schemas['AddressCheck'];
|
|
13
|
+
export type VerificationRequest = Schemas['VerificationRequest'];
|
|
14
|
+
export type Verification = Schemas['Verification'];
|
|
15
|
+
export type VerificationCheck = Schemas['VerificationCheck'];
|
|
16
|
+
export type VerificationStatus = Schemas['VerificationStatus'];
|
|
17
|
+
export type InboundEmail = Schemas['InboundEmail'];
|
|
18
|
+
export type EmailEvent = Schemas['EmailEvent'];
|
|
19
|
+
export type PaymentEvent = Schemas['PaymentEvent'];
|
|
20
|
+
/** API version these types describe, sent as Iris-Version unless you pass another `version`. */
|
|
21
|
+
export declare const API_VERSION = "2026-11-23";
|
|
4
22
|
export type IrisOptions = ClientOptions & {
|
|
5
23
|
apiKey: string;
|
|
24
|
+
version?: string;
|
|
25
|
+
};
|
|
26
|
+
/** An answer other than 2xx. Branch on `status` and `code`; `message` and `fix` are French text that may change. */
|
|
27
|
+
export declare class IrisError extends Error {
|
|
28
|
+
readonly status: number;
|
|
29
|
+
readonly code: string;
|
|
30
|
+
readonly fix: string;
|
|
31
|
+
readonly docs: string;
|
|
32
|
+
name: string;
|
|
33
|
+
constructor(status: number, code: string, message: string, fix: string, docs: string);
|
|
34
|
+
}
|
|
35
|
+
type Query<P extends '/api/emails' | '/api/events' | '/api/stats'> = Omit<NonNullable<paths[P]['get']['parameters']['query']>, 'cursor'>;
|
|
36
|
+
/** Client of the Iris API. Use from your server only: the key must stay secret. Every method throws an IrisError on a non-2xx answer. */
|
|
37
|
+
export declare function createIris({ apiKey, version, baseUrl, headers, ...options }: IrisOptions): {
|
|
38
|
+
/** Queues an email (202). Pass the same `idempotencyKey`, an order number for example, on a retry so it is not sent twice. */
|
|
39
|
+
sendEmail: (body: SendEmailRequest, { idempotencyKey }?: {
|
|
40
|
+
idempotencyKey?: string;
|
|
41
|
+
}) => Promise<{
|
|
42
|
+
id?: string | undefined;
|
|
43
|
+
ids?: string[] | undefined;
|
|
44
|
+
status: "queued" | "scheduled";
|
|
45
|
+
batch_id?: string | undefined;
|
|
46
|
+
}>;
|
|
47
|
+
/** Every email of the key's project, newest first, fetching the next page as you iterate. */
|
|
48
|
+
listEmails: (query?: Query<"/api/emails">) => AsyncGenerator<{
|
|
49
|
+
id: string;
|
|
50
|
+
status: "queued" | "scheduled" | "sent" | "delivered" | "bounced" | "failed" | "cancelled";
|
|
51
|
+
message_id?: string | undefined;
|
|
52
|
+
from: components["schemas"]["Mailbox"];
|
|
53
|
+
to: string[];
|
|
54
|
+
subject: string;
|
|
55
|
+
created_at: string;
|
|
56
|
+
send_at?: string | null | undefined;
|
|
57
|
+
error?: string | null | undefined;
|
|
58
|
+
}, void, undefined>;
|
|
59
|
+
getEmail: (id: string) => Promise<{
|
|
60
|
+
id: string;
|
|
61
|
+
status: "queued" | "scheduled" | "sent" | "delivered" | "bounced" | "failed" | "cancelled";
|
|
62
|
+
message_id?: string | undefined;
|
|
63
|
+
from: components["schemas"]["Mailbox"];
|
|
64
|
+
to: string[];
|
|
65
|
+
subject: string;
|
|
66
|
+
created_at: string;
|
|
67
|
+
send_at?: string | null | undefined;
|
|
68
|
+
error?: string | null | undefined;
|
|
69
|
+
}>;
|
|
70
|
+
/** Cancels a scheduled email (its `id` or `batch_id`) that has not left yet, and gives its units back. */
|
|
71
|
+
cancelEmail: (id: string) => Promise<{
|
|
72
|
+
id: string;
|
|
73
|
+
status: "cancelled";
|
|
74
|
+
cancelled: number;
|
|
75
|
+
}>;
|
|
76
|
+
checkEmailAddresses: (body: AddressCheckRequest) => Promise<{
|
|
77
|
+
email: string;
|
|
78
|
+
valid_syntax: boolean;
|
|
79
|
+
normalized: string | null;
|
|
80
|
+
mail_server: "mx" | "a" | null | "none" | "unknown";
|
|
81
|
+
disposable: boolean;
|
|
82
|
+
role: boolean;
|
|
83
|
+
suggestion: string | null;
|
|
84
|
+
suppressed: boolean;
|
|
85
|
+
verdict: "deliverable" | "risky" | "undeliverable";
|
|
86
|
+
} | {
|
|
87
|
+
results: {
|
|
88
|
+
email: string;
|
|
89
|
+
valid_syntax: boolean;
|
|
90
|
+
normalized: string | null;
|
|
91
|
+
mail_server: "mx" | "a" | null | "none" | "unknown";
|
|
92
|
+
disposable: boolean;
|
|
93
|
+
role: boolean;
|
|
94
|
+
suggestion: string | null;
|
|
95
|
+
suppressed: boolean;
|
|
96
|
+
verdict: "deliverable" | "risky" | "undeliverable";
|
|
97
|
+
}[];
|
|
98
|
+
}>;
|
|
99
|
+
/** Events of the key's project, newest first, fetching the next page as you iterate. */
|
|
100
|
+
listEvents: (query?: Query<"/api/events">) => AsyncGenerator<{
|
|
101
|
+
id: string;
|
|
102
|
+
type: "email.delivered" | "email.bounced" | "email.soft_bounced" | "email.complained" | "email.opened" | "email.clicked" | "email.unsubscribed";
|
|
103
|
+
email_id: string;
|
|
104
|
+
recipient?: string | null | undefined;
|
|
105
|
+
created_at: string;
|
|
106
|
+
link?: string | undefined;
|
|
107
|
+
}, void, undefined>;
|
|
108
|
+
/** Totals over `from`..`to` (YYYY-MM-DD, UTC, both included); the last 30 days by default. */
|
|
109
|
+
getStats: (query?: Query<"/api/stats">) => Promise<{
|
|
110
|
+
from?: string | undefined;
|
|
111
|
+
to?: string | undefined;
|
|
112
|
+
requests?: number | undefined;
|
|
113
|
+
delivered?: number | undefined;
|
|
114
|
+
hard_bounces?: number | undefined;
|
|
115
|
+
soft_bounces?: number | undefined;
|
|
116
|
+
complaints?: number | undefined;
|
|
117
|
+
unsubscribed?: number | undefined;
|
|
118
|
+
opens?: number | undefined;
|
|
119
|
+
unique_opens?: number | undefined;
|
|
120
|
+
clicks?: number | undefined;
|
|
121
|
+
unique_clicks?: number | undefined;
|
|
122
|
+
}>;
|
|
123
|
+
listSuppressions: () => AsyncGenerator<{
|
|
124
|
+
email: string;
|
|
125
|
+
reason: "hard_bounce" | "complaint" | "unsubscribe";
|
|
126
|
+
created_at: string;
|
|
127
|
+
}, void, undefined>;
|
|
128
|
+
deleteSuppression: (email: string) => Promise<void>;
|
|
129
|
+
revokeSecret: (id: string) => Promise<{
|
|
130
|
+
id: string;
|
|
131
|
+
revoked: true;
|
|
132
|
+
}>;
|
|
133
|
+
/** Downloads attachment `index` of an inbound email; its name and type are in the webhook's `attachments`. */
|
|
134
|
+
getInboundAttachment: (delivery: string, index: number) => Promise<Blob>;
|
|
135
|
+
createVerification: (body: VerificationRequest) => Promise<{
|
|
136
|
+
verificationId: string;
|
|
137
|
+
channel: "email" | "sms" | "whatsapp";
|
|
138
|
+
units?: number | undefined;
|
|
139
|
+
expiresAt: string;
|
|
140
|
+
}>;
|
|
141
|
+
checkVerification: (body: VerificationCheck) => Promise<{
|
|
142
|
+
status: "pending" | "approved" | "max_attempts" | "canceled" | "expired";
|
|
143
|
+
}>;
|
|
144
|
+
cancelVerification: (id: string) => Promise<{
|
|
145
|
+
status: "pending" | "approved" | "max_attempts" | "canceled" | "expired";
|
|
146
|
+
}>;
|
|
147
|
+
resendVerification: (id: string) => Promise<{
|
|
148
|
+
verificationId: string;
|
|
149
|
+
channel: "email" | "sms" | "whatsapp";
|
|
150
|
+
units?: number | undefined;
|
|
151
|
+
expiresAt: string;
|
|
152
|
+
}>;
|
|
6
153
|
};
|
|
7
|
-
/** Typed client of every route of the Iris OpenAPI document. Use from your server only. */
|
|
8
|
-
export declare function createIris({ apiKey, baseUrl, headers, ...options }: IrisOptions): import("openapi-fetch").Client<paths, `${string}/${string}`>;
|
|
9
154
|
export type Iris = ReturnType<typeof createIris>;
|
|
10
155
|
/** Verifies an inbound email or email event delivery (Standard Webhooks, whsec_ secret) and returns the parsed body; throws if invalid. */
|
|
11
156
|
export declare function verifyWebhook<T = InboundEmail | EmailEvent>(secret: string, rawBody: string, headers: Headers | Record<string, string>): T;
|
|
12
157
|
/** Checks X-Iris-Signature of a payment event; during a secret rotation the header carries two signatures, either may match. */
|
|
13
158
|
export declare function verifyPaymentWebhook(secret: string, rawBody: string | Uint8Array, timestamp: string, signature: string, maxAgeSeconds?: number): boolean;
|
|
14
|
-
export type IrisError = components['schemas']['Error'];
|
|
15
|
-
export type InboundEmail = components['schemas']['InboundEmail'];
|
|
16
|
-
export type EmailEvent = components['schemas']['EmailEvent'];
|
|
17
|
-
export type PaymentEvent = components['schemas']['PaymentEvent'];
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,69 @@
|
|
|
1
1
|
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
2
2
|
import createClient from 'openapi-fetch';
|
|
3
3
|
import { Webhook } from 'standardwebhooks';
|
|
4
|
-
/**
|
|
5
|
-
export
|
|
6
|
-
|
|
4
|
+
/** API version these types describe, sent as Iris-Version unless you pass another `version`. */
|
|
5
|
+
export const API_VERSION = '2026-11-23';
|
|
6
|
+
/** An answer other than 2xx. Branch on `status` and `code`; `message` and `fix` are French text that may change. */
|
|
7
|
+
export class IrisError extends Error {
|
|
8
|
+
status;
|
|
9
|
+
code;
|
|
10
|
+
fix;
|
|
11
|
+
docs;
|
|
12
|
+
name = 'IrisError';
|
|
13
|
+
constructor(status, code, message, fix, docs) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.status = status;
|
|
16
|
+
this.code = code;
|
|
17
|
+
this.fix = fix;
|
|
18
|
+
this.docs = docs;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async function call(request) {
|
|
22
|
+
const { data, error, response } = await request;
|
|
23
|
+
if (response.ok)
|
|
24
|
+
return data;
|
|
25
|
+
// /v1/verify still answers a flat {code, message} without fix or docs.
|
|
26
|
+
const body = typeof error === 'object' && error ? (error.error ?? error) : undefined;
|
|
27
|
+
if (body?.code)
|
|
28
|
+
throw new IrisError(response.status, body.code, body.message ?? '', body.fix ?? '', body.docs ?? '');
|
|
29
|
+
throw new IrisError(response.status, 'http_error', typeof error === 'string' && error ? error : response.statusText, '', '');
|
|
30
|
+
}
|
|
31
|
+
async function* paginate(page) {
|
|
32
|
+
let cursor;
|
|
33
|
+
do {
|
|
34
|
+
const p = await page(cursor);
|
|
35
|
+
yield* p.data;
|
|
36
|
+
cursor = p.next_cursor ?? undefined;
|
|
37
|
+
} while (cursor);
|
|
38
|
+
}
|
|
39
|
+
/** Client of the Iris API. Use from your server only: the key must stay secret. Every method throws an IrisError on a non-2xx answer. */
|
|
40
|
+
export function createIris({ apiKey, version = API_VERSION, baseUrl = 'https://iris.orvlabs.com', headers, ...options }) {
|
|
41
|
+
const client = createClient({ ...options, baseUrl, headers: { ...headers, Authorization: `Bearer ${apiKey}`, 'Iris-Version': version } });
|
|
42
|
+
return {
|
|
43
|
+
/** Queues an email (202). Pass the same `idempotencyKey`, an order number for example, on a retry so it is not sent twice. */
|
|
44
|
+
sendEmail: (body, { idempotencyKey } = {}) => call(client.POST('/api/emails', { body, params: { header: { 'Idempotency-Key': idempotencyKey } } })),
|
|
45
|
+
/** Every email of the key's project, newest first, fetching the next page as you iterate. */
|
|
46
|
+
listEmails: (query = {}) => paginate((cursor) => call(client.GET('/api/emails', { params: { query: { ...query, cursor } } }))),
|
|
47
|
+
getEmail: (id) => call(client.GET('/api/emails/{id}', { params: { path: { id } } })),
|
|
48
|
+
/** Cancels a scheduled email (its `id` or `batch_id`) that has not left yet, and gives its units back. */
|
|
49
|
+
cancelEmail: (id) => call(client.POST('/api/emails/{id}/cancel', { params: { path: { id } } })),
|
|
50
|
+
checkEmailAddresses: (body) => call(client.POST('/api/emails/check', { body })),
|
|
51
|
+
/** Events of the key's project, newest first, fetching the next page as you iterate. */
|
|
52
|
+
listEvents: (query = {}) => paginate((cursor) => call(client.GET('/api/events', { params: { query: { ...query, cursor } } }))),
|
|
53
|
+
/** Totals over `from`..`to` (YYYY-MM-DD, UTC, both included); the last 30 days by default. */
|
|
54
|
+
getStats: (query = {}) => call(client.GET('/api/stats', { params: { query } })),
|
|
55
|
+
listSuppressions: () => paginate((cursor) => call(client.GET('/api/suppressions', { params: { query: { cursor } } }))),
|
|
56
|
+
deleteSuppression: async (email) => {
|
|
57
|
+
await call(client.DELETE('/api/suppressions/{email}', { params: { path: { email } } }));
|
|
58
|
+
},
|
|
59
|
+
revokeSecret: (id) => call(client.POST('/api/secrets/{id}/revoke', { params: { path: { id } } })),
|
|
60
|
+
/** Downloads attachment `index` of an inbound email; its name and type are in the webhook's `attachments`. */
|
|
61
|
+
getInboundAttachment: (delivery, index) => call(client.GET('/api/inbound/{delivery}/attachments/{index}', { params: { path: { delivery, index } }, parseAs: 'blob' })),
|
|
62
|
+
createVerification: (body) => call(client.POST('/v1/verify', { body })),
|
|
63
|
+
checkVerification: (body) => call(client.POST('/v1/verify/check', { body })),
|
|
64
|
+
cancelVerification: (id) => call(client.POST('/v1/verify/{id}/cancel', { params: { path: { id } } })),
|
|
65
|
+
resendVerification: (id) => call(client.POST('/v1/verify/{id}/resend', { params: { path: { id } } })),
|
|
66
|
+
};
|
|
7
67
|
}
|
|
8
68
|
/** Verifies an inbound email or email event delivery (Standard Webhooks, whsec_ secret) and returns the parsed body; throws if invalid. */
|
|
9
69
|
export function verifyWebhook(secret, rawBody, headers) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orvlabs/iris",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "SDK TypeScript de l'API Iris : client typé de chaque route, vérification des webhooks.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://iris.orvlabs.com/docs",
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
"email",
|
|
10
10
|
"transactional",
|
|
11
11
|
"senegal",
|
|
12
|
-
"brevo",
|
|
13
12
|
"sdk",
|
|
14
13
|
"webhooks",
|
|
15
14
|
"otp"
|
|
@@ -30,7 +29,7 @@
|
|
|
30
29
|
"node": ">=20.19"
|
|
31
30
|
},
|
|
32
31
|
"scripts": {
|
|
33
|
-
"generate": "openapi-typescript https://iris.orvlabs.com/openapi.json -o src/generated/api.ts",
|
|
32
|
+
"generate": "openapi-typescript https://iris.orvlabs.com/openapi.json -o src/generated/api.ts --default-non-nullable false --empty-objects-unknown",
|
|
34
33
|
"build": "npm run generate && rm -rf dist && tsc",
|
|
35
34
|
"test": "npm run build && node --test test/*.test.mjs",
|
|
36
35
|
"prepublishOnly": "npm test"
|