@pallasoft/ps-utilities 2.13.0 → 2.15.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/client/constants/device-config.d.ts +6 -0
- package/dist/client/constants/device-config.js +9 -0
- package/dist/client/device-service.d.ts +5 -0
- package/dist/client/device-service.js +22 -0
- package/dist/client/http-service.js +16 -12
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.js +1 -0
- package/dist/common/constants/http-content-type.d.ts +8 -0
- package/dist/common/constants/http-content-type.js +11 -0
- package/dist/common/constants/http-header.d.ts +20 -0
- package/dist/common/constants/http-header.js +23 -0
- package/dist/common/constants/http-method.d.ts +9 -0
- package/dist/common/constants/http-method.js +13 -0
- package/dist/common/constants/index.d.ts +5 -0
- package/dist/common/constants/index.js +5 -0
- package/dist/common/constants/relative-time-config.d.ts +21 -0
- package/dist/common/constants/relative-time-config.js +14 -0
- package/dist/common/constants/request-client-config.d.ts +5 -0
- package/dist/common/constants/request-client-config.js +9 -0
- package/dist/common/date-service.d.ts +3 -0
- package/dist/common/date-service.js +9 -0
- package/dist/common/error-response-service.d.ts +2 -0
- package/dist/common/error-response-service.js +3 -0
- package/dist/common/index.d.ts +3 -0
- package/dist/common/index.js +3 -0
- package/dist/common/json-service.d.ts +5 -0
- package/dist/common/json-service.js +23 -0
- package/dist/common/relative-time-service.d.ts +4 -0
- package/dist/common/relative-time-service.js +25 -0
- package/dist/common/request-client-service.d.ts +6 -0
- package/dist/common/request-client-service.js +28 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +3 -1
- package/dist/models/coded-error-data.d.ts +3 -0
- package/dist/models/coded-error-data.js +2 -0
- package/dist/models/device-data.d.ts +4 -0
- package/dist/models/device-data.js +2 -0
- package/dist/models/json-value-guard.d.ts +1 -0
- package/dist/models/json-value-guard.js +2 -0
- package/dist/models/relative-time-options.d.ts +5 -0
- package/dist/models/relative-time-options.js +2 -0
- package/dist/models/request-client-data.d.ts +4 -0
- package/dist/models/request-client-data.js +2 -0
- package/dist/models/request-client-options.d.ts +4 -0
- package/dist/models/request-client-options.js +2 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +1 -0
- package/dist/server/timing-safe-service.d.ts +3 -0
- package/dist/server/timing-safe-service.js +15 -0
- package/package.json +5 -3
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeviceConfig = void 0;
|
|
4
|
+
exports.DeviceConfig = {
|
|
5
|
+
ios: /iPhone|iPad|iPod/i,
|
|
6
|
+
macintosh: /Macintosh/i,
|
|
7
|
+
mobile: /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Mobile|Tablet|Silk|Kindle/i,
|
|
8
|
+
touchPointsForTablet: 1,
|
|
9
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeviceService = void 0;
|
|
4
|
+
var device_config_1 = require("./constants/device-config");
|
|
5
|
+
var DeviceService = /** @class */ (function () {
|
|
6
|
+
function DeviceService() {
|
|
7
|
+
}
|
|
8
|
+
DeviceService.fromUserAgent = function (userAgent, maxTouchPoints) {
|
|
9
|
+
var isIPadOS = device_config_1.DeviceConfig.macintosh.test(userAgent) && maxTouchPoints > device_config_1.DeviceConfig.touchPointsForTablet;
|
|
10
|
+
return {
|
|
11
|
+
isIOS: device_config_1.DeviceConfig.ios.test(userAgent) || isIPadOS,
|
|
12
|
+
isMobile: device_config_1.DeviceConfig.mobile.test(userAgent) || isIPadOS,
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
DeviceService.current = function () {
|
|
16
|
+
if (typeof navigator === 'undefined')
|
|
17
|
+
return { isIOS: false, isMobile: false };
|
|
18
|
+
return DeviceService.fromUserAgent(navigator.userAgent, navigator.maxTouchPoints);
|
|
19
|
+
};
|
|
20
|
+
return DeviceService;
|
|
21
|
+
}());
|
|
22
|
+
exports.DeviceService = DeviceService;
|
|
@@ -37,6 +37,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.HttpService = void 0;
|
|
40
|
+
var http_content_type_1 = require("../common/constants/http-content-type");
|
|
41
|
+
var http_header_1 = require("../common/constants/http-header");
|
|
42
|
+
var http_method_1 = require("../common/constants/http-method");
|
|
40
43
|
var isBinaryBody = function (data) {
|
|
41
44
|
return data instanceof FormData ||
|
|
42
45
|
data instanceof Blob ||
|
|
@@ -49,17 +52,18 @@ var HttpService = /** @class */ (function () {
|
|
|
49
52
|
HttpService.createApiClient = function (options) {
|
|
50
53
|
var _this = this;
|
|
51
54
|
if (options === void 0) { options = {}; }
|
|
52
|
-
var apiKey = options.apiKey, _a = options.apiKeyHeader, apiKeyHeader = _a === void 0 ?
|
|
55
|
+
var apiKey = options.apiKey, _a = options.apiKeyHeader, apiKeyHeader = _a === void 0 ? http_header_1.HttpHeader.apiKey : _a, baseURL = options.baseURL, defaultHeaders = options.headers;
|
|
53
56
|
var request = function (method, url, data, config) { return __awaiter(_this, void 0, void 0, function () {
|
|
54
57
|
var fullUrl, sendsBinaryBody, headers, body, response, responseData, error;
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
var _a;
|
|
59
|
+
return __generator(this, function (_b) {
|
|
60
|
+
switch (_b.label) {
|
|
57
61
|
case 0:
|
|
58
62
|
fullUrl = baseURL ? "".concat(baseURL).concat(url) : url;
|
|
59
63
|
sendsBinaryBody = isBinaryBody(data);
|
|
60
64
|
headers = sendsBinaryBody
|
|
61
65
|
? {}
|
|
62
|
-
: {
|
|
66
|
+
: (_a = {}, _a[http_header_1.HttpHeader.contentType] = http_content_type_1.HttpContentType.json, _a);
|
|
63
67
|
if (defaultHeaders)
|
|
64
68
|
Object.assign(headers, defaultHeaders);
|
|
65
69
|
if (apiKey)
|
|
@@ -69,18 +73,18 @@ var HttpService = /** @class */ (function () {
|
|
|
69
73
|
body = data === undefined ? undefined : sendsBinaryBody ? data : JSON.stringify(data);
|
|
70
74
|
return [4 /*yield*/, fetch(fullUrl, { method: method, headers: headers, body: body })];
|
|
71
75
|
case 1:
|
|
72
|
-
response =
|
|
76
|
+
response = _b.sent();
|
|
73
77
|
return [4 /*yield*/, ((config === null || config === void 0 ? void 0 : config.responseType) === 'arraybuffer'
|
|
74
78
|
? response.arrayBuffer()
|
|
75
79
|
: (config === null || config === void 0 ? void 0 : config.responseType) === 'text'
|
|
76
80
|
? response.text()
|
|
77
81
|
: (config === null || config === void 0 ? void 0 : config.responseType) === 'json'
|
|
78
82
|
? response.json()
|
|
79
|
-
: String(response.headers.get(
|
|
83
|
+
: String(response.headers.get(http_header_1.HttpHeader.contentType)).includes(http_content_type_1.HttpContentType.json)
|
|
80
84
|
? response.json()
|
|
81
85
|
: response.text())];
|
|
82
86
|
case 2:
|
|
83
|
-
responseData =
|
|
87
|
+
responseData = _b.sent();
|
|
84
88
|
if (!response.ok) {
|
|
85
89
|
error = new Error("Request failed with status ".concat(response.status));
|
|
86
90
|
error.response = { data: responseData, status: response.status };
|
|
@@ -92,19 +96,19 @@ var HttpService = /** @class */ (function () {
|
|
|
92
96
|
}); };
|
|
93
97
|
return {
|
|
94
98
|
get: function (url, config) {
|
|
95
|
-
return request(
|
|
99
|
+
return request(http_method_1.HttpMethod.Get, url, undefined, config);
|
|
96
100
|
},
|
|
97
101
|
post: function (url, data, config) {
|
|
98
|
-
return request(
|
|
102
|
+
return request(http_method_1.HttpMethod.Post, url, data, config);
|
|
99
103
|
},
|
|
100
104
|
put: function (url, data, config) {
|
|
101
|
-
return request(
|
|
105
|
+
return request(http_method_1.HttpMethod.Put, url, data, config);
|
|
102
106
|
},
|
|
103
107
|
patch: function (url, data, config) {
|
|
104
|
-
return request(
|
|
108
|
+
return request(http_method_1.HttpMethod.Patch, url, data, config);
|
|
105
109
|
},
|
|
106
110
|
delete: function (url, config) {
|
|
107
|
-
return request(
|
|
111
|
+
return request(http_method_1.HttpMethod.Delete, url, undefined, config);
|
|
108
112
|
},
|
|
109
113
|
};
|
|
110
114
|
};
|
package/dist/client/index.d.ts
CHANGED
package/dist/client/index.js
CHANGED
|
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./debounce-service"), exports);
|
|
18
|
+
__exportStar(require("./device-service"), exports);
|
|
18
19
|
__exportStar(require("./http-service"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const HttpContentType: {
|
|
2
|
+
readonly formUrlEncoded: "application/x-www-form-urlencoded";
|
|
3
|
+
readonly html: "text/html";
|
|
4
|
+
readonly json: "application/json";
|
|
5
|
+
readonly multipartFormData: "multipart/form-data";
|
|
6
|
+
readonly octetStream: "application/octet-stream";
|
|
7
|
+
readonly plainText: "text/plain";
|
|
8
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpContentType = void 0;
|
|
4
|
+
exports.HttpContentType = {
|
|
5
|
+
formUrlEncoded: 'application/x-www-form-urlencoded',
|
|
6
|
+
html: 'text/html',
|
|
7
|
+
json: 'application/json',
|
|
8
|
+
multipartFormData: 'multipart/form-data',
|
|
9
|
+
octetStream: 'application/octet-stream',
|
|
10
|
+
plainText: 'text/plain',
|
|
11
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const HttpHeader: {
|
|
2
|
+
readonly accept: "Accept";
|
|
3
|
+
readonly apiKey: "X-API-Key";
|
|
4
|
+
readonly authorization: "Authorization";
|
|
5
|
+
readonly cacheControl: "Cache-Control";
|
|
6
|
+
readonly cfConnectingIp: "CF-Connecting-IP";
|
|
7
|
+
readonly contentDisposition: "Content-Disposition";
|
|
8
|
+
readonly contentSecurityPolicy: "Content-Security-Policy";
|
|
9
|
+
readonly contentType: "Content-Type";
|
|
10
|
+
readonly contentTypeOptions: "X-Content-Type-Options";
|
|
11
|
+
readonly cookie: "Cookie";
|
|
12
|
+
readonly forwardedFor: "X-Forwarded-For";
|
|
13
|
+
readonly frameOptions: "X-Frame-Options";
|
|
14
|
+
readonly location: "Location";
|
|
15
|
+
readonly realIp: "X-Real-IP";
|
|
16
|
+
readonly robotsTag: "X-Robots-Tag";
|
|
17
|
+
readonly setCookie: "Set-Cookie";
|
|
18
|
+
readonly strictTransportSecurity: "Strict-Transport-Security";
|
|
19
|
+
readonly userAgent: "User-Agent";
|
|
20
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpHeader = void 0;
|
|
4
|
+
exports.HttpHeader = {
|
|
5
|
+
accept: 'Accept',
|
|
6
|
+
apiKey: 'X-API-Key',
|
|
7
|
+
authorization: 'Authorization',
|
|
8
|
+
cacheControl: 'Cache-Control',
|
|
9
|
+
cfConnectingIp: 'CF-Connecting-IP',
|
|
10
|
+
contentDisposition: 'Content-Disposition',
|
|
11
|
+
contentSecurityPolicy: 'Content-Security-Policy',
|
|
12
|
+
contentType: 'Content-Type',
|
|
13
|
+
contentTypeOptions: 'X-Content-Type-Options',
|
|
14
|
+
cookie: 'Cookie',
|
|
15
|
+
forwardedFor: 'X-Forwarded-For',
|
|
16
|
+
frameOptions: 'X-Frame-Options',
|
|
17
|
+
location: 'Location',
|
|
18
|
+
realIp: 'X-Real-IP',
|
|
19
|
+
robotsTag: 'X-Robots-Tag',
|
|
20
|
+
setCookie: 'Set-Cookie',
|
|
21
|
+
strictTransportSecurity: 'Strict-Transport-Security',
|
|
22
|
+
userAgent: 'User-Agent',
|
|
23
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpMethod = void 0;
|
|
4
|
+
var HttpMethod;
|
|
5
|
+
(function (HttpMethod) {
|
|
6
|
+
HttpMethod["Delete"] = "DELETE";
|
|
7
|
+
HttpMethod["Get"] = "GET";
|
|
8
|
+
HttpMethod["Head"] = "HEAD";
|
|
9
|
+
HttpMethod["Options"] = "OPTIONS";
|
|
10
|
+
HttpMethod["Patch"] = "PATCH";
|
|
11
|
+
HttpMethod["Post"] = "POST";
|
|
12
|
+
HttpMethod["Put"] = "PUT";
|
|
13
|
+
})(HttpMethod || (exports.HttpMethod = HttpMethod = {}));
|
|
@@ -10,3 +10,8 @@ export * from './socket-token-config';
|
|
|
10
10
|
export * from './user-agent-config';
|
|
11
11
|
export * from './amount-direction';
|
|
12
12
|
export * from './error-response-config';
|
|
13
|
+
export * from './http-content-type';
|
|
14
|
+
export * from './http-header';
|
|
15
|
+
export * from './http-method';
|
|
16
|
+
export * from './relative-time-config';
|
|
17
|
+
export * from './request-client-config';
|
|
@@ -26,3 +26,8 @@ __exportStar(require("./socket-token-config"), exports);
|
|
|
26
26
|
__exportStar(require("./user-agent-config"), exports);
|
|
27
27
|
__exportStar(require("./amount-direction"), exports);
|
|
28
28
|
__exportStar(require("./error-response-config"), exports);
|
|
29
|
+
__exportStar(require("./http-content-type"), exports);
|
|
30
|
+
__exportStar(require("./http-header"), exports);
|
|
31
|
+
__exportStar(require("./http-method"), exports);
|
|
32
|
+
__exportStar(require("./relative-time-config"), exports);
|
|
33
|
+
__exportStar(require("./request-client-config"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const RelativeTimeConfig: {
|
|
2
|
+
readonly futureToleranceSeconds: 300;
|
|
3
|
+
readonly justNowSeconds: 45;
|
|
4
|
+
readonly millisecondsPerSecond: 1000;
|
|
5
|
+
readonly format: {
|
|
6
|
+
readonly numeric: "auto";
|
|
7
|
+
};
|
|
8
|
+
readonly units: readonly [{
|
|
9
|
+
readonly limitSeconds: 3600;
|
|
10
|
+
readonly seconds: 60;
|
|
11
|
+
readonly unit: "minute";
|
|
12
|
+
}, {
|
|
13
|
+
readonly limitSeconds: 86400;
|
|
14
|
+
readonly seconds: 3600;
|
|
15
|
+
readonly unit: "hour";
|
|
16
|
+
}, {
|
|
17
|
+
readonly limitSeconds: 604800;
|
|
18
|
+
readonly seconds: 86400;
|
|
19
|
+
readonly unit: "day";
|
|
20
|
+
}];
|
|
21
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RelativeTimeConfig = void 0;
|
|
4
|
+
exports.RelativeTimeConfig = {
|
|
5
|
+
futureToleranceSeconds: 300,
|
|
6
|
+
justNowSeconds: 45,
|
|
7
|
+
millisecondsPerSecond: 1000,
|
|
8
|
+
format: { numeric: 'auto' },
|
|
9
|
+
units: [
|
|
10
|
+
{ limitSeconds: 3600, seconds: 60, unit: 'minute' },
|
|
11
|
+
{ limitSeconds: 86400, seconds: 3600, unit: 'hour' },
|
|
12
|
+
{ limitSeconds: 604800, seconds: 86400, unit: 'day' },
|
|
13
|
+
],
|
|
14
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequestClientConfig = void 0;
|
|
4
|
+
var http_header_1 = require("./http-header");
|
|
5
|
+
exports.RequestClientConfig = {
|
|
6
|
+
addressHeaders: [http_header_1.HttpHeader.cfConnectingIp, http_header_1.HttpHeader.realIp, http_header_1.HttpHeader.forwardedFor],
|
|
7
|
+
agentHeader: http_header_1.HttpHeader.userAgent,
|
|
8
|
+
listSeparator: ',',
|
|
9
|
+
};
|
|
@@ -19,4 +19,7 @@ export declare class DateService {
|
|
|
19
19
|
static nowUnixSeconds(): number;
|
|
20
20
|
static fromParts(year: number, monthIndex: number, day: number): Dayjs;
|
|
21
21
|
static isValid(date: string | number): boolean;
|
|
22
|
+
static addDays(date: string, days: number): string;
|
|
23
|
+
static addDaysToInstant(instant: Date, days: number): Date;
|
|
24
|
+
static startOfUtcDay(instant: Date): Date;
|
|
22
25
|
}
|
|
@@ -97,6 +97,15 @@ var DateService = /** @class */ (function () {
|
|
|
97
97
|
DateService.isValid = function (date) {
|
|
98
98
|
return (0, dayjs_1.default)(date).isValid();
|
|
99
99
|
};
|
|
100
|
+
DateService.addDays = function (date, days) {
|
|
101
|
+
return dayjs_1.default.utc(date).add(days, 'day').format('YYYY-MM-DD');
|
|
102
|
+
};
|
|
103
|
+
DateService.addDaysToInstant = function (instant, days) {
|
|
104
|
+
return dayjs_1.default.utc(instant).add(days, 'day').toDate();
|
|
105
|
+
};
|
|
106
|
+
DateService.startOfUtcDay = function (instant) {
|
|
107
|
+
return dayjs_1.default.utc(instant).startOf('day').toDate();
|
|
108
|
+
};
|
|
100
109
|
return DateService;
|
|
101
110
|
}());
|
|
102
111
|
exports.DateService = DateService;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { CodedErrorData } from '../models/coded-error-data';
|
|
1
2
|
export declare class ErrorResponseService {
|
|
3
|
+
static create(message: string, code: number): CodedErrorData;
|
|
2
4
|
static code(error: unknown): number | null;
|
|
3
5
|
static isClientError(status: number): boolean;
|
|
4
6
|
static pageContent<Content extends {
|
|
@@ -16,6 +16,9 @@ var error_response_config_1 = require("./constants/error-response-config");
|
|
|
16
16
|
var ErrorResponseService = /** @class */ (function () {
|
|
17
17
|
function ErrorResponseService() {
|
|
18
18
|
}
|
|
19
|
+
ErrorResponseService.create = function (message, code) {
|
|
20
|
+
return Object.assign(new Error(message), { code: code });
|
|
21
|
+
};
|
|
19
22
|
ErrorResponseService.code = function (error) {
|
|
20
23
|
if (typeof error !== 'object' || error === null || !('code' in error))
|
|
21
24
|
return null;
|
package/dist/common/index.d.ts
CHANGED
|
@@ -20,3 +20,6 @@ export * from './user-agent-service';
|
|
|
20
20
|
export * from './user-token-service';
|
|
21
21
|
export * from './validation-service';
|
|
22
22
|
export * from './error-response-service';
|
|
23
|
+
export * from './relative-time-service';
|
|
24
|
+
export * from './request-client-service';
|
|
25
|
+
export * from './json-service';
|
package/dist/common/index.js
CHANGED
|
@@ -36,3 +36,6 @@ __exportStar(require("./user-agent-service"), exports);
|
|
|
36
36
|
__exportStar(require("./user-token-service"), exports);
|
|
37
37
|
__exportStar(require("./validation-service"), exports);
|
|
38
38
|
__exportStar(require("./error-response-service"), exports);
|
|
39
|
+
__exportStar(require("./relative-time-service"), exports);
|
|
40
|
+
__exportStar(require("./request-client-service"), exports);
|
|
41
|
+
__exportStar(require("./json-service"), exports);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JsonService = void 0;
|
|
4
|
+
var JsonService = /** @class */ (function () {
|
|
5
|
+
function JsonService() {
|
|
6
|
+
}
|
|
7
|
+
JsonService.read = function (text) {
|
|
8
|
+
if (typeof text !== 'string')
|
|
9
|
+
return undefined;
|
|
10
|
+
try {
|
|
11
|
+
return JSON.parse(text);
|
|
12
|
+
}
|
|
13
|
+
catch (_a) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
JsonService.parse = function (text, guard) {
|
|
18
|
+
var value = this.read(text);
|
|
19
|
+
return value !== undefined && guard(value) ? value : null;
|
|
20
|
+
};
|
|
21
|
+
return JsonService;
|
|
22
|
+
}());
|
|
23
|
+
exports.JsonService = JsonService;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RelativeTimeService = void 0;
|
|
4
|
+
var relative_time_config_1 = require("./constants/relative-time-config");
|
|
5
|
+
var date_service_1 = require("./date-service");
|
|
6
|
+
var RelativeTimeService = /** @class */ (function () {
|
|
7
|
+
function RelativeTimeService() {
|
|
8
|
+
}
|
|
9
|
+
RelativeTimeService.format = function (value, now, options) {
|
|
10
|
+
if (!date_service_1.DateService.isValid(value))
|
|
11
|
+
return value;
|
|
12
|
+
var seconds = (now.getTime() - date_service_1.DateService.getDate(value).valueOf()) /
|
|
13
|
+
relative_time_config_1.RelativeTimeConfig.millisecondsPerSecond;
|
|
14
|
+
if (seconds < -relative_time_config_1.RelativeTimeConfig.futureToleranceSeconds)
|
|
15
|
+
return options.formatDate(value);
|
|
16
|
+
if (seconds < relative_time_config_1.RelativeTimeConfig.justNowSeconds)
|
|
17
|
+
return options.justNow;
|
|
18
|
+
var step = relative_time_config_1.RelativeTimeConfig.units.find(function (unit) { return seconds < unit.limitSeconds; });
|
|
19
|
+
return step === undefined
|
|
20
|
+
? options.formatDate(value)
|
|
21
|
+
: new Intl.RelativeTimeFormat(options.locale, relative_time_config_1.RelativeTimeConfig.format).format(-Math.max(1, Math.round(seconds / step.seconds)), step.unit);
|
|
22
|
+
};
|
|
23
|
+
return RelativeTimeService;
|
|
24
|
+
}());
|
|
25
|
+
exports.RelativeTimeService = RelativeTimeService;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RequestClientData } from '../models/request-client-data';
|
|
2
|
+
import type { RequestClientOptions } from '../models/request-client-options';
|
|
3
|
+
export declare class RequestClientService {
|
|
4
|
+
static from(headers: Headers, options?: RequestClientOptions): RequestClientData;
|
|
5
|
+
private static _limit;
|
|
6
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequestClientService = void 0;
|
|
4
|
+
var request_client_config_1 = require("./constants/request-client-config");
|
|
5
|
+
var RequestClientService = /** @class */ (function () {
|
|
6
|
+
function RequestClientService() {
|
|
7
|
+
}
|
|
8
|
+
RequestClientService.from = function (headers, options) {
|
|
9
|
+
if (options === void 0) { options = {}; }
|
|
10
|
+
var address = request_client_config_1.RequestClientConfig.addressHeaders
|
|
11
|
+
.map(function (name) { return headers.get(name); })
|
|
12
|
+
.find(function (value) { return value !== null && value.trim() !== ''; });
|
|
13
|
+
var agent = headers.get(request_client_config_1.RequestClientConfig.agentHeader);
|
|
14
|
+
return {
|
|
15
|
+
ipAddress: address === undefined
|
|
16
|
+
? null
|
|
17
|
+
: this._limit(address.split(request_client_config_1.RequestClientConfig.listSeparator)[0].trim(), options.ipAddressMaxLength),
|
|
18
|
+
userAgent: agent === null || agent.trim() === ''
|
|
19
|
+
? null
|
|
20
|
+
: this._limit(agent.trim(), options.userAgentMaxLength),
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
RequestClientService._limit = function (value, maxLength) {
|
|
24
|
+
return typeof maxLength === 'number' ? value.slice(0, maxLength) : value;
|
|
25
|
+
};
|
|
26
|
+
return RequestClientService;
|
|
27
|
+
}());
|
|
28
|
+
exports.RequestClientService = RequestClientService;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,11 @@ import * as CommonNamespace from './common';
|
|
|
3
3
|
export declare const Common: typeof CommonNamespace;
|
|
4
4
|
export declare const Client: typeof ClientNamespace;
|
|
5
5
|
export { AmountDirection } from './common/constants/amount-direction';
|
|
6
|
+
export { HttpMethod } from './common/constants/http-method';
|
|
7
|
+
export type { CodedErrorData } from './models/coded-error-data';
|
|
8
|
+
export type { DeviceData } from './models/device-data';
|
|
6
9
|
export type { EmailPreviewInput } from './models/email-preview-input';
|
|
10
|
+
export type { JsonValueGuard } from './models/json-value-guard';
|
|
7
11
|
export type { SignedTokenHeader } from './models/signed-token-header';
|
|
8
12
|
export type { SignedTokenKeyPair } from './models/signed-token-key-pair';
|
|
9
13
|
export type { SocketTokenClaims } from './models/socket-token-claims';
|
|
@@ -17,3 +21,6 @@ export type { DataKeyPair } from './common/envelope-crypto-service';
|
|
|
17
21
|
export type { PhoneCountryData } from './models/phone-country-data';
|
|
18
22
|
export type { PhoneDisplayData } from './models/phone-display-data';
|
|
19
23
|
export type { PostalCodeFormatData } from './models/postal-code-format-data';
|
|
24
|
+
export type { RelativeTimeOptions } from './models/relative-time-options';
|
|
25
|
+
export type { RequestClientData } from './models/request-client-data';
|
|
26
|
+
export type { RequestClientOptions } from './models/request-client-options';
|
package/dist/index.js
CHANGED
|
@@ -33,10 +33,12 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.AmountDirection = exports.Client = exports.Common = void 0;
|
|
36
|
+
exports.HttpMethod = 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
41
|
var amount_direction_1 = require("./common/constants/amount-direction");
|
|
42
42
|
Object.defineProperty(exports, "AmountDirection", { enumerable: true, get: function () { return amount_direction_1.AmountDirection; } });
|
|
43
|
+
var http_method_1 = require("./common/constants/http-method");
|
|
44
|
+
Object.defineProperty(exports, "HttpMethod", { enumerable: true, get: function () { return http_method_1.HttpMethod; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type JsonValueGuard<Value> = (value: unknown) => value is Value;
|
package/dist/server/index.d.ts
CHANGED
package/dist/server/index.js
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TimingSafeService = void 0;
|
|
4
|
+
var node_crypto_1 = require("node:crypto");
|
|
5
|
+
var TimingSafeService = /** @class */ (function () {
|
|
6
|
+
function TimingSafeService() {
|
|
7
|
+
}
|
|
8
|
+
TimingSafeService.equals = function (candidate, secret) {
|
|
9
|
+
var candidateBytes = Buffer.from(candidate);
|
|
10
|
+
var secretBytes = Buffer.from(secret);
|
|
11
|
+
return (candidateBytes.length === secretBytes.length && (0, node_crypto_1.timingSafeEqual)(candidateBytes, secretBytes));
|
|
12
|
+
};
|
|
13
|
+
return TimingSafeService;
|
|
14
|
+
}());
|
|
15
|
+
exports.TimingSafeService = TimingSafeService;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pallasoft/ps-utilities",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.15.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
"format:prettier": "npx prettier --write \"**/*.{js,ts,json,md}\"",
|
|
40
40
|
"lint:eslint": "npx eslint \"**/*.{js,ts}\"",
|
|
41
41
|
"lint:eslint:fix": "npx eslint --fix \"**/*.{js,ts}\"",
|
|
42
|
-
"release": "semantic-release"
|
|
42
|
+
"release": "semantic-release",
|
|
43
|
+
"test": "vitest run"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
46
|
"@commitlint/cli": "^20.1.0",
|
|
@@ -65,9 +66,10 @@
|
|
|
65
66
|
"lint-staged": "^16.2.7",
|
|
66
67
|
"prettier": "^3.6.2",
|
|
67
68
|
"semantic-release": "^24.2.0",
|
|
69
|
+
"socket.io-client": "^4.8.3",
|
|
68
70
|
"ts-node": "^10.9.2",
|
|
69
71
|
"typescript": "^5.9.3",
|
|
70
|
-
"
|
|
72
|
+
"vitest": "^3.2.7"
|
|
71
73
|
},
|
|
72
74
|
"peerDependencies": {
|
|
73
75
|
"hono": "^4.0.0",
|