@ariary/notification 1.0.6 → 1.0.8

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,46 +1,2 @@
1
- interface ApiConfig {
2
- projectId: string;
3
- secretId: string;
4
- baseUrl?: string;
5
- }
6
1
 
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
- }
23
- declare class AriariBridge {
24
- private static instance;
25
- private constructor();
26
- static getInstance(): AriariBridge;
27
- config(cfg: ApiConfig): void;
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;
43
- }
44
- declare const Ariari: AriariBridge;
45
-
46
- export { Ariari as default };
2
+ export { }
package/dist/index.d.ts CHANGED
@@ -1,46 +1,2 @@
1
- interface ApiConfig {
2
- projectId: string;
3
- secretId: string;
4
- baseUrl?: string;
5
- }
6
1
 
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
- }
23
- declare class AriariBridge {
24
- private static instance;
25
- private constructor();
26
- static getInstance(): AriariBridge;
27
- config(cfg: ApiConfig): void;
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;
43
- }
44
- declare const Ariari: AriariBridge;
45
-
46
- export { Ariari as default };
2
+ export { }
package/dist/index.js CHANGED
@@ -1,118 +1 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- default: () => src_default
24
- });
25
- module.exports = __toCommonJS(src_exports);
26
-
27
- // src/config/index.ts
28
- var config = null;
29
- function setConfig(cfg) {
30
- config = cfg;
31
- }
32
- function getConfig() {
33
- return config;
34
- }
35
-
36
- // src/http/index.ts
37
- async function request(method, endpoint, options = {}) {
38
- const config2 = getConfig();
39
- if (!config2) {
40
- throw new Error("Ariari not configured. Call Ariari.config() first.");
41
- }
42
- const baseUrl = config2.baseUrl || "https://back.ariari.mg";
43
- const url = `${baseUrl}${endpoint}`;
44
- const headers = {
45
- "Content-Type": "application/json",
46
- "x-project-id": config2.projectId
47
- };
48
- if (options.requiresSecret !== false) {
49
- headers["x-secret-id"] = config2.secretId;
50
- }
51
- const fetchOptions = {
52
- method,
53
- headers
54
- };
55
- if (options.body && (method === "POST" || method === "PATCH" || method === "PUT")) {
56
- fetchOptions.body = JSON.stringify(options.body);
57
- }
58
- try {
59
- const response = await fetch(url, fetchOptions);
60
- const data = await response.json();
61
- if (!response.ok) {
62
- const message = data?.message || "Unknown error";
63
- throw new Error(`[${response.status}] ${message}`);
64
- }
65
- return data;
66
- } catch (error) {
67
- if (error instanceof Error) {
68
- throw error;
69
- }
70
- throw new Error("Network error");
71
- }
72
- }
73
- async function httpGet(endpoint, requiresSecret = true) {
74
- return request("GET", endpoint, { requiresSecret });
75
- }
76
- async function httpPost(endpoint, body, requiresSecret = true) {
77
- return request("POST", endpoint, { body, requiresSecret });
78
- }
79
-
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;
86
- }
87
- };
88
- var AriariBridge = class _AriariBridge {
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;
98
- }
99
- static getInstance() {
100
- if (!_AriariBridge.instance) {
101
- _AriariBridge.instance = new _AriariBridge();
102
- }
103
- return _AriariBridge.instance;
104
- }
105
- config(cfg) {
106
- setConfig(cfg);
107
- }
108
- async send(...data) {
109
- const messages = data.map((item) => ({
110
- phones: Array.isArray(item.phone) ? item.phone : [item.phone],
111
- message: item.message
112
- }));
113
- const one = await httpPost("/api/sms/bulk", { messages });
114
- return new Task(one.id);
115
- }
116
- };
117
- var Ariari = AriariBridge.getInstance();
118
- var src_default = Ariari;
package/dist/index.mjs CHANGED
@@ -1,95 +0,0 @@
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}`);
38
- }
39
- return data;
40
- } catch (error) {
41
- if (error instanceof Error) {
42
- throw error;
43
- }
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
-
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;
60
- }
61
- };
62
- var AriariBridge = class _AriariBridge {
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;
72
- }
73
- static getInstance() {
74
- if (!_AriariBridge.instance) {
75
- _AriariBridge.instance = new _AriariBridge();
76
- }
77
- return _AriariBridge.instance;
78
- }
79
- config(cfg) {
80
- setConfig(cfg);
81
- }
82
- async send(...data) {
83
- const messages = data.map((item) => ({
84
- phones: Array.isArray(item.phone) ? item.phone : [item.phone],
85
- message: item.message
86
- }));
87
- const one = await httpPost("/api/sms/bulk", { messages });
88
- return new Task(one.id);
89
- }
90
- };
91
- var Ariari = AriariBridge.getInstance();
92
- var src_default = Ariari;
93
- export {
94
- src_default as default
95
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ariary/notification",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "SMS et Notification Task SDK pour l'API Ariary",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",