@corbit2/node-red-corbit-sms 1.0.2 → 1.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/CHANGELOG.md +12 -0
- package/README.md +2 -2
- package/nodes/corbit-sms.html +1 -1
- package/nodes/lib/corbit.js +58 -10
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.4 (2026-11-20)
|
|
4
|
+
|
|
5
|
+
- Hidden direction marks that come with numbers copied on Android, iOS or from Arabic text (such as U+200F and U+061C) are removed before a number is checked, so a correct number is no longer refused because of them. The two direction overrides (U+202D and U+202E) are refused instead, because they show the digits in a different order from the number that would be sent.
|
|
6
|
+
- A number with a note in brackets at the end, such as `+971501234567 (1)`, with nested or unpaired brackets, or with a bracket at the start around more than a country code, such as `(+971501234567) 1`, is refused before sending. Before, the note digits could be added to the number and the message could go to someone else. Brackets used for formatting still work, for example `(+966) 50 123 4567` and `+1 (202) 555-0123`, also in a list of numbers.
|
|
7
|
+
- A number may be at most 40 characters (200 including hidden characters), and very long input is refused quickly.
|
|
8
|
+
- If the connection to Corbit SMS drops while a message is being sent, the error now says the SMS may have been sent, so it is checked before sending again (the connection can drop after Corbit SMS has accepted the message).
|
|
9
|
+
- The source code moved to https://github.com/corbit-sms.
|
|
10
|
+
|
|
11
|
+
## 1.0.3 (2026-11-08)
|
|
12
|
+
|
|
13
|
+
- A Saudi mobile number must have exactly 9 digits after 966 (9665XXXXXXXX). Numbers with a digit too many or too few, such as 9665012345678, are rejected before sending instead of going to a wrong number.
|
|
14
|
+
|
|
3
15
|
## 1.0.2 (2026-11-08)
|
|
4
16
|
|
|
5
17
|
- Lists of numbers are read like the Corbit SMS app: the Arabic comma and semicolon (« ، » « ؛ », typed by the Arabic iPhone keyboard) and tabs (from a spreadsheet) separate numbers too, and numbers separated only by spaces are read one by one. A number copied from phone contacts with spaces, such as `+966 50 123 4567`, stays one number.
|
package/README.md
CHANGED
|
@@ -65,7 +65,7 @@ The result is written to `msg.payload`; the other message properties are kept.
|
|
|
65
65
|
| Get balance | `{ balance }` |
|
|
66
66
|
| Get sender names | Array of `{ name, status, ... }` |
|
|
67
67
|
|
|
68
|
-
**Phone numbers.** Spaces, dashes, brackets, a leading `+` or `00` are removed, and Arabic digits are accepted. Saudi local numbers (`05XXXXXXXX`) become `9665XXXXXXXX`. Anything that could turn into a wrong number is rejected and nothing is sent: local numbers of other countries (starting with `0`; write them in international format), decimals such as `9.66501E+11` from a spreadsheet, and extra text such as `ext 12`.
|
|
68
|
+
**Phone numbers.** Spaces, dashes, brackets, a leading `+` or `00` are removed, and Arabic digits are accepted. Saudi local numbers (`05XXXXXXXX`) become `9665XXXXXXXX`. Anything that could turn into a wrong number is rejected and nothing is sent: local numbers of other countries (starting with `0`; write them in international format), decimals such as `9.66501E+11` from a spreadsheet, and extra text such as `ext 12`. Hidden direction marks that come with copied numbers are removed. A note in brackets at the end, such as `+971501234567 (1)`, nested or unpaired brackets, and a bracket at the start around more than a country code are rejected, because removing the brackets would give someone else's number. Brackets used for formatting still work: `(+966) 50 123 4567`, `+1 (202) 555-0123`. A number may be at most 40 characters.
|
|
69
69
|
|
|
70
70
|
**Sender name.** Click **Load my sender names** to pick one of your approved names, or type it.
|
|
71
71
|
|
|
@@ -109,7 +109,7 @@ Import them from **Menu → Import → Examples → @corbit2/node-red-corbit-sms
|
|
|
109
109
|
## Links
|
|
110
110
|
|
|
111
111
|
- [Corbit SMS API documentation](https://api.corbit.sa/doc)
|
|
112
|
-
- [Report a problem](https://github.com/
|
|
112
|
+
- [Report a problem](https://github.com/corbit-sms/node-red-corbit-sms/issues)
|
|
113
113
|
|
|
114
114
|
## License
|
|
115
115
|
|
package/nodes/corbit-sms.html
CHANGED
|
@@ -347,5 +347,5 @@ messages from a Split node, or sent to several nodes, share it, so only the firs
|
|
|
347
347
|
### References
|
|
348
348
|
|
|
349
349
|
- [Corbit SMS API documentation](https://api.corbit.sa/doc)
|
|
350
|
-
- [GitHub repository and issues](https://github.com/
|
|
350
|
+
- [GitHub repository and issues](https://github.com/corbit-sms/node-red-corbit-sms)
|
|
351
351
|
</script>
|
package/nodes/lib/corbit.js
CHANGED
|
@@ -20,12 +20,41 @@ class CorbitError extends Error {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
// Invisible marks that come with numbers copied on Android, iOS and Arabic pages: Arabic letter
|
|
24
|
+
// mark, zero-width characters, direction marks, embeddings and isolates, word joiner, BOM.
|
|
25
|
+
// Removing them never changes a number.
|
|
26
|
+
const PHONE_MARKS = /[\u061c\u200b-\u200f\u202a-\u202c\u2060-\u2064\u2066-\u2069\ufeff]/g;
|
|
27
|
+
// Direction overrides (U+202D, U+202E) reverse how the digits are shown, so the number on the
|
|
28
|
+
// screen is not the number that would be sent: such a number is refused, not cleaned.
|
|
29
|
+
const DIRECTION_OVERRIDES = /[\u202d\u202e]/;
|
|
30
|
+
// A number is at most 40 characters once the invisible marks are removed, and 200 with them.
|
|
31
|
+
const MAX_NUMBER_LENGTH = 40;
|
|
32
|
+
const MAX_RAW_NUMBER_LENGTH = 200;
|
|
33
|
+
// A bracket at the start of a number may only hold a country code: "(+966) 50 123 4567".
|
|
34
|
+
const LEADING_BRACKET = /^\(\s*(?:\+|00)?\d{1,4}\s*\)/;
|
|
35
|
+
|
|
36
|
+
/** Balanced brackets, never nested, and no ")" closing the number (only spaces or hyphens after it). */
|
|
37
|
+
function bracketsOk(text) {
|
|
38
|
+
let open = false;
|
|
39
|
+
for (const c of text) {
|
|
40
|
+
if (c === '(') {
|
|
41
|
+
if (open) return false;
|
|
42
|
+
open = true;
|
|
43
|
+
} else if (c === ')') {
|
|
44
|
+
if (!open) return false;
|
|
45
|
+
open = false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return !open && !/\)[\s-]*$/.test(text);
|
|
49
|
+
}
|
|
50
|
+
|
|
23
51
|
/**
|
|
24
52
|
* Turns a phone number into the digits-only international format the API expects.
|
|
25
|
-
* Accepts "+966 50 123 4567", "
|
|
26
|
-
* Arabic-Indic digits, and the Saudi local forms "0501234567" and "501234567".
|
|
53
|
+
* Accepts "+966 50 123 4567", "(+966) 50 123 4567", "00966501234567", "966501234567",
|
|
54
|
+
* "+966 (0)50 123 4567", Arabic-Indic digits, and the Saudi local forms "0501234567" and "501234567".
|
|
27
55
|
* Anything that could turn into a wrong number is rejected instead of guessed:
|
|
28
|
-
* local numbers of other countries, decimals, "9.66501E+11", "ext 12"
|
|
56
|
+
* local numbers of other countries, decimals, "9.66501E+11", "ext 12",
|
|
57
|
+
* a bracket note at the end ("+971501234567 (1)").
|
|
29
58
|
* Returns undefined when the number cannot be used.
|
|
30
59
|
*/
|
|
31
60
|
function normalizeNumber(raw) {
|
|
@@ -34,16 +63,28 @@ function normalizeNumber(raw) {
|
|
|
34
63
|
if (!Number.isSafeInteger(raw) || raw <= 0) return undefined;
|
|
35
64
|
text = String(raw);
|
|
36
65
|
} else if (typeof raw === 'string') {
|
|
66
|
+
if (raw.length > MAX_RAW_NUMBER_LENGTH || DIRECTION_OVERRIDES.test(raw)) return undefined;
|
|
37
67
|
text = raw
|
|
68
|
+
.replace(PHONE_MARKS, '')
|
|
38
69
|
.trim()
|
|
39
70
|
.replace(/[٠-٩]/g, (d) => String(d.charCodeAt(0) - 0x0660))
|
|
40
71
|
.replace(/[۰-۹]/g, (d) => String(d.charCodeAt(0) - 0x06f0));
|
|
41
72
|
} else {
|
|
42
73
|
return undefined;
|
|
43
74
|
}
|
|
44
|
-
if (
|
|
75
|
+
if (text.length > MAX_NUMBER_LENGTH) return undefined;
|
|
76
|
+
// Only digits, spaces, "-", brackets and one leading "+" (an opening bracket may come before it).
|
|
77
|
+
// Checked on the text as written, before anything is removed: a dot is never a separator.
|
|
78
|
+
const body = text.replace(/^\(\s*/, '');
|
|
79
|
+
if (!/^\+?[\d\s\-()]+$/.test(body)) return undefined;
|
|
80
|
+
// "(+971501234567) 1" would become 9715012345671, someone else's number.
|
|
81
|
+
if (text.startsWith('(') && !LEADING_BRACKET.test(text)) return undefined;
|
|
82
|
+
// A ")" closing the number is a note or an extension ("+971501234567 (1)", "(1-01)", "(1) -"), and brackets
|
|
83
|
+
// must pair up without nesting ("(1", "1)", "((1))"): dropping them would give 9715012345671, someone else.
|
|
84
|
+
// Balanced brackets at the start or in the middle are formatting: "(+966) 50 ...", "+1 (202) 555-0123".
|
|
85
|
+
if (!bracketsOk(text)) return undefined;
|
|
45
86
|
let digits = text.replace(/\D/g, '');
|
|
46
|
-
if (
|
|
87
|
+
if (body.startsWith('+')) {
|
|
47
88
|
// Already international.
|
|
48
89
|
} else if (digits.startsWith('00')) {
|
|
49
90
|
digits = digits.slice(2);
|
|
@@ -56,6 +97,8 @@ function normalizeNumber(raw) {
|
|
|
56
97
|
}
|
|
57
98
|
// "+966 (0)50 …": drop the trunk zero after the Saudi country code.
|
|
58
99
|
if (/^9660\d{9}$/.test(digits)) digits = '966' + digits.slice(4);
|
|
100
|
+
// A Saudi mobile number is exactly 9665 + 8 digits; anything else would reach a wrong number.
|
|
101
|
+
if (digits.startsWith('9665') && !/^9665\d{8}$/.test(digits)) return undefined;
|
|
59
102
|
return /^[1-9]\d{7,14}$/.test(digits) ? digits : undefined;
|
|
60
103
|
}
|
|
61
104
|
|
|
@@ -63,7 +106,8 @@ function normalizeNumber(raw) {
|
|
|
63
106
|
// new line, tab, and the Arabic comma and semicolon (what the Arabic iPhone
|
|
64
107
|
// keyboard types). A space alone is not a separator: see splitNumbers.
|
|
65
108
|
const LIST_SEPARATORS = /[,;،؛\r\n\t]+/;
|
|
66
|
-
// A piece that reads as one number written with spaces (as copied from phone contacts).
|
|
109
|
+
// A piece that reads as one number written with spaces (as copied from phone contacts). It is tested
|
|
110
|
+
// after an opening bracket at the start is removed, so "(+966) 50 123 4567" stays one number.
|
|
67
111
|
const SPACED_NUMBER = /^\+?[0-9٠-٩۰-۹()\-\s]+$/;
|
|
68
112
|
|
|
69
113
|
/**
|
|
@@ -77,9 +121,9 @@ function splitNumbers(value) {
|
|
|
77
121
|
if (typeof value === 'number') return [value];
|
|
78
122
|
const tokens = [];
|
|
79
123
|
for (const piece of String(value).split(LIST_SEPARATORS)) {
|
|
80
|
-
const p = piece.trim();
|
|
124
|
+
const p = piece.replace(PHONE_MARKS, '').trim();
|
|
81
125
|
if (p === '') continue;
|
|
82
|
-
if (SPACED_NUMBER.test(p)) {
|
|
126
|
+
if (SPACED_NUMBER.test(p.replace(/^\(\s*/, ''))) {
|
|
83
127
|
const joined = p.replace(/\s+/g, '');
|
|
84
128
|
if (normalizeNumber(joined)) {
|
|
85
129
|
tokens.push(joined);
|
|
@@ -232,8 +276,12 @@ async function apiRequest({ token, baseUrl, method, path, body, query, headers =
|
|
|
232
276
|
if (controller.signal.aborted) throw new CorbitError('The request was cancelled');
|
|
233
277
|
// Never put the error text itself in the message: it can contain header values.
|
|
234
278
|
const code = error && error.cause && typeof error.cause.code === 'string' ? error.cause.code : 'network error';
|
|
235
|
-
|
|
236
|
-
|
|
279
|
+
// The connection can drop after Corbit SMS has accepted the message (seen in the live test of
|
|
280
|
+
// 2026-11-20: ECONNRESET, yet the SMS was sent and charged), so a send must not look safe to repeat.
|
|
281
|
+
throw new CorbitError(sends ? `Could not reach Corbit SMS (${code}); the SMS may have been sent` : `Could not reach Corbit SMS (${code})`, {
|
|
282
|
+
hint: sends
|
|
283
|
+
? 'Check the message status or your Corbit SMS account before you send again, so the SMS is not sent twice.'
|
|
284
|
+
: 'Check the internet connection of the Node-RED server and the base URL.',
|
|
237
285
|
});
|
|
238
286
|
} finally {
|
|
239
287
|
clearTimeout(timer);
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@corbit2/node-red-corbit-sms",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Node-RED node for Corbit SMS: send SMS (single and bulk), check delivery status and reports, read the balance and sender names.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Ahmed Gamal",
|
|
8
8
|
"email": "a.gamal@corbit.sa"
|
|
9
9
|
},
|
|
10
|
-
"homepage": "https://github.com/
|
|
10
|
+
"homepage": "https://github.com/corbit-sms/node-red-corbit-sms#readme",
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/
|
|
13
|
+
"url": "git+https://github.com/corbit-sms/node-red-corbit-sms.git"
|
|
14
14
|
},
|
|
15
15
|
"bugs": {
|
|
16
|
-
"url": "https://github.com/
|
|
16
|
+
"url": "https://github.com/corbit-sms/node-red-corbit-sms/issues"
|
|
17
17
|
},
|
|
18
18
|
"keywords": [
|
|
19
19
|
"node-red",
|