@ariary/notification 1.0.9 → 2.0.0

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.js CHANGED
@@ -80,6 +80,13 @@ async function httpPost(endpoint, body, requiresSecret = true) {
80
80
  }
81
81
 
82
82
  // src/index.ts
83
+ function normalizePhoneNumber(phone) {
84
+ let normalized = phone.replace(/\D/g, "");
85
+ if (normalized.startsWith("261")) {
86
+ normalized = "0" + normalized.slice(3);
87
+ }
88
+ return normalized;
89
+ }
83
90
  var Task = class {
84
91
  constructor(id) {
85
92
  this.id = id;
@@ -94,7 +101,7 @@ var Task = class {
94
101
  var Notification = class {
95
102
  async send(...data) {
96
103
  const messages = data.map((item) => ({
97
- phones: Array.isArray(item.phone) ? item.phone : [item.phone],
104
+ phones: (Array.isArray(item.phone) ? item.phone : [item.phone]).map(normalizePhoneNumber),
98
105
  message: item.message
99
106
  }));
100
107
  const response = await httpPost("/api/sms/bulk", { messages });
package/dist/index.mjs CHANGED
@@ -52,6 +52,13 @@ async function httpPost(endpoint, body, requiresSecret = true) {
52
52
  }
53
53
 
54
54
  // src/index.ts
55
+ function normalizePhoneNumber(phone) {
56
+ let normalized = phone.replace(/\D/g, "");
57
+ if (normalized.startsWith("261")) {
58
+ normalized = "0" + normalized.slice(3);
59
+ }
60
+ return normalized;
61
+ }
55
62
  var Task = class {
56
63
  constructor(id) {
57
64
  this.id = id;
@@ -66,7 +73,7 @@ var Task = class {
66
73
  var Notification = class {
67
74
  async send(...data) {
68
75
  const messages = data.map((item) => ({
69
- phones: Array.isArray(item.phone) ? item.phone : [item.phone],
76
+ phones: (Array.isArray(item.phone) ? item.phone : [item.phone]).map(normalizePhoneNumber),
70
77
  message: item.message
71
78
  }));
72
79
  const response = await httpPost("/api/sms/bulk", { messages });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ariary/notification",
3
- "version": "1.0.9",
3
+ "version": "2.0.0",
4
4
  "description": "SMS et Notification Task SDK pour l'API Ariary",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",