@ariary/ariary 1.0.8 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,329 +15,159 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/index.ts
31
21
  var src_exports = {};
32
22
  __export(src_exports, {
33
- ApiClient: () => ApiClient,
34
- AriarySDK: () => AriarySDK,
35
- NotifTaskService: () => NotifTaskService,
36
- PaymentService: () => PaymentService,
37
- SmsService: () => SmsService,
38
- TransferService: () => TransferService,
39
- sendPayment: () => sendPayment
23
+ Ariari: () => Ariari
40
24
  });
41
25
  module.exports = __toCommonJS(src_exports);
42
26
 
43
- // src/client.ts
44
- var import_axios = __toESM(require("axios"));
45
- var ApiClient = class {
46
- constructor(config, baseUrl) {
47
- this.config = config;
48
- const finalBaseUrl = baseUrl || config.baseUrl || "https://back.ariari.mg/payment/api-docs";
49
- this.client = import_axios.default.create({
50
- baseURL: finalBaseUrl,
51
- headers: {
52
- "Content-Type": "application/json"
53
- }
54
- });
55
- }
56
- /**
57
- * Effectue une requête POST avec les en-têtes d'authentification
58
- */
59
- async post(endpoint, data, requiresSecret = true) {
60
- const headers = {
61
- "x-project-id": this.config.projectId
62
- };
63
- if (requiresSecret) {
64
- headers["x-secret-id"] = this.config.secretId;
65
- }
66
- try {
67
- const response = await this.client.post(endpoint, data, { headers });
68
- return response.data;
69
- } catch (error) {
70
- throw this.handleError(error);
71
- }
72
- }
73
- /**
74
- * Effectue une requête GET avec les en-têtes d'authentification
75
- */
76
- async get(endpoint, requiresSecret = true) {
77
- const headers = {
78
- "x-project-id": this.config.projectId
79
- };
80
- if (requiresSecret) {
81
- headers["x-secret-id"] = this.config.secretId;
82
- }
83
- try {
84
- const response = await this.client.get(endpoint, { headers });
85
- return response.data;
86
- } catch (error) {
87
- throw this.handleError(error);
88
- }
89
- }
90
- /**
91
- * Effectue une requête PATCH avec les en-têtes d'authentification
92
- */
93
- async patch(endpoint, data, requiresSecret = true) {
94
- const headers = {
95
- "x-project-id": this.config.projectId
96
- };
97
- if (requiresSecret) {
98
- headers["x-secret-id"] = this.config.secretId;
99
- }
100
- try {
101
- const response = await this.client.patch(endpoint, data, { headers });
102
- return response.data;
103
- } catch (error) {
104
- throw this.handleError(error);
105
- }
106
- }
107
- /**
108
- * Effectue une requête PUT avec les en-têtes d'authentification
109
- */
110
- async put(endpoint, data, requiresSecret = true) {
111
- const headers = {
112
- "x-project-id": this.config.projectId
113
- };
114
- if (requiresSecret) {
115
- headers["x-secret-id"] = this.config.secretId;
116
- }
27
+ // src/http.ts
28
+ async function request(method, endpoint, body) {
29
+ const config2 = getConfig();
30
+ const baseUrl = config2.baseUrl || "https://back.ariari.mg/payment/api-docs";
31
+ const url = `${baseUrl}${endpoint}`;
32
+ const response = await fetch(url, {
33
+ method,
34
+ headers: {
35
+ "Content-Type": "application/json",
36
+ "x-project-id": config2.projectId,
37
+ "x-secret-id": config2.secretId
38
+ },
39
+ body: body ? JSON.stringify(body) : void 0
40
+ });
41
+ if (!response.ok) {
42
+ const text = await response.text();
43
+ let message = response.statusText;
117
44
  try {
118
- const response = await this.client.put(endpoint, data, { headers });
119
- return response.data;
120
- } catch (error) {
121
- throw this.handleError(error);
122
- }
123
- }
124
- /**
125
- * Effectue une requête DELETE avec les en-têtes d'authentification
126
- */
127
- async delete(endpoint, requiresSecret = true) {
128
- const headers = {
129
- "x-project-id": this.config.projectId
130
- };
131
- if (requiresSecret) {
132
- headers["x-secret-id"] = this.config.secretId;
133
- }
134
- try {
135
- const response = await this.client.delete(endpoint, { headers });
136
- return response.data;
137
- } catch (error) {
138
- throw this.handleError(error);
139
- }
140
- }
141
- /**
142
- * Gère les erreurs API
143
- */
144
- handleError(error) {
145
- if (error.response) {
146
- const status = error.response.status;
147
- const message = error.response.data?.message || error.response.statusText;
148
- return new Error(`[${status}] ${message}`);
45
+ message = JSON.parse(text).message || message;
46
+ } catch (e) {
149
47
  }
150
- return error;
48
+ throw new Error(`[${response.status}] ${message}`);
151
49
  }
152
- };
50
+ return response.json();
51
+ }
52
+ async function httpGet(endpoint) {
53
+ return request("GET", endpoint);
54
+ }
55
+ async function httpPost(endpoint, body) {
56
+ return request("POST", endpoint, body);
57
+ }
58
+ async function httpPatch(endpoint, body) {
59
+ return request("PATCH", endpoint, body);
60
+ }
61
+ async function httpPut(endpoint, body) {
62
+ return request("PUT", endpoint, body);
63
+ }
64
+ async function httpDelete(endpoint) {
65
+ return request("DELETE", endpoint);
66
+ }
153
67
 
154
- // src/payment.ts
155
- var PaymentService = class {
156
- constructor(client) {
157
- this.client = client;
158
- }
159
- /**
160
- * Crée un nouveau paiement
161
- * @param paymentData Les données du paiement
162
- * @returns La réponse de création du paiement
163
- */
164
- async createPayment(paymentData) {
165
- const response = await this.client.post(
166
- "/api/payments",
167
- paymentData,
168
- false
169
- );
170
- return response;
171
- }
172
- /**
173
- * Récupère tous les paiements de l'application
174
- * @returns La liste de tous les paiements
175
- */
176
- async getAllPayments() {
177
- const response = await this.client.get(
178
- "/api/payments",
179
- false
180
- );
181
- return response;
182
- }
183
- /**
184
- * Récupère un paiement par son ID
185
- * @param paymentId L'ID du paiement à récupérer
186
- * @returns Le paiement demandé
187
- */
188
- async getPaymentById(paymentId) {
189
- const response = await this.client.get(
190
- `/api/payments/${paymentId}`,
191
- false
192
- );
193
- return response;
194
- }
195
- /**
196
- * Met à jour le reste d'un paiement avec un code de ticket
197
- * @param paymentId L'ID du paiement à mettre à jour
198
- * @param ticketCode Le code du ticket à associer
199
- * @returns Le paiement mis à jour
200
- */
201
- async updatePaymentRest(paymentId, ticketCode) {
202
- const response = await this.client.put(
203
- `/api/payments/${paymentId}/rest`,
204
- { ticketCode },
205
- false
206
- );
207
- return response;
68
+ // src/payment/service.ts
69
+ var paymentService = {
70
+ async create(data) {
71
+ return httpPost("/api/payments", data);
72
+ },
73
+ async getAll() {
74
+ return httpGet("/api/payments");
75
+ },
76
+ async getById(id) {
77
+ return httpGet(`/api/payments/${id}`);
78
+ },
79
+ async updateRest(paymentId, ticketCode) {
80
+ return httpPut(`/api/payments/${paymentId}/rest`, {
81
+ ticketCode
82
+ });
83
+ },
84
+ async transfert(data) {
85
+ return httpPost("/api/send-transaction", data);
86
+ },
87
+ async getAllTransfert() {
88
+ return httpGet("/api/send-transaction");
208
89
  }
209
90
  };
210
91
 
211
- // src/sms.ts
212
- var SmsService = class {
213
- constructor(client) {
214
- this.client = client;
215
- }
216
- async notify(message, numbers) {
217
- const phones = Array.isArray(numbers) ? numbers : [numbers];
218
- const response = await this.client.post(
219
- "/api/sms/multi",
220
- { phones, message },
221
- true
222
- );
223
- return response;
224
- }
225
- async notifyBulk(messages) {
92
+ // src/notification/service.ts
93
+ var smsApi = {
94
+ async send(data) {
95
+ const phones = Array.isArray(data.phone) ? data.phone : [data.phone];
96
+ return httpPost("/api/sms/multi", {
97
+ phones,
98
+ message: data.message
99
+ });
100
+ },
101
+ async sendBulk(messages) {
226
102
  const bulkMessages = messages.map((item) => ({
227
103
  message: item.message,
228
- phones: Array.isArray(item.numbers) ? item.numbers : [item.numbers]
104
+ phones: Array.isArray(item.phone) ? item.phone : [item.phone]
229
105
  }));
230
- const response = await this.client.post(
231
- "/api/sms/bulk",
232
- { messages: bulkMessages },
233
- true
234
- );
235
- return response;
236
- }
237
- async getAll() {
238
- const response = await this.client.get(
239
- "/api/sms",
240
- true
241
- );
242
- return response;
243
- }
244
- };
245
-
246
- // src/transfert.ts
247
- var TransferService = class {
248
- constructor(client) {
249
- this.client = client;
250
- }
251
- async send(phone, amount) {
252
- const response = await this.client.post(
253
- "/api/send-transaction",
254
- { phone, amount },
255
- true
256
- );
257
- return response;
258
- }
106
+ return httpPost("/api/sms/bulk", {
107
+ messages: bulkMessages
108
+ });
109
+ },
259
110
  async getAll() {
260
- const response = await this.client.get(
261
- "/api/send-transaction",
262
- true
263
- );
264
- return response;
111
+ return httpGet("/api/sms");
265
112
  }
266
113
  };
267
-
268
- // src/notif-task.ts
269
- var NotifTaskService = class {
270
- constructor(client) {
271
- this.client = client;
272
- }
114
+ var notifTaskApi = {
273
115
  async findAll(projectId) {
274
- const response = await this.client.get(
275
- `/api/notif-task?projectId=${projectId}`,
276
- true
277
- );
278
- return response;
279
- }
116
+ return httpGet(`/api/notif-task?projectId=${projectId}`);
117
+ },
280
118
  async findOne(id) {
281
- const response = await this.client.get(
282
- `/api/notif-task/${id}`,
283
- true
284
- );
285
- return response;
286
- }
287
- async update(id, updateNotifTaskDto) {
288
- const response = await this.client.patch(
289
- `/api/notif-task/${id}`,
290
- updateNotifTaskDto,
291
- true
292
- );
293
- return response;
294
- }
295
- async remove(id) {
296
- const response = await this.client.delete(
297
- `/api/notif-task/${id}`,
298
- true
299
- );
300
- return response;
301
- }
119
+ return httpGet(`/api/notif-task/${id}`);
120
+ },
121
+ async update(id, data) {
122
+ return httpPatch(`/api/notif-task/${id}`, data);
123
+ },
124
+ async delete(id) {
125
+ return httpDelete(`/api/notif-task/${id}`);
126
+ },
302
127
  async getSmsDetails(id) {
303
- const response = await this.client.get(
304
- `/api/notif-task/${id}/sms-details`,
305
- true
306
- );
307
- return response;
308
- }
128
+ return httpGet(`/api/notif-task/${id}/sms-details`);
129
+ },
309
130
  async retryFailedSms(id) {
310
- const response = await this.client.post(
131
+ return httpPost(
311
132
  `/api/notif-task/${id}/retry-failed-sms`,
312
- {},
313
- true
133
+ {}
314
134
  );
315
- return response;
316
135
  }
317
136
  };
137
+ var notificationService = {
138
+ ...smsApi,
139
+ task: notifTaskApi
140
+ };
318
141
 
319
- // src/index.ts
320
- var AriarySDK = class {
321
- constructor(config) {
322
- const finalConfig = { ...config, baseUrl: config.baseUrl || "https://back.ariari.mg/payment/api-docs" };
323
- this.paymentClient = new ApiClient(finalConfig);
324
- this.defaultClient = new ApiClient(finalConfig);
325
- this.payment = new PaymentService(this.paymentClient);
326
- this.sms = new SmsService(this.defaultClient);
327
- this.transfer = new TransferService(this.defaultClient);
328
- this.notifTask = new NotifTaskService(this.defaultClient);
142
+ // src/ariari.ts
143
+ var config = null;
144
+ function getConfig() {
145
+ if (!config) {
146
+ throw new Error(
147
+ "Ariari not configured. Call Ariari.config({ secretId, projectId }) first."
148
+ );
329
149
  }
330
- };
331
- async function sendPayment(code, amount, projectId, secretId) {
332
- const sdk = new AriarySDK({ secretId, projectId });
333
- const paymentData = { code, amount, projectId };
334
- return sdk.payment.createPayment(paymentData);
150
+ return config;
335
151
  }
152
+ var Ariari = {
153
+ /**
154
+ * Configure the SDK with your API credentials
155
+ * @param cfg Configuration object with secretId and projectId
156
+ */
157
+ config(cfg) {
158
+ if (!cfg.secretId || !cfg.projectId) {
159
+ throw new Error("secretId and projectId are required");
160
+ }
161
+ config = {
162
+ secretId: cfg.secretId,
163
+ projectId: cfg.projectId,
164
+ baseUrl: cfg.baseUrl || "https://back.ariari.mg/payment/api-docs"
165
+ };
166
+ },
167
+ payment: paymentService,
168
+ notification: notificationService
169
+ };
336
170
  // Annotate the CommonJS export names for ESM import in node:
337
171
  0 && (module.exports = {
338
- ApiClient,
339
- AriarySDK,
340
- NotifTaskService,
341
- PaymentService,
342
- SmsService,
343
- TransferService,
344
- sendPayment
172
+ Ariari
345
173
  });