@bitblit/ratchet-common 4.0.115-alpha → 4.0.119-alpha
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/lib/index.d.ts +73 -1
- package/lib/index.mjs +4 -0
- package/lib/index.mjs.map +1 -0
- package/lib/lang/base64-ratchet.d.ts +1 -1
- package/lib/stream/buffer-writable.d.ts +2 -2
- package/lib/stream/multi-stream.d.ts +1 -1
- package/lib/stream/stream-ratchet.d.ts +2 -2
- package/lib/stream/string-writable.d.ts +1 -1
- package/package.json +9 -5
- package/lib/2d/line-2d.js +0 -1
- package/lib/2d/plane-2d.js +0 -1
- package/lib/2d/point-2d.js +0 -1
- package/lib/2d/poly-line-2d.js +0 -1
- package/lib/2d/ratchet-2d.js +0 -245
- package/lib/2d/ratchet-2d.spec.js +0 -117
- package/lib/build/build-information.js +0 -1
- package/lib/build/ratchet-common-info.js +0 -14
- package/lib/histogram/histogram-entry.js +0 -1
- package/lib/histogram/histogram.js +0 -48
- package/lib/histogram/histogram.spec.js +0 -19
- package/lib/index.js +0 -1
- package/lib/jwt/common-jwt-token.js +0 -1
- package/lib/jwt/expired-jwt-handling.js +0 -6
- package/lib/jwt/jwt-ratchet-like.js +0 -1
- package/lib/jwt/jwt-ratchet.js +0 -164
- package/lib/jwt/jwt-ratchet.spec.js +0 -49
- package/lib/jwt/jwt-token-base.js +0 -1
- package/lib/lang/array-ratchet.js +0 -83
- package/lib/lang/array-ratchet.spec.js +0 -68
- package/lib/lang/base64-ratchet.js +0 -45
- package/lib/lang/base64-ratchet.spec.js +0 -28
- package/lib/lang/boolean-ratchet.js +0 -45
- package/lib/lang/boolean-ratchet.spec.js +0 -81
- package/lib/lang/composite-last-success-provider.js +0 -26
- package/lib/lang/composite-last-success-provider.spec.js +0 -26
- package/lib/lang/date-ratchet.js +0 -29
- package/lib/lang/date-ratchet.spec.js +0 -21
- package/lib/lang/duration-ratchet.js +0 -42
- package/lib/lang/duration-ratchet.spec.js +0 -39
- package/lib/lang/enum-ratchet.js +0 -30
- package/lib/lang/enum-ratchet.spec.js +0 -31
- package/lib/lang/error-ratchet.js +0 -44
- package/lib/lang/error-ratchet.spec.js +0 -20
- package/lib/lang/esm-ratchet.js +0 -17
- package/lib/lang/expiring-object.js +0 -72
- package/lib/lang/expiring-object.spec.js +0 -51
- package/lib/lang/geolocation-ratchet.js +0 -263
- package/lib/lang/geolocation-ratchet.spec.js +0 -74
- package/lib/lang/global-ratchet.js +0 -43
- package/lib/lang/global-ratchet.spec.js +0 -14
- package/lib/lang/key-value.js +0 -4
- package/lib/lang/last-success-provider.js +0 -1
- package/lib/lang/map-ratchet.js +0 -164
- package/lib/lang/map-ratchet.spec.js +0 -90
- package/lib/lang/no.js +0 -4
- package/lib/lang/no.spec.js +0 -7
- package/lib/lang/number-ratchet.js +0 -155
- package/lib/lang/number-ratchet.spec.js +0 -118
- package/lib/lang/parsed-url.js +0 -1
- package/lib/lang/promise-ratchet.js +0 -138
- package/lib/lang/promise-ratchet.spec.js +0 -74
- package/lib/lang/require-ratchet.js +0 -56
- package/lib/lang/require-ratchet.spec.js +0 -80
- package/lib/lang/stop-watch.js +0 -114
- package/lib/lang/string-ratchet.js +0 -201
- package/lib/lang/string-ratchet.spec.js +0 -158
- package/lib/lang/time-zone-ratchet.js +0 -77
- package/lib/lang/time-zone-ratchet.spec.js +0 -40
- package/lib/lang/timeout-token.js +0 -17
- package/lib/lang/timeout-token.spec.js +0 -9
- package/lib/lang/transform-ratchet.js +0 -66
- package/lib/lang/transform-ratchet.spec.js +0 -118
- package/lib/logger/classic-single-line-log-message-formatter.js +0 -13
- package/lib/logger/log-message-builder.js +0 -48
- package/lib/logger/log-message-format-type.js +0 -6
- package/lib/logger/log-message-formatter.js +0 -1
- package/lib/logger/log-message-processor.js +0 -1
- package/lib/logger/log-message.js +0 -1
- package/lib/logger/log-snapshot.js +0 -1
- package/lib/logger/logger-instance.js +0 -208
- package/lib/logger/logger-level-name.js +0 -9
- package/lib/logger/logger-meta.js +0 -1
- package/lib/logger/logger-options.js +0 -1
- package/lib/logger/logger-output-function.js +0 -6
- package/lib/logger/logger-ring-buffer.js +0 -73
- package/lib/logger/logger-util.js +0 -44
- package/lib/logger/logger-util.spec.js +0 -9
- package/lib/logger/logger.js +0 -134
- package/lib/logger/logger.spec.js +0 -134
- package/lib/logger/none-log-message-formatter.js +0 -5
- package/lib/logger/structured-json-log-message-formatter.js +0 -19
- package/lib/network/browser-local-ip-provider.js +0 -21
- package/lib/network/browser-local-ip-provider.spec.js +0 -16
- package/lib/network/fixed-local-ip-provider.js +0 -9
- package/lib/network/local-ip-provider.js +0 -1
- package/lib/network/network-ratchet.js +0 -102
- package/lib/network/network-ratchet.spec.js +0 -13
- package/lib/stream/buffer-writable.js +0 -16
- package/lib/stream/multi-stream.js +0 -12
- package/lib/stream/stream-ratchet.js +0 -68
- package/lib/stream/stream-ratchet.spec.js +0 -13
- package/lib/stream/string-writable.js +0 -14
- package/lib/stream/string-writable.spec.js +0 -12
- package/lib/third-party/google/google-recaptcha-ratchet.js +0 -28
- package/lib/third-party/google/google-recaptcha-ratchet.spec.js +0 -20
- package/lib/third-party/twilio/twilio-ratchet.js +0 -73
- package/lib/transform/built-in-transforms.js +0 -191
- package/lib/transform/transform-rule.js +0 -1
- package/lib/tx/transaction-configuration.js +0 -1
- package/lib/tx/transaction-final-state.js +0 -6
- package/lib/tx/transaction-ratchet.js +0 -76
- package/lib/tx/transaction-ratchet.spec.js +0 -130
- package/lib/tx/transaction-result.js +0 -1
- package/lib/tx/transaction-step.js +0 -1
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { BrowserLocalIpProvider } from './browser-local-ip-provider.js';
|
|
2
|
-
import { NetworkRatchet } from './network-ratchet.js';
|
|
3
|
-
import { PromiseRatchet } from '../lang/promise-ratchet.js';
|
|
4
|
-
import { jest } from '@jest/globals';
|
|
5
|
-
jest.mock('./network-ratchet');
|
|
6
|
-
describe('#browserLocalIpProvider', function () {
|
|
7
|
-
it('should pull a local ip and return it', async () => {
|
|
8
|
-
const mockStaticFn = jest.fn(() => Promise.resolve('192.168.1.1'));
|
|
9
|
-
NetworkRatchet.findLocalIp = mockStaticFn;
|
|
10
|
-
const up = new BrowserLocalIpProvider();
|
|
11
|
-
while (!up.ready()) {
|
|
12
|
-
await PromiseRatchet.wait(250);
|
|
13
|
-
}
|
|
14
|
-
expect(up.currentLocalIpAddress()).toEqual('192.168.1.1');
|
|
15
|
-
});
|
|
16
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { Logger } from '../logger/logger.js';
|
|
2
|
-
export class NetworkRatchet {
|
|
3
|
-
static LOCAL_IP = null;
|
|
4
|
-
static findLocalIp(useCache = true) {
|
|
5
|
-
Logger.info('Attempting to find local IP (V 2)');
|
|
6
|
-
if (NetworkRatchet.LOCAL_IP && useCache) {
|
|
7
|
-
return Promise.resolve(NetworkRatchet.LOCAL_IP);
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
if (typeof window !== 'undefined') {
|
|
11
|
-
return new Promise(function (resolve, reject) {
|
|
12
|
-
try {
|
|
13
|
-
const RTCPeerConnection = window['RTCPeerConnection'] || window['webkitRTCPeerConnection'] || window['mozRTCPeerConnection'];
|
|
14
|
-
if (RTCPeerConnection) {
|
|
15
|
-
const rtc = new RTCPeerConnection({ iceServers: [] });
|
|
16
|
-
const addrs = Object.create(null);
|
|
17
|
-
addrs['0.0.0.0'] = false;
|
|
18
|
-
if (1 || window['mozRTCPeerConnection']) {
|
|
19
|
-
rtc.createDataChannel('', { reliable: false });
|
|
20
|
-
}
|
|
21
|
-
rtc.onicecandidate = function (evt) {
|
|
22
|
-
if (evt.candidate) {
|
|
23
|
-
NetworkRatchet.grepSDP('a=' + evt.candidate.candidate, addrs, resolve);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
rtc.createOffer(function (offerDesc) {
|
|
27
|
-
NetworkRatchet.grepSDP(offerDesc.sdp, addrs, resolve);
|
|
28
|
-
rtc.setLocalDescription(offerDesc);
|
|
29
|
-
}, function (e) {
|
|
30
|
-
Logger.warn('Offer failed : %s', e);
|
|
31
|
-
resolve(NetworkRatchet.updateLocalIP('FIND_UNSUPPORTED'));
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
Logger.warn('IP Address find not supported on this device');
|
|
36
|
-
resolve(NetworkRatchet.updateLocalIP('FIND_UNSUPPORTED'));
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
catch (err) {
|
|
40
|
-
Logger.warn('Error finding local ip address : %s', err);
|
|
41
|
-
resolve(NetworkRatchet.updateLocalIP('ERROR'));
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
Logger.warn('Window not found, cannot calculate local ip');
|
|
47
|
-
return Promise.resolve(NetworkRatchet.updateLocalIP('NO_WINDOW'));
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
static parseUrl(href) {
|
|
52
|
-
const match = href.match(/^(https?\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
|
|
53
|
-
const rval = match &&
|
|
54
|
-
{
|
|
55
|
-
href: href,
|
|
56
|
-
protocol: match[1],
|
|
57
|
-
host: match[2],
|
|
58
|
-
hostname: match[3],
|
|
59
|
-
port: match[4],
|
|
60
|
-
pathname: match[5],
|
|
61
|
-
search: match[6],
|
|
62
|
-
hash: match[7],
|
|
63
|
-
};
|
|
64
|
-
return rval;
|
|
65
|
-
}
|
|
66
|
-
static updateLocalIP(newIp) {
|
|
67
|
-
NetworkRatchet.LOCAL_IP = newIp;
|
|
68
|
-
return NetworkRatchet.LOCAL_IP;
|
|
69
|
-
}
|
|
70
|
-
static grepSDP(sdp, addrs, resolve) {
|
|
71
|
-
const hosts = [];
|
|
72
|
-
sdp.split('\r\n').forEach(function (line) {
|
|
73
|
-
if (~line.indexOf('a=candidate')) {
|
|
74
|
-
const parts = line.split(' '), addr = parts[4], type = parts[7];
|
|
75
|
-
if (type === 'host') {
|
|
76
|
-
NetworkRatchet.updateAddressList(addr, addrs, resolve);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
else if (~line.indexOf('c=')) {
|
|
80
|
-
const parts = line.split(' '), addr = parts[2];
|
|
81
|
-
NetworkRatchet.updateAddressList(addr, addrs, resolve);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
static updateAddressList(newAddr, addrs, resolve) {
|
|
86
|
-
if (newAddr in addrs)
|
|
87
|
-
return;
|
|
88
|
-
else
|
|
89
|
-
addrs[newAddr] = true;
|
|
90
|
-
const displayAddrs = Object.keys(addrs).filter(function (k) {
|
|
91
|
-
return addrs[k];
|
|
92
|
-
});
|
|
93
|
-
if (displayAddrs && displayAddrs.length == 1) {
|
|
94
|
-
resolve(NetworkRatchet.updateLocalIP(displayAddrs[0]));
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
const multi = displayAddrs.sort().join(',');
|
|
98
|
-
Logger.warn('Multiple addresses found, returning sorted join : %s', multi);
|
|
99
|
-
resolve(NetworkRatchet.updateLocalIP(multi));
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { NetworkRatchet } from './network-ratchet.js';
|
|
2
|
-
describe('#parseUrl', function () {
|
|
3
|
-
it('should parse the url and return correct values', function () {
|
|
4
|
-
const result = NetworkRatchet.parseUrl('http://example.com:3000/pathname/?search=test#hash');
|
|
5
|
-
expect(result.protocol).toEqual('http:');
|
|
6
|
-
expect(result.host).toEqual('example.com:3000');
|
|
7
|
-
expect(result.hostname).toEqual('example.com');
|
|
8
|
-
expect(result.port).toEqual('3000');
|
|
9
|
-
expect(result.pathname).toEqual('/pathname/');
|
|
10
|
-
expect(result.search).toEqual('?search=test');
|
|
11
|
-
expect(result.hash).toEqual('#hash');
|
|
12
|
-
});
|
|
13
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Writable } from 'stream';
|
|
2
|
-
export class BufferWritable extends Writable {
|
|
3
|
-
_val = [];
|
|
4
|
-
constructor() {
|
|
5
|
-
super();
|
|
6
|
-
}
|
|
7
|
-
_write(chunk, encoding, callback) {
|
|
8
|
-
if (chunk) {
|
|
9
|
-
this._val.push(chunk);
|
|
10
|
-
}
|
|
11
|
-
callback();
|
|
12
|
-
}
|
|
13
|
-
get value() {
|
|
14
|
-
return Buffer.concat(this._val);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Readable } from 'stream';
|
|
2
|
-
export class MultiStream extends Readable {
|
|
3
|
-
_object;
|
|
4
|
-
constructor(object, options = {}) {
|
|
5
|
-
super(object instanceof Buffer || typeof object === 'string' ? options : { objectMode: true });
|
|
6
|
-
this._object = object;
|
|
7
|
-
}
|
|
8
|
-
_read() {
|
|
9
|
-
this.push(this._object);
|
|
10
|
-
this._object = null;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { Readable } from 'stream';
|
|
2
|
-
import { ErrorRatchet } from '../lang/error-ratchet.js';
|
|
3
|
-
import { StringRatchet } from '../lang/string-ratchet.js';
|
|
4
|
-
export class StreamRatchet {
|
|
5
|
-
constructor() { }
|
|
6
|
-
static readableToBufferSync(stream) {
|
|
7
|
-
const bufs = [];
|
|
8
|
-
let next = stream.read();
|
|
9
|
-
while (next) {
|
|
10
|
-
bufs.push(next);
|
|
11
|
-
next = stream.read();
|
|
12
|
-
}
|
|
13
|
-
return Buffer.concat(bufs);
|
|
14
|
-
}
|
|
15
|
-
static async webReadableStreamToBuffer(stream) {
|
|
16
|
-
const out = [];
|
|
17
|
-
const writer = new WritableStream({
|
|
18
|
-
async write(chunk, controller) {
|
|
19
|
-
if (typeof chunk === 'string') {
|
|
20
|
-
StringRatchet.stringToUint8Array(chunk);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
out.push(chunk);
|
|
24
|
-
}
|
|
25
|
-
return null;
|
|
26
|
-
},
|
|
27
|
-
abort(reason) {
|
|
28
|
-
ErrorRatchet.throwFormattedErr('StringWebWritableStream failure : %s', reason);
|
|
29
|
-
},
|
|
30
|
-
}, {
|
|
31
|
-
highWaterMark: 3,
|
|
32
|
-
size: () => 1,
|
|
33
|
-
});
|
|
34
|
-
await stream.pipeTo(writer);
|
|
35
|
-
return Buffer.concat(out);
|
|
36
|
-
}
|
|
37
|
-
static async webReadableStreamToString(stream) {
|
|
38
|
-
const buf = await StreamRatchet.webReadableStreamToBuffer(stream);
|
|
39
|
-
return buf.toString();
|
|
40
|
-
}
|
|
41
|
-
static stringToReadable(input) {
|
|
42
|
-
return new Readable({
|
|
43
|
-
read() {
|
|
44
|
-
this.push(input);
|
|
45
|
-
this.push(null);
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
static stringToWebReadableStream(input) {
|
|
50
|
-
const rval = new ReadableStream({
|
|
51
|
-
start(controller) {
|
|
52
|
-
if (input) {
|
|
53
|
-
controller.enqueue(input);
|
|
54
|
-
}
|
|
55
|
-
controller.close();
|
|
56
|
-
return null;
|
|
57
|
-
},
|
|
58
|
-
}, {
|
|
59
|
-
highWaterMark: input ? input.length : null,
|
|
60
|
-
});
|
|
61
|
-
return rval;
|
|
62
|
-
}
|
|
63
|
-
static anyToStringReadable(input) {
|
|
64
|
-
return input === null || input === undefined
|
|
65
|
-
? StreamRatchet.stringToReadable(null)
|
|
66
|
-
: StreamRatchet.stringToReadable(StringRatchet.safeString(input));
|
|
67
|
-
}
|
|
68
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { StreamRatchet } from './stream-ratchet.js';
|
|
2
|
-
describe('#StreamRatchet', function () {
|
|
3
|
-
it('should wrap a string in a readable', async () => {
|
|
4
|
-
const r = StreamRatchet.stringToReadable('test');
|
|
5
|
-
const out = r.read(200);
|
|
6
|
-
expect(out.length).toEqual(4);
|
|
7
|
-
});
|
|
8
|
-
it('should wrap an number in a readable', async () => {
|
|
9
|
-
const r = StreamRatchet.anyToStringReadable(401);
|
|
10
|
-
const out = r.read(200);
|
|
11
|
-
expect(out.length).toEqual(3);
|
|
12
|
-
});
|
|
13
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Writable } from 'stream';
|
|
2
|
-
export class StringWritable extends Writable {
|
|
3
|
-
_val = '';
|
|
4
|
-
constructor() {
|
|
5
|
-
super();
|
|
6
|
-
}
|
|
7
|
-
_write(chunk, encoding, callback) {
|
|
8
|
-
this._val += chunk ? chunk.toString() : '';
|
|
9
|
-
callback();
|
|
10
|
-
}
|
|
11
|
-
get value() {
|
|
12
|
-
return this._val;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { StringWritable } from './string-writable.js';
|
|
2
|
-
describe('#StringWritable', function () {
|
|
3
|
-
it('should write cumulatively to a string', async () => {
|
|
4
|
-
const sr = new StringWritable();
|
|
5
|
-
const callback = () => {
|
|
6
|
-
};
|
|
7
|
-
sr._write('a', null, callback);
|
|
8
|
-
sr._write('b', null, callback);
|
|
9
|
-
sr._write('c', null, callback);
|
|
10
|
-
expect(sr.value.length).toEqual(3);
|
|
11
|
-
});
|
|
12
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Logger } from '../../logger/logger.js';
|
|
2
|
-
import { StringRatchet } from '../../lang/string-ratchet.js';
|
|
3
|
-
import fetch from 'cross-fetch';
|
|
4
|
-
export class GoogleRecaptchaRatchet {
|
|
5
|
-
static GOOGLE_VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify?secret={{KEY}}&response={{TOKEN}}';
|
|
6
|
-
static async verifyRecaptchaToken(keySecret, token, fetchFn = fetch) {
|
|
7
|
-
Logger.debug('Verifying recaptcha token : %s', token);
|
|
8
|
-
let rval = null;
|
|
9
|
-
if (!StringRatchet.safeString(token)) {
|
|
10
|
-
Logger.warn('Recaptcha validation error, no token passed : %s', token);
|
|
11
|
-
return rval;
|
|
12
|
-
}
|
|
13
|
-
Logger.info('Validating Recaptcha via Google API : %s', token);
|
|
14
|
-
let url = GoogleRecaptchaRatchet.GOOGLE_VERIFY_URL;
|
|
15
|
-
url = url.split('{{KEY}}').join(keySecret);
|
|
16
|
-
url = url.split('{{TOKEN}}').join(token);
|
|
17
|
-
try {
|
|
18
|
-
const resp = await fetchFn(url);
|
|
19
|
-
const body = await resp.json();
|
|
20
|
-
rval = body && body.success;
|
|
21
|
-
}
|
|
22
|
-
catch (err) {
|
|
23
|
-
Logger.error('Failed to read from google : %s', err);
|
|
24
|
-
rval = false;
|
|
25
|
-
}
|
|
26
|
-
return rval;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { GoogleRecaptchaRatchet } from './google-recaptcha-ratchet.js';
|
|
2
|
-
import { jest } from '@jest/globals';
|
|
3
|
-
const fakeFetch = jest.fn((input, init) => Promise.resolve({
|
|
4
|
-
json: () => Promise.resolve({ success: true }),
|
|
5
|
-
}));
|
|
6
|
-
const fakeFailFetch = jest.fn((input, init) => Promise.reject('Failed to read'));
|
|
7
|
-
describe('#googleRecaptchaService', () => {
|
|
8
|
-
it('should validate a recaptcha token', async () => {
|
|
9
|
-
const res = await GoogleRecaptchaRatchet.verifyRecaptchaToken('anykey', 'anytoken', fakeFetch);
|
|
10
|
-
expect(res).toBeTruthy();
|
|
11
|
-
});
|
|
12
|
-
it('should fail with no token', async () => {
|
|
13
|
-
const res = await GoogleRecaptchaRatchet.verifyRecaptchaToken('anykey', null, fakeFetch);
|
|
14
|
-
expect(res).toBeFalsy();
|
|
15
|
-
});
|
|
16
|
-
it('should fail if http fails', async () => {
|
|
17
|
-
const res = await GoogleRecaptchaRatchet.verifyRecaptchaToken('anykey', 'anytoken', fakeFailFetch);
|
|
18
|
-
expect(res).toBeFalsy();
|
|
19
|
-
});
|
|
20
|
-
});
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import fetch from 'cross-fetch';
|
|
2
|
-
import { RequireRatchet } from '../../lang/require-ratchet.js';
|
|
3
|
-
import { Base64Ratchet } from '../../lang/base64-ratchet.js';
|
|
4
|
-
import { StringRatchet } from '../../lang/string-ratchet.js';
|
|
5
|
-
import { Logger } from '../../logger/logger.js';
|
|
6
|
-
export class TwilioRatchet {
|
|
7
|
-
accountSid;
|
|
8
|
-
authToken;
|
|
9
|
-
outBoundNumber;
|
|
10
|
-
static TWILLIO_BASE_API_URL = 'https://api.twilio.com/2010-04-01';
|
|
11
|
-
constructor(accountSid, authToken, outBoundNumber) {
|
|
12
|
-
this.accountSid = accountSid;
|
|
13
|
-
this.authToken = authToken;
|
|
14
|
-
this.outBoundNumber = outBoundNumber;
|
|
15
|
-
RequireRatchet.notNullOrUndefined(accountSid, 'accountSid');
|
|
16
|
-
RequireRatchet.notNullOrUndefined(authToken, 'authToken');
|
|
17
|
-
RequireRatchet.notNullOrUndefined(outBoundNumber, 'outBoundNumber');
|
|
18
|
-
RequireRatchet.true(TwilioRatchet.isValidE164Number(outBoundNumber), 'outBoundNumber invalid format');
|
|
19
|
-
}
|
|
20
|
-
static async sendMessageDirect(accountSid, authToken, outBoundNumber, recipientPhoneNumbers, message) {
|
|
21
|
-
const ratchet = new TwilioRatchet(accountSid, authToken, outBoundNumber);
|
|
22
|
-
const rval = await ratchet.sendMessage(recipientPhoneNumbers, message);
|
|
23
|
-
return rval;
|
|
24
|
-
}
|
|
25
|
-
static generateTwilioBasicAuth(sid, authToken) {
|
|
26
|
-
const authHeader = 'Basic ' + Base64Ratchet.generateBase64VersionOfString(sid + ':' + authToken);
|
|
27
|
-
return authHeader;
|
|
28
|
-
}
|
|
29
|
-
async sendMessage(recipientPhoneNumbers, message) {
|
|
30
|
-
const rval = [];
|
|
31
|
-
RequireRatchet.notNullOrUndefined(recipientPhoneNumbers, 'recipientPhoneNumbers');
|
|
32
|
-
RequireRatchet.notNullOrUndefined(StringRatchet.trimToNull(message), 'message');
|
|
33
|
-
RequireRatchet.true(recipientPhoneNumbers.length > 0, 'recipientPhoneNumbers non-empty');
|
|
34
|
-
recipientPhoneNumbers.forEach((p) => {
|
|
35
|
-
RequireRatchet.true(TwilioRatchet.isValidE164Number(p), p + ' is not valid');
|
|
36
|
-
});
|
|
37
|
-
if (!!recipientPhoneNumbers && recipientPhoneNumbers.length > 0 && !!StringRatchet.trimToNull(message)) {
|
|
38
|
-
Logger.info('Sending %s to %j', message, recipientPhoneNumbers);
|
|
39
|
-
for (let i = 0; i < recipientPhoneNumbers.length; i++) {
|
|
40
|
-
const phoneNumber = recipientPhoneNumbers[i];
|
|
41
|
-
Logger.info('To: %s', phoneNumber);
|
|
42
|
-
if (!TwilioRatchet.isValidE164Number(phoneNumber)) {
|
|
43
|
-
throw new Error('number must be E164 format!');
|
|
44
|
-
}
|
|
45
|
-
const body = 'Body=' +
|
|
46
|
-
encodeURIComponent(message) +
|
|
47
|
-
'&From=' +
|
|
48
|
-
encodeURIComponent(this.outBoundNumber) +
|
|
49
|
-
'&To=' +
|
|
50
|
-
encodeURIComponent(phoneNumber);
|
|
51
|
-
const post = {
|
|
52
|
-
method: 'post',
|
|
53
|
-
headers: {
|
|
54
|
-
authorization: TwilioRatchet.generateTwilioBasicAuth(this.accountSid, this.authToken),
|
|
55
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
56
|
-
},
|
|
57
|
-
body: body,
|
|
58
|
-
};
|
|
59
|
-
const res = await fetch(TwilioRatchet.TWILLIO_BASE_API_URL + '/Accounts/' + this.accountSid + '/Messages.json', post);
|
|
60
|
-
const parsedResponse = await res.json();
|
|
61
|
-
Logger.debug('TwilioRatchet: For %s got %j', phoneNumber, parsedResponse);
|
|
62
|
-
rval.push(parsedResponse);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
Logger.warn('Not sending empty message / empty recipients');
|
|
67
|
-
}
|
|
68
|
-
return rval;
|
|
69
|
-
}
|
|
70
|
-
static isValidE164Number(num) {
|
|
71
|
-
return /^\+?[1-9]\d{1,14}$/.test(num);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import { Logger } from '../logger/logger.js';
|
|
2
|
-
import { NumberRatchet } from '../lang/number-ratchet.js';
|
|
3
|
-
import { DateTime } from 'luxon';
|
|
4
|
-
export class BuiltInTransforms {
|
|
5
|
-
static keysOnly(rule) {
|
|
6
|
-
return {
|
|
7
|
-
transform(value, isKey, context) {
|
|
8
|
-
return isKey ? rule.transform(value, isKey, context) : value;
|
|
9
|
-
},
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
static valuesOnly(rule) {
|
|
13
|
-
return {
|
|
14
|
-
transform(value, isKey, context) {
|
|
15
|
-
return !isKey ? rule.transform(value, isKey, context) : value;
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
static stringReplaceTransform(input, output) {
|
|
20
|
-
return {
|
|
21
|
-
transform(value, isKey, context) {
|
|
22
|
-
return value == input ? output : value;
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
static stripStringTransform(input) {
|
|
27
|
-
return {
|
|
28
|
-
transform(value, isKey, context) {
|
|
29
|
-
return value == input ? null : value;
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
static retainAll(input) {
|
|
34
|
-
return {
|
|
35
|
-
transform(value, isKey, context) {
|
|
36
|
-
return input.indexOf(value) == -1 ? null : value;
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
static removeAll(input) {
|
|
41
|
-
return {
|
|
42
|
-
transform(value, isKey, context) {
|
|
43
|
-
return input.indexOf(value) > -1 ? null : value;
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
static snakeToCamelCase() {
|
|
48
|
-
return {
|
|
49
|
-
transform(value, isKey, context) {
|
|
50
|
-
let rval = value;
|
|
51
|
-
if (typeof value == 'string') {
|
|
52
|
-
rval = value.replace(/_([a-z0-9])/gi, function (s, group1) {
|
|
53
|
-
return group1.toUpperCase();
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
return rval;
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
static stringToNumber() {
|
|
61
|
-
return {
|
|
62
|
-
transform(value, isKey, context) {
|
|
63
|
-
let rval = value;
|
|
64
|
-
if (typeof value == 'string') {
|
|
65
|
-
const num = NumberRatchet.safeNumber(value);
|
|
66
|
-
if (num !== null) {
|
|
67
|
-
rval = num;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return rval;
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
static camelToSnakeCase() {
|
|
75
|
-
return {
|
|
76
|
-
transform(value, isKey, context) {
|
|
77
|
-
let rval = value;
|
|
78
|
-
if (typeof value == 'string') {
|
|
79
|
-
rval = value
|
|
80
|
-
.replace(/\.?([A-Z]+)/g, function (x, y) {
|
|
81
|
-
return '_' + y.toLowerCase();
|
|
82
|
-
})
|
|
83
|
-
.replace(/^_/, '');
|
|
84
|
-
}
|
|
85
|
-
return rval;
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
static concatenateToNewField(newFieldName, oldFieldNamesInOrder, abortIfFieldMissing = true) {
|
|
90
|
-
return {
|
|
91
|
-
transform(value, isKey, context) {
|
|
92
|
-
if (typeof value == 'object') {
|
|
93
|
-
let rval = '';
|
|
94
|
-
oldFieldNamesInOrder.forEach((n) => {
|
|
95
|
-
if (rval != null) {
|
|
96
|
-
const temp = value[n];
|
|
97
|
-
if (temp == null && abortIfFieldMissing) {
|
|
98
|
-
rval = null;
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
rval = temp == null ? rval : rval + String(temp);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
if (rval != null) {
|
|
106
|
-
value[newFieldName] = rval;
|
|
107
|
-
oldFieldNamesInOrder.forEach((n) => delete value[n]);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return value;
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
static numberToBool(fieldNames) {
|
|
115
|
-
return {
|
|
116
|
-
transform(value, isKey, context) {
|
|
117
|
-
if (typeof value == 'object') {
|
|
118
|
-
fieldNames.forEach((n) => {
|
|
119
|
-
const oldVal = value[n];
|
|
120
|
-
if (typeof oldVal == 'number') {
|
|
121
|
-
const newVal = 0 != oldVal;
|
|
122
|
-
value[n] = newVal;
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
return value;
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
static boolToNumber(fieldNames) {
|
|
131
|
-
return {
|
|
132
|
-
transform(value, isKey, context) {
|
|
133
|
-
if (typeof value == 'object') {
|
|
134
|
-
fieldNames.forEach((n) => {
|
|
135
|
-
const oldVal = value[n];
|
|
136
|
-
if (typeof oldVal == 'boolean') {
|
|
137
|
-
const newVal = oldVal ? 1 : 0;
|
|
138
|
-
value[n] = newVal;
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
return value;
|
|
143
|
-
},
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
static makeDuplicateField(oldName, newName) {
|
|
147
|
-
return {
|
|
148
|
-
transform(value, isKey, context) {
|
|
149
|
-
if (typeof value == 'object') {
|
|
150
|
-
const oldVal = value[oldName];
|
|
151
|
-
if (oldVal != null) {
|
|
152
|
-
value[newName] = oldVal;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return value;
|
|
156
|
-
},
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
static addField(name, valueToAdd) {
|
|
160
|
-
return {
|
|
161
|
-
transform(value, isKey, context) {
|
|
162
|
-
if (typeof value == 'object') {
|
|
163
|
-
value[name] = valueToAdd;
|
|
164
|
-
}
|
|
165
|
-
return value;
|
|
166
|
-
},
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
static reformatDateFields(fieldNames, oldFormat, newFormat) {
|
|
170
|
-
return {
|
|
171
|
-
transform(value, isKey, context) {
|
|
172
|
-
if (typeof value == 'object') {
|
|
173
|
-
fieldNames.forEach((key) => {
|
|
174
|
-
const oldValue = value[key];
|
|
175
|
-
if (oldValue != null) {
|
|
176
|
-
try {
|
|
177
|
-
const parsed = DateTime.fromFormat(oldValue, oldFormat);
|
|
178
|
-
const newValue = parsed.toFormat(newFormat);
|
|
179
|
-
value[key] = newValue;
|
|
180
|
-
}
|
|
181
|
-
catch (err) {
|
|
182
|
-
Logger.warn('Failed to reparse date %s in format %s : %s', oldValue, oldFormat, err);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
return value;
|
|
188
|
-
},
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export var TransactionFinalState;
|
|
2
|
-
(function (TransactionFinalState) {
|
|
3
|
-
TransactionFinalState["Success"] = "Success";
|
|
4
|
-
TransactionFinalState["RolledBack"] = "RolledBack";
|
|
5
|
-
TransactionFinalState["RollbackFailed"] = "RollbackFailed";
|
|
6
|
-
})(TransactionFinalState || (TransactionFinalState = {}));
|