@marcohefti/request-network-api-client 0.5.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.
Files changed (39) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +97 -0
  3. package/dist/cjs/domains/client-ids/index.js +309 -0
  4. package/dist/cjs/domains/client-ids/index.js.map +1 -0
  5. package/dist/cjs/domains/currencies/index.js +347 -0
  6. package/dist/cjs/domains/currencies/index.js.map +1 -0
  7. package/dist/cjs/domains/payer/index.js +450 -0
  8. package/dist/cjs/domains/payer/index.js.map +1 -0
  9. package/dist/cjs/domains/payouts/index.js +304 -0
  10. package/dist/cjs/domains/payouts/index.js.map +1 -0
  11. package/dist/cjs/domains/requests/index.js +544 -0
  12. package/dist/cjs/domains/requests/index.js.map +1 -0
  13. package/dist/cjs/index.js +3466 -0
  14. package/dist/cjs/index.js.map +1 -0
  15. package/dist/esm/domains/client-ids/index.d.mts +2 -0
  16. package/dist/esm/domains/client-ids/index.js +307 -0
  17. package/dist/esm/domains/client-ids/index.js.map +1 -0
  18. package/dist/esm/domains/currencies/index.d.mts +3 -0
  19. package/dist/esm/domains/currencies/index.js +344 -0
  20. package/dist/esm/domains/currencies/index.js.map +1 -0
  21. package/dist/esm/domains/payer/index.d.mts +2 -0
  22. package/dist/esm/domains/payer/index.js +446 -0
  23. package/dist/esm/domains/payer/index.js.map +1 -0
  24. package/dist/esm/domains/payouts/index.d.mts +2 -0
  25. package/dist/esm/domains/payouts/index.js +302 -0
  26. package/dist/esm/domains/payouts/index.js.map +1 -0
  27. package/dist/esm/domains/requests/index.d.mts +2 -0
  28. package/dist/esm/domains/requests/index.js +542 -0
  29. package/dist/esm/domains/requests/index.js.map +1 -0
  30. package/dist/esm/index-BmWmfcnn.d.mts +113 -0
  31. package/dist/esm/index-CNK36ZX5.d.mts +26 -0
  32. package/dist/esm/index-Cd7x0Hv-.d.mts +39 -0
  33. package/dist/esm/index-Q2g0D7V8.d.mts +79 -0
  34. package/dist/esm/index-ziziGrHN.d.mts +220 -0
  35. package/dist/esm/index.d.mts +5478 -0
  36. package/dist/esm/index.js +3435 -0
  37. package/dist/esm/index.js.map +1 -0
  38. package/dist/esm/openapi-types-CtUFCrk4.d.mts +3368 -0
  39. package/package.json +168 -0
