@ariary/notification 3.0.13 → 4.1.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/README.md CHANGED
@@ -12,7 +12,7 @@ yarn add @ariary/notification
12
12
 
13
13
  1. Sign in at [ariari.mg](https://ariari.mg)
14
14
  2. Create a project
15
- 3. You'll receive a `projectId` and a `secret`
15
+ 3. You'll receive a `secret`
16
16
 
17
17
  ## Setup
18
18
 
@@ -20,7 +20,6 @@ yarn add @ariary/notification
20
20
  import Ariari from '@ariary/notification'
21
21
 
22
22
  Ariari.config({
23
- projectId: 'your-project-id',
24
23
  secret: 'your-secret',
25
24
  })
26
25
  ```
@@ -198,13 +197,11 @@ Use `name` to manage separate Ariari instances with different credentials. `Aria
198
197
  ```ts
199
198
  const marketing = Ariari.config({
200
199
  name: 'marketing',
201
- projectId: 'project-a',
202
200
  secret: 'secret-a',
203
201
  })
204
202
 
205
203
  const alerts = Ariari.config({
206
204
  name: 'alerts',
207
- projectId: 'project-b',
208
205
  secret: 'secret-b',
209
206
  })
210
207
 
package/dist/index.d.mts CHANGED
@@ -1,11 +1,239 @@
1
+ /**
2
+ * API Payment Service - NestJS
3
+ * Système de gestion des paiements - NestJS
4
+ *
5
+ * The version of the OpenAPI document: 1.0
6
+ *
7
+ *
8
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9
+ * https://openapi-generator.tech
10
+ * Do not edit the class manually.
11
+ */
12
+ /**
13
+ *
14
+ * @export
15
+ * @interface EstimateMessage
16
+ */
17
+ interface EstimateMessage$1 {
18
+ /**
19
+ * SMS text content
20
+ * @type {string}
21
+ * @memberof EstimateMessage
22
+ */
23
+ text: string;
24
+ /**
25
+ * Number of recipients (default 1)
26
+ * @type {number}
27
+ * @memberof EstimateMessage
28
+ */
29
+ repeat?: number;
30
+ }
31
+
32
+ /**
33
+ * API Payment Service - NestJS
34
+ * Système de gestion des paiements - NestJS
35
+ *
36
+ * The version of the OpenAPI document: 1.0
37
+ *
38
+ *
39
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
40
+ * https://openapi-generator.tech
41
+ * Do not edit the class manually.
42
+ */
43
+ /**
44
+ *
45
+ * @export
46
+ * @interface EstimateSmsResponse
47
+ */
48
+ interface EstimateSmsResponse {
49
+ /**
50
+ * Total SMS count
51
+ * @type {number}
52
+ * @memberof EstimateSmsResponse
53
+ */
54
+ sms: number;
55
+ /**
56
+ * Total credit consumption
57
+ * @type {number}
58
+ * @memberof EstimateSmsResponse
59
+ */
60
+ credit: number;
61
+ }
62
+
63
+ /**
64
+ * API Payment Service - NestJS
65
+ * Système de gestion des paiements - NestJS
66
+ *
67
+ * The version of the OpenAPI document: 1.0
68
+ *
69
+ *
70
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
71
+ * https://openapi-generator.tech
72
+ * Do not edit the class manually.
73
+ */
74
+ /**
75
+ *
76
+ * @export
77
+ * @interface NotifTaskStatus
78
+ */
79
+ interface NotifTaskStatus {
80
+ /**
81
+ * Nombre total de SMS
82
+ * @type {number}
83
+ * @memberof NotifTaskStatus
84
+ */
85
+ total: number;
86
+ /**
87
+ * Nombre de SMS envoyés avec succès
88
+ * @type {number}
89
+ * @memberof NotifTaskStatus
90
+ */
91
+ sent: number;
92
+ /**
93
+ * Nombre de SMS échoués
94
+ * @type {number}
95
+ * @memberof NotifTaskStatus
96
+ */
97
+ failed: number;
98
+ /**
99
+ * Nombre de SMS reçus par le destinataire
100
+ * @type {number}
101
+ * @memberof NotifTaskStatus
102
+ */
103
+ delivered: number;
104
+ }
105
+
106
+ /**
107
+ * API Payment Service - NestJS
108
+ * Système de gestion des paiements - NestJS
109
+ *
110
+ * The version of the OpenAPI document: 1.0
111
+ *
112
+ *
113
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
114
+ * https://openapi-generator.tech
115
+ * Do not edit the class manually.
116
+ */
117
+ /**
118
+ *
119
+ * @export
120
+ */
121
+ declare const SmsStatus$1: {
122
+ readonly Scheduled: "SCHEDULED";
123
+ readonly Pending: "PENDING";
124
+ readonly Sent: "SENT";
125
+ readonly Delivered: "DELIVERED";
126
+ readonly Failed: "FAILED";
127
+ };
128
+ type SmsStatus$1 = typeof SmsStatus$1[keyof typeof SmsStatus$1];
129
+
130
+ /**
131
+ * API Payment Service - NestJS
132
+ * Système de gestion des paiements - NestJS
133
+ *
134
+ * The version of the OpenAPI document: 1.0
135
+ *
136
+ *
137
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
138
+ * https://openapi-generator.tech
139
+ * Do not edit the class manually.
140
+ */
141
+
142
+ /**
143
+ *
144
+ * @export
145
+ * @interface SmsDetail
146
+ */
147
+ interface SmsDetail$1 {
148
+ /**
149
+ * ID unique du SMS
150
+ * @type {string}
151
+ * @memberof SmsDetail
152
+ */
153
+ smsId: string;
154
+ /**
155
+ * Numéro de téléphone destinataire
156
+ * @type {string}
157
+ * @memberof SmsDetail
158
+ */
159
+ phone: string;
160
+ /**
161
+ * Contenu du message SMS
162
+ * @type {string}
163
+ * @memberof SmsDetail
164
+ */
165
+ message: string;
166
+ /**
167
+ * Statut du SMS
168
+ * @type {SmsStatus}
169
+ * @memberof SmsDetail
170
+ */
171
+ status: SmsStatus$1;
172
+ /**
173
+ * Nombre de retries effectués (0-2, au-delà de 2 = FAILED)
174
+ * @type {number}
175
+ * @memberof SmsDetail
176
+ */
177
+ retryCount: number;
178
+ }
179
+
180
+ /**
181
+ * API Payment Service - NestJS
182
+ * Système de gestion des paiements - NestJS
183
+ *
184
+ * The version of the OpenAPI document: 1.0
185
+ *
186
+ *
187
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
188
+ * https://openapi-generator.tech
189
+ * Do not edit the class manually.
190
+ */
191
+
192
+ /**
193
+ *
194
+ * @export
195
+ * @interface ResponseNotifTask
196
+ */
197
+ interface ResponseNotifTask {
198
+ /**
199
+ * ID unique de la tâche de notification
200
+ * @type {string}
201
+ * @memberof ResponseNotifTask
202
+ */
203
+ id: string;
204
+ /**
205
+ * Statut par SMS
206
+ * @type {NotifTaskStatus}
207
+ * @memberof ResponseNotifTask
208
+ */
209
+ status: NotifTaskStatus;
210
+ /**
211
+ * Statut par pages SMS
212
+ * @type {NotifTaskStatus}
213
+ * @memberof ResponseNotifTask
214
+ */
215
+ statusPage: NotifTaskStatus;
216
+ /**
217
+ * ID du projet
218
+ * @type {string}
219
+ * @memberof ResponseNotifTask
220
+ */
221
+ projectId: string;
222
+ /**
223
+ * Date de création de la tâche
224
+ * @type {Date}
225
+ * @memberof ResponseNotifTask
226
+ */
227
+ createdAt: Date;
228
+ }
229
+
1
230
  type Data = {
2
- body?: Record<string, unknown>;
231
+ body?: Record<string, unknown> | object;
3
232
  params?: Record<string, string>;
4
233
  public?: boolean;
5
234
  };
6
235
  type PData = Omit<Data, 'body'>;
7
236
  type Config = {
8
- projectId: string;
9
237
  secret: string;
10
238
  baseUrl?: string;
11
239
  };
@@ -28,40 +256,17 @@ declare enum SmsStatus {
28
256
  DELIVERED = "DELIVERED",
29
257
  FAILED = "FAILED"
30
258
  }
31
- type TaskCounters = {
32
- total: number;
33
- sent: number;
34
- failed: number;
35
- delivered: number;
36
- };
37
- type TaskData = {
38
- _id: string;
39
- projectId: string;
40
- status: TaskCounters;
41
- statusPage: TaskCounters;
42
- createdAt: string;
43
- scheduledAt?: string;
44
- };
45
- type SmsDetail = {
46
- smsId: string;
47
- phone: string;
48
- message: string;
49
- status: SmsStatus;
50
- retryCount: number;
259
+ type SmsDetail = SmsDetail$1;
260
+ type EstimateMessage = EstimateMessage$1;
261
+ type EstimateResponse = EstimateSmsResponse;
262
+ type TaskData = ResponseNotifTask & {
263
+ scheduledAt?: Date;
51
264
  };
52
265
  type TaskResponse = {
53
266
  task: TaskData;
54
267
  sms: SmsDetail[];
55
268
  total: number;
56
269
  };
57
- type EstimateMessage = {
58
- text: string;
59
- repeat?: number;
60
- };
61
- type EstimateResponse = {
62
- sms: number;
63
- credit: number;
64
- };
65
270
 
66
271
  declare class Task {
67
272
  id: string;
@@ -87,7 +292,7 @@ declare class Ariari {
87
292
  estimate: (...messages: EstimateMessage[]) => Promise<EstimateResponse>;
88
293
  static send: (...args: [string, ...Message[]] | Message[]) => Promise<Task>;
89
294
  static getTask: (taskId: string) => Task;
90
- static estimate: (...messages: EstimateMessage[]) => Promise<EstimateResponse>;
295
+ static estimate: (...messages: EstimateMessage[]) => Promise<EstimateSmsResponse>;
91
296
  }
92
297
 
93
298
  export { SmsStatus, Ariari as default };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,239 @@
1
+ /**
2
+ * API Payment Service - NestJS
3
+ * Système de gestion des paiements - NestJS
4
+ *
5
+ * The version of the OpenAPI document: 1.0
6
+ *
7
+ *
8
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9
+ * https://openapi-generator.tech
10
+ * Do not edit the class manually.
11
+ */
12
+ /**
13
+ *
14
+ * @export
15
+ * @interface EstimateMessage
16
+ */
17
+ interface EstimateMessage$1 {
18
+ /**
19
+ * SMS text content
20
+ * @type {string}
21
+ * @memberof EstimateMessage
22
+ */
23
+ text: string;
24
+ /**
25
+ * Number of recipients (default 1)
26
+ * @type {number}
27
+ * @memberof EstimateMessage
28
+ */
29
+ repeat?: number;
30
+ }
31
+
32
+ /**
33
+ * API Payment Service - NestJS
34
+ * Système de gestion des paiements - NestJS
35
+ *
36
+ * The version of the OpenAPI document: 1.0
37
+ *
38
+ *
39
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
40
+ * https://openapi-generator.tech
41
+ * Do not edit the class manually.
42
+ */
43
+ /**
44
+ *
45
+ * @export
46
+ * @interface EstimateSmsResponse
47
+ */
48
+ interface EstimateSmsResponse {
49
+ /**
50
+ * Total SMS count
51
+ * @type {number}
52
+ * @memberof EstimateSmsResponse
53
+ */
54
+ sms: number;
55
+ /**
56
+ * Total credit consumption
57
+ * @type {number}
58
+ * @memberof EstimateSmsResponse
59
+ */
60
+ credit: number;
61
+ }
62
+
63
+ /**
64
+ * API Payment Service - NestJS
65
+ * Système de gestion des paiements - NestJS
66
+ *
67
+ * The version of the OpenAPI document: 1.0
68
+ *
69
+ *
70
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
71
+ * https://openapi-generator.tech
72
+ * Do not edit the class manually.
73
+ */
74
+ /**
75
+ *
76
+ * @export
77
+ * @interface NotifTaskStatus
78
+ */
79
+ interface NotifTaskStatus {
80
+ /**
81
+ * Nombre total de SMS
82
+ * @type {number}
83
+ * @memberof NotifTaskStatus
84
+ */
85
+ total: number;
86
+ /**
87
+ * Nombre de SMS envoyés avec succès
88
+ * @type {number}
89
+ * @memberof NotifTaskStatus
90
+ */
91
+ sent: number;
92
+ /**
93
+ * Nombre de SMS échoués
94
+ * @type {number}
95
+ * @memberof NotifTaskStatus
96
+ */
97
+ failed: number;
98
+ /**
99
+ * Nombre de SMS reçus par le destinataire
100
+ * @type {number}
101
+ * @memberof NotifTaskStatus
102
+ */
103
+ delivered: number;
104
+ }
105
+
106
+ /**
107
+ * API Payment Service - NestJS
108
+ * Système de gestion des paiements - NestJS
109
+ *
110
+ * The version of the OpenAPI document: 1.0
111
+ *
112
+ *
113
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
114
+ * https://openapi-generator.tech
115
+ * Do not edit the class manually.
116
+ */
117
+ /**
118
+ *
119
+ * @export
120
+ */
121
+ declare const SmsStatus$1: {
122
+ readonly Scheduled: "SCHEDULED";
123
+ readonly Pending: "PENDING";
124
+ readonly Sent: "SENT";
125
+ readonly Delivered: "DELIVERED";
126
+ readonly Failed: "FAILED";
127
+ };
128
+ type SmsStatus$1 = typeof SmsStatus$1[keyof typeof SmsStatus$1];
129
+
130
+ /**
131
+ * API Payment Service - NestJS
132
+ * Système de gestion des paiements - NestJS
133
+ *
134
+ * The version of the OpenAPI document: 1.0
135
+ *
136
+ *
137
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
138
+ * https://openapi-generator.tech
139
+ * Do not edit the class manually.
140
+ */
141
+
142
+ /**
143
+ *
144
+ * @export
145
+ * @interface SmsDetail
146
+ */
147
+ interface SmsDetail$1 {
148
+ /**
149
+ * ID unique du SMS
150
+ * @type {string}
151
+ * @memberof SmsDetail
152
+ */
153
+ smsId: string;
154
+ /**
155
+ * Numéro de téléphone destinataire
156
+ * @type {string}
157
+ * @memberof SmsDetail
158
+ */
159
+ phone: string;
160
+ /**
161
+ * Contenu du message SMS
162
+ * @type {string}
163
+ * @memberof SmsDetail
164
+ */
165
+ message: string;
166
+ /**
167
+ * Statut du SMS
168
+ * @type {SmsStatus}
169
+ * @memberof SmsDetail
170
+ */
171
+ status: SmsStatus$1;
172
+ /**
173
+ * Nombre de retries effectués (0-2, au-delà de 2 = FAILED)
174
+ * @type {number}
175
+ * @memberof SmsDetail
176
+ */
177
+ retryCount: number;
178
+ }
179
+
180
+ /**
181
+ * API Payment Service - NestJS
182
+ * Système de gestion des paiements - NestJS
183
+ *
184
+ * The version of the OpenAPI document: 1.0
185
+ *
186
+ *
187
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
188
+ * https://openapi-generator.tech
189
+ * Do not edit the class manually.
190
+ */
191
+
192
+ /**
193
+ *
194
+ * @export
195
+ * @interface ResponseNotifTask
196
+ */
197
+ interface ResponseNotifTask {
198
+ /**
199
+ * ID unique de la tâche de notification
200
+ * @type {string}
201
+ * @memberof ResponseNotifTask
202
+ */
203
+ id: string;
204
+ /**
205
+ * Statut par SMS
206
+ * @type {NotifTaskStatus}
207
+ * @memberof ResponseNotifTask
208
+ */
209
+ status: NotifTaskStatus;
210
+ /**
211
+ * Statut par pages SMS
212
+ * @type {NotifTaskStatus}
213
+ * @memberof ResponseNotifTask
214
+ */
215
+ statusPage: NotifTaskStatus;
216
+ /**
217
+ * ID du projet
218
+ * @type {string}
219
+ * @memberof ResponseNotifTask
220
+ */
221
+ projectId: string;
222
+ /**
223
+ * Date de création de la tâche
224
+ * @type {Date}
225
+ * @memberof ResponseNotifTask
226
+ */
227
+ createdAt: Date;
228
+ }
229
+
1
230
  type Data = {
2
- body?: Record<string, unknown>;
231
+ body?: Record<string, unknown> | object;
3
232
  params?: Record<string, string>;
4
233
  public?: boolean;
5
234
  };
6
235
  type PData = Omit<Data, 'body'>;
7
236
  type Config = {
8
- projectId: string;
9
237
  secret: string;
10
238
  baseUrl?: string;
11
239
  };
@@ -28,40 +256,17 @@ declare enum SmsStatus {
28
256
  DELIVERED = "DELIVERED",
29
257
  FAILED = "FAILED"
30
258
  }
31
- type TaskCounters = {
32
- total: number;
33
- sent: number;
34
- failed: number;
35
- delivered: number;
36
- };
37
- type TaskData = {
38
- _id: string;
39
- projectId: string;
40
- status: TaskCounters;
41
- statusPage: TaskCounters;
42
- createdAt: string;
43
- scheduledAt?: string;
44
- };
45
- type SmsDetail = {
46
- smsId: string;
47
- phone: string;
48
- message: string;
49
- status: SmsStatus;
50
- retryCount: number;
259
+ type SmsDetail = SmsDetail$1;
260
+ type EstimateMessage = EstimateMessage$1;
261
+ type EstimateResponse = EstimateSmsResponse;
262
+ type TaskData = ResponseNotifTask & {
263
+ scheduledAt?: Date;
51
264
  };
52
265
  type TaskResponse = {
53
266
  task: TaskData;
54
267
  sms: SmsDetail[];
55
268
  total: number;
56
269
  };
57
- type EstimateMessage = {
58
- text: string;
59
- repeat?: number;
60
- };
61
- type EstimateResponse = {
62
- sms: number;
63
- credit: number;
64
- };
65
270
 
66
271
  declare class Task {
67
272
  id: string;
@@ -87,7 +292,7 @@ declare class Ariari {
87
292
  estimate: (...messages: EstimateMessage[]) => Promise<EstimateResponse>;
88
293
  static send: (...args: [string, ...Message[]] | Message[]) => Promise<Task>;
89
294
  static getTask: (taskId: string) => Task;
90
- static estimate: (...messages: EstimateMessage[]) => Promise<EstimateResponse>;
295
+ static estimate: (...messages: EstimateMessage[]) => Promise<EstimateSmsResponse>;
91
296
  }
92
297
 
93
298
  export { SmsStatus, Ariari as default };
package/dist/index.js CHANGED
@@ -31,7 +31,6 @@ async function request(verb, endpoint, options, config) {
31
31
  const url = `${config.baseUrl || "https://api.ariari.mg"}${endpoint}`;
32
32
  const headers = { "Content-Type": "application/json" };
33
33
  if (!options.public) {
34
- headers["x-project-id"] = config.projectId;
35
34
  headers["x-secret"] = config.secret;
36
35
  }
37
36
  const fetchOptions = { method: verb, headers };
@@ -68,6 +67,64 @@ var normalizePhoneNumber = (phone) => {
68
67
  return normalized;
69
68
  };
70
69
 
70
+ // ../common/gen/models/NotifTaskStatus.ts
71
+ function NotifTaskStatusFromJSON(json) {
72
+ return NotifTaskStatusFromJSONTyped(json, false);
73
+ }
74
+ function NotifTaskStatusFromJSONTyped(json, ignoreDiscriminator) {
75
+ if (json == null) {
76
+ return json;
77
+ }
78
+ return {
79
+ "total": json["total"],
80
+ "sent": json["sent"],
81
+ "failed": json["failed"],
82
+ "delivered": json["delivered"]
83
+ };
84
+ }
85
+
86
+ // ../common/gen/models/ResponseNotifTask.ts
87
+ function ResponseNotifTaskFromJSON(json) {
88
+ return ResponseNotifTaskFromJSONTyped(json, false);
89
+ }
90
+ function ResponseNotifTaskFromJSONTyped(json, ignoreDiscriminator) {
91
+ if (json == null) {
92
+ return json;
93
+ }
94
+ return {
95
+ "id": json["_id"],
96
+ "status": NotifTaskStatusFromJSON(json["status"]),
97
+ "statusPage": NotifTaskStatusFromJSON(json["statusPage"]),
98
+ "projectId": json["projectId"],
99
+ "createdAt": new Date(json["createdAt"])
100
+ };
101
+ }
102
+
103
+ // ../common/gen/models/SmsStatus.ts
104
+ function SmsStatusFromJSON(json) {
105
+ return SmsStatusFromJSONTyped(json, false);
106
+ }
107
+ function SmsStatusFromJSONTyped(json, ignoreDiscriminator) {
108
+ return json;
109
+ }
110
+
111
+ // ../common/gen/models/SmsDetail.ts
112
+ function SmsDetailFromJSON(json) {
113
+ return SmsDetailFromJSONTyped(json, false);
114
+ }
115
+ function SmsDetailFromJSONTyped(json, ignoreDiscriminator) {
116
+ if (json == null) {
117
+ return json;
118
+ }
119
+ return {
120
+ "smsId": json["smsId"],
121
+ "phone": json["phone"],
122
+ "message": json["message"],
123
+ "status": SmsStatusFromJSON(json["status"]),
124
+ "retryCount": json["retryCount"]
125
+ };
126
+ }
127
+
71
128
  // src/types/index.ts
72
129
  var SmsStatus = /* @__PURE__ */ ((SmsStatus2) => {
73
130
  SmsStatus2["SCHEDULED"] = "SCHEDULED";
@@ -90,6 +147,17 @@ var parseSchedule = (input) => {
90
147
  }
91
148
  return input;
92
149
  };
150
+ var parseTaskResponse = (raw) => {
151
+ const task = {
152
+ ...ResponseNotifTaskFromJSON(raw.task),
153
+ ...raw.task.scheduledAt != null && { scheduledAt: new Date(raw.task.scheduledAt) }
154
+ };
155
+ return {
156
+ task,
157
+ sms: Array.isArray(raw.sms) ? raw.sms.map(SmsDetailFromJSON) : [],
158
+ total: raw.total ?? 0
159
+ };
160
+ };
93
161
  var instances = {};
94
162
  var Task = class {
95
163
  constructor(id, requester) {
@@ -98,14 +166,17 @@ var Task = class {
98
166
  }
99
167
  async status(count, page) {
100
168
  if (count === void 0) {
101
- return this._requester.get(`/api/notif-task/${this.id}`);
169
+ const res2 = await this._requester.get(`/api/notif-task/${this.id}`);
170
+ return parseTaskResponse(res2);
102
171
  }
103
172
  const details = `${count},${page || 1}`;
104
- return this._requester.get(`/api/notif-task/${this.id}?details=${details}`);
173
+ const res = await this._requester.get(`/api/notif-task/${this.id}?details=${details}`);
174
+ return parseTaskResponse(res);
105
175
  }
106
176
  // All SMS at once
107
177
  async fullStatus() {
108
- return this._requester.get(`/api/notif-task/${this.id}?details=-1`);
178
+ const res = await this._requester.get(`/api/notif-task/${this.id}?details=-1`);
179
+ return parseTaskResponse(res);
109
180
  }
110
181
  };
111
182
  var _Ariari = class _Ariari {
@@ -122,7 +193,8 @@ var _Ariari = class _Ariari {
122
193
  ...scheduledAt && { scheduledAt }
123
194
  };
124
195
  const response = await this._requester.post("/api/sms/bulk", { body });
125
- return new Task(response._id, this._requester);
196
+ const task = ResponseNotifTaskFromJSON(response);
197
+ return new Task(task.id, this._requester);
126
198
  };
127
199
  this.getTask = (taskId) => new Task(taskId, this._requester);
128
200
  this.estimate = async (...messages) => {
@@ -136,7 +208,7 @@ var _Ariari = class _Ariari {
136
208
  _Ariari.config = (nameAndConfig) => new _Ariari(nameAndConfig);
137
209
  _Ariari.init = _Ariari.config;
138
210
  _Ariari.get = (name = "main") => {
139
- if (!instances[name]) throw new Error(`The instance of Ariari with the name "${name}" doesn't exist yet. Call Ariari.config(... )`);
211
+ if (!instances[name]) throw new Error(`The instance of Ariari with the name "${name}" doesn't exist yet. Call Ariari.config(...)`);
140
212
  return instances[name];
141
213
  };
