@ariary/notification 3.0.2 → 3.0.4

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
@@ -1,6 +1,6 @@
1
1
  type Data = {
2
- body?: Record<string, any>;
3
- params?: Record<string, any>;
2
+ body?: Record<string, unknown>;
3
+ params?: Record<string, string>;
4
4
  public?: boolean;
5
5
  };
6
6
  type PData = Omit<Data, 'body'>;
@@ -10,17 +10,20 @@ type Config = {
10
10
  baseUrl?: string;
11
11
  };
12
12
  declare const createRequester: (config: Config) => {
13
- get: <T = any>(url: string, data?: PData) => Promise<T>;
14
- post: <T = any>(url: string, data?: Data) => Promise<T>;
15
- patch: <T = any>(url: string, data?: Data) => Promise<T>;
16
- put: <T = any>(url: string, data?: Data) => Promise<T>;
17
- delete: <T = any>(url: string, data?: PData) => Promise<T>;
13
+ get: <T>(url: string, data?: PData) => Promise<T>;
14
+ post: <T>(url: string, data?: Data) => Promise<T>;
15
+ patch: <T>(url: string, data?: Data) => Promise<T>;
16
+ put: <T>(url: string, data?: Data) => Promise<T>;
17
+ delete: <T = void>(url: string, data?: PData) => Promise<T>;
18
18
  };
19
19
 
20
20
  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;
@@ -32,6 +35,7 @@ type TaskResponse = {
32
35
  _id: string;
33
36
  projectId: string;
34
37
  status: TaskStatus;
38
+ statusPage: TaskStatus;
35
39
  createdAt: string;
36
40
  scheduledAt?: string;
37
41
  };
@@ -52,21 +56,23 @@ declare class Task {
52
56
  id: string;
53
57
  private _requester;
54
58
  constructor(id: string, requester: ReturnType<typeof createRequester>);
55
- get(): Promise<TaskStatus>;
56
- get(count: number, page?: number): Promise<TaskWithDetails>;
59
+ status(): Promise<TaskStatus>;
60
+ status(count: number, page?: number): Promise<TaskWithDetails>;
57
61
  }
58
62
  declare class Ariari {
59
63
  private _config;
60
64
  private _requester;
61
65
  private constructor();
62
- static config(nameAndConfig: Config & {
66
+ static config: (nameAndConfig: Config & {
67
+ name?: string;
68
+ }) => Ariari;
69
+ static init: (nameAndConfig: Config & {
63
70
  name?: string;
64
- }): Ariari;
65
- static init: typeof Ariari.config;
71
+ }) => Ariari;
66
72
  static get: (name?: string) => Ariari;
67
- send: (...data: Message[]) => Promise<Task>;
73
+ send: (...args: [SendOptions, ...Message[]] | Message[]) => Promise<Task>;
68
74
  getTask: (taskId: string) => Task;
69
- static send: (...data: Message[]) => Promise<Task>;
75
+ static send: (...args: [SendOptions, ...Message[]] | Message[]) => Promise<Task>;
70
76
  static getTask: (taskId: string) => Promise<Task>;
71
77
  }
72
78
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  type Data = {
2
- body?: Record<string, any>;
3
- params?: Record<string, any>;
2
+ body?: Record<string, unknown>;
3
+ params?: Record<string, string>;
4
4
  public?: boolean;
5
5
  };
6
6
  type PData = Omit<Data, 'body'>;
@@ -10,17 +10,20 @@ type Config = {
10
10
  baseUrl?: string;
11
11
  };
12
12
  declare const createRequester: (config: Config) => {
13
- get: <T = any>(url: string, data?: PData) => Promise<T>;
14
- post: <T = any>(url: string, data?: Data) => Promise<T>;
15
- patch: <T = any>(url: string, data?: Data) => Promise<T>;
16
- put: <T = any>(url: string, data?: Data) => Promise<T>;
17
- delete: <T = any>(url: string, data?: PData) => Promise<T>;
13
+ get: <T>(url: string, data?: PData) => Promise<T>;
14
+ post: <T>(url: string, data?: Data) => Promise<T>;
15
+ patch: <T>(url: string, data?: Data) => Promise<T>;
16
+ put: <T>(url: string, data?: Data) => Promise<T>;
17
+ delete: <T = void>(url: string, data?: PData) => Promise<T>;
18
18
  };
19
19
 
20
20
  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;
@@ -32,6 +35,7 @@ type TaskResponse = {
32
35
  _id: string;
33
36
  projectId: string;
34
37
  status: TaskStatus;
38
+ statusPage: TaskStatus;
35
39
  createdAt: string;
36
40
  scheduledAt?: string;
37
41
  };
@@ -52,21 +56,23 @@ declare class Task {
52
56
  id: string;
53
57
  private _requester;
54
58
  constructor(id: string, requester: ReturnType<typeof createRequester>);
55
- get(): Promise<TaskStatus>;
56
- get(count: number, page?: number): Promise<TaskWithDetails>;
59
+ status(): Promise<TaskStatus>;
60
+ status(count: number, page?: number): Promise<TaskWithDetails>;
57
61
  }
