@ariary/ariary 2.0.7 → 2.0.8

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 CHANGED
@@ -1,56 +1,93 @@
1
- # Ariari SDK
1
+ # Ariari
2
2
 
3
- SDK officiel pour l'API de paiement Ariari. Permet d'envoyer des paiements, des SMS et des transferts d'argent.
3
+ Complete SDK for managing payments and notifications with Ariari.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install @ariary/ariary
8
+ npm install ariari-ariari
9
9
  ```
10
10
 
11
11
  ## Configuration
12
12
 
13
13
  ```typescript
14
- import { Ariari } from '@ariary/ariary';
14
+ import Ariari from 'ariari-ariari';
15
15
 
16
16
  Ariari.config({
17
- secretId: 'votre_secret_id',
18
- projectId: 'votre_project_id'
17
+ projectId: 'your-project-id',
18
+ secretId: 'your-secret-id'
19
19
  });
20
20
  ```
21
21
 
22
- ## Utilisation
22
+ ## Notification
23
+
24
+ ### Send Notification
23
25
 
24
26
  ```typescript
25
- // Pay
26
- const payment = await Ariari.payment.create({ code: 'PAY-123', amount: 5000, projectId: 'your_project_id' });
27
- const payments = await Ariari.payment.getAll();
28
- const paymentById = await Ariari.payment.getById(paymentId);
29
- const updated = await Ariari.payment.updateRest(paymentId, 'TICKET123');
30
- const transfer = await Ariari.payment.transfert({ phone: '261345678901', amount: 5000 });
31
- const transfers = await Ariari.payment.getAllTransfert();
32
-
33
- // Notifications
34
- const sms = await Ariari.notification.send({ phone: '261345678901', message: 'Hello' });
35
- const bulkSms = await Ariari.notification.sendBulk([
36
- { phone: '261345678901', message: 'Message 1' },
37
- { phone: '261345678902', message: 'Message 2' }
38
- ]);
39
- const allSms = await Ariari.notification.getAll();
40
- const tasks = await Ariari.notification.task.findAll('projectId');
41
- const task = await Ariari.notification.task.findOne(taskId);
42
- const updatedTask = await Ariari.notification.task.update(taskId, { message: 'New' });
43
- const deleted = await Ariari.notification.task.delete(taskId);
44
- const smsDetails = await Ariari.notification.task.getSmsDetails(taskId);
45
- const retried = await Ariari.notification.task.retryFailedSms(taskId);
46
- ```
47
-
48
- ## Imports
27
+ const task = await Ariari.send(
28
+ { phone: '+261123456789', message: 'Message 1' },
29
+ { phone: ['+261987654321', '+261555555555'], message: 'Message 2' }
30
+ );
31
+
32
+ // Check task status
33
+ const status = await task.status();
34
+ // Returns TaskSummary: { total: 2, sent: 2, failed: 0, pending: 0 }
35
+
36
+ // Get detailed SMS information
37
+ const details = await task.smsDetails();
38
+ // Returns TaskDetails with notifTaskId, projectId, summary, smsDetails array, and createdAt
39
+ ```
40
+
41
+
42
+ ### List Tasks
43
+
44
+ ```typescript
45
+ const result = await Ariari.tasks({
46
+ from: 0,
47
+ count: 20,
48
+ order: -1
49
+ });
50
+
51
+ const nextResult = await Ariari.tasks(result.next);
52
+ ...
53
+ const prevResult = await Ariari.tasks(result.prev);
54
+ ```
55
+
56
+ ## Payment
57
+
49
58
 
50
59
  ```typescript
51
- import { Ariari } from '@ariary/ariary';
60
+ const payment = await Ariari.payment.create({
61
+ code: 'PAY-123',
62
+ amount: 5000,
63
+ projectId: 'your-project-id'
64
+ });
65
+
66
+ // Get payment details
67
+ await payment.get();
68
+
69
+ // Update payment
70
+ await payment.updateRest('TICKET123');
71
+ ```
72
+
73
+ ### Get All Payments
74
+
75
+ ```typescript
76
+ const payments = await Ariari.payment.getAll();
52
77
  ```
53
78
 
54
- ## License
79
+ ### Get Payment by ID
55
80
 
