@applite/duticotac-react 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,14 +1,371 @@
1
1
  "use client";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
24
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
+ // If the importer is in node compatibility mode or this is not an ESM
26
+ // file that has been converted to a CommonJS file using a Babel-
27
+ // compatible transform (i.e. "__esModule" has not been set), then set
28
+ // "default" to the CommonJS "module.exports" for node compatibility.
29
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30
+ mod
31
+ ));
32
+
33
+ // ../../node_modules/.pnpm/@applite+duticotac@0.0.3/node_modules/@applite/duticotac/dist/index.js
34
+ var require_dist = __commonJS({
35
+ "../../node_modules/.pnpm/@applite+duticotac@0.0.3/node_modules/@applite/duticotac/dist/index.js"(exports, module) {
36
+ "use strict";
37
+ var __defProp2 = Object.defineProperty;
38
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
39
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
40
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
41
+ var __export2 = (target, all) => {
42
+ for (var name in all)
43
+ __defProp2(target, name, { get: all[name], enumerable: true });
44
+ };
45
+ var __copyProps2 = (to, from, except, desc) => {
46
+ if (from && typeof from === "object" || typeof from === "function") {
47
+ for (let key of __getOwnPropNames2(from))
48
+ if (!__hasOwnProp2.call(to, key) && key !== except)
49
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
50
+ }
51
+ return to;
52
+ };
53
+ var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
54
+ var index_exports2 = {};
55
+ __export2(index_exports2, {
56
+ BalanceModule: () => BalanceModule,
57
+ DuticotacError: () => DuticotacError2,
58
+ DuticotacSDK: () => DuticotacSDK2,
59
+ ERROR_MESSAGES: () => ERROR_MESSAGES,
60
+ HttpClient: () => HttpClient,
61
+ MobileMoneyModule: () => MobileMoneyModule,
62
+ OfferModule: () => OfferModule,
63
+ PaymentMethodModule: () => PaymentMethodModule,
64
+ TransactionModule: () => TransactionModule,
65
+ WebhookModule: () => WebhookModule,
66
+ getErrorMessage: () => getErrorMessage2,
67
+ getProviderLogo: () => getProviderLogo2,
68
+ getProviderName: () => getProviderName2
69
+ });
70
+ module.exports = __toCommonJS(index_exports2);
71
+ var ERROR_MESSAGES = {
72
+ "payment-failed": "\xC9chec du paiement",
73
+ "ref-or-idFromClient-required": "R\xE9f\xE9rence ou IDFromClient requis",
74
+ "product-not-found": "Produit non trouv\xE9",
75
+ "no-api-key": "Cl\xE9 API non fournie",
76
+ "phone-required": "Num\xE9ro de t\xE9l\xE9phone requis",
77
+ "iap-not-available": "Les achats in-app ne sont pas disponibles.",
78
+ "iap-purchase-failed": "Echec de l'achat",
79
+ "otp-required": "Code OTP requis pour les paiements Orange Money",
80
+ "app-not-found": "Application non trouv\xE9e dans AppLite UI",
81
+ "duticotac-setting-not-found": "Configuration Duticotac non trouv\xE9e",
82
+ "payment-method-not-activated": "M\xE9thode de paiement non activ\xE9e",
83
+ "no-provider-found": "M\xE9thode de paiement non activ\xE9e",
84
+ "customer-not-found": "Client non trouv\xE9",
85
+ "invalid-plateform": "Plateforme invalide",
86
+ "unknown-error": "Une erreur inconnue est survenue",
87
+ "reference-required": "R\xE9f\xE9rence requise",
88
+ "polling-timeout": "Temps d'attente de la transaction expir\xE9",
89
+ "payment-cancelled": "Paiement annul\xE9",
90
+ "wait-before-retry": "Veuillez attendre avant de r\xE9essayer",
91
+ "context-not-mounted": "Contexte non mont\xE9",
92
+ "show-modal-bottom-sheet-error": "Erreur lors de l'affichage de la fen\xEAtre modale"
93
+ };
94
+ function getErrorMessage2(code) {
95
+ return ERROR_MESSAGES[code] ?? ERROR_MESSAGES["unknown-error"];
96
+ }
97
+ var DuticotacError2 = class extends Error {
98
+ constructor(code, message) {
99
+ super(message ?? getErrorMessage2(code));
100
+ this.code = code;
101
+ this.name = "DuticotacError";
102
+ }
103
+ };
104
+ var DEFAULT_BASE_URL = "https://api.applite.freddydro.dev";
105
+ var HttpClient = class {
106
+ constructor(config = {}) {
107
+ this.baseUrl = config.baseUrl?.replace(/\/$/, "") ?? DEFAULT_BASE_URL;
108
+ this.headers = config.headers ?? {};
109
+ this.fetchImpl = config.fetchFn ?? fetch;
110
+ this.apiKey = config.apiKey;
111
+ this.appId = config.appId;
112
+ }
113
+ async post(path, body) {
114
+ const mergedBody = {
115
+ ...this.apiKey ? { apiKey: this.apiKey } : {},
116
+ ...this.appId !== void 0 ? { appId: this.appId } : {},
117
+ ...body
118
+ };
119
+ const url = `${this.baseUrl}${path}`;
120
+ const response = await this.fetchImpl(url, {
121
+ method: "POST",
122
+ headers: {
123
+ "Content-Type": "application/json",
124
+ ...this.headers
125
+ },
126
+ body: JSON.stringify(mergedBody)
127
+ });
128
+ const contentType = response.headers.get("content-type") ?? "";
129
+ const isJson = contentType.includes("application/json");
130
+ const payload = isJson ? await response.json() : null;
131
+ if (!response.ok) {
132
+ const errorCode = typeof payload?.error === "string" ? payload.error : "unknown-error";
133
+ throw new DuticotacError2(
134
+ errorCode,
135
+ `Request failed with status ${response.status}: ${payload?.error ?? response.statusText}`
136
+ );
137
+ }
138
+ if (!payload || payload.success !== true) {
139
+ const errorCode = typeof payload?.error === "string" ? payload.error : "unknown-error";
140
+ throw new DuticotacError2(errorCode);
141
+ }
142
+ return payload;
143
+ }
144
+ };
145
+ var BalanceModule = class {
146
+ constructor(http) {
147
+ this.http = http;
148
+ }
149
+ balance(params = {}) {
150
+ return this.http.post("/duticotac/balance", params);
151
+ }
152
+ };
153
+ var OfferModule = class {
154
+ constructor(http) {
155
+ this.http = http;
156
+ }
157
+ create(params) {
158
+ return this.http.post("/duticotac/offer/create", params);
159
+ }
160
+ list(params = {}) {
161
+ return this.http.post("/duticotac/offer/list", params);
162
+ }
163
+ get(params) {
164
+ const { ref, ...body } = params;
165
+ return this.http.post(`/duticotac/offer/${ref}`, body);
166
+ }
167
+ update(params) {
168
+ const { ref, ...body } = params;
169
+ return this.http.post(`/duticotac/offer/${ref}/edit`, body);
170
+ }
171
+ delete(params) {
172
+ const { ref, ...body } = params;
173
+ return this.http.post(`/duticotac/offer/${ref}/delete`, body);
174
+ }
175
+ };
176
+ var MobileMoneyModule = class {
177
+ constructor(http) {
178
+ this.http = http;
179
+ }
180
+ cashin(params) {
181
+ return this.http.post(
182
+ "/duticotac/pay/mobile-money/cashin",
183
+ params
184
+ );
185
+ }
186
+ cashout(params) {
187
+ if (params.paymentMethod === "OM_CI" && !params.otp) {
188
+ throw new DuticotacError2("otp-required");
189
+ }
190
+ if (!params.ref && !params.idFromClient) {
191
+ throw new DuticotacError2("ref-or-idFromClient-required");
192
+ }
193
+ return this.http.post(
194
+ "/duticotac/pay/mobile-money/cashout",
195
+ params
196
+ );
197
+ }
198
+ handleCashinWebhook(params) {
199
+ return this.http.post("/duticotac/pay/mobile-money/cashin/webhook", params);
200
+ }
201
+ handleCashoutWebhook(params) {
202
+ return this.http.post(
203
+ "/duticotac/pay/mobile-money/cashout/webhook",
204
+ params
205
+ );
206
+ }
207
+ };
208
+ var PaymentMethodModule = class {
209
+ constructor(http) {
210
+ this.http = http;
211
+ }
212
+ get(params = {}) {
213
+ return this.http.post(
214
+ "/duticotac/payment-method",
215
+ params
216
+ );
217
+ }
218
+ set(params) {
219
+ return this.http.post(
220
+ "/duticotac/payment-method/set",
221
+ params
222
+ );
223
+ }
224
+ };
225
+ var WebhookModule = class {
226
+ constructor(http) {
227
+ this.http = http;
228
+ }
229
+ get(params = {}) {
230
+ return this.http.post("/duticotac/webhook", params);
231
+ }
232
+ set(params) {
233
+ return this.http.post("/duticotac/webhook/set", params);
234
+ }
235
+ };
236
+ function backoff(attempt) {
237
+ switch (attempt) {
238
+ case 1:
239
+ return 1e3;
240
+ case 2:
241
+ return 2e3;
242
+ case 3:
243
+ return 3e3;
244
+ case 4:
245
+ return 5e3;
246
+ default:
247
+ return 8e3;
248
+ }
249
+ }
250
+ function delay(ms) {
251
+ return new Promise((resolve) => setTimeout(resolve, ms));
252
+ }
253
+ var TransactionModule = class {
254
+ constructor(http) {
255
+ this.http = http;
256
+ }
257
+ get(params) {
258
+ return this.http.post(
259
+ "/duticotac/transaction/get",
260
+ params
261
+ );
262
+ }
263
+ async poll(id, options) {
264
+ const intervalMs = options?.intervalMs ?? 2e3;
265
+ const timeoutMs = options?.timeoutMs ?? 9e4;
266
+ const start = Date.now();
267
+ let attempt = 0;
268
+ while (true) {
269
+ attempt++;
270
+ const elapsed = Date.now() - start;
271
+ if (elapsed > timeoutMs) {
272
+ throw new DuticotacError2("polling-timeout");
273
+ }
274
+ if (options?.signal?.aborted) {
275
+ throw new DuticotacError2("payment-cancelled");
276
+ }
277
+ options?.onPoll?.(attempt, elapsed);
278
+ try {
279
+ const result = await this.get({ id });
280
+ const status = result.data?.status;
281
+ if (status === "CONFIRMED") return result;
282
+ if (status === "CANCELLED") throw new DuticotacError2("payment-cancelled");
283
+ if (status === "FAILED")
284
+ throw new DuticotacError2("payment-failed");
285
+ const wait = Math.max(backoff(attempt), intervalMs);
286
+ await delay(wait);
287
+ } catch (e) {
288
+ if (e instanceof DuticotacError2) throw e;
289
+ const wait = Math.max(backoff(attempt), intervalMs);
290
+ await delay(wait);
291
+ }
292
+ }
293
+ }
294
+ };
295
+ function getProviderName2(provider) {
296
+ switch (provider) {
297
+ case "OM_CI":
298
+ return "Orange Money";
299
+ case "MTN_CI":
300
+ return "MTN Momo";
301
+ case "MOOV_CI":
302
+ return "Moov (Flooz)";
303
+ case "WAVE_CI":
304
+ return "Wave";
305
+ case "CREDIT_CARD":
306
+ return "Carte de cr\xE9dit";
307
+ case "CASH":
308
+ return "Esp\xE8ces";
309
+ case "IAP":
310
+ return "Achat Int\xE9gr\xE9";
311
+ }
312
+ }
313
+ function getProviderLogo2(provider) {
314
+ switch (provider) {
315
+ case "OM_CI":
316
+ return "https://payto.freddydro.dev/images/OM.png";
317
+ case "MTN_CI":
318
+ return "https://payto.freddydro.dev/images/MTN.png";
319
+ case "MOOV_CI":
320
+ return "https://payto.freddydro.dev/images/MOOV.png";
321
+ case "WAVE_CI":
322
+ return "https://payto.freddydro.dev/images/WAVE.png";
323
+ case "CREDIT_CARD":
324
+ return "https://payto.freddydro.dev/images/CREDIT_CARD.png";
325
+ case "CASH":
326
+ return "https://payto.freddydro.dev/images/CASH.png";
327
+ case "IAP":
328
+ return "https://payto.freddydro.dev/images/IAP.png";
329
+ }
330
+ }
331
+ var DuticotacSDK2 = class {
332
+ constructor(config = {}) {
333
+ this.http = new HttpClient(config);
334
+ this.balance = new BalanceModule(this.http);
335
+ this.offer = new OfferModule(this.http);
336
+ this.mobileMoney = new MobileMoneyModule(this.http);
337
+ this.paymentMethod = new PaymentMethodModule(this.http);
338
+ this.webhook = new WebhookModule(this.http);
339
+ this.transaction = new TransactionModule(this.http);
340
+ }
341
+ };
342
+ }
343
+ });
344
+
345
+ // src/index.ts
346
+ var index_exports = {};
347
+ __export(index_exports, {
348
+ DuticotacPaymentModal: () => DuticotacPaymentModal,
349
+ OtpInput: () => OtpInput,
350
+ PhoneInput: () => PhoneInput,
351
+ ProviderSelector: () => ProviderSelector,
352
+ ResponsiveDialog: () => ResponsiveDialog,
353
+ TransactionStatus: () => TransactionStatus,
354
+ cn: () => cn,
355
+ formatCFA: () => formatCFA,
356
+ getPhoneRegex: () => getPhoneRegex,
357
+ needsOtp: () => needsOtp,
358
+ normalizePhone: () => normalizePhone,
359
+ useDuticotac: () => useDuticotac,
360
+ validatePhone: () => validatePhone
361
+ });
2
362
 
