@pallasoft/ps-utilities 2.11.0 → 2.13.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 +2 -0
- package/dist/common/amount-service.js +9 -0
- package/dist/common/constants/amount-config.d.ts +1 -0
- package/dist/common/constants/amount-config.js +1 -0
- package/dist/common/constants/amount-direction.d.ts +5 -0
- package/dist/common/constants/amount-direction.js +9 -0
- package/dist/common/constants/error-response-config.d.ts +4 -0
- package/dist/common/constants/error-response-config.js +7 -0
- package/dist/common/constants/index.d.ts +2 -0
- package/dist/common/constants/index.js +2 -0
- package/dist/common/constants/user-token-config.d.ts +0 -1
- package/dist/common/constants/user-token-config.js +0 -1
- package/dist/common/date-service.d.ts +4 -0
- package/dist/common/date-service.js +12 -0
- package/dist/common/error-response-service.d.ts +7 -0
- package/dist/common/error-response-service.js +34 -0
- package/dist/common/index.d.ts +1 -0
- package/dist/common/index.js +1 -0
- package/dist/common/socket-token-service.js +3 -2
- package/dist/common/user-token-service.js +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/package.json +1 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { AmountDirection } from './constants/amount-direction';
|
|
1
2
|
export declare class AmountService {
|
|
2
3
|
static normalise(raw: string): string;
|
|
3
4
|
static toNumber(raw: string): number;
|
|
4
5
|
static isAmount(raw: string): boolean;
|
|
6
|
+
static direction(raw: string): AmountDirection;
|
|
5
7
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AmountService = void 0;
|
|
4
4
|
var amount_config_1 = require("./constants/amount-config");
|
|
5
|
+
var amount_direction_1 = require("./constants/amount-direction");
|
|
5
6
|
var AmountService = /** @class */ (function () {
|
|
6
7
|
function AmountService() {
|
|
7
8
|
}
|
|
@@ -30,6 +31,14 @@ var AmountService = /** @class */ (function () {
|
|
|
30
31
|
var normalised = AmountService.normalise(raw);
|
|
31
32
|
return (normalised !== '' && normalised !== amount_config_1.AmountConfig.minus && Number.isFinite(Number(normalised)));
|
|
32
33
|
};
|
|
34
|
+
AmountService.direction = function (raw) {
|
|
35
|
+
if (!AmountService.isAmount(raw))
|
|
36
|
+
return amount_direction_1.AmountDirection.Neutral;
|
|
37
|
+
var normalised = AmountService.normalise(raw);
|
|
38
|
+
if (amount_config_1.AmountConfig.zeroPattern.test(normalised))
|
|
39
|
+
return amount_direction_1.AmountDirection.Neutral;
|
|
40
|
+
return normalised.startsWith(amount_config_1.AmountConfig.minus) ? amount_direction_1.AmountDirection.Out : amount_direction_1.AmountDirection.In;
|
|
41
|
+
};
|
|
33
42
|
return AmountService;
|
|
34
43
|
}());
|
|
35
44
|
exports.AmountService = AmountService;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AmountDirection = void 0;
|
|
4
|
+
var AmountDirection;
|
|
5
|
+
(function (AmountDirection) {
|
|
6
|
+
AmountDirection["In"] = "in";
|
|
7
|
+
AmountDirection["Neutral"] = "neutral";
|
|
8
|
+
AmountDirection["Out"] = "out";
|
|
9
|
+
})(AmountDirection || (exports.AmountDirection = AmountDirection = {}));
|
|
@@ -24,3 +24,5 @@ __exportStar(require("./validation-config"), exports);
|
|
|
24
24
|
__exportStar(require("./file-size-config"), exports);
|
|
25
25
|
__exportStar(require("./socket-token-config"), exports);
|
|
26
26
|
__exportStar(require("./user-agent-config"), exports);
|
|
27
|
+
__exportStar(require("./amount-direction"), exports);
|
|
28
|
+
__exportStar(require("./error-response-config"), exports);
|
|
@@ -15,4 +15,8 @@ export declare class DateService {
|
|
|
15
15
|
static formatDateToString(date: string | number, short?: boolean): string;
|
|
16
16
|
static formatTimeToString(date: string | number, short?: boolean): string;
|
|
17
17
|
static diffInMins(startDate: string | number, endDate: string | number): number;
|
|
18
|
+
static nowMilliseconds(): number;
|
|
19
|
+
static nowUnixSeconds(): number;
|
|
20
|
+
static fromParts(year: number, monthIndex: number, day: number): Dayjs;
|
|
21
|
+
static isValid(date: string | number): boolean;
|
|
18
22
|
}
|
|
@@ -85,6 +85,18 @@ var DateService = /** @class */ (function () {
|
|
|
85
85
|
var end = (0, dayjs_1.default)(endDate);
|
|
86
86
|
return end.diff(start, 'minutes');
|
|
87
87
|
};
|
|
88
|
+
DateService.nowMilliseconds = function () {
|
|
89
|
+
return (0, dayjs_1.default)().valueOf();
|
|
90
|
+
};
|
|
91
|
+
DateService.nowUnixSeconds = function () {
|
|
92
|
+
return (0, dayjs_1.default)().unix();
|
|
93
|
+
};
|
|
94
|
+
DateService.fromParts = function (year, monthIndex, day) {
|
|
95
|
+
return (0, dayjs_1.default)("".concat(String(year).padStart(4, '0'), "-").concat(String(monthIndex + 1).padStart(2, '0'), "-").concat(String(day).padStart(2, '0')));
|
|
96
|
+
};
|
|
97
|
+
DateService.isValid = function (date) {
|
|
98
|
+
return (0, dayjs_1.default)(date).isValid();
|
|
99
|
+
};
|
|
88
100
|
return DateService;
|
|
89
101
|
}());
|
|
90
102
|
exports.DateService = DateService;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare class ErrorResponseService {
|
|
2
|
+
static code(error: unknown): number | null;
|
|
3
|
+
static isClientError(status: number): boolean;
|
|
4
|
+
static pageContent<Content extends {
|
|
5
|
+
description: string;
|
|
6
|
+
}>(status: number, message: string | undefined, base: Content): Content;
|
|
7
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.ErrorResponseService = void 0;
|
|
15
|
+
var error_response_config_1 = require("./constants/error-response-config");
|
|
16
|
+
var ErrorResponseService = /** @class */ (function () {
|
|
17
|
+
function ErrorResponseService() {
|
|
18
|
+
}
|
|
19
|
+
ErrorResponseService.code = function (error) {
|
|
20
|
+
if (typeof error !== 'object' || error === null || !('code' in error))
|
|
21
|
+
return null;
|
|
22
|
+
return typeof error.code === 'number' ? error.code : null;
|
|
23
|
+
};
|
|
24
|
+
ErrorResponseService.isClientError = function (status) {
|
|
25
|
+
return (status >= error_response_config_1.ErrorResponseConfig.clientErrorStart &&
|
|
26
|
+
status < error_response_config_1.ErrorResponseConfig.serverErrorStart);
|
|
27
|
+
};
|
|
28
|
+
ErrorResponseService.pageContent = function (status, message, base) {
|
|
29
|
+
return ErrorResponseService.isClientError(status) && message !== undefined && message !== ''
|
|
30
|
+
? __assign(__assign({}, base), { description: message }) : base;
|
|
31
|
+
};
|
|
32
|
+
return ErrorResponseService;
|
|
33
|
+
}());
|
|
34
|
+
exports.ErrorResponseService = ErrorResponseService;
|
package/dist/common/index.d.ts
CHANGED
package/dist/common/index.js
CHANGED
|
@@ -35,3 +35,4 @@ __exportStar(require("./url-service"), exports);
|
|
|
35
35
|
__exportStar(require("./user-agent-service"), exports);
|
|
36
36
|
__exportStar(require("./user-token-service"), exports);
|
|
37
37
|
__exportStar(require("./validation-service"), exports);
|
|
38
|
+
__exportStar(require("./error-response-service"), exports);
|
|
@@ -38,6 +38,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.SocketTokenService = void 0;
|
|
40
40
|
var socket_token_config_1 = require("./constants/socket-token-config");
|
|
41
|
+
var date_service_1 = require("./date-service");
|
|
41
42
|
var signed_token_service_1 = require("./signed-token-service");
|
|
42
43
|
var SocketTokenService = /** @class */ (function () {
|
|
43
44
|
function SocketTokenService() {
|
|
@@ -49,7 +50,7 @@ var SocketTokenService = /** @class */ (function () {
|
|
|
49
50
|
return __generator(this, function (_a) {
|
|
50
51
|
claims = {
|
|
51
52
|
scope: scope,
|
|
52
|
-
exp:
|
|
53
|
+
exp: date_service_1.DateService.nowUnixSeconds() + seconds,
|
|
53
54
|
};
|
|
54
55
|
return [2 /*return*/, signed_token_service_1.SignedTokenService.sign(claims, privateKey)];
|
|
55
56
|
});
|
|
@@ -67,7 +68,7 @@ var SocketTokenService = /** @class */ (function () {
|
|
|
67
68
|
typeof claims.scope !== 'string' ||
|
|
68
69
|
claims.scope === '' ||
|
|
69
70
|
typeof claims.exp !== 'number' ||
|
|
70
|
-
claims.exp * socket_token_config_1.SocketTokenConfig.millisecondsPerSecond <
|
|
71
|
+
claims.exp * socket_token_config_1.SocketTokenConfig.millisecondsPerSecond < date_service_1.DateService.nowMilliseconds())
|
|
71
72
|
return [2 /*return*/, null];
|
|
72
73
|
return [2 /*return*/, claims.scope];
|
|
73
74
|
}
|
|
@@ -38,6 +38,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.UserTokenService = void 0;
|
|
40
40
|
var user_token_config_1 = require("./constants/user-token-config");
|
|
41
|
+
var date_service_1 = require("./date-service");
|
|
41
42
|
var signed_token_service_1 = require("./signed-token-service");
|
|
42
43
|
var UserTokenService = /** @class */ (function () {
|
|
43
44
|
function UserTokenService() {
|
|
@@ -108,7 +109,7 @@ var UserTokenService = /** @class */ (function () {
|
|
|
108
109
|
claims.jti !== '');
|
|
109
110
|
};
|
|
110
111
|
UserTokenService._now = function () {
|
|
111
|
-
return
|
|
112
|
+
return date_service_1.DateService.nowUnixSeconds();
|
|
112
113
|
};
|
|
113
114
|
return UserTokenService;
|
|
114
115
|
}());
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import * as ClientNamespace from './client';
|
|
|
2
2
|
import * as CommonNamespace from './common';
|
|
3
3
|
export declare const Common: typeof CommonNamespace;
|
|
4
4
|
export declare const Client: typeof ClientNamespace;
|
|
5
|
+
export { AmountDirection } from './common/constants/amount-direction';
|
|
5
6
|
export type { EmailPreviewInput } from './models/email-preview-input';
|
|
6
7
|
export type { SignedTokenHeader } from './models/signed-token-header';
|
|
7
8
|
export type { SignedTokenKeyPair } from './models/signed-token-key-pair';
|
package/dist/index.js
CHANGED
|
@@ -33,8 +33,10 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.Client = exports.Common = void 0;
|
|
36
|
+
exports.AmountDirection = exports.Client = exports.Common = void 0;
|
|
37
37
|
var ClientNamespace = __importStar(require("./client"));
|
|
38
38
|
var CommonNamespace = __importStar(require("./common"));
|
|
39
39
|
exports.Common = CommonNamespace;
|
|
40
40
|
exports.Client = ClientNamespace;
|
|
41
|
+
var amount_direction_1 = require("./common/constants/amount-direction");
|
|
42
|
+
Object.defineProperty(exports, "AmountDirection", { enumerable: true, get: function () { return amount_direction_1.AmountDirection; } });
|