56
- ISC
81
+ ```typescript
82
+ const payment = Ariari.payment.getById('payment-id-123');
83
+ await payment.get();
84
+ await payment.updateRest('TICKET123');
85
+ ```
86
+ ```typescript
87
+ const payment = await Ariari.payment({
88
+ phone: '261345678901',
89
+ amount: 5000
90
+ });
91
+
92
+ const payments = await Ariari.payment.getPayments();
93
+ ```
package/dist/index.d.mts CHANGED
@@ -1,195 +1,88 @@
1
- interface CreateSmsDto {
2
- message: string;
3
- phone: string;
4
- }
5
- interface SendSmsDto {
6
- message: string;
7
- phones: string[];
8
- }
9
- interface BulkSmsDto {
10
- messages: {
11
- phones: string[];
12
- message: string;
13
- }[];
14
- }
15
- interface SendSmsResponseDto {
16
- id: string;
17
- message: string;
18
- phone: string;
19
- status: string;
20
- createdAt: string;
21
- }
22
- interface ResponseSmsDto {
23
- id: string;
1
+ type Config = {
2
+ projectId: string;
3
+ secretId: string;
4
+ };
5
+ type Message = {
6
+ phone: string[] | string;
24
7
  message: string;
25
- phone: string;
26
- status: string;
27
- createdAt: string;
28
- updatedAt: string;
29
- }
30
- interface MultiSmsResponseDto {
31
- status: string;
32
- data: {
33
- id: string;
34
- message: string;
8
+ };
9
+ type GetTaskParam = {
10
+ from?: number;
11
+ count?: number;
12
+ order?: -1 | 1;
13
+ };
14
+ type TaskSummary = {
15
+ total: number;
16
+ sent: number;
17
+ failed: number;
18
+ pending: number;
19
+ };
20
+ type TaskDetails = {
21
+ notifTaskId: string;
22
+ projectId: string;
23
+ summary: TaskSummary;
24
+ smsDetails: Array<{
25
+ smsId: string;
35
26
  phone: string;
36
- status: string;
37
- }[];
38
- }
39
- interface BulkSmsResponseDto {
40
- status: string;
41
- data: {
42
- id: string;
43
27
  message: string;
44
- phone: string;
45
- status: string;
46
- }[];
47
- }
48
- interface CreateNotifTaskDto {
49
- message: string;
50
- phones: string[];
51
- }
52
- interface UpdateNotifTaskDto {
53
- message?: string;
54
- phones?: string[];
55
- }
56
- interface ResponseNotifTaskDto {
57
- id: string;
58
- message: string;
59
- phones: string[];
60
- status: string;
61
- createdAt: string;
62
- updatedAt: string;
63
- }
64
- interface SmsDetail {
65
- id: string;
66
- phone: string;
67
- message: string;
68
- status: string;
69
- attempts: number;
70
- lastAttempt?: string;
71
- createdAt: string;
72
- updatedAt: string;
73
- }
74
- interface NotifTaskDetailsDto {
75
- id: string;
76
- message: string;
77
- status: string;
78
- totalSms: number;
79
- successCount: number;
80
- failedCount: number;
81
- pendingCount: number;
82
- smsDetails: SmsDetail[];
28
+ status: 'PENDING' | 'SENT' | 'FAILED';
29
+ retryCount: number;
30
+ }>;
83
31
  createdAt: string;
84
- updatedAt: string;
85
- }
86
- interface RetryFailedSmsResponseDto {
87
- status: string;
88
- message: string;
89
- retried?: number;
90
- }
91
-
92
- interface SmsApi {
93
- send(data: {
94
- phone: string | string[];
95
- message: string;
96
- }): Promise<MultiSmsResponseDto>;
97
- sendBulk(messages: {
98
- phone: string | string[];
99
- message: string;
100
- }[]): Promise<BulkSmsResponseDto>;
101
- getAll(): Promise<ResponseSmsDto[]>;
102
- }
103
- interface NotifTaskApi {
104
- findAll(projectId: string): Promise<ResponseNotifTaskDto[]>;
105
- findOne(id: string): Promise<ResponseNotifTaskDto>;
106
- update(id: string, data: UpdateNotifTaskDto): Promise<ResponseNotifTaskDto>;
107
- delete(id: string): Promise<ResponseNotifTaskDto>;
108
- getSmsDetails(id: string): Promise<NotifTaskDetailsDto>;
109
- retryFailedSms(id: string): Promise<RetryFailedSmsResponseDto>;
110
- }
111
- interface NotificationService extends SmsApi {
112
- task: NotifTaskApi;
113
- }
114
-
115
- interface CreatePaymentDto {
32
+ };
33
+ type CreatePaymentParam = {
116
34
  code: string;
117
35
  amount: number;
118
36
  projectId: string;
119
- }
120
- interface PaymentResponseDto {
37
+ };
38
+ type PaymentResponse = {
121
39
  id: string;
122
- transactionId: string;
40
+ code: string;
123
41
  amount: number;
124
- rest: number;
125
42
  projectId: string;
126
- status: string;
127
- parts: Array<{
128
- id: string;
129
- amount: number;
130
- transactionId: string;
131
- date: string;
132
- }>;
133
- createdAt: string;
134
- updatedAt: string;
135
- }
136
- interface SendTransactionDto {
43
+ };
44
+ type PaymentParam = {
137
45
  phone: string;
138
46
  amount: number;
139
- }
140
- interface SendTransactionResponse {
47
+ };
48
+
49
+ declare class Task {
141
50
  id: string;
142
- phone: string;
143
- amount: number;
144
- status: string;
145
- message: string;
146
- requestId: string;
147
- projectId: string;
148
- secretId: string;
149
- createdAt: string;
51
+ constructor(id: string);
52
+ status(): Promise<TaskSummary>;
53
+ smsDetails(): Promise<TaskDetails>;
150
54
  }
151
- interface TransactionResponseDto {
55
+ declare class Payment {
152
56
  id: string;
153
- phone: string;
154
- amount: number;
155
- rest?: number;
156
- status: string;
157
- ticketCode: string;
158
- createdAt: string;
159
- updatedAt: string;
160
- }
161
-
162
- interface PaymentService {
163
- create(data: CreatePaymentDto): Promise<PaymentResponseDto>;
164
- getAll(): Promise<PaymentResponseDto[]>;
165
- getById(id: string): Promise<PaymentResponseDto>;
166
- updateRest(paymentId: string, ticketCode: string): Promise<PaymentResponseDto>;
167
- transfert(data: {
168
- phone: string;
57
+ constructor(id: string);
58
+ get: () => Promise<unknown>;
59
+ updateRest: (ticketCode: string) => Promise<unknown>;
60
+ }
61
+ declare class Ariari {
62
+ send(...data: Message[]): Promise<Task>;
63
+ tasks(param: GetTaskParam): Promise<unknown>;
64
+ createPayment(data: {
65
+ code: string;
169
66
  amount: number;
170
- }): Promise<SendTransactionResponse>;
171
- getAllTransfert(): Promise<SendTransactionResponse[]>;
172
- }
173
-
174
- interface AriariConfig {
175
- secretId: string;
176
- projectId: string;
177
- baseUrl?: string;
178
- }
179
- declare const Ariari: {
180
- /**
181
- * Configure the SDK with your API credentials
182
- * @param cfg Configuration object with secretId and projectId
183
- */
184
- config(cfg: AriariConfig): void;
185
- payment: PaymentService;
186
- notification: NotificationService;
187
- };
188
-
189
- interface ApiResponse<T> {
190
- status: string;
191
- data?: T;
192
- message?: string;
67
+ projectId: string;
68
+ }): Promise<Payment>;
69
+ getAllPayments: () => Promise<unknown>;
70
+ payment: {
71
+ create: (data: {
72
+ code: string;
73
+ amount: number;
74
+ projectId: string;
75
+ }) => Promise<Payment>;
76
+ getAll: () => Promise<unknown>;
77
+ getById: (id: string) => Payment;
78
+ payment: (data: {
79
+ phone: string;
80
+ amount: number;
81
+ }) => Promise<unknown>;
82
+ getPayments: () => Promise<unknown>;
83
+ };
84
+ Task: typeof Task;
85
+ Payment: typeof Payment;
193
86
  }
194
87
 
195
- export { type ApiResponse, Ariari, type BulkSmsDto, type BulkSmsResponseDto, type CreateNotifTaskDto, type CreatePaymentDto, type CreateSmsDto, type MultiSmsResponseDto, type NotifTaskDetailsDto, type PaymentResponseDto, type ResponseNotifTaskDto, type ResponseSmsDto, type RetryFailedSmsResponseDto, type SendSmsDto, type SendSmsResponseDto, type SendTransactionDto, type SendTransactionResponse, type SmsDetail, type TransactionResponseDto, type UpdateNotifTaskDto };
88
+ export { Ariari, type Config, type CreatePaymentParam, type GetTaskParam, type Message, Payment, type PaymentParam, type PaymentResponse, Task, type TaskDetails, type TaskSummary };
package/dist/index.d.ts CHANGED
@@ -1,195 +1,88 @@
1
- interface CreateSmsDto {
2
- message: string;
3
- phone: string;
4
- }
5
- interface SendSmsDto {
6
- message: string;
7
- phones: string[];
8
- }
9
- interface BulkSmsDto {
10
- messages: {
11
- phones: string[];
12
- message: string;
13
- }[];
14
- }
15
- interface SendSmsResponseDto {
16
- id: string;
17
- message: string;
18
- phone: string;
19
- status: string;
20
- createdAt: string;
21
- }
22
- interface ResponseSmsDto {
23
- id: string;
1
+ type Config = {
2
+ projectId: string;
3
+ secretId: string;
4
+ };
5
+ type Message = {
6
+ phone: string[] | string;
24
7
  message: string;
25
- phone: string;
26
- status: string;
27
- createdAt: string;
28
- updatedAt: string;
29
- }
30
- interface MultiSmsResponseDto {
31
- status: string;
32
- data: {
33
- id: string;
34
- message: string;
8
+ };
9
+ type GetTaskParam = {
10
+ from?: number;
11
+ count?: number;
12
+ order?: -1 | 1;
13
+ };
14
+ type TaskSummary = {
15
+ total: number;
16
+ sent: number;
17
+ failed: number;
18
+ pending: number;
19
+ };
20
+ type TaskDetails = {
21
+ notifTaskId: string;
22
+ projectId: string;
23
+ summary: TaskSummary;
24
+ smsDetails: Array<{
25
+ smsId: string;
35
26
  phone: string;
36
- status: string;
37
- }[];
38
- }
39
- interface BulkSmsResponseDto {
40
- status: string;
41
- data: {
42
- id: string;
43
27
  message: string;
44
- phone: string;
45
- status: string;
46
- }[];
47
- }
48
- interface CreateNotifTaskDto {
49
- message: string;
50
- phones: string[];
51
- }
52
- interface UpdateNotifTaskDto {
53
- message?: string;
54
- phones?: string[];
55
- }
56
- interface ResponseNotifTaskDto {
57
- id: string;
58
- message: string;
59
- phones: string[];
60
- status: string;
61
- createdAt: string;
62
- updatedAt: string;
63
- }
64
- interface SmsDetail {
65
- id: string;
66
- phone: string;
67
- message: string;
68
- status: string;
69
- attempts: number;
70
- lastAttempt?: string;
71
- createdAt: string;
72
- updatedAt: string;
73
- }
74
- interface NotifTaskDetailsDto {
75
- id: string;
76
- message: string;
77
- status: string;
78
- totalSms: number;
79
- successCount: number;
80
- failedCount: number;
81
- pendingCount: number;
82
- smsDetails: SmsDetail[];
28
+ status: 'PENDING' | 'SENT' | 'FAILED';
29
+ retryCount: number;
30
+ }>;
83
31
  createdAt: string;
84
- updatedAt: string;
85
- }
86
- interface RetryFailedSmsResponseDto {
87
- status: string;
88
- message: string;
89
- retried?: number;
90
- }
91
-
92
- interface SmsApi {
93
- send(data: {
94
- phone: string | string[];
95
- message: string;
96
- }): Promise<MultiSmsResponseDto>;
97
- sendBulk(messages: {
98
- phone: string | string[];
99
- message: string;
100
- }[]): Promise<BulkSmsResponseDto>;
101
- getAll(): Promise<ResponseSmsDto[]>;
102
- }
103
- interface NotifTaskApi {
104
- findAll(projectId: string): Promise<ResponseNotifTaskDto[]>;
105
- findOne(id: string): Promise<ResponseNotifTaskDto>;
106
- update(id: string, data: UpdateNotifTaskDto): Promise<ResponseNotifTaskDto>;
107
- delete(id: string): Promise<ResponseNotifTaskDto>;
108
- getSmsDetails(id: string): Promise<NotifTaskDetailsDto>;
109
- retryFailedSms(id: string): Promise<RetryFailedSmsResponseDto>;
110
- }
111
- interface NotificationService extends SmsApi {
112
- task: NotifTaskApi;
113
- }
114
-
115
- interface CreatePaymentDto {
32
+ };
33
+ type CreatePaymentParam = {
116
34
  code: string;
117
35
  amount: number;
118
36
  projectId: string;
119
- }
120
- interface PaymentResponseDto {
37
+ };
38
+ type PaymentResponse = {
121
39
  id: string;
122
- transactionId: string;
40
+ code: string;
123
41
  amount: number;
124
- rest: number;
125
42
  projectId: string;
126
- status: string;
127
- parts: Array<{
128
- id: string;
129
- amount: number;
130
- transactionId: string;
131
- date: string;
132
- }>;
133
- createdAt: string;
134
- updatedAt: string;
135
- }
136
- interface SendTransactionDto {
43
+ };
44
+ type PaymentParam = {
137
45
  phone: string;
138
46
  amount: number;
139
- }
140
- interface SendTransactionResponse {
47
+ };
48
+
49
+ declare class Task {
141
50
  id: string;
142
- phone: string;
143
- amount: number;
144
- status: string;
145
- message: string;
146
- requestId: string;
147
- projectId: string;
148
- secretId: string;
149
- createdAt: string;
51
+ constructor(id: string);
52
+ status(): Promise<TaskSummary>;
53
+ smsDetails(): Promise<TaskDetails>;
150
54
  }
151
- interface TransactionResponseDto {
55
+ declare class Payment {
152
56
  id: string;
153
- phone: string;
154
- amount: number;
155
- rest?: number;
156
- status: string;
157
- ticketCode: string;
158
- createdAt: string;
159
- updatedAt: string;
160
- }
161
-
162
- interface PaymentService {
163
- create(data: CreatePaymentDto): Promise<PaymentResponseDto>;
164
- getAll(): Promise<PaymentResponseDto[]>;
165
- getById(id: string): Promise<PaymentResponseDto>;
166
- updateRest(paymentId: string, ticketCode: string): Promise<PaymentResponseDto>;
167
- transfert(data: {
168
- phone: string;
57
+ constructor(id: string);
58
+ get: () => Promise<unknown>;
59
+ updateRest: (ticketCode: string) => Promise<unknown>;
60
+ }
61
+ declare class Ariari {
62
+ send(...data: Message[]): Promise<Task>;
63
+ tasks(param: GetTaskParam): Promise<unknown>;
64
+ createPayment(data: {
65
+ code: string;
169
66
  amount: number;
170
- }): Promise<SendTransactionResponse>;
171
- getAllTransfert(): Promise<SendTransactionResponse[]>;
172
- }
173
-
174
- interface AriariConfig {
175
- secretId: string;
176
- projectId: string;
177
- baseUrl?: string;
178
- }
179
- declare const Ariari: {
180
- /**
181
- * Configure the SDK with your API credentials
182
- * @param cfg Configuration object with secretId and projectId
183
- */
184
- config(cfg: AriariConfig): void;
185
- payment: PaymentService;
186
- notification: NotificationService;
187
- };
188
-
189
- interface ApiResponse<T> {
190
- status: string;
191
- data?: T;
192
- message?: string;
67
+ projectId: string;
68
+ }): Promise<Payment>;
69
+ getAllPayments: () => Promise<unknown>;
70
+ payment: {
71
+ create: (data: {
72
+ code: string;
73
+ amount: number;
74
+ projectId: string;
75
+ }) => Promise<Payment>;
76
+ getAll: () => Promise<unknown>;
77
+ getById: (id: string) => Payment;
78
+ payment: (data: {
79
+ phone: string;
80
+ amount: number;
81
+ }) => Promise<unknown>;
82
+ getPayments: () => Promise<unknown>;
83
+ };
84
+ Task: typeof Task;
85
+ Payment: typeof Payment;
193
86
  }
194
87
 
195
- export { type ApiResponse, Ariari, type BulkSmsDto, type BulkSmsResponseDto, type CreateNotifTaskDto, type CreatePaymentDto, type CreateSmsDto, type MultiSmsResponseDto, type NotifTaskDetailsDto, type PaymentResponseDto, type ResponseNotifTaskDto, type ResponseSmsDto, type RetryFailedSmsResponseDto, type SendSmsDto, type SendSmsResponseDto, type SendTransactionDto, type SendTransactionResponse, type SmsDetail, type TransactionResponseDto, type UpdateNotifTaskDto };
88
+ export { Ariari, type Config, type CreatePaymentParam, type GetTaskParam, type Message, Payment, type PaymentParam, type PaymentResponse, Task, type TaskDetails, type TaskSummary };
package/dist/index.js CHANGED
@@ -20,155 +20,130 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
- Ariari: () => Ariari
23
+ Ariari: () => Ariari,
24
+ Payment: () => Payment,
25
+ Task: () => Task
24
26
  });
25
27
  module.exports = __toCommonJS(src_exports);
26
28
 
27
- // src/http.ts
28
- async function request(method, endpoint, body) {
29
+ // src/config/index.ts
30
+ var config = null;
31
+ function getConfig() {
32
+ return config;
33
+ }
34
+
35
+ // src/http/index.ts
36
+ async function request(method, endpoint, options = {}) {
29
37
  const config2 = getConfig();
38
+ if (!config2) {
39
+ throw new Error("Ariari not configured. Call Ariari.config() first.");
40
+ }
30
41
  const baseUrl = config2.baseUrl || "https://back.ariari.mg";
31
42
  const url = `${baseUrl}${endpoint}`;
32
- const response = await fetch(url, {
43
+ const headers = {
44
+ "Content-Type": "application/json",
45
+ "x-project-id": config2.projectId
46
+ };
47
+ if (options.requiresSecret !== false) {
48
+ headers["x-secret-id"] = config2.secretId;
49
+ }
50
+ const fetchOptions = {
33
51
  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;
44
- try {
45
- message = JSON.parse(text).message || message;
46
- } catch (e) {
52
+ headers
53
+ };
54
+ if (options.body && (method === "POST" || method === "PATCH" || method === "PUT")) {
55
+ fetchOptions.body = JSON.stringify(options.body);
56
+ }
57
+ try {
58
+ const response = await fetch(url, fetchOptions);
59
+ const data = await response.json();
60
+ if (!response.ok) {
61
+ const message = data?.message || "Unknown error";
62
+ throw new Error(`[${response.status}] ${message}`);
47
63
  }
48
- throw new Error(`[${response.status}] ${message}`);
64
+ return data;
65
+ } catch (error) {
66
+ if (error instanceof Error) {
67
+ throw error;
68
+ }
69
+ throw new Error("Network error");
49
70
  }
50
- return response.json();
51
- }
52
- async function httpGet(endpoint) {
53
- return request("GET", endpoint);
54
71
  }
55
- async function httpPost(endpoint, body) {
56
- return request("POST", endpoint, body);
72
+ async function httpGet(endpoint, requiresSecret = true) {
73
+ return request("GET", endpoint, { requiresSecret });
57
74
  }
58
- async function httpPatch(endpoint, body) {
59
- return request("PATCH", endpoint, body);
75
+ async function httpPost(endpoint, body, requiresSecret = true) {
76
+ return request("POST", endpoint, { body, requiresSecret });
60
77
  }
61
- async function httpPut(endpoint, body) {
62
- return request("PUT", endpoint, body);
63
- }
64
- async function httpDelete(endpoint) {
65
- return request("DELETE", endpoint);
78
+ async function httpPut(endpoint, body, requiresSecret = true) {
79
+ return request("PUT", endpoint, { body, requiresSecret });
66
80
  }
67
81
 
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");
82
+ // src/types/index.ts
83
+ function normalizePhoneNumber(phone) {
84
+ let normalized = phone.replace(/\D/g, "");
85
+ if (normalized.startsWith("261")) {
86
+ normalized = "0" + normalized.slice(3);
89
87
  }
90
- };
91
-
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) {
102
- const bulkMessages = messages.map((item) => ({
103
- message: item.message,
104
- phones: Array.isArray(item.phone) ? item.phone : [item.phone]
105
- }));
106
- return httpPost("/api/sms/bulk", {
107
- messages: bulkMessages
108
- });
109
- },
110
- async getAll() {
111
- return httpGet("/api/sms");
88
+ return normalized;
89
+ }
90
+ var Task = class {
91
+ constructor(id) {
92
+ this.id = id;
112
93
  }
113
- };
114
- var notifTaskApi = {
115
- async findAll(projectId) {
116
- return httpGet(`/api/notif-task?projectId=${projectId}`);
117
- },
118
- async findOne(id) {
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
- },
127
- async getSmsDetails(id) {
128
- return httpGet(`/api/notif-task/${id}/sms-details`);
129
- },
130
- async retryFailedSms(id) {
131
- return httpPost(
132
- `/api/notif-task/${id}/retry-failed-sms`,
133
- {}
134
- );
94
+ async status() {
95
+ const response = await httpGet(`/api/notif-task/${this.id}/sms-details`);
96
+ return response.summary;
97
+ }
98
+ async smsDetails() {
99
+ return httpGet(`/api/notif-task/${this.id}/sms-details`);
135
100
  }
136
101
  };
137
- var notificationService = {
138
- ...smsApi,
139
- task: notifTaskApi
102
+ var Payment = class {
103
+ constructor(id) {
104
+ this.get = () => httpGet(`/api/payments/${this.id}`);
105
+ this.updateRest = (ticketCode) => httpPut(`/api/payments/${this.id}/rest`, { ticketCode });
106
+ this.id = id;
107
+ }
140
108
  };
141
-
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
- );
109
+ var Ariari = class {
110
+ constructor() {
111
+ this.getAllPayments = () => httpGet("/api/payments");
112
+ this.payment = {
113
+ create: this.createPayment.bind(this),
114
+ getAll: this.getAllPayments.bind(this),
115
+ getById: (id) => new Payment(id),
116
+ payment: (data) => httpPost("/api/send-transaction", data),
117
+ getPayments: () => httpGet("/api/send-transaction")
118
+ };
119
+ this.Task = Task;
120
+ this.Payment = Payment;
149
121
  }
150
- return config;
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");
122
+ async send(...data) {
123
+ const messages = data.map((item) => ({
124
+ phones: (Array.isArray(item.phone) ? item.phone : [item.phone]).map(normalizePhoneNumber),
125
+ message: item.message
126
+ }));
127
+ const response = await httpPost("/api/sms/bulk", { messages });
128
+ if (!response.data || !Array.isArray(response.data) || response.data.length === 0) {
129
+ throw new Error("Invalid response: no SMS IDs returned");
160
130
  }
161
- config = {
162
- secretId: cfg.secretId,
163
- projectId: cfg.projectId,
164
- baseUrl: cfg.baseUrl || "https://back.ariari.mg"
165
- };
166
- },
167
- payment: paymentService,
168
- // Notifications
169
- notification: notificationService
131
+ if (!response.notifTaskId) {
132
+ throw new Error("Invalid response: no notifTaskId returned");
133
+ }
134
+ return new Task(response.notifTaskId);
135
+ }
136
+ async tasks(param) {
137
+ return httpGet(`/api/sms?from=${param.from}&count=${param.count}&order=${param.order}`);
138
+ }
139
+ async createPayment(data) {
140
+ const res = await httpPost("/api/payments", data);
141
+ return new Payment(res.id);
142
+ }
170
143
  };
171
144
  // Annotate the CommonJS export names for ESM import in node:
172
145
  0 && (module.exports = {
173
- Ariari
146
+ Ariari,
147
+ Payment,
148
+ Task
174
149
  });
package/dist/index.mjs CHANGED
@@ -1,147 +1,120 @@
1
- // src/http.ts
2
- async function request(method, endpoint, body) {
1
+ // src/config/index.ts
2
+ var config = null;
3
+ function getConfig() {
4
+ return config;
5
+ }
6
+
7
+ // src/http/index.ts
8
+ async function request(method, endpoint, options = {}) {
3
9
  const config2 = getConfig();
10
+ if (!config2) {
11
+ throw new Error("Ariari not configured. Call Ariari.config() first.");
12
+ }
4
13
  const baseUrl = config2.baseUrl || "https://back.ariari.mg";
5
14
  const url = `${baseUrl}${endpoint}`;
6
- const response = await fetch(url, {
15
+ const headers = {
16
+ "Content-Type": "application/json",
17
+ "x-project-id": config2.projectId
18
+ };
19
+ if (options.requiresSecret !== false) {
20
+ headers["x-secret-id"] = config2.secretId;
21
+ }
22
+ const fetchOptions = {
7
23
  method,
8
- headers: {
9
- "Content-Type": "application/json",
10
- "x-project-id": config2.projectId,
11
- "x-secret-id": config2.secretId
12
- },
13
- body: body ? JSON.stringify(body) : void 0
14
- });
15
- if (!response.ok) {
16
- const text = await response.text();
17
- let message = response.statusText;
18
- try {
19
- message = JSON.parse(text).message || message;
20
- } catch (e) {
24
+ headers
25
+ };
26
+ if (options.body && (method === "POST" || method === "PATCH" || method === "PUT")) {
27
+ fetchOptions.body = JSON.stringify(options.body);
28
+ }
29
+ try {
30
+ const response = await fetch(url, fetchOptions);
31
+ const data = await response.json();
32
+ if (!response.ok) {
33
+ const message = data?.message || "Unknown error";
34
+ throw new Error(`[${response.status}] ${message}`);
21
35
  }
22
- throw new Error(`[${response.status}] ${message}`);
36
+ return data;
37
+ } catch (error) {
38
+ if (error instanceof Error) {
39
+ throw error;
40
+ }
41
+ throw new Error("Network error");
23
42
  }
24
- return response.json();
25
- }
26
- async function httpGet(endpoint) {
27
- return request("GET", endpoint);
28
43
  }
29
- async function httpPost(endpoint, body) {
30
- return request("POST", endpoint, body);
44
+ async function httpGet(endpoint, requiresSecret = true) {
45
+ return request("GET", endpoint, { requiresSecret });
31
46
  }
32
- async function httpPatch(endpoint, body) {
33
- return request("PATCH", endpoint, body);
47
+ async function httpPost(endpoint, body, requiresSecret = true) {
48
+ return request("POST", endpoint, { body, requiresSecret });
34
49
  }
35
- async function httpPut(endpoint, body) {
36
- return request("PUT", endpoint, body);
37
- }
38
- async function httpDelete(endpoint) {
39
- return request("DELETE", endpoint);
50
+ async function httpPut(endpoint, body, requiresSecret = true) {
51
+ return request("PUT", endpoint, { body, requiresSecret });
40
52
  }
41
53
 
42
- // src/payment/service.ts
43
- var paymentService = {
44
- async create(data) {
45
- return httpPost("/api/payments", data);
46
- },
47
- async getAll() {
48
- return httpGet("/api/payments");
49
- },
50
- async getById(id) {
51
- return httpGet(`/api/payments/${id}`);
52
- },
53
- async updateRest(paymentId, ticketCode) {
54
- return httpPut(`/api/payments/${paymentId}/rest`, {
55
- ticketCode
56
- });
57
- },
58
- async transfert(data) {
59
- return httpPost("/api/send-transaction", data);
60
- },
61
- async getAllTransfert() {
62
- return httpGet("/api/send-transaction");
54
+ // src/types/index.ts
55
+ function normalizePhoneNumber(phone) {
56
+ let normalized = phone.replace(/\D/g, "");
57
+ if (normalized.startsWith("261")) {
58
+ normalized = "0" + normalized.slice(3);
63
59
  }
64
- };
65
-
66
- // src/notification/service.ts
67
- var smsApi = {
68
- async send(data) {
69
- const phones = Array.isArray(data.phone) ? data.phone : [data.phone];
70
- return httpPost("/api/sms/multi", {
71
- phones,
72
- message: data.message
73
- });
74
- },
75
- async sendBulk(messages) {
76
- const bulkMessages = messages.map((item) => ({
77
- message: item.message,
78
- phones: Array.isArray(item.phone) ? item.phone : [item.phone]
79
- }));
80
- return httpPost("/api/sms/bulk", {
81
- messages: bulkMessages
82
- });
83
- },
84
- async getAll() {
85
- return httpGet("/api/sms");
60
+ return normalized;
61
+ }
62
+ var Task = class {
63
+ constructor(id) {
64
+ this.id = id;
86
65
  }
87
- };
88
- var notifTaskApi = {
89
- async findAll(projectId) {
90
- return httpGet(`/api/notif-task?projectId=${projectId}`);
91
- },
92
- async findOne(id) {
93
- return httpGet(`/api/notif-task/${id}`);
94
- },
95
- async update(id, data) {
96
- return httpPatch(`/api/notif-task/${id}`, data);
97
- },
98
- async delete(id) {
99
- return httpDelete(`/api/notif-task/${id}`);
100
- },
101
- async getSmsDetails(id) {
102
- return httpGet(`/api/notif-task/${id}/sms-details`);
103
- },
104
- async retryFailedSms(id) {
105
- return httpPost(
106
- `/api/notif-task/${id}/retry-failed-sms`,
107
- {}
108
- );
66
+ async status() {
67
+ const response = await httpGet(`/api/notif-task/${this.id}/sms-details`);
68
+ return response.summary;
69
+ }
70
+ async smsDetails() {
71
+ return httpGet(`/api/notif-task/${this.id}/sms-details`);
109
72
  }
110
73
  };
111
- var notificationService = {
112
- ...smsApi,
113
- task: notifTaskApi
74
+ var Payment = class {
75
+ constructor(id) {
76
+ this.get = () => httpGet(`/api/payments/${this.id}`);
77
+ this.updateRest = (ticketCode) => httpPut(`/api/payments/${this.id}/rest`, { ticketCode });
78
+ this.id = id;
79
+ }
114
80
  };
115
-
116
- // src/ariari.ts
117
- var config = null;
118
- function getConfig() {
119
- if (!config) {
120
- throw new Error(
121
- "Ariari not configured. Call Ariari.config({ secretId, projectId }) first."
122
- );
81
+ var Ariari = class {
82
+ constructor() {
83
+ this.getAllPayments = () => httpGet("/api/payments");
84
+ this.payment = {
85
+ create: this.createPayment.bind(this),
86
+ getAll: this.getAllPayments.bind(this),
87
+ getById: (id) => new Payment(id),
88
+ payment: (data) => httpPost("/api/send-transaction", data),
89
+ getPayments: () => httpGet("/api/send-transaction")
90
+ };
91
+ this.Task = Task;
92
+ this.Payment = Payment;
123
93
  }
124
- return config;
125
- }
126
- var Ariari = {
127
- /**
128
- * Configure the SDK with your API credentials
129
- * @param cfg Configuration object with secretId and projectId
130
- */
131
- config(cfg) {
132
- if (!cfg.secretId || !cfg.projectId) {
133
- throw new Error("secretId and projectId are required");
94
+ async send(...data) {
95
+ const messages = data.map((item) => ({
96
+ phones: (Array.isArray(item.phone) ? item.phone : [item.phone]).map(normalizePhoneNumber),
97
+ message: item.message
98
+ }));
99
+ const response = await httpPost("/api/sms/bulk", { messages });
100
+ if (!response.data || !Array.isArray(response.data) || response.data.length === 0) {
101
+ throw new Error("Invalid response: no SMS IDs returned");
134
102
  }
135
- config = {
136
- secretId: cfg.secretId,
137
- projectId: cfg.projectId,
138
- baseUrl: cfg.baseUrl || "https://back.ariari.mg"
139
- };
140
- },
141
- payment: paymentService,
142
- // Notifications
143
- notification: notificationService
103
+ if (!response.notifTaskId) {
104
+ throw new Error("Invalid response: no notifTaskId returned");
105
+ }
106
+ return new Task(response.notifTaskId);
107
+ }
108
+ async tasks(param) {
109
+ return httpGet(`/api/sms?from=${param.from}&count=${param.count}&order=${param.order}`);
110
+ }
111
+ async createPayment(data) {
112
+ const res = await httpPost("/api/payments", data);
113
+ return new Payment(res.id);
114
+ }
144
115
  };
145
116
  export {
146
- Ariari
117
+ Ariari,
118
+ Payment,
119
+ Task
147
120
  };
package/package.json CHANGED
@@ -1,52 +1,52 @@
1
- {
2
- "name": "@ariary/ariary",
3
- "version": "2.0.7",
4
- "description": "SDK officiel pour l'API de paiement Ariary",
5
- "main": "dist/index.js",
6
- "module": "dist/index.mjs",
7
- "types": "dist/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "types": "./dist/index.d.ts",
11
- "import": "./dist/index.mjs",
12
- "require": "./dist/index.js"
13
- }
14
- },
15
- "files": [
16
- "dist"
17
- ],
18
- "tsup": [
19
- {
20
- "entry": {
21
- "index": "src/index.ts"
22
- },
23
- "format": [
24
- "cjs",
25
- "esm"
26
- ],
27
- "outDir": "dist",
28
- "dts": true,
29
- "splitting": false,
30
- "sourcemap": false,
31
- "clean": true,
32
- "minify": false,
33
- "exclude": ["README.md"]
34
- }
35
- ],
36
- "scripts": {
37
- "build": "tsup",
38
- "test": "echo \"Error: no test specified\" && exit 1"
39
- },
40
- "keywords": [
41
- "ariary",
42
- "pay",
43
- "notifications"
44
- ],
45
- "author": "Ariary",
46
- "license": "ISC",
47
- "dependencies": {},
48
- "devDependencies": {
49
- "tsup": "^8.5.1",
50
- "typescript": "^5.9.3"
51
- }
52
- }
1
+ {
2
+ "name": "@ariary/ariary",
3
+ "version": "2.0.8",
4
+ "description": "SDK officiel pour l'API de paiement Ariary",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "tsup": [
19
+ {
20
+ "entry": {
21
+ "index": "src/index.ts"
22
+ },
23
+ "format": [
24
+ "cjs",
25
+ "esm"
26
+ ],
27
+ "outDir": "dist",
28
+ "dts": true,
29
+ "splitting": false,
30
+ "sourcemap": false,
31
+ "clean": true,
32
+ "minify": false,
33
+ "exclude": ["README.md"]
34
+ }
35
+ ],
36
+ "scripts": {
37
+ "build": "tsup",
38
+ "test": "echo \"Error: no test specified\" && exit 1"
39
+ },
40
+ "keywords": [
41
+ "ariary",
42
+ "pay",
43
+ "notifications"
44
+ ],
45
+ "author": "Ariary",
46
+ "license": "ISC",
47
+ "dependencies": {},
48
+ "devDependencies": {
49
+ "tsup": "^8.5.1",
50
+ "typescript": "^5.9.3"
51
+ }
52
+ }