58
62
  declare class Ariari {
59
63
  private _config;
60
64
  private _requester;
61
65
  private constructor();
62
- static config(nameAndConfig: Config & {
66
+ static config: (nameAndConfig: Config & {
67
+ name?: string;
68
+ }) => Ariari;
69
+ static init: (nameAndConfig: Config & {
63
70
  name?: string;
64
- }): Ariari;
65
- static init: typeof Ariari.config;
71
+ }) => Ariari;
66
72
  static get: (name?: string) => Ariari;
67
- send: (...data: Message[]) => Promise<Task>;
73
+ send: (...args: [SendOptions, ...Message[]] | Message[]) => Promise<Task>;
68
74
  getTask: (taskId: string) => Task;
69
- static send: (...data: Message[]) => Promise<Task>;
75
+ static send: (...args: [SendOptions, ...Message[]] | Message[]) => Promise<Task>;
70
76
  static getTask: (taskId: string) => Promise<Task>;
71
77
  }
72
78
 
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,33 @@ var Task = class {
85
85
  };
86
86
  var _Ariari = class _Ariari {
87
87
  constructor({ name = "main", ...config }) {
88
- this.send = async (...data) => {
89
- const messages = data.map((item) => ({
90
- phones: (Array.isArray(item.phone) ? item.phone : [item.phone]).map(normalizePhoneNumber),
91
- message: item.message
92
- }));
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);
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;
92
+ const body = {
93
+ messages: data.map((item) => ({
94
+ phones: (Array.isArray(item.phone) ? item.phone : [item.phone]).map(normalizePhoneNumber),
95
+ message: item.message
96
+ })),
97
+ ...options.scheduledAt && { scheduledAt: options.scheduledAt }
98
+ };
99
+ const response = await this._requester.post("/api/sms/bulk", { body });
100
+ return new Task(response._id, this._requester);
101
101
  };
102
102
  this.getTask = (taskId) => new Task(taskId, this._requester);
103
103
  this._config = config;
104
104
  this._requester = createRequester(config);
105
105
  instances[name] = this;
106
106
  }
107
- static config(nameAndConfig) {
108
- return new _Ariari(nameAndConfig);
109
- }
110
107
  };
108
+ _Ariari.config = (nameAndConfig) => new _Ariari(nameAndConfig);
111
109
  _Ariari.init = _Ariari.config;
112
110
  _Ariari.get = (name = "main") => {
113
111
  if (!instances[name]) throw new Error(`The instance of Ariari with the name "${name}" doesn't exist yet. Call Ariari.config(... )`);
114
112
  return instances[name];
115
113
  };
116
- _Ariari.send = async (...data) => await _Ariari.get("main")?.send(...data);
114
+ _Ariari.send = async (...args) => await _Ariari.get("main")?.send(...args);
117
115
  _Ariari.getTask = async (taskId) => _Ariari.get("main")?.getTask(taskId);
118
116
  var Ariari = _Ariari;
119
117
  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,33 @@ var Task = class {
59
59
  };
60
60
  var _Ariari = class _Ariari {
61
61
  constructor({ name = "main", ...config }) {
62
- this.send = async (...data) => {
63
- const messages = data.map((item) => ({
64
- phones: (Array.isArray(item.phone) ? item.phone : [item.phone]).map(normalizePhoneNumber),
65
- message: item.message
66
- }));
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);
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;
66
+ const body = {
67
+ messages: data.map((item) => ({
68
+ phones: (Array.isArray(item.phone) ? item.phone : [item.phone]).map(normalizePhoneNumber),
69
+ message: item.message
70
+ })),
71
+ ...options.scheduledAt && { scheduledAt: options.scheduledAt }
72
+ };
73
+ const response = await this._requester.post("/api/sms/bulk", { body });
74
+ return new Task(response._id, this._requester);
75
75
  };
76
76
  this.getTask = (taskId) => new Task(taskId, this._requester);
77
77
  this._config = config;
78
78
  this._requester = createRequester(config);
79
79
  instances[name] = this;
80
80
  }
81
- static config(nameAndConfig) {
82
- return new _Ariari(nameAndConfig);
83
- }
84
81
  };
82
+ _Ariari.config = (nameAndConfig) => new _Ariari(nameAndConfig);
85
83
  _Ariari.init = _Ariari.config;
86
84
  _Ariari.get = (name = "main") => {
87
85
  if (!instances[name]) throw new Error(`The instance of Ariari with the name "${name}" doesn't exist yet. Call Ariari.config(... )`);
88
86
  return instances[name];
89
87
  };
90
- _Ariari.send = async (...data) => await _Ariari.get("main")?.send(...data);
88
+ _Ariari.send = async (...args) => await _Ariari.get("main")?.send(...args);
91
89
  _Ariari.getTask = async (taskId) => _Ariari.get("main")?.getTask(taskId);
92
90
  var Ariari = _Ariari;
93
91
  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.4",
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
  }