@ariary/notification 1.0.2 → 1.0.3

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,46 +1,59 @@
1
- # @ariary/notification
2
-
3
- Un outil pour envoyer des SMS via Ariary et suivre leur état.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install @ariary/notification
9
- ```
10
-
11
- ## Usage
12
-
13
- ### Initialisation
14
-
15
- ```typescript
16
- import { Ariari } from '@ariary/notification';
17
-
18
- Ariari.config({
19
- projectId: 'your-project-id',
20
- secretId: 'your-secret-id'
21
- });
22
- ```
23
-
24
- ## Notifications
25
-
26
- ```typescript
27
- // SMS
28
- const sms = await Ariari.notification.send({ phone: ['261345678901', '261345678902'], message: 'Hello' });
29
- const bulkSms = await Ariari.notification.sendBulk([
30
- { phone: '261345678901', message: 'Message 1' },
31
- { phone: '261345678902', message: 'Message 2' }
32
- ]);
33
- const allSms = await Ariari.notification.getAll();
34
-
35
- // Notification Tasks
36
- const tasks = await Ariari.notification.task.findAll('projectId');
37
- const task = await Ariari.notification.task.findOne(taskId);
38
- const updatedTask = await Ariari.notification.task.update(taskId, { message: 'New' });
39
- const deleted = await Ariari.notification.task.delete(taskId);
40
- const smsDetails = await Ariari.notification.task.getSmsDetails(taskId);
41
- const retried = await Ariari.notification.task.retryFailedSms(taskId);
42
- ```
43
-
44
- ## License
45
-
46
- ISC
1
+ # Ariari Notification
2
+
3
+ Simple SDK for sending SMS notifications.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @ariari/notification
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Configuration
14
+
15
+ ```typescript
16
+ import Ariari from '@ariari/notification';
17
+
18
+ Ariari.config({
19
+ projectId: 'your-project-id',
20
+ secretId: 'your-secret-id'
21
+ });
22
+ ```
23
+
24
+ ### Send Messages
25
+
26
+ ```typescript
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
+ await task.status();
34
+ ```
35
+
36
+ ### Check Task Status
37
+
38
+ You can also check the status of a task by ID:
39
+
40
+ ```typescript
41
+ const task = new Ariari.Task('task-id-123');
42
+ await task.status();
43
+ await task.detailedStatus();
44
+ ```
45
+
46
+ ### List Tasks
47
+
48
+ ```typescript
49
+ const result = await Ariari.tasks({
50
+ from: 0,
51
+ count: 20,
52
+ order: -1
53
+ });
54
+
55
+
56
+ const nextResult = await Ariari.tasks(result.next);
57
+ ...
58
+ const prevResult = await Ariari.tasks(result.prev);
59
+ ```
package/dist/index.d.mts CHANGED
@@ -1,133 +1,46 @@
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;
24
- 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;
35
- phone: string;
36
- status: string;
37
- }[];
38
- }
39
- interface BulkSmsResponseDto {
40
- status: string;
41
- data: {
42
- id: string;
43
- 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[];
83
- 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
- declare const notificationService: NotificationService;
115
-
116
1
  interface ApiConfig {
117
2
  projectId: string;
118
3
  secretId: string;
119
4
  baseUrl?: string;
120
5
  }
121
- declare function setConfig(cfg: ApiConfig): void;
122
- declare function getConfig(): ApiConfig | null;
123
6
 
7
+ type Message = {
8
+ phone: string[] | string;
9
+ message: string;
10
+ };
11
+ type GetTaskParam = {
12
+ from: number;
13
+ count: number;
14
+ order: -1 | 1;
15
+ };
16
+
17
+ declare class Task {
18
+ id: string;
19
+ constructor(id: string);
20
+ status: () => Promise<unknown>;
21
+ detailedStatus: () => Promise<unknown>;
22
+ }
124
23
  declare class AriariBridge {
125
24
  private static instance;
126
25
  private constructor();
127
26
  static getInstance(): AriariBridge;
128
27
  config(cfg: ApiConfig): void;
129
- get notification(): NotificationService;
28
+ send(...data: Message[]): Promise<Task>;
29
+ tasks: ({ from, count, order }: GetTaskParam) => Promise<{
30
+ tasks: never[];
31
+ next: {
32
+ from: number;
33
+ count: number;
34
+ order: 1 | -1;
35
+ };
36
+ prev: {
37
+ from: number;
38
+ count: number;
39
+ order: 1 | -1;
40
+ } | undefined;
41
+ }>;
42
+ Task: typeof Task;
130
43
  }
131
44
  declare const Ariari: AriariBridge;
132
45
 
133
- export { type ApiConfig, Ariari, type BulkSmsDto, type BulkSmsResponseDto, type CreateNotifTaskDto, type CreateSmsDto, type MultiSmsResponseDto, type NotifTaskApi, type NotifTaskDetailsDto, type NotificationService, type ResponseNotifTaskDto, type ResponseSmsDto, type RetryFailedSmsResponseDto, type SendSmsDto, type SendSmsResponseDto, type SmsApi, type SmsDetail, type UpdateNotifTaskDto, getConfig, notificationService, setConfig };
46
+ export { Ariari as default };
package/dist/index.d.ts CHANGED
@@ -1,133 +1,46 @@
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;
24
- 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;
35
- phone: string;
36
- status: string;
37
- }[];
38
- }
39
- interface BulkSmsResponseDto {
40
- status: string;
41
- data: {
42
- id: string;
43
- 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[];
83
- 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
- declare const notificationService: NotificationService;
115
-
116
1
  interface ApiConfig {
117
2
  projectId: string;
118
3
  secretId: string;
119
4
  baseUrl?: string;
120
5
  }
121
- declare function setConfig(cfg: ApiConfig): void;
122
- declare function getConfig(): ApiConfig | null;
123
6
 
7
+ type Message = {
8
+ phone: string[] | string;
9
+ message: string;
10
+ };
11
+ type GetTaskParam = {
12
+ from: number;
13
+ count: number;
14
+ order: -1 | 1;
15
+ };
16
+
17
+ declare class Task {
18
+ id: string;
19
+ constructor(id: string);
20
+ status: () => Promise<unknown>;
21
+ detailedStatus: () => Promise<unknown>;
22
+ }
124
23
  declare class AriariBridge {
125
24
  private static instance;
126
25
  private constructor();
127
26
  static getInstance(): AriariBridge;
128
27
  config(cfg: ApiConfig): void;
129
- get notification(): NotificationService;
28
+ send(...data: Message[]): Promise<Task>;
29
+ tasks: ({ from, count, order }: GetTaskParam) => Promise<{
30
+ tasks: never[];
31
+ next: {
32
+ from: number;
33
+ count: number;
34
+ order: 1 | -1;
35
+ };
36
+ prev: {
37
+ from: number;
38
+ count: number;
39
+ order: 1 | -1;
40
+ } | undefined;
41
+ }>;
42
+ Task: typeof Task;
130
43
  }
131
44
  declare const Ariari: AriariBridge;
132
45
 
133
- export { type ApiConfig, Ariari, type BulkSmsDto, type BulkSmsResponseDto, type CreateNotifTaskDto, type CreateSmsDto, type MultiSmsResponseDto, type NotifTaskApi, type NotifTaskDetailsDto, type NotificationService, type ResponseNotifTaskDto, type ResponseSmsDto, type RetryFailedSmsResponseDto, type SendSmsDto, type SendSmsResponseDto, type SmsApi, type SmsDetail, type UpdateNotifTaskDto, getConfig, notificationService, setConfig };
46
+ export { Ariari as default };
package/dist/index.js CHANGED
@@ -20,10 +20,7 @@ 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,
24
- getConfig: () => getConfig,
25
- notificationService: () => notificationService,
26
- setConfig: () => setConfig
23
+ default: () => src_default
27
24
  });
28
25
  module.exports = __toCommonJS(src_exports);
29
26
 
@@ -79,66 +76,25 @@ async function httpGet(endpoint, requiresSecret = true) {
79
76
  async function httpPost(endpoint, body, requiresSecret = true) {
80
77
  return request("POST", endpoint, { body, requiresSecret });
81
78
  }
82
- async function httpPatch(endpoint, body, requiresSecret = true) {
83
- return request("PATCH", endpoint, { body, requiresSecret });
84
- }
85
- async function httpDelete(endpoint, requiresSecret = true) {
86
- return request("DELETE", endpoint, { requiresSecret });
87
- }
88
79
 
89
- // src/services/notification.ts
90
- var smsApi = {
91
- async send(data) {
92
- const phones = Array.isArray(data.phone) ? data.phone : [data.phone];
93
- return httpPost("/api/sms/multi", {
94
- phones,
95
- message: data.message
96
- });
97
- },
98
- async sendBulk(messages) {
99
- const bulkMessages = messages.map((item) => ({
100
- message: item.message,
101
- phones: Array.isArray(item.phone) ? item.phone : [item.phone]
102
- }));
103
- return httpPost("/api/sms/bulk", {
104
- messages: bulkMessages
105
- });
106
- },
107
- async getAll() {
108
- return httpGet("/api/sms");
109
- }
110
- };
111
- var notifTaskApi = {
112
- async findAll(projectId) {
113
- return httpGet(`/api/notif-task?projectId=${projectId}`);
114
- },
115
- async findOne(id) {
116
- return httpGet(`/api/notif-task/${id}`);
117
- },
118
- async update(id, data) {
119
- return httpPatch(`/api/notif-task/${id}`, data);
120
- },
121
- async delete(id) {
122
- return httpDelete(`/api/notif-task/${id}`);
123
- },
124
- async getSmsDetails(id) {
125
- return httpGet(`/api/notif-task/${id}/sms-details`);
126
- },
127
- async retryFailedSms(id) {
128
- return httpPost(
129
- `/api/notif-task/${id}/retry-failed-sms`,
130
- {}
131
- );
80
+ // src/index.ts
81
+ var Task = class {
82
+ constructor(id) {
83
+ this.status = () => httpGet(`/api/notif-task/${this.id}`);
84
+ this.detailedStatus = () => httpGet(`/api/notif-task/${this.id}/detailed`);
85
+ this.id = id;
132
86
  }
133
87
  };
134
- var notificationService = {
135
- ...smsApi,
136
- task: notifTaskApi
137
- };
138
-
139
- // src/index.ts
140
88
  var AriariBridge = class _AriariBridge {
141
89
  constructor() {
90
+ this.tasks = async ({ from = 0, count = 20, order = -1 }) => {
91
+ return {
92
+ tasks: [],
93
+ next: { from: from + count + 1, count, order },
94
+ prev: from > 0 ? { from: from - count - 1, count, order } : void 0
95
+ };
96
+ };
97
+ this.Task = Task;
142
98
  }
143
99
  static getInstance() {
144
100
  if (!_AriariBridge.instance) {
@@ -149,15 +105,14 @@ var AriariBridge = class _AriariBridge {
149
105
  config(cfg) {
150
106
  setConfig(cfg);
151
107
  }
152
- get notification() {
153
- return notificationService;
108
+ async send(...data) {
109
+ const messages = data.reduce((old, item) => {
110
+ old.push(...Array.isArray(item.phone) ? item.phone.map((phone) => ({ phone, message: item.message })) : [item]);
111
+ return old;
112
+ }, []);
113
+ const one = await httpPost("/api/sms/bulk", { messages });
114
+ return new Task(one.id);
154
115
  }
155
116
  };
156
117
  var Ariari = AriariBridge.getInstance();
157
- // Annotate the CommonJS export names for ESM import in node:
158
- 0 && (module.exports = {
159
- Ariari,
160
- getConfig,
161
- notificationService,
162
- setConfig
163
- });
118
+ var src_default = Ariari;
package/dist/index.mjs CHANGED
@@ -50,66 +50,25 @@ async function httpGet(endpoint, requiresSecret = true) {
50
50
  async function httpPost(endpoint, body, requiresSecret = true) {
51
51
  return request("POST", endpoint, { body, requiresSecret });
52
52
  }
53
- async function httpPatch(endpoint, body, requiresSecret = true) {
54
- return request("PATCH", endpoint, { body, requiresSecret });
55
- }
56
- async function httpDelete(endpoint, requiresSecret = true) {
57
- return request("DELETE", endpoint, { requiresSecret });
58
- }
59
53
 
60
- // src/services/notification.ts
61
- var smsApi = {
62
- async send(data) {
63
- const phones = Array.isArray(data.phone) ? data.phone : [data.phone];
64
- return httpPost("/api/sms/multi", {
65
- phones,
66
- message: data.message
67
- });
68
- },
69
- async sendBulk(messages) {
70
- const bulkMessages = messages.map((item) => ({
71
- message: item.message,
72
- phones: Array.isArray(item.phone) ? item.phone : [item.phone]
73
- }));
74
- return httpPost("/api/sms/bulk", {
75
- messages: bulkMessages
76
- });
77
- },
78
- async getAll() {
79
- return httpGet("/api/sms");
80
- }
81
- };
82
- var notifTaskApi = {
83
- async findAll(projectId) {
84
- return httpGet(`/api/notif-task?projectId=${projectId}`);
85
- },
86
- async findOne(id) {
87
- return httpGet(`/api/notif-task/${id}`);
88
- },
89
- async update(id, data) {
90
- return httpPatch(`/api/notif-task/${id}`, data);
91
- },
92
- async delete(id) {
93
- return httpDelete(`/api/notif-task/${id}`);
94
- },
95
- async getSmsDetails(id) {
96
- return httpGet(`/api/notif-task/${id}/sms-details`);
97
- },
98
- async retryFailedSms(id) {
99
- return httpPost(
100
- `/api/notif-task/${id}/retry-failed-sms`,
101
- {}
102
- );
54
+ // src/index.ts
55
+ var Task = class {
56
+ constructor(id) {
57
+ this.status = () => httpGet(`/api/notif-task/${this.id}`);
58
+ this.detailedStatus = () => httpGet(`/api/notif-task/${this.id}/detailed`);
59
+ this.id = id;
103
60
  }
104
61
  };
105
- var notificationService = {
106
- ...smsApi,
107
- task: notifTaskApi
108
- };
109
-
110
- // src/index.ts
111
62
  var AriariBridge = class _AriariBridge {
112
63
  constructor() {
64
+ this.tasks = async ({ from = 0, count = 20, order = -1 }) => {
65
+ return {
66
+ tasks: [],
67
+ next: { from: from + count + 1, count, order },
68
+ prev: from > 0 ? { from: from - count - 1, count, order } : void 0
69
+ };
70
+ };
71
+ this.Task = Task;
113
72
  }
114
73
  static getInstance() {
115
74
  if (!_AriariBridge.instance) {
@@ -120,14 +79,17 @@ var AriariBridge = class _AriariBridge {
120
79
  config(cfg) {
121
80
  setConfig(cfg);
122
81
  }
123
- get notification() {
124
- return notificationService;
82
+ async send(...data) {
83
+ const messages = data.reduce((old, item) => {
84
+ old.push(...Array.isArray(item.phone) ? item.phone.map((phone) => ({ phone, message: item.message })) : [item]);
85
+ return old;
86
+ }, []);
87
+ const one = await httpPost("/api/sms/bulk", { messages });
88
+ return new Task(one.id);
125
89
  }
126
90
  };
127
91
  var Ariari = AriariBridge.getInstance();
92
+ var src_default = Ariari;
128
93
  export {
129
- Ariari,
130
- getConfig,
131
- notificationService,
132
- setConfig
94
+ src_default as default
133
95
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ariary/notification",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "SMS et Notification Task SDK pour l'API Ariary",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",