@reachflow/sdk 0.1.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/LICENSE +21 -0
- package/README.md +109 -0
- package/dist/index.cjs +382 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +238 -0
- package/dist/index.d.ts +238 -0
- package/dist/index.js +352 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/** Statut de cycle de vie d'un message API. */
|
|
2
|
+
type MessageStatus = 'queued' | 'processing' | 'sent' | 'delivered' | 'failed' | 'cancelled';
|
|
3
|
+
type MediaType = 'image' | 'document' | 'audio' | 'video';
|
|
4
|
+
type FailureCode = 'warmup_daily_limit' | 'risk_circuit_open' | 'provider_disconnected' | 'provider_banned' | 'send_not_allowed' | 'instance_busy' | 'delivery_timeout' | 'delivery_failed' | 'send_error' | 'provider_not_found';
|
|
5
|
+
type OtpVerifyReason = 'invalidated' | 'already_used' | 'expired' | 'max_attempts_reached' | 'invalid_code' | 'not_found';
|
|
6
|
+
interface ReachFlowClientOptions {
|
|
7
|
+
/** Clé API `rfl_live_…` ou `rfl_test_…`. */
|
|
8
|
+
apiKey: string;
|
|
9
|
+
/**
|
|
10
|
+
* URL de base sans `/api/v1` (défaut : sandbox ReachFlow).
|
|
11
|
+
* @default "https://sandbox-api.reachflow.me"
|
|
12
|
+
*/
|
|
13
|
+
baseUrl?: string;
|
|
14
|
+
/** Timeout HTTP en millisecondes. @default 30000 */
|
|
15
|
+
timeoutMs?: number;
|
|
16
|
+
/** Implémentation fetch (tests, Node < 18). @default global fetch */
|
|
17
|
+
fetch?: typeof fetch;
|
|
18
|
+
/** Nombre max de retries sur 429 / 5xx retryables. @default 2 */
|
|
19
|
+
maxRetries?: number;
|
|
20
|
+
}
|
|
21
|
+
interface SendMessageParams {
|
|
22
|
+
providerId: string;
|
|
23
|
+
to: string;
|
|
24
|
+
message: string;
|
|
25
|
+
variables?: Record<string, string>;
|
|
26
|
+
scheduleAt?: string;
|
|
27
|
+
saveContact?: boolean;
|
|
28
|
+
idempotencyKey?: string;
|
|
29
|
+
}
|
|
30
|
+
interface SendMediaParams {
|
|
31
|
+
providerId: string;
|
|
32
|
+
to: string;
|
|
33
|
+
mediaUrl: string;
|
|
34
|
+
mediaType: MediaType;
|
|
35
|
+
caption?: string;
|
|
36
|
+
saveContact?: boolean;
|
|
37
|
+
idempotencyKey?: string;
|
|
38
|
+
}
|
|
39
|
+
interface BulkRecipient {
|
|
40
|
+
to: string;
|
|
41
|
+
variables?: Record<string, string>;
|
|
42
|
+
}
|
|
43
|
+
interface SendBulkParams {
|
|
44
|
+
providerId: string;
|
|
45
|
+
messageTemplate: string;
|
|
46
|
+
recipients: BulkRecipient[];
|
|
47
|
+
scheduleAt?: string;
|
|
48
|
+
saveContact?: boolean;
|
|
49
|
+
idempotencyKey?: string;
|
|
50
|
+
}
|
|
51
|
+
interface SendAcceptedResponse {
|
|
52
|
+
messageId: string;
|
|
53
|
+
status: 'queued';
|
|
54
|
+
queuedAt: string;
|
|
55
|
+
}
|
|
56
|
+
interface BulkRejection {
|
|
57
|
+
to: string;
|
|
58
|
+
reason: string;
|
|
59
|
+
}
|
|
60
|
+
interface SendBulkResponse {
|
|
61
|
+
bulkId: string;
|
|
62
|
+
accepted: number;
|
|
63
|
+
rejected: number;
|
|
64
|
+
rejections: BulkRejection[];
|
|
65
|
+
messageIds: string[];
|
|
66
|
+
}
|
|
67
|
+
interface MessageStatusResponse {
|
|
68
|
+
messageId: string;
|
|
69
|
+
status: MessageStatus;
|
|
70
|
+
to: string;
|
|
71
|
+
providerId: string;
|
|
72
|
+
queuedAt: string;
|
|
73
|
+
sentAt: string | null;
|
|
74
|
+
deliveredAt: string | null;
|
|
75
|
+
failedAt: string | null;
|
|
76
|
+
failureCode: FailureCode | null;
|
|
77
|
+
failureReason: string | null;
|
|
78
|
+
}
|
|
79
|
+
interface ProviderSummary {
|
|
80
|
+
id: string;
|
|
81
|
+
name: string;
|
|
82
|
+
phoneNumber: string | null;
|
|
83
|
+
status: string;
|
|
84
|
+
warmupDay: number;
|
|
85
|
+
riskScore: number;
|
|
86
|
+
}
|
|
87
|
+
interface ProviderDailyStats {
|
|
88
|
+
sent: number;
|
|
89
|
+
delivered: number;
|
|
90
|
+
failed: number;
|
|
91
|
+
messagesLimit: number | null;
|
|
92
|
+
newContactsLimit: number | null;
|
|
93
|
+
}
|
|
94
|
+
interface ProviderDetail extends ProviderSummary {
|
|
95
|
+
dailyStats: ProviderDailyStats;
|
|
96
|
+
}
|
|
97
|
+
interface ProviderListResponse {
|
|
98
|
+
providers: ProviderSummary[];
|
|
99
|
+
}
|
|
100
|
+
interface OtpSendParams {
|
|
101
|
+
providerId: string;
|
|
102
|
+
phoneNumber: string;
|
|
103
|
+
codeLength?: number;
|
|
104
|
+
expiresIn?: number;
|
|
105
|
+
brandName?: string;
|
|
106
|
+
template?: string;
|
|
107
|
+
saveContact?: boolean;
|
|
108
|
+
}
|
|
109
|
+
interface OtpSendResponse {
|
|
110
|
+
otpId: string;
|
|
111
|
+
messageId: string;
|
|
112
|
+
expiresAt: string;
|
|
113
|
+
}
|
|
114
|
+
interface OtpVerifyParams {
|
|
115
|
+
otpId: string;
|
|
116
|
+
code: string;
|
|
117
|
+
}
|
|
118
|
+
interface OtpVerifyResponse {
|
|
119
|
+
valid: boolean;
|
|
120
|
+
reason?: OtpVerifyReason;
|
|
121
|
+
attemptsLeft?: number;
|
|
122
|
+
}
|
|
123
|
+
interface WaitForTerminalOptions {
|
|
124
|
+
/** Intervalle entre polls en ms. @default 2000 */
|
|
125
|
+
pollIntervalMs?: number;
|
|
126
|
+
/** Timeout total en ms. @default 120000 */
|
|
127
|
+
timeoutMs?: number;
|
|
128
|
+
}
|
|
129
|
+
declare const TERMINAL_MESSAGE_STATUSES: ReadonlySet<MessageStatus>;
|
|
130
|
+
declare const DEFAULT_BASE_URL = "https://sandbox-api.reachflow.me";
|
|
131
|
+
|
|
132
|
+
interface RequestOptions {
|
|
133
|
+
method: 'GET' | 'POST';
|
|
134
|
+
path: string;
|
|
135
|
+
body?: unknown;
|
|
136
|
+
idempotencyKey?: string;
|
|
137
|
+
}
|
|
138
|
+
interface ResolvedClientConfig {
|
|
139
|
+
apiKey: string;
|
|
140
|
+
baseUrl: string;
|
|
141
|
+
apiPrefix: string;
|
|
142
|
+
timeoutMs: number;
|
|
143
|
+
fetchImpl: typeof fetch;
|
|
144
|
+
maxRetries: number;
|
|
145
|
+
}
|
|
146
|
+
declare class HttpClient {
|
|
147
|
+
private readonly config;
|
|
148
|
+
constructor(config: ResolvedClientConfig);
|
|
149
|
+
request<T>(options: RequestOptions): Promise<T>;
|
|
150
|
+
private requestOnce;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
declare class MessagesResource {
|
|
154
|
+
private readonly http;
|
|
155
|
+
constructor(http: HttpClient);
|
|
156
|
+
/** Envoie un message texte (réponse HTTP 202). */
|
|
157
|
+
send(params: SendMessageParams): Promise<SendAcceptedResponse>;
|
|
158
|
+
/** Envoie un média via URL HTTPS publique (réponse HTTP 202). */
|
|
159
|
+
sendMedia(params: SendMediaParams): Promise<SendAcceptedResponse>;
|
|
160
|
+
/** Envoie un lot de messages (même modèle, destinataires multiples). */
|
|
161
|
+
sendBulk(params: SendBulkParams): Promise<SendBulkResponse>;
|
|
162
|
+
/** Consulte le statut d'un message précédemment accepté. */
|
|
163
|
+
getStatus(messageId: string): Promise<MessageStatusResponse>;
|
|
164
|
+
/**
|
|
165
|
+
* Poll jusqu'à un statut terminal (`sent`, `delivered`, `failed`, `cancelled`).
|
|
166
|
+
* Lance `ReachFlowError` si timeout.
|
|
167
|
+
*/
|
|
168
|
+
waitForTerminal(messageId: string, options?: WaitForTerminalOptions): Promise<MessageStatusResponse>;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
declare class OtpResource {
|
|
172
|
+
private readonly http;
|
|
173
|
+
constructor(http: HttpClient);
|
|
174
|
+
/**
|
|
175
|
+
* Génère et envoie un code OTP par WhatsApp.
|
|
176
|
+
* Le code n'est jamais retourné par l'API — uniquement sur WhatsApp.
|
|
177
|
+
*/
|
|
178
|
+
send(params: OtpSendParams): Promise<OtpSendResponse>;
|
|
179
|
+
/** Vérifie un code saisi par l'utilisateur final. */
|
|
180
|
+
verify(params: OtpVerifyParams): Promise<OtpVerifyResponse>;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
declare class ProvidersResource {
|
|
184
|
+
private readonly http;
|
|
185
|
+
constructor(http: HttpClient);
|
|
186
|
+
/** Liste les numéros WhatsApp accessibles via l'API. */
|
|
187
|
+
list(): Promise<ProviderListResponse>;
|
|
188
|
+
/** Détail d'un provider avec statistiques journalières. */
|
|
189
|
+
get(providerId: string): Promise<ProviderDetail>;
|
|
190
|
+
/**
|
|
191
|
+
* Retourne le premier provider au statut `connected`, ou le premier de la liste.
|
|
192
|
+
* Utile pour les scripts de test / démarrage rapide.
|
|
193
|
+
*/
|
|
194
|
+
findConnected(): Promise<ProviderDetail | ProviderListResponse['providers'][number] | null>;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Client officiel pour l'API publique ReachFlow (REST v1).
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```ts
|
|
202
|
+
* const client = new ReachFlow({ apiKey: process.env.REACHFLOW_API_KEY! });
|
|
203
|
+
* const { providers } = await client.providers.list();
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
declare class ReachFlow {
|
|
207
|
+
readonly messages: MessagesResource;
|
|
208
|
+
readonly providers: ProvidersResource;
|
|
209
|
+
readonly otp: OtpResource;
|
|
210
|
+
private readonly http;
|
|
211
|
+
private readonly config;
|
|
212
|
+
constructor(options: ReachFlowClientOptions);
|
|
213
|
+
/** URL de base configurée (sans `/api/v1`). */
|
|
214
|
+
get baseUrl(): string;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
type ReachFlowErrorCode = 'unauthorized' | 'plan_required' | 'insufficient_scope' | 'rate_limit_exceeded' | 'too_many_auth_failures' | 'validation_error' | 'not_found' | 'api_error' | 'network_error' | 'timeout';
|
|
218
|
+
declare class ReachFlowError extends Error {
|
|
219
|
+
readonly statusCode: number;
|
|
220
|
+
readonly code: ReachFlowErrorCode;
|
|
221
|
+
readonly retryable: boolean;
|
|
222
|
+
readonly retryAfterMs?: number;
|
|
223
|
+
readonly body?: unknown;
|
|
224
|
+
constructor(params: {
|
|
225
|
+
message: string;
|
|
226
|
+
statusCode: number;
|
|
227
|
+
code: ReachFlowErrorCode;
|
|
228
|
+
retryable?: boolean;
|
|
229
|
+
retryAfterMs?: number;
|
|
230
|
+
body?: unknown;
|
|
231
|
+
cause?: unknown;
|
|
232
|
+
});
|
|
233
|
+
static fromResponse(status: number, body: unknown, fallbackMessage?: string): ReachFlowError;
|
|
234
|
+
static network(cause: unknown): ReachFlowError;
|
|
235
|
+
static timeout(timeoutMs: number): ReachFlowError;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export { type BulkRecipient, DEFAULT_BASE_URL, type FailureCode, type MediaType, type MessageStatus, type MessageStatusResponse, type OtpSendParams, type OtpSendResponse, type OtpVerifyParams, type OtpVerifyReason, type OtpVerifyResponse, type ProviderDailyStats, type ProviderDetail, type ProviderListResponse, type ProviderSummary, ReachFlow, type ReachFlowClientOptions, ReachFlowError, type ReachFlowErrorCode, type SendAcceptedResponse, type SendBulkParams, type SendBulkResponse, type SendMediaParams, type SendMessageParams, TERMINAL_MESSAGE_STATUSES, type WaitForTerminalOptions };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/** Statut de cycle de vie d'un message API. */
|
|
2
|
+
type MessageStatus = 'queued' | 'processing' | 'sent' | 'delivered' | 'failed' | 'cancelled';
|
|
3
|
+
type MediaType = 'image' | 'document' | 'audio' | 'video';
|
|
4
|
+
type FailureCode = 'warmup_daily_limit' | 'risk_circuit_open' | 'provider_disconnected' | 'provider_banned' | 'send_not_allowed' | 'instance_busy' | 'delivery_timeout' | 'delivery_failed' | 'send_error' | 'provider_not_found';
|
|
5
|
+
type OtpVerifyReason = 'invalidated' | 'already_used' | 'expired' | 'max_attempts_reached' | 'invalid_code' | 'not_found';
|
|
6
|
+
interface ReachFlowClientOptions {
|
|
7
|
+
/** Clé API `rfl_live_…` ou `rfl_test_…`. */
|
|
8
|
+
apiKey: string;
|
|
9
|
+
/**
|
|
10
|
+
* URL de base sans `/api/v1` (défaut : sandbox ReachFlow).
|
|
11
|
+
* @default "https://sandbox-api.reachflow.me"
|
|
12
|
+
*/
|
|
13
|
+
baseUrl?: string;
|
|
14
|
+
/** Timeout HTTP en millisecondes. @default 30000 */
|
|
15
|
+
timeoutMs?: number;
|
|
16
|
+
/** Implémentation fetch (tests, Node < 18). @default global fetch */
|
|
17
|
+
fetch?: typeof fetch;
|
|
18
|
+
/** Nombre max de retries sur 429 / 5xx retryables. @default 2 */
|
|
19
|
+
maxRetries?: number;
|
|
20
|
+
}
|
|
21
|
+
interface SendMessageParams {
|
|
22
|
+
providerId: string;
|
|
23
|
+
to: string;
|
|
24
|
+
message: string;
|
|
25
|
+
variables?: Record<string, string>;
|
|
26
|
+
scheduleAt?: string;
|
|
27
|
+
saveContact?: boolean;
|
|
28
|
+
idempotencyKey?: string;
|
|
29
|
+
}
|
|
30
|
+
interface SendMediaParams {
|
|
31
|
+
providerId: string;
|
|
32
|
+
to: string;
|
|
33
|
+
mediaUrl: string;
|
|
34
|
+
mediaType: MediaType;
|
|
35
|
+
caption?: string;
|
|
36
|
+
saveContact?: boolean;
|
|
37
|
+
idempotencyKey?: string;
|
|
38
|
+
}
|
|
39
|
+
interface BulkRecipient {
|
|
40
|
+
to: string;
|
|
41
|
+
variables?: Record<string, string>;
|
|
42
|
+
}
|
|
43
|
+
interface SendBulkParams {
|
|
44
|
+
providerId: string;
|
|
45
|
+
messageTemplate: string;
|
|
46
|
+
recipients: BulkRecipient[];
|
|
47
|
+
scheduleAt?: string;
|
|
48
|
+
saveContact?: boolean;
|
|
49
|
+
idempotencyKey?: string;
|
|
50
|
+
}
|
|
51
|
+
interface SendAcceptedResponse {
|
|
52
|
+
messageId: string;
|
|
53
|
+
status: 'queued';
|
|
54
|
+
queuedAt: string;
|
|
55
|
+
}
|
|
56
|
+
interface BulkRejection {
|
|
57
|
+
to: string;
|
|
58
|
+
reason: string;
|
|
59
|
+
}
|
|
60
|
+
interface SendBulkResponse {
|
|
61
|
+
bulkId: string;
|
|
62
|
+
accepted: number;
|
|
63
|
+
rejected: number;
|
|
64
|
+
rejections: BulkRejection[];
|
|
65
|
+
messageIds: string[];
|
|
66
|
+
}
|
|
67
|
+
interface MessageStatusResponse {
|
|
68
|
+
messageId: string;
|
|
69
|
+
status: MessageStatus;
|
|
70
|
+
to: string;
|
|
71
|
+
providerId: string;
|
|
72
|
+
queuedAt: string;
|
|
73
|
+
sentAt: string | null;
|
|
74
|
+
deliveredAt: string | null;
|
|
75
|
+
failedAt: string | null;
|
|
76
|
+
failureCode: FailureCode | null;
|
|
77
|
+
failureReason: string | null;
|
|
78
|
+
}
|
|
79
|
+
interface ProviderSummary {
|
|
80
|
+
id: string;
|
|
81
|
+
name: string;
|
|
82
|
+
phoneNumber: string | null;
|
|
83
|
+
status: string;
|
|
84
|
+
warmupDay: number;
|
|
85
|
+
riskScore: number;
|
|
86
|
+
}
|
|
87
|
+
interface ProviderDailyStats {
|
|
88
|
+
sent: number;
|
|
89
|
+
delivered: number;
|
|
90
|
+
failed: number;
|
|
91
|
+
messagesLimit: number | null;
|
|
92
|
+
newContactsLimit: number | null;
|
|
93
|
+
}
|
|
94
|
+
interface ProviderDetail extends ProviderSummary {
|
|
95
|
+
dailyStats: ProviderDailyStats;
|
|
96
|
+
}
|
|
97
|
+
interface ProviderListResponse {
|
|
98
|
+
providers: ProviderSummary[];
|
|
99
|
+
}
|
|
100
|
+
interface OtpSendParams {
|
|
101
|
+
providerId: string;
|
|
102
|
+
phoneNumber: string;
|
|
103
|
+
codeLength?: number;
|
|
104
|
+
expiresIn?: number;
|
|
105
|
+
brandName?: string;
|
|
106
|
+
template?: string;
|
|
107
|
+
saveContact?: boolean;
|
|
108
|
+
}
|
|
109
|
+
interface OtpSendResponse {
|
|
110
|
+
otpId: string;
|
|
111
|
+
messageId: string;
|
|
112
|
+
expiresAt: string;
|
|
113
|
+
}
|
|
114
|
+
interface OtpVerifyParams {
|
|
115
|
+
otpId: string;
|
|
116
|
+
code: string;
|
|
117
|
+
}
|
|
118
|
+
interface OtpVerifyResponse {
|
|
119
|
+
valid: boolean;
|
|
120
|
+
reason?: OtpVerifyReason;
|
|
121
|
+
attemptsLeft?: number;
|
|
122
|
+
}
|
|
123
|
+
interface WaitForTerminalOptions {
|
|
124
|
+
/** Intervalle entre polls en ms. @default 2000 */
|
|
125
|
+
pollIntervalMs?: number;
|
|
126
|
+
/** Timeout total en ms. @default 120000 */
|
|
127
|
+
timeoutMs?: number;
|
|
128
|
+
}
|
|
129
|
+
declare const TERMINAL_MESSAGE_STATUSES: ReadonlySet<MessageStatus>;
|
|
130
|
+
declare const DEFAULT_BASE_URL = "https://sandbox-api.reachflow.me";
|
|
131
|
+
|
|
132
|
+
interface RequestOptions {
|
|
133
|
+
method: 'GET' | 'POST';
|
|
134
|
+
path: string;
|
|
135
|
+
body?: unknown;
|
|
136
|
+
idempotencyKey?: string;
|
|
137
|
+
}
|
|
138
|
+
interface ResolvedClientConfig {
|
|
139
|
+
apiKey: string;
|
|
140
|
+
baseUrl: string;
|
|
141
|
+
apiPrefix: string;
|
|
142
|
+
timeoutMs: number;
|
|
143
|
+
fetchImpl: typeof fetch;
|
|
144
|
+
maxRetries: number;
|
|
145
|
+
}
|
|
146
|
+
declare class HttpClient {
|
|
147
|
+
private readonly config;
|
|
148
|
+
constructor(config: ResolvedClientConfig);
|
|
149
|
+
request<T>(options: RequestOptions): Promise<T>;
|
|
150
|
+
private requestOnce;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
declare class MessagesResource {
|
|
154
|
+
private readonly http;
|
|
155
|
+
constructor(http: HttpClient);
|
|
156
|
+
/** Envoie un message texte (réponse HTTP 202). */
|
|
157
|
+
send(params: SendMessageParams): Promise<SendAcceptedResponse>;
|
|
158
|
+
/** Envoie un média via URL HTTPS publique (réponse HTTP 202). */
|
|
159
|
+
sendMedia(params: SendMediaParams): Promise<SendAcceptedResponse>;
|
|
160
|
+
/** Envoie un lot de messages (même modèle, destinataires multiples). */
|
|
161
|
+
sendBulk(params: SendBulkParams): Promise<SendBulkResponse>;
|
|
162
|
+
/** Consulte le statut d'un message précédemment accepté. */
|
|
163
|
+
getStatus(messageId: string): Promise<MessageStatusResponse>;
|
|
164
|
+
/**
|
|
165
|
+
* Poll jusqu'à un statut terminal (`sent`, `delivered`, `failed`, `cancelled`).
|
|
166
|
+
* Lance `ReachFlowError` si timeout.
|
|
167
|
+
*/
|
|
168
|
+
waitForTerminal(messageId: string, options?: WaitForTerminalOptions): Promise<MessageStatusResponse>;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
declare class OtpResource {
|
|
172
|
+
private readonly http;
|
|
173
|
+
constructor(http: HttpClient);
|
|
174
|
+
/**
|
|
175
|
+
* Génère et envoie un code OTP par WhatsApp.
|
|
176
|
+
* Le code n'est jamais retourné par l'API — uniquement sur WhatsApp.
|
|
177
|
+
*/
|
|
178
|
+
send(params: OtpSendParams): Promise<OtpSendResponse>;
|
|
179
|
+
/** Vérifie un code saisi par l'utilisateur final. */
|
|
180
|
+
verify(params: OtpVerifyParams): Promise<OtpVerifyResponse>;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
declare class ProvidersResource {
|
|
184
|
+
private readonly http;
|
|
185
|
+
constructor(http: HttpClient);
|
|
186
|
+
/** Liste les numéros WhatsApp accessibles via l'API. */
|
|
187
|
+
list(): Promise<ProviderListResponse>;
|
|
188
|
+
/** Détail d'un provider avec statistiques journalières. */
|
|
189
|
+
get(providerId: string): Promise<ProviderDetail>;
|
|
190
|
+
/**
|
|
191
|
+
* Retourne le premier provider au statut `connected`, ou le premier de la liste.
|
|
192
|
+
* Utile pour les scripts de test / démarrage rapide.
|
|
193
|
+
*/
|
|
194
|
+
findConnected(): Promise<ProviderDetail | ProviderListResponse['providers'][number] | null>;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Client officiel pour l'API publique ReachFlow (REST v1).
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```ts
|
|
202
|
+
* const client = new ReachFlow({ apiKey: process.env.REACHFLOW_API_KEY! });
|
|
203
|
+
* const { providers } = await client.providers.list();
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
declare class ReachFlow {
|
|
207
|
+
readonly messages: MessagesResource;
|
|
208
|
+
readonly providers: ProvidersResource;
|
|
209
|
+
readonly otp: OtpResource;
|
|
210
|
+
private readonly http;
|
|
211
|
+
private readonly config;
|
|
212
|
+
constructor(options: ReachFlowClientOptions);
|
|
213
|
+
/** URL de base configurée (sans `/api/v1`). */
|
|
214
|
+
get baseUrl(): string;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
type ReachFlowErrorCode = 'unauthorized' | 'plan_required' | 'insufficient_scope' | 'rate_limit_exceeded' | 'too_many_auth_failures' | 'validation_error' | 'not_found' | 'api_error' | 'network_error' | 'timeout';
|
|
218
|
+
declare class ReachFlowError extends Error {
|
|
219
|
+
readonly statusCode: number;
|
|
220
|
+
readonly code: ReachFlowErrorCode;
|
|
221
|
+
readonly retryable: boolean;
|
|
222
|
+
readonly retryAfterMs?: number;
|
|
223
|
+
readonly body?: unknown;
|
|
224
|
+
constructor(params: {
|
|
225
|
+
message: string;
|
|
226
|
+
statusCode: number;
|
|
227
|
+
code: ReachFlowErrorCode;
|
|
228
|
+
retryable?: boolean;
|
|
229
|
+
retryAfterMs?: number;
|
|
230
|
+
body?: unknown;
|
|
231
|
+
cause?: unknown;
|
|
232
|
+
});
|
|
233
|
+
static fromResponse(status: number, body: unknown, fallbackMessage?: string): ReachFlowError;
|
|
234
|
+
static network(cause: unknown): ReachFlowError;
|
|
235
|
+
static timeout(timeoutMs: number): ReachFlowError;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export { type BulkRecipient, DEFAULT_BASE_URL, type FailureCode, type MediaType, type MessageStatus, type MessageStatusResponse, type OtpSendParams, type OtpSendResponse, type OtpVerifyParams, type OtpVerifyReason, type OtpVerifyResponse, type ProviderDailyStats, type ProviderDetail, type ProviderListResponse, type ProviderSummary, ReachFlow, type ReachFlowClientOptions, ReachFlowError, type ReachFlowErrorCode, type SendAcceptedResponse, type SendBulkParams, type SendBulkResponse, type SendMediaParams, type SendMessageParams, TERMINAL_MESSAGE_STATUSES, type WaitForTerminalOptions };
|