@@ -0,0 +1,3466 @@
1
+ 'use strict';
2
+
3
+ var zod = require('zod');
4
+ var buffer = require('buffer');
5
+ var crypto = require('crypto');
6
+
7
+ var __defProp = Object.defineProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+
13
+ // src/core/errors/request-api.error.ts
14
+ var REQUEST_ERROR_NAME = "RequestApiError";
15
+ var RequestApiError = class extends Error {
16
+ status;
17
+ code;
18
+ detail;
19
+ errors;
20
+ requestId;
21
+ correlationId;
22
+ retryAfterMs;
23
+ headers;
24
+ meta;
25
+ constructor(metadata) {
26
+ super(metadata.message, { cause: metadata.cause });
27
+ this.name = REQUEST_ERROR_NAME;
28
+ this.status = metadata.status;
29
+ this.code = metadata.code;
30
+ this.detail = metadata.detail;
31
+ this.errors = metadata.errors;
32
+ this.requestId = metadata.requestId;
33
+ this.correlationId = metadata.correlationId;
34
+ this.retryAfterMs = metadata.retryAfterMs;
35
+ this.headers = metadata.headers;
36
+ this.meta = metadata.meta;
37
+ }
38
+ toJSON() {
39
+ return {
40
+ name: this.name,
41
+ message: this.message,
42
+ status: this.status,
43
+ code: this.code,
44
+ detail: this.detail,
45
+ errors: this.errors,
46
+ requestId: this.requestId,
47
+ correlationId: this.correlationId,
48
+ retryAfterMs: this.retryAfterMs,
49
+ headers: this.headers,
50
+ meta: this.meta
51
+ };
52
+ }
53
+ };
54
+ var REQUEST_ID_HEADER = "x-request-id";
55
+ var CORRELATION_ID_HEADER = "x-correlation-id";
56
+ var RETRY_AFTER_HEADER = "retry-after";
57
+ function normaliseHeaders(headers) {
58
+ if (!headers) {
59
+ return void 0;
60
+ }
61
+ if (typeof headers.get === "function") {
62
+ const lookup = headers;
63
+ return {
64
+ [REQUEST_ID_HEADER]: lookup.get(REQUEST_ID_HEADER),
65
+ [CORRELATION_ID_HEADER]: lookup.get(CORRELATION_ID_HEADER),
66
+ [RETRY_AFTER_HEADER]: lookup.get(RETRY_AFTER_HEADER)
67
+ };
68
+ }
69
+ return {
70
+ [REQUEST_ID_HEADER]: headers[REQUEST_ID_HEADER],
71
+ [CORRELATION_ID_HEADER]: headers[CORRELATION_ID_HEADER],
72
+ [RETRY_AFTER_HEADER]: headers[RETRY_AFTER_HEADER]
73
+ };
74
+ }
75
+ function parseRetryAfter(headerValue) {
76
+ if (!headerValue) {
77
+ return void 0;
78
+ }
79
+ const numeric = Number(headerValue);
80
+ if (!Number.isNaN(numeric)) {
81
+ return numeric * 1e3;
82
+ }
83
+ const parsedDate = Date.parse(headerValue);
84
+ if (Number.isNaN(parsedDate)) {
85
+ return void 0;
86
+ }
87
+ const delay = parsedDate - Date.now();
88
+ return delay > 0 ? delay : 0;
89
+ }
90
+ function buildRequestApiError(options) {
91
+ const { payload, status, headers, fallbackMessage, meta, cause } = options;
92
+ const normalisedHeaders = normaliseHeaders(headers);
93
+ const retryAfterHeader = normalisedHeaders?.[RETRY_AFTER_HEADER];
94
+ const retryAfterMs = parseRetryAfter(retryAfterHeader);
95
+ const code = typeof payload?.code === "string" && payload.code.length > 0 ? payload.code : `HTTP_${String(status)}`;
96
+ const message = typeof payload?.message === "string" && payload.message.length > 0 ? payload.message : fallbackMessage ?? "Request Network API error";
97
+ const maybeErrors = Array.isArray(payload?.errors) ? payload.errors : void 0;
98
+ const errors = maybeErrors?.filter(Boolean);
99
+ return new RequestApiError({
100
+ status,
101
+ code,
102
+ message,
103
+ detail: payload?.detail,
104
+ errors,
105
+ requestId: normalisedHeaders?.[REQUEST_ID_HEADER],
106
+ correlationId: normalisedHeaders?.[CORRELATION_ID_HEADER],
107
+ retryAfterMs,
108
+ headers: normalisedHeaders,
109
+ meta,
110
+ cause
111
+ });
112
+ }
113
+ function isRequestApiError(error) {
114
+ return error instanceof RequestApiError || typeof error === "object" && error !== null && error.name === REQUEST_ERROR_NAME;
115
+ }
116
+
117
+ // src/core/http/retry.policy.ts
118
+ var DEFAULT_RETRY_CONFIG = {
119
+ maxAttempts: 3,
120
+ initialDelayMs: 250,
121
+ maxDelayMs: 5e3,
122
+ backoffFactor: 2,
123
+ jitter: "full",
124
+ retryStatusCodes: [408, 425, 429, 500, 502, 503, 504],
125
+ allowedMethods: ["GET", "HEAD", "OPTIONS", "PUT", "DELETE"]
126
+ };
127
+ function shouldRetryRequest(config, input) {
128
+ if (config.maxAttempts <= 1) {
129
+ return { retry: false, reason: "retries-disabled" };
130
+ }
131
+ if (input.attempt >= config.maxAttempts) {
132
+ return { retry: false, reason: "max-attempts-exceeded" };
133
+ }
134
+ if (config.shouldRetry) {
135
+ const decision = config.shouldRetry(input);
136
+ if (!decision) {
137
+ return { retry: false, reason: "predicate-declined" };
138
+ }
139
+ } else {
140
+ const statusFromError = isRequestApiError(input.error) ? input.error.status : void 0;
141
+ const status = input.response?.status ?? statusFromError;
142
+ if (typeof status !== "number" || !config.retryStatusCodes.includes(status)) {
143
+ return { retry: false, reason: "status-not-retriable" };
144
+ }
145
+ }
146
+ const delay = computeRetryDelay(config, input);
147
+ return { retry: true, delayMs: delay, reason: "retry-scheduled" };
148
+ }
149
+ function computeRetryDelay(config, input) {
150
+ const retryAfter = input.response?.retryAfterMs ?? extractRetryAfterFromError(input.error);
151
+ if (retryAfter !== void 0 && retryAfter >= 0) {
152
+ return clampDelay(retryAfter, config.maxDelayMs);
153
+ }
154
+ const attemptIndex = input.attempt - 1;
155
+ const exponential = config.initialDelayMs * Math.pow(config.backoffFactor, attemptIndex);
156
+ const jittered = applyJitter(exponential, config.jitter);
157
+ return clampDelay(jittered, config.maxDelayMs);
158
+ }
159
+ function hasRetryAfter(x) {
160
+ return typeof x === "object" && x !== null && "retryAfterMs" in x;
161
+ }
162
+ function extractRetryAfterFromError(err) {
163
+ if (isRequestApiError(err)) {
164
+ return err.retryAfterMs;
165
+ }
166
+ if (hasRetryAfter(err) && typeof err.retryAfterMs === "number") {
167
+ return err.retryAfterMs;
168
+ }
169
+ return void 0;
170
+ }
171
+ function clampDelay(delay, maxDelay) {
172
+ if (delay < 0) {
173
+ return 0;
174
+ }
175
+ return delay > maxDelay ? maxDelay : delay;
176
+ }
177
+ function applyJitter(delay, jitter) {
178
+ if (delay <= 0) {
179
+ return 0;
180
+ }
181
+ switch (jitter) {
182
+ case "none": {
183
+ return delay;
184
+ }
185
+ case "half": {
186
+ const min = delay / 2;
187
+ return randomInRange(min, delay);
188
+ }
189
+ case "full":
190
+ default: {
191
+ return randomInRange(0, delay);
192
+ }
193
+ }
194
+ }
195
+ function randomInRange(min, max) {
196
+ if (min >= max) {
197
+ return min;
198
+ }
199
+ return min + Math.random() * (max - min);
200
+ }
201
+
202
+ // src/validation/schema.registry.ts
203
+ function serialiseKey(key) {
204
+ const variant = key.variant ?? "default";
205
+ const status = key.status?.toString() ?? "any";
206
+ return `${key.operationId}|${key.kind}|${variant}|${status}`;
207
+ }
208
+ var SchemaRegistry = class {
209
+ store = /* @__PURE__ */ new Map();
210
+ register(entry) {
211
+ const id = serialiseKey(entry.key);
212
+ this.store.set(id, entry);
213
+ }
214
+ get(key) {
215
+ const id = serialiseKey(key);
216
+ return this.store.get(id)?.schema;
217
+ }
218
+ /**
219
+ * Removes every registered schema — primarily useful in tests.
220
+ */
221
+ clear() {
222
+ this.store.clear();
223
+ }
224
+ };
225
+ var schemaRegistry = new SchemaRegistry();
226
+
227
+ // src/validation/zod.helpers.ts
228
+ var ValidationError = class extends Error {
229
+ constructor(message, cause) {
230
+ super(message, { cause });
231
+ this.cause = cause;
232
+ this.name = "ClientValidationError";
233
+ }
234
+ };
235
+ function parseWithSchema(options) {
236
+ const { schema, value, description } = options;
237
+ const outcome = schema.safeParse(value);
238
+ if (outcome.success) {
239
+ return { success: true, data: outcome.data };
240
+ }
241
+ const error = new ValidationError(description ?? "Validation failed", outcome.error);
242
+ return { success: false, error };
243
+ }
244
+ function parseWithRegistry(options) {
245
+ const schema = schemaRegistry.get(options.key);
246
+ if (!schema) {
247
+ if (options.skipOnMissingSchema) {
248
+ return { success: true, data: options.value };
249
+ }
250
+ return { success: false, error: new ValidationError(`No schema registered for ${options.key.operationId}`) };
251
+ }
252
+ return parseWithSchema({ schema, value: options.value, description: options.description });
253
+ }
254
+
255
+ // src/core/http/http.types.ts
256
+ function toQueryItems(value) {
257
+ const items = Array.isArray(value) ? value : [value];
258
+ return items.map((item) => String(item));
259
+ }
260
+ function resolveQuerySerializer(serializer) {
261
+ if (!serializer || serializer === "comma") {
262
+ return ({ key, value, set }) => {
263
+ const joined = toQueryItems(value).join(",");
264
+ set(key, joined);
265
+ };
266
+ }
267
+ if (serializer === "repeat") {
268
+ return ({ key, value, append }) => {
269
+ const items = toQueryItems(value);
270
+ for (const item of items) {
271
+ append(key, item);
272
+ }
273
+ };
274
+ }
275
+ return serializer;
276
+ }
277
+ function buildUrl(baseUrl, path, query, serializer) {
278
+ const base = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
279
+ const cleanPath = path.startsWith("/") ? path : `/${path}`;
280
+ const url = new URL(base + cleanPath);
281
+ if (!query) return url.toString();
282
+ const serialize = resolveQuerySerializer(serializer);
283
+ const params = url.searchParams;
284
+ for (const key of Object.keys(query)) {
285
+ const raw = query[key];
286
+ if (raw === void 0) continue;
287
+ serialize({
288
+ key,
289
+ value: raw,
290
+ set: (k, value) => {
291
+ params.delete(k);
292
+ params.set(k, value);
293
+ },
294
+ append: (k, value) => {
295
+ params.append(k, value);
296
+ }
297
+ });
298
+ }
299
+ return url.toString();
300
+ }
301
+ function composeInterceptors(terminal, interceptors = []) {
302
+ return interceptors.reduceRight((next, interceptor) => {
303
+ return (req) => interceptor(req, next);
304
+ }, terminal);
305
+ }
306
+
307
+ // src/core/auth/credential-header.builder.ts
308
+ function buildCredentialHeaders(options) {
309
+ const headers = {};
310
+ if (options.apiKey) headers["x-api-key"] = options.apiKey;
311
+ if (options.clientId) headers["x-client-id"] = options.clientId;
312
+ if (options.origin) headers["Origin"] = options.origin;
313
+ return headers;
314
+ }
315
+
316
+ // src/core/http/adapters/adapter.utils.ts
317
+ function headersToRecord(headers) {
318
+ const out = {};
319
+ headers.forEach((value, key) => {
320
+ out[key.toLowerCase()] = value;
321
+ });
322
+ return out;
323
+ }
324
+ function resolveSignal(options) {
325
+ const { signal, timeoutMs } = options;
326
+ if (timeoutMs === void 0) {
327
+ return { signal, dispose: () => {
328
+ } };
329
+ }
330
+ const controller = new AbortController();
331
+ let timer;
332
+ const abortForTimeout = () => {
333
+ controller.abort(new Error(`Request timed out after ${String(timeoutMs)}ms`));
334
+ };
335
+ if (timeoutMs <= 0) {
336
+ abortForTimeout();
337
+ } else {
338
+ timer = setTimeout(abortForTimeout, timeoutMs);
339
+ }
340
+ const cleanupTimer = () => {
341
+ if (timer) clearTimeout(timer);
342
+ };
343
+ controller.signal.addEventListener("abort", cleanupTimer, { once: true });
344
+ let removeAbortListener;
345
+ if (signal) {
346
+ if (signal.aborted) {
347
+ cleanupTimer();
348
+ controller.abort(signal.reason);
349
+ } else {
350
+ const onAbort = () => {
351
+ cleanupTimer();
352
+ controller.abort(signal.reason);
353
+ };
354
+ signal.addEventListener("abort", onAbort, { once: true });
355
+ removeAbortListener = () => {
356
+ signal.removeEventListener("abort", onAbort);
357
+ };
358
+ }
359
+ }
360
+ const dispose = () => {
361
+ cleanupTimer();
362
+ if (removeAbortListener) {
363
+ removeAbortListener();
364
+ }
365
+ };
366
+ return { signal: controller.signal, dispose };
367
+ }
368
+ function createFetchInit(request) {
369
+ const headers = { ...request.headers ?? {} };
370
+ const init = {
371
+ method: request.method,
372
+ headers
373
+ };
374
+ if (request.body !== void 0) {
375
+ const body = request.body;
376
+ const isFormData = typeof FormData !== "undefined" && body instanceof FormData;
377
+ const isBlob = typeof Blob !== "undefined" && body instanceof Blob;
378
+ const isUint8 = body instanceof Uint8Array;
379
+ const isArrayBuffer = typeof ArrayBuffer !== "undefined" && body instanceof ArrayBuffer;
380
+ if (typeof body === "string" || isFormData || isBlob || isUint8 || isArrayBuffer) {
381
+ init.body = body;
382
+ } else {
383
+ init.body = JSON.stringify(body);
384
+ headers["content-type"] ??= "application/json";
385
+ }
386
+ }
387
+ const { signal, dispose } = resolveSignal({ signal: request.signal, timeoutMs: request.timeoutMs });
388
+ if (signal) {
389
+ init.signal = signal;
390
+ }
391
+ return { init, dispose };
392
+ }
393
+
394
+ // src/core/http/adapters/node-fetch.adapter.ts
395
+ var nodeFetchAdapter = {
396
+ async send(request) {
397
+ const { init, dispose } = createFetchInit(request);
398
+ try {
399
+ const res = await fetch(request.url, init);
400
+ const respHeaders = headersToRecord(res.headers);
401
+ const contentType = respHeaders["content-type"] ?? "";
402
+ let data;
403
+ let text;
404
+ if (res.status !== 204) {
405
+ try {
406
+ if (contentType.includes("application/json")) {
407
+ data = await res.json();
408
+ } else {
409
+ text = await res.text();
410
+ }
411
+ } catch {
412
+ }
413
+ }
414
+ const normalized = {
415
+ status: res.status,
416
+ ok: res.ok,
417
+ headers: respHeaders,
418
+ data,
419
+ text
420
+ };
421
+ return normalized;
422
+ } finally {
423
+ dispose();
424
+ }
425
+ }
426
+ };
427
+
428
+ // src/core/http/interceptors/logger.utils.ts
429
+ var LEVEL_RANK = {
430
+ silent: 0,
431
+ error: 1,
432
+ info: 2,
433
+ debug: 3
434
+ };
435
+ function shouldLog(level, threshold) {
436
+ return LEVEL_RANK[level] >= LEVEL_RANK[threshold];
437
+ }
438
+
439
+ // src/core/http/interceptors/logging.interceptor.ts
440
+ function createLoggingInterceptor(options) {
441
+ const log = options?.logger;
442
+ const level = options?.level ?? "info";
443
+ const EVENT_LEVEL = {
444
+ "request:start": "debug",
445
+ "request:response": "info",
446
+ "request:error": "error"
447
+ };
448
+ const emit = (event, meta) => {
449
+ if (!log) return;
450
+ const threshold = EVENT_LEVEL[event];
451
+ if (!shouldLog(level, threshold)) return;
452
+ log(event, meta);
453
+ };
454
+ return async (req, next) => {
455
+ const startedAt = Date.now();
456
+ emit("request:start", { method: req.method, url: req.url, meta: req.meta });
457
+ try {
458
+ const res = await next(req);
459
+ const durationMs = Date.now() - startedAt;
460
+ emit("request:response", { method: req.method, url: req.url, status: res.status, ok: res.ok, durationMs, meta: req.meta });
461
+ return res;
462
+ } catch (error) {
463
+ const durationMs = Date.now() - startedAt;
464
+ emit("request:error", { method: req.method, url: req.url, durationMs, error, meta: req.meta });
465
+ throw error;
466
+ }
467
+ };
468
+ }
469
+
470
+ // src/core/http/interceptors/retry.interceptor.ts
471
+ function sleep(ms) {
472
+ return new Promise((resolve) => setTimeout(resolve, ms));
473
+ }
474
+ function createRetryInterceptor(options) {
475
+ const cfg = { ...DEFAULT_RETRY_CONFIG, ...options?.config ?? {} };
476
+ const allowed = new Set(cfg.allowedMethods ?? ["GET", "HEAD", "OPTIONS", "PUT", "DELETE"]);
477
+ const log = options?.logger;
478
+ const level = options?.logLevel ?? "info";
479
+ const RETRY_EVENT = "request:retry";
480
+ const RATE_LIMIT_EVENT = "rate-limit";
481
+ const DEFAULT_RETRY_REASON = "retry-scheduled";
482
+ const emit = (event, meta) => {
483
+ const threshold = event === RETRY_EVENT ? "info" : "info";
484
+ if (!log) return;
485
+ if (!shouldLog(level, threshold)) return;
486
+ log(event, meta);
487
+ };
488
+ const parseRetryAfterMs = (headers) => {
489
+ if (!headers) return void 0;
490
+ const header = headers["retry-after"] ?? headers["Retry-After"];
491
+ return parseRetryAfter(header);
492
+ };
493
+ const scheduleRetry = async (delayMs, meta) => {
494
+ emit(RETRY_EVENT, { ...meta, reason: meta.reason ?? DEFAULT_RETRY_REASON });
495
+ if (delayMs > 0) {
496
+ await sleep(delayMs);
497
+ }
498
+ };
499
+ const maybeHandleResponse = async ({
500
+ res,
501
+ attempt,
502
+ context,
503
+ isAllowedMethod
504
+ }) => {
505
+ if (res.ok) {
506
+ return false;
507
+ }
508
+ const retryAfterMs = parseRetryAfterMs(res.headers);
509
+ if (res.status === 429) {
510
+ emit(RATE_LIMIT_EVENT, { ...context, status: res.status, attempt, retryAfterMs });
511
+ }
512
+ const decision = isAllowedMethod ? shouldRetryRequest(cfg, { attempt, response: { status: res.status, headers: res.headers, retryAfterMs } }) : { retry: false };
513
+ if (!decision.retry) {
514
+ return false;
515
+ }
516
+ const delay = decision.delayMs ?? computeRetryDelay(cfg, { attempt, response: { status: res.status, headers: res.headers, retryAfterMs } });
517
+ await scheduleRetry(delay, {
518
+ ...context,
519
+ attempt,
520
+ nextAttempt: attempt + 1,
521
+ status: res.status,
522
+ delayMs: delay,
523
+ reason: decision.reason,
524
+ retryAfterMs
525
+ });
526
+ return true;
527
+ };
528
+ const maybeHandleError = async ({
529
+ error,
530
+ attempt,
531
+ context
532
+ }) => {
533
+ const decision = shouldRetryRequest(cfg, { attempt, error });
534
+ if (!decision.retry) {
535
+ return false;
536
+ }
537
+ const delay = decision.delayMs ?? computeRetryDelay(cfg, { attempt, error });
538
+ await scheduleRetry(delay, {
539
+ ...context,
540
+ attempt,
541
+ nextAttempt: attempt + 1,
542
+ delayMs: delay,
543
+ reason: decision.reason,
544
+ error
545
+ });
546
+ return true;
547
+ };
548
+ return async function retryInterceptor(req, next) {
549
+ const isAllowedMethod = allowed.has(req.method);
550
+ for (let attempt = 1; attempt <= cfg.maxAttempts; attempt++) {
551
+ try {
552
+ const res = await next(req);
553
+ const shouldRetry = await maybeHandleResponse({
554
+ res,
555
+ attempt,
556
+ context: { method: req.method, url: req.url, meta: req.meta },
557
+ isAllowedMethod
558
+ });
559
+ if (!shouldRetry) {
560
+ return res;
561
+ }
562
+ continue;
563
+ } catch (error) {
564
+ const shouldRetry = await maybeHandleError({
565
+ error,
566
+ attempt,
567
+ context: { method: req.method, url: req.url, meta: req.meta }
568
+ });
569
+ if (shouldRetry) {
570
+ continue;
571
+ }
572
+ throw error;
573
+ }
574
+ }
575
+ return next(req);
576
+ };
577
+ }
578
+
579
+ // src/core/http/validation.config.ts
580
+ var DEFAULT_RUNTIME_VALIDATION = {
581
+ requests: true,
582
+ responses: true,
583
+ errors: true
584
+ };
585
+ function normaliseBoolean(flag, fallback) {
586
+ return typeof flag === "boolean" ? flag : fallback;
587
+ }
588
+ function normaliseRuntimeValidation(option) {
589
+ if (typeof option === "boolean") {
590
+ return {
591
+ requests: option,
592
+ responses: option,
593
+ errors: option
594
+ };
595
+ }
596
+ return {
597
+ requests: normaliseBoolean(option?.requests, DEFAULT_RUNTIME_VALIDATION.requests),
598
+ responses: normaliseBoolean(option?.responses, DEFAULT_RUNTIME_VALIDATION.responses),
599
+ errors: normaliseBoolean(option?.errors, DEFAULT_RUNTIME_VALIDATION.errors)
600
+ };
601
+ }
602
+ function mergeRuntimeValidation(base, override) {
603
+ if (override === void 0) {
604
+ return base;
605
+ }
606
+ if (typeof override === "boolean") {
607
+ return {
608
+ requests: override,
609
+ responses: override,
610
+ errors: override
611
+ };
612
+ }
613
+ return {
614
+ requests: normaliseBoolean(override.requests, base.requests),
615
+ responses: normaliseBoolean(override.responses, base.responses),
616
+ errors: normaliseBoolean(override.errors, base.errors)
617
+ };
618
+ }
619
+ function cloneRuntimeValidation(config) {
620
+ return { ...config };
621
+ }
622
+
623
+ // src/core/http/client.factory.ts
624
+ var DEFAULT_BASE_URL = "https://api.request.network";
625
+ function buildTelemetryHeaders(userAgent, sdkInfo) {
626
+ const headers = {};
627
+ if (userAgent) headers["user-agent"] = userAgent;
628
+ if (sdkInfo?.name) headers["x-sdk"] = sdkInfo.version ? `${sdkInfo.name}/${sdkInfo.version}` : sdkInfo.name;
629
+ return headers;
630
+ }
631
+ function buildHeaders(credentials, defaults, extra) {
632
+ return {
633
+ ...buildCredentialHeaders(credentials),
634
+ ...defaults ?? {},
635
+ ...{}
636
+ };
637
+ }
638
+ function asRecord(value) {
639
+ if (value && typeof value === "object" || Array.isArray(value)) {
640
+ return value;
641
+ }
642
+ return void 0;
643
+ }
644
+ function mapToError(res, req, validation) {
645
+ const operationId = req.meta?.operationId;
646
+ const rawPayload = asRecord(res.data);
647
+ let payload = rawPayload;
648
+ if (validation.errors && operationId) {
649
+ const schemaKey = { operationId, kind: "response", status: res.status };
650
+ const parsed = parseWithRegistry({
651
+ key: schemaKey,
652
+ value: rawPayload ?? res.data,
653
+ description: `Error response for ${operationId}`,
654
+ skipOnMissingSchema: true
655
+ });
656
+ if (!parsed.success) {
657
+ throw parsed.error;
658
+ }
659
+ payload = asRecord(parsed.data);
660
+ }
661
+ const error = buildRequestApiError({
662
+ payload,
663
+ status: res.status,
664
+ headers: res.headers,
665
+ fallbackMessage: res.text ?? `HTTP ${String(res.status)}`
666
+ });
667
+ throw error;
668
+ }
669
+ function createHttpClient(options = {}) {
670
+ const baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;
671
+ const adapter = options.adapter ?? nodeFetchAdapter;
672
+ const defaults = { ...buildTelemetryHeaders(options.userAgent, options.sdkInfo), ...options.headers ?? {} };
673
+ const creds = { apiKey: options.apiKey, clientId: options.clientId, origin: options.origin };
674
+ const userInterceptors = options.interceptors ?? [];
675
+ const logLevel = options.logLevel ?? (options.logger ? "info" : "silent");
676
+ const runtimeValidation = normaliseRuntimeValidation(options.runtimeValidation);
677
+ function buildBaseInterceptors(meta) {
678
+ const retryCfg = meta?.retry ?? options.retry?.config;
679
+ const retryOptions = {
680
+ ...options.retry ?? {},
681
+ logger: options.retry?.logger ?? options.logger,
682
+ logLevel: options.retry?.logLevel ?? logLevel
683
+ };
684
+ if (retryCfg) {
685
+ retryOptions.config = retryCfg;
686
+ }
687
+ return [createRetryInterceptor(retryOptions), createLoggingInterceptor({ logger: options.logger, level: logLevel })];
688
+ }
689
+ const cfg = {
690
+ baseUrl,
691
+ defaultHeaders: buildHeaders(creds, defaults),
692
+ adapter,
693
+ logger: options.logger,
694
+ querySerializer: options.querySerializer};
695
+ async function dispatch(req) {
696
+ const perRequestInterceptors = req.meta?.interceptors ?? [];
697
+ const baseInterceptors = buildBaseInterceptors(req.meta);
698
+ const all = [...perRequestInterceptors, ...userInterceptors, ...baseInterceptors];
699
+ const terminal = (r) => cfg.adapter.send(r);
700
+ const chain = composeInterceptors(terminal, all);
701
+ return chain(req);
702
+ }
703
+ async function request(init) {
704
+ const serializer = init.querySerializer ?? cfg.querySerializer;
705
+ const url = buildUrl(cfg.baseUrl, init.path, init.query, serializer);
706
+ const headers = { ...cfg.defaultHeaders ?? {}, ...init.headers ?? {} };
707
+ const req = {
708
+ method: init.method,
709
+ url,
710
+ headers,
711
+ body: init.body,
712
+ signal: init.signal,
713
+ timeoutMs: init.timeoutMs,
714
+ meta: init.meta
715
+ };
716
+ const res = await dispatch(req);
717
+ const effectiveValidation = mergeRuntimeValidation(runtimeValidation, req.meta?.validation);
718
+ if (!res.ok) {
719
+ mapToError(res, req, effectiveValidation);
720
+ }
721
+ return { status: res.status, headers: res.headers, data: res.data };
722
+ }
723
+ return {
724
+ request,
725
+ get: (path, init) => request({ ...init ?? {}, path, method: "GET" }),
726
+ post: (path, body, init) => request({ ...init ?? {}, path, method: "POST", body }),
727
+ put: (path, body, init) => request({ ...init ?? {}, path, method: "PUT", body }),
728
+ patch: (path, body, init) => request({ ...init ?? {}, path, method: "PATCH", body }),
729
+ delete: (path, init) => {
730
+ const { body, ...rest } = init ?? {};
731
+ return request({ ...rest, path, method: "DELETE", body });
732
+ },
733
+ head: (path, init) => request({ ...init ?? {}, path, method: "HEAD" }),
734
+ options: (path, init) => request({ ...init ?? {}, path, method: "OPTIONS" }),
735
+ getRuntimeValidationConfig: () => cloneRuntimeValidation(runtimeValidation)
736
+ };
737
+ }
738
+
739
+ // src/core/http/adapters/browser-fetch.adapter.ts
740
+ var browserFetchAdapter = {
741
+ async send(request) {
742
+ const { init, dispose } = createFetchInit(request);
743
+ try {
744
+ const res = await fetch(request.url, init);
745
+ const respHeaders = headersToRecord(res.headers);
746
+ const contentType = respHeaders["content-type"] ?? "";
747
+ let data;
748
+ let text;
749
+ if (res.status !== 204) {
750
+ try {
751
+ if (contentType.includes("application/json")) {
752
+ data = await res.json();
753
+ } else {
754
+ text = await res.text();
755
+ }
756
+ } catch {
757
+ }
758
+ }
759
+ const normalized = {
760
+ status: res.status,
761
+ ok: res.ok,
762
+ headers: respHeaders,
763
+ data,
764
+ text
765
+ };
766
+ return normalized;
767
+ } finally {
768
+ dispose();
769
+ }
770
+ }
771
+ };
772
+
773
+ // src/domains/client-ids/index.ts
774
+ var client_ids_exports = {};
775
+ __export(client_ids_exports, {
776
+ createClientIdsApi: () => createClientIdsApi
777
+ });
778
+
779
+ // src/core/http/operation.helper.ts
780
+ async function requestJson(http, params) {
781
+ const {
782
+ operationId,
783
+ method,
784
+ path,
785
+ query,
786
+ body,
787
+ schemaKey,
788
+ requestSchemaKey,
789
+ description,
790
+ querySerializer,
791
+ signal,
792
+ timeoutMs,
793
+ validation,
794
+ meta
795
+ } = params;
796
+ const runtimeValidation = mergeRuntimeValidation(http.getRuntimeValidationConfig(), validation);
797
+ let requestBody = body;
798
+ if (runtimeValidation.requests && requestSchemaKey && body !== void 0) {
799
+ const parsedRequest = parseWithRegistry({
800
+ key: requestSchemaKey,
801
+ value: body,
802
+ description: `${description ?? operationId} request`,
803
+ skipOnMissingSchema: true
804
+ });
805
+ if (!parsedRequest.success) {
806
+ throw parsedRequest.error;
807
+ }
808
+ requestBody = parsedRequest.data;
809
+ }
810
+ const metaValidation = validation ?? meta?.validation;
811
+ const requestMeta = {
812
+ ...meta ?? {},
813
+ operationId,
814
+ validation: metaValidation
815
+ };
816
+ const res = await http.request({
817
+ method,
818
+ path,
819
+ query,
820
+ body: requestBody,
821
+ querySerializer,
822
+ signal,
823
+ timeoutMs,
824
+ meta: requestMeta
825
+ });
826
+ if (!runtimeValidation.responses) {
827
+ return res.data;
828
+ }
829
+ const parsedResponse = parseWithRegistry({ key: schemaKey, value: res.data, description });
830
+ if (!parsedResponse.success) throw parsedResponse.error;
831
+ return parsedResponse.data;
832
+ }
833
+ async function requestVoid(http, params) {
834
+ const { operationId, method, path, query, body, querySerializer, signal, timeoutMs, requestSchemaKey, validation, meta } = params;
835
+ const runtimeValidation = mergeRuntimeValidation(http.getRuntimeValidationConfig(), validation);
836
+ let requestBody = body;
837
+ if (runtimeValidation.requests && requestSchemaKey && body !== void 0) {
838
+ const parsedRequest = parseWithRegistry({
839
+ key: requestSchemaKey,
840
+ value: body,
841
+ description: `${operationId} request`,
842
+ skipOnMissingSchema: true
843
+ });
844
+ if (!parsedRequest.success) {
845
+ throw parsedRequest.error;
846
+ }
847
+ requestBody = parsedRequest.data;
848
+ }
849
+ const metaValidation = validation ?? meta?.validation;
850
+ const requestMeta = {
851
+ ...meta ?? {},
852
+ operationId,
853
+ validation: metaValidation
854
+ };
855
+ await http.request({
856
+ method,
857
+ path,
858
+ query,
859
+ body: requestBody,
860
+ querySerializer,
861
+ signal,
862
+ timeoutMs,
863
+ meta: requestMeta
864
+ });
865
+ }
866
+
867
+ // src/core/http/path.builder.ts
868
+ function buildPath(template, params) {
869
+ return template.replace(/\{(.*?)\}/g, (_, key) => encodeURIComponent(String(params[key] ?? "")));
870
+ }
871
+
872
+ // src/domains/client-ids/client-ids.facade.ts
873
+ function createClientIdsApi(http) {
874
+ const PATH_BASE = "/v2/client-ids";
875
+ return {
876
+ async list() {
877
+ const OP = "ClientIdV2Controller_findAll_v2";
878
+ return requestJson(http, {
879
+ operationId: OP,
880
+ method: "GET",
881
+ path: PATH_BASE,
882
+ schemaKey: { operationId: OP, kind: "response", status: 200 },
883
+ description: "List client IDs"
884
+ });
885
+ },
886
+ async create(body) {
887
+ const OP = "ClientIdV2Controller_create_v2";
888
+ return requestJson(http, {
889
+ operationId: OP,
890
+ method: "POST",
891
+ path: PATH_BASE,
892
+ body,
893
+ requestSchemaKey: { operationId: OP, kind: "request", variant: "application/json" },
894
+ schemaKey: { operationId: OP, kind: "response", status: 201 },
895
+ description: "Create client ID"
896
+ });
897
+ },
898
+ async findOne(id) {
899
+ const path = buildPath(`${PATH_BASE}/{id}`, { id });
900
+ const OP = "ClientIdV2Controller_findOne_v2";
901
+ return requestJson(http, {
902
+ operationId: OP,
903
+ method: "GET",
904
+ path,
905
+ schemaKey: { operationId: OP, kind: "response", status: 200 },
906
+ description: "Get client ID"
907
+ });
908
+ },
909
+ async update(id, body) {
910
+ const path = buildPath(`${PATH_BASE}/{id}`, { id });
911
+ const OP = "ClientIdV2Controller_update_v2";
912
+ return requestJson(http, {
913
+ operationId: OP,
914
+ method: "PUT",
915
+ path,
916
+ body,
917
+ requestSchemaKey: { operationId: OP, kind: "request", variant: "application/json" },
918
+ schemaKey: { operationId: OP, kind: "response", status: 200 },
919
+ description: "Update client ID"
920
+ });
921
+ },
922
+ async revoke(id) {
923
+ const path = buildPath(`${PATH_BASE}/{id}`, { id });
924
+ const OP = "ClientIdV2Controller_delete_v2";
925
+ await requestVoid(http, {
926
+ operationId: OP,
927
+ method: "DELETE",
928
+ path
929
+ });
930
+ }
931
+ };
932
+ }
933
+ var ErrorDetailSchema = zod.z.object({
934
+ message: zod.z.string(),
935
+ code: zod.z.string().optional(),
936
+ field: zod.z.string().optional(),
937
+ source: zod.z.object({
938
+ pointer: zod.z.string().optional(),
939
+ parameter: zod.z.string().optional()
940
+ }).passthrough().optional(),
941
+ meta: zod.z.record(zod.z.unknown()).optional()
942
+ }).passthrough();
943
+ var ErrorEnvelopeSchema = zod.z.object({
944
+ status: zod.z.number().optional(),
945
+ statusCode: zod.z.number().optional(),
946
+ code: zod.z.string().optional(),
947
+ error: zod.z.string().optional(),
948
+ message: zod.z.union([
949
+ zod.z.string(),
950
+ zod.z.array(zod.z.union([zod.z.string(), ErrorDetailSchema])),
951
+ ErrorDetailSchema
952
+ ]).optional(),
953
+ detail: zod.z.unknown().optional(),
954
+ errors: zod.z.array(ErrorDetailSchema).optional(),
955
+ requestId: zod.z.string().optional(),
956
+ correlationId: zod.z.string().optional(),
957
+ retryAfter: zod.z.union([zod.z.number(), zod.z.string()]).optional(),
958
+ retryAfterMs: zod.z.number().optional(),
959
+ meta: zod.z.record(zod.z.unknown()).optional()
960
+ }).passthrough();
961
+ var ClientIdV2Controller_findAll_v2_200 = zod.z.array(zod.z.object({ "id": zod.z.string().optional(), "clientId": zod.z.string().optional(), "label": zod.z.string().optional(), "allowedDomains": zod.z.array(zod.z.string()).optional(), "status": zod.z.string().optional(), "createdAt": zod.z.string().optional(), "lastUsedAt": zod.z.string().nullable().optional() }).passthrough());
962
+ schemaRegistry.register({ key: { operationId: "ClientIdV2Controller_findAll_v2", kind: "response", status: 200 }, schema: ClientIdV2Controller_findAll_v2_200 });
963
+ var ClientIdV2Controller_findAll_v2_401 = ErrorEnvelopeSchema;
964
+ schemaRegistry.register({ key: { operationId: "ClientIdV2Controller_findAll_v2", kind: "response", status: 401 }, schema: ClientIdV2Controller_findAll_v2_401 });
965
+ var ClientIdV2Controller_findAll_v2_429 = ErrorEnvelopeSchema;
966
+ schemaRegistry.register({ key: { operationId: "ClientIdV2Controller_findAll_v2", kind: "response", status: 429 }, schema: ClientIdV2Controller_findAll_v2_429 });
967
+ var ClientIdV2Controller_create_v2_Request = zod.z.object({ "label": zod.z.string(), "allowedDomains": zod.z.array(zod.z.string()), "feePercentage": zod.z.string().optional(), "feeAddress": zod.z.string().optional() }).passthrough();
968
+ schemaRegistry.register({ key: { operationId: "ClientIdV2Controller_create_v2", kind: "request", variant: "application/json" }, schema: ClientIdV2Controller_create_v2_Request });
969
+ var ClientIdV2Controller_create_v2_201 = zod.z.object({ "id": zod.z.string().optional(), "clientId": zod.z.string().optional(), "label": zod.z.string().optional(), "allowedDomains": zod.z.array(zod.z.string()).optional(), "feePercentage": zod.z.string().nullable().optional(), "feeAddress": zod.z.string().nullable().optional(), "status": zod.z.string().optional(), "createdAt": zod.z.string().optional() }).passthrough();
970
+ schemaRegistry.register({ key: { operationId: "ClientIdV2Controller_create_v2", kind: "response", status: 201 }, schema: ClientIdV2Controller_create_v2_201 });
971
+ var ClientIdV2Controller_create_v2_400 = ErrorEnvelopeSchema;
972
+ schemaRegistry.register({ key: { operationId: "ClientIdV2Controller_create_v2", kind: "response", status: 400 }, schema: ClientIdV2Controller_create_v2_400 });
973
+ var ClientIdV2Controller_create_v2_401 = ErrorEnvelopeSchema;
974
+ schemaRegistry.register({ key: { operationId: "ClientIdV2Controller_create_v2", kind: "response", status: 401 }, schema: ClientIdV2Controller_create_v2_401 });
975
+ var ClientIdV2Controller_create_v2_429 = ErrorEnvelopeSchema;
976
+ schemaRegistry.register({ key: { operationId: "ClientIdV2Controller_create_v2", kind: "response", status: 429 }, schema: ClientIdV2Controller_create_v2_429 });
977
+ var ClientIdV2Controller_findOne_v2_200 = zod.z.object({ "id": zod.z.string().optional(), "clientId": zod.z.string().optional(), "label": zod.z.string().optional(), "allowedDomains": zod.z.array(zod.z.string()).optional(), "feePercentage": zod.z.string().nullable().optional(), "feeAddress": zod.z.string().nullable().optional(), "status": zod.z.string().optional(), "createdAt": zod.z.string().optional(), "updatedAt": zod.z.string().optional(), "lastUsedAt": zod.z.string().nullable().optional() }).passthrough();
978
+ schemaRegistry.register({ key: { operationId: "ClientIdV2Controller_findOne_v2", kind: "response", status: 200 }, schema: ClientIdV2Controller_findOne_v2_200 });
979
+ var ClientIdV2Controller_findOne_v2_401 = ErrorEnvelopeSchema;
980
+ schemaRegistry.register({ key: { operationId: "ClientIdV2Controller_findOne_v2", kind: "response", status: 401 }, schema: ClientIdV2Controller_findOne_v2_401 });
981
+ var ClientIdV2Controller_findOne_v2_404 = ErrorEnvelopeSchema;
982
+ schemaRegistry.register({ key: { operationId: "ClientIdV2Controller_findOne_v2", kind: "response", status: 404 }, schema: ClientIdV2Controller_findOne_v2_404 });
983
+ var ClientIdV2Controller_findOne_v2_429 = ErrorEnvelopeSchema;
984
+ schemaRegistry.register({ key: { operationId: "ClientIdV2Controller_findOne_v2", kind: "response", status: 429 }, schema: ClientIdV2Controller_findOne_v2_429 });
985
+ var ClientIdV2Controller_update_v2_Request = zod.z.object({ "label": zod.z.string().optional(), "allowedDomains": zod.z.array(zod.z.string()).optional(), "feePercentage": zod.z.string().nullable().optional(), "feeAddress": zod.z.string().nullable().optional(), "status": zod.z.enum(["active", "inactive", "revoked"]).optional() }).passthrough();
986
+ schemaRegistry.register({ key: { operationId: "ClientIdV2Controller_update_v2", kind: "request", variant: "application/json" }, schema: ClientIdV2Controller_update_v2_Request });
987
+ var ClientIdV2Controller_update_v2_200 = zod.z.object({ "id": zod.z.string().optional(), "clientId": zod.z.string().optional(), "label": zod.z.string().optional(), "allowedDomains": zod.z.array(zod.z.string()).optional(), "feePercentage": zod.z.string().nullable().optional(), "feeAddress": zod.z.string().nullable().optional(), "status": zod.z.string().optional(), "updatedAt": zod.z.string().optional() }).passthrough();
988
+ schemaRegistry.register({ key: { operationId: "ClientIdV2Controller_update_v2", kind: "response", status: 200 }, schema: ClientIdV2Controller_update_v2_200 });
989
+ var ClientIdV2Controller_update_v2_400 = ErrorEnvelopeSchema;
990
+ schemaRegistry.register({ key: { operationId: "ClientIdV2Controller_update_v2", kind: "response", status: 400 }, schema: ClientIdV2Controller_update_v2_400 });
991
+ var ClientIdV2Controller_update_v2_401 = ErrorEnvelopeSchema;
992
+ schemaRegistry.register({ key: { operationId: "ClientIdV2Controller_update_v2", kind: "response", status: 401 }, schema: ClientIdV2Controller_update_v2_401 });
993
+ var ClientIdV2Controller_update_v2_404 = ErrorEnvelopeSchema;
994
+ schemaRegistry.register({ key: { operationId: "ClientIdV2Controller_update_v2", kind: "response", status: 404 }, schema: ClientIdV2Controller_update_v2_404 });
995
+ var ClientIdV2Controller_update_v2_429 = ErrorEnvelopeSchema;
996
+ schemaRegistry.register({ key: { operationId: "ClientIdV2Controller_update_v2", kind: "response", status: 429 }, schema: ClientIdV2Controller_update_v2_429 });
997
+ var ClientIdV2Controller_delete_v2_200 = zod.z.unknown();
998
+ schemaRegistry.register({ key: { operationId: "ClientIdV2Controller_delete_v2", kind: "response", status: 200 }, schema: ClientIdV2Controller_delete_v2_200 });
999
+ var ClientIdV2Controller_delete_v2_401 = ErrorEnvelopeSchema;
1000
+ schemaRegistry.register({ key: { operationId: "ClientIdV2Controller_delete_v2", kind: "response", status: 401 }, schema: ClientIdV2Controller_delete_v2_401 });
1001
+ var ClientIdV2Controller_delete_v2_404 = ErrorEnvelopeSchema;
1002
+ schemaRegistry.register({ key: { operationId: "ClientIdV2Controller_delete_v2", kind: "response", status: 404 }, schema: ClientIdV2Controller_delete_v2_404 });
1003
+ var ClientIdV2Controller_delete_v2_429 = ErrorEnvelopeSchema;
1004
+ schemaRegistry.register({ key: { operationId: "ClientIdV2Controller_delete_v2", kind: "response", status: 429 }, schema: ClientIdV2Controller_delete_v2_429 });
1005
+
1006
+ // src/domains/currencies/index.ts
1007
+ var currencies_exports = {};
1008
+ __export(currencies_exports, {
1009
+ createCurrenciesApi: () => createCurrenciesApi,
1010
+ createCurrenciesV1Api: () => createCurrenciesV1Api
1011
+ });
1012
+ var ErrorDetailSchema2 = zod.z.object({
1013
+ message: zod.z.string(),
1014
+ code: zod.z.string().optional(),
1015
+ field: zod.z.string().optional(),
1016
+ source: zod.z.object({
1017
+ pointer: zod.z.string().optional(),
1018
+ parameter: zod.z.string().optional()
1019
+ }).passthrough().optional(),
1020
+ meta: zod.z.record(zod.z.unknown()).optional()
1021
+ }).passthrough();
1022
+ var ErrorEnvelopeSchema2 = zod.z.object({
1023
+ status: zod.z.number().optional(),
1024
+ statusCode: zod.z.number().optional(),
1025
+ code: zod.z.string().optional(),
1026
+ error: zod.z.string().optional(),
1027
+ message: zod.z.union([
1028
+ zod.z.string(),
1029
+ zod.z.array(zod.z.union([zod.z.string(), ErrorDetailSchema2])),
1030
+ ErrorDetailSchema2
1031
+ ]).optional(),
1032
+ detail: zod.z.unknown().optional(),
1033
+ errors: zod.z.array(ErrorDetailSchema2).optional(),
1034
+ requestId: zod.z.string().optional(),
1035
+ correlationId: zod.z.string().optional(),
1036
+ retryAfter: zod.z.union([zod.z.number(), zod.z.string()]).optional(),
1037
+ retryAfterMs: zod.z.number().optional(),
1038
+ meta: zod.z.record(zod.z.unknown()).optional()
1039
+ }).passthrough();
1040
+ var CurrenciesV1Controller_getNetworkTokens_v1_200 = zod.z.unknown();
1041
+ schemaRegistry.register({ key: { operationId: "CurrenciesV1Controller_getNetworkTokens_v1", kind: "response", status: 200 }, schema: CurrenciesV1Controller_getNetworkTokens_v1_200 });
1042
+ var CurrenciesV1Controller_getNetworkTokens_v1_400 = ErrorEnvelopeSchema2;
1043
+ schemaRegistry.register({ key: { operationId: "CurrenciesV1Controller_getNetworkTokens_v1", kind: "response", status: 400 }, schema: CurrenciesV1Controller_getNetworkTokens_v1_400 });
1044
+ var CurrenciesV1Controller_getNetworkTokens_v1_404 = ErrorEnvelopeSchema2;
1045
+ schemaRegistry.register({ key: { operationId: "CurrenciesV1Controller_getNetworkTokens_v1", kind: "response", status: 404 }, schema: CurrenciesV1Controller_getNetworkTokens_v1_404 });
1046
+ var CurrenciesV1Controller_getNetworkTokens_v1_429 = ErrorEnvelopeSchema2;
1047
+ schemaRegistry.register({ key: { operationId: "CurrenciesV1Controller_getNetworkTokens_v1", kind: "response", status: 429 }, schema: CurrenciesV1Controller_getNetworkTokens_v1_429 });
1048
+ var CurrenciesV1Controller_getConversionRoutes_v1_200 = zod.z.unknown();
1049
+ schemaRegistry.register({ key: { operationId: "CurrenciesV1Controller_getConversionRoutes_v1", kind: "response", status: 200 }, schema: CurrenciesV1Controller_getConversionRoutes_v1_200 });
1050
+ var CurrenciesV1Controller_getConversionRoutes_v1_404 = ErrorEnvelopeSchema2;
1051
+ schemaRegistry.register({ key: { operationId: "CurrenciesV1Controller_getConversionRoutes_v1", kind: "response", status: 404 }, schema: CurrenciesV1Controller_getConversionRoutes_v1_404 });
1052
+ var CurrenciesV1Controller_getConversionRoutes_v1_429 = ErrorEnvelopeSchema2;
1053
+ schemaRegistry.register({ key: { operationId: "CurrenciesV1Controller_getConversionRoutes_v1", kind: "response", status: 429 }, schema: CurrenciesV1Controller_getConversionRoutes_v1_429 });
1054
+ var CurrenciesV2Controller_getNetworkTokens_v2_200 = zod.z.unknown();
1055
+ schemaRegistry.register({ key: { operationId: "CurrenciesV2Controller_getNetworkTokens_v2", kind: "response", status: 200 }, schema: CurrenciesV2Controller_getNetworkTokens_v2_200 });
1056
+ var CurrenciesV2Controller_getNetworkTokens_v2_400 = ErrorEnvelopeSchema2;
1057
+ schemaRegistry.register({ key: { operationId: "CurrenciesV2Controller_getNetworkTokens_v2", kind: "response", status: 400 }, schema: CurrenciesV2Controller_getNetworkTokens_v2_400 });
1058
+ var CurrenciesV2Controller_getNetworkTokens_v2_404 = ErrorEnvelopeSchema2;
1059
+ schemaRegistry.register({ key: { operationId: "CurrenciesV2Controller_getNetworkTokens_v2", kind: "response", status: 404 }, schema: CurrenciesV2Controller_getNetworkTokens_v2_404 });
1060
+ var CurrenciesV2Controller_getNetworkTokens_v2_429 = ErrorEnvelopeSchema2;
1061
+ schemaRegistry.register({ key: { operationId: "CurrenciesV2Controller_getNetworkTokens_v2", kind: "response", status: 429 }, schema: CurrenciesV2Controller_getNetworkTokens_v2_429 });
1062
+ var CurrenciesV2Controller_getConversionRoutes_v2_200 = zod.z.unknown();
1063
+ schemaRegistry.register({ key: { operationId: "CurrenciesV2Controller_getConversionRoutes_v2", kind: "response", status: 200 }, schema: CurrenciesV2Controller_getConversionRoutes_v2_200 });
1064
+ var CurrenciesV2Controller_getConversionRoutes_v2_404 = ErrorEnvelopeSchema2;
1065
+ schemaRegistry.register({ key: { operationId: "CurrenciesV2Controller_getConversionRoutes_v2", kind: "response", status: 404 }, schema: CurrenciesV2Controller_getConversionRoutes_v2_404 });
1066
+ var CurrenciesV2Controller_getConversionRoutes_v2_429 = ErrorEnvelopeSchema2;
1067
+ schemaRegistry.register({ key: { operationId: "CurrenciesV2Controller_getConversionRoutes_v2", kind: "response", status: 429 }, schema: CurrenciesV2Controller_getConversionRoutes_v2_429 });
1068
+
1069
+ // src/domains/currencies/currencies.schemas.ts
1070
+ var OP_LIST = "CurrenciesV2Controller_getNetworkTokens_v2";
1071
+ var OP_CONVERSION_ROUTES = "CurrenciesV2Controller_getConversionRoutes_v2";
1072
+ var CurrencyTokenSchema = zod.z.object({
1073
+ id: zod.z.string(),
1074
+ name: zod.z.string(),
1075
+ symbol: zod.z.string(),
1076
+ decimals: zod.z.number(),
1077
+ address: zod.z.string().optional(),
1078
+ network: zod.z.string().optional(),
1079
+ type: zod.z.string().optional(),
1080
+ hash: zod.z.string().optional(),
1081
+ chainId: zod.z.number().optional()
1082
+ }).passthrough();
1083
+ var CurrenciesListSchema = zod.z.array(CurrencyTokenSchema);
1084
+ var ConversionRoutesSchema = zod.z.object({
1085
+ currencyId: zod.z.string(),
1086
+ network: zod.z.string().nullable().optional(),
1087
+ conversionRoutes: zod.z.array(CurrencyTokenSchema)
1088
+ }).passthrough();
1089
+ schemaRegistry.register({ key: { operationId: OP_LIST, kind: "response", status: 200 }, schema: CurrenciesListSchema });
1090
+ schemaRegistry.register({ key: { operationId: OP_CONVERSION_ROUTES, kind: "response", status: 200 }, schema: ConversionRoutesSchema });
1091
+
1092
+ // src/domains/currencies/v1/index.ts
1093
+ var v1_exports = {};
1094
+ __export(v1_exports, {
1095
+ createCurrenciesV1Api: () => createCurrenciesV1Api
1096
+ });
1097
+ var OP_LIST_V1 = "CurrenciesV1Controller_getNetworkTokens_v1";
1098
+ var OP_CONVERSION_ROUTES_V1 = "CurrenciesV1Controller_getConversionRoutes_v1";
1099
+ var DESCRIPTION_LIST = "Legacy currencies list";
1100
+ var DESCRIPTION_CONVERSION_ROUTES = "Legacy conversion routes";
1101
+ var CurrenciesV1ListSchema = zod.z.union([CurrenciesListSchema, CurrencyTokenSchema]);
1102
+ schemaRegistry.register({ key: { operationId: OP_LIST_V1, kind: "response", status: 200 }, schema: CurrenciesV1ListSchema });
1103
+ schemaRegistry.register({
1104
+ key: { operationId: OP_CONVERSION_ROUTES_V1, kind: "response", status: 200 },
1105
+ schema: ConversionRoutesSchema
1106
+ });
1107
+ var DESCRIPTIONS = {
1108
+ list: DESCRIPTION_LIST,
1109
+ conversionRoutes: DESCRIPTION_CONVERSION_ROUTES
1110
+ };
1111
+
1112
+ // src/domains/currencies/v1/currencies.v1.facade.ts
1113
+ var CURRENCIES_V1_PATH = "/v1/currencies";
1114
+ var CONVERSION_ROUTES_SEGMENT = "conversion-routes";
1115
+ function toQuery(input) {
1116
+ return input;
1117
+ }
1118
+ function createCurrenciesV1Api(http) {
1119
+ return {
1120
+ async list(query, options) {
1121
+ const data = await requestJson(http, {
1122
+ operationId: OP_LIST_V1,
1123
+ method: "GET",
1124
+ path: CURRENCIES_V1_PATH,
1125
+ query: toQuery(query ?? void 0),
1126
+ schemaKey: { operationId: OP_LIST_V1, kind: "response", status: 200 },
1127
+ description: DESCRIPTIONS.list,
1128
+ signal: options?.signal,
1129
+ timeoutMs: options?.timeoutMs,
1130
+ validation: options?.validation
1131
+ });
1132
+ const parsed = parseWithSchema({
1133
+ schema: CurrenciesV1ListSchema,
1134
+ value: data,
1135
+ description: DESCRIPTIONS.list
1136
+ });
1137
+ if (!parsed.success) throw parsed.error;
1138
+ const payload = parsed.data;
1139
+ const tokens = Array.isArray(payload) ? payload : [payload];
1140
+ return tokens;
1141
+ },
1142
+ async getConversionRoutes(currencyId, query, options) {
1143
+ const path = `${CURRENCIES_V1_PATH}/${encodeURIComponent(currencyId)}/${CONVERSION_ROUTES_SEGMENT}`;
1144
+ const data = await requestJson(http, {
1145
+ operationId: OP_CONVERSION_ROUTES_V1,
1146
+ method: "GET",
1147
+ path,
1148
+ query: toQuery(query ?? void 0),
1149
+ schemaKey: { operationId: OP_CONVERSION_ROUTES_V1, kind: "response", status: 200 },
1150
+ description: DESCRIPTIONS.conversionRoutes,
1151
+ signal: options?.signal,
1152
+ timeoutMs: options?.timeoutMs,
1153
+ validation: options?.validation
1154
+ });
1155
+ const parsed = parseWithSchema({
1156
+ schema: ConversionRoutesSchema,
1157
+ value: data,
1158
+ description: DESCRIPTIONS.conversionRoutes
1159
+ });
1160
+ if (!parsed.success) throw parsed.error;
1161
+ return parsed.data;
1162
+ }
1163
+ };
1164
+ }
1165
+
1166
+ // src/domains/currencies/currencies.facade.ts
1167
+ var CURRENCIES_PATH = "/v2/currencies";
1168
+ var CONVERSION_ROUTES_SEGMENT2 = "conversion-routes";
1169
+ var DESCRIPTION_LIST2 = "Currencies list";
1170
+ var DESCRIPTION_CONVERSION_ROUTES2 = "Conversion routes";
1171
+ function createCurrenciesApi(http) {
1172
+ const legacy = createCurrenciesV1Api(http);
1173
+ function toQuery2(input) {
1174
+ return input;
1175
+ }
1176
+ return {
1177
+ legacy,
1178
+ async list(query, options) {
1179
+ const data = await requestJson(http, {
1180
+ operationId: OP_LIST,
1181
+ method: "GET",
1182
+ path: CURRENCIES_PATH,
1183
+ query: toQuery2(query ?? void 0),
1184
+ schemaKey: { operationId: OP_LIST, kind: "response", status: 200 },
1185
+ description: DESCRIPTION_LIST2,
1186
+ signal: options?.signal,
1187
+ timeoutMs: options?.timeoutMs,
1188
+ validation: options?.validation
1189
+ });
1190
+ const parsed = parseWithSchema({
1191
+ schema: CurrenciesListSchema,
1192
+ value: data,
1193
+ description: DESCRIPTION_LIST2
1194
+ });
1195
+ if (!parsed.success) throw parsed.error;
1196
+ const list = parsed.data;
1197
+ return list;
1198
+ },
1199
+ async getConversionRoutes(currencyId, query, options) {
1200
+ const path = `${CURRENCIES_PATH}/${encodeURIComponent(currencyId)}/${CONVERSION_ROUTES_SEGMENT2}`;
1201
+ const data = await requestJson(http, {
1202
+ operationId: OP_CONVERSION_ROUTES,
1203
+ method: "GET",
1204
+ path,
1205
+ query: toQuery2(query ?? void 0),
1206
+ schemaKey: { operationId: OP_CONVERSION_ROUTES, kind: "response", status: 200 },
1207
+ description: DESCRIPTION_CONVERSION_ROUTES2,
1208
+ signal: options?.signal,
1209
+ timeoutMs: options?.timeoutMs,
1210
+ validation: options?.validation
1211
+ });
1212
+ const parsed = parseWithSchema({
1213
+ schema: ConversionRoutesSchema,
1214
+ value: data,
1215
+ description: DESCRIPTION_CONVERSION_ROUTES2
1216
+ });
1217
+ if (!parsed.success) throw parsed.error;
1218
+ const routes = parsed.data;
1219
+ return routes;
1220
+ }
1221
+ };
1222
+ }
1223
+
1224
+ // src/domains/pay/index.ts
1225
+ var pay_exports = {};
1226
+ __export(pay_exports, {
1227
+ createPayApi: () => createPayApi,
1228
+ createPayV1Api: () => createPayV1Api
1229
+ });
1230
+
1231
+ // src/domains/pay/v1/index.ts
1232
+ var v1_exports2 = {};
1233
+ __export(v1_exports2, {
1234
+ createPayV1Api: () => createPayV1Api
1235
+ });
1236
+
1237
+ // src/domains/pay/v1/pay.v1.facade.ts
1238
+ var OP_PAY_REQUEST = "PayV1Controller_payRequest_v1";
1239
+ var PAY_PATH = "/v1/pay";
1240
+ var DESCRIPTION_PAY_REQUEST = "Legacy pay request";
1241
+ function createPayV1Api(http) {
1242
+ return {
1243
+ async payRequest(body, options) {
1244
+ return requestJson(http, {
1245
+ operationId: OP_PAY_REQUEST,
1246
+ method: "POST",
1247
+ path: PAY_PATH,
1248
+ body,
1249
+ requestSchemaKey: { operationId: OP_PAY_REQUEST, kind: "request", variant: "application/json" },
1250
+ schemaKey: { operationId: OP_PAY_REQUEST, kind: "response", status: 201 },
1251
+ description: DESCRIPTION_PAY_REQUEST,
1252
+ signal: options?.signal,
1253
+ timeoutMs: options?.timeoutMs,
1254
+ validation: options?.validation,
1255
+ meta: options?.meta
1256
+ });
1257
+ }
1258
+ };
1259
+ }
1260
+ var ErrorDetailSchema3 = zod.z.object({
1261
+ message: zod.z.string(),
1262
+ code: zod.z.string().optional(),
1263
+ field: zod.z.string().optional(),
1264
+ source: zod.z.object({
1265
+ pointer: zod.z.string().optional(),
1266
+ parameter: zod.z.string().optional()
1267
+ }).passthrough().optional(),
1268
+ meta: zod.z.record(zod.z.unknown()).optional()
1269
+ }).passthrough();
1270
+ var ErrorEnvelopeSchema3 = zod.z.object({
1271
+ status: zod.z.number().optional(),
1272
+ statusCode: zod.z.number().optional(),
1273
+ code: zod.z.string().optional(),
1274
+ error: zod.z.string().optional(),
1275
+ message: zod.z.union([
1276
+ zod.z.string(),
1277
+ zod.z.array(zod.z.union([zod.z.string(), ErrorDetailSchema3])),
1278
+ ErrorDetailSchema3
1279
+ ]).optional(),
1280
+ detail: zod.z.unknown().optional(),
1281
+ errors: zod.z.array(ErrorDetailSchema3).optional(),
1282
+ requestId: zod.z.string().optional(),
1283
+ correlationId: zod.z.string().optional(),
1284
+ retryAfter: zod.z.union([zod.z.number(), zod.z.string()]).optional(),
1285
+ retryAfterMs: zod.z.number().optional(),
1286
+ meta: zod.z.record(zod.z.unknown()).optional()
1287
+ }).passthrough();
1288
+ var PayV1Controller_payRequest_v1_Request = zod.z.object({ "payee": zod.z.string(), "amount": zod.z.string(), "invoiceCurrency": zod.z.string(), "paymentCurrency": zod.z.string() }).passthrough();
1289
+ schemaRegistry.register({ key: { operationId: "PayV1Controller_payRequest_v1", kind: "request", variant: "application/json" }, schema: PayV1Controller_payRequest_v1_Request });
1290
+ var PayV1Controller_payRequest_v1_201 = zod.z.object({ "requestId": zod.z.string() }).passthrough();
1291
+ schemaRegistry.register({ key: { operationId: "PayV1Controller_payRequest_v1", kind: "response", status: 201 }, schema: PayV1Controller_payRequest_v1_201 });
1292
+ var PayV1Controller_payRequest_v1_401 = ErrorEnvelopeSchema3;
1293
+ schemaRegistry.register({ key: { operationId: "PayV1Controller_payRequest_v1", kind: "response", status: 401 }, schema: PayV1Controller_payRequest_v1_401 });
1294
+ var PayV1Controller_payRequest_v1_404 = ErrorEnvelopeSchema3;
1295
+ schemaRegistry.register({ key: { operationId: "PayV1Controller_payRequest_v1", kind: "response", status: 404 }, schema: PayV1Controller_payRequest_v1_404 });
1296
+ var PayV1Controller_payRequest_v1_429 = ErrorEnvelopeSchema3;
1297
+ schemaRegistry.register({ key: { operationId: "PayV1Controller_payRequest_v1", kind: "response", status: 429 }, schema: PayV1Controller_payRequest_v1_429 });
1298
+ var PayoutV2Controller_payRequest_v2_Request = zod.z.object({ "payee": zod.z.string(), "amount": zod.z.string(), "invoiceCurrency": zod.z.string(), "paymentCurrency": zod.z.string(), "feePercentage": zod.z.string().optional(), "feeAddress": zod.z.string().optional(), "recurrence": zod.z.object({ "startDate": zod.z.string(), "frequency": zod.z.enum(["DAILY", "WEEKLY", "MONTHLY", "YEARLY"]), "totalPayments": zod.z.number(), "payer": zod.z.string() }).passthrough().optional(), "payerWallet": zod.z.string().optional(), "customerInfo": zod.z.object({ "firstName": zod.z.string().optional(), "lastName": zod.z.string().optional(), "email": zod.z.string().optional(), "address": zod.z.object({ "street": zod.z.string().optional(), "city": zod.z.string().optional(), "state": zod.z.string().optional(), "postalCode": zod.z.string().optional(), "country": zod.z.string().optional() }).passthrough().optional() }).passthrough().optional(), "reference": zod.z.string().optional() }).passthrough();
1299
+ schemaRegistry.register({ key: { operationId: "PayoutV2Controller_payRequest_v2", kind: "request", variant: "application/json" }, schema: PayoutV2Controller_payRequest_v2_Request });
1300
+ var PayoutV2Controller_payRequest_v2_201 = zod.z.object({ "requestId": zod.z.string() }).passthrough();
1301
+ schemaRegistry.register({ key: { operationId: "PayoutV2Controller_payRequest_v2", kind: "response", status: 201 }, schema: PayoutV2Controller_payRequest_v2_201 });
1302
+ var PayoutV2Controller_payRequest_v2_404 = ErrorEnvelopeSchema3;
1303
+ schemaRegistry.register({ key: { operationId: "PayoutV2Controller_payRequest_v2", kind: "response", status: 404 }, schema: PayoutV2Controller_payRequest_v2_404 });
1304
+ var PayoutV2Controller_payRequest_v2_429 = ErrorEnvelopeSchema3;
1305
+ schemaRegistry.register({ key: { operationId: "PayoutV2Controller_payRequest_v2", kind: "response", status: 429 }, schema: PayoutV2Controller_payRequest_v2_429 });
1306
+ var PayoutV2Controller_payBatchRequest_v2_Request = zod.z.object({ "requests": zod.z.array(zod.z.object({ "payee": zod.z.string(), "amount": zod.z.string(), "invoiceCurrency": zod.z.string(), "paymentCurrency": zod.z.string() }).passthrough()).optional(), "requestIds": zod.z.array(zod.z.string()).optional(), "payer": zod.z.string().optional() }).passthrough();
1307
+ schemaRegistry.register({ key: { operationId: "PayoutV2Controller_payBatchRequest_v2", kind: "request", variant: "application/json" }, schema: PayoutV2Controller_payBatchRequest_v2_Request });
1308
+ var PayoutV2Controller_payBatchRequest_v2_201 = zod.z.object({ "ERC20ApprovalTransactions": zod.z.array(zod.z.object({ "data": zod.z.string(), "to": zod.z.string(), "value": zod.z.number() }).passthrough()).optional(), "ERC20BatchPaymentTransaction": zod.z.object({ "data": zod.z.string(), "to": zod.z.string(), "value": zod.z.object({ "type": zod.z.enum(["BigNumber"]), "hex": zod.z.string() }).passthrough() }).passthrough().optional(), "ETHBatchPaymentTransaction": zod.z.object({ "data": zod.z.string(), "to": zod.z.string(), "value": zod.z.object({ "type": zod.z.enum(["BigNumber"]), "hex": zod.z.string() }).passthrough() }).passthrough().optional() }).passthrough();
1309
+ schemaRegistry.register({ key: { operationId: "PayoutV2Controller_payBatchRequest_v2", kind: "response", status: 201 }, schema: PayoutV2Controller_payBatchRequest_v2_201 });
1310
+ var PayoutV2Controller_payBatchRequest_v2_400 = ErrorEnvelopeSchema3;
1311
+ schemaRegistry.register({ key: { operationId: "PayoutV2Controller_payBatchRequest_v2", kind: "response", status: 400 }, schema: PayoutV2Controller_payBatchRequest_v2_400 });
1312
+ var PayoutV2Controller_payBatchRequest_v2_429 = ErrorEnvelopeSchema3;
1313
+ schemaRegistry.register({ key: { operationId: "PayoutV2Controller_payBatchRequest_v2", kind: "response", status: 429 }, schema: PayoutV2Controller_payBatchRequest_v2_429 });
1314
+ var PayoutV2Controller_getRecurringPaymentStatus_v2_200 = zod.z.unknown();
1315
+ schemaRegistry.register({ key: { operationId: "PayoutV2Controller_getRecurringPaymentStatus_v2", kind: "response", status: 200 }, schema: PayoutV2Controller_getRecurringPaymentStatus_v2_200 });
1316
+ var PayoutV2Controller_getRecurringPaymentStatus_v2_404 = ErrorEnvelopeSchema3;
1317
+ schemaRegistry.register({ key: { operationId: "PayoutV2Controller_getRecurringPaymentStatus_v2", kind: "response", status: 404 }, schema: PayoutV2Controller_getRecurringPaymentStatus_v2_404 });
1318
+ var PayoutV2Controller_getRecurringPaymentStatus_v2_429 = ErrorEnvelopeSchema3;
1319
+ schemaRegistry.register({ key: { operationId: "PayoutV2Controller_getRecurringPaymentStatus_v2", kind: "response", status: 429 }, schema: PayoutV2Controller_getRecurringPaymentStatus_v2_429 });
1320
+ var PayoutV2Controller_submitRecurringPaymentSignature_v2_Request = zod.z.object({ "permitSignature": zod.z.string() }).passthrough();
1321
+ schemaRegistry.register({ key: { operationId: "PayoutV2Controller_submitRecurringPaymentSignature_v2", kind: "request", variant: "application/json" }, schema: PayoutV2Controller_submitRecurringPaymentSignature_v2_Request });
1322
+ var PayoutV2Controller_submitRecurringPaymentSignature_v2_201 = zod.z.unknown();
1323
+ schemaRegistry.register({ key: { operationId: "PayoutV2Controller_submitRecurringPaymentSignature_v2", kind: "response", status: 201 }, schema: PayoutV2Controller_submitRecurringPaymentSignature_v2_201 });
1324
+ var PayoutV2Controller_submitRecurringPaymentSignature_v2_400 = ErrorEnvelopeSchema3;
1325
+ schemaRegistry.register({ key: { operationId: "PayoutV2Controller_submitRecurringPaymentSignature_v2", kind: "response", status: 400 }, schema: PayoutV2Controller_submitRecurringPaymentSignature_v2_400 });
1326
+ var PayoutV2Controller_submitRecurringPaymentSignature_v2_404 = ErrorEnvelopeSchema3;
1327
+ schemaRegistry.register({ key: { operationId: "PayoutV2Controller_submitRecurringPaymentSignature_v2", kind: "response", status: 404 }, schema: PayoutV2Controller_submitRecurringPaymentSignature_v2_404 });
1328
+ var PayoutV2Controller_submitRecurringPaymentSignature_v2_429 = ErrorEnvelopeSchema3;
1329
+ schemaRegistry.register({ key: { operationId: "PayoutV2Controller_submitRecurringPaymentSignature_v2", kind: "response", status: 429 }, schema: PayoutV2Controller_submitRecurringPaymentSignature_v2_429 });
1330
+ var PayoutV2Controller_updateRecurringPayment_v2_Request = zod.z.object({ "action": zod.z.enum(["cancel", "unpause"]) }).passthrough();
1331
+ schemaRegistry.register({ key: { operationId: "PayoutV2Controller_updateRecurringPayment_v2", kind: "request", variant: "application/json" }, schema: PayoutV2Controller_updateRecurringPayment_v2_Request });
1332
+ var PayoutV2Controller_updateRecurringPayment_v2_200 = zod.z.unknown();
1333
+ schemaRegistry.register({ key: { operationId: "PayoutV2Controller_updateRecurringPayment_v2", kind: "response", status: 200 }, schema: PayoutV2Controller_updateRecurringPayment_v2_200 });
1334
+ var PayoutV2Controller_updateRecurringPayment_v2_400 = ErrorEnvelopeSchema3;
1335
+ schemaRegistry.register({ key: { operationId: "PayoutV2Controller_updateRecurringPayment_v2", kind: "response", status: 400 }, schema: PayoutV2Controller_updateRecurringPayment_v2_400 });
1336
+ var PayoutV2Controller_updateRecurringPayment_v2_404 = ErrorEnvelopeSchema3;
1337
+ schemaRegistry.register({ key: { operationId: "PayoutV2Controller_updateRecurringPayment_v2", kind: "response", status: 404 }, schema: PayoutV2Controller_updateRecurringPayment_v2_404 });
1338
+ var PayoutV2Controller_updateRecurringPayment_v2_429 = ErrorEnvelopeSchema3;
1339
+ schemaRegistry.register({ key: { operationId: "PayoutV2Controller_updateRecurringPayment_v2", kind: "response", status: 429 }, schema: PayoutV2Controller_updateRecurringPayment_v2_429 });
1340
+
1341
+ // src/domains/pay/pay.facade.ts
1342
+ function createPayApi(http) {
1343
+ const legacy = createPayV1Api(http);
1344
+ return {
1345
+ ...legacy,
1346
+ legacy
1347
+ };
1348
+ }
1349
+
1350
+ // src/domains/payer/index.ts
1351
+ var payer_exports = {};
1352
+ __export(payer_exports, {
1353
+ createPayerApi: () => createPayerApi,
1354
+ createPayerV1Api: () => createPayerV1Api,
1355
+ createPayerV2Api: () => createPayerV2Api
1356
+ });
1357
+
1358
+ // src/domains/payer/v1/index.ts
1359
+ var v1_exports3 = {};
1360
+ __export(v1_exports3, {
1361
+ createPayerV1Api: () => createPayerV1Api
1362
+ });
1363
+
1364
+ // src/domains/payer/v1/payer.v1.facade.ts
1365
+ var OP_CREATE_COMPLIANCE = "PayerV1Controller_getComplianceData_v1";
1366
+ var OP_GET_STATUS = "PayerV1Controller_getComplianceStatus_v1";
1367
+ var OP_UPDATE_STATUS = "PayerV1Controller_updateComplianceStatus_v1";
1368
+ var OP_CREATE_PAYMENT_DETAILS = "PayerV1Controller_createPaymentDetails_v1";
1369
+ var OP_GET_PAYMENT_DETAILS = "PayerV1Controller_getPaymentDetails_v1";
1370
+ function createPayerV1Api(http) {
1371
+ return {
1372
+ async createComplianceData(body, options) {
1373
+ return requestJson(http, {
1374
+ operationId: OP_CREATE_COMPLIANCE,
1375
+ method: "POST",
1376
+ path: "/v1/payer",
1377
+ body,
1378
+ requestSchemaKey: { operationId: OP_CREATE_COMPLIANCE, kind: "request", variant: "application/json" },
1379
+ schemaKey: { operationId: OP_CREATE_COMPLIANCE, kind: "response", status: 200 },
1380
+ description: "Legacy create compliance data",
1381
+ signal: options?.signal,
1382
+ timeoutMs: options?.timeoutMs,
1383
+ validation: options?.validation,
1384
+ meta: options?.meta
1385
+ });
1386
+ },
1387
+ async getComplianceStatus(clientUserId, options) {
1388
+ const path = `/v1/payer/${encodeURIComponent(clientUserId)}`;
1389
+ return requestJson(http, {
1390
+ operationId: OP_GET_STATUS,
1391
+ method: "GET",
1392
+ path,
1393
+ schemaKey: { operationId: OP_GET_STATUS, kind: "response", status: 200 },
1394
+ description: "Legacy get compliance status",
1395
+ signal: options?.signal,
1396
+ timeoutMs: options?.timeoutMs,
1397
+ validation: options?.validation,
1398
+ meta: options?.meta
1399
+ });
1400
+ },
1401
+ async updateComplianceStatus(clientUserId, body, options) {
1402
+ const path = `/v1/payer/${encodeURIComponent(clientUserId)}`;
1403
+ return requestJson(http, {
1404
+ operationId: OP_UPDATE_STATUS,
1405
+ method: "PATCH",
1406
+ path,
1407
+ body,
1408
+ requestSchemaKey: { operationId: OP_UPDATE_STATUS, kind: "request", variant: "application/json" },
1409
+ schemaKey: { operationId: OP_UPDATE_STATUS, kind: "response", status: 200 },
1410
+ description: "Legacy update compliance status",
1411
+ signal: options?.signal,
1412
+ timeoutMs: options?.timeoutMs,
1413
+ validation: options?.validation,
1414
+ meta: options?.meta
1415
+ });
1416
+ },
1417
+ async createPaymentDetails(clientUserId, body, options) {
1418
+ const path = `/v1/payer/${encodeURIComponent(clientUserId)}/payment-details`;
1419
+ return requestJson(http, {
1420
+ operationId: OP_CREATE_PAYMENT_DETAILS,
1421
+ method: "POST",
1422
+ path,
1423
+ body,
1424
+ requestSchemaKey: { operationId: OP_CREATE_PAYMENT_DETAILS, kind: "request", variant: "application/json" },
1425
+ schemaKey: { operationId: OP_CREATE_PAYMENT_DETAILS, kind: "response", status: 201 },
1426
+ description: "Legacy create payment details",
1427
+ signal: options?.signal,
1428
+ timeoutMs: options?.timeoutMs,
1429
+ validation: options?.validation,
1430
+ meta: options?.meta
1431
+ });
1432
+ },
1433
+ async getPaymentDetails(clientUserId, options) {
1434
+ const path = `/v1/payer/${encodeURIComponent(clientUserId)}/payment-details`;
1435
+ return requestJson(http, {
1436
+ operationId: OP_GET_PAYMENT_DETAILS,
1437
+ method: "GET",
1438
+ path,
1439
+ schemaKey: { operationId: OP_GET_PAYMENT_DETAILS, kind: "response", status: 200 },
1440
+ description: "Legacy get payment details",
1441
+ signal: options?.signal,
1442
+ timeoutMs: options?.timeoutMs,
1443
+ validation: options?.validation,
1444
+ meta: options?.meta
1445
+ });
1446
+ }
1447
+ };
1448
+ }
1449
+ var ErrorDetailSchema4 = zod.z.object({
1450
+ message: zod.z.string(),
1451
+ code: zod.z.string().optional(),
1452
+ field: zod.z.string().optional(),
1453
+ source: zod.z.object({
1454
+ pointer: zod.z.string().optional(),
1455
+ parameter: zod.z.string().optional()
1456
+ }).passthrough().optional(),
1457
+ meta: zod.z.record(zod.z.unknown()).optional()
1458
+ }).passthrough();
1459
+ var ErrorEnvelopeSchema4 = zod.z.object({
1460
+ status: zod.z.number().optional(),
1461
+ statusCode: zod.z.number().optional(),
1462
+ code: zod.z.string().optional(),
1463
+ error: zod.z.string().optional(),
1464
+ message: zod.z.union([
1465
+ zod.z.string(),
1466
+ zod.z.array(zod.z.union([zod.z.string(), ErrorDetailSchema4])),
1467
+ ErrorDetailSchema4
1468
+ ]).optional(),
1469
+ detail: zod.z.unknown().optional(),
1470
+ errors: zod.z.array(ErrorDetailSchema4).optional(),
1471
+ requestId: zod.z.string().optional(),
1472
+ correlationId: zod.z.string().optional(),
1473
+ retryAfter: zod.z.union([zod.z.number(), zod.z.string()]).optional(),
1474
+ retryAfterMs: zod.z.number().optional(),
1475
+ meta: zod.z.record(zod.z.unknown()).optional()
1476
+ }).passthrough();
1477
+ var PayerV1Controller_getComplianceData_v1_Request = zod.z.object({ "clientUserId": zod.z.string(), "email": zod.z.string(), "firstName": zod.z.string(), "lastName": zod.z.string(), "beneficiaryType": zod.z.enum(["individual", "business"]), "companyName": zod.z.string().optional(), "dateOfBirth": zod.z.string(), "addressLine1": zod.z.string(), "addressLine2": zod.z.string().optional(), "city": zod.z.string(), "state": zod.z.string(), "postcode": zod.z.string(), "country": zod.z.string(), "nationality": zod.z.string(), "phone": zod.z.string(), "ssn": zod.z.string(), "sourceOfFunds": zod.z.string().optional(), "businessActivity": zod.z.string().optional() }).passthrough();
1478
+ schemaRegistry.register({ key: { operationId: "PayerV1Controller_getComplianceData_v1", kind: "request", variant: "application/json" }, schema: PayerV1Controller_getComplianceData_v1_Request });
1479
+ var PayerV1Controller_getComplianceData_v1_200 = zod.z.object({ "agreementUrl": zod.z.string().optional(), "kycUrl": zod.z.string().optional(), "status": zod.z.object({ "agreementStatus": zod.z.enum(["not_started", "completed"]), "kycStatus": zod.z.enum(["not_started", "completed"]) }).passthrough(), "userId": zod.z.string().optional() }).passthrough();
1480
+ schemaRegistry.register({ key: { operationId: "PayerV1Controller_getComplianceData_v1", kind: "response", status: 200 }, schema: PayerV1Controller_getComplianceData_v1_200 });
1481
+ var PayerV1Controller_getComplianceData_v1_400 = zod.z.object({ "statusCode": zod.z.number().optional(), "message": zod.z.string().optional(), "error": zod.z.string().optional() }).passthrough();
1482
+ schemaRegistry.register({ key: { operationId: "PayerV1Controller_getComplianceData_v1", kind: "response", status: 400 }, schema: PayerV1Controller_getComplianceData_v1_400 });
1483
+ var PayerV1Controller_getComplianceData_v1_401 = ErrorEnvelopeSchema4;
1484
+ schemaRegistry.register({ key: { operationId: "PayerV1Controller_getComplianceData_v1", kind: "response", status: 401 }, schema: PayerV1Controller_getComplianceData_v1_401 });
1485
+ var PayerV1Controller_getComplianceData_v1_404 = zod.z.object({ "statusCode": zod.z.number().optional(), "message": zod.z.string().optional(), "error": zod.z.string().optional() }).passthrough();
1486
+ schemaRegistry.register({ key: { operationId: "PayerV1Controller_getComplianceData_v1", kind: "response", status: 404 }, schema: PayerV1Controller_getComplianceData_v1_404 });
1487
+ var PayerV1Controller_getComplianceData_v1_429 = ErrorEnvelopeSchema4;
1488
+ schemaRegistry.register({ key: { operationId: "PayerV1Controller_getComplianceData_v1", kind: "response", status: 429 }, schema: PayerV1Controller_getComplianceData_v1_429 });
1489
+ var PayerV1Controller_getComplianceStatus_v1_200 = zod.z.object({ "kycStatus": zod.z.string().optional(), "agreementStatus": zod.z.string().optional(), "isCompliant": zod.z.boolean().optional(), "userId": zod.z.string().optional() }).passthrough();
1490
+ schemaRegistry.register({ key: { operationId: "PayerV1Controller_getComplianceStatus_v1", kind: "response", status: 200 }, schema: PayerV1Controller_getComplianceStatus_v1_200 });
1491
+ var PayerV1Controller_getComplianceStatus_v1_401 = ErrorEnvelopeSchema4;
1492
+ schemaRegistry.register({ key: { operationId: "PayerV1Controller_getComplianceStatus_v1", kind: "response", status: 401 }, schema: PayerV1Controller_getComplianceStatus_v1_401 });
1493
+ var PayerV1Controller_getComplianceStatus_v1_404 = zod.z.object({ "statusCode": zod.z.number().optional(), "message": zod.z.string().optional(), "error": zod.z.string().optional() }).passthrough();
1494
+ schemaRegistry.register({ key: { operationId: "PayerV1Controller_getComplianceStatus_v1", kind: "response", status: 404 }, schema: PayerV1Controller_getComplianceStatus_v1_404 });
1495
+ var PayerV1Controller_getComplianceStatus_v1_429 = ErrorEnvelopeSchema4;
1496
+ schemaRegistry.register({ key: { operationId: "PayerV1Controller_getComplianceStatus_v1", kind: "response", status: 429 }, schema: PayerV1Controller_getComplianceStatus_v1_429 });
1497
+ var PayerV1Controller_updateComplianceStatus_v1_Request = zod.z.object({ "agreementCompleted": zod.z.boolean() }).passthrough();
1498
+ schemaRegistry.register({ key: { operationId: "PayerV1Controller_updateComplianceStatus_v1", kind: "request", variant: "application/json" }, schema: PayerV1Controller_updateComplianceStatus_v1_Request });
1499
+ var PayerV1Controller_updateComplianceStatus_v1_200 = zod.z.object({ "success": zod.z.boolean().optional() }).passthrough();
1500
+ schemaRegistry.register({ key: { operationId: "PayerV1Controller_updateComplianceStatus_v1", kind: "response", status: 200 }, schema: PayerV1Controller_updateComplianceStatus_v1_200 });
1501
+ var PayerV1Controller_updateComplianceStatus_v1_400 = zod.z.object({ "statusCode": zod.z.number().optional(), "message": zod.z.string().optional(), "error": zod.z.string().optional() }).passthrough();
1502
+ schemaRegistry.register({ key: { operationId: "PayerV1Controller_updateComplianceStatus_v1", kind: "response", status: 400 }, schema: PayerV1Controller_updateComplianceStatus_v1_400 });
1503
+ var PayerV1Controller_updateComplianceStatus_v1_401 = ErrorEnvelopeSchema4;
1504
+ schemaRegistry.register({ key: { operationId: "PayerV1Controller_updateComplianceStatus_v1", kind: "response", status: 401 }, schema: PayerV1Controller_updateComplianceStatus_v1_401 });
1505
+ var PayerV1Controller_updateComplianceStatus_v1_404 = zod.z.object({ "statusCode": zod.z.number().optional(), "message": zod.z.string().optional(), "error": zod.z.string().optional() }).passthrough();
1506
+ schemaRegistry.register({ key: { operationId: "PayerV1Controller_updateComplianceStatus_v1", kind: "response", status: 404 }, schema: PayerV1Controller_updateComplianceStatus_v1_404 });
1507
+ var PayerV1Controller_updateComplianceStatus_v1_429 = ErrorEnvelopeSchema4;
1508
+ schemaRegistry.register({ key: { operationId: "PayerV1Controller_updateComplianceStatus_v1", kind: "response", status: 429 }, schema: PayerV1Controller_updateComplianceStatus_v1_429 });
1509
+ var PayerV1Controller_getPaymentDetails_v1_200 = zod.z.object({ "paymentDetails": zod.z.array(zod.z.object({ "id": zod.z.string().optional(), "userId": zod.z.string().optional(), "bankName": zod.z.string().optional(), "accountName": zod.z.string().optional(), "beneficiaryType": zod.z.string().optional(), "accountNumber": zod.z.string().optional(), "routingNumber": zod.z.string().optional(), "currency": zod.z.string().optional(), "status": zod.z.string().optional(), "rails": zod.z.string().optional() }).passthrough()).optional() }).passthrough();
1510
+ schemaRegistry.register({ key: { operationId: "PayerV1Controller_getPaymentDetails_v1", kind: "response", status: 200 }, schema: PayerV1Controller_getPaymentDetails_v1_200 });
1511
+ var PayerV1Controller_getPaymentDetails_v1_401 = ErrorEnvelopeSchema4;
1512
+ schemaRegistry.register({ key: { operationId: "PayerV1Controller_getPaymentDetails_v1", kind: "response", status: 401 }, schema: PayerV1Controller_getPaymentDetails_v1_401 });
1513
+ var PayerV1Controller_getPaymentDetails_v1_404 = zod.z.object({ "statusCode": zod.z.number().optional(), "message": zod.z.string().optional(), "error": zod.z.string().optional() }).passthrough();
1514
+ schemaRegistry.register({ key: { operationId: "PayerV1Controller_getPaymentDetails_v1", kind: "response", status: 404 }, schema: PayerV1Controller_getPaymentDetails_v1_404 });
1515
+ var PayerV1Controller_getPaymentDetails_v1_429 = ErrorEnvelopeSchema4;
1516
+ schemaRegistry.register({ key: { operationId: "PayerV1Controller_getPaymentDetails_v1", kind: "response", status: 429 }, schema: PayerV1Controller_getPaymentDetails_v1_429 });
1517
+ var PayerV1Controller_createPaymentDetails_v1_Request = zod.z.object({ "bankName": zod.z.string(), "accountName": zod.z.string(), "accountNumber": zod.z.string().optional(), "routingNumber": zod.z.string().optional(), "beneficiaryType": zod.z.enum(["individual", "business"]), "currency": zod.z.string(), "addressLine1": zod.z.string(), "addressLine2": zod.z.string().optional(), "city": zod.z.string(), "state": zod.z.string().optional(), "country": zod.z.string(), "dateOfBirth": zod.z.string(), "postalCode": zod.z.string(), "rails": zod.z.enum(["local", "swift", "wire"]).optional(), "sortCode": zod.z.string().optional(), "iban": zod.z.string().optional(), "swiftBic": zod.z.string().optional(), "documentNumber": zod.z.string().optional(), "documentType": zod.z.string().optional(), "accountType": zod.z.enum(["checking", "savings"]).optional(), "ribNumber": zod.z.string().optional(), "bsbNumber": zod.z.string().optional(), "ncc": zod.z.string().optional(), "branchCode": zod.z.string().optional(), "bankCode": zod.z.string().optional(), "ifsc": zod.z.string().optional() }).passthrough();
1518
+ schemaRegistry.register({ key: { operationId: "PayerV1Controller_createPaymentDetails_v1", kind: "request", variant: "application/json" }, schema: PayerV1Controller_createPaymentDetails_v1_Request });
1519
+ var PayerV1Controller_createPaymentDetails_v1_201 = zod.z.object({ "payment_detail": zod.z.object({ "id": zod.z.string().optional(), "clientUserId": zod.z.string().optional(), "bankName": zod.z.string().optional(), "accountName": zod.z.string().optional(), "currency": zod.z.string().optional(), "beneficiaryType": zod.z.enum(["individual", "business"]).optional() }).passthrough().optional() }).passthrough();
1520
+ schemaRegistry.register({ key: { operationId: "PayerV1Controller_createPaymentDetails_v1", kind: "response", status: 201 }, schema: PayerV1Controller_createPaymentDetails_v1_201 });
1521
+ var PayerV1Controller_createPaymentDetails_v1_400 = zod.z.object({ "statusCode": zod.z.number().optional(), "message": zod.z.string().optional(), "error": zod.z.string().optional() }).passthrough();
1522
+ schemaRegistry.register({ key: { operationId: "PayerV1Controller_createPaymentDetails_v1", kind: "response", status: 400 }, schema: PayerV1Controller_createPaymentDetails_v1_400 });
1523
+ var PayerV1Controller_createPaymentDetails_v1_401 = ErrorEnvelopeSchema4;
1524
+ schemaRegistry.register({ key: { operationId: "PayerV1Controller_createPaymentDetails_v1", kind: "response", status: 401 }, schema: PayerV1Controller_createPaymentDetails_v1_401 });
1525
+ var PayerV1Controller_createPaymentDetails_v1_404 = zod.z.object({ "statusCode": zod.z.number().optional(), "message": zod.z.string().optional(), "error": zod.z.string().optional() }).passthrough();
1526
+ schemaRegistry.register({ key: { operationId: "PayerV1Controller_createPaymentDetails_v1", kind: "response", status: 404 }, schema: PayerV1Controller_createPaymentDetails_v1_404 });
1527
+ var PayerV1Controller_createPaymentDetails_v1_429 = ErrorEnvelopeSchema4;
1528
+ schemaRegistry.register({ key: { operationId: "PayerV1Controller_createPaymentDetails_v1", kind: "response", status: 429 }, schema: PayerV1Controller_createPaymentDetails_v1_429 });
1529
+ var PayerV2Controller_getComplianceData_v2_Request = zod.z.object({ "clientUserId": zod.z.string(), "email": zod.z.string(), "firstName": zod.z.string(), "lastName": zod.z.string(), "beneficiaryType": zod.z.enum(["individual", "business"]), "companyName": zod.z.string().optional(), "dateOfBirth": zod.z.string(), "addressLine1": zod.z.string(), "addressLine2": zod.z.string().optional(), "city": zod.z.string(), "state": zod.z.string(), "postcode": zod.z.string(), "country": zod.z.string(), "nationality": zod.z.string(), "phone": zod.z.string(), "ssn": zod.z.string(), "sourceOfFunds": zod.z.string().optional(), "businessActivity": zod.z.string().optional() }).passthrough();
1530
+ schemaRegistry.register({ key: { operationId: "PayerV2Controller_getComplianceData_v2", kind: "request", variant: "application/json" }, schema: PayerV2Controller_getComplianceData_v2_Request });
1531
+ var PayerV2Controller_getComplianceData_v2_200 = zod.z.object({ "agreementUrl": zod.z.string().optional(), "kycUrl": zod.z.string().optional(), "status": zod.z.object({ "agreementStatus": zod.z.enum(["not_started", "completed"]), "kycStatus": zod.z.enum(["not_started", "completed"]) }).passthrough(), "userId": zod.z.string().optional() }).passthrough();
1532
+ schemaRegistry.register({ key: { operationId: "PayerV2Controller_getComplianceData_v2", kind: "response", status: 200 }, schema: PayerV2Controller_getComplianceData_v2_200 });
1533
+ var PayerV2Controller_getComplianceData_v2_400 = zod.z.object({ "statusCode": zod.z.number().optional(), "message": zod.z.string().optional(), "error": zod.z.string().optional() }).passthrough();
1534
+ schemaRegistry.register({ key: { operationId: "PayerV2Controller_getComplianceData_v2", kind: "response", status: 400 }, schema: PayerV2Controller_getComplianceData_v2_400 });
1535
+ var PayerV2Controller_getComplianceData_v2_401 = ErrorEnvelopeSchema4;
1536
+ schemaRegistry.register({ key: { operationId: "PayerV2Controller_getComplianceData_v2", kind: "response", status: 401 }, schema: PayerV2Controller_getComplianceData_v2_401 });
1537
+ var PayerV2Controller_getComplianceData_v2_404 = zod.z.object({ "statusCode": zod.z.number().optional(), "message": zod.z.string().optional(), "error": zod.z.string().optional() }).passthrough();
1538
+ schemaRegistry.register({ key: { operationId: "PayerV2Controller_getComplianceData_v2", kind: "response", status: 404 }, schema: PayerV2Controller_getComplianceData_v2_404 });
1539
+ var PayerV2Controller_getComplianceData_v2_429 = ErrorEnvelopeSchema4;
1540
+ schemaRegistry.register({ key: { operationId: "PayerV2Controller_getComplianceData_v2", kind: "response", status: 429 }, schema: PayerV2Controller_getComplianceData_v2_429 });
1541
+ var PayerV2Controller_getComplianceStatus_v2_200 = zod.z.object({ "kycStatus": zod.z.string().optional(), "agreementStatus": zod.z.string().optional(), "isCompliant": zod.z.boolean().optional(), "userId": zod.z.string().optional() }).passthrough();
1542
+ schemaRegistry.register({ key: { operationId: "PayerV2Controller_getComplianceStatus_v2", kind: "response", status: 200 }, schema: PayerV2Controller_getComplianceStatus_v2_200 });
1543
+ var PayerV2Controller_getComplianceStatus_v2_401 = ErrorEnvelopeSchema4;
1544
+ schemaRegistry.register({ key: { operationId: "PayerV2Controller_getComplianceStatus_v2", kind: "response", status: 401 }, schema: PayerV2Controller_getComplianceStatus_v2_401 });
1545
+ var PayerV2Controller_getComplianceStatus_v2_404 = zod.z.object({ "statusCode": zod.z.number().optional(), "message": zod.z.string().optional(), "error": zod.z.string().optional() }).passthrough();
1546
+ schemaRegistry.register({ key: { operationId: "PayerV2Controller_getComplianceStatus_v2", kind: "response", status: 404 }, schema: PayerV2Controller_getComplianceStatus_v2_404 });
1547
+ var PayerV2Controller_getComplianceStatus_v2_429 = ErrorEnvelopeSchema4;
1548
+ schemaRegistry.register({ key: { operationId: "PayerV2Controller_getComplianceStatus_v2", kind: "response", status: 429 }, schema: PayerV2Controller_getComplianceStatus_v2_429 });
1549
+ var PayerV2Controller_updateComplianceStatus_v2_Request = zod.z.object({ "agreementCompleted": zod.z.boolean() }).passthrough();
1550
+ schemaRegistry.register({ key: { operationId: "PayerV2Controller_updateComplianceStatus_v2", kind: "request", variant: "application/json" }, schema: PayerV2Controller_updateComplianceStatus_v2_Request });
1551
+ var PayerV2Controller_updateComplianceStatus_v2_200 = zod.z.object({ "success": zod.z.boolean().optional() }).passthrough();
1552
+ schemaRegistry.register({ key: { operationId: "PayerV2Controller_updateComplianceStatus_v2", kind: "response", status: 200 }, schema: PayerV2Controller_updateComplianceStatus_v2_200 });
1553
+ var PayerV2Controller_updateComplianceStatus_v2_400 = zod.z.object({ "statusCode": zod.z.number().optional(), "message": zod.z.string().optional(), "error": zod.z.string().optional() }).passthrough();
1554
+ schemaRegistry.register({ key: { operationId: "PayerV2Controller_updateComplianceStatus_v2", kind: "response", status: 400 }, schema: PayerV2Controller_updateComplianceStatus_v2_400 });
1555
+ var PayerV2Controller_updateComplianceStatus_v2_401 = ErrorEnvelopeSchema4;
1556
+ schemaRegistry.register({ key: { operationId: "PayerV2Controller_updateComplianceStatus_v2", kind: "response", status: 401 }, schema: PayerV2Controller_updateComplianceStatus_v2_401 });
1557
+ var PayerV2Controller_updateComplianceStatus_v2_404 = zod.z.object({ "statusCode": zod.z.number().optional(), "message": zod.z.string().optional(), "error": zod.z.string().optional() }).passthrough();
1558
+ schemaRegistry.register({ key: { operationId: "PayerV2Controller_updateComplianceStatus_v2", kind: "response", status: 404 }, schema: PayerV2Controller_updateComplianceStatus_v2_404 });
1559
+ var PayerV2Controller_updateComplianceStatus_v2_429 = ErrorEnvelopeSchema4;
1560
+ schemaRegistry.register({ key: { operationId: "PayerV2Controller_updateComplianceStatus_v2", kind: "response", status: 429 }, schema: PayerV2Controller_updateComplianceStatus_v2_429 });
1561
+ var PayerV2Controller_getPaymentDetails_v2_200 = zod.z.object({ "paymentDetails": zod.z.array(zod.z.object({ "id": zod.z.string().optional(), "userId": zod.z.string().optional(), "bankName": zod.z.string().optional(), "accountName": zod.z.string().optional(), "beneficiaryType": zod.z.string().optional(), "accountNumber": zod.z.string().optional(), "routingNumber": zod.z.string().optional(), "currency": zod.z.string().optional(), "status": zod.z.string().optional(), "rails": zod.z.string().optional() }).passthrough()).optional() }).passthrough();
1562
+ schemaRegistry.register({ key: { operationId: "PayerV2Controller_getPaymentDetails_v2", kind: "response", status: 200 }, schema: PayerV2Controller_getPaymentDetails_v2_200 });
1563
+ var PayerV2Controller_getPaymentDetails_v2_401 = ErrorEnvelopeSchema4;
1564
+ schemaRegistry.register({ key: { operationId: "PayerV2Controller_getPaymentDetails_v2", kind: "response", status: 401 }, schema: PayerV2Controller_getPaymentDetails_v2_401 });
1565
+ var PayerV2Controller_getPaymentDetails_v2_404 = zod.z.object({ "statusCode": zod.z.number().optional(), "message": zod.z.string().optional(), "error": zod.z.string().optional() }).passthrough();
1566
+ schemaRegistry.register({ key: { operationId: "PayerV2Controller_getPaymentDetails_v2", kind: "response", status: 404 }, schema: PayerV2Controller_getPaymentDetails_v2_404 });
1567
+ var PayerV2Controller_getPaymentDetails_v2_429 = ErrorEnvelopeSchema4;
1568
+ schemaRegistry.register({ key: { operationId: "PayerV2Controller_getPaymentDetails_v2", kind: "response", status: 429 }, schema: PayerV2Controller_getPaymentDetails_v2_429 });
1569
+ var PayerV2Controller_createPaymentDetails_v2_Request = zod.z.object({ "bankName": zod.z.string(), "accountName": zod.z.string(), "accountNumber": zod.z.string().optional(), "routingNumber": zod.z.string().optional(), "beneficiaryType": zod.z.enum(["individual", "business"]), "currency": zod.z.string(), "addressLine1": zod.z.string(), "addressLine2": zod.z.string().optional(), "city": zod.z.string(), "state": zod.z.string().optional(), "country": zod.z.string(), "dateOfBirth": zod.z.string(), "postalCode": zod.z.string(), "rails": zod.z.enum(["local", "swift", "wire"]).optional(), "sortCode": zod.z.string().optional(), "iban": zod.z.string().optional(), "swiftBic": zod.z.string().optional(), "documentNumber": zod.z.string().optional(), "documentType": zod.z.string().optional(), "accountType": zod.z.enum(["checking", "savings"]).optional(), "ribNumber": zod.z.string().optional(), "bsbNumber": zod.z.string().optional(), "ncc": zod.z.string().optional(), "branchCode": zod.z.string().optional(), "bankCode": zod.z.string().optional(), "ifsc": zod.z.string().optional() }).passthrough();
1570
+ schemaRegistry.register({ key: { operationId: "PayerV2Controller_createPaymentDetails_v2", kind: "request", variant: "application/json" }, schema: PayerV2Controller_createPaymentDetails_v2_Request });
1571
+ var PayerV2Controller_createPaymentDetails_v2_201 = zod.z.object({ "payment_detail": zod.z.object({ "id": zod.z.string().optional(), "clientUserId": zod.z.string().optional(), "bankName": zod.z.string().optional(), "accountName": zod.z.string().optional(), "currency": zod.z.string().optional(), "beneficiaryType": zod.z.enum(["individual", "business"]).optional() }).passthrough().optional() }).passthrough();
1572
+ schemaRegistry.register({ key: { operationId: "PayerV2Controller_createPaymentDetails_v2", kind: "response", status: 201 }, schema: PayerV2Controller_createPaymentDetails_v2_201 });
1573
+ var PayerV2Controller_createPaymentDetails_v2_400 = zod.z.object({ "statusCode": zod.z.number().optional(), "message": zod.z.string().optional(), "error": zod.z.string().optional() }).passthrough();
1574
+ schemaRegistry.register({ key: { operationId: "PayerV2Controller_createPaymentDetails_v2", kind: "response", status: 400 }, schema: PayerV2Controller_createPaymentDetails_v2_400 });
1575
+ var PayerV2Controller_createPaymentDetails_v2_401 = ErrorEnvelopeSchema4;
1576
+ schemaRegistry.register({ key: { operationId: "PayerV2Controller_createPaymentDetails_v2", kind: "response", status: 401 }, schema: PayerV2Controller_createPaymentDetails_v2_401 });
1577
+ var PayerV2Controller_createPaymentDetails_v2_404 = zod.z.object({ "statusCode": zod.z.number().optional(), "message": zod.z.string().optional(), "error": zod.z.string().optional() }).passthrough();
1578
+ schemaRegistry.register({ key: { operationId: "PayerV2Controller_createPaymentDetails_v2", kind: "response", status: 404 }, schema: PayerV2Controller_createPaymentDetails_v2_404 });
1579
+ var PayerV2Controller_createPaymentDetails_v2_429 = ErrorEnvelopeSchema4;
1580
+ schemaRegistry.register({ key: { operationId: "PayerV2Controller_createPaymentDetails_v2", kind: "response", status: 429 }, schema: PayerV2Controller_createPaymentDetails_v2_429 });
1581
+
1582
+ // src/domains/payer/v2/index.ts
1583
+ var v2_exports = {};
1584
+ __export(v2_exports, {
1585
+ createPayerV2Api: () => createPayerV2Api
1586
+ });
1587
+
1588
+ // src/domains/payer/v2/payer.v2.facade.ts
1589
+ var OP_CREATE_COMPLIANCE2 = "PayerV2Controller_getComplianceData_v2";
1590
+ var OP_GET_STATUS2 = "PayerV2Controller_getComplianceStatus_v2";
1591
+ var OP_UPDATE_STATUS2 = "PayerV2Controller_updateComplianceStatus_v2";
1592
+ var OP_CREATE_PAYMENT_DETAILS2 = "PayerV2Controller_createPaymentDetails_v2";
1593
+ var OP_GET_PAYMENT_DETAILS2 = "PayerV2Controller_getPaymentDetails_v2";
1594
+ function createPayerV2Api(http) {
1595
+ return {
1596
+ async createComplianceData(body, options) {
1597
+ return requestJson(http, {
1598
+ operationId: OP_CREATE_COMPLIANCE2,
1599
+ method: "POST",
1600
+ path: "/v2/payer",
1601
+ body,
1602
+ requestSchemaKey: { operationId: OP_CREATE_COMPLIANCE2, kind: "request", variant: "application/json" },
1603
+ schemaKey: { operationId: OP_CREATE_COMPLIANCE2, kind: "response", status: 200 },
1604
+ description: "Create compliance data",
1605
+ signal: options?.signal,
1606
+ timeoutMs: options?.timeoutMs,
1607
+ validation: options?.validation,
1608
+ meta: options?.meta
1609
+ });
1610
+ },
1611
+ async getComplianceStatus(clientUserId, options) {
1612
+ const path = `/v2/payer/${encodeURIComponent(clientUserId)}`;
1613
+ return requestJson(http, {
1614
+ operationId: OP_GET_STATUS2,
1615
+ method: "GET",
1616
+ path,
1617
+ schemaKey: { operationId: OP_GET_STATUS2, kind: "response", status: 200 },
1618
+ description: "Get compliance status",
1619
+ signal: options?.signal,
1620
+ timeoutMs: options?.timeoutMs,
1621
+ validation: options?.validation,
1622
+ meta: options?.meta
1623
+ });
1624
+ },
1625
+ async updateComplianceStatus(clientUserId, body, options) {
1626
+ const path = `/v2/payer/${encodeURIComponent(clientUserId)}`;
1627
+ return requestJson(http, {
1628
+ operationId: OP_UPDATE_STATUS2,
1629
+ method: "PATCH",
1630
+ path,
1631
+ body,
1632
+ requestSchemaKey: { operationId: OP_UPDATE_STATUS2, kind: "request", variant: "application/json" },
1633
+ schemaKey: { operationId: OP_UPDATE_STATUS2, kind: "response", status: 200 },
1634
+ description: "Update compliance status",
1635
+ signal: options?.signal,
1636
+ timeoutMs: options?.timeoutMs,
1637
+ validation: options?.validation,
1638
+ meta: options?.meta
1639
+ });
1640
+ },
1641
+ async createPaymentDetails(clientUserId, body, options) {
1642
+ const path = `/v2/payer/${encodeURIComponent(clientUserId)}/payment-details`;
1643
+ return requestJson(http, {
1644
+ operationId: OP_CREATE_PAYMENT_DETAILS2,
1645
+ method: "POST",
1646
+ path,
1647
+ body,
1648
+ requestSchemaKey: { operationId: OP_CREATE_PAYMENT_DETAILS2, kind: "request", variant: "application/json" },
1649
+ schemaKey: { operationId: OP_CREATE_PAYMENT_DETAILS2, kind: "response", status: 201 },
1650
+ description: "Create payment details",
1651
+ signal: options?.signal,
1652
+ timeoutMs: options?.timeoutMs,
1653
+ validation: options?.validation,
1654
+ meta: options?.meta
1655
+ });
1656
+ },
1657
+ async getPaymentDetails(clientUserId, options) {
1658
+ const path = `/v2/payer/${encodeURIComponent(clientUserId)}/payment-details`;
1659
+ return requestJson(http, {
1660
+ operationId: OP_GET_PAYMENT_DETAILS2,
1661
+ method: "GET",
1662
+ path,
1663
+ schemaKey: { operationId: OP_GET_PAYMENT_DETAILS2, kind: "response", status: 200 },
1664
+ description: "Get payment details",
1665
+ signal: options?.signal,
1666
+ timeoutMs: options?.timeoutMs,
1667
+ validation: options?.validation,
1668
+ meta: options?.meta
1669
+ });
1670
+ }
1671
+ };
1672
+ }
1673
+
1674
+ // src/domains/payer/payer.facade.ts
1675
+ function createPayerApi(http) {
1676
+ const v2 = createPayerV2Api(http);
1677
+ const legacy = createPayerV1Api(http);
1678
+ return Object.assign({ legacy }, v2);
1679
+ }
1680
+
1681
+ // src/domains/payments/index.ts
1682
+ var payments_exports = {};
1683
+ __export(payments_exports, {
1684
+ createPaymentsApi: () => createPaymentsApi
1685
+ });
1686
+ var ErrorDetailSchema5 = zod.z.object({
1687
+ message: zod.z.string(),
1688
+ code: zod.z.string().optional(),
1689
+ field: zod.z.string().optional(),
1690
+ source: zod.z.object({
1691
+ pointer: zod.z.string().optional(),
1692
+ parameter: zod.z.string().optional()
1693
+ }).passthrough().optional(),
1694
+ meta: zod.z.record(zod.z.unknown()).optional()
1695
+ }).passthrough();
1696
+ var ErrorEnvelopeSchema5 = zod.z.object({
1697
+ status: zod.z.number().optional(),
1698
+ statusCode: zod.z.number().optional(),
1699
+ code: zod.z.string().optional(),
1700
+ error: zod.z.string().optional(),
1701
+ message: zod.z.union([
1702
+ zod.z.string(),
1703
+ zod.z.array(zod.z.union([zod.z.string(), ErrorDetailSchema5])),
1704
+ ErrorDetailSchema5
1705
+ ]).optional(),
1706
+ detail: zod.z.unknown().optional(),
1707
+ errors: zod.z.array(ErrorDetailSchema5).optional(),
1708
+ requestId: zod.z.string().optional(),
1709
+ correlationId: zod.z.string().optional(),
1710
+ retryAfter: zod.z.union([zod.z.number(), zod.z.string()]).optional(),
1711
+ retryAfterMs: zod.z.number().optional(),
1712
+ meta: zod.z.record(zod.z.unknown()).optional()
1713
+ }).passthrough();
1714
+ var PaymentV2Controller_searchPayments_v2_200 = zod.z.object({ "payments": zod.z.array(zod.z.object({ "id": zod.z.string(), "amount": zod.z.string(), "sourceNetwork": zod.z.string(), "destinationNetwork": zod.z.string(), "sourceTxHash": zod.z.string().nullable().optional(), "destinationTxHash": zod.z.string().nullable().optional(), "timestamp": zod.z.string(), "type": zod.z.enum(["direct", "conversion", "crosschain", "recurring"]), "conversionRateSource": zod.z.string().nullable().optional(), "conversionRateDestination": zod.z.string().nullable().optional(), "convertedAmountSource": zod.z.string().nullable().optional(), "convertedAmountDestination": zod.z.string().nullable().optional(), "currency": zod.z.string(), "paymentCurrency": zod.z.string(), "fees": zod.z.array(zod.z.object({ "type": zod.z.enum(["gas", "platform", "crosschain", "crypto-to-fiat", "offramp"]).optional(), "stage": zod.z.enum(["sending", "receiving", "proxying", "refunding"]).optional(), "provider": zod.z.string().optional(), "amount": zod.z.string().optional(), "amountInUSD": zod.z.string().optional(), "currency": zod.z.string().optional(), "receiverAddress": zod.z.string().optional(), "network": zod.z.string().optional(), "rateProvider": zod.z.string().optional() }).passthrough()).nullable().optional(), "recurringPaymentId": zod.z.string().nullable().optional(), "rateProvider": zod.z.enum(["lifi", "chainlink", "coingecko", "unknown"]).optional(), "request": zod.z.object({ "requestId": zod.z.string().optional(), "paymentReference": zod.z.string().optional(), "hasBeenPaid": zod.z.boolean().optional(), "customerInfo": zod.z.object({ "firstName": zod.z.string().optional(), "lastName": zod.z.string().optional(), "email": zod.z.string().optional(), "address": zod.z.object({ "street": zod.z.string().optional(), "city": zod.z.string().optional(), "state": zod.z.string().optional(), "postalCode": zod.z.string().optional(), "country": zod.z.string().optional() }).passthrough().optional() }).passthrough().nullable().optional(), "reference": zod.z.string().nullable().optional() }).passthrough().optional() }).passthrough()), "pagination": zod.z.object({ "total": zod.z.number(), "limit": zod.z.number(), "offset": zod.z.number(), "hasMore": zod.z.boolean() }).passthrough() }).passthrough();
1715
+ schemaRegistry.register({ key: { operationId: "PaymentV2Controller_searchPayments_v2", kind: "response", status: 200 }, schema: PaymentV2Controller_searchPayments_v2_200 });
1716
+ var PaymentV2Controller_searchPayments_v2_400 = zod.z.object({ "statusCode": zod.z.number().optional(), "message": zod.z.string().optional(), "errors": zod.z.array(zod.z.object({ "field": zod.z.string().optional(), "message": zod.z.string().optional() }).passthrough()).optional() }).passthrough();
1717
+ schemaRegistry.register({ key: { operationId: "PaymentV2Controller_searchPayments_v2", kind: "response", status: 400 }, schema: PaymentV2Controller_searchPayments_v2_400 });
1718
+ var PaymentV2Controller_searchPayments_v2_401 = zod.z.object({ "statusCode": zod.z.number().optional(), "message": zod.z.string().optional(), "error": zod.z.string().optional() }).passthrough();
1719
+ schemaRegistry.register({ key: { operationId: "PaymentV2Controller_searchPayments_v2", kind: "response", status: 401 }, schema: PaymentV2Controller_searchPayments_v2_401 });
1720
+ var PaymentV2Controller_searchPayments_v2_429 = ErrorEnvelopeSchema5;
1721
+ schemaRegistry.register({ key: { operationId: "PaymentV2Controller_searchPayments_v2", kind: "response", status: 429 }, schema: PaymentV2Controller_searchPayments_v2_429 });
1722
+
1723
+ // src/domains/payments/payments.schemas.ts
1724
+ var OP_SEARCH_PAYMENTS = "PaymentV2Controller_searchPayments_v2";
1725
+ var AddressSchema = zod.z.object({
1726
+ street: zod.z.string().optional(),
1727
+ city: zod.z.string().optional(),
1728
+ state: zod.z.string().optional(),
1729
+ postalCode: zod.z.string().optional(),
1730
+ country: zod.z.string().optional()
1731
+ }).passthrough();
1732
+ var CustomerInfoSchema = zod.z.object({
1733
+ firstName: zod.z.string().optional(),
1734
+ lastName: zod.z.string().optional(),
1735
+ email: zod.z.string().optional(),
1736
+ address: AddressSchema.optional()
1737
+ }).passthrough();
1738
+ var FeeSchema = zod.z.object({
1739
+ type: zod.z.enum(["gas", "platform", "crosschain", "crypto-to-fiat", "offramp"]).optional(),
1740
+ stage: zod.z.enum(["sending", "receiving", "proxying", "refunding"]).optional(),
1741
+ provider: zod.z.string().optional(),
1742
+ amount: zod.z.string().optional(),
1743
+ amountInUSD: zod.z.string().optional(),
1744
+ currency: zod.z.string().optional(),
1745
+ receiverAddress: zod.z.string().optional(),
1746
+ network: zod.z.string().optional(),
1747
+ rateProvider: zod.z.string().optional()
1748
+ }).passthrough();
1749
+ var RequestInfoSchema = zod.z.object({
1750
+ requestId: zod.z.string().optional(),
1751
+ paymentReference: zod.z.string().optional(),
1752
+ hasBeenPaid: zod.z.boolean().optional(),
1753
+ customerInfo: CustomerInfoSchema.nullable().optional(),
1754
+ reference: zod.z.string().nullable().optional()
1755
+ }).passthrough();
1756
+ var PaymentRecordSchema = zod.z.object({
1757
+ id: zod.z.string(),
1758
+ amount: zod.z.string(),
1759
+ sourceNetwork: zod.z.string(),
1760
+ destinationNetwork: zod.z.string(),
1761
+ sourceTxHash: zod.z.string().nullable().optional(),
1762
+ destinationTxHash: zod.z.string().nullable().optional(),
1763
+ timestamp: zod.z.string(),
1764
+ type: zod.z.enum(["direct", "conversion", "crosschain", "recurring"]),
1765
+ conversionRateSource: zod.z.string().nullable().optional(),
1766
+ conversionRateDestination: zod.z.string().nullable().optional(),
1767
+ convertedAmountSource: zod.z.string().nullable().optional(),
1768
+ convertedAmountDestination: zod.z.string().nullable().optional(),
1769
+ currency: zod.z.string(),
1770
+ paymentCurrency: zod.z.string(),
1771
+ fees: zod.z.array(FeeSchema).nullable().optional(),
1772
+ recurringPaymentId: zod.z.string().nullable().optional(),
1773
+ rateProvider: zod.z.enum(["lifi", "chainlink", "coingecko", "unknown"]).nullable().optional(),
1774
+ request: RequestInfoSchema.optional()
1775
+ }).passthrough();
1776
+ var PaginationSchema = zod.z.object({
1777
+ total: zod.z.number(),
1778
+ limit: zod.z.number(),
1779
+ offset: zod.z.number(),
1780
+ hasMore: zod.z.boolean()
1781
+ }).passthrough();
1782
+ var PaymentSearchResponseSchema = zod.z.object({
1783
+ payments: zod.z.array(PaymentRecordSchema),
1784
+ pagination: PaginationSchema
1785
+ }).passthrough();
1786
+ schemaRegistry.register({
1787
+ key: { operationId: OP_SEARCH_PAYMENTS, kind: "response", status: 200 },
1788
+ schema: PaymentSearchResponseSchema
1789
+ });
1790
+
1791
+ // src/domains/requests/request.helpers.ts
1792
+ function buildRequestQuery(input) {
1793
+ if (!input) return void 0;
1794
+ const entries = Object.entries(input).filter(([, value]) => value !== void 0);
1795
+ if (entries.length === 0) return void 0;
1796
+ return Object.fromEntries(entries);
1797
+ }
1798
+ var STATUS_KIND_MAP = {
1799
+ paid: "paid",
1800
+ completed: "paid",
1801
+ settled: "paid",
1802
+ pending: "pending",
1803
+ processing: "pending",
1804
+ open: "pending",
1805
+ awaitingpayment: "pending",
1806
+ awaiting_payment: "pending",
1807
+ cancelled: "cancelled",
1808
+ canceled: "cancelled",
1809
+ voided: "cancelled",
1810
+ overdue: "overdue",
1811
+ expired: "overdue"
1812
+ };
1813
+ function normalizeReference(value) {
1814
+ if (value === void 0) return void 0;
1815
+ return value;
1816
+ }
1817
+ function normalizeCustomerInfo(value) {
1818
+ if (value === void 0) return void 0;
1819
+ if (value === null) return null;
1820
+ return {
1821
+ firstName: value.firstName ?? void 0,
1822
+ lastName: value.lastName ?? void 0,
1823
+ email: value.email ?? void 0,
1824
+ address: value.address ? {
1825
+ street: value.address.street ?? void 0,
1826
+ city: value.address.city ?? void 0,
1827
+ state: value.address.state ?? void 0,
1828
+ postalCode: value.address.postalCode ?? void 0,
1829
+ country: value.address.country ?? void 0
1830
+ } : void 0
1831
+ };
1832
+ }
1833
+ function normalizePayments(payments) {
1834
+ if (!payments) return void 0;
1835
+ return payments.map((payment) => ({ ...payment }));
1836
+ }
1837
+ function buildStatusBase(raw, overrides) {
1838
+ return {
1839
+ paymentReference: raw.paymentReference ?? void 0,
1840
+ requestId: raw.requestId ?? void 0,
1841
+ isListening: "isListening" in raw ? raw.isListening ?? void 0 : void 0,
1842
+ txHash: raw.txHash ?? null,
1843
+ hasBeenPaid: raw.hasBeenPaid ?? false,
1844
+ status: "status" in raw ? raw.status ?? void 0 : void 0,
1845
+ recurrence: "recurrence" in raw ? raw.recurrence : void 0,
1846
+ originalRequestId: "originalRequestId" in raw ? raw.originalRequestId ?? void 0 : void 0,
1847
+ originalRequestPaymentReference: "originalRequestPaymentReference" in raw ? raw.originalRequestPaymentReference ?? void 0 : void 0,
1848
+ isRecurrenceStopped: "isRecurrenceStopped" in raw ? raw.isRecurrenceStopped ?? void 0 : void 0,
1849
+ isCryptoToFiatAvailable: "isCryptoToFiatAvailable" in raw ? raw.isCryptoToFiatAvailable ?? void 0 : void 0,
1850
+ payments: "payments" in raw ? normalizePayments(raw.payments) : void 0,
1851
+ customerInfo: "customerInfo" in raw ? normalizeCustomerInfo(
1852
+ raw.customerInfo
1853
+ ) : void 0,
1854
+ reference: "reference" in raw ? normalizeReference(raw.reference ?? null) : void 0,
1855
+ ...overrides
1856
+ };
1857
+ }
1858
+ function normalizeLegacyStatusResponse(raw) {
1859
+ if (raw.hasBeenPaid) {
1860
+ return {
1861
+ kind: "paid",
1862
+ ...buildStatusBase(raw, { hasBeenPaid: true }),
1863
+ hasBeenPaid: true
1864
+ };
1865
+ }
1866
+ return {
1867
+ kind: "pending",
1868
+ ...buildStatusBase(raw, { hasBeenPaid: false }),
1869
+ hasBeenPaid: false
1870
+ };
1871
+ }
1872
+ function normalizeRequestStatusResponse(raw) {
1873
+ const statusKey = raw.status?.trim().toLowerCase();
1874
+ const mapped = statusKey ? STATUS_KIND_MAP[statusKey] : void 0;
1875
+ const kind = raw.hasBeenPaid ? "paid" : mapped ?? (statusKey ? "unknown" : "pending");
1876
+ if (kind === "paid") {
1877
+ return {
1878
+ kind,
1879
+ ...buildStatusBase(raw, { hasBeenPaid: true }),
1880
+ hasBeenPaid: true
1881
+ };
1882
+ }
1883
+ return {
1884
+ kind,
1885
+ ...buildStatusBase(raw, { hasBeenPaid: false }),
1886
+ hasBeenPaid: false
1887
+ };
1888
+ }
1889
+
1890
+ // src/domains/payments/payments.facade.ts
1891
+ function createPaymentsApi(http) {
1892
+ return {
1893
+ async search(query, options) {
1894
+ const requestQuery = buildRequestQuery(query ? { ...query } : void 0);
1895
+ return requestJson(http, {
1896
+ operationId: OP_SEARCH_PAYMENTS,
1897
+ method: "GET",
1898
+ path: "/v2/payments",
1899
+ query: requestQuery,
1900
+ schemaKey: { operationId: OP_SEARCH_PAYMENTS, kind: "response", status: 200 },
1901
+ description: "Search payments",
1902
+ signal: options?.signal,
1903
+ timeoutMs: options?.timeoutMs,
1904
+ validation: options?.validation,
1905
+ meta: options?.meta
1906
+ });
1907
+ }
1908
+ };
1909
+ }
1910
+
1911
+ // src/domains/payouts/index.ts
1912
+ var payouts_exports = {};
1913
+ __export(payouts_exports, {
1914
+ createPayoutsApi: () => createPayoutsApi
1915
+ });
1916
+
1917
+ // src/domains/payouts/payouts.facade.ts
1918
+ var OP_CREATE = "PayoutV2Controller_payRequest_v2";
1919
+ var OP_CREATE_BATCH = "PayoutV2Controller_payBatchRequest_v2";
1920
+ var OP_RECURRING_STATUS = "PayoutV2Controller_getRecurringPaymentStatus_v2";
1921
+ var OP_SUBMIT_SIGNATURE = "PayoutV2Controller_submitRecurringPaymentSignature_v2";
1922
+ var OP_UPDATE_RECURRING = "PayoutV2Controller_updateRecurringPayment_v2";
1923
+ function createPayoutsApi(http) {
1924
+ return {
1925
+ async create(body, options) {
1926
+ return requestJson(http, {
1927
+ operationId: OP_CREATE,
1928
+ method: "POST",
1929
+ path: "/v2/payouts",
1930
+ body,
1931
+ requestSchemaKey: { operationId: OP_CREATE, kind: "request", variant: "application/json" },
1932
+ schemaKey: { operationId: OP_CREATE, kind: "response", status: 201 },
1933
+ description: "Create payout",
1934
+ signal: options?.signal,
1935
+ timeoutMs: options?.timeoutMs,
1936
+ validation: options?.validation,
1937
+ meta: options?.meta
1938
+ });
1939
+ },
1940
+ async createBatch(body, options) {
1941
+ return requestJson(http, {
1942
+ operationId: OP_CREATE_BATCH,
1943
+ method: "POST",
1944
+ path: "/v2/payouts/batch",
1945
+ body,
1946
+ requestSchemaKey: { operationId: OP_CREATE_BATCH, kind: "request", variant: "application/json" },
1947
+ schemaKey: { operationId: OP_CREATE_BATCH, kind: "response", status: 201 },
1948
+ description: "Create payout batch",
1949
+ signal: options?.signal,
1950
+ timeoutMs: options?.timeoutMs,
1951
+ validation: options?.validation,
1952
+ meta: options?.meta
1953
+ });
1954
+ },
1955
+ async getRecurringStatus(recurringId, options) {
1956
+ const path = `/v2/payouts/recurring/${encodeURIComponent(recurringId)}`;
1957
+ return requestJson(http, {
1958
+ operationId: OP_RECURRING_STATUS,
1959
+ method: "GET",
1960
+ path,
1961
+ schemaKey: { operationId: OP_RECURRING_STATUS, kind: "response", status: 200 },
1962
+ description: "Get recurring payout status",
1963
+ signal: options?.signal,
1964
+ timeoutMs: options?.timeoutMs,
1965
+ validation: options?.validation,
1966
+ meta: options?.meta
1967
+ });
1968
+ },
1969
+ async submitRecurringSignature(recurringId, body, options) {
1970
+ const path = `/v2/payouts/recurring/${encodeURIComponent(recurringId)}`;
1971
+ return requestJson(http, {
1972
+ operationId: OP_SUBMIT_SIGNATURE,
1973
+ method: "POST",
1974
+ path,
1975
+ body,
1976
+ requestSchemaKey: { operationId: OP_SUBMIT_SIGNATURE, kind: "request", variant: "application/json" },
1977
+ schemaKey: { operationId: OP_SUBMIT_SIGNATURE, kind: "response", status: 201 },
1978
+ description: "Submit recurring payout signature",
1979
+ signal: options?.signal,
1980
+ timeoutMs: options?.timeoutMs,
1981
+ validation: options?.validation,
1982
+ meta: options?.meta
1983
+ });
1984
+ },
1985
+ async updateRecurring(recurringId, body, options) {
1986
+ const path = `/v2/payouts/recurring/${encodeURIComponent(recurringId)}`;
1987
+ return requestJson(http, {
1988
+ operationId: OP_UPDATE_RECURRING,
1989
+ method: "PATCH",
1990
+ path,
1991
+ body,
1992
+ requestSchemaKey: { operationId: OP_UPDATE_RECURRING, kind: "request", variant: "application/json" },
1993
+ schemaKey: { operationId: OP_UPDATE_RECURRING, kind: "response", status: 200 },
1994
+ description: "Update recurring payout",
1995
+ signal: options?.signal,
1996
+ timeoutMs: options?.timeoutMs,
1997
+ validation: options?.validation,
1998
+ meta: options?.meta
1999
+ });
2000
+ }
2001
+ };
2002
+ }
2003
+
2004
+ // src/domains/requests/index.ts
2005
+ var requests_exports = {};
2006
+ __export(requests_exports, {
2007
+ createRequestsApi: () => createRequestsApi
2008
+ });
2009
+
2010
+ // src/domains/requests/requests.facade.ts
2011
+ var OP_CREATE2 = "RequestControllerV2_createRequest_v2";
2012
+ var OP_PAYMENT_ROUTES = "RequestControllerV2_getRequestPaymentRoutes_v2";
2013
+ var OP_PAYMENT_CALLDATA = "RequestControllerV2_getPaymentCalldata_v2";
2014
+ var OP_UPDATE = "RequestControllerV2_updateRequest_v2";
2015
+ var OP_SEND_PAYMENT_INTENT = "RequestControllerV2_sendPaymentIntent_v2";
2016
+ var OP_REQUEST_STATUS = "RequestControllerV2_getRequestStatus_v2";
2017
+ var KIND_CALLDATA = "calldata";
2018
+ var KIND_PAYMENT_INTENT = "paymentIntent";
2019
+ function isPaymentIntentPayload(payload) {
2020
+ return "paymentIntentId" in payload;
2021
+ }
2022
+ function isCalldataPayload(payload) {
2023
+ return "transactions" in payload;
2024
+ }
2025
+ function createRequestsApi(http) {
2026
+ return {
2027
+ async create(body, options) {
2028
+ return requestJson(http, {
2029
+ operationId: OP_CREATE2,
2030
+ method: "POST",
2031
+ path: "/v2/request",
2032
+ body,
2033
+ requestSchemaKey: { operationId: OP_CREATE2, kind: "request", variant: "application/json" },
2034
+ schemaKey: { operationId: OP_CREATE2, kind: "response", status: 201 },
2035
+ description: "Create request",
2036
+ signal: options?.signal,
2037
+ timeoutMs: options?.timeoutMs,
2038
+ validation: options?.validation,
2039
+ meta: options?.meta
2040
+ });
2041
+ },
2042
+ async getRequestStatus(requestId, options) {
2043
+ const path = `/v2/request/${encodeURIComponent(requestId)}`;
2044
+ const raw = await requestJson(http, {
2045
+ operationId: OP_REQUEST_STATUS,
2046
+ method: "GET",
2047
+ path,
2048
+ schemaKey: { operationId: OP_REQUEST_STATUS, kind: "response", status: 200 },
2049
+ description: "Request status",
2050
+ signal: options?.signal,
2051
+ timeoutMs: options?.timeoutMs,
2052
+ validation: options?.validation,
2053
+ meta: options?.meta
2054
+ });
2055
+ return normalizeRequestStatusResponse(raw);
2056
+ },
2057
+ async getPaymentRoutes(requestId, options) {
2058
+ const path = `/v2/request/${encodeURIComponent(requestId)}/routes`;
2059
+ return requestJson(http, {
2060
+ operationId: OP_PAYMENT_ROUTES,
2061
+ method: "GET",
2062
+ path,
2063
+ query: buildRequestQuery({
2064
+ wallet: options.wallet,
2065
+ amount: options.amount,
2066
+ feePercentage: options.feePercentage,
2067
+ feeAddress: options.feeAddress
2068
+ }),
2069
+ schemaKey: { operationId: OP_PAYMENT_ROUTES, kind: "response", status: 200 },
2070
+ description: "Payment routes",
2071
+ signal: options.signal,
2072
+ timeoutMs: options.timeoutMs,
2073
+ validation: options.validation,
2074
+ meta: options.meta
2075
+ });
2076
+ },
2077
+ async getPaymentCalldata(requestId, options) {
2078
+ const path = `/v2/request/${encodeURIComponent(requestId)}/pay`;
2079
+ const queryInput = {
2080
+ wallet: options?.wallet,
2081
+ chain: options?.chain,
2082
+ token: options?.token,
2083
+ amount: options?.amount,
2084
+ clientUserId: options?.clientUserId,
2085
+ paymentDetailsId: options?.paymentDetailsId,
2086
+ feePercentage: options?.feePercentage,
2087
+ feeAddress: options?.feeAddress
2088
+ };
2089
+ const raw = await requestJson(http, {
2090
+ operationId: OP_PAYMENT_CALLDATA,
2091
+ method: "GET",
2092
+ path,
2093
+ query: buildRequestQuery(queryInput),
2094
+ schemaKey: { operationId: OP_PAYMENT_CALLDATA, kind: "response", status: 200 },
2095
+ description: "Payment calldata",
2096
+ signal: options?.signal,
2097
+ timeoutMs: options?.timeoutMs,
2098
+ validation: options?.validation,
2099
+ meta: options?.meta
2100
+ });
2101
+ if (isCalldataPayload(raw)) {
2102
+ return { kind: KIND_CALLDATA, ...raw };
2103
+ }
2104
+ if (isPaymentIntentPayload(raw)) {
2105
+ return { kind: KIND_PAYMENT_INTENT, ...raw };
2106
+ }
2107
+ throw new ValidationError("Unexpected payment calldata response", raw);
2108
+ },
2109
+ async update(requestId, options) {
2110
+ const path = `/v2/request/${encodeURIComponent(requestId)}`;
2111
+ await requestVoid(http, {
2112
+ operationId: OP_UPDATE,
2113
+ method: "PATCH",
2114
+ path,
2115
+ signal: options?.signal,
2116
+ timeoutMs: options?.timeoutMs,
2117
+ validation: options?.validation,
2118
+ meta: options?.meta
2119
+ });
2120
+ },
2121
+ async sendPaymentIntent(paymentIntentId, body, options) {
2122
+ const path = `/v2/request/payment-intents/${encodeURIComponent(paymentIntentId)}`;
2123
+ await requestVoid(http, {
2124
+ operationId: OP_SEND_PAYMENT_INTENT,
2125
+ method: "POST",
2126
+ path,
2127
+ body,
2128
+ requestSchemaKey: { operationId: OP_SEND_PAYMENT_INTENT, kind: "request", variant: "application/json" },
2129
+ signal: options?.signal,
2130
+ timeoutMs: options?.timeoutMs,
2131
+ validation: options?.validation,
2132
+ meta: options?.meta
2133
+ });
2134
+ }
2135
+ };
2136
+ }
2137
+ var ErrorDetailSchema6 = zod.z.object({
2138
+ message: zod.z.string(),
2139
+ code: zod.z.string().optional(),
2140
+ field: zod.z.string().optional(),
2141
+ source: zod.z.object({
2142
+ pointer: zod.z.string().optional(),
2143
+ parameter: zod.z.string().optional()
2144
+ }).passthrough().optional(),
2145
+ meta: zod.z.record(zod.z.unknown()).optional()
2146
+ }).passthrough();
2147
+ var ErrorEnvelopeSchema6 = zod.z.object({
2148
+ status: zod.z.number().optional(),
2149
+ statusCode: zod.z.number().optional(),
2150
+ code: zod.z.string().optional(),
2151
+ error: zod.z.string().optional(),
2152
+ message: zod.z.union([
2153
+ zod.z.string(),
2154
+ zod.z.array(zod.z.union([zod.z.string(), ErrorDetailSchema6])),
2155
+ ErrorDetailSchema6
2156
+ ]).optional(),
2157
+ detail: zod.z.unknown().optional(),
2158
+ errors: zod.z.array(ErrorDetailSchema6).optional(),
2159
+ requestId: zod.z.string().optional(),
2160
+ correlationId: zod.z.string().optional(),
2161
+ retryAfter: zod.z.union([zod.z.number(), zod.z.string()]).optional(),
2162
+ retryAfterMs: zod.z.number().optional(),
2163
+ meta: zod.z.record(zod.z.unknown()).optional()
2164
+ }).passthrough();
2165
+ var RequestControllerV1_createRequest_v1_Request = zod.z.object({ "payer": zod.z.string().optional(), "payee": zod.z.string(), "amount": zod.z.string(), "invoiceCurrency": zod.z.string(), "paymentCurrency": zod.z.string(), "recurrence": zod.z.object({ "startDate": zod.z.string(), "frequency": zod.z.enum(["DAILY", "WEEKLY", "MONTHLY", "YEARLY"]) }).passthrough().optional() }).passthrough();
2166
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_createRequest_v1", kind: "request", variant: "application/json" }, schema: RequestControllerV1_createRequest_v1_Request });
2167
+ var RequestControllerV1_createRequest_v1_201 = zod.z.object({ "paymentReference": zod.z.string().optional(), "requestID": zod.z.string().optional() }).passthrough();
2168
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_createRequest_v1", kind: "response", status: 201 }, schema: RequestControllerV1_createRequest_v1_201 });
2169
+ var RequestControllerV1_createRequest_v1_400 = ErrorEnvelopeSchema6;
2170
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_createRequest_v1", kind: "response", status: 400 }, schema: RequestControllerV1_createRequest_v1_400 });
2171
+ var RequestControllerV1_createRequest_v1_401 = ErrorEnvelopeSchema6;
2172
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_createRequest_v1", kind: "response", status: 401 }, schema: RequestControllerV1_createRequest_v1_401 });
2173
+ var RequestControllerV1_createRequest_v1_404 = ErrorEnvelopeSchema6;
2174
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_createRequest_v1", kind: "response", status: 404 }, schema: RequestControllerV1_createRequest_v1_404 });
2175
+ var RequestControllerV1_createRequest_v1_429 = ErrorEnvelopeSchema6;
2176
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_createRequest_v1", kind: "response", status: 429 }, schema: RequestControllerV1_createRequest_v1_429 });
2177
+ var RequestControllerV1_getRequestStatus_v1_200 = zod.z.object({ "hasBeenPaid": zod.z.boolean().optional(), "paymentReference": zod.z.string().optional(), "requestId": zod.z.string().optional(), "isListening": zod.z.boolean().optional(), "txHash": zod.z.string().nullable().optional() }).passthrough();
2178
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_getRequestStatus_v1", kind: "response", status: 200 }, schema: RequestControllerV1_getRequestStatus_v1_200 });
2179
+ var RequestControllerV1_getRequestStatus_v1_401 = ErrorEnvelopeSchema6;
2180
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_getRequestStatus_v1", kind: "response", status: 401 }, schema: RequestControllerV1_getRequestStatus_v1_401 });
2181
+ var RequestControllerV1_getRequestStatus_v1_404 = ErrorEnvelopeSchema6;
2182
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_getRequestStatus_v1", kind: "response", status: 404 }, schema: RequestControllerV1_getRequestStatus_v1_404 });
2183
+ var RequestControllerV1_getRequestStatus_v1_429 = ErrorEnvelopeSchema6;
2184
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_getRequestStatus_v1", kind: "response", status: 429 }, schema: RequestControllerV1_getRequestStatus_v1_429 });
2185
+ var RequestControllerV1_stopRecurrenceRequest_v1_200 = zod.z.unknown();
2186
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_stopRecurrenceRequest_v1", kind: "response", status: 200 }, schema: RequestControllerV1_stopRecurrenceRequest_v1_200 });
2187
+ var RequestControllerV1_stopRecurrenceRequest_v1_401 = ErrorEnvelopeSchema6;
2188
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_stopRecurrenceRequest_v1", kind: "response", status: 401 }, schema: RequestControllerV1_stopRecurrenceRequest_v1_401 });
2189
+ var RequestControllerV1_stopRecurrenceRequest_v1_404 = ErrorEnvelopeSchema6;
2190
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_stopRecurrenceRequest_v1", kind: "response", status: 404 }, schema: RequestControllerV1_stopRecurrenceRequest_v1_404 });
2191
+ var RequestControllerV1_stopRecurrenceRequest_v1_429 = ErrorEnvelopeSchema6;
2192
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_stopRecurrenceRequest_v1", kind: "response", status: 429 }, schema: RequestControllerV1_stopRecurrenceRequest_v1_429 });
2193
+ var RequestControllerV1_getPaymentCalldata_v1_200 = zod.z.union([zod.z.object({ "transactions": zod.z.array(zod.z.object({ "data": zod.z.string(), "to": zod.z.string(), "value": zod.z.object({ "type": zod.z.enum(["BigNumber"]).optional(), "hex": zod.z.string().optional() }).passthrough() }).passthrough()), "metadata": zod.z.object({ "stepsRequired": zod.z.number(), "needsApproval": zod.z.boolean(), "approvalTransactionIndex": zod.z.number().nullable().optional(), "hasEnoughBalance": zod.z.boolean(), "hasEnoughGas": zod.z.boolean() }).passthrough() }).passthrough(), zod.z.object({ "paymentIntentId": zod.z.string(), "paymentIntent": zod.z.string(), "approvalPermitPayload": zod.z.string().nullable().optional(), "approvalCalldata": zod.z.object({ "to": zod.z.string().optional(), "data": zod.z.string().optional(), "value": zod.z.string().optional() }).passthrough().nullable().optional(), "metadata": zod.z.object({ "supportsEIP2612": zod.z.boolean() }).passthrough() }).passthrough()]);
2194
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_getPaymentCalldata_v1", kind: "response", status: 200 }, schema: RequestControllerV1_getPaymentCalldata_v1_200 });
2195
+ var RequestControllerV1_getPaymentCalldata_v1_400 = ErrorEnvelopeSchema6;
2196
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_getPaymentCalldata_v1", kind: "response", status: 400 }, schema: RequestControllerV1_getPaymentCalldata_v1_400 });
2197
+ var RequestControllerV1_getPaymentCalldata_v1_401 = ErrorEnvelopeSchema6;
2198
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_getPaymentCalldata_v1", kind: "response", status: 401 }, schema: RequestControllerV1_getPaymentCalldata_v1_401 });
2199
+ var RequestControllerV1_getPaymentCalldata_v1_404 = ErrorEnvelopeSchema6;
2200
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_getPaymentCalldata_v1", kind: "response", status: 404 }, schema: RequestControllerV1_getPaymentCalldata_v1_404 });
2201
+ var RequestControllerV1_getPaymentCalldata_v1_429 = ErrorEnvelopeSchema6;
2202
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_getPaymentCalldata_v1", kind: "response", status: 429 }, schema: RequestControllerV1_getPaymentCalldata_v1_429 });
2203
+ var RequestControllerV1_getRequestPaymentRoutes_v1_200 = zod.z.object({ "routes": zod.z.array(zod.z.object({ "id": zod.z.string(), "fee": zod.z.number(), "feeBreakdown": zod.z.array(zod.z.object({ "type": zod.z.enum(["gas", "platform", "crosschain", "crypto-to-fiat", "offramp"]).optional(), "stage": zod.z.enum(["sending", "receiving", "proxying", "refunding", "overall"]).optional(), "provider": zod.z.string().optional(), "amount": zod.z.string().optional(), "amountInUSD": zod.z.string().optional(), "currency": zod.z.string().optional(), "receiverAddress": zod.z.string().optional(), "network": zod.z.string().optional(), "rateProvider": zod.z.string().optional() }).passthrough()).optional(), "speed": zod.z.union([zod.z.string(), zod.z.number()]), "price_impact": zod.z.number().optional(), "chain": zod.z.string(), "token": zod.z.string() }).passthrough()) }).passthrough();
2204
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_getRequestPaymentRoutes_v1", kind: "response", status: 200 }, schema: RequestControllerV1_getRequestPaymentRoutes_v1_200 });
2205
+ var RequestControllerV1_getRequestPaymentRoutes_v1_400 = ErrorEnvelopeSchema6;
2206
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_getRequestPaymentRoutes_v1", kind: "response", status: 400 }, schema: RequestControllerV1_getRequestPaymentRoutes_v1_400 });
2207
+ var RequestControllerV1_getRequestPaymentRoutes_v1_401 = ErrorEnvelopeSchema6;
2208
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_getRequestPaymentRoutes_v1", kind: "response", status: 401 }, schema: RequestControllerV1_getRequestPaymentRoutes_v1_401 });
2209
+ var RequestControllerV1_getRequestPaymentRoutes_v1_404 = ErrorEnvelopeSchema6;
2210
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_getRequestPaymentRoutes_v1", kind: "response", status: 404 }, schema: RequestControllerV1_getRequestPaymentRoutes_v1_404 });
2211
+ var RequestControllerV1_getRequestPaymentRoutes_v1_429 = ErrorEnvelopeSchema6;
2212
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_getRequestPaymentRoutes_v1", kind: "response", status: 429 }, schema: RequestControllerV1_getRequestPaymentRoutes_v1_429 });
2213
+ var RequestControllerV1_sendPaymentIntent_v1_Request = zod.z.object({ "signedPaymentIntent": zod.z.object({ "signature": zod.z.string(), "nonce": zod.z.string(), "deadline": zod.z.string() }).passthrough(), "signedApprovalPermit": zod.z.object({ "signature": zod.z.string(), "nonce": zod.z.string(), "deadline": zod.z.string() }).passthrough().optional() }).passthrough();
2214
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_sendPaymentIntent_v1", kind: "request", variant: "application/json" }, schema: RequestControllerV1_sendPaymentIntent_v1_Request });
2215
+ var RequestControllerV1_sendPaymentIntent_v1_401 = ErrorEnvelopeSchema6;
2216
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_sendPaymentIntent_v1", kind: "response", status: 401 }, schema: RequestControllerV1_sendPaymentIntent_v1_401 });
2217
+ var RequestControllerV1_sendPaymentIntent_v1_404 = ErrorEnvelopeSchema6;
2218
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_sendPaymentIntent_v1", kind: "response", status: 404 }, schema: RequestControllerV1_sendPaymentIntent_v1_404 });
2219
+ var RequestControllerV1_sendPaymentIntent_v1_429 = ErrorEnvelopeSchema6;
2220
+ schemaRegistry.register({ key: { operationId: "RequestControllerV1_sendPaymentIntent_v1", kind: "response", status: 429 }, schema: RequestControllerV1_sendPaymentIntent_v1_429 });
2221
+ var RequestControllerV2_createRequest_v2_Request = zod.z.object({ "payer": zod.z.string().optional(), "payee": zod.z.string().optional(), "amount": zod.z.string(), "invoiceCurrency": zod.z.string(), "paymentCurrency": zod.z.string(), "recurrence": zod.z.object({ "startDate": zod.z.string(), "frequency": zod.z.enum(["DAILY", "WEEKLY", "MONTHLY", "YEARLY"]) }).passthrough().optional(), "isCryptoToFiatAvailable": zod.z.boolean().optional(), "customerInfo": zod.z.object({ "firstName": zod.z.string().optional(), "lastName": zod.z.string().optional(), "email": zod.z.string().optional(), "address": zod.z.object({ "street": zod.z.string().optional(), "city": zod.z.string().optional(), "state": zod.z.string().optional(), "postalCode": zod.z.string().optional(), "country": zod.z.string().optional() }).passthrough().optional() }).passthrough().optional(), "reference": zod.z.string().optional(), "originalRequestId": zod.z.string().optional(), "originalRequestPaymentReference": zod.z.string().optional() }).passthrough();
2222
+ schemaRegistry.register({ key: { operationId: "RequestControllerV2_createRequest_v2", kind: "request", variant: "application/json" }, schema: RequestControllerV2_createRequest_v2_Request });
2223
+ var RequestControllerV2_createRequest_v2_201 = zod.z.object({ "paymentReference": zod.z.string().optional(), "requestId": zod.z.string().optional() }).passthrough();
2224
+ schemaRegistry.register({ key: { operationId: "RequestControllerV2_createRequest_v2", kind: "response", status: 201 }, schema: RequestControllerV2_createRequest_v2_201 });
2225
+ var RequestControllerV2_createRequest_v2_400 = ErrorEnvelopeSchema6;
2226
+ schemaRegistry.register({ key: { operationId: "RequestControllerV2_createRequest_v2", kind: "response", status: 400 }, schema: RequestControllerV2_createRequest_v2_400 });
2227
+ var RequestControllerV2_createRequest_v2_404 = ErrorEnvelopeSchema6;
2228
+ schemaRegistry.register({ key: { operationId: "RequestControllerV2_createRequest_v2", kind: "response", status: 404 }, schema: RequestControllerV2_createRequest_v2_404 });
2229
+ var RequestControllerV2_createRequest_v2_429 = ErrorEnvelopeSchema6;
2230
+ schemaRegistry.register({ key: { operationId: "RequestControllerV2_createRequest_v2", kind: "response", status: 429 }, schema: RequestControllerV2_createRequest_v2_429 });
2231
+ var RequestControllerV2_getRequestStatus_v2_200 = zod.z.object({ "hasBeenPaid": zod.z.boolean().optional(), "paymentReference": zod.z.string().optional(), "requestId": zod.z.string().optional(), "isListening": zod.z.boolean().optional(), "txHash": zod.z.string().nullable().optional(), "recurrence": zod.z.object({}).passthrough().optional(), "originalRequestId": zod.z.string().optional(), "status": zod.z.string().optional(), "isCryptoToFiatAvailable": zod.z.boolean().optional(), "originalRequestPaymentReference": zod.z.string().optional(), "payments": zod.z.array(zod.z.object({}).passthrough()).optional(), "isRecurrenceStopped": zod.z.boolean().optional(), "customerInfo": zod.z.object({ "firstName": zod.z.string().optional(), "lastName": zod.z.string().optional(), "email": zod.z.string().optional(), "address": zod.z.object({ "street": zod.z.string().optional(), "city": zod.z.string().optional(), "state": zod.z.string().optional(), "postalCode": zod.z.string().optional(), "country": zod.z.string().optional() }).passthrough().optional() }).passthrough().nullable().optional(), "reference": zod.z.string().nullable().optional() }).passthrough();
2232
+ schemaRegistry.register({ key: { operationId: "RequestControllerV2_getRequestStatus_v2", kind: "response", status: 200 }, schema: RequestControllerV2_getRequestStatus_v2_200 });
2233
+ var RequestControllerV2_getRequestStatus_v2_404 = ErrorEnvelopeSchema6;
2234
+ schemaRegistry.register({ key: { operationId: "RequestControllerV2_getRequestStatus_v2", kind: "response", status: 404 }, schema: RequestControllerV2_getRequestStatus_v2_404 });
2235
+ var RequestControllerV2_getRequestStatus_v2_429 = ErrorEnvelopeSchema6;
2236
+ schemaRegistry.register({ key: { operationId: "RequestControllerV2_getRequestStatus_v2", kind: "response", status: 429 }, schema: RequestControllerV2_getRequestStatus_v2_429 });
2237
+ var RequestControllerV2_updateRequest_v2_200 = zod.z.unknown();
2238
+ schemaRegistry.register({ key: { operationId: "RequestControllerV2_updateRequest_v2", kind: "response", status: 200 }, schema: RequestControllerV2_updateRequest_v2_200 });
2239
+ var RequestControllerV2_updateRequest_v2_404 = ErrorEnvelopeSchema6;
2240
+ schemaRegistry.register({ key: { operationId: "RequestControllerV2_updateRequest_v2", kind: "response", status: 404 }, schema: RequestControllerV2_updateRequest_v2_404 });
2241
+ var RequestControllerV2_updateRequest_v2_429 = ErrorEnvelopeSchema6;
2242
+ schemaRegistry.register({ key: { operationId: "RequestControllerV2_updateRequest_v2", kind: "response", status: 429 }, schema: RequestControllerV2_updateRequest_v2_429 });
2243
+ var RequestControllerV2_getPaymentCalldata_v2_200 = zod.z.union([zod.z.object({ "transactions": zod.z.array(zod.z.object({ "data": zod.z.string(), "to": zod.z.string(), "value": zod.z.object({ "type": zod.z.enum(["BigNumber"]).optional(), "hex": zod.z.string().optional() }).passthrough() }).passthrough()), "metadata": zod.z.object({ "stepsRequired": zod.z.number(), "needsApproval": zod.z.boolean(), "approvalTransactionIndex": zod.z.number().nullable().optional(), "hasEnoughBalance": zod.z.boolean(), "hasEnoughGas": zod.z.boolean() }).passthrough() }).passthrough(), zod.z.object({ "paymentIntentId": zod.z.string(), "paymentIntent": zod.z.string(), "approvalPermitPayload": zod.z.string().nullable().optional(), "approvalCalldata": zod.z.object({ "to": zod.z.string().optional(), "data": zod.z.string().optional(), "value": zod.z.string().optional() }).passthrough().nullable().optional(), "metadata": zod.z.object({ "supportsEIP2612": zod.z.boolean() }).passthrough() }).passthrough()]);
2244
+ schemaRegistry.register({ key: { operationId: "RequestControllerV2_getPaymentCalldata_v2", kind: "response", status: 200 }, schema: RequestControllerV2_getPaymentCalldata_v2_200 });
2245
+ var RequestControllerV2_getPaymentCalldata_v2_400 = ErrorEnvelopeSchema6;
2246
+ schemaRegistry.register({ key: { operationId: "RequestControllerV2_getPaymentCalldata_v2", kind: "response", status: 400 }, schema: RequestControllerV2_getPaymentCalldata_v2_400 });
2247
+ var RequestControllerV2_getPaymentCalldata_v2_404 = ErrorEnvelopeSchema6;
2248
+ schemaRegistry.register({ key: { operationId: "RequestControllerV2_getPaymentCalldata_v2", kind: "response", status: 404 }, schema: RequestControllerV2_getPaymentCalldata_v2_404 });
2249
+ var RequestControllerV2_getPaymentCalldata_v2_429 = ErrorEnvelopeSchema6;
2250
+ schemaRegistry.register({ key: { operationId: "RequestControllerV2_getPaymentCalldata_v2", kind: "response", status: 429 }, schema: RequestControllerV2_getPaymentCalldata_v2_429 });
2251
+ var RequestControllerV2_getRequestPaymentRoutes_v2_200 = zod.z.object({ "routes": zod.z.array(zod.z.object({ "id": zod.z.string(), "fee": zod.z.number(), "feeBreakdown": zod.z.array(zod.z.object({ "type": zod.z.enum(["gas", "platform", "crosschain", "crypto-to-fiat", "offramp"]).optional(), "stage": zod.z.enum(["sending", "receiving", "proxying", "refunding", "overall"]).optional(), "provider": zod.z.string().optional(), "amount": zod.z.string().optional(), "amountInUSD": zod.z.string().optional(), "currency": zod.z.string().optional(), "receiverAddress": zod.z.string().optional(), "network": zod.z.string().optional(), "rateProvider": zod.z.string().optional() }).passthrough()).optional(), "speed": zod.z.union([zod.z.string(), zod.z.number()]), "price_impact": zod.z.number().optional(), "chain": zod.z.string(), "token": zod.z.string() }).passthrough()) }).passthrough();
2252
+ schemaRegistry.register({ key: { operationId: "RequestControllerV2_getRequestPaymentRoutes_v2", kind: "response", status: 200 }, schema: RequestControllerV2_getRequestPaymentRoutes_v2_200 });
2253
+ var RequestControllerV2_getRequestPaymentRoutes_v2_400 = ErrorEnvelopeSchema6;
2254
+ schemaRegistry.register({ key: { operationId: "RequestControllerV2_getRequestPaymentRoutes_v2", kind: "response", status: 400 }, schema: RequestControllerV2_getRequestPaymentRoutes_v2_400 });
2255
+ var RequestControllerV2_getRequestPaymentRoutes_v2_404 = ErrorEnvelopeSchema6;
2256
+ schemaRegistry.register({ key: { operationId: "RequestControllerV2_getRequestPaymentRoutes_v2", kind: "response", status: 404 }, schema: RequestControllerV2_getRequestPaymentRoutes_v2_404 });
2257
+ var RequestControllerV2_getRequestPaymentRoutes_v2_429 = ErrorEnvelopeSchema6;
2258
+ schemaRegistry.register({ key: { operationId: "RequestControllerV2_getRequestPaymentRoutes_v2", kind: "response", status: 429 }, schema: RequestControllerV2_getRequestPaymentRoutes_v2_429 });
2259
+ var RequestControllerV2_sendPaymentIntent_v2_Request = zod.z.object({ "signedPaymentIntent": zod.z.object({ "signature": zod.z.string(), "nonce": zod.z.string(), "deadline": zod.z.string() }).passthrough(), "signedApprovalPermit": zod.z.object({ "signature": zod.z.string(), "nonce": zod.z.string(), "deadline": zod.z.string() }).passthrough().optional() }).passthrough();
2260
+ schemaRegistry.register({ key: { operationId: "RequestControllerV2_sendPaymentIntent_v2", kind: "request", variant: "application/json" }, schema: RequestControllerV2_sendPaymentIntent_v2_Request });
2261
+ var RequestControllerV2_sendPaymentIntent_v2_200 = zod.z.unknown();
2262
+ schemaRegistry.register({ key: { operationId: "RequestControllerV2_sendPaymentIntent_v2", kind: "response", status: 200 }, schema: RequestControllerV2_sendPaymentIntent_v2_200 });
2263
+ var RequestControllerV2_sendPaymentIntent_v2_404 = ErrorEnvelopeSchema6;
2264
+ schemaRegistry.register({ key: { operationId: "RequestControllerV2_sendPaymentIntent_v2", kind: "response", status: 404 }, schema: RequestControllerV2_sendPaymentIntent_v2_404 });
2265
+ var RequestControllerV2_sendPaymentIntent_v2_429 = ErrorEnvelopeSchema6;
2266
+ schemaRegistry.register({ key: { operationId: "RequestControllerV2_sendPaymentIntent_v2", kind: "response", status: 429 }, schema: RequestControllerV2_sendPaymentIntent_v2_429 });
2267
+ var NullableRequestStatusSchema = zod.z.preprocess((value) => {
2268
+ if (!value || typeof value !== "object") {
2269
+ return value;
2270
+ }
2271
+ const next = { ...value };
2272
+ if (next.recurrence === null) {
2273
+ delete next.recurrence;
2274
+ }
2275
+ if (next.originalRequestId === null) {
2276
+ next.originalRequestId = void 0;
2277
+ }
2278
+ if (next.originalRequestPaymentReference === null) {
2279
+ next.originalRequestPaymentReference = void 0;
2280
+ }
2281
+ return next;
2282
+ }, RequestControllerV2_getRequestStatus_v2_200);
2283
+ schemaRegistry.register({
2284
+ key: { operationId: "RequestControllerV2_getRequestStatus_v2", kind: "response", status: 200 },
2285
+ schema: NullableRequestStatusSchema
2286
+ });
2287
+ var FlexibleRoutesSchema = zod.z.object({
2288
+ routes: zod.z.array(
2289
+ zod.z.object({
2290
+ fee: zod.z.union([zod.z.number(), zod.z.string()]).optional()
2291
+ }).passthrough()
2292
+ )
2293
+ }).passthrough();
2294
+ schemaRegistry.register({
2295
+ key: { operationId: "RequestControllerV2_getRequestPaymentRoutes_v2", kind: "response", status: 200 },
2296
+ schema: FlexibleRoutesSchema
2297
+ });
2298
+
2299
+ // src/request.client.ts
2300
+ function createRequestClient(options) {
2301
+ const http = createHttpClient(options);
2302
+ return {
2303
+ http,
2304
+ currencies: createCurrenciesApi(http),
2305
+ clientIds: createClientIdsApi(http),
2306
+ requests: createRequestsApi(http),
2307
+ payouts: createPayoutsApi(http),
2308
+ payments: createPaymentsApi(http),
2309
+ payer: createPayerApi(http),
2310
+ pay: createPayApi(http)
2311
+ };
2312
+ }
2313
+ function createRequestClientFromEnv(options) {
2314
+ const env = options?.env ?? process.env;
2315
+ const baseUrl = env.REQUEST_API_URL ?? env.REQUEST_SDK_BASE_URL;
2316
+ const apiKey = env.REQUEST_API_KEY ?? env.REQUEST_SDK_API_KEY;
2317
+ const clientId = env.REQUEST_CLIENT_ID ?? env.REQUEST_SDK_CLIENT_ID;
2318
+ return createRequestClient({ baseUrl, apiKey, clientId });
2319
+ }
2320
+
2321
+ // src/core/config/request-environment.config.ts
2322
+ var RequestEnvironment = {
2323
+ production: "https://api.request.network",
2324
+ // Legacy placeholder for partner-managed sandboxes; Request does not operate a public staging host.
2325
+ staging: "https://api.stage.request.network",
2326
+ local: "http://127.0.0.1:8080"
2327
+ };
2328
+
2329
+ // src/domains/requests/v1/index.ts
2330
+ var v1_exports4 = {};
2331
+ __export(v1_exports4, {
2332
+ createRequestsV1Api: () => createRequestsV1Api
2333
+ });
2334
+
2335
+ // src/domains/requests/v1/requests.v1.facade.ts
2336
+ var OP_CREATE3 = "RequestControllerV1_createRequest_v1";
2337
+ var OP_PAYMENT_ROUTES2 = "RequestControllerV1_getRequestPaymentRoutes_v1";
2338
+ var OP_PAYMENT_CALLDATA2 = "RequestControllerV1_getPaymentCalldata_v1";
2339
+ var OP_REQUEST_STATUS2 = "RequestControllerV1_getRequestStatus_v1";
2340
+ var OP_SEND_PAYMENT_INTENT2 = "RequestControllerV1_sendPaymentIntent_v1";
2341
+ var OP_STOP_RECURRENCE = "RequestControllerV1_stopRecurrenceRequest_v1";
2342
+ var KIND_CALLDATA2 = "calldata";
2343
+ var KIND_PAYMENT_INTENT2 = "paymentIntent";
2344
+ function isPaymentIntentPayload2(payload) {
2345
+ return "paymentIntentId" in payload;
2346
+ }
2347
+ function isCalldataPayload2(payload) {
2348
+ return "transactions" in payload;
2349
+ }
2350
+ function createRequestsV1Api(http) {
2351
+ return {
2352
+ async create(body, options) {
2353
+ return requestJson(http, {
2354
+ operationId: OP_CREATE3,
2355
+ method: "POST",
2356
+ path: "/v1/request",
2357
+ body,
2358
+ requestSchemaKey: { operationId: OP_CREATE3, kind: "request", variant: "application/json" },
2359
+ schemaKey: { operationId: OP_CREATE3, kind: "response", status: 201 },
2360
+ description: "Create legacy request",
2361
+ signal: options?.signal,
2362
+ timeoutMs: options?.timeoutMs,
2363
+ validation: options?.validation,
2364
+ meta: options?.meta
2365
+ });
2366
+ },
2367
+ async getPaymentRoutes(paymentReference, options) {
2368
+ const path = `/v1/request/${encodeURIComponent(paymentReference)}/routes`;
2369
+ return requestJson(http, {
2370
+ operationId: OP_PAYMENT_ROUTES2,
2371
+ method: "GET",
2372
+ path,
2373
+ query: buildRequestQuery({
2374
+ wallet: options.wallet,
2375
+ amount: options.amount,
2376
+ feePercentage: options.feePercentage,
2377
+ feeAddress: options.feeAddress
2378
+ }),
2379
+ schemaKey: { operationId: OP_PAYMENT_ROUTES2, kind: "response", status: 200 },
2380
+ description: "Legacy payment routes",
2381
+ signal: options.signal,
2382
+ timeoutMs: options.timeoutMs,
2383
+ validation: options.validation,
2384
+ meta: options.meta
2385
+ });
2386
+ },
2387
+ async getPaymentCalldata(paymentReference, options) {
2388
+ const path = `/v1/request/${encodeURIComponent(paymentReference)}/pay`;
2389
+ const query = buildRequestQuery({
2390
+ wallet: options?.wallet,
2391
+ chain: options?.chain,
2392
+ token: options?.token,
2393
+ amount: options?.amount
2394
+ });
2395
+ const raw = await requestJson(http, {
2396
+ operationId: OP_PAYMENT_CALLDATA2,
2397
+ method: "GET",
2398
+ path,
2399
+ query,
2400
+ schemaKey: { operationId: OP_PAYMENT_CALLDATA2, kind: "response", status: 200 },
2401
+ description: "Legacy payment calldata",
2402
+ signal: options?.signal,
2403
+ timeoutMs: options?.timeoutMs,
2404
+ validation: options?.validation,
2405
+ meta: options?.meta
2406
+ });
2407
+ if (isCalldataPayload2(raw)) {
2408
+ return { kind: KIND_CALLDATA2, ...raw };
2409
+ }
2410
+ if (isPaymentIntentPayload2(raw)) {
2411
+ return { kind: KIND_PAYMENT_INTENT2, ...raw };
2412
+ }
2413
+ throw new ValidationError("Unexpected payment calldata response", raw);
2414
+ },
2415
+ async getRequestStatus(paymentReference, options) {
2416
+ const path = `/v1/request/${encodeURIComponent(paymentReference)}`;
2417
+ const rawStatus = await requestJson(http, {
2418
+ operationId: OP_REQUEST_STATUS2,
2419
+ method: "GET",
2420
+ path,
2421
+ schemaKey: { operationId: OP_REQUEST_STATUS2, kind: "response", status: 200 },
2422
+ description: "Legacy request status",
2423
+ signal: options?.signal,
2424
+ timeoutMs: options?.timeoutMs,
2425
+ validation: options?.validation,
2426
+ meta: options?.meta
2427
+ });
2428
+ return normalizeLegacyStatusResponse(rawStatus);
2429
+ },
2430
+ async sendPaymentIntent(paymentIntentId, body, options) {
2431
+ const path = `/v1/request/${encodeURIComponent(paymentIntentId)}/send`;
2432
+ await requestVoid(http, {
2433
+ operationId: OP_SEND_PAYMENT_INTENT2,
2434
+ method: "POST",
2435
+ path,
2436
+ body,
2437
+ requestSchemaKey: { operationId: OP_SEND_PAYMENT_INTENT2, kind: "request", variant: "application/json" },
2438
+ signal: options?.signal,
2439
+ timeoutMs: options?.timeoutMs,
2440
+ validation: options?.validation,
2441
+ meta: options?.meta
2442
+ });
2443
+ },
2444
+ async stopRecurrence(paymentReference, options) {
2445
+ const path = `/v1/request/${encodeURIComponent(paymentReference)}/stop-recurrence`;
2446
+ await requestVoid(http, {
2447
+ operationId: OP_STOP_RECURRENCE,
2448
+ method: "PATCH",
2449
+ path,
2450
+ signal: options?.signal,
2451
+ timeoutMs: options?.timeoutMs,
2452
+ validation: options?.validation,
2453
+ meta: options?.meta
2454
+ });
2455
+ }
2456
+ };
2457
+ }
2458
+
2459
+ // src/webhooks/index.ts
2460
+ var webhooks_exports = {};
2461
+ __export(webhooks_exports, {
2462
+ DEFAULT_SIGNATURE_ALGORITHM: () => DEFAULT_SIGNATURE_ALGORITHM,
2463
+ DEFAULT_SIGNATURE_HEADER: () => DEFAULT_SIGNATURE_HEADER,
2464
+ RequestWebhookSignatureError: () => RequestWebhookSignatureError,
2465
+ WEBHOOK_EVENT_NAMES: () => WEBHOOK_EVENT_NAMES,
2466
+ WebhookDispatcher: () => WebhookDispatcher,
2467
+ createWebhookDispatcher: () => createWebhookDispatcher,
2468
+ createWebhookMiddleware: () => createWebhookMiddleware,
2469
+ events: () => events_exports,
2470
+ getWebhookSchema: () => getWebhookSchema,
2471
+ isRequestWebhookSignatureError: () => isRequestWebhookSignatureError,
2472
+ parseWebhookEvent: () => parseWebhookEvent,
2473
+ testing: () => testing_webhook_exports,
2474
+ verifyWebhookSignature: () => verifyWebhookSignature
2475
+ });
2476
+
2477
+ // src/webhooks/errors.webhook.ts
2478
+ var RequestWebhookSignatureError = class _RequestWebhookSignatureError extends Error {
2479
+ static code = "ERR_REQUEST_WEBHOOK_SIGNATURE_VERIFICATION_FAILED";
2480
+ code = _RequestWebhookSignatureError.code;
2481
+ statusCode = 401;
2482
+ headerName;
2483
+ signature;
2484
+ timestamp;
2485
+ reason;
2486
+ constructor(message, options) {
2487
+ const { headerName, signature, timestamp, reason, cause } = options;
2488
+ super(message, { cause });
2489
+ this.name = "RequestWebhookSignatureError";
2490
+ this.headerName = headerName;
2491
+ this.signature = signature;
2492
+ this.timestamp = timestamp ?? null;
2493
+ this.reason = reason;
2494
+ }
2495
+ };
2496
+ function isRequestWebhookSignatureError(error) {
2497
+ return error instanceof RequestWebhookSignatureError;
2498
+ }
2499
+
2500
+ // src/webhooks/headers.webhook.ts
2501
+ function coerceHeaderValue(value) {
2502
+ if (value == null) return void 0;
2503
+ if (Array.isArray(value)) {
2504
+ const first = value.find((item) => item.length > 0);
2505
+ return first ?? void 0;
2506
+ }
2507
+ return typeof value === "string" ? value : String(value);
2508
+ }
2509
+ function isFetchHeaders(input) {
2510
+ return typeof Headers !== "undefined" && input instanceof Headers;
2511
+ }
2512
+ function normaliseHeaders2(headers) {
2513
+ const result = {};
2514
+ if (!headers) return result;
2515
+ if (isFetchHeaders(headers)) {
2516
+ headers.forEach((value, key) => {
2517
+ result[key.toLowerCase()] = value;
2518
+ });
2519
+ return result;
2520
+ }
2521
+ for (const [key, value] of Object.entries(headers)) {
2522
+ const coerced = coerceHeaderValue(value);
2523
+ if (coerced != null) {
2524
+ result[key.toLowerCase()] = coerced;
2525
+ }
2526
+ }
2527
+ return result;
2528
+ }
2529
+ function pickHeader(headers, headerName) {
2530
+ if (!headers) return void 0;
2531
+ const lower = headerName.toLowerCase();
2532
+ if (isFetchHeaders(headers)) {
2533
+ const value = headers.get(headerName);
2534
+ return value ?? void 0;
2535
+ }
2536
+ const record = headers;
2537
+ const direct = record[headerName];
2538
+ if (typeof direct === "string") {
2539
+ return direct;
2540
+ }
2541
+ if (direct != null) {
2542
+ const coercedDirect = coerceHeaderValue(direct);
2543
+ if (coercedDirect) return coercedDirect;
2544
+ }
2545
+ const fallback = record[lower];
2546
+ if (typeof fallback === "string") {
2547
+ return fallback;
2548
+ }
2549
+ if (fallback != null) {
2550
+ return coerceHeaderValue(fallback);
2551
+ }
2552
+ return void 0;
2553
+ }
2554
+
2555
+ // src/webhooks/signature.webhook.ts
2556
+ var DEFAULT_SIGNATURE_HEADER = "x-request-network-signature";
2557
+ var DEFAULT_SIGNATURE_ALGORITHM = "sha256";
2558
+ var HEX_SIGNATURE_PATTERN = /^[0-9a-f]+$/i;
2559
+ function toBuffer(rawBody) {
2560
+ if (typeof rawBody === "string") {
2561
+ return buffer.Buffer.from(rawBody, "utf8");
2562
+ }
2563
+ if (rawBody instanceof ArrayBuffer) {
2564
+ return buffer.Buffer.from(rawBody);
2565
+ }
2566
+ return buffer.Buffer.from(rawBody.buffer, rawBody.byteOffset, rawBody.byteLength);
2567
+ }
2568
+ function stripAlgorithmPrefix(signature, headerName) {
2569
+ const trimmed = signature.trim();
2570
+ const equalityIndex = trimmed.indexOf("=");
2571
+ if (equalityIndex === -1) {
2572
+ return trimmed;
2573
+ }
2574
+ const prefix = trimmed.slice(0, equalityIndex).toLowerCase();
2575
+ if (prefix !== DEFAULT_SIGNATURE_ALGORITHM) {
2576
+ throw new RequestWebhookSignatureError("Unsupported signature algorithm", {
2577
+ headerName,
2578
+ signature,
2579
+ timestamp: null,
2580
+ reason: "invalid_format"
2581
+ });
2582
+ }
2583
+ return trimmed.slice(equalityIndex + 1);
2584
+ }
2585
+ function parseSignatureValue(signature, headerName) {
2586
+ const stripped = stripAlgorithmPrefix(signature, headerName);
2587
+ const trimmed = stripped.trim();
2588
+ if (!trimmed || !HEX_SIGNATURE_PATTERN.test(trimmed)) {
2589
+ throw new RequestWebhookSignatureError("Invalid webhook signature format", {
2590
+ headerName,
2591
+ signature,
2592
+ timestamp: null,
2593
+ reason: "invalid_format"
2594
+ });
2595
+ }
2596
+ const lower = trimmed.toLowerCase();
2597
+ if (lower.length % 2 !== 0) {
2598
+ throw new RequestWebhookSignatureError("Invalid webhook signature length", {
2599
+ headerName,
2600
+ signature,
2601
+ timestamp: null,
2602
+ reason: "invalid_format"
2603
+ });
2604
+ }
2605
+ const digest = buffer.Buffer.from(lower, "hex");
2606
+ return { normalisedHex: lower, buffer: digest };
2607
+ }
2608
+ function computeHmac(secret, body) {
2609
+ return crypto.createHmac(DEFAULT_SIGNATURE_ALGORITHM, secret).update(body).digest();
2610
+ }
2611
+ function isReadonlyStringArray(value) {
2612
+ return Array.isArray(value);
2613
+ }
2614
+ function toSecretArray(secret) {
2615
+ return isReadonlyStringArray(secret) ? [...secret] : [secret];
2616
+ }
2617
+ function parseTimestamp(value) {
2618
+ const trimmed = value.trim();
2619
+ if (!trimmed) {
2620
+ return null;
2621
+ }
2622
+ if (/^-?\d+(\.\d+)?$/.test(trimmed)) {
2623
+ const numeric = Number(trimmed);
2624
+ if (!Number.isFinite(numeric)) {
2625
+ return null;
2626
+ }
2627
+ if (numeric > 1e12) {
2628
+ return Math.trunc(numeric);
2629
+ }
2630
+ if (numeric > 1e9) {
2631
+ return Math.trunc(numeric);
2632
+ }
2633
+ return Math.trunc(numeric * 1e3);
2634
+ }
2635
+ const parsed = Date.parse(trimmed);
2636
+ if (Number.isNaN(parsed)) {
2637
+ return null;
2638
+ }
2639
+ return parsed;
2640
+ }
2641
+ function resolveTimestamp(options, headers, headerName) {
2642
+ if (typeof options.timestamp === "number") {
2643
+ return options.timestamp;
2644
+ }
2645
+ if (!options.timestampHeader) {
2646
+ return null;
2647
+ }
2648
+ const headerValue = pickHeader(headers, options.timestampHeader);
2649
+ if (!headerValue) {
2650
+ return null;
2651
+ }
2652
+ const parsed = parseTimestamp(headerValue);
2653
+ if (parsed == null) {
2654
+ throw new RequestWebhookSignatureError("Invalid webhook timestamp header", {
2655
+ headerName: options.timestampHeader,
2656
+ signature: pickHeader(headers, headerName) ?? null,
2657
+ timestamp: null,
2658
+ reason: "invalid_format"
2659
+ });
2660
+ }
2661
+ return parsed;
2662
+ }
2663
+ function verifyWebhookSignature(options) {
2664
+ const {
2665
+ rawBody,
2666
+ secret,
2667
+ headers: rawHeaders,
2668
+ signature: explicitSignature,
2669
+ headerName = DEFAULT_SIGNATURE_HEADER,
2670
+ toleranceMs,
2671
+ now = () => Date.now()
2672
+ } = options;
2673
+ const headers = normaliseHeaders2(rawHeaders);
2674
+ const signatureValue = explicitSignature ?? pickHeader(headers, headerName);
2675
+ if (!signatureValue) {
2676
+ throw new RequestWebhookSignatureError(`Missing webhook signature header: ${headerName}`, {
2677
+ headerName,
2678
+ signature: null,
2679
+ timestamp: null,
2680
+ reason: "missing_signature"
2681
+ });
2682
+ }
2683
+ const { normalisedHex, buffer: signatureBuffer } = parseSignatureValue(signatureValue, headerName);
2684
+ const timestamp = resolveTimestamp(options, headers, headerName);
2685
+ if (typeof toleranceMs === "number" && toleranceMs >= 0 && timestamp != null) {
2686
+ const distance = Math.abs(now() - timestamp);
2687
+ if (distance > toleranceMs) {
2688
+ throw new RequestWebhookSignatureError("Webhook signature timestamp outside tolerance", {
2689
+ headerName,
2690
+ signature: normalisedHex,
2691
+ timestamp,
2692
+ reason: "tolerance_exceeded"
2693
+ });
2694
+ }
2695
+ }
2696
+ const bodyBuffer = toBuffer(rawBody);
2697
+ const secrets = toSecretArray(secret);
2698
+ if (secrets.length === 0) {
2699
+ throw new RequestWebhookSignatureError("No webhook secrets configured", {
2700
+ headerName,
2701
+ signature: normalisedHex,
2702
+ timestamp,
2703
+ reason: "invalid_signature"
2704
+ });
2705
+ }
2706
+ const digests = secrets.map((candidate) => computeHmac(candidate, bodyBuffer));
2707
+ const digestLength = digests[0].length;
2708
+ if (signatureBuffer.length !== digestLength) {
2709
+ throw new RequestWebhookSignatureError("Webhook signature length mismatch", {
2710
+ headerName,
2711
+ signature: normalisedHex,
2712
+ timestamp,
2713
+ reason: "invalid_format"
2714
+ });
2715
+ }
2716
+ for (let index = 0; index < digests.length; index += 1) {
2717
+ const digest = digests[index];
2718
+ if (crypto.timingSafeEqual(signatureBuffer, digest)) {
2719
+ return {
2720
+ signature: normalisedHex,
2721
+ matchedSecret: secrets[index],
2722
+ timestamp: timestamp ?? null,
2723
+ headers
2724
+ };
2725
+ }
2726
+ }
2727
+ throw new RequestWebhookSignatureError("Invalid webhook signature", {
2728
+ headerName,
2729
+ signature: normalisedHex,
2730
+ timestamp,
2731
+ reason: "invalid_signature"
2732
+ });
2733
+ }
2734
+ var COMPLIANCE_KYC_STATUSES = [
2735
+ "not_started",
2736
+ "initiated",
2737
+ "pending",
2738
+ "approved",
2739
+ "rejected",
2740
+ "failed",
2741
+ "completed"
2742
+ ];
2743
+ var COMPLIANCE_AGREEMENT_STATUSES = [
2744
+ "not_started",
2745
+ "pending",
2746
+ "completed",
2747
+ "rejected",
2748
+ "failed",
2749
+ "signed"
2750
+ ];
2751
+ var PAYMENT_FAILED_SUB_STATUSES = ["failed", "bounced", "insufficient_funds"];
2752
+ var PAYMENT_PROCESSING_SUB_STATUSES = [
2753
+ "initiated",
2754
+ "pending_internal_assessment",
2755
+ "ongoing_checks",
2756
+ "sending_fiat",
2757
+ "fiat_sent",
2758
+ "bounced",
2759
+ "retry_required",
2760
+ "processing"
2761
+ ];
2762
+ var PAYMENT_DETAIL_STATUSES = ["approved", "failed", "pending", "verified"];
2763
+ var webhookBaseSchema = zod.z.object({
2764
+ event: zod.z.string()
2765
+ }).passthrough();
2766
+ var paymentConfirmedSchema = webhookBaseSchema.extend({
2767
+ event: zod.z.literal("payment.confirmed")
2768
+ });
2769
+ var paymentFailedSchema = webhookBaseSchema.extend({
2770
+ event: zod.z.literal("payment.failed"),
2771
+ subStatus: zod.z.enum(PAYMENT_FAILED_SUB_STATUSES).optional(),
2772
+ failureReason: zod.z.string().optional(),
2773
+ retryAfter: zod.z.string().optional()
2774
+ });
2775
+ var paymentProcessingSchema = webhookBaseSchema.extend({
2776
+ event: zod.z.literal("payment.processing"),
2777
+ subStatus: zod.z.enum(PAYMENT_PROCESSING_SUB_STATUSES)
2778
+ });
2779
+ var paymentDetailUpdatedSchema = webhookBaseSchema.extend({
2780
+ event: zod.z.literal("payment_detail.updated"),
2781
+ status: zod.z.enum(PAYMENT_DETAIL_STATUSES),
2782
+ paymentDetailsId: zod.z.string().optional(),
2783
+ paymentAccountId: zod.z.string().optional(),
2784
+ rejectionMessage: zod.z.string().optional()
2785
+ });
2786
+ var complianceUpdatedSchema = webhookBaseSchema.extend({
2787
+ event: zod.z.literal("compliance.updated"),
2788
+ kycStatus: zod.z.enum(COMPLIANCE_KYC_STATUSES).optional(),
2789
+ agreementStatus: zod.z.enum(COMPLIANCE_AGREEMENT_STATUSES).optional(),
2790
+ isCompliant: zod.z.boolean().optional()
2791
+ });
2792
+ var paymentPartialSchema = webhookBaseSchema.extend({
2793
+ event: zod.z.literal("payment.partial")
2794
+ });
2795
+ var paymentRefundedSchema = webhookBaseSchema.extend({
2796
+ event: zod.z.literal("payment.refunded"),
2797
+ refundedTo: zod.z.string(),
2798
+ refundAmount: zod.z.string()
2799
+ });
2800
+ var requestRecurringSchema = webhookBaseSchema.extend({
2801
+ event: zod.z.literal("request.recurring"),
2802
+ originalRequestId: zod.z.string(),
2803
+ originalRequestPaymentReference: zod.z.string()
2804
+ });
2805
+ var webhookEventSchemas = {
2806
+ "payment.confirmed": paymentConfirmedSchema,
2807
+ "payment.failed": paymentFailedSchema,
2808
+ "payment.processing": paymentProcessingSchema,
2809
+ "payment_detail.updated": paymentDetailUpdatedSchema,
2810
+ "compliance.updated": complianceUpdatedSchema,
2811
+ "payment.partial": paymentPartialSchema,
2812
+ "payment.refunded": paymentRefundedSchema,
2813
+ "request.recurring": requestRecurringSchema
2814
+ };
2815
+ var WEBHOOK_EVENT_NAMES = Object.freeze(Object.keys(webhookEventSchemas));
2816
+ for (const [eventName, schema] of Object.entries(webhookEventSchemas)) {
2817
+ schemaRegistry.register({
2818
+ key: { operationId: eventName, kind: "webhook" },
2819
+ schema
2820
+ });
2821
+ }
2822
+ function getWebhookSchema(event) {
2823
+ return webhookEventSchemas[event];
2824
+ }
2825
+
2826
+ // src/webhooks/parser.webhook.ts
2827
+ function ensureBuffer(rawBody) {
2828
+ if (typeof rawBody === "string") {
2829
+ return buffer.Buffer.from(rawBody, "utf8");
2830
+ }
2831
+ if (rawBody instanceof ArrayBuffer) {
2832
+ return buffer.Buffer.from(rawBody);
2833
+ }
2834
+ return buffer.Buffer.from(rawBody.buffer, rawBody.byteOffset, rawBody.byteLength);
2835
+ }
2836
+ function normaliseBody(rawBody) {
2837
+ const buffer = ensureBuffer(rawBody);
2838
+ const view = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2839
+ return { buffer, view };
2840
+ }
2841
+ function parseJsonBody(buffer) {
2842
+ try {
2843
+ const text = buffer.toString("utf8");
2844
+ return JSON.parse(text);
2845
+ } catch (error) {
2846
+ throw new ValidationError("Invalid webhook JSON payload", error);
2847
+ }
2848
+ }
2849
+ function resolveEventName(body) {
2850
+ if (!body || typeof body !== "object" || Array.isArray(body)) {
2851
+ throw new ValidationError("Webhook payload must be a JSON object");
2852
+ }
2853
+ const candidate = body.event;
2854
+ if (typeof candidate !== "string" || candidate.length === 0) {
2855
+ throw new ValidationError("Webhook payload missing `event` field");
2856
+ }
2857
+ return candidate;
2858
+ }
2859
+ function assertWebhookEventName(name) {
2860
+ if (!WEBHOOK_EVENT_NAMES.includes(name)) {
2861
+ throw new ValidationError(`Unknown webhook event: ${name}`);
2862
+ }
2863
+ }
2864
+ function verifySignatureIfRequired(options, buffer, headers) {
2865
+ if (options.skipSignatureVerification) {
2866
+ return null;
2867
+ }
2868
+ return verifyWebhookSignature({
2869
+ rawBody: buffer,
2870
+ secret: options.secret,
2871
+ headers,
2872
+ signature: options.signature,
2873
+ headerName: options.headerName,
2874
+ toleranceMs: options.toleranceMs,
2875
+ timestampHeader: options.timestampHeader,
2876
+ now: options.now
2877
+ });
2878
+ }
2879
+ function parseWebhookEvent(options) {
2880
+ const { buffer, view } = normaliseBody(options.rawBody);
2881
+ const headers = options.skipSignatureVerification ? normaliseHeaders2(options.headers) : void 0;
2882
+ const verification = verifySignatureIfRequired(options, buffer, options.headers);
2883
+ const normalisedHeaders = verification?.headers ?? headers ?? normaliseHeaders2(options.headers);
2884
+ const signature = verification?.signature ?? options.signature ?? pickHeader(normalisedHeaders, options.headerName ?? DEFAULT_SIGNATURE_HEADER) ?? null;
2885
+ const matchedSecret = verification?.matchedSecret ?? null;
2886
+ const timestamp = verification?.timestamp ?? null;
2887
+ const jsonBody = parseJsonBody(buffer);
2888
+ const eventName = resolveEventName(jsonBody);
2889
+ assertWebhookEventName(eventName);
2890
+ const schema = getWebhookSchema(eventName);
2891
+ if (!schema) {
2892
+ throw new ValidationError(`No schema registered for webhook event ${eventName}`);
2893
+ }
2894
+ const parsed = parseWithSchema({
2895
+ schema,
2896
+ value: jsonBody,
2897
+ description: `Webhook event ${eventName}`
2898
+ });
2899
+ if (!parsed.success || !parsed.data) {
2900
+ const cause = parsed.error instanceof Error ? parsed.error : new ValidationError(`Invalid payload for webhook event ${eventName}`, parsed.error);
2901
+ throw cause;
2902
+ }
2903
+ const typedEventName = eventName;
2904
+ const payload = parsed.data;
2905
+ return {
2906
+ event: typedEventName,
2907
+ payload,
2908
+ signature,
2909
+ matchedSecret,
2910
+ timestamp,
2911
+ rawBody: view,
2912
+ headers: normalisedHeaders
2913
+ };
2914
+ }
2915
+
2916
+ // src/webhooks/dispatcher.webhook.ts
2917
+ function ensureHandlerSet(store, event) {
2918
+ let set = store.get(event);
2919
+ if (!set) {
2920
+ set = /* @__PURE__ */ new Set();
2921
+ store.set(event, set);
2922
+ }
2923
+ return set;
2924
+ }
2925
+ var WebhookDispatcher = class {
2926
+ handlers = /* @__PURE__ */ new Map();
2927
+ on(event, handler) {
2928
+ const set = ensureHandlerSet(this.handlers, event);
2929
+ const wrapped = handler;
2930
+ set.add(wrapped);
2931
+ return () => {
2932
+ const existing = this.handlers.get(event);
2933
+ if (!existing) return;
2934
+ existing.delete(wrapped);
2935
+ if (existing.size === 0) {
2936
+ this.handlers.delete(event);
2937
+ }
2938
+ };
2939
+ }
2940
+ once(event, handler) {
2941
+ const disposeRef = {};
2942
+ const wrapped = async (evt, context) => {
2943
+ disposeRef.dispose?.();
2944
+ await handler(evt, context);
2945
+ };
2946
+ const dispose = this.on(event, wrapped);
2947
+ disposeRef.dispose = dispose;
2948
+ return dispose;
2949
+ }
2950
+ off(event, handler) {
2951
+ const set = this.handlers.get(event);
2952
+ if (!set) return;
2953
+ set.delete(handler);
2954
+ if (set.size === 0) {
2955
+ this.handlers.delete(event);
2956
+ }
2957
+ }
2958
+ clear() {
2959
+ this.handlers.clear();
2960
+ }
2961
+ handlerCount(event) {
2962
+ if (event) {
2963
+ return this.handlers.get(event)?.size ?? 0;
2964
+ }
2965
+ let total = 0;
2966
+ for (const set of this.handlers.values()) {
2967
+ total += set.size;
2968
+ }
2969
+ return total;
2970
+ }
2971
+ async dispatch(event, context = {}) {
2972
+ const set = this.handlers.get(event.event);
2973
+ if (!set || set.size === 0) {
2974
+ return;
2975
+ }
2976
+ const handlers = Array.from(set);
2977
+ for (const handler of handlers) {
2978
+ await handler(event, context);
2979
+ }
2980
+ }
2981
+ /**
2982
+ * Syntactic sugar for strongly typed handler registration that returns the original handler for chaining.
2983
+ */
2984
+ register(event, handler) {
2985
+ this.on(event, handler);
2986
+ return handler;
2987
+ }
2988
+ };
2989
+ function createWebhookDispatcher() {
2990
+ return new WebhookDispatcher();
2991
+ }
2992
+
2993
+ // src/webhooks/testing.webhook.ts
2994
+ var testing_webhook_exports = {};
2995
+ __export(testing_webhook_exports, {
2996
+ DEFAULT_TEST_WEBHOOK_SECRET: () => DEFAULT_TEST_WEBHOOK_SECRET,
2997
+ createMockWebhookRequest: () => createMockWebhookRequest,
2998
+ createMockWebhookResponse: () => createMockWebhookResponse,
2999
+ generateTestWebhookSignature: () => generateTestWebhookSignature,
3000
+ isWebhookVerificationBypassed: () => isWebhookVerificationBypassed,
3001
+ setWebhookVerificationBypass: () => setWebhookVerificationBypass,
3002
+ withWebhookVerificationDisabled: () => withWebhookVerificationDisabled
3003
+ });
3004
+ var DEFAULT_TEST_WEBHOOK_SECRET = "whsec_test_secret";
3005
+ var inMemoryBypass = false;
3006
+ function toBuffer2(body) {
3007
+ if (typeof body === "string") {
3008
+ return buffer.Buffer.from(body, "utf8");
3009
+ }
3010
+ if (body instanceof ArrayBuffer) {
3011
+ return buffer.Buffer.from(body);
3012
+ }
3013
+ if (ArrayBuffer.isView(body)) {
3014
+ const view = body;
3015
+ return buffer.Buffer.from(view.buffer, view.byteOffset, view.byteLength);
3016
+ }
3017
+ return buffer.Buffer.from(JSON.stringify(body));
3018
+ }
3019
+ function generateTestWebhookSignature(rawBody, secret = DEFAULT_TEST_WEBHOOK_SECRET) {
3020
+ const buffer = toBuffer2(rawBody);
3021
+ return crypto.createHmac(DEFAULT_SIGNATURE_ALGORITHM, secret).update(buffer).digest("hex");
3022
+ }
3023
+ function isWebhookVerificationBypassed() {
3024
+ if (typeof process !== "undefined" && process.env.REQUEST_WEBHOOK_DISABLE_VERIFICATION === "true") {
3025
+ return true;
3026
+ }
3027
+ return inMemoryBypass;
3028
+ }
3029
+ function setWebhookVerificationBypass(enabled) {
3030
+ inMemoryBypass = enabled;
3031
+ }
3032
+ async function withWebhookVerificationDisabled(fn) {
3033
+ const previous = inMemoryBypass;
3034
+ inMemoryBypass = true;
3035
+ try {
3036
+ return await fn();
3037
+ } finally {
3038
+ inMemoryBypass = previous;
3039
+ }
3040
+ }
3041
+ function createMockWebhookRequest(options) {
3042
+ const { payload, secret = DEFAULT_TEST_WEBHOOK_SECRET, headerName = DEFAULT_SIGNATURE_HEADER, headers } = options;
3043
+ const rawBody = toBuffer2(payload);
3044
+ const signature = generateTestWebhookSignature(rawBody, secret);
3045
+ const req = {
3046
+ headers: {
3047
+ ...headers ?? {},
3048
+ [headerName]: signature
3049
+ },
3050
+ rawBody,
3051
+ body: rawBody
3052
+ };
3053
+ return req;
3054
+ }
3055
+ function createMockWebhookResponse() {
3056
+ return {
3057
+ statusCode: 200,
3058
+ body: void 0,
3059
+ headersSent: false,
3060
+ status(code) {
3061
+ this.statusCode = code;
3062
+ return this;
3063
+ },
3064
+ json(payload) {
3065
+ this.body = payload;
3066
+ this.headersSent = true;
3067
+ return this;
3068
+ },
3069
+ send(payload) {
3070
+ this.body = payload;
3071
+ this.headersSent = true;
3072
+ return this;
3073
+ }
3074
+ };
3075
+ }
3076
+
3077
+ // src/webhooks/middleware.webhook.ts
3078
+ var DEFAULT_ATTACH_PROPERTY = "webhook";
3079
+ function isArrayBufferView(value) {
3080
+ return Boolean(value) && ArrayBuffer.isView(value);
3081
+ }
3082
+ function isBinaryLike(value) {
3083
+ return typeof value === "string" || value instanceof ArrayBuffer || isArrayBufferView(value);
3084
+ }
3085
+ var defaultGetRawBody = (req) => {
3086
+ const carrier = req;
3087
+ if (isBinaryLike(carrier.rawBody)) {
3088
+ return carrier.rawBody;
3089
+ }
3090
+ if (isBinaryLike(carrier.body)) {
3091
+ return carrier.body;
3092
+ }
3093
+ return null;
3094
+ };
3095
+ var defaultDispatchContext = (req, res, event) => ({
3096
+ req,
3097
+ res,
3098
+ event
3099
+ });
3100
+ async function handleSuccess(parsed, req, res, options) {
3101
+ const {
3102
+ dispatcher,
3103
+ onEvent,
3104
+ logger,
3105
+ attachProperty = DEFAULT_ATTACH_PROPERTY,
3106
+ buildDispatchContext = defaultDispatchContext
3107
+ } = options;
3108
+ Reflect.set(req, attachProperty, parsed);
3109
+ if (logger?.debug) {
3110
+ logger.debug("Webhook event verified", { event: parsed.event, signature: parsed.signature });
3111
+ }
3112
+ if (dispatcher) {
3113
+ const context = buildDispatchContext(req, res, parsed);
3114
+ await dispatcher.dispatch(parsed, context);
3115
+ }
3116
+ if (onEvent) {
3117
+ await onEvent(parsed, req, res);
3118
+ }
3119
+ }
3120
+ async function handleError(error, req, res, options) {
3121
+ const { logger, onError } = options;
3122
+ if (error instanceof RequestWebhookSignatureError) {
3123
+ logger?.warn?.("Webhook signature verification failed", {
3124
+ error,
3125
+ header: error.headerName,
3126
+ reason: error.reason
3127
+ });
3128
+ if (!res.headersSent) {
3129
+ res.status(error.statusCode).json({
3130
+ error: "invalid_webhook_signature",
3131
+ reason: error.reason
3132
+ });
3133
+ }
3134
+ return;
3135
+ }
3136
+ logger?.error?.("Webhook middleware error", { error });
3137
+ if (onError) {
3138
+ await onError(error, req, res);
3139
+ }
3140
+ }
3141
+ function createWebhookMiddleware(options) {
3142
+ const {
3143
+ secret,
3144
+ headerName,
3145
+ timestampHeader,
3146
+ toleranceMs,
3147
+ getRawBody = defaultGetRawBody,
3148
+ skipVerification,
3149
+ autoNext = true
3150
+ } = options;
3151
+ if (!secret || Array.isArray(secret) && secret.length === 0) {
3152
+ throw new Error("createWebhookMiddleware requires at least one webhook secret");
3153
+ }
3154
+ const handler = async (req, res, next) => {
3155
+ const rawBody = getRawBody(req);
3156
+ if (!isBinaryLike(rawBody)) {
3157
+ const bodyError = new Error("Webhook middleware requires the raw request body. Configure express.raw() or supply getRawBody.");
3158
+ await handleError(bodyError, req, res, options);
3159
+ if (!res.headersSent && autoNext) {
3160
+ next(bodyError);
3161
+ }
3162
+ return;
3163
+ }
3164
+ const shouldSkip = skipVerification?.(req) ?? isWebhookVerificationBypassed();
3165
+ try {
3166
+ const parsed = parseWebhookEvent({
3167
+ rawBody,
3168
+ headers: req.headers,
3169
+ secret,
3170
+ headerName,
3171
+ timestampHeader,
3172
+ toleranceMs,
3173
+ skipSignatureVerification: shouldSkip
3174
+ });
3175
+ await handleSuccess(parsed, req, res, options);
3176
+ if (autoNext) {
3177
+ next();
3178
+ }
3179
+ } catch (error) {
3180
+ await handleError(error, req, res, options);
3181
+ if (!res.headersSent && autoNext) {
3182
+ const err = error instanceof Error ? error : new Error("Webhook middleware handler failed", { cause: error });
3183
+ next(err);
3184
+ }
3185
+ }
3186
+ };
3187
+ return handler;
3188
+ }
3189
+
3190
+ // src/webhooks/events/index.ts
3191
+ var events_exports = {};
3192
+ __export(events_exports, {
3193
+ COMPLIANCE_AGREEMENT_STATUSES: () => COMPLIANCE_AGREEMENT_STATUSES2,
3194
+ COMPLIANCE_KYC_STATUSES: () => COMPLIANCE_KYC_STATUSES2,
3195
+ COMPLIANCE_UPDATED_EVENT: () => COMPLIANCE_UPDATED_EVENT,
3196
+ PAYMENT_CONFIRMED_EVENT: () => PAYMENT_CONFIRMED_EVENT,
3197
+ PAYMENT_DETAIL_STATUSES: () => PAYMENT_DETAIL_STATUSES2,
3198
+ PAYMENT_DETAIL_UPDATED_EVENT: () => PAYMENT_DETAIL_UPDATED_EVENT,
3199
+ PAYMENT_FAILED_EVENT: () => PAYMENT_FAILED_EVENT,
3200
+ PAYMENT_FAILED_SUB_STATUSES: () => PAYMENT_FAILED_SUB_STATUSES2,
3201
+ PAYMENT_PARTIAL_EVENT: () => PAYMENT_PARTIAL_EVENT,
3202
+ PAYMENT_PROCESSING_EVENT: () => PAYMENT_PROCESSING_EVENT,
3203
+ PAYMENT_PROCESSING_STAGES: () => PAYMENT_PROCESSING_STAGES,
3204
+ PAYMENT_REFUNDED_EVENT: () => PAYMENT_REFUNDED_EVENT,
3205
+ REQUEST_RECURRING_EVENT: () => REQUEST_RECURRING_EVENT,
3206
+ assertComplianceUpdatedEvent: () => assertComplianceUpdatedEvent,
3207
+ assertPaymentConfirmedEvent: () => assertPaymentConfirmedEvent,
3208
+ assertPaymentDetailUpdatedEvent: () => assertPaymentDetailUpdatedEvent,
3209
+ assertPaymentFailedEvent: () => assertPaymentFailedEvent,
3210
+ assertPaymentPartialEvent: () => assertPaymentPartialEvent,
3211
+ assertPaymentProcessingEvent: () => assertPaymentProcessingEvent,
3212
+ assertPaymentRefundedEvent: () => assertPaymentRefundedEvent,
3213
+ assertRequestRecurringEvent: () => assertRequestRecurringEvent,
3214
+ complianceStatusSummary: () => complianceStatusSummary,
3215
+ createEventPredicate: () => createEventPredicate,
3216
+ isAgreementRejected: () => isAgreementRejected,
3217
+ isBouncedFailure: () => isBouncedFailure,
3218
+ isComplianceUpdatedEvent: () => isComplianceUpdatedEvent,
3219
+ isInsufficientFundsFailure: () => isInsufficientFundsFailure,
3220
+ isKycComplete: () => isKycComplete,
3221
+ isPaymentConfirmedEvent: () => isPaymentConfirmedEvent,
3222
+ isPaymentDetailApproved: () => isPaymentDetailApproved,
3223
+ isPaymentDetailPending: () => isPaymentDetailPending,
3224
+ isPaymentDetailRejected: () => isPaymentDetailRejected,
3225
+ isPaymentDetailUpdatedEvent: () => isPaymentDetailUpdatedEvent,
3226
+ isPaymentDetailVerified: () => isPaymentDetailVerified,
3227
+ isPaymentFailedEvent: () => isPaymentFailedEvent,
3228
+ isPaymentPartialEvent: () => isPaymentPartialEvent,
3229
+ isPaymentProcessingEvent: () => isPaymentProcessingEvent,
3230
+ isPaymentRefundedEvent: () => isPaymentRefundedEvent,
3231
+ isProcessingTerminalStatus: () => isProcessingTerminalStatus,
3232
+ isRequestRecurringEvent: () => isRequestRecurringEvent,
3233
+ isRetryRequired: () => isRetryRequired,
3234
+ onComplianceUpdated: () => onComplianceUpdated,
3235
+ onPaymentConfirmed: () => onPaymentConfirmed,
3236
+ onPaymentDetailUpdated: () => onPaymentDetailUpdated,
3237
+ onPaymentFailed: () => onPaymentFailed,
3238
+ onPaymentPartial: () => onPaymentPartial,
3239
+ onPaymentProcessing: () => onPaymentProcessing,
3240
+ onPaymentRefunded: () => onPaymentRefunded,
3241
+ onRequestRecurring: () => onRequestRecurring,
3242
+ processingStageLabel: () => processingStageLabel,
3243
+ registerEventHandler: () => registerEventHandler
3244
+ });
3245
+
3246
+ // src/webhooks/events/base.event.ts
3247
+ function registerEventHandler(dispatcher, event, handler) {
3248
+ return dispatcher.on(event, async (parsed, dispatchContext) => {
3249
+ await handler(parsed.payload, { event: parsed, dispatchContext });
3250
+ });
3251
+ }
3252
+ function createEventPredicate(event) {
3253
+ return (parsed) => parsed.event === event;
3254
+ }
3255
+
3256
+ // src/webhooks/events/payment-confirmed.event.ts
3257
+ var PAYMENT_CONFIRMED_EVENT = "payment.confirmed";
3258
+ var isPaymentConfirmedEvent = createEventPredicate(PAYMENT_CONFIRMED_EVENT);
3259
+ function onPaymentConfirmed(dispatcher, handler) {
3260
+ return registerEventHandler(dispatcher, PAYMENT_CONFIRMED_EVENT, handler);
3261
+ }
3262
+ function assertPaymentConfirmedEvent(event) {
3263
+ if (event.event !== PAYMENT_CONFIRMED_EVENT) {
3264
+ throw new TypeError(`Expected payment.confirmed event. Received ${event.event}.`);
3265
+ }
3266
+ }
3267
+
3268
+ // src/webhooks/events/payment-failed.event.ts
3269
+ var PAYMENT_FAILED_EVENT = "payment.failed";
3270
+ var PAYMENT_FAILED_SUB_STATUSES2 = Object.freeze(["failed", "bounced", "insufficient_funds"]);
3271
+ var isPaymentFailedEvent = createEventPredicate(PAYMENT_FAILED_EVENT);
3272
+ function onPaymentFailed(dispatcher, handler) {
3273
+ return registerEventHandler(dispatcher, PAYMENT_FAILED_EVENT, handler);
3274
+ }
3275
+ function assertPaymentFailedEvent(event) {
3276
+ if (event.event !== PAYMENT_FAILED_EVENT) {
3277
+ throw new TypeError(`Expected payment.failed event. Received ${event.event}.`);
3278
+ }
3279
+ }
3280
+ function isBouncedFailure(payload) {
3281
+ return payload.subStatus === "bounced";
3282
+ }
3283
+ function isInsufficientFundsFailure(payload) {
3284
+ return payload.subStatus === "insufficient_funds";
3285
+ }
3286
+
3287
+ // src/webhooks/events/payment-processing.event.ts
3288
+ var PAYMENT_PROCESSING_EVENT = "payment.processing";
3289
+ var PAYMENT_PROCESSING_STAGES = Object.freeze([
3290
+ "initiated",
3291
+ "pending_internal_assessment",
3292
+ "ongoing_checks",
3293
+ "processing",
3294
+ "sending_fiat",
3295
+ "fiat_sent",
3296
+ "bounced",
3297
+ "retry_required"
3298
+ ]);
3299
+ var TERMINAL_STAGES = /* @__PURE__ */ new Set(["fiat_sent", "bounced", "retry_required"]);
3300
+ var STAGE_LABELS = {
3301
+ initiated: "Transfer initiated",
3302
+ pending_internal_assessment: "Pending internal assessment",
3303
+ ongoing_checks: "Ongoing compliance checks",
3304
+ processing: "Processing payment",
3305
+ sending_fiat: "Sending fiat to recipient",
3306
+ fiat_sent: "Fiat delivered",
3307
+ bounced: "Payment bounced",
3308
+ retry_required: "Retry required"
3309
+ };
3310
+ var isPaymentProcessingEvent = createEventPredicate(PAYMENT_PROCESSING_EVENT);
3311
+ function onPaymentProcessing(dispatcher, handler) {
3312
+ return registerEventHandler(dispatcher, PAYMENT_PROCESSING_EVENT, handler);
3313
+ }
3314
+ function assertPaymentProcessingEvent(event) {
3315
+ if (event.event !== PAYMENT_PROCESSING_EVENT) {
3316
+ throw new TypeError(`Expected payment.processing event. Received ${event.event}.`);
3317
+ }
3318
+ }
3319
+ function isProcessingTerminalStatus(stage) {
3320
+ return TERMINAL_STAGES.has(stage);
3321
+ }
3322
+ function processingStageLabel(stage) {
3323
+ return STAGE_LABELS[stage];
3324
+ }
3325
+ function isRetryRequired(stage) {
3326
+ return stage === "retry_required";
3327
+ }
3328
+
3329
+ // src/webhooks/events/payment-detail-updated.event.ts
3330
+ var PAYMENT_DETAIL_UPDATED_EVENT = "payment_detail.updated";
3331
+ var PAYMENT_DETAIL_STATUSES2 = Object.freeze(["approved", "failed", "pending", "verified"]);
3332
+ var isPaymentDetailUpdatedEvent = createEventPredicate(PAYMENT_DETAIL_UPDATED_EVENT);
3333
+ function onPaymentDetailUpdated(dispatcher, handler) {
3334
+ return registerEventHandler(dispatcher, PAYMENT_DETAIL_UPDATED_EVENT, handler);
3335
+ }
3336
+ function assertPaymentDetailUpdatedEvent(event) {
3337
+ if (event.event !== PAYMENT_DETAIL_UPDATED_EVENT) {
3338
+ throw new TypeError(`Expected payment_detail.updated event. Received ${event.event}.`);
3339
+ }
3340
+ }
3341
+ function isPaymentDetailApproved(payload) {
3342
+ return payload.status === "approved";
3343
+ }
3344
+ function isPaymentDetailRejected(payload) {
3345
+ return payload.status === "failed";
3346
+ }
3347
+ function isPaymentDetailPending(payload) {
3348
+ return payload.status === "pending";
3349
+ }
3350
+ function isPaymentDetailVerified(payload) {
3351
+ return payload.status === "verified";
3352
+ }
3353
+
3354
+ // src/webhooks/events/compliance-updated.event.ts
3355
+ var COMPLIANCE_UPDATED_EVENT = "compliance.updated";
3356
+ var COMPLIANCE_KYC_STATUSES2 = Object.freeze([
3357
+ "initiated",
3358
+ "pending",
3359
+ "approved",
3360
+ "rejected",
3361
+ "failed"
3362
+ ]);
3363
+ var COMPLIANCE_AGREEMENT_STATUSES2 = Object.freeze([
3364
+ "not_started",
3365
+ "pending",
3366
+ "completed",
3367
+ "rejected",
3368
+ "failed",
3369
+ "signed"
3370
+ ]);
3371
+ var isComplianceUpdatedEvent = createEventPredicate(COMPLIANCE_UPDATED_EVENT);
3372
+ function onComplianceUpdated(dispatcher, handler) {
3373
+ return registerEventHandler(dispatcher, COMPLIANCE_UPDATED_EVENT, handler);
3374
+ }
3375
+ function assertComplianceUpdatedEvent(event) {
3376
+ if (event.event !== COMPLIANCE_UPDATED_EVENT) {
3377
+ throw new TypeError(`Expected compliance.updated event. Received ${event.event}.`);
3378
+ }
3379
+ }
3380
+ function isKycComplete(payload) {
3381
+ return payload.kycStatus === "approved";
3382
+ }
3383
+ function isAgreementRejected(payload) {
3384
+ return payload.agreementStatus === "rejected" || payload.agreementStatus === "failed";
3385
+ }
3386
+ function complianceStatusSummary(payload) {
3387
+ const parts = [];
3388
+ const kyc = payload.kycStatus ? String(payload.kycStatus).replace(/_/g, " ") : "unknown";
3389
+ const agreement = payload.agreementStatus ? String(payload.agreementStatus).replace(/_/g, " ") : "unknown";
3390
+ parts.push(`KYC: ${kyc}`);
3391
+ parts.push(`Agreement: ${agreement}`);
3392
+ if (payload.clientUserId) {
3393
+ const clientUserId = JSON.stringify(payload.clientUserId);
3394
+ parts.push(`Client user: ${clientUserId}`);
3395
+ }
3396
+ return parts.join(" | ");
3397
+ }
3398
+
3399
+ // src/webhooks/events/payment-partial.event.ts
3400
+ var PAYMENT_PARTIAL_EVENT = "payment.partial";
3401
+ var isPaymentPartialEvent = createEventPredicate(PAYMENT_PARTIAL_EVENT);
3402
+ function onPaymentPartial(dispatcher, handler) {
3403
+ return registerEventHandler(dispatcher, PAYMENT_PARTIAL_EVENT, handler);
3404
+ }
3405
+ function assertPaymentPartialEvent(event) {
3406
+ if (event.event !== PAYMENT_PARTIAL_EVENT) {
3407
+ throw new TypeError(`Expected payment.partial event. Received ${event.event}.`);
3408
+ }
3409
+ }
3410
+
3411
+ // src/webhooks/events/payment-refunded.event.ts
3412
+ var PAYMENT_REFUNDED_EVENT = "payment.refunded";
3413
+ var isPaymentRefundedEvent = createEventPredicate(PAYMENT_REFUNDED_EVENT);
3414
+ function onPaymentRefunded(dispatcher, handler) {
3415
+ return registerEventHandler(dispatcher, PAYMENT_REFUNDED_EVENT, handler);
3416
+ }
3417
+ function assertPaymentRefundedEvent(event) {
3418
+ if (event.event !== PAYMENT_REFUNDED_EVENT) {
3419
+ throw new TypeError(`Expected payment.refunded event. Received ${event.event}.`);
3420
+ }
3421
+ }
3422
+
3423
+ // src/webhooks/events/request-recurring.event.ts
3424
+ var REQUEST_RECURRING_EVENT = "request.recurring";
3425
+ var isRequestRecurringEvent = createEventPredicate(REQUEST_RECURRING_EVENT);
3426
+ function onRequestRecurring(dispatcher, handler) {
3427
+ return registerEventHandler(dispatcher, REQUEST_RECURRING_EVENT, handler);
3428
+ }
3429
+ function assertRequestRecurringEvent(event) {
3430
+ if (event.event !== REQUEST_RECURRING_EVENT) {
3431
+ throw new TypeError(`Expected request.recurring event. Received ${event.event}.`);
3432
+ }
3433
+ }
3434
+
3435
+ exports.DEFAULT_RETRY_CONFIG = DEFAULT_RETRY_CONFIG;
3436
+ exports.RequestApiError = RequestApiError;
3437
+ exports.RequestEnvironment = RequestEnvironment;
3438
+ exports.SchemaRegistry = SchemaRegistry;
3439
+ exports.ValidationError = ValidationError;
3440
+ exports.browserFetchAdapter = browserFetchAdapter;
3441
+ exports.buildRequestApiError = buildRequestApiError;
3442
+ exports.clientIds = client_ids_exports;
3443
+ exports.computeRetryDelay = computeRetryDelay;
3444
+ exports.createHttpClient = createHttpClient;
3445
+ exports.createRequestClient = createRequestClient;
3446
+ exports.createRequestClientFromEnv = createRequestClientFromEnv;
3447
+ exports.currencies = currencies_exports;
3448
+ exports.currenciesV1 = v1_exports;
3449
+ exports.isRequestApiError = isRequestApiError;
3450
+ exports.nodeFetchAdapter = nodeFetchAdapter;
3451
+ exports.parseWithRegistry = parseWithRegistry;
3452
+ exports.parseWithSchema = parseWithSchema;
3453
+ exports.pay = pay_exports;
3454
+ exports.payV1 = v1_exports2;
3455
+ exports.payer = payer_exports;
3456
+ exports.payerV1 = v1_exports3;
3457
+ exports.payerV2 = v2_exports;
3458
+ exports.payments = payments_exports;
3459
+ exports.payouts = payouts_exports;
3460
+ exports.requests = requests_exports;
3461
+ exports.requestsV1 = v1_exports4;
3462
+ exports.schemaRegistry = schemaRegistry;
3463
+ exports.shouldRetryRequest = shouldRetryRequest;
3464
+ exports.webhooks = webhooks_exports;
3465
+ //# sourceMappingURL=index.js.map
3466
+ //# sourceMappingURL=index.js.map