@pallasoft/ps-utilities 2.6.0 → 2.8.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/common/amount-service.d.ts +5 -0
- package/dist/common/amount-service.js +35 -0
- package/dist/common/constants/amount-config.d.ts +7 -0
- package/dist/common/constants/amount-config.js +10 -0
- package/dist/common/constants/index.d.ts +6 -0
- package/dist/common/constants/index.js +6 -0
- package/dist/common/constants/phone-config.d.ts +6 -0
- package/dist/common/constants/phone-config.js +9 -0
- package/dist/common/constants/postal-code-formats.d.ts +5 -0
- package/dist/common/constants/postal-code-formats.js +13 -0
- package/dist/common/constants/signed-token-config.d.ts +17 -0
- package/dist/common/constants/signed-token-config.js +14 -0
- package/dist/common/constants/user-token-config.d.ts +6 -0
- package/dist/common/constants/user-token-config.js +9 -0
- package/dist/common/constants/validation-config.d.ts +8 -0
- package/dist/common/constants/validation-config.js +11 -0
- package/dist/common/index.d.ts +8 -2
- package/dist/common/index.js +8 -2
- package/dist/common/phone-service.d.ts +14 -0
- package/dist/common/phone-service.js +78 -0
- package/dist/common/postal-code-service.d.ts +5 -0
- package/dist/common/postal-code-service.js +42 -0
- package/dist/common/signed-token-service.d.ts +19 -0
- package/dist/common/signed-token-service.js +233 -0
- package/dist/common/user-token-service.d.ts +11 -0
- package/dist/common/user-token-service.js +115 -0
- package/dist/common/validation-service.d.ts +7 -0
- package/dist/common/validation-service.js +36 -0
- package/dist/index.d.ts +10 -0
- package/dist/models/phone-country-data.d.ts +5 -0
- package/dist/models/phone-country-data.js +2 -0
- package/dist/models/phone-display-data.d.ts +4 -0
- package/dist/models/phone-display-data.js +2 -0
- package/dist/models/postal-code-format-data.d.ts +5 -0
- package/dist/models/postal-code-format-data.js +2 -0
- package/dist/models/signed-token-header.d.ts +4 -0
- package/dist/models/signed-token-header.js +2 -0
- package/dist/models/signed-token-key-pair.d.ts +4 -0
- package/dist/models/signed-token-key-pair.js +2 -0
- package/dist/models/user-token-claims.d.ts +12 -0
- package/dist/models/user-token-claims.js +2 -0
- package/dist/models/user-token-issue-options.d.ts +6 -0
- package/dist/models/user-token-issue-options.js +2 -0
- package/dist/models/user-token-request.d.ts +4 -0
- package/dist/models/user-token-request.js +2 -0
- package/dist/models/user-token-subject.d.ts +5 -0
- package/dist/models/user-token-subject.js +2 -0
- package/dist/models/user-token-verify-options.d.ts +6 -0
- package/dist/models/user-token-verify-options.js +2 -0
- package/package.json +3 -2
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AmountService = void 0;
|
|
4
|
+
var amount_config_1 = require("./constants/amount-config");
|
|
5
|
+
var AmountService = /** @class */ (function () {
|
|
6
|
+
function AmountService() {
|
|
7
|
+
}
|
|
8
|
+
AmountService.normalise = function (raw) {
|
|
9
|
+
var trimmed = raw.trim();
|
|
10
|
+
var isBracketed = trimmed.startsWith(amount_config_1.AmountConfig.openBracket) && trimmed.endsWith(amount_config_1.AmountConfig.closeBracket);
|
|
11
|
+
var isNegative = isBracketed || trimmed.startsWith(amount_config_1.AmountConfig.minus);
|
|
12
|
+
var kept = trimmed.replace(amount_config_1.AmountConfig.disallowed, '');
|
|
13
|
+
var pointIndex = kept.indexOf(amount_config_1.AmountConfig.point);
|
|
14
|
+
var digits = pointIndex === -1
|
|
15
|
+
? kept
|
|
16
|
+
: "".concat(kept.slice(0, pointIndex + 1)).concat(kept
|
|
17
|
+
.slice(pointIndex + 1)
|
|
18
|
+
.split(amount_config_1.AmountConfig.point)
|
|
19
|
+
.join(''));
|
|
20
|
+
if (digits === '')
|
|
21
|
+
return isNegative && !isBracketed ? amount_config_1.AmountConfig.minus : '';
|
|
22
|
+
return isNegative ? "".concat(amount_config_1.AmountConfig.minus).concat(digits) : digits;
|
|
23
|
+
};
|
|
24
|
+
AmountService.toNumber = function (raw) {
|
|
25
|
+
var normalised = AmountService.normalise(raw);
|
|
26
|
+
var parsed = Number(normalised);
|
|
27
|
+
return normalised === '' || !Number.isFinite(parsed) ? 0 : parsed;
|
|
28
|
+
};
|
|
29
|
+
AmountService.isAmount = function (raw) {
|
|
30
|
+
var normalised = AmountService.normalise(raw);
|
|
31
|
+
return (normalised !== '' && normalised !== amount_config_1.AmountConfig.minus && Number.isFinite(Number(normalised)));
|
|
32
|
+
};
|
|
33
|
+
return AmountService;
|
|
34
|
+
}());
|
|
35
|
+
exports.AmountService = AmountService;
|
|
@@ -14,4 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./amount-config"), exports);
|
|
17
18
|
__exportStar(require("./email-preview-config"), exports);
|
|
19
|
+
__exportStar(require("./phone-config"), exports);
|
|
20
|
+
__exportStar(require("./postal-code-formats"), exports);
|
|
21
|
+
__exportStar(require("./signed-token-config"), exports);
|
|
22
|
+
__exportStar(require("./user-token-config"), exports);
|
|
23
|
+
__exportStar(require("./validation-config"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PostalCodeConfig = exports.PostalCodeFormats = void 0;
|
|
4
|
+
exports.PostalCodeFormats = {
|
|
5
|
+
CA: { allowed: /[^A-Z0-9]/g, groups: [3, 3], separator: ' ' },
|
|
6
|
+
GB: { allowed: /[^A-Z0-9]/g, groups: [], separator: ' ' },
|
|
7
|
+
IN: { allowed: /[^0-9]/g, groups: [6], separator: '' },
|
|
8
|
+
NL: { allowed: /[^A-Z0-9]/g, groups: [4, 2], separator: ' ' },
|
|
9
|
+
US: { allowed: /[^0-9]/g, groups: [5, 4], separator: '-' },
|
|
10
|
+
};
|
|
11
|
+
exports.PostalCodeConfig = {
|
|
12
|
+
fallbackAllowed: /[^A-Z0-9 -]/g,
|
|
13
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const SignedTokenConfig: {
|
|
2
|
+
readonly algorithm: "ES256";
|
|
3
|
+
readonly type: "JWT";
|
|
4
|
+
readonly keyAlgorithm: {
|
|
5
|
+
readonly name: "ECDSA";
|
|
6
|
+
readonly namedCurve: "P-256";
|
|
7
|
+
};
|
|
8
|
+
readonly signAlgorithm: {
|
|
9
|
+
readonly name: "ECDSA";
|
|
10
|
+
readonly hash: "SHA-256";
|
|
11
|
+
};
|
|
12
|
+
readonly privateKeyFormat: "pkcs8";
|
|
13
|
+
readonly publicKeyFormat: "spki";
|
|
14
|
+
readonly separator: ".";
|
|
15
|
+
readonly partCount: 3;
|
|
16
|
+
readonly keyCacheLimit: 20;
|
|
17
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignedTokenConfig = void 0;
|
|
4
|
+
exports.SignedTokenConfig = {
|
|
5
|
+
algorithm: 'ES256',
|
|
6
|
+
type: 'JWT',
|
|
7
|
+
keyAlgorithm: { name: 'ECDSA', namedCurve: 'P-256' },
|
|
8
|
+
signAlgorithm: { name: 'ECDSA', hash: 'SHA-256' },
|
|
9
|
+
privateKeyFormat: 'pkcs8',
|
|
10
|
+
publicKeyFormat: 'spki',
|
|
11
|
+
separator: '.',
|
|
12
|
+
partCount: 3,
|
|
13
|
+
keyCacheLimit: 20,
|
|
14
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidationConfig = void 0;
|
|
4
|
+
exports.ValidationConfig = {
|
|
5
|
+
email: /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
|
|
6
|
+
webProtocols: ['http:', 'https:'],
|
|
7
|
+
hostSeparator: '.',
|
|
8
|
+
urlProtocol: 'https://',
|
|
9
|
+
urlProtocolPattern: /^[a-z][a-z0-9+.-]*:\/\//i,
|
|
10
|
+
uuid: /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,
|
|
11
|
+
};
|
package/dist/common/index.d.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
+
export * from './amount-service';
|
|
1
2
|
export * from './color-service';
|
|
2
3
|
export * from './constants';
|
|
3
4
|
export * from './crypto-service';
|
|
5
|
+
export * from './date-service';
|
|
4
6
|
export * from './email-preview-service';
|
|
5
7
|
export * from './encrypted-fields-service';
|
|
6
8
|
export * from './envelope-crypto-service';
|
|
7
|
-
export * from './date-service';
|
|
8
9
|
export * from './number-format-service';
|
|
10
|
+
export * from './phone-service';
|
|
11
|
+
export * from './postal-code-service';
|
|
9
12
|
export * from './recaptcha-service';
|
|
10
|
-
export * from './
|
|
13
|
+
export * from './signed-token-service';
|
|
11
14
|
export * from './string-service';
|
|
12
15
|
export * from './transform-service';
|
|
16
|
+
export * from './url-service';
|
|
17
|
+
export * from './user-token-service';
|
|
18
|
+
export * from './validation-service';
|
package/dist/common/index.js
CHANGED
|
@@ -14,15 +14,21 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./amount-service"), exports);
|
|
17
18
|
__exportStar(require("./color-service"), exports);
|
|
18
19
|
__exportStar(require("./constants"), exports);
|
|
19
20
|
__exportStar(require("./crypto-service"), exports);
|
|
21
|
+
__exportStar(require("./date-service"), exports);
|
|
20
22
|
__exportStar(require("./email-preview-service"), exports);
|
|
21
23
|
__exportStar(require("./encrypted-fields-service"), exports);
|
|
22
24
|
__exportStar(require("./envelope-crypto-service"), exports);
|
|
23
|
-
__exportStar(require("./date-service"), exports);
|
|
24
25
|
__exportStar(require("./number-format-service"), exports);
|
|
26
|
+
__exportStar(require("./phone-service"), exports);
|
|
27
|
+
__exportStar(require("./postal-code-service"), exports);
|
|
25
28
|
__exportStar(require("./recaptcha-service"), exports);
|
|
26
|
-
__exportStar(require("./
|
|
29
|
+
__exportStar(require("./signed-token-service"), exports);
|
|
27
30
|
__exportStar(require("./string-service"), exports);
|
|
28
31
|
__exportStar(require("./transform-service"), exports);
|
|
32
|
+
__exportStar(require("./url-service"), exports);
|
|
33
|
+
__exportStar(require("./user-token-service"), exports);
|
|
34
|
+
__exportStar(require("./validation-service"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type CountryCode } from 'libphonenumber-js';
|
|
2
|
+
import type { PhoneCountryData } from '../models/phone-country-data';
|
|
3
|
+
import type { PhoneDisplayData } from '../models/phone-display-data';
|
|
4
|
+
export declare class PhoneService {
|
|
5
|
+
static isCountry(code: string): code is CountryCode;
|
|
6
|
+
static countries(preferred: string, locale?: string): PhoneCountryData[];
|
|
7
|
+
static display(value: string, fallbackCountry: string): PhoneDisplayData;
|
|
8
|
+
static format(national: string, country: string): string;
|
|
9
|
+
static formatForDisplay(value: string, country: string): string;
|
|
10
|
+
static toStored(national: string, country: string): string;
|
|
11
|
+
static isValid(national: string, country: string): boolean;
|
|
12
|
+
static callingCode(country: string): string;
|
|
13
|
+
private static parse;
|
|
14
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PhoneService = void 0;
|
|
4
|
+
var libphonenumber_js_1 = require("libphonenumber-js");
|
|
5
|
+
var phone_config_1 = require("./constants/phone-config");
|
|
6
|
+
var PhoneService = /** @class */ (function () {
|
|
7
|
+
function PhoneService() {
|
|
8
|
+
}
|
|
9
|
+
PhoneService.isCountry = function (code) {
|
|
10
|
+
return (0, libphonenumber_js_1.getCountries)().includes(code);
|
|
11
|
+
};
|
|
12
|
+
PhoneService.countries = function (preferred, locale) {
|
|
13
|
+
if (locale === void 0) { locale = phone_config_1.PhoneConfig.locale; }
|
|
14
|
+
var names = new Intl.DisplayNames([locale], { type: phone_config_1.PhoneConfig.displayNamesType });
|
|
15
|
+
var options = (0, libphonenumber_js_1.getCountries)().map(function (code) {
|
|
16
|
+
var name = names.of(code);
|
|
17
|
+
return {
|
|
18
|
+
callingCode: (0, libphonenumber_js_1.getCountryCallingCode)(code),
|
|
19
|
+
code: code,
|
|
20
|
+
label: name !== undefined ? name : code,
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
return options.sort(function (left, right) {
|
|
24
|
+
if (left.code === preferred)
|
|
25
|
+
return -1;
|
|
26
|
+
if (right.code === preferred)
|
|
27
|
+
return 1;
|
|
28
|
+
return left.label.localeCompare(right.label);
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
PhoneService.display = function (value, fallbackCountry) {
|
|
32
|
+
var parsed = value.startsWith(phone_config_1.PhoneConfig.plus)
|
|
33
|
+
? (0, libphonenumber_js_1.parsePhoneNumberFromString)(value)
|
|
34
|
+
: undefined;
|
|
35
|
+
if (parsed !== undefined && parsed.country !== undefined)
|
|
36
|
+
return { country: parsed.country, national: parsed.formatNational() };
|
|
37
|
+
return { country: fallbackCountry, national: value };
|
|
38
|
+
};
|
|
39
|
+
PhoneService.format = function (national, country) {
|
|
40
|
+
if (!PhoneService.isCountry(country))
|
|
41
|
+
return national;
|
|
42
|
+
return new libphonenumber_js_1.AsYouType(country).input(national);
|
|
43
|
+
};
|
|
44
|
+
PhoneService.formatForDisplay = function (value, country) {
|
|
45
|
+
var parsed = PhoneService.parse(value, country);
|
|
46
|
+
if (parsed === undefined || !parsed.isValid())
|
|
47
|
+
return value.trim();
|
|
48
|
+
return parsed.country === country ? parsed.formatNational() : parsed.formatInternational();
|
|
49
|
+
};
|
|
50
|
+
PhoneService.toStored = function (national, country) {
|
|
51
|
+
var trimmed = national.trim();
|
|
52
|
+
if (trimmed === '' || !PhoneService.isCountry(country))
|
|
53
|
+
return trimmed;
|
|
54
|
+
var parsed = (0, libphonenumber_js_1.parsePhoneNumberFromString)(trimmed, country);
|
|
55
|
+
return parsed !== undefined ? parsed.number : trimmed;
|
|
56
|
+
};
|
|
57
|
+
PhoneService.isValid = function (national, country) {
|
|
58
|
+
if (national.trim() === '')
|
|
59
|
+
return true;
|
|
60
|
+
var parsed = PhoneService.parse(national, country);
|
|
61
|
+
return parsed !== undefined && parsed.isValid();
|
|
62
|
+
};
|
|
63
|
+
PhoneService.callingCode = function (country) {
|
|
64
|
+
return PhoneService.isCountry(country) ? (0, libphonenumber_js_1.getCountryCallingCode)(country) : '';
|
|
65
|
+
};
|
|
66
|
+
PhoneService.parse = function (value, country) {
|
|
67
|
+
var trimmed = value.trim();
|
|
68
|
+
if (trimmed === '')
|
|
69
|
+
return undefined;
|
|
70
|
+
if (trimmed.startsWith(phone_config_1.PhoneConfig.plus))
|
|
71
|
+
return (0, libphonenumber_js_1.parsePhoneNumberFromString)(trimmed);
|
|
72
|
+
return PhoneService.isCountry(country)
|
|
73
|
+
? (0, libphonenumber_js_1.parsePhoneNumberFromString)(trimmed, country)
|
|
74
|
+
: undefined;
|
|
75
|
+
};
|
|
76
|
+
return PhoneService;
|
|
77
|
+
}());
|
|
78
|
+
exports.PhoneService = PhoneService;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PostalCodeService = void 0;
|
|
4
|
+
var postal_code_formats_1 = require("./constants/postal-code-formats");
|
|
5
|
+
var PostalCodeService = /** @class */ (function () {
|
|
6
|
+
function PostalCodeService() {
|
|
7
|
+
}
|
|
8
|
+
PostalCodeService.format = function (raw, country) {
|
|
9
|
+
var upper = raw.toUpperCase();
|
|
10
|
+
var format = postal_code_formats_1.PostalCodeFormats[country];
|
|
11
|
+
if (format === undefined)
|
|
12
|
+
return upper.replace(postal_code_formats_1.PostalCodeConfig.fallbackAllowed, '');
|
|
13
|
+
var compact = upper.replace(format.allowed, '');
|
|
14
|
+
if (format.groups.length === 0)
|
|
15
|
+
return upper.replace(postal_code_formats_1.PostalCodeConfig.fallbackAllowed, '');
|
|
16
|
+
var parts = [];
|
|
17
|
+
var cursor = 0;
|
|
18
|
+
for (var _i = 0, _a = format.groups; _i < _a.length; _i++) {
|
|
19
|
+
var size = _a[_i];
|
|
20
|
+
if (cursor >= compact.length)
|
|
21
|
+
break;
|
|
22
|
+
parts.push(compact.slice(cursor, cursor + size));
|
|
23
|
+
cursor += size;
|
|
24
|
+
}
|
|
25
|
+
return parts.join(format.separator);
|
|
26
|
+
};
|
|
27
|
+
PostalCodeService.maxLength = function (country) {
|
|
28
|
+
var format = postal_code_formats_1.PostalCodeFormats[country];
|
|
29
|
+
if (format === undefined || format.groups.length === 0)
|
|
30
|
+
return undefined;
|
|
31
|
+
return (format.groups.reduce(function (sum, size) { return sum + size; }, 0) +
|
|
32
|
+
format.separator.length * (format.groups.length - 1));
|
|
33
|
+
};
|
|
34
|
+
PostalCodeService.isValid = function (raw, country) {
|
|
35
|
+
var format = postal_code_formats_1.PostalCodeFormats[country];
|
|
36
|
+
if (raw.trim() === '' || format === undefined || format.groups.length === 0)
|
|
37
|
+
return true;
|
|
38
|
+
return PostalCodeService.format(raw, country).length === PostalCodeService.maxLength(country);
|
|
39
|
+
};
|
|
40
|
+
return PostalCodeService;
|
|
41
|
+
}());
|
|
42
|
+
exports.PostalCodeService = PostalCodeService;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { SignedTokenKeyPair } from '../models/signed-token-key-pair';
|
|
2
|
+
export declare class SignedTokenService {
|
|
3
|
+
private static _textEncoder;
|
|
4
|
+
private static _textDecoder;
|
|
5
|
+
private static _privateKeys;
|
|
6
|
+
private static _publicKeys;
|
|
7
|
+
static generateKeyPair(): Promise<SignedTokenKeyPair>;
|
|
8
|
+
static sign<Claims extends object>(claims: Claims, privateKey: string): Promise<string>;
|
|
9
|
+
static verify<Claims extends object>(token: string, publicKeys: string[]): Promise<Claims | null>;
|
|
10
|
+
private static _privateKey;
|
|
11
|
+
private static _publicKey;
|
|
12
|
+
private static _remember;
|
|
13
|
+
private static _encodeJson;
|
|
14
|
+
private static _decodeJson;
|
|
15
|
+
private static _toBase64;
|
|
16
|
+
private static _fromBase64;
|
|
17
|
+
private static _toBase64Url;
|
|
18
|
+
private static _fromBase64Url;
|
|
19
|
+
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.SignedTokenService = void 0;
|
|
40
|
+
var signed_token_config_1 = require("./constants/signed-token-config");
|
|
41
|
+
var SignedTokenService = /** @class */ (function () {
|
|
42
|
+
function SignedTokenService() {
|
|
43
|
+
}
|
|
44
|
+
SignedTokenService.generateKeyPair = function () {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
46
|
+
var pair, privateKey, publicKey;
|
|
47
|
+
return __generator(this, function (_a) {
|
|
48
|
+
switch (_a.label) {
|
|
49
|
+
case 0: return [4 /*yield*/, crypto.subtle.generateKey(signed_token_config_1.SignedTokenConfig.keyAlgorithm, true, [
|
|
50
|
+
'sign',
|
|
51
|
+
'verify',
|
|
52
|
+
])];
|
|
53
|
+
case 1:
|
|
54
|
+
pair = (_a.sent());
|
|
55
|
+
return [4 /*yield*/, crypto.subtle.exportKey(signed_token_config_1.SignedTokenConfig.privateKeyFormat, pair.privateKey)];
|
|
56
|
+
case 2:
|
|
57
|
+
privateKey = _a.sent();
|
|
58
|
+
return [4 /*yield*/, crypto.subtle.exportKey(signed_token_config_1.SignedTokenConfig.publicKeyFormat, pair.publicKey)];
|
|
59
|
+
case 3:
|
|
60
|
+
publicKey = _a.sent();
|
|
61
|
+
return [2 /*return*/, {
|
|
62
|
+
privateKey: this._toBase64(new Uint8Array(privateKey)),
|
|
63
|
+
publicKey: this._toBase64(new Uint8Array(publicKey)),
|
|
64
|
+
}];
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
SignedTokenService.sign = function (claims, privateKey) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
71
|
+
var header, signingInput, signature, _a, _b, _c;
|
|
72
|
+
return __generator(this, function (_d) {
|
|
73
|
+
switch (_d.label) {
|
|
74
|
+
case 0:
|
|
75
|
+
header = {
|
|
76
|
+
alg: signed_token_config_1.SignedTokenConfig.algorithm,
|
|
77
|
+
typ: signed_token_config_1.SignedTokenConfig.type,
|
|
78
|
+
};
|
|
79
|
+
signingInput = "".concat(this._encodeJson(header)).concat(signed_token_config_1.SignedTokenConfig.separator).concat(this._encodeJson(claims));
|
|
80
|
+
_b = (_a = crypto.subtle).sign;
|
|
81
|
+
_c = [signed_token_config_1.SignedTokenConfig.signAlgorithm];
|
|
82
|
+
return [4 /*yield*/, this._privateKey(privateKey)];
|
|
83
|
+
case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([_d.sent(), this._textEncoder.encode(signingInput)]))];
|
|
84
|
+
case 2:
|
|
85
|
+
signature = _d.sent();
|
|
86
|
+
return [2 /*return*/, "".concat(signingInput).concat(signed_token_config_1.SignedTokenConfig.separator).concat(this._toBase64Url(new Uint8Array(signature)))];
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
SignedTokenService.verify = function (token, publicKeys) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
93
|
+
var parts, encodedHeader, encodedClaims, encodedSignature, header, signature, signingInput, _i, publicKeys_1, publicKey, key, isValid;
|
|
94
|
+
return __generator(this, function (_a) {
|
|
95
|
+
switch (_a.label) {
|
|
96
|
+
case 0:
|
|
97
|
+
parts = token.split(signed_token_config_1.SignedTokenConfig.separator);
|
|
98
|
+
if (parts.length !== signed_token_config_1.SignedTokenConfig.partCount)
|
|
99
|
+
return [2 /*return*/, null];
|
|
100
|
+
encodedHeader = parts[0], encodedClaims = parts[1], encodedSignature = parts[2];
|
|
101
|
+
header = this._decodeJson(encodedHeader);
|
|
102
|
+
if (header === null ||
|
|
103
|
+
header.alg !== signed_token_config_1.SignedTokenConfig.algorithm ||
|
|
104
|
+
header.typ !== signed_token_config_1.SignedTokenConfig.type)
|
|
105
|
+
return [2 /*return*/, null];
|
|
106
|
+
signature = this._fromBase64Url(encodedSignature);
|
|
107
|
+
if (signature === null)
|
|
108
|
+
return [2 /*return*/, null];
|
|
109
|
+
signingInput = this._textEncoder.encode("".concat(encodedHeader).concat(signed_token_config_1.SignedTokenConfig.separator).concat(encodedClaims));
|
|
110
|
+
_i = 0, publicKeys_1 = publicKeys;
|
|
111
|
+
_a.label = 1;
|
|
112
|
+
case 1:
|
|
113
|
+
if (!(_i < publicKeys_1.length)) return [3 /*break*/, 5];
|
|
114
|
+
publicKey = publicKeys_1[_i];
|
|
115
|
+
return [4 /*yield*/, this._publicKey(publicKey).catch(function () { return null; })];
|
|
116
|
+
case 2:
|
|
117
|
+
key = _a.sent();
|
|
118
|
+
if (key === null)
|
|
119
|
+
return [3 /*break*/, 4];
|
|
120
|
+
return [4 /*yield*/, crypto.subtle
|
|
121
|
+
.verify(signed_token_config_1.SignedTokenConfig.signAlgorithm, key, signature, signingInput)
|
|
122
|
+
.catch(function () { return false; })];
|
|
123
|
+
case 3:
|
|
124
|
+
isValid = _a.sent();
|
|
125
|
+
if (isValid)
|
|
126
|
+
return [2 /*return*/, this._decodeJson(encodedClaims)];
|
|
127
|
+
_a.label = 4;
|
|
128
|
+
case 4:
|
|
129
|
+
_i++;
|
|
130
|
+
return [3 /*break*/, 1];
|
|
131
|
+
case 5: return [2 /*return*/, null];
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
SignedTokenService._privateKey = function (privateKey) {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
138
|
+
var cached, key;
|
|
139
|
+
return __generator(this, function (_a) {
|
|
140
|
+
switch (_a.label) {
|
|
141
|
+
case 0:
|
|
142
|
+
cached = this._privateKeys.get(privateKey);
|
|
143
|
+
if (cached !== undefined)
|
|
144
|
+
return [2 /*return*/, cached];
|
|
145
|
+
return [4 /*yield*/, crypto.subtle.importKey(signed_token_config_1.SignedTokenConfig.privateKeyFormat, this._fromBase64(privateKey), signed_token_config_1.SignedTokenConfig.keyAlgorithm, false, ['sign'])];
|
|
146
|
+
case 1:
|
|
147
|
+
key = _a.sent();
|
|
148
|
+
this._remember(this._privateKeys, privateKey, key);
|
|
149
|
+
return [2 /*return*/, key];
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
SignedTokenService._publicKey = function (publicKey) {
|
|
155
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
156
|
+
var cached, key;
|
|
157
|
+
return __generator(this, function (_a) {
|
|
158
|
+
switch (_a.label) {
|
|
159
|
+
case 0:
|
|
160
|
+
cached = this._publicKeys.get(publicKey);
|
|
161
|
+
if (cached !== undefined)
|
|
162
|
+
return [2 /*return*/, cached];
|
|
163
|
+
return [4 /*yield*/, crypto.subtle.importKey(signed_token_config_1.SignedTokenConfig.publicKeyFormat, this._fromBase64(publicKey), signed_token_config_1.SignedTokenConfig.keyAlgorithm, false, ['verify'])];
|
|
164
|
+
case 1:
|
|
165
|
+
key = _a.sent();
|
|
166
|
+
this._remember(this._publicKeys, publicKey, key);
|
|
167
|
+
return [2 /*return*/, key];
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
SignedTokenService._remember = function (cache, source, key) {
|
|
173
|
+
if (cache.size >= signed_token_config_1.SignedTokenConfig.keyCacheLimit) {
|
|
174
|
+
var oldest = cache.keys().next().value;
|
|
175
|
+
if (oldest !== undefined)
|
|
176
|
+
cache.delete(oldest);
|
|
177
|
+
}
|
|
178
|
+
cache.set(source, key);
|
|
179
|
+
};
|
|
180
|
+
SignedTokenService._encodeJson = function (value) {
|
|
181
|
+
return this._toBase64Url(this._textEncoder.encode(JSON.stringify(value)));
|
|
182
|
+
};
|
|
183
|
+
SignedTokenService._decodeJson = function (encoded) {
|
|
184
|
+
var bytes = this._fromBase64Url(encoded);
|
|
185
|
+
if (bytes === null)
|
|
186
|
+
return null;
|
|
187
|
+
try {
|
|
188
|
+
var value = JSON.parse(this._textDecoder.decode(bytes));
|
|
189
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
190
|
+
? value
|
|
191
|
+
: null;
|
|
192
|
+
}
|
|
193
|
+
catch (_a) {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
SignedTokenService._toBase64 = function (bytes) {
|
|
198
|
+
var binary = '';
|
|
199
|
+
for (var index = 0; index < bytes.length; index += 1) {
|
|
200
|
+
binary += String.fromCharCode(bytes[index]);
|
|
201
|
+
}
|
|
202
|
+
return btoa(binary);
|
|
203
|
+
};
|
|
204
|
+
SignedTokenService._fromBase64 = function (value) {
|
|
205
|
+
var binary = atob(value.trim());
|
|
206
|
+
var bytes = new Uint8Array(binary.length);
|
|
207
|
+
for (var index = 0; index < binary.length; index += 1) {
|
|
208
|
+
bytes[index] = binary.charCodeAt(index);
|
|
209
|
+
}
|
|
210
|
+
return bytes;
|
|
211
|
+
};
|
|
212
|
+
SignedTokenService._toBase64Url = function (bytes) {
|
|
213
|
+
return this._toBase64(bytes).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
214
|
+
};
|
|
215
|
+
SignedTokenService._fromBase64Url = function (value) {
|
|
216
|
+
if (!/^[A-Za-z0-9_-]*$/.test(value))
|
|
217
|
+
return null;
|
|
218
|
+
var base64 = value.replace(/-/g, '+').replace(/_/g, '/');
|
|
219
|
+
var padding = base64.length % 4 === 0 ? '' : '='.repeat(4 - (base64.length % 4));
|
|
220
|
+
try {
|
|
221
|
+
return this._fromBase64("".concat(base64).concat(padding));
|
|
222
|
+
}
|
|
223
|
+
catch (_a) {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
SignedTokenService._textEncoder = new TextEncoder();
|
|
228
|
+
SignedTokenService._textDecoder = new TextDecoder();
|
|
229
|
+
SignedTokenService._privateKeys = new Map();
|
|
230
|
+
SignedTokenService._publicKeys = new Map();
|
|
231
|
+
return SignedTokenService;
|
|
232
|
+
}());
|
|
233
|
+
exports.SignedTokenService = SignedTokenService;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { UserTokenClaims } from '../models/user-token-claims';
|
|
2
|
+
import type { UserTokenIssueOptions } from '../models/user-token-issue-options';
|
|
3
|
+
import type { UserTokenRequest } from '../models/user-token-request';
|
|
4
|
+
import type { UserTokenSubject } from '../models/user-token-subject';
|
|
5
|
+
import type { UserTokenVerifyOptions } from '../models/user-token-verify-options';
|
|
6
|
+
export declare class UserTokenService {
|
|
7
|
+
static issue(subject: UserTokenSubject, request: UserTokenRequest, options: UserTokenIssueOptions): Promise<string>;
|
|
8
|
+
static verify(token: string, request: UserTokenRequest, options: UserTokenVerifyOptions): Promise<UserTokenClaims | null>;
|
|
9
|
+
private static _isWellFormed;
|
|
10
|
+
private static _now;
|
|
11
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.UserTokenService = void 0;
|
|
40
|
+
var user_token_config_1 = require("./constants/user-token-config");
|
|
41
|
+
var signed_token_service_1 = require("./signed-token-service");
|
|
42
|
+
var UserTokenService = /** @class */ (function () {
|
|
43
|
+
function UserTokenService() {
|
|
44
|
+
}
|
|
45
|
+
UserTokenService.issue = function (subject, request, options) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
+
var issuedAt, lifetime, claims;
|
|
48
|
+
return __generator(this, function (_a) {
|
|
49
|
+
issuedAt = this._now();
|
|
50
|
+
lifetime = typeof options.lifetimeSeconds === 'number'
|
|
51
|
+
? Math.min(options.lifetimeSeconds, user_token_config_1.UserTokenConfig.maxLifetimeSeconds)
|
|
52
|
+
: user_token_config_1.UserTokenConfig.defaultLifetimeSeconds;
|
|
53
|
+
claims = {
|
|
54
|
+
iss: options.issuer,
|
|
55
|
+
aud: options.audience,
|
|
56
|
+
sub: subject.id,
|
|
57
|
+
email: subject.email.trim().toLowerCase(),
|
|
58
|
+
name: subject.displayName,
|
|
59
|
+
htm: request.method.toUpperCase(),
|
|
60
|
+
htu: request.path,
|
|
61
|
+
iat: issuedAt,
|
|
62
|
+
exp: issuedAt + lifetime,
|
|
63
|
+
jti: crypto.randomUUID(),
|
|
64
|
+
};
|
|
65
|
+
return [2 /*return*/, signed_token_service_1.SignedTokenService.sign(claims, options.privateKey)];
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
UserTokenService.verify = function (token, request, options) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
71
|
+
var claims, now, maxLifetime;
|
|
72
|
+
return __generator(this, function (_a) {
|
|
73
|
+
switch (_a.label) {
|
|
74
|
+
case 0: return [4 /*yield*/, signed_token_service_1.SignedTokenService.verify(token, options.publicKeys)];
|
|
75
|
+
case 1:
|
|
76
|
+
claims = _a.sent();
|
|
77
|
+
if (claims === null || !this._isWellFormed(claims))
|
|
78
|
+
return [2 /*return*/, null];
|
|
79
|
+
now = this._now();
|
|
80
|
+
maxLifetime = typeof options.maxLifetimeSeconds === 'number'
|
|
81
|
+
? options.maxLifetimeSeconds
|
|
82
|
+
: user_token_config_1.UserTokenConfig.maxLifetimeSeconds;
|
|
83
|
+
if (claims.iss !== options.issuer ||
|
|
84
|
+
claims.aud !== options.audience ||
|
|
85
|
+
claims.htm !== request.method.toUpperCase() ||
|
|
86
|
+
claims.htu !== request.path ||
|
|
87
|
+
claims.iat > now + user_token_config_1.UserTokenConfig.clockSkewSeconds ||
|
|
88
|
+
claims.exp <= now - user_token_config_1.UserTokenConfig.clockSkewSeconds ||
|
|
89
|
+
claims.exp - claims.iat > maxLifetime)
|
|
90
|
+
return [2 /*return*/, null];
|
|
91
|
+
return [2 /*return*/, claims];
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
UserTokenService._isWellFormed = function (claims) {
|
|
97
|
+
return (typeof claims.iss === 'string' &&
|
|
98
|
+
typeof claims.aud === 'string' &&
|
|
99
|
+
typeof claims.sub === 'string' &&
|
|
100
|
+
typeof claims.email === 'string' &&
|
|
101
|
+
claims.email !== '' &&
|
|
102
|
+
typeof claims.name === 'string' &&
|
|
103
|
+
typeof claims.htm === 'string' &&
|
|
104
|
+
typeof claims.htu === 'string' &&
|
|
105
|
+
typeof claims.iat === 'number' &&
|
|
106
|
+
typeof claims.exp === 'number' &&
|
|
107
|
+
typeof claims.jti === 'string' &&
|
|
108
|
+
claims.jti !== '');
|
|
109
|
+
};
|
|
110
|
+
UserTokenService._now = function () {
|
|
111
|
+
return Math.floor(Date.now() / user_token_config_1.UserTokenConfig.millisecondsPerSecond);
|
|
112
|
+
};
|
|
113
|
+
return UserTokenService;
|
|
114
|
+
}());
|
|
115
|
+
exports.UserTokenService = UserTokenService;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare class ValidationService {
|
|
2
|
+
static isEmail(value: string): boolean;
|
|
3
|
+
static withProtocol(value: string): string;
|
|
4
|
+
static isWebUrl(value: string): boolean;
|
|
5
|
+
static isPhone(value: string, country: string): boolean;
|
|
6
|
+
static isUuid(value: string): boolean;
|
|
7
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidationService = void 0;
|
|
4
|
+
var validation_config_1 = require("./constants/validation-config");
|
|
5
|
+
var phone_service_1 = require("./phone-service");
|
|
6
|
+
var ValidationService = /** @class */ (function () {
|
|
7
|
+
function ValidationService() {
|
|
8
|
+
}
|
|
9
|
+
ValidationService.isEmail = function (value) {
|
|
10
|
+
return validation_config_1.ValidationConfig.email.test(value.trim());
|
|
11
|
+
};
|
|
12
|
+
ValidationService.withProtocol = function (value) {
|
|
13
|
+
var trimmed = value.trim();
|
|
14
|
+
if (trimmed === '' || validation_config_1.ValidationConfig.urlProtocolPattern.test(trimmed))
|
|
15
|
+
return trimmed;
|
|
16
|
+
return "".concat(validation_config_1.ValidationConfig.urlProtocol).concat(trimmed);
|
|
17
|
+
};
|
|
18
|
+
ValidationService.isWebUrl = function (value) {
|
|
19
|
+
try {
|
|
20
|
+
var url_1 = new URL(ValidationService.withProtocol(value));
|
|
21
|
+
return (validation_config_1.ValidationConfig.webProtocols.some(function (protocol) { return protocol === url_1.protocol; }) &&
|
|
22
|
+
url_1.hostname.includes(validation_config_1.ValidationConfig.hostSeparator));
|
|
23
|
+
}
|
|
24
|
+
catch (_a) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
ValidationService.isPhone = function (value, country) {
|
|
29
|
+
return value.trim() !== '' && phone_service_1.PhoneService.isValid(value, country);
|
|
30
|
+
};
|
|
31
|
+
ValidationService.isUuid = function (value) {
|
|
32
|
+
return validation_config_1.ValidationConfig.uuid.test(value.trim());
|
|
33
|
+
};
|
|
34
|
+
return ValidationService;
|
|
35
|
+
}());
|
|
36
|
+
exports.ValidationService = ValidationService;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,5 +3,15 @@ import * as CommonNamespace from './common';
|
|
|
3
3
|
export declare const Common: typeof CommonNamespace;
|
|
4
4
|
export declare const Client: typeof ClientNamespace;
|
|
5
5
|
export type { EmailPreviewInput } from './models/email-preview-input';
|
|
6
|
+
export type { SignedTokenHeader } from './models/signed-token-header';
|
|
7
|
+
export type { SignedTokenKeyPair } from './models/signed-token-key-pair';
|
|
8
|
+
export type { UserTokenClaims } from './models/user-token-claims';
|
|
9
|
+
export type { UserTokenIssueOptions } from './models/user-token-issue-options';
|
|
10
|
+
export type { UserTokenRequest } from './models/user-token-request';
|
|
11
|
+
export type { UserTokenSubject } from './models/user-token-subject';
|
|
12
|
+
export type { UserTokenVerifyOptions } from './models/user-token-verify-options';
|
|
6
13
|
export type { EncryptedFieldsSpec } from './common/encrypted-fields-service';
|
|
7
14
|
export type { DataKeyPair } from './common/envelope-crypto-service';
|
|
15
|
+
export type { PhoneCountryData } from './models/phone-country-data';
|
|
16
|
+
export type { PhoneDisplayData } from './models/phone-display-data';
|
|
17
|
+
export type { PostalCodeFormatData } from './models/postal-code-format-data';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pallasoft/ps-utilities",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -69,7 +69,8 @@
|
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"@esbuild-plugins/tsconfig-paths": "^0.1.2",
|
|
71
71
|
"dayjs": "^1.11.19",
|
|
72
|
-
"esbuild": "^0.27.0"
|
|
72
|
+
"esbuild": "^0.27.0",
|
|
73
|
+
"libphonenumber-js": "^1.13.14"
|
|
73
74
|
},
|
|
74
75
|
"publishConfig": {
|
|
75
76
|
"access": "public",
|