@orvlabs/iris 0.0.0-stage → 0.1.1

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.
@@ -0,0 +1,5 @@
1
+ /**
2
+ * This file was auto-generated by openapi-typescript.
3
+ * Do not make direct changes to the file.
4
+ */
5
+ export {};
@@ -0,0 +1,17 @@
1
+ import { type ClientOptions } from 'openapi-fetch';
2
+ import type { components, paths } from './generated/api.js';
3
+ export type { components, paths } from './generated/api.js';
4
+ export type IrisOptions = ClientOptions & {
5
+ apiKey: string;
6
+ };
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
+ export type Iris = ReturnType<typeof createIris>;
10
+ /** Verifies an inbound email or email event delivery (Standard Webhooks, whsec_ secret) and returns the parsed body; throws if invalid. */
11
+ export declare function verifyWebhook<T = InboundEmail | EmailEvent>(secret: string, rawBody: string, headers: Headers | Record<string, string>): T;
12
+ /** Checks X-Iris-Signature of a payment event; during a secret rotation the header carries two signatures, either may match. */
13
+ 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 ADDED
@@ -0,0 +1,21 @@
1
+ import { createHmac, timingSafeEqual } from 'node:crypto';
2
+ import createClient from 'openapi-fetch';
3
+ import { Webhook } from 'standardwebhooks';
4
+ /** Typed client of every route of the Iris OpenAPI document. Use from your server only. */
5
+ export function createIris({ apiKey, baseUrl = 'https://iris.orvlabs.com', headers, ...options }) {
6
+ return createClient({ ...options, baseUrl, headers: { ...headers, 'api-key': apiKey } });
7
+ }
8
+ /** Verifies an inbound email or email event delivery (Standard Webhooks, whsec_ secret) and returns the parsed body; throws if invalid. */
9
+ export function verifyWebhook(secret, rawBody, headers) {
10
+ return new Webhook(secret).verify(rawBody, headers instanceof Headers ? Object.fromEntries(headers) : headers);
11
+ }
12
+ /** Checks X-Iris-Signature of a payment event; during a secret rotation the header carries two signatures, either may match. */
13
+ export function verifyPaymentWebhook(secret, rawBody, timestamp, signature, maxAgeSeconds = 300) {
14
+ if (!/^\d+$/.test(timestamp) || Math.abs(Date.now() / 1000 - Number(timestamp)) > maxAgeSeconds)
15
+ return false;
16
+ const expected = Buffer.from(`v1=${createHmac('sha256', secret).update(`${timestamp}.`).update(rawBody).digest('hex')}`);
17
+ return signature.split(' ').some((s) => {
18
+ const got = Buffer.from(s);
19
+ return got.length === expected.length && timingSafeEqual(got, expected);
20
+ });
21
+ }
package/package.json CHANGED
@@ -1,6 +1,56 @@
1
1
  {
2
2
  "name": "@orvlabs/iris",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "SDK TypeScript de l'API Iris : client typé de chaque route, vérification des webhooks.",
5
+ "license": "MIT",
6
+ "homepage": "https://iris.orvlabs.com/docs",
7
+ "keywords": [
8
+ "iris",
9
+ "email",
10
+ "transactional",
11
+ "senegal",
12
+ "brevo",
13
+ "sdk",
14
+ "webhooks",
15
+ "otp"
16
+ ],
17
+ "type": "module",
18
+ "types": "./dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "default": "./dist/index.js"
23
+ }
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "LICENSE"
28
+ ],
29
+ "engines": {
30
+ "node": ">=20.19"
31
+ },
32
+ "scripts": {
33
+ "generate": "openapi-typescript https://iris.orvlabs.com/openapi.json -o src/generated/api.ts",
34
+ "build": "npm run generate && rm -rf dist && tsc",
35
+ "test": "npm run build && node --test test/*.test.mjs",
36
+ "prepublishOnly": "npm test"
37
+ },
38
+ "dependencies": {
39
+ "openapi-fetch": "0.17.0",
40
+ "standardwebhooks": "1.3.0"
41
+ },
42
+ "devDependencies": {
43
+ "@types/node": "22.19.19",
44
+ "openapi-typescript": "7.13.0",
45
+ "typescript": "5.9.3"
46
+ },
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git+https://github.com/orvlabs/iris-js.git"
50
+ },
51
+ "bugs": "https://github.com/orvlabs/iris-js/issues",
52
+ "publishConfig": {
53
+ "access": "public",
54
+ "provenance": true
55
+ }
56
+ }