@nuvei-connect/nc-websdk 1.0.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.
- package/README.md +62 -0
- package/dist/cdn-index.d.ts +2 -0
- package/dist/cdn-index.d.ts.map +1 -0
- package/dist/cdn-index.js +8 -0
- package/dist/common/enums/index.d.ts +25 -0
- package/dist/common/enums/index.d.ts.map +1 -0
- package/dist/common/enums/index.js +29 -0
- package/dist/config/default-config.d.ts +3 -0
- package/dist/config/default-config.d.ts.map +1 -0
- package/dist/config/default-config.js +25 -0
- package/dist/core/index.d.ts +178 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +629 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/interfaces/index.d.ts +77 -0
- package/dist/interfaces/index.d.ts.map +1 -0
- package/dist/interfaces/index.js +2 -0
- package/dist/interfaces/post-message.interfaces.d.ts +17 -0
- package/dist/interfaces/post-message.interfaces.d.ts.map +1 -0
- package/dist/interfaces/post-message.interfaces.js +2 -0
- package/dist/interfaces/utils.interfaces.d.ts +4 -0
- package/dist/interfaces/utils.interfaces.d.ts.map +1 -0
- package/dist/interfaces/utils.interfaces.js +3 -0
- package/dist/services/default-auth-provider.d.ts +17 -0
- package/dist/services/default-auth-provider.d.ts.map +1 -0
- package/dist/services/default-auth-provider.js +225 -0
- package/dist/utils/common.utils.d.ts +27 -0
- package/dist/utils/common.utils.d.ts.map +1 -0
- package/dist/utils/common.utils.js +102 -0
- package/dist/utils/date.utils.d.ts +2 -0
- package/dist/utils/date.utils.d.ts.map +1 -0
- package/dist/utils/date.utils.js +29 -0
- package/dist/utils/iframe-url.utils.d.ts +6 -0
- package/dist/utils/iframe-url.utils.d.ts.map +1 -0
- package/dist/utils/iframe-url.utils.js +37 -0
- package/dist/utils/object.utils.d.ts +56 -0
- package/dist/utils/object.utils.d.ts.map +1 -0
- package/dist/utils/object.utils.js +214 -0
- package/package.json +44 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.utils.d.ts","sourceRoot":"","sources":["../../src/utils/object.utils.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAyB5D;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,GAAG,CAiD1E;AAED;;;;GAIG;AACH,eAAO,MAAM,oCAAoC,GAC/C,eAAe,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KACpC,MAAM,CAAC,MAAM,EAAE,GAAG,CAKpB,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,GAAG,CA0B1D;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,GAAG,EACR,UAAU,GAAE,MAAW,EACvB,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAC5B,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAsBrB;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,GAAG,GAAG,CAkBnD"}
|
|
@@ -0,0 +1,214 @@
|
|
|
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.buildObjectTreeFromDotNotationObject = void 0;
|
|
15
|
+
exports.isObjectHasAnyValidValue = isObjectHasAnyValidValue;
|
|
16
|
+
exports.updateObjectByPath = updateObjectByPath;
|
|
17
|
+
exports.getValueByPath = getValueByPath;
|
|
18
|
+
exports.flattenToDotNotation = flattenToDotNotation;
|
|
19
|
+
exports.deepMerge = deepMerge;
|
|
20
|
+
var common_utils_1 = require("./common.utils");
|
|
21
|
+
/**
|
|
22
|
+
* Recursively checks if any value in a given value is valid, i.e., it is not null, undefined, or an empty string.
|
|
23
|
+
* This function also checks for primitive values, arrays, and objects.
|
|
24
|
+
*
|
|
25
|
+
* @param value The value to check.
|
|
26
|
+
* @returns True if any value in the given value is valid, false otherwise.
|
|
27
|
+
*/
|
|
28
|
+
function isObjectHasAnyValidValue(value) {
|
|
29
|
+
// Empty cases
|
|
30
|
+
if ((0, common_utils_1.isDataValid)(value) === false) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
if (value === undefined || value === null || value === '')
|
|
34
|
+
return false;
|
|
35
|
+
// Primitive values
|
|
36
|
+
if (typeof value !== 'object') {
|
|
37
|
+
return Boolean(value);
|
|
38
|
+
}
|
|
39
|
+
// Array handling
|
|
40
|
+
if (Array.isArray(value)) {
|
|
41
|
+
if (value.length === 0)
|
|
42
|
+
return false;
|
|
43
|
+
return value.some(function (item) { return isObjectHasAnyValidValue(item); });
|
|
44
|
+
}
|
|
45
|
+
// Object handling
|
|
46
|
+
var keys = Object.keys(value);
|
|
47
|
+
if (keys.length === 0)
|
|
48
|
+
return false;
|
|
49
|
+
return keys.some(function (key) { return isObjectHasAnyValidValue(value[key]); });
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Updates an object at a given path with a new value.
|
|
53
|
+
*
|
|
54
|
+
* @param {Object} obj - The object to update.
|
|
55
|
+
* @param {string} path - The path to the value to update this should a dot separated string e.g. "a.b.c" or "a[0].b.c" or "a[0][1].b.c" etc.
|
|
56
|
+
* @param {*} value - The new value to set at the given path.
|
|
57
|
+
* @returns {Object} A deep clone of the original object with the updated value.
|
|
58
|
+
*/
|
|
59
|
+
function updateObjectByPath(obj, path, value) {
|
|
60
|
+
// Deep clone the object (using structuredClone if available, else fallback)
|
|
61
|
+
var clone = typeof structuredClone === 'function' ? structuredClone(obj) : JSON.parse(JSON.stringify(obj));
|
|
62
|
+
var parts = path.split('.');
|
|
63
|
+
var current = clone;
|
|
64
|
+
for (var i = 0; i < parts.length; i++) {
|
|
65
|
+
var part = parts[i];
|
|
66
|
+
var arrayMatch = part.match(/^([a-zA-Z0-9_$]+)\[(\d+)\]$/);
|
|
67
|
+
if (arrayMatch) {
|
|
68
|
+
var key = arrayMatch[1];
|
|
69
|
+
var index = parseInt(arrayMatch[2], 10);
|
|
70
|
+
if (!current[key])
|
|
71
|
+
current[key] = [];
|
|
72
|
+
if (!current[key][index])
|
|
73
|
+
current[key][index] = {};
|
|
74
|
+
if (i === parts.length - 1) {
|
|
75
|
+
// If value is an object and current[key][index] exists, merge them
|
|
76
|
+
if (typeof value === 'object' &&
|
|
77
|
+
value !== null &&
|
|
78
|
+
!Array.isArray(value) &&
|
|
79
|
+
current[key][index]) {
|
|
80
|
+
current[key][index] = __assign(__assign({}, current[key][index]), value);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
current[key][index] = value;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
current = current[key][index];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
if (i === parts.length - 1) {
|
|
92
|
+
// If value is an object and current[part] exists, merge them
|
|
93
|
+
if (typeof value === 'object' && value !== null && !Array.isArray(value) && current[part]) {
|
|
94
|
+
current[part] = __assign(__assign({}, current[part]), value);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
current[part] = value;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
if (!current[part])
|
|
102
|
+
current[part] = {};
|
|
103
|
+
current = current[part];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return clone;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Builds an object tree from a flat object with dot notation keys.
|
|
111
|
+
* @param {Record<string, string>} currentObject - A flat object with dot notation keys.
|
|
112
|
+
* @returns {Record<string, any>} - An object tree built from the flat object.
|
|
113
|
+
*/
|
|
114
|
+
var buildObjectTreeFromDotNotationObject = function (currentObject) {
|
|
115
|
+
return Object.entries(currentObject).reduce(function (acc, _a) {
|
|
116
|
+
var path = _a[0], value = _a[1];
|
|
117
|
+
return updateObjectByPath(acc, path, value);
|
|
118
|
+
}, {});
|
|
119
|
+
};
|
|
120
|
+
exports.buildObjectTreeFromDotNotationObject = buildObjectTreeFromDotNotationObject;
|
|
121
|
+
/**
|
|
122
|
+
* Given an object and a path, returns the value at that path in the object.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* getValueByPath({ a: { b: 'c' } }, 'a.b') // 'c'
|
|
126
|
+
* getValueByPath({ a: 'b' }, 'a.b') // undefined
|
|
127
|
+
* @param {Object} obj - object to search
|
|
128
|
+
* @param {string} path - path to search in the object
|
|
129
|
+
* @returns {*} value at the given path or undefined
|
|
130
|
+
*/
|
|
131
|
+
function getValueByPath(obj, path) {
|
|
132
|
+
var parts = path.split('.');
|
|
133
|
+
var current = obj;
|
|
134
|
+
for (var i = 0; i < parts.length; i++) {
|
|
135
|
+
if (current == null)
|
|
136
|
+
return undefined;
|
|
137
|
+
var part = parts[i];
|
|
138
|
+
var arrayMatch = part.match(/^([a-zA-Z0-9_$]+)\[(\d+)\]$/);
|
|
139
|
+
if (arrayMatch) {
|
|
140
|
+
var key = arrayMatch[1];
|
|
141
|
+
var index = parseInt(arrayMatch[2], 10);
|
|
142
|
+
if (!Array.isArray(current[key]) || current[key][index] === undefined) {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
current = current[key][index];
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
if (typeof current !== 'object' || !(part in current)) {
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
current = current[part];
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return current;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Flattens an object into a single-level object with dot notation keys.
|
|
158
|
+
* If the object is an array, each element is recursively processed.
|
|
159
|
+
* If the object is an object, each key is recursively processed.
|
|
160
|
+
* Primitive values are added to the output object under their respective dot notation key.
|
|
161
|
+
* @param {any} obj - The object to flatten
|
|
162
|
+
* @param {string} parentPath - The parent path to use when generating the dot notation key
|
|
163
|
+
* @param {Record<string, any>} out - The output object to add flattened values to
|
|
164
|
+
* @returns {Record<string, any>} - The flattened object
|
|
165
|
+
*/
|
|
166
|
+
function flattenToDotNotation(obj, parentPath, out) {
|
|
167
|
+
if (parentPath === void 0) { parentPath = ''; }
|
|
168
|
+
if (out === void 0) { out = {}; }
|
|
169
|
+
if (obj === null || obj === undefined)
|
|
170
|
+
return out;
|
|
171
|
+
if (Array.isArray(obj)) {
|
|
172
|
+
obj.forEach(function (item, index) {
|
|
173
|
+
var path = parentPath ? "".concat(parentPath, "[").concat(index, "]") : "[".concat(index, "]");
|
|
174
|
+
flattenToDotNotation(item, path, out);
|
|
175
|
+
});
|
|
176
|
+
return out;
|
|
177
|
+
}
|
|
178
|
+
if (typeof obj === 'object') {
|
|
179
|
+
for (var key in obj) {
|
|
180
|
+
var path = parentPath ? "".concat(parentPath, ".").concat(key) : key;
|
|
181
|
+
flattenToDotNotation(obj[key], path, out);
|
|
182
|
+
}
|
|
183
|
+
return out;
|
|
184
|
+
}
|
|
185
|
+
// primitive
|
|
186
|
+
out[parentPath] = obj;
|
|
187
|
+
return out;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Deeply merges two objects together.
|
|
191
|
+
* If two objects have the same key and the values are both objects,
|
|
192
|
+
* the objects are merged recursively. If the values are not objects,
|
|
193
|
+
* the value from the second object is used.
|
|
194
|
+
* @param {any} obj1 - The first object to merge
|
|
195
|
+
* @param {any} obj2 - The second object to merge
|
|
196
|
+
* @returns {any} The merged object
|
|
197
|
+
*/
|
|
198
|
+
function deepMerge(obj1, obj2) {
|
|
199
|
+
var result = __assign({}, obj1);
|
|
200
|
+
for (var _i = 0, _a = Object.keys(obj2); _i < _a.length; _i++) {
|
|
201
|
+
var key = _a[_i];
|
|
202
|
+
if (obj1[key] &&
|
|
203
|
+
typeof obj1[key] === 'object' &&
|
|
204
|
+
typeof obj2[key] === 'object' &&
|
|
205
|
+
!Array.isArray(obj1[key]) &&
|
|
206
|
+
!Array.isArray(obj2[key])) {
|
|
207
|
+
result[key] = deepMerge(obj1[key], obj2[key]);
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
result[key] = obj2[key];
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return result;
|
|
214
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nuvei-connect/nc-websdk",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc && tsc-alias",
|
|
9
|
+
"prepare": "npm run build",
|
|
10
|
+
"dev": "ts-node -r tsconfig-paths/register src/index.ts",
|
|
11
|
+
"start": "node -r tsconfig-paths/register dist/index.js",
|
|
12
|
+
"test": "jest",
|
|
13
|
+
"lint": "eslint src --ext .ts",
|
|
14
|
+
"docs": "typedoc --out docs src"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist/**/*"
|
|
18
|
+
],
|
|
19
|
+
"keywords": [
|
|
20
|
+
"sdk",
|
|
21
|
+
"web",
|
|
22
|
+
"client"
|
|
23
|
+
],
|
|
24
|
+
"author": "",
|
|
25
|
+
"license": "ISC",
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"axios": "^1.9.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "^22.15.23",
|
|
31
|
+
"esbuild": "^0.25.5",
|
|
32
|
+
"tsc-alias": "^1.8.16",
|
|
33
|
+
"typescript": "^5.8.3"
|
|
34
|
+
},
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"require": "./dist/index.js",
|
|
38
|
+
"import": "./dist/index.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
}
|
|
44
|
+
}
|