142
214
  _Ariari.send = async (...args) => await _Ariari.get("main")?.send(...args);
package/dist/index.mjs CHANGED
@@ -4,7 +4,6 @@ async function request(verb, endpoint, options, config) {
4
4
  const url = `${config.baseUrl || "https://api.ariari.mg"}${endpoint}`;
5
5
  const headers = { "Content-Type": "application/json" };
6
6
  if (!options.public) {
7
- headers["x-project-id"] = config.projectId;
8
7
  headers["x-secret"] = config.secret;
9
8
  }
10
9
  const fetchOptions = { method: verb, headers };
@@ -41,6 +40,64 @@ var normalizePhoneNumber = (phone) => {
41
40
  return normalized;
42
41
  };
43
42
 
43
+ // ../common/gen/models/NotifTaskStatus.ts
44
+ function NotifTaskStatusFromJSON(json) {
45
+ return NotifTaskStatusFromJSONTyped(json, false);
46
+ }
47
+ function NotifTaskStatusFromJSONTyped(json, ignoreDiscriminator) {
48
+ if (json == null) {
49
+ return json;
50
+ }
51
+ return {
52
+ "total": json["total"],
53
+ "sent": json["sent"],
54
+ "failed": json["failed"],
55
+ "delivered": json["delivered"]
56
+ };
57
+ }
58
+
59
+ // ../common/gen/models/ResponseNotifTask.ts
60
+ function ResponseNotifTaskFromJSON(json) {
61
+ return ResponseNotifTaskFromJSONTyped(json, false);
62
+ }
63
+ function ResponseNotifTaskFromJSONTyped(json, ignoreDiscriminator) {
64
+ if (json == null) {
65
+ return json;
66
+ }
67
+ return {
68
+ "id": json["_id"],
69
+ "status": NotifTaskStatusFromJSON(json["status"]),
70
+ "statusPage": NotifTaskStatusFromJSON(json["statusPage"]),
71
+ "projectId": json["projectId"],
72
+ "createdAt": new Date(json["createdAt"])
73
+ };
74
+ }
75
+
76
+ // ../common/gen/models/SmsStatus.ts
77
+ function SmsStatusFromJSON(json) {
78
+ return SmsStatusFromJSONTyped(json, false);
79
+ }
80
+ function SmsStatusFromJSONTyped(json, ignoreDiscriminator) {
81
+ return json;
82
+ }
83
+
84
+ // ../common/gen/models/SmsDetail.ts
85
+ function SmsDetailFromJSON(json) {
86
+ return SmsDetailFromJSONTyped(json, false);
87
+ }
88
+ function SmsDetailFromJSONTyped(json, ignoreDiscriminator) {
89
+ if (json == null) {
90
+ return json;
91
+ }
92
+ return {
93
+ "smsId": json["smsId"],
94
+ "phone": json["phone"],
95
+ "message": json["message"],
96
+ "status": SmsStatusFromJSON(json["status"]),
97
+ "retryCount": json["retryCount"]
98
+ };
99
+ }
100
+
44
101
  // src/types/index.ts
45
102
  var SmsStatus = /* @__PURE__ */ ((SmsStatus2) => {
46
103
  SmsStatus2["SCHEDULED"] = "SCHEDULED";
@@ -63,6 +120,17 @@ var parseSchedule = (input) => {
63
120
  }
64
121
  return input;
65
122
  };
123
+ var parseTaskResponse = (raw) => {
124
+ const task = {
125
+ ...ResponseNotifTaskFromJSON(raw.task),
126
+ ...raw.task.scheduledAt != null && { scheduledAt: new Date(raw.task.scheduledAt) }
127
+ };
128
+ return {
129
+ task,
130
+ sms: Array.isArray(raw.sms) ? raw.sms.map(SmsDetailFromJSON) : [],
131
+ total: raw.total ?? 0
132
+ };
133
+ };
66
134
  var instances = {};
67
135
  var Task = class {
68
136
  constructor(id, requester) {
@@ -71,14 +139,17 @@ var Task = class {
71
139
  }
72
140
  async status(count, page) {
73
141
  if (count === void 0) {
74
- return this._requester.get(`/api/notif-task/${this.id}`);
142
+ const res2 = await this._requester.get(`/api/notif-task/${this.id}`);
143
+ return parseTaskResponse(res2);
75
144
  }
76
145
  const details = `${count},${page || 1}`;
77
- return this._requester.get(`/api/notif-task/${this.id}?details=${details}`);
146
+ const res = await this._requester.get(`/api/notif-task/${this.id}?details=${details}`);
147
+ return parseTaskResponse(res);
78
148
  }
79
149
  // All SMS at once
80
150
  async fullStatus() {
81
- return this._requester.get(`/api/notif-task/${this.id}?details=-1`);
151
+ const res = await this._requester.get(`/api/notif-task/${this.id}?details=-1`);
152
+ return parseTaskResponse(res);
82
153
  }
83
154
  };
84
155
  var _Ariari = class _Ariari {
@@ -95,7 +166,8 @@ var _Ariari = class _Ariari {
95
166
  ...scheduledAt && { scheduledAt }
96
167
  };
97
168
  const response = await this._requester.post("/api/sms/bulk", { body });
98
- return new Task(response._id, this._requester);
169
+ const task = ResponseNotifTaskFromJSON(response);
170
+ return new Task(task.id, this._requester);
99
171
  };
100
172
  this.getTask = (taskId) => new Task(taskId, this._requester);
101
173
  this.estimate = async (...messages) => {
@@ -109,7 +181,7 @@ var _Ariari = class _Ariari {
109
181
  _Ariari.config = (nameAndConfig) => new _Ariari(nameAndConfig);
110
182
  _Ariari.init = _Ariari.config;
111
183
  _Ariari.get = (name = "main") => {
112
- if (!instances[name]) throw new Error(`The instance of Ariari with the name "${name}" doesn't exist yet. Call Ariari.config(... )`);
184
+ if (!instances[name]) throw new Error(`The instance of Ariari with the name "${name}" doesn't exist yet. Call Ariari.config(...)`);
113
185
  return instances[name];
114
186
  };
115
187
  _Ariari.send = async (...args) => await _Ariari.get("main")?.send(...args);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ariary/notification",
3
- "version": "3.0.13",
3
+ "version": "4.1.0",
4
4
  "description": "Ariary SMS & Notification SDK (ariari.mg) — Send SMS in Madagascar with automatic phone normalization, bulk messaging, deferred/scheduled sending, delivery tracking, credit estimation. Supports Orange, Airtel, Telma. Multi-instance, TypeScript-first.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",