@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/dist/index.mjs CHANGED
@@ -1,220 +1,133 @@
1
- // src/client.ts
2
- import axios from "axios";
3
- var ApiClient = class {
4
- constructor(config, baseUrl) {
5
- this.config = config;
6
- const finalBaseUrl = baseUrl || config.baseUrl || "https://back.ariari.mg/payment/api-docs";
7
- this.client = axios.create({
8
- baseURL: finalBaseUrl,
9
- headers: {
10
- "Content-Type": "application/json"
11
- }
12
- });
13
- }
14
- /**
15
- * Effectue une requête POST avec les en-têtes d'authentification
16
- */
17
- async post(endpoint, data, requiresSecret = true) {
18
- const headers = {
19
- "x-project-id": this.config.projectId
20
- };
21
- if (requiresSecret) {
22
- headers["x-secret-id"] = this.config.secretId;
23
- }
24
- try {
25
- const response = await this.client.post(endpoint, data, { headers });
26
- return response.data;
27
- } catch (error) {
28
- throw this.handleError(error);
29
- }
30
- }
31
- /**
32
- * Effectue une requête GET avec les en-têtes d'authentification
33
- */
34
- async get(endpoint, requiresSecret = true) {
35
- const headers = {
36
- "x-project-id": this.config.projectId
37
- };
38
- if (requiresSecret) {
39
- headers["x-secret-id"] = this.config.secretId;
40
- }
41
- try {
42
- const response = await this.client.get(endpoint, { headers });
43
- return response.data;
44
- } catch (error) {
45
- throw this.handleError(error);
46
- }
47
- }
48
- /**
49
- * Effectue une requête PATCH avec les en-têtes d'authentification
50
- */
51
- async patch(endpoint, data, requiresSecret = true) {
52
- const headers = {
53
- "x-project-id": this.config.projectId
54
- };
55
- if (requiresSecret) {
56
- headers["x-secret-id"] = this.config.secretId;
57
- }
58
- try {
59
- const response = await this.client.patch(endpoint, data, { headers });
60
- return response.data;
61
- } catch (error) {
62
- throw this.handleError(error);
63
- }
64
- }
65
- /**
66
- * Effectue une requête PUT avec les en-têtes d'authentification
67
- */
68
- async put(endpoint, data, requiresSecret = true) {
69
- const headers = {
70
- "x-project-id": this.config.projectId
71
- };
72
- if (requiresSecret) {
73
- headers["x-secret-id"] = this.config.secretId;
74
- }
75
- try {
76
- const response = await this.client.put(endpoint, data, { headers });
77
- return response.data;
78
- } catch (error) {
79
- throw this.handleError(error);
80
- }
81
- }
82
- /**
83
- * Effectue une requête DELETE avec les en-têtes d'authentification
84
- */
85
- async delete(endpoint, requiresSecret = true) {
86
- const headers = {
87
- "x-project-id": this.config.projectId
88
- };
89
- if (requiresSecret) {
90
- headers["x-secret-id"] = this.config.secretId;
91
- }
92
- try {
93
- const response = await this.client.delete(endpoint, { headers });
94
- return response.data;
95
- } catch (error) {
96
- throw this.handleError(error);
1
+ // src/config/index.ts
2
+ var config = null;
3
+ function setConfig(cfg) {
4
+ config = cfg;
5
+ }
6
+ function getConfig() {
7
+ return config;
8
+ }
9
+
10
+ // src/http/index.ts
11
+ async function request(method, endpoint, options = {}) {
12
+ const config2 = getConfig();
13
+ if (!config2) {
14
+ throw new Error("Ariari not configured. Call Ariari.config() first.");
15
+ }
16
+ const baseUrl = config2.baseUrl || "https://back.ariari.mg";
17
+ const url = `${baseUrl}${endpoint}`;
18
+ const headers = {
19
+ "Content-Type": "application/json",
20
+ "x-project-id": config2.projectId
21
+ };
22
+ if (options.requiresSecret !== false) {
23
+ headers["x-secret-id"] = config2.secretId;
24
+ }
25
+ const fetchOptions = {
26
+ method,
27
+ headers
28
+ };
29
+ if (options.body && (method === "POST" || method === "PATCH" || method === "PUT")) {
30
+ fetchOptions.body = JSON.stringify(options.body);
31
+ }
32
+ try {
33
+ const response = await fetch(url, fetchOptions);
34
+ const data = await response.json();
35
+ if (!response.ok) {
36
+ const message = data?.message || "Unknown error";
37
+ throw new Error(`[${response.status}] ${message}`);
97
38
  }
98
- }
99
- /**
100
- * Gère les erreurs API
101
- */
102
- handleError(error) {
103
- if (error.response) {
104
- const status = error.response.status;
105
- const message = error.response.data?.message || error.response.statusText;
106
- return new Error(`[${status}] ${message}`);
39
+ return data;
40
+ } catch (error) {
41
+ if (error instanceof Error) {
42
+ throw error;
107
43
  }
108
- return error;
109
- }
110
- };
44
+ throw new Error("Network error");
45
+ }
46
+ }
47
+ async function httpGet(endpoint, requiresSecret = true) {
48
+ return request("GET", endpoint, { requiresSecret });
49
+ }
50
+ async function httpPost(endpoint, body, requiresSecret = true) {
51
+ return request("POST", endpoint, { body, requiresSecret });
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
+ }
111
59
 
112
- // src/sms.ts
113
- var SmsService = class {
114
- constructor(client) {
115
- this.client = client;
116
- }
117
- async notify(message, numbers) {
118
- const phones = Array.isArray(numbers) ? numbers : [numbers];
119
- const response = await this.client.post(
120
- "/api/sms/multi",
121
- { phones, message },
122
- true
123
- );
124
- return response;
125
- }
126
- async notifyBulk(messages) {
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) {
127
70
  const bulkMessages = messages.map((item) => ({
128
71
  message: item.message,
129
- phones: Array.isArray(item.numbers) ? item.numbers : [item.numbers]
72
+ phones: Array.isArray(item.phone) ? item.phone : [item.phone]
130
73
  }));
131
- const response = await this.client.post(
132
- "/api/sms/bulk",
133
- { messages: bulkMessages },
134
- true
135
- );
136
- return response;
137
- }
74
+ return httpPost("/api/sms/bulk", {
75
+ messages: bulkMessages
76
+ });
77
+ },
138
78
  async getAll() {
139
- const response = await this.client.get(
140
- "/api/sms",
141
- true
142
- );
143
- return response;
79
+ return httpGet("/api/sms");
144
80
  }
145
81
  };
146
-
147
- // src/notif-task.ts
148
- var NotifTaskService = class {
149
- constructor(client) {
150
- this.client = client;
151
- }
152
- async create(createNotifTaskDto) {
153
- const response = await this.client.post(
154
- "/api/notif-task",
155
- createNotifTaskDto,
156
- true
157
- );
158
- return response;
159
- }
82
+ var notifTaskApi = {
160
83
  async findAll(projectId) {
161
- const response = await this.client.get(
162
- `/api/notif-task?projectId=${projectId}`,
163
- true
164
- );
165
- return response;
166
- }
84
+ return httpGet(`/api/notif-task?projectId=${projectId}`);
85
+ },
167
86
  async findOne(id) {
168
- const response = await this.client.get(
169
- `/api/notif-task/${id}`,
170
- true
171
- );
172
- return response;
173
- }
174
- async update(id, updateNotifTaskDto) {
175
- const response = await this.client.patch(
176
- `/api/notif-task/${id}`,
177
- updateNotifTaskDto,
178
- true
179
- );
180
- return response;
181
- }
182
- async remove(id) {
183
- const response = await this.client.delete(
184
- `/api/notif-task/${id}`,
185
- true
186
- );
187
- return response;
188
- }
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
+ },
189
95
  async getSmsDetails(id) {
190
- const response = await this.client.get(
191
- `/api/notif-task/${id}/sms-details`,
192
- true
193
- );
194
- return response;
195
- }
96
+ return httpGet(`/api/notif-task/${id}/sms-details`);
97
+ },
196
98
  async retryFailedSms(id) {
197
- const response = await this.client.post(
99
+ return httpPost(
198
100
  `/api/notif-task/${id}/retry-failed-sms`,
199
- {},
200
- true
101
+ {}
201
102
  );
202
- return response;
203
103
  }
204
104
  };