3
363
  // src/components/payment-modal.tsx
364
+ var import_duticotac2 = __toESM(require_dist());
4
365
  import * as React2 from "react";
5
- import {
6
- DuticotacError,
7
- getErrorMessage
8
- } from "@applite/duticotac";
9
366
 
10
367
  // src/components/provider-selector.tsx
11
- import { getProviderName, getProviderLogo } from "@applite/duticotac";
368
+ var import_duticotac = __toESM(require_dist());
12
369
 
13
370
  // src/utils/cn.ts
14
371
  import { clsx } from "clsx";
@@ -55,8 +412,8 @@ function ProviderSelector({
55
412
  /* @__PURE__ */ jsx(
56
413
  "img",
57
414
  {
58
- src: getProviderLogo(provider),
59
- alt: getProviderName(provider),
415
+ src: (0, import_duticotac.getProviderLogo)(provider),
416
+ alt: (0, import_duticotac.getProviderName)(provider),
60
417
  width: 44,
61
418
  height: 44,
62
419
  className: "rounded-lg object-contain"
@@ -69,7 +426,7 @@ function ProviderSelector({
69
426
  "text-center text-xs leading-tight",
70
427
  selected ? "font-semibold text-primary" : "font-medium text-muted-foreground"
71
428
  ),
72
- children: getProviderName(provider)
429
+ children: (0, import_duticotac.getProviderName)(provider)
73
430
  }
74
431
  )
75
432
  ]
@@ -516,11 +873,11 @@ function DuticotacPaymentModal({
516
873
  onSuccess?.(confirmed.data);
517
874
  } catch (e) {
518
875
  if (controller.signal.aborted) return;
519
- if (e instanceof DuticotacError) {
876
+ if (e instanceof import_duticotac2.DuticotacError) {
520
877
  setErrorMessage(e.message);
521
878
  } else {
522
879
  setErrorMessage(
523
- getErrorMessage("unknown-error")
880
+ (0, import_duticotac2.getErrorMessage)("unknown-error")
524
881
  );
525
882
  }
526
883
  setStep("error");
@@ -917,6 +1274,9 @@ function useDuticotac(config) {
917
1274
  Dialog: DialogElement
918
1275
  };
919
1276
  }
1277
+
1278
+ // src/index.ts
1279
+ __reExport(index_exports, __toESM(require_dist()));
920
1280
  export {
921
1281
  DuticotacPaymentModal,
922
1282
  OtpInput,