@ariary/notification 3.0.2 → 3.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/dist/index.d.mts CHANGED
@@ -21,6 +21,9 @@ type Message = {
21
21
  phone: string[] | string;
22
22
  message: string;
23
23
  };
24
+ type SendOptions = {
25
+ scheduledAt?: string;
26
+ };
24
27
  type SmsStatus = 'SCHEDULED' | 'PENDING' | 'SENT' | 'DELIVERED' | 'FAILED';
25
28
  type TaskStatus = {
26
29
  total: number;
@@ -52,21 +55,23 @@ declare class Task {
52
55
  id: string;
53
56
  private _requester;
54
57
  constructor(id: string, requester: ReturnType<typeof createRequester>);
55
- get(): Promise<TaskStatus>;
56
- get(count: number, page?: number): Promise<TaskWithDetails>;
58
+ status(): Promise<TaskStatus>;
59
+ status(count: number, page?: number): Promise<TaskWithDetails>;
57
60
  }
58
61
  declare class Ariari {
59
62
  private _config;
60
63
  private _requester;
61
64
  private constructor();
62
- static config(nameAndConfig: Config & {
65
+ static config: (nameAndConfig: Config & {
66
+ name?: string;
67
+ }) => Ariari;
68
+ static init: (nameAndConfig: Config & {
63
69
  name?: string;
64
- }): Ariari;
65
- static init: typeof Ariari.config;
70
+ }) => Ariari;
66
71
  static get: (name?: string) => Ariari;
67
- send: (...data: Message[]) => Promise<Task>;
72
+ send: (...args: [SendOptions, ...Message[]] | Message[]) => Promise<Task>;
68
73
  getTask: (taskId: string) => Task;
69
- static send: (...data: Message[]) => Promise<Task>;
74
+ static send: (...args: [SendOptions, ...Message[]] | Message[]) => Promise<Task>;
70
75
  static getTask: (taskId: string) => Promise<Task>;
71
76
  }
72
77
 
package/dist/index.d.ts CHANGED
@@ -21,6 +21,9 @@ type Message = {
21
21
  phone: string[] | string;
22
22
  message: string;
23
23
  };
24
+ type SendOptions = {
25
+ scheduledAt?: string;
26
+ };
24
27
  type SmsStatus = 'SCHEDULED' | 'PENDING' | 'SENT' | 'DELIVERED' | 'FAILED';
25
28
  type TaskStatus = {
26
29
  total: number;
@@ -52,21 +55,23 @@ declare class Task {
52
55
  id: string;
53
56
  private _requester;
54
57
  constructor(id: string, requester: ReturnType<typeof createRequester>);
55
- get(): Promise<TaskStatus>;
56
- get(count: number, page?: number): Promise<TaskWithDetails>;
58
+ status(): Promise<TaskStatus>;
59
+ status(count: number, page?: number): Promise<TaskWithDetails>;
57
60
  }
58
61
  declare class Ariari {
59
62
  private _config;
60
63
  private _requester;
61
64
  private constructor();
62
- static config(nameAndConfig: Config & {
65
+ static config: (nameAndConfig: Config & {
66
+ name?: string;
67
+ }) => Ariari;
68
+ static init: (nameAndConfig: Config & {
63
69
  name?: string;
64
- }): Ariari;
65
- static init: typeof Ariari.config;
70
+ }) => Ariari;
66
71
  static get: (name?: string) => Ariari;
67
- send: (...data: Message[]) => Promise<Task>;
72
+ send: (...args: [SendOptions, ...Message[]] | Message[]) => Promise<Task>;
68
73
  getTask: (taskId: string) => Task;
69
- static send: (...data: Message[]) => Promise<Task>;
74
+ static send: (...args: [SendOptions, ...Message[]] | Message[]) => Promise<Task>;
70
75
  static getTask: (taskId: string) => Promise<Task>;
71
76
  }
72
77
 
package/dist/index.js CHANGED
@@ -74,7 +74,7 @@ var Task = class {
74
74
  this.id = id;
75
75
  this._requester = requester;
76
76
  }
77
- async get(count, page) {
77
+ async status(count, page) {
78
78
  if (count === void 0) {
79
79
  const response = await this._requester.get(`/api/notif-task/${this.id}`);
80
80
  return response.status;
@@ -85,35 +85,32 @@ var Task = class {
85
85
  };
86
86
  var _Ariari = class _Ariari {
87
87
  constructor({ name = "main", ...config }) {
88
- this.send = async (...data) => {
88
+ this.send = async (...args) => {
89
+ const hasOptions = args[0] && "scheduledAt" in args[0];
90
+ const options = hasOptions ? args[0] : {};
91
+ const data = hasOptions ? args.slice(1) : args;
89
92
  const messages = data.map((item) => ({
90
93
  phones: (Array.isArray(item.phone) ? item.phone : [item.phone]).map(normalizePhoneNumber),
91
94
  message: item.message
92
95
  }));
93
- const response = await this._requester.post("/api/sms/bulk", { body: { messages } });
94
- if (!response.data || !Array.isArray(response.data) || response.data.length === 0) {
95
- throw new Error("Invalid response: no SMS IDs returned");
96
- }
97
- if (!response.notifTaskId) {
98
- throw new Error("Invalid response: no notifTaskId returned");
99
- }
100
- return new Task(response.notifTaskId, this._requester);
96
+ const body = { messages };
97
+ if (options.scheduledAt) body.scheduledAt = options.scheduledAt;
98
+ const response = await this._requester.post("/api/sms/bulk", { body });
99
+ return new Task(response._id, this._requester);
101
100
  };
102
101
  this.getTask = (taskId) => new Task(taskId, this._requester);
103
102
  this._config = config;
104
103
  this._requester = createRequester(config);
105
104
  instances[name] = this;
106
105
  }
107
- static config(nameAndConfig) {
108
- return new _Ariari(nameAndConfig);
109
- }
110
106
  };
107
+ _Ariari.config = (nameAndConfig) => new _Ariari(nameAndConfig);
111
108
  _Ariari.init = _Ariari.config;
112
109
  _Ariari.get = (name = "main") => {
113
110
  if (!instances[name]) throw new Error(`The instance of Ariari with the name "${name}" doesn't exist yet. Call Ariari.config(... )`);
114
111
  return instances[name];
115
112
  };
116
- _Ariari.send = async (...data) => await _Ariari.get("main")?.send(...data);
113
+ _Ariari.send = async (...args) => await _Ariari.get("main")?.send(...args);
117
114
  _Ariari.getTask = async (taskId) => _Ariari.get("main")?.getTask(taskId);
118
115
  var Ariari = _Ariari;
119
116
  var src_default = Ariari;
package/dist/index.mjs CHANGED
@@ -48,7 +48,7 @@ var Task = class {
48
48
  this.id = id;
49
49
  this._requester = requester;
50
50
  }
51
- async get(count, page) {
51
+ async status(count, page) {
52
52
  if (count === void 0) {
53
53
  const response = await this._requester.get(`/api/notif-task/${this.id}`);
54
54
  return response.status;
@@ -59,35 +59,32 @@ var Task = class {
59
59
  };
60
60
  var _Ariari = class _Ariari {
61
61
  constructor({ name = "main", ...config }) {
62
- this.send = async (...data) => {
62
+ this.send = async (...args) => {
63
+ const hasOptions = args[0] && "scheduledAt" in args[0];
64
+ const options = hasOptions ? args[0] : {};
65
+ const data = hasOptions ? args.slice(1) : args;
63
66
  const messages = data.map((item) => ({
64
67
  phones: (Array.isArray(item.phone) ? item.phone : [item.phone]).map(normalizePhoneNumber),
65
68
  message: item.message
66
69
  }));
67
- const response = await this._requester.post("/api/sms/bulk", { body: { messages } });
68
- if (!response.data || !Array.isArray(response.data) || response.data.length === 0) {
69
- throw new Error("Invalid response: no SMS IDs returned");
70
- }
71
- if (!response.notifTaskId) {
72
- throw new Error("Invalid response: no notifTaskId returned");
73
- }
74
- return new Task(response.notifTaskId, this._requester);
70
+ const body = { messages };
71
+ if (options.scheduledAt) body.scheduledAt = options.scheduledAt;
72
+ const response = await this._requester.post("/api/sms/bulk", { body });
73
+ return new Task(response._id, this._requester);
75
74
  };
76
75
  this.getTask = (taskId) => new Task(taskId, this._requester);
77
76
  this._config = config;
78
77
  this._requester = createRequester(config);
79
78
  instances[name] = this;
80
79
  }
81
- static config(nameAndConfig) {
82
- return new _Ariari(nameAndConfig);
83
- }
84
80
  };
81
+ _Ariari.config = (nameAndConfig) => new _Ariari(nameAndConfig);
85
82
  _Ariari.init = _Ariari.config;
86
83
  _Ariari.get = (name = "main") => {
87
84
  if (!instances[name]) throw new Error(`The instance of Ariari with the name "${name}" doesn't exist yet. Call Ariari.config(... )`);
88
85
  return instances[name];
89
86
  };
90
- _Ariari.send = async (...data) => await _Ariari.get("main")?.send(...data);
87
+ _Ariari.send = async (...args) => await _Ariari.get("main")?.send(...args);
91
88
  _Ariari.getTask = async (taskId) => _Ariari.get("main")?.getTask(taskId);
92
89
  var Ariari = _Ariari;
93
90
  var src_default = Ariari;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ariary/notification",
3
- "version": "3.0.2",
3
+ "version": "3.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",
@@ -16,7 +16,8 @@
16
16
  "dist"
17
17
  ],
18
18
  "scripts": {
19
- "build": "tsup"
19
+ "build": "tsup",
20
+ "test": "node --env-file=.env node_modules/.bin/tsx test.ts"
20
21
  },
21
22
  "keywords": [
22
23
  "ariary",
@@ -28,7 +29,9 @@
28
29
  "license": "ISC",
29
30
  "dependencies": {},
30
31
  "devDependencies": {
32
+ "@types/node": "^25.3.0",
31
33
  "tsup": "^8.5.1",
34
+ "tsx": "^4.21.0",
32
35
  "typescript": "^5.9.3"
33
36
  }
34
37
  }