@ariary/notification 1.0.1 → 1.0.2
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 +46 -76
- package/dist/index.d.mts +130 -15
- package/dist/index.d.ts +130 -15
- package/dist/index.js +114 -211
- package/dist/index.mjs +110 -197
- package/package.json +49 -68
- package/dist/client-BOI4a9h5.d.mts +0 -40
- package/dist/client-BOI4a9h5.d.ts +0 -40
- package/dist/notif-task/index.d.mts +0 -59
- package/dist/notif-task/index.d.ts +0 -59
- package/dist/notif-task/index.js +0 -88
- package/dist/notif-task/index.mjs +0 -61
- package/dist/sms/index.d.mts +0 -62
- package/dist/sms/index.d.ts +0 -62
- package/dist/sms/index.js +0 -64
- package/dist/sms/index.mjs +0 -37
package/dist/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,244 +15,149 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/index.ts
|
|
31
21
|
var src_exports = {};
|
|
32
22
|
__export(src_exports, {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
23
|
+
Ariari: () => Ariari,
|
|
24
|
+
getConfig: () => getConfig,
|
|
25
|
+
notificationService: () => notificationService,
|
|
26
|
+
setConfig: () => setConfig
|
|
37
27
|
});
|
|
38
28
|
module.exports = __toCommonJS(src_exports);
|
|
39
29
|
|
|
40
|
-
// src/
|
|
41
|
-
var
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
"
|
|
76
|
-
|
|
77
|
-
if (requiresSecret) {
|
|
78
|
-
headers["x-secret-id"] = this.config.secretId;
|
|
79
|
-
}
|
|
80
|
-
try {
|
|
81
|
-
const response = await this.client.get(endpoint, { headers });
|
|
82
|
-
return response.data;
|
|
83
|
-
} catch (error) {
|
|
84
|
-
throw this.handleError(error);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Effectue une requête PATCH avec les en-têtes d'authentification
|
|
89
|
-
*/
|
|
90
|
-
async patch(endpoint, data, requiresSecret = true) {
|
|
91
|
-
const headers = {
|
|
92
|
-
"x-project-id": this.config.projectId
|
|
93
|
-
};
|
|
94
|
-
if (requiresSecret) {
|
|
95
|
-
headers["x-secret-id"] = this.config.secretId;
|
|
96
|
-
}
|
|
97
|
-
try {
|
|
98
|
-
const response = await this.client.patch(endpoint, data, { headers });
|
|
99
|
-
return response.data;
|
|
100
|
-
} catch (error) {
|
|
101
|
-
throw this.handleError(error);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Effectue une requête PUT avec les en-têtes d'authentification
|
|
106
|
-
*/
|
|
107
|
-
async put(endpoint, data, requiresSecret = true) {
|
|
108
|
-
const headers = {
|
|
109
|
-
"x-project-id": this.config.projectId
|
|
110
|
-
};
|
|
111
|
-
if (requiresSecret) {
|
|
112
|
-
headers["x-secret-id"] = this.config.secretId;
|
|
113
|
-
}
|
|
114
|
-
try {
|
|
115
|
-
const response = await this.client.put(endpoint, data, { headers });
|
|
116
|
-
return response.data;
|
|
117
|
-
} catch (error) {
|
|
118
|
-
throw this.handleError(error);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Effectue une requête DELETE avec les en-têtes d'authentification
|
|
123
|
-
*/
|
|
124
|
-
async delete(endpoint, requiresSecret = true) {
|
|
125
|
-
const headers = {
|
|
126
|
-
"x-project-id": this.config.projectId
|
|
127
|
-
};
|
|
128
|
-
if (requiresSecret) {
|
|
129
|
-
headers["x-secret-id"] = this.config.secretId;
|
|
130
|
-
}
|
|
131
|
-
try {
|
|
132
|
-
const response = await this.client.delete(endpoint, { headers });
|
|
133
|
-
return response.data;
|
|
134
|
-
} catch (error) {
|
|
135
|
-
throw this.handleError(error);
|
|
30
|
+
// src/config/index.ts
|
|
31
|
+
var config = null;
|
|
32
|
+
function setConfig(cfg) {
|
|
33
|
+
config = cfg;
|
|
34
|
+
}
|
|
35
|
+
function getConfig() {
|
|
36
|
+
return config;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/http/index.ts
|
|
40
|
+
async function request(method, endpoint, options = {}) {
|
|
41
|
+
const config2 = getConfig();
|
|
42
|
+
if (!config2) {
|
|
43
|
+
throw new Error("Ariari not configured. Call Ariari.config() first.");
|
|
44
|
+
}
|
|
45
|
+
const baseUrl = config2.baseUrl || "https://back.ariari.mg";
|
|
46
|
+
const url = `${baseUrl}${endpoint}`;
|
|
47
|
+
const headers = {
|
|
48
|
+
"Content-Type": "application/json",
|
|
49
|
+
"x-project-id": config2.projectId
|
|
50
|
+
};
|
|
51
|
+
if (options.requiresSecret !== false) {
|
|
52
|
+
headers["x-secret-id"] = config2.secretId;
|
|
53
|
+
}
|
|
54
|
+
const fetchOptions = {
|
|
55
|
+
method,
|
|
56
|
+
headers
|
|
57
|
+
};
|
|
58
|
+
if (options.body && (method === "POST" || method === "PATCH" || method === "PUT")) {
|
|
59
|
+
fetchOptions.body = JSON.stringify(options.body);
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const response = await fetch(url, fetchOptions);
|
|
63
|
+
const data = await response.json();
|
|
64
|
+
if (!response.ok) {
|
|
65
|
+
const message = data?.message || "Unknown error";
|
|
66
|
+
throw new Error(`[${response.status}] ${message}`);
|
|
136
67
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
handleError(error) {
|
|
142
|
-
if (error.response) {
|
|
143
|
-
const status = error.response.status;
|
|
144
|
-
const message = error.response.data?.message || error.response.statusText;
|
|
145
|
-
return new Error(`[${status}] ${message}`);
|
|
68
|
+
return data;
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (error instanceof Error) {
|
|
71
|
+
throw error;
|
|
146
72
|
}
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
}
|
|
73
|
+
throw new Error("Network error");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async function httpGet(endpoint, requiresSecret = true) {
|
|
77
|
+
return request("GET", endpoint, { requiresSecret });
|
|
78
|
+
}
|
|
79
|
+
async function httpPost(endpoint, body, requiresSecret = true) {
|
|
80
|
+
return request("POST", endpoint, { body, requiresSecret });
|
|
81
|
+
}
|
|
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
|
+
}
|
|
150
88
|
|
|
151
|
-
// src/
|
|
152
|
-
var
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
true
|
|
162
|
-
);
|
|
163
|
-
return response;
|
|
164
|
-
}
|
|
165
|
-
async notifyBulk(messages) {
|
|
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) {
|
|
166
99
|
const bulkMessages = messages.map((item) => ({
|
|
167
100
|
message: item.message,
|
|
168
|
-
phones: Array.isArray(item.
|
|
101
|
+
phones: Array.isArray(item.phone) ? item.phone : [item.phone]
|
|
169
102
|
}));
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
);
|
|
175
|
-
return response;
|
|
176
|
-
}
|
|
103
|
+
return httpPost("/api/sms/bulk", {
|
|
104
|
+
messages: bulkMessages
|
|
105
|
+
});
|
|
106
|
+
},
|
|
177
107
|
async getAll() {
|
|
178
|
-
|
|
179
|
-
"/api/sms",
|
|
180
|
-
true
|
|
181
|
-
);
|
|
182
|
-
return response;
|
|
108
|
+
return httpGet("/api/sms");
|
|
183
109
|
}
|
|
184
110
|
};
|
|
185
|
-
|
|
186
|
-
// src/notif-task.ts
|
|
187
|
-
var NotifTaskService = class {
|
|
188
|
-
constructor(client) {
|
|
189
|
-
this.client = client;
|
|
190
|
-
}
|
|
191
|
-
async create(createNotifTaskDto) {
|
|
192
|
-
const response = await this.client.post(
|
|
193
|
-
"/api/notif-task",
|
|
194
|
-
createNotifTaskDto,
|
|
195
|
-
true
|
|
196
|
-
);
|
|
197
|
-
return response;
|
|
198
|
-
}
|
|
111
|
+
var notifTaskApi = {
|
|
199
112
|
async findAll(projectId) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
true
|
|
203
|
-
);
|
|
204
|
-
return response;
|
|
205
|
-
}
|
|
113
|
+
return httpGet(`/api/notif-task?projectId=${projectId}`);
|
|
114
|
+
},
|
|
206
115
|
async findOne(id) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
);
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
`/api/notif-task/${id}`,
|
|
216
|
-
updateNotifTaskDto,
|
|
217
|
-
true
|
|
218
|
-
);
|
|
219
|
-
return response;
|
|
220
|
-
}
|
|
221
|
-
async remove(id) {
|
|
222
|
-
const response = await this.client.delete(
|
|
223
|
-
`/api/notif-task/${id}`,
|
|
224
|
-
true
|
|
225
|
-
);
|
|
226
|
-
return response;
|
|
227
|
-
}
|
|
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
|
+
},
|
|
228
124
|
async getSmsDetails(id) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
true
|
|
232
|
-
);
|
|
233
|
-
return response;
|
|
234
|
-
}
|
|
125
|
+
return httpGet(`/api/notif-task/${id}/sms-details`);
|
|
126
|
+
},
|
|
235
127
|
async retryFailedSms(id) {
|
|
236
|
-
|
|
128
|
+
return httpPost(
|
|
237
129
|
`/api/notif-task/${id}/retry-failed-sms`,
|
|
238
|
-
{}
|
|
239
|
-
true
|
|
130
|
+
{}
|
|
240
131
|
);
|
|
241
|
-
return response;
|
|
242
132
|
}
|
|
243
133
|
};
|
|
134
|
+
var notificationService = {
|
|
135
|
+
...smsApi,
|
|
136
|
+
task: notifTaskApi
|
|
137
|
+
};
|
|
244
138
|
|
|
245
139
|
// src/index.ts
|
|
246
|
-
var
|
|
247
|
-
constructor(
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
140
|
+
var AriariBridge = class _AriariBridge {
|
|
141
|
+
constructor() {
|
|
142
|
+
}
|
|
143
|
+
static getInstance() {
|
|
144
|
+
if (!_AriariBridge.instance) {
|
|
145
|
+
_AriariBridge.instance = new _AriariBridge();
|
|
146
|
+
}
|
|
147
|
+
return _AriariBridge.instance;
|
|
148
|
+
}
|
|
149
|
+
config(cfg) {
|
|
150
|
+
setConfig(cfg);
|
|
151
|
+
}
|
|
152
|
+
get notification() {
|
|
153
|
+
return notificationService;
|
|
252
154
|
}
|
|
253
155
|
};
|
|
156
|
+
var Ariari = AriariBridge.getInstance();
|
|
254
157
|
// Annotate the CommonJS export names for ESM import in node:
|
|
255
158
|
0 && (module.exports = {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
159
|
+
Ariari,
|
|
160
|
+
getConfig,
|
|
161
|
+
notificationService,
|
|
162
|
+
setConfig
|
|
260
163
|
});
|