@ariary/ariary 1.0.8 → 2.0.1
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/README.md +25 -122
- package/dist/index.d.mts +194 -22
- package/dist/index.d.ts +194 -22
- package/dist/index.js +121 -293
- package/dist/index.mjs +120 -276
- package/package.json +3 -29
- package/dist/client-CKv433F4.d.mts +0 -42
- package/dist/client-CKv433F4.d.ts +0 -42
- package/dist/notif-task/index.d.mts +0 -58
- package/dist/notif-task/index.d.ts +0 -58
- package/dist/notif-task/index.js +0 -80
- package/dist/notif-task/index.mjs +0 -53
- package/dist/payment/index.d.mts +0 -54
- package/dist/payment/index.d.ts +0 -54
- package/dist/payment/index.js +0 -86
- package/dist/payment/index.mjs +0 -59
- package/dist/sms/index.d.mts +0 -62
- package/dist/sms/index.d.ts +0 -62
- package/dist/sms/index.js +0 -64
- package/dist/sms/index.mjs +0 -37
- package/dist/transfert/index.d.mts +0 -36
- package/dist/transfert/index.d.ts +0 -36
- package/dist/transfert/index.js +0 -51
- package/dist/transfert/index.mjs +0 -24
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
|
-
|
|
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/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
119
|
-
|
|
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
|
-
|
|
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
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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/
|
|
212
|
-
var
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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.
|
|
104
|
+
phones: Array.isArray(item.phone) ? item.phone : [item.phone]
|
|
229
105
|
}));
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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
|
-
|
|
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
|
-
|
|
275
|
-
|
|
276
|
-
true
|
|
277
|
-
);
|
|
278
|
-
return response;
|
|
279
|
-
}
|
|
116
|
+
return httpGet(`/api/notif-task?projectId=${projectId}`);
|
|
117
|
+
},
|
|
280
118
|
async findOne(id) {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
);
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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
|
-
|
|
304
|
-
|
|
305
|
-
true
|
|
306
|
-
);
|
|
307
|
-
return response;
|
|
308
|
-
}
|
|
128
|
+
return httpGet(`/api/notif-task/${id}/sms-details`);
|
|
129
|
+
},
|
|
309
130
|
async retryFailedSms(id) {
|
|
310
|
-
|
|
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/
|
|
320
|
-
var
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
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
|
-
|
|
339
|
-
AriarySDK,
|
|
340
|
-
NotifTaskService,
|
|
341
|
-
PaymentService,
|
|
342
|
-
SmsService,
|
|
343
|
-
TransferService,
|
|
344
|
-
sendPayment
|
|
172
|
+
Ariari
|
|
345
173
|
});
|