@pallasoft/ps-utilities 1.0.6 → 1.2.1

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.
@@ -0,0 +1,9 @@
1
+ import { AxiosInstance } from 'axios';
2
+ export interface CreateApiClientOptions {
3
+ apiKey?: string;
4
+ apiKeyHeader?: string;
5
+ baseURL?: string;
6
+ }
7
+ export declare class HttpService {
8
+ static createApiClient(options?: CreateApiClientOptions): AxiosInstance;
9
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.HttpService = void 0;
7
+ var axios_1 = __importDefault(require("axios"));
8
+ var HttpService = /** @class */ (function () {
9
+ function HttpService() {
10
+ }
11
+ HttpService.createApiClient = function (options) {
12
+ if (options === void 0) { options = {}; }
13
+ var apiKey = options.apiKey, _a = options.apiKeyHeader, apiKeyHeader = _a === void 0 ? 'X-API-Key' : _a, baseURL = options.baseURL;
14
+ var client = axios_1.default.create(baseURL ? { baseURL: baseURL } : undefined);
15
+ client.interceptors.request.use(function (config) {
16
+ if (apiKey)
17
+ config.headers[apiKeyHeader] = apiKey;
18
+ config.headers['Content-Type'] = 'application/json';
19
+ return config;
20
+ }, function (error) {
21
+ return Promise.reject(error);
22
+ });
23
+ return client;
24
+ };
25
+ return HttpService;
26
+ }());
27
+ exports.HttpService = HttpService;
@@ -0,0 +1 @@
1
+ export * from './http-service';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./http-service"), exports);
@@ -0,0 +1,3 @@
1
+ export declare class ColorService {
2
+ static hexToRgb(hex: string): [number, number, number];
3
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ColorService = void 0;
4
+ var ColorService = /** @class */ (function () {
5
+ function ColorService() {
6
+ }
7
+ ColorService.hexToRgb = function (hex) {
8
+ var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
9
+ return result
10
+ ? [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)]
11
+ : [0, 0, 0];
12
+ };
13
+ return ColorService;
14
+ }());
15
+ exports.ColorService = ColorService;
@@ -0,0 +1,19 @@
1
+ export declare class CryptoService {
2
+ private static _algorithm;
3
+ private static _keyLength;
4
+ private static _iterations;
5
+ private static _ivLength;
6
+ private static _saltLength;
7
+ private static _textEncoder;
8
+ private static _textDecoder;
9
+ private static _payloadVersion;
10
+ private static _payloadAlgorithm;
11
+ private static _aad;
12
+ private static _toBase64;
13
+ private static _fromBase64;
14
+ private static _getAdditionalData;
15
+ private static _parsePayload;
16
+ private static _deriveKey;
17
+ static encryptPayload(payload: Record<string, unknown>, cryptoKey: string): Promise<string>;
18
+ static decryptPayload<T>(encryptedPayload: string, cryptoKey: string): Promise<T>;
19
+ }
@@ -0,0 +1,158 @@
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.CryptoService = void 0;
40
+ var CryptoService = /** @class */ (function () {
41
+ function CryptoService() {
42
+ }
43
+ CryptoService._toBase64 = function (bytes) {
44
+ var binary = '';
45
+ for (var index = 0; index < bytes.length; index += 1) {
46
+ binary += String.fromCharCode(bytes[index]);
47
+ }
48
+ return btoa(binary);
49
+ };
50
+ CryptoService._fromBase64 = function (value) {
51
+ var binary = atob(value);
52
+ var bytes = new Uint8Array(binary.length);
53
+ for (var index = 0; index < binary.length; index += 1) {
54
+ bytes[index] = binary.charCodeAt(index);
55
+ }
56
+ return bytes;
57
+ };
58
+ CryptoService._getAdditionalData = function () {
59
+ return this._textEncoder.encode(this._aad);
60
+ };
61
+ CryptoService._parsePayload = function (encryptedPayload) {
62
+ var payload = JSON.parse(encryptedPayload);
63
+ if (payload.v !== this._payloadVersion ||
64
+ payload.alg !== this._payloadAlgorithm ||
65
+ !payload.iv ||
66
+ !payload.salt ||
67
+ !payload.ciphertext) {
68
+ throw new Error('Encrypted payload is malformed');
69
+ }
70
+ return payload;
71
+ };
72
+ CryptoService._deriveKey = function (cryptoKey, salt) {
73
+ return __awaiter(this, void 0, void 0, function () {
74
+ var baseKey;
75
+ return __generator(this, function (_a) {
76
+ switch (_a.label) {
77
+ case 0: return [4 /*yield*/, crypto.subtle.importKey('raw', this._textEncoder.encode(cryptoKey), 'PBKDF2', false, ['deriveKey'])];
78
+ case 1:
79
+ baseKey = _a.sent();
80
+ return [4 /*yield*/, crypto.subtle.deriveKey({
81
+ name: 'PBKDF2',
82
+ hash: 'SHA-256',
83
+ salt: salt,
84
+ iterations: this._iterations,
85
+ }, baseKey, {
86
+ name: this._algorithm,
87
+ length: this._keyLength,
88
+ }, false, ['encrypt', 'decrypt'])];
89
+ case 2: return [2 /*return*/, _a.sent()];
90
+ }
91
+ });
92
+ });
93
+ };
94
+ CryptoService.encryptPayload = function (payload, cryptoKey) {
95
+ return __awaiter(this, void 0, void 0, function () {
96
+ var iv, salt, key, encryptedBuffer, serializedPayload;
97
+ return __generator(this, function (_a) {
98
+ switch (_a.label) {
99
+ case 0:
100
+ iv = crypto.getRandomValues(new Uint8Array(this._ivLength));
101
+ salt = crypto.getRandomValues(new Uint8Array(this._saltLength));
102
+ return [4 /*yield*/, this._deriveKey(cryptoKey, salt)];
103
+ case 1:
104
+ key = _a.sent();
105
+ return [4 /*yield*/, crypto.subtle.encrypt({
106
+ name: this._algorithm,
107
+ iv: iv,
108
+ additionalData: this._getAdditionalData(),
109
+ }, key, this._textEncoder.encode(JSON.stringify(payload)))];
110
+ case 2:
111
+ encryptedBuffer = _a.sent();
112
+ serializedPayload = {
113
+ v: this._payloadVersion,
114
+ alg: this._payloadAlgorithm,
115
+ iv: this._toBase64(iv),
116
+ salt: this._toBase64(salt),
117
+ ciphertext: this._toBase64(new Uint8Array(encryptedBuffer)),
118
+ };
119
+ return [2 /*return*/, JSON.stringify(serializedPayload)];
120
+ }
121
+ });
122
+ });
123
+ };
124
+ CryptoService.decryptPayload = function (encryptedPayload, cryptoKey) {
125
+ return __awaiter(this, void 0, void 0, function () {
126
+ var payload, key, decryptedBuffer;
127
+ return __generator(this, function (_a) {
128
+ switch (_a.label) {
129
+ case 0:
130
+ payload = this._parsePayload(encryptedPayload);
131
+ return [4 /*yield*/, this._deriveKey(cryptoKey, this._fromBase64(payload.salt))];
132
+ case 1:
133
+ key = _a.sent();
134
+ return [4 /*yield*/, crypto.subtle.decrypt({
135
+ name: this._algorithm,
136
+ iv: this._fromBase64(payload.iv),
137
+ additionalData: this._getAdditionalData(),
138
+ }, key, this._fromBase64(payload.ciphertext))];
139
+ case 2:
140
+ decryptedBuffer = _a.sent();
141
+ return [2 /*return*/, JSON.parse(this._textDecoder.decode(decryptedBuffer))];
142
+ }
143
+ });
144
+ });
145
+ };
146
+ CryptoService._algorithm = 'AES-GCM';
147
+ CryptoService._keyLength = 256;
148
+ CryptoService._iterations = 100000;
149
+ CryptoService._ivLength = 12;
150
+ CryptoService._saltLength = 16;
151
+ CryptoService._textEncoder = new TextEncoder();
152
+ CryptoService._textDecoder = new TextDecoder();
153
+ CryptoService._payloadVersion = 1;
154
+ CryptoService._payloadAlgorithm = 'A256GCM';
155
+ CryptoService._aad = 'encrypted-form:v1:a256gcm';
156
+ return CryptoService;
157
+ }());
158
+ exports.CryptoService = CryptoService;
@@ -1,3 +1,7 @@
1
+ export * from './color-service';
2
+ export * from './crypto-service';
1
3
  export * from './date-service';
4
+ export * from './number-format-service';
5
+ export * from './recaptcha-service';
2
6
  export * from './url-service';
3
7
  export * from './string-service';
@@ -14,6 +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("./color-service"), exports);
18
+ __exportStar(require("./crypto-service"), exports);
17
19
  __exportStar(require("./date-service"), exports);