105
+ var notificationService = {
106
+ ...smsApi,
107
+ task: notifTaskApi
108
+ };
205
109
 
206
110
  // src/index.ts
207
- var SmsSdk = class {
208
- constructor(config) {
209
- const finalConfig = { ...config, baseUrl: config.baseUrl || "https://back.ariari.mg/payment/api-docs" };
210
- this.client = new ApiClient(finalConfig);
211
- this.sms = new SmsService(this.client);
212
- this.notifTask = new NotifTaskService(this.client);
111
+ var AriariBridge = class _AriariBridge {
112
+ constructor() {
113
+ }
114
+ static getInstance() {
115
+ if (!_AriariBridge.instance) {
116
+ _AriariBridge.instance = new _AriariBridge();
117
+ }
118
+ return _AriariBridge.instance;
119
+ }
120
+ config(cfg) {
121
+ setConfig(cfg);
122
+ }
123
+ get notification() {
124
+ return notificationService;
213
125
  }
214
126
  };
127
+ var Ariari = AriariBridge.getInstance();
215
128
  export {
216
- ApiClient,
217
- NotifTaskService,
218
- SmsSdk,
219
- SmsService
129
+ Ariari,
130
+ getConfig,
131
+ notificationService,
132
+ setConfig
220
133
  };
package/package.json CHANGED
@@ -1,68 +1,49 @@
1
- {
2
- "name": "@ariary/notification",
3
- "version": "1.0.1",
4
- "description": "SMS et Notification Task SDK pour l'API Ariary",
5
- "main": "dist/index.js",
6
- "module": "dist/index.mjs",
7
- "types": "dist/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "types": "./dist/index.d.ts",
11
- "import": "./dist/index.mjs",
12
- "require": "./dist/index.js"
13
- },
14
- "./sms": {
15
- "types": "./dist/sms/index.d.ts",
16
- "import": "./dist/sms/index.mjs",
17
- "require": "./dist/sms/index.js"
18
- },
19
- "./notif-task": {
20
- "types": "./dist/notif-task/index.d.ts",
21
- "import": "./dist/notif-task/index.mjs",
22
- "require": "./dist/notif-task/index.js"
23
- }
24
- },
25
- "files": [
26
- "dist"
27
- ],
28
- "tsup": [
29
- {
30
- "entry": {
31
- "index": "src/index.ts",
32
- "sms/index": "src/sms/index.ts",
33
- "notif-task/index": "src/notif-task/index.ts"
34
- },
35
- "format": [
36
- "cjs",
37
- "esm"
38
- ],
39
- "outDir": "dist",
40
- "dts": true,
41
- "splitting": false,
42
- "sourcemap": false,
43
- "clean": true,
44
- "minify": false
45
- }
46
- ],
47
- "scripts": {
48
- "build": "tsup"
49
- },
50
- "keywords": [
51
- "ariary",
52
- "sms",
53
- "notification",
54
- "api"
55
- ],
56
- "author": "Ariary",
57
- "license": "ISC",
58
- "publishConfig": {
59
- "access": "public"
60
- },
61
- "dependencies": {
62
- "axios": "^1.13.2"
63
- },
64
- "devDependencies": {
65
- "tsup": "^8.5.1",
66
- "typescript": "^5.9.3"
67
- }
68
- }
1
+ {
2
+ "name": "@ariary/notification",
3
+ "version": "1.0.2",
4
+ "description": "SMS et Notification Task SDK pour l'API Ariary",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "tsup": {
19
+ "entry": {
20
+ "index": "src/index.ts"
21
+ },
22
+ "format": [
23
+ "cjs",
24
+ "esm"
25
+ ],
26
+ "outDir": "dist",
27
+ "dts": true,
28
+ "splitting": false,
29
+ "sourcemap": false,
30
+ "clean": true,
31
+ "minify": false
32
+ },
33
+ "scripts": {
34
+ "build": "tsup"
35
+ },
36
+ "keywords": [
37
+ "ariary",
38
+ "sms",
39
+ "notification",
40
+ "api"
41
+ ],
42
+ "author": "Ariary",
43
+ "license": "ISC",
44
+ "dependencies": {},
45
+ "devDependencies": {
46
+ "tsup": "^8.5.1",
47
+ "typescript": "^5.9.3"
48
+ }
49
+ }
@@ -1,40 +0,0 @@
1
- /**
2
- * Configuration de l'API
3
- */
4
- interface ApiConfig {
5
- projectId: string;
6
- secretId: string;
7
- baseUrl?: string;
8
- }
9
-
10
- declare class ApiClient {
11
- private client;
12
- private config;
13
- constructor(config: ApiConfig, baseUrl?: string);
14
- /**
15
- * Effectue une requête POST avec les en-têtes d'authentification
16
- */
17
- post<T>(endpoint: string, data: any, requiresSecret?: boolean): Promise<T>;
18
- /**
19
- * Effectue une requête GET avec les en-têtes d'authentification
20
- */
21
- get<T>(endpoint: string, requiresSecret?: boolean): Promise<T>;
22
- /**
23
- * Effectue une requête PATCH avec les en-têtes d'authentification
24
- */
25
- patch<T>(endpoint: string, data: any, requiresSecret?: boolean): Promise<T>;
26
- /**
27
- * Effectue une requête PUT avec les en-têtes d'authentification
28
- */
29
- put<T>(endpoint: string, data: any, requiresSecret?: boolean): Promise<T>;
30
- /**
31
- * Effectue une requête DELETE avec les en-têtes d'authentification
32
- */
33
- delete<T>(endpoint: string, requiresSecret?: boolean): Promise<T>;
34
- /**
35
- * Gère les erreurs API
36
- */
37
- private handleError;
38
- }
39
-
40
- export { type ApiConfig as A, ApiClient as a };
@@ -1,40 +0,0 @@
1
- /**
2
- * Configuration de l'API
3
- */
4
- interface ApiConfig {
5
- projectId: string;
6
- secretId: string;
7
- baseUrl?: string;
8
- }
9
-
10
- declare class ApiClient {
11
- private client;
12
- private config;
13
- constructor(config: ApiConfig, baseUrl?: string);
14
- /**
15
- * Effectue une requête POST avec les en-têtes d'authentification
16
- */
17
- post<T>(endpoint: string, data: any, requiresSecret?: boolean): Promise<T>;
18
- /**
19
- * Effectue une requête GET avec les en-têtes d'authentification
20
- */
21
- get<T>(endpoint: string, requiresSecret?: boolean): Promise<T>;
22
- /**
23
- * Effectue une requête PATCH avec les en-têtes d'authentification
24
- */
25
- patch<T>(endpoint: string, data: any, requiresSecret?: boolean): Promise<T>;
26
- /**
27
- * Effectue une requête PUT avec les en-têtes d'authentification
28
- */
29
- put<T>(endpoint: string, data: any, requiresSecret?: boolean): Promise<T>;
30
- /**
31
- * Effectue une requête DELETE avec les en-têtes d'authentification
32
- */
33
- delete<T>(endpoint: string, requiresSecret?: boolean): Promise<T>;
34
- /**
35
- * Gère les erreurs API
36
- */
37
- private handleError;
38
- }
39
-
40
- export { type ApiConfig as A, ApiClient as a };
@@ -1,59 +0,0 @@
1
- import { a as ApiClient } from '../client-BOI4a9h5.mjs';
2
-
3
- interface CreateNotifTaskDto {
4
- message: string;
5
- phones: string[];
6
- }
7
- interface UpdateNotifTaskDto {
8
- message?: string;
9
- phones?: string[];
10
- }
11
- interface ResponseNotifTaskDto {
12
- id: string;
13
- message: string;
14
- phones: string[];
15
- status: string;
16
- createdAt: string;
17
- updatedAt: string;
18
- }
19
- interface SmsDetail {
20
- id: string;
21
- phone: string;
22
- message: string;
23
- status: string;
24
- attempts: number;
25
- lastAttempt?: string;
26
- createdAt: string;
27
- updatedAt: string;
28
- }
29
- interface NotifTaskDetailsDto {
30
- id: string;
31
- message: string;
32
- status: string;
33
- totalSms: number;
34
- successCount: number;
35
- failedCount: number;
36
- pendingCount: number;
37
- smsDetails: SmsDetail[];
38
- createdAt: string;
39
- updatedAt: string;
40
- }
41
- interface RetryFailedSmsResponseDto {
42
- status: string;
43
- message: string;
44
- retried?: number;
45
- }
46
-
47
- declare class NotifTaskService {
48
- private client;
49
- constructor(client: ApiClient);
50
- create(createNotifTaskDto: CreateNotifTaskDto): Promise<ResponseNotifTaskDto>;
51
- findAll(projectId: string): Promise<ResponseNotifTaskDto[]>;
52
- findOne(id: string): Promise<ResponseNotifTaskDto>;
53
- update(id: string, updateNotifTaskDto: UpdateNotifTaskDto): Promise<ResponseNotifTaskDto>;
54
- remove(id: string): Promise<ResponseNotifTaskDto>;
55
- getSmsDetails(id: string): Promise<NotifTaskDetailsDto>;
56
- retryFailedSms(id: string): Promise<RetryFailedSmsResponseDto>;
57
- }
58
-
59
- export { type CreateNotifTaskDto, type NotifTaskDetailsDto, NotifTaskService, type ResponseNotifTaskDto, type RetryFailedSmsResponseDto, type SmsDetail, type UpdateNotifTaskDto };
@@ -1,59 +0,0 @@
1
- import { a as ApiClient } from '../client-BOI4a9h5.js';
2
-
3
- interface CreateNotifTaskDto {
4
- message: string;
5
- phones: string[];
6
- }
7
- interface UpdateNotifTaskDto {
8
- message?: string;
9
- phones?: string[];
10
- }
11
- interface ResponseNotifTaskDto {
12
- id: string;
13
- message: string;
14
- phones: string[];
15
- status: string;
16
- createdAt: string;
17
- updatedAt: string;
18
- }
19
- interface SmsDetail {
20
- id: string;
21
- phone: string;
22
- message: string;
23
- status: string;
24
- attempts: number;
25
- lastAttempt?: string;
26
- createdAt: string;
27
- updatedAt: string;
28
- }
29
- interface NotifTaskDetailsDto {
30
- id: string;
31
- message: string;
32
- status: string;
33
- totalSms: number;
34
- successCount: number;
35
- failedCount: number;
36
- pendingCount: number;
37
- smsDetails: SmsDetail[];
38
- createdAt: string;
39
- updatedAt: string;
40
- }
41
- interface RetryFailedSmsResponseDto {
42
- status: string;
43
- message: string;
44
- retried?: number;
45
- }
46
-
47
- declare class NotifTaskService {
48
- private client;
49
- constructor(client: ApiClient);
50
- create(createNotifTaskDto: CreateNotifTaskDto): Promise<ResponseNotifTaskDto>;
51
- findAll(projectId: string): Promise<ResponseNotifTaskDto[]>;
52
- findOne(id: string): Promise<ResponseNotifTaskDto>;
53
- update(id: string, updateNotifTaskDto: UpdateNotifTaskDto): Promise<ResponseNotifTaskDto>;
54
- remove(id: string): Promise<ResponseNotifTaskDto>;
55
- getSmsDetails(id: string): Promise<NotifTaskDetailsDto>;
56
- retryFailedSms(id: string): Promise<RetryFailedSmsResponseDto>;
57
- }
58
-
59
- export { type CreateNotifTaskDto, type NotifTaskDetailsDto, NotifTaskService, type ResponseNotifTaskDto, type RetryFailedSmsResponseDto, type SmsDetail, type UpdateNotifTaskDto };