@voyantjs/plugin-netopia 0.1.1 → 0.3.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 (44) hide show
  1. package/dist/client.d.ts.map +1 -0
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/{src/plugin.d.ts → plugin.d.ts} +32 -32
  4. package/dist/{src/plugin.d.ts.map → plugin.d.ts.map} +1 -1
  5. package/dist/service-callback.d.ts +5 -0
  6. package/dist/service-callback.d.ts.map +1 -0
  7. package/dist/service-callback.js +124 -0
  8. package/dist/service-collect.d.ts +9 -0
  9. package/dist/service-collect.d.ts.map +1 -0
  10. package/dist/service-collect.js +70 -0
  11. package/dist/service-shared.d.ts +33 -0
  12. package/dist/service-shared.d.ts.map +1 -0
  13. package/dist/service-shared.js +44 -0
  14. package/dist/service-start.d.ts +6 -0
  15. package/dist/service-start.d.ts.map +1 -0
  16. package/dist/service-start.js +81 -0
  17. package/dist/service.d.ts +13 -0
  18. package/dist/service.d.ts.map +1 -0
  19. package/dist/service.js +12 -0
  20. package/dist/types.d.ts.map +1 -0
  21. package/dist/validation.d.ts.map +1 -0
  22. package/package.json +6 -6
  23. package/dist/src/client.d.ts.map +0 -1
  24. package/dist/src/index.d.ts.map +0 -1
  25. package/dist/src/service.d.ts +0 -36
  26. package/dist/src/service.d.ts.map +0 -1
  27. package/dist/src/service.js +0 -314
  28. package/dist/src/types.d.ts.map +0 -1
  29. package/dist/src/validation.d.ts.map +0 -1
  30. package/dist/tests/unit/client.test.d.ts +0 -2
  31. package/dist/tests/unit/client.test.d.ts.map +0 -1
  32. package/dist/tests/unit/client.test.js +0 -254
  33. package/dist/tests/unit/plugin.test.d.ts +0 -2
  34. package/dist/tests/unit/plugin.test.d.ts.map +0 -1
  35. package/dist/tests/unit/plugin.test.js +0 -346
  36. /package/dist/{src/client.d.ts → client.d.ts} +0 -0
  37. /package/dist/{src/client.js → client.js} +0 -0
  38. /package/dist/{src/index.d.ts → index.d.ts} +0 -0
  39. /package/dist/{src/index.js → index.js} +0 -0
  40. /package/dist/{src/plugin.js → plugin.js} +0 -0
  41. /package/dist/{src/types.d.ts → types.d.ts} +0 -0
  42. /package/dist/{src/types.js → types.js} +0 -0
  43. /package/dist/{src/validation.d.ts → validation.d.ts} +0 -0
  44. /package/dist/{src/validation.js → validation.js} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voyantjs/plugin-netopia",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "license": "FSL-1.1-Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
@@ -33,10 +33,10 @@
33
33
  "drizzle-orm": "^0.45.2",
34
34
  "hono": "^4.12.10",
35
35
  "zod": "^4.3.6",
36
- "@voyantjs/core": "0.1.1",
37
- "@voyantjs/finance": "0.1.1",
38
- "@voyantjs/hono": "0.1.1",
39
- "@voyantjs/notifications": "0.1.1"
36
+ "@voyantjs/core": "0.3.0",
37
+ "@voyantjs/finance": "0.3.0",
38
+ "@voyantjs/hono": "0.3.0",
39
+ "@voyantjs/notifications": "0.3.0"
40
40
  },
41
41
  "devDependencies": {
42
42
  "typescript": "^6.0.2",
@@ -58,7 +58,7 @@
58
58
  "typecheck": "tsc --noEmit",
59
59
  "lint": "biome check src/",
60
60
  "test": "vitest run",
61
- "build": "tsc -p tsconfig.json",
61
+ "build": "pnpm run clean && tsc -p tsconfig.json",
62
62
  "clean": "rm -rf dist"
63
63
  },