20
+ __exportStar(require("./number-format-service"), exports);
21
+ __exportStar(require("./recaptcha-service"), exports);
18
22
  __exportStar(require("./url-service"), exports);
19
23
  __exportStar(require("./string-service"), exports);
@@ -0,0 +1,5 @@
1
+ export declare class NumberFormatService {
2
+ static formatCurrency(value: number, currencyCode: string, locale?: string, minimumFractionDigits?: number, maximumFractionDigits?: number): string;
3
+ static formatCompact(value: number, locale?: string): string;
4
+ static formatPercent(value: number, locale?: string): string;
5
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NumberFormatService = void 0;
4
+ var NumberFormatService = /** @class */ (function () {
5
+ function NumberFormatService() {
6
+ }
7
+ NumberFormatService.formatCurrency = function (value, currencyCode, locale, minimumFractionDigits, maximumFractionDigits) {
8
+ if (locale === void 0) { locale = 'en-US'; }
9
+ if (minimumFractionDigits === void 0) { minimumFractionDigits = 0; }
10
+ if (maximumFractionDigits === void 0) { maximumFractionDigits = 2; }
11
+ return new Intl.NumberFormat(locale, {
12
+ currency: currencyCode,
13
+ maximumFractionDigits: maximumFractionDigits,
14
+ minimumFractionDigits: minimumFractionDigits,
15
+ style: 'currency',
16
+ }).format(value);
17
+ };
18
+ NumberFormatService.formatCompact = function (value, locale) {
19
+ if (locale === void 0) { locale = 'en-US'; }
20
+ return new Intl.NumberFormat(locale, {
21
+ compactDisplay: 'short',
22
+ notation: 'compact',
23
+ }).format(value);
24
+ };
25
+ NumberFormatService.formatPercent = function (value, locale) {
26
+ if (locale === void 0) { locale = 'en-US'; }
27
+ return new Intl.NumberFormat(locale, {
28
+ maximumFractionDigits: 1,
29
+ style: 'percent',
30
+ }).format(value);
31
+ };
32
+ return NumberFormatService;
33
+ }());
34
+ exports.NumberFormatService = NumberFormatService;
@@ -0,0 +1,8 @@
1
+ export interface RecaptchaVerifyResult {
2
+ success: boolean;
3
+ errorCodes: string[];
4
+ }
5
+ export declare class RecaptchaService {
6
+ private static _verifyUrl;
7
+ static verify(token: string, secretKey: string, remoteIp?: string): Promise<RecaptchaVerifyResult>;
8
+ }
@@ -0,0 +1,76 @@
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.RecaptchaService = void 0;
40
+ var RecaptchaService = /** @class */ (function () {
41
+ function RecaptchaService() {
42
+ }
43
+ RecaptchaService.verify = function (token, secretKey, remoteIp) {
44
+ return __awaiter(this, void 0, void 0, function () {
45
+ var params, response, data;
46
+ return __generator(this, function (_a) {
47
+ switch (_a.label) {
48
+ case 0:
49
+ params = new URLSearchParams({ secret: secretKey, response: token });
50
+ if (remoteIp)
51
+ params.set('remoteip', remoteIp);
52
+ return [4 /*yield*/, fetch(this._verifyUrl, {
53
+ method: 'POST',
54
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
55
+ body: params.toString(),
56
+ })];
57
+ case 1:
58
+ response = _a.sent();
59
+ if (!response.ok) {
60
+ return [2 /*return*/, { success: false, errorCodes: ['verification-request-failed'] }];
61
+ }
62
+ return [4 /*yield*/, response.json()];
63
+ case 2:
64
+ data = (_a.sent());
65
+ return [2 /*return*/, {
66
+ success: !!data.success,
67
+ errorCodes: data['error-codes'] || [],
68
+ }];
69
+ }
70
+ });
71
+ });
72
+ };
73
+ RecaptchaService._verifyUrl = 'https://www.google.com/recaptcha/api/siteverify';
74
+ return RecaptchaService;
75
+ }());
76
+ exports.RecaptchaService = RecaptchaService;
package/dist/index.d.ts CHANGED
@@ -1 +1,4 @@
1
- export * as Common from './common';
1
+ import * as ClientNamespace from './client';
2
+ import * as CommonNamespace from './common';
3
+ export declare const Common: typeof CommonNamespace;
4
+ export declare const Client: typeof ClientNamespace;
package/dist/index.js CHANGED
@@ -33,5 +33,8 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.Common = void 0;
37
- exports.Common = __importStar(require("./common"));
36
+ exports.Client = exports.Common = void 0;
37
+ var ClientNamespace = __importStar(require("./client"));
38
+ var CommonNamespace = __importStar(require("./common"));
39
+ exports.Common = CommonNamespace;
40
+ exports.Client = ClientNamespace;
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "@pallasoft/ps-utilities",
3
- "version": "1.0.6",
4
- "type": "module",
3
+ "version": "1.2.1",
5
4
  "private": false,
6
5
  "main": "./dist/index.js",
7
6
  "types": "./dist/index.d.ts",
@@ -16,12 +15,15 @@
16
15
  "scripts": {
17
16
  "husky:prepare": "npx husky",
18
17
  "build": "tsc",
18
+ "setup:graphify": "sh scripts/graphify-setup.sh",
19
+ "update:graphify": "sh scripts/graphify-update.sh",
19
20
  "lint": "npm run lint:eslint",
20
21
  "lint:fix": "npm run lint:eslint:fix",
21
22
  "format:check": "npx prettier --check --ignore-unknown \"src/**/*.{js,ts,json,md}\"",
22
23
  "format:prettier": "npx prettier --write \"**/*.{js,ts,json,md}\"",
23
24
  "lint:eslint": "npx eslint \"**/*.{js,ts}\"",
24
- "lint:eslint:fix": "npx eslint --fix \"**/*.{js,ts}\""
25
+ "lint:eslint:fix": "npx eslint --fix \"**/*.{js,ts}\"",
26
+ "release": "semantic-release"
25
27
  },
26
28
  "devDependencies": {
27
29
  "@commitlint/cli": "^20.1.0",
@@ -39,11 +41,24 @@
39
41
  "lint-staged": "^16.2.7",
40
42
  "prettier": "^3.6.2",
41
43
  "ts-node": "^10.9.2",
42
- "typescript": "^5.9.3"
44
+ "typescript": "^5.9.3",
45
+ "@semantic-release/changelog": "^6.0.3",
46
+ "@semantic-release/commit-analyzer": "^13.0.0",
47
+ "@semantic-release/git": "^10.0.1",
48
+ "@semantic-release/github": "^11.0.1",
49
+ "@semantic-release/npm": "^12.0.0",
50
+ "@semantic-release/release-notes-generator": "^14.0.1",
51
+ "conventional-changelog-conventionalcommits": "^7.0.2",
52
+ "semantic-release": "^24.2.0"
43
53
  },
44
54
  "dependencies": {
45
55
  "@esbuild-plugins/tsconfig-paths": "^0.1.2",
56
+ "axios": "^1.16.0",
46
57
  "dayjs": "^1.11.19",
47
58
  "esbuild": "^0.27.0"
59
+ },
60
+ "publishConfig": {
61
+ "access": "public",
62
+ "registry": "https://registry.npmjs.org/"
48
63
  }
49
64
  }