64
64
  "main": "./dist/index.js",
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,qBAAqB,EACrB,0BAA0B,EAC1B,2BAA2B,EAC3B,6BAA6B,EAC9B,MAAM,YAAY,CAAA;AAEnB,MAAM,WAAW,gBAAgB;IAC/B,gBAAgB,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAAC,2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@@
1
- import { type PaymentSession } from "@voyantjs/finance";
2
- import { type NotificationDelivery, type NotificationService } from "@voyantjs/notifications";
3
- import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
4
- import type { z } from "zod";
5
- import { type NetopiaClientApi } from "./client.js";
6
- import type { NetopiaRuntimeOptions, NetopiaStartPaymentInput, NetopiaStartPaymentResponse, NetopiaWebhookPayload, ResolvedNetopiaRuntimeOptions } from "./types.js";
7
- import type { netopiaCollectBookingGuaranteeSchema, netopiaCollectBookingScheduleSchema, netopiaCollectInvoiceSchema } from "./validation.js";
8
- export interface NetopiaStartPaymentResult {
9
- session: PaymentSession;
10
- providerResponse: NetopiaStartPaymentResponse;
11
- orderId: string;
12
- }
13
- export interface NetopiaCallbackResult {
14
- action: "processing" | "completed" | "failed" | "ignored";
15
- reason?: string;
16
- session: PaymentSession | null;
17
- orderId: string;
18
- }
19
- export interface NetopiaCollectPaymentResult extends NetopiaStartPaymentResult {
20
- paymentSessionNotification: NotificationDelivery | null;
21
- invoiceNotification: NotificationDelivery | null;
22
- }
23
- type NetopiaCollectBookingScheduleInput = z.infer<typeof netopiaCollectBookingScheduleSchema>;
24
- type NetopiaCollectBookingGuaranteeInput = z.infer<typeof netopiaCollectBookingGuaranteeSchema>;
25
- type NetopiaCollectInvoiceInput = z.infer<typeof netopiaCollectInvoiceSchema>;
26
- export declare function deriveNetopiaOrderId(session: PaymentSession): string;
27
- export declare function mapNetopiaPaymentStatus(status: number, options: Pick<ResolvedNetopiaRuntimeOptions, "successStatuses" | "processingStatuses">): "completed" | "processing" | "failed";
28
- export declare const netopiaService: {
29
- startPaymentSession(db: PostgresJsDatabase, sessionId: string, input: NetopiaStartPaymentInput, runtimeOptions?: NetopiaRuntimeOptions, clientOverride?: NetopiaClientApi, bindings?: Record<string, unknown>): Promise<NetopiaStartPaymentResult>;
30
- collectBookingSchedule(db: PostgresJsDatabase, scheduleId: string, input: NetopiaCollectBookingScheduleInput, runtimeOptions?: NetopiaRuntimeOptions, clientOverride?: NetopiaClientApi, dispatcherOverride?: NotificationService, bindings?: Record<string, unknown>): Promise<NetopiaCollectPaymentResult>;
31
- collectBookingGuarantee(db: PostgresJsDatabase, guaranteeId: string, input: NetopiaCollectBookingGuaranteeInput, runtimeOptions?: NetopiaRuntimeOptions, clientOverride?: NetopiaClientApi, dispatcherOverride?: NotificationService, bindings?: Record<string, unknown>): Promise<NetopiaCollectPaymentResult>;
32
- collectInvoice(db: PostgresJsDatabase, invoiceId: string, input: NetopiaCollectInvoiceInput, runtimeOptions?: NetopiaRuntimeOptions, clientOverride?: NetopiaClientApi, dispatcherOverride?: NotificationService, bindings?: Record<string, unknown>): Promise<NetopiaCollectPaymentResult>;
33
- handleCallback(db: PostgresJsDatabase, payload: NetopiaWebhookPayload, runtimeOptions?: NetopiaRuntimeOptions, bindings?: Record<string, unknown>): Promise<NetopiaCallbackResult>;
34
- };
35
- export {};
36
- //# sourceMappingURL=service.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvE,OAAO,EAGL,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EAEzB,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AACjE,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAE5B,OAAO,EAEL,KAAK,gBAAgB,EAEtB,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAEV,qBAAqB,EACrB,wBAAwB,EAExB,2BAA2B,EAC3B,qBAAqB,EACrB,6BAA6B,EAC9B,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EACV,oCAAoC,EACpC,mCAAmC,EACnC,2BAA2B,EAC5B,MAAM,iBAAiB,CAAA;AAExB,MAAM,WAAW,yBAAyB;IACxC,OAAO,EAAE,cAA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B,eACT,MAAM,SACZ,mCAAmC,mBAC1B,qBAAqB,mBACpB,gBAAgB,uBACZ,mBAAmB,aAC7B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,OAAO,CAAC,2BAA2B,CAAC;uBAyCjC,kBAAkB,aACX,MAAM,SACV,0BAA0B,mBACjB,qBAAqB,mBACpB,gBAAgB,uBACZ,mBAAmB,aAC7B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,OAAO,CAAC,2BAA2B,CAAC;uBAoDjC,kBAAkB,WACb,qBAAqB,mBACd,qBAAqB,aAC1B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,OAAO,CAAC,qBAAqB,CAAC;CA+IlC,CAAA"}
@@ -1,314 +0,0 @@
1
- import { financeService } from "@voyantjs/finance";
2
- import { createDefaultNotificationProviders, createNotificationService, notificationsService, } from "@voyantjs/notifications";
3
- import { createNetopiaClient, resolveNetopiaRuntimeOptions, } from "./client.js";
4
- function centsToAmount(cents) {
5
- return Number((cents / 100).toFixed(2));
6
- }
7
- function amountToCents(amount) {
8
- return Math.round(amount * 100);
9
- }
10
- function normalizeCurrency(currency) {
11
- return currency.trim().toUpperCase();
12
- }
13
- function mergeRecord(base, extra) {
14
- return {
15
- ...(base ?? {}),
16
- ...extra,
17
- };
18
- }
19
- function buildDefaultProducts(session, description) {
20
- return [
21
- {
22
- name: description,
23
- price: centsToAmount(session.amountCents),
24
- vat: 0,
25
- },
26
- ];
27
- }
28
- export function deriveNetopiaOrderId(session) {
29
- return session.externalReference ?? session.clientReference ?? session.id;
30
- }
31
- export function mapNetopiaPaymentStatus(status, options) {
32
- if (options.successStatuses.includes(status))
33
- return "completed";
34
- if (options.processingStatuses.includes(status))
35
- return "processing";
36
- return "failed";
37
- }
38
- function resolveNotificationDispatcher(bindings, runtimeOptions, dispatcherOverride) {
39
- if (dispatcherOverride) {
40
- return dispatcherOverride;
41
- }
42
- return createNotificationService(runtimeOptions.resolveNotificationProviders?.(bindings ?? {}) ??
43
- createDefaultNotificationProviders(bindings ?? {}));
44
- }
45
- export const netopiaService = {
46
- async startPaymentSession(db, sessionId, input, runtimeOptions = {}, clientOverride, bindings) {
47
- const session = await financeService.getPaymentSessionById(db, sessionId);
48
- if (!session) {
49
- throw new Error("Payment session not found");
50
- }
51
- if (session.provider && session.provider !== "netopia") {
52
- throw new Error(`Payment session ${sessionId} is already assigned to provider "${session.provider}"`);
53
- }
54
- if (["paid", "authorized", "cancelled", "expired"].includes(session.status)) {
55
- throw new Error(`Payment session ${sessionId} is not startable from status "${session.status}"`);
56
- }
57
- const runtime = resolveNetopiaRuntimeOptions(bindings, runtimeOptions);
58
- const client = clientOverride ??
59
- createNetopiaClient({
60
- apiUrl: runtime.apiUrl,
61
- apiKey: runtime.apiKey,
62
- fetch: runtime.fetch,
63
- });
64
- const description = input.description ?? session.notes ?? `Payment ${session.id}`;
65
- const orderId = deriveNetopiaOrderId(session);
66
- const request = {
67
- config: {
68
- emailTemplate: input.emailTemplate ?? runtime.emailTemplate,
69
- notifyUrl: input.notifyUrl ?? runtime.notifyUrl,
70
- redirectUrl: input.returnUrl ?? runtime.redirectUrl,
71
- language: input.language ?? runtime.language,
72
- },
73
- payment: {
74
- options: input.options ?? { installments: 1 },
75
- instrument: input.instrument,
76
- data: input.browserData,
77
- },
78
- order: {
79
- ntpID: "",
80
- posSignature: runtime.posSignature,
81
- dateTime: new Date().toISOString(),
82
- description,
83
- orderID: orderId,
84
- amount: centsToAmount(session.amountCents),
85
- currency: normalizeCurrency(session.currency),
86
- billing: input.billing,
87
- shipping: input.shipping ?? input.billing,
88
- products: input.products && input.products.length > 0
89
- ? input.products
90
- : buildDefaultProducts(session, description),
91
- installments: input.installments ?? { selected: 1, available: [0] },
92
- data: input.orderData,
93
- },
94
- };
95
- const providerResponse = await client.startCardPayment(request);
96
- const payment = providerResponse.payment;
97
- if (!payment?.paymentURL) {
98
- throw new Error("Netopia start payment succeeded without paymentURL");
99
- }
100
- const updated = await financeService.markPaymentSessionRequiresRedirect(db, session.id, {
101
- provider: "netopia",
102
- providerSessionId: payment.ntpID ?? null,
103
- providerPaymentId: payment.ntpID ?? null,
104
- externalReference: orderId,
105
- redirectUrl: payment.paymentURL,
106
- returnUrl: input.returnUrl ?? runtime.redirectUrl,
107
- cancelUrl: input.cancelUrl ?? null,
108
- callbackUrl: input.callbackUrl ?? input.notifyUrl ?? runtime.notifyUrl,
109
- providerPayload: mergeRecord(session.providerPayload, {
110
- netopiaStartRequest: request,
111
- netopiaStartResponse: providerResponse,
112
- }),
113
- metadata: input.metadata ?? undefined,
114
- notes: input.notes ?? session.notes ?? undefined,
115
- });
116
- if (!updated) {
117
- throw new Error("Payment session disappeared while saving Netopia redirect state");
118
- }
119
- return {
120
- session: updated,
121
- providerResponse,
122
- orderId,
123
- };
124
- },
125
- async collectBookingSchedule(db, scheduleId, input, runtimeOptions = {}, clientOverride, dispatcherOverride, bindings) {
126
- const session = await financeService.createPaymentSessionFromBookingSchedule(db, scheduleId, {
127
- ...(input.paymentSession ?? {}),
128
- provider: "netopia",
129
- });
130
- if (!session) {
131
- throw new Error("Payment schedule not found");
132
- }
133
- const started = await this.startPaymentSession(db, session.id, input.netopia, runtimeOptions, clientOverride, bindings);
134
- const dispatcher = input.notification
135
- ? resolveNotificationDispatcher(bindings, runtimeOptions, dispatcherOverride)
136
- : null;
137
- const paymentSessionNotification = input.notification && dispatcher
138
- ? await notificationsService.sendPaymentSessionNotification(db, dispatcher, started.session.id, input.notification)
139
- : null;
140
- return {
141
- ...started,
142
- paymentSessionNotification,
143
- invoiceNotification: null,
144
- };
145
- },
146
- async collectBookingGuarantee(db, guaranteeId, input, runtimeOptions = {}, clientOverride, dispatcherOverride, bindings) {
147
- const session = await financeService.createPaymentSessionFromBookingGuarantee(db, guaranteeId, {
148
- ...(input.paymentSession ?? {}),
149
- provider: "netopia",
150
- });
151
- if (!session) {
152
- throw new Error("Booking guarantee not found");
153
- }
154
- const started = await this.startPaymentSession(db, session.id, input.netopia, runtimeOptions, clientOverride, bindings);
155
- const dispatcher = input.notification
156
- ? resolveNotificationDispatcher(bindings, runtimeOptions, dispatcherOverride)
157
- : null;
158
- const paymentSessionNotification = input.notification && dispatcher
159
- ? await notificationsService.sendPaymentSessionNotification(db, dispatcher, started.session.id, input.notification)
160
- : null;
161
- return {
162
- ...started,
163
- paymentSessionNotification,
164
- invoiceNotification: null,
165
- };
166
- },
167
- async collectInvoice(db, invoiceId, input, runtimeOptions = {}, clientOverride, dispatcherOverride, bindings) {
168
- const session = await financeService.createPaymentSessionFromInvoice(db, invoiceId, {
169
- ...(input.paymentSession ?? {}),
170
- provider: "netopia",
171
- });
172
- if (!session) {
173
- throw new Error("Invoice not found");
174
- }
175
- const started = await this.startPaymentSession(db, session.id, input.netopia, runtimeOptions, clientOverride, bindings);
176
- const shouldNotify = Boolean(input.paymentSessionNotification || input.invoiceNotification);
177
- const dispatcher = shouldNotify
178
- ? resolveNotificationDispatcher(bindings, runtimeOptions, dispatcherOverride)
179
- : null;
180
- const paymentSessionNotification = input.paymentSessionNotification && dispatcher
181
- ? await notificationsService.sendPaymentSessionNotification(db, dispatcher, started.session.id, input.paymentSessionNotification)
182
- : null;
183
- const invoiceNotification = input.invoiceNotification && dispatcher
184
- ? await notificationsService.sendInvoiceNotification(db, dispatcher, invoiceId, input.invoiceNotification)
185
- : null;
186
- return {
187
- ...started,
188
- paymentSessionNotification,
189
- invoiceNotification,
190
- };
191
- },
192
- async handleCallback(db, payload, runtimeOptions = {}, bindings) {
193
- const runtime = resolveNetopiaRuntimeOptions(bindings, runtimeOptions);
194
- const orderId = payload.order.orderID;
195
- const lookup = await financeService.listPaymentSessions(db, {
196
- provider: "netopia",
197
- externalReference: orderId,
198
- limit: 1,
199
- offset: 0,
200
- });
201
- let session = lookup.data[0] ?? null;
202
- if (!session) {
203
- session = await financeService.getPaymentSessionById(db, orderId);
204
- }
205
- if (!session) {
206
- return {
207
- action: "ignored",
208
- reason: "payment_session_not_found",
209
- session: null,
210
- orderId,
211
- };
212
- }
213
- const callbackState = mapNetopiaPaymentStatus(payload.payment.status, runtime);
214
- const providerPayload = mergeRecord(session.providerPayload, {
215
- netopiaCallback: payload,
216
- });
217
- const normalizedCurrency = normalizeCurrency(payload.payment.currency);
218
- const amountCents = amountToCents(payload.payment.amount);
219
- if (callbackState === "completed" &&
220
- (normalizedCurrency !== normalizeCurrency(session.currency) ||
221
- amountCents !== session.amountCents)) {
222
- const failed = await financeService.failPaymentSession(db, session.id, {
223
- providerSessionId: payload.payment.ntpID,
224
- providerPaymentId: payload.payment.ntpID,
225
- externalReference: orderId,
226
- failureCode: "amount_or_currency_mismatch",
227
- failureMessage: `Expected ${session.amountCents} ${normalizeCurrency(session.currency)}, received ${amountCents} ${normalizedCurrency}`,
228
- providerPayload,
229
- });
230
- return {
231
- action: "failed",
232
- reason: "amount_or_currency_mismatch",
233
- session: failed,
234
- orderId,
235
- };
236
- }
237
- if (callbackState === "processing") {
238
- const updated = await financeService.updatePaymentSession(db, session.id, {
239
- status: "processing",
240
- provider: "netopia",
241
- providerSessionId: payload.payment.ntpID,
242
- providerPaymentId: payload.payment.ntpID,
243
- externalReference: orderId,
244
- providerPayload,
245
- });
246
- return {
247
- action: "processing",
248
- session: updated,
249
- orderId,
250
- };
251
- }
252
- if (callbackState === "completed") {
253
- if (session.status === "paid" || session.status === "authorized") {
254
- const current = await financeService.updatePaymentSession(db, session.id, {
255
- provider: "netopia",
256
- providerSessionId: payload.payment.ntpID,
257
- providerPaymentId: payload.payment.ntpID,
258
- externalReference: orderId,
259
- providerPayload,
260
- });
261
- return {
262
- action: "ignored",
263
- reason: "already_completed",
264
- session: current,
265
- orderId,
266
- };
267
- }
268
- const completed = await financeService.completePaymentSession(db, session.id, {
269
- status: "paid",
270
- captureMode: "manual",
271
- paymentMethod: "credit_card",
272
- providerSessionId: payload.payment.ntpID,
273
- providerPaymentId: payload.payment.ntpID,
274
- externalReference: orderId,
275
- externalAuthorizationId: typeof payload.payment.data?.AuthCode === "string"
276
- ? payload.payment.data.AuthCode
277
- : payload.payment.ntpID,
278
- externalCaptureId: typeof payload.payment.data?.RRN === "string"
279
- ? payload.payment.data.RRN
280
- : payload.payment.ntpID,
281
- approvalCode: typeof payload.payment.data?.AuthCode === "string"
282
- ? payload.payment.data.AuthCode
283
- : undefined,
284
- referenceNumber: typeof payload.payment.data?.RRN === "string" ? payload.payment.data.RRN : undefined,
285
- authorizedAt: new Date().toISOString(),
286
- capturedAt: new Date().toISOString(),
287
- paymentDate: new Date().toISOString(),
288
- providerPayload,
289
- });
290
- return {
291
- action: "completed",
292
- session: completed,
293
- orderId,
294
- };
295
- }
296
- const failed = await financeService.failPaymentSession(db, session.id, {
297
- providerSessionId: payload.payment.ntpID,
298
- providerPaymentId: payload.payment.ntpID,
299
- externalReference: orderId,
300
- failureCode: typeof payload.payment.code === "string" && payload.payment.code.length > 0
301
- ? payload.payment.code
302
- : `netopia_status_${payload.payment.status}`,
303
- failureMessage: typeof payload.payment.message === "string" && payload.payment.message.length > 0
304
- ? payload.payment.message
305
- : "Netopia payment was not approved",
306
- providerPayload,
307
- });
308
- return {
309
- action: "failed",
310
- session: failed,
311
- orderId,
312
- };
313
- },
314
- };
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAEnE,MAAM,MAAM,YAAY,GAAG,CACzB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE;IACJ,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,KACE,OAAO,CAAC;IACX,EAAE,EAAE,OAAO,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;IAC5B,IAAI,E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AAA;AAEF,eAAO,MAAM,8BAA8B;;;;;;;iBAOzC,CAAA;AAEF,eAAO,MAAM,wBAAwB,sDAA8C,CAAA;AAEnF,eAAO,MAAM,gCAAgC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkB3C,CAAA;AAEF,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;iBA4BtC,CAAA;AAEF,eAAO,MAAM,mCAAmC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAI9C,CAAA;AAEF,eAAO,MAAM,oCAAoC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAI/C,CAAA;AAEF,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAKtC,CAAA"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=client.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.test.d.ts","sourceRoot":"","sources":["../../../tests/unit/client.test.ts"],"names":[],"mappings":""}