@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.
Files changed (41) hide show
  1. package/README.md +62 -0
  2. package/dist/cdn-index.d.ts +2 -0
  3. package/dist/cdn-index.d.ts.map +1 -0
  4. package/dist/cdn-index.js +8 -0
  5. package/dist/common/enums/index.d.ts +25 -0
  6. package/dist/common/enums/index.d.ts.map +1 -0
  7. package/dist/common/enums/index.js +29 -0
  8. package/dist/config/default-config.d.ts +3 -0
  9. package/dist/config/default-config.d.ts.map +1 -0
  10. package/dist/config/default-config.js +25 -0
  11. package/dist/core/index.d.ts +178 -0
  12. package/dist/core/index.d.ts.map +1 -0
  13. package/dist/core/index.js +629 -0
  14. package/dist/index.d.ts +6 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +10 -0
  17. package/dist/interfaces/index.d.ts +77 -0
  18. package/dist/interfaces/index.d.ts.map +1 -0
  19. package/dist/interfaces/index.js +2 -0
  20. package/dist/interfaces/post-message.interfaces.d.ts +17 -0
  21. package/dist/interfaces/post-message.interfaces.d.ts.map +1 -0
  22. package/dist/interfaces/post-message.interfaces.js +2 -0
  23. package/dist/interfaces/utils.interfaces.d.ts +4 -0
  24. package/dist/interfaces/utils.interfaces.d.ts.map +1 -0
  25. package/dist/interfaces/utils.interfaces.js +3 -0
  26. package/dist/services/default-auth-provider.d.ts +17 -0
  27. package/dist/services/default-auth-provider.d.ts.map +1 -0
  28. package/dist/services/default-auth-provider.js +225 -0
  29. package/dist/utils/common.utils.d.ts +27 -0
  30. package/dist/utils/common.utils.d.ts.map +1 -0
  31. package/dist/utils/common.utils.js +102 -0
  32. package/dist/utils/date.utils.d.ts +2 -0
  33. package/dist/utils/date.utils.d.ts.map +1 -0
  34. package/dist/utils/date.utils.js +29 -0
  35. package/dist/utils/iframe-url.utils.d.ts +6 -0
  36. package/dist/utils/iframe-url.utils.d.ts.map +1 -0
  37. package/dist/utils/iframe-url.utils.js +37 -0
  38. package/dist/utils/object.utils.d.ts +56 -0
  39. package/dist/utils/object.utils.d.ts.map +1 -0
  40. package/dist/utils/object.utils.js +214 -0
  41. package/package.json +44 -0
@@ -0,0 +1,77 @@
1
+ import { EnvironmentEnum, ModulesNameEnum } from "../common/enums";
2
+ export interface INuveiInitParams {
3
+ fetchClientSession?: () => Promise<IClientSession>;
4
+ refreshClientSession?: (payload: IRefreshClientSessionParams) => Promise<IClientRefreshSession>;
5
+ destroySession?: () => Promise<boolean>;
6
+ componentName?: ModulesNameEnum;
7
+ container?: HTMLElement | string;
8
+ authConfig?: IAuthConfig;
9
+ config?: Partial<INuveiSdkConfig>;
10
+ onReady?: (instance: INuveiInstance) => void | Promise<void>;
11
+ onError?: (error: unknown) => void;
12
+ onMessage?: (message: any) => void;
13
+ }
14
+ export interface IBaseClientSession {
15
+ accessToken: string;
16
+ accessTokenExpiry: string;
17
+ refreshToken: string;
18
+ refreshTokenExpiry: string;
19
+ }
20
+ export interface IClientSession extends IBaseClientSession {
21
+ isSuccess: boolean;
22
+ }
23
+ export interface IRefreshClientSessionParams {
24
+ refreshToken: string;
25
+ accessToken: string;
26
+ }
27
+ export interface IClientRefreshSession {
28
+ isSuccess: boolean;
29
+ accessToken: string;
30
+ accessTokenExpiry: string;
31
+ description?: string;
32
+ }
33
+ export interface IAuthProvider {
34
+ fetchClientSession: () => Promise<IClientSession>;
35
+ refreshClientSession: (payload: IRefreshClientSessionParams) => Promise<IClientRefreshSession>;
36
+ destroySession: () => Promise<boolean>;
37
+ }
38
+ export interface IAuthConfig {
39
+ authApiUrl: string;
40
+ authToken?: string;
41
+ referenceId?: string;
42
+ }
43
+ export interface INuveiSdkConfig {
44
+ iframeId: string;
45
+ containerId: string;
46
+ iframeStyle: Record<string, string>;
47
+ sessionValidation: (token: string, tokenExpiry?: string) => boolean;
48
+ sessionCheckInterval: number;
49
+ environment: EnvironmentEnum;
50
+ iframeBaseUrl?: string;
51
+ }
52
+ export interface HTMLIFrameElement extends HTMLElement {
53
+ allow: string;
54
+ allowFullscreen: boolean;
55
+ contentDocument: Document | null;
56
+ contentWindow: Window | null;
57
+ height: string;
58
+ name: string;
59
+ referrerPolicy: string;
60
+ sandbox: DOMTokenList;
61
+ src: string;
62
+ srcdoc: string;
63
+ width: string;
64
+ getSVGDocument(): Document | null;
65
+ }
66
+ export interface sendMessagePayload {
67
+ type: string;
68
+ message: string;
69
+ }
70
+ export interface INuveiInstance {
71
+ initialize: () => Promise<HTMLIFrameElement | void>;
72
+ loadComponent: (componentName: ModulesNameEnum) => Promise<HTMLIFrameElement | void>;
73
+ destroy: () => void;
74
+ destroyIframe: () => void;
75
+ logout: () => void;
76
+ }
77
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,17 @@
1
+ import { AcknowledgeMessageActionType, ModulesNameType, PostMessageActionType } from "../common/enums";
2
+ export interface ICommonISdkData {
3
+ frontendAccessToken: string;
4
+ componentName: ModulesNameType;
5
+ other?: any;
6
+ }
7
+ export interface ISdkPostMessagePayload {
8
+ action: PostMessageActionType;
9
+ source: 'NUVEI_WEB_SDK';
10
+ data: any;
11
+ }
12
+ export interface ISdkAcknowledgeMessage {
13
+ action: AcknowledgeMessageActionType;
14
+ source: 'NUVEI_IFRAME';
15
+ data: any;
16
+ }
17
+ //# sourceMappingURL=post-message.interfaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"post-message.interfaces.d.ts","sourceRoot":"","sources":["../../src/interfaces/post-message.interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAErG,MAAM,WAAW,eAAe;IAC5B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,aAAa,EAAE,eAAe,CAAC;IAC/B,KAAK,CAAC,EAAE,GAAG,CAAC;CACf;AAED,MAAM,WAAW,sBAAsB;IACnC,MAAM,EAAE,qBAAqB,CAAC;IAC9B,MAAM,EAAE,eAAe,CAAC;IACxB,IAAI,EAAE,GAAG,CAAC;CACb;AAED,MAAM,WAAW,sBAAsB;IACnC,MAAM,EAAE,4BAA4B,CAAC;IACrC,MAAM,EAAE,cAAc,CAAC;IACvB,IAAI,EAAE,GAAG,CAAC;CACb"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export interface IQueryBuilderParams {
2
+ [key: string]: any;
3
+ }
4
+ //# sourceMappingURL=utils.interfaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.interfaces.d.ts","sourceRoot":"","sources":["../../src/interfaces/utils.interfaces.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,mBAAmB;IAAG,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CAAE"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ ;
@@ -0,0 +1,17 @@
1
+ import { ModulesNameEnum } from '../common/enums';
2
+ import { IAuthConfig, IAuthProvider, IClientRefreshSession, IClientSession, IRefreshClientSessionParams } from '../interfaces/index';
3
+ export default class DefaultAuthProvider implements IAuthProvider {
4
+ private readonly authConfig;
5
+ private readonly moduleName?;
6
+ private currentAccessToken;
7
+ constructor(authConfig: IAuthConfig, componentName?: ModulesNameEnum);
8
+ fetchClientSession: () => Promise<IClientSession>;
9
+ refreshClientSession: (payload: IRefreshClientSessionParams) => Promise<IClientRefreshSession>;
10
+ destroySession: () => Promise<boolean>;
11
+ private getAuthModuleName;
12
+ private getHeaders;
13
+ private getAuthUrl;
14
+ private parseJsonResponse;
15
+ private createAuthError;
16
+ }
17
+ //# sourceMappingURL=default-auth-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-auth-provider.d.ts","sourceRoot":"","sources":["../../src/services/default-auth-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EACL,WAAW,EACX,aAAa,EACb,qBAAqB,EACrB,cAAc,EACd,2BAA2B,EAC5B,MAAM,mBAAmB,CAAC;AAiB3B,MAAM,CAAC,OAAO,OAAO,mBAAoB,YAAW,aAAa;IAC/D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAc;IACzC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAkB;IAC9C,OAAO,CAAC,kBAAkB,CAAM;gBAEpB,UAAU,EAAE,WAAW,EAAE,aAAa,CAAC,EAAE,eAAe;IAK7D,kBAAkB,QAAa,OAAO,CAAC,cAAc,CAAC,CA8B3D;IAEK,oBAAoB,GACzB,SAAS,2BAA2B,KACnC,OAAO,CAAC,qBAAqB,CAAC,CA0B/B;IAEK,cAAc,QAAa,OAAO,CAAC,OAAO,CAAC,CA2BhD;IAEF,OAAO,CAAC,iBAAiB,CAQvB;IAEF,OAAO,CAAC,UAAU,CAKhB;IAEF,OAAO,CAAC,UAAU,CAQhB;IAEF,OAAO,CAAC,iBAAiB,CA2BvB;IAEF,OAAO,CAAC,eAAe,CAWrB;CACH"}
@@ -0,0 +1,225 @@
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ 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);
24
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ 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;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ var enums_1 = require("../common/enums");
51
+ var common_utils_1 = require("../utils/common.utils");
52
+ var SESSION_FAILED_RESPONSE = {
53
+ isSuccess: false,
54
+ accessToken: '',
55
+ accessTokenExpiry: '',
56
+ refreshToken: '',
57
+ refreshTokenExpiry: '',
58
+ };
59
+ var REFRESH_FAILED_RESPONSE = {
60
+ isSuccess: false,
61
+ accessToken: '',
62
+ accessTokenExpiry: '',
63
+ };
64
+ var DefaultAuthProvider = /** @class */ (function () {
65
+ function DefaultAuthProvider(authConfig, componentName) {
66
+ var _this = this;
67
+ this.currentAccessToken = '';
68
+ this.fetchClientSession = function () { return __awaiter(_this, void 0, void 0, function () {
69
+ var url, payload, response, session, error_1;
70
+ return __generator(this, function (_a) {
71
+ switch (_a.label) {
72
+ case 0:
73
+ url = this.getAuthUrl('/auth/micro-frontend/tokens');
74
+ payload = (0, common_utils_1.buildValidObject)({
75
+ modules: [{ name: this.getAuthModuleName() }],
76
+ referenceId: this.authConfig.referenceId,
77
+ });
78
+ _a.label = 1;
79
+ case 1:
80
+ _a.trys.push([1, 4, , 5]);
81
+ return [4 /*yield*/, fetch(url, {
82
+ method: 'POST',
83
+ headers: this.getHeaders(),
84
+ body: JSON.stringify(payload),
85
+ })];
86
+ case 2:
87
+ response = _a.sent();
88
+ return [4 /*yield*/, this.parseJsonResponse(response, url, 'Frontend AccessToken')];
89
+ case 3:
90
+ session = _a.sent();
91
+ this.currentAccessToken = session.accessToken || '';
92
+ return [2 /*return*/, __assign(__assign(__assign({}, SESSION_FAILED_RESPONSE), session), { isSuccess: true })];
93
+ case 4:
94
+ error_1 = _a.sent();
95
+ throw this.createAuthError('Frontend AccessToken', url, error_1);
96
+ case 5: return [2 /*return*/];
97
+ }
98
+ });
99
+ }); };
100
+ this.refreshClientSession = function (payload) { return __awaiter(_this, void 0, void 0, function () {
101
+ var url, response, session, error_2;
102
+ return __generator(this, function (_a) {
103
+ switch (_a.label) {
104
+ case 0:
105
+ url = this.getAuthUrl('/auth/micro-frontend/tokens/refresh');
106
+ _a.label = 1;
107
+ case 1:
108
+ _a.trys.push([1, 4, , 5]);
109
+ return [4 /*yield*/, fetch(url, {
110
+ method: 'POST',
111
+ headers: this.getHeaders(),
112
+ body: JSON.stringify((0, common_utils_1.buildValidObject)(payload)),
113
+ })];
114
+ case 2:
115
+ response = _a.sent();
116
+ return [4 /*yield*/, this.parseJsonResponse(response, url, 'Frontend AccessToken Refresh')];
117
+ case 3:
118
+ session = _a.sent();
119
+ this.currentAccessToken = session.accessToken || this.currentAccessToken;
120
+ return [2 /*return*/, __assign(__assign(__assign({}, REFRESH_FAILED_RESPONSE), session), { isSuccess: true })];
121
+ case 4:
122
+ error_2 = _a.sent();
123
+ throw this.createAuthError('Frontend AccessToken Refresh', url, error_2);
124
+ case 5: return [2 /*return*/];
125
+ }
126
+ });
127
+ }); };
128
+ this.destroySession = function () { return __awaiter(_this, void 0, void 0, function () {
129
+ var url, response, responseText, error_3;
130
+ return __generator(this, function (_a) {
131
+ switch (_a.label) {
132
+ case 0:
133
+ if (!this.currentAccessToken) {
134
+ return [2 /*return*/, true];
135
+ }
136
+ url = this.getAuthUrl('/auth/access-token/revoke');
137
+ _a.label = 1;
138
+ case 1:
139
+ _a.trys.push([1, 5, , 6]);
140
+ return [4 /*yield*/, fetch(url, {
141
+ method: 'POST',
142
+ headers: this.getHeaders(),
143
+ body: JSON.stringify({ accessToken: this.currentAccessToken }),
144
+ })];
145
+ case 2:
146
+ response = _a.sent();
147
+ if (!!response.ok) return [3 /*break*/, 4];
148
+ return [4 /*yield*/, response.text()];
149
+ case 3:
150
+ responseText = _a.sent();
151
+ throw new Error("Session revoke failed(Web SDK): ".concat(response.status, " ").concat(response.statusText, ". URL: ").concat(url, ". Response: ").concat(responseText.slice(0, 200)));
152
+ case 4:
153
+ this.currentAccessToken = '';
154
+ return [2 /*return*/, true];
155
+ case 5:
156
+ error_3 = _a.sent();
157
+ console.error(this.createAuthError('Session revoke', url, error_3).message);
158
+ return [2 /*return*/, false];
159
+ case 6: return [2 /*return*/];
160
+ }
161
+ });
162
+ }); };
163
+ this.getAuthModuleName = function () {
164
+ switch (_this.moduleName) {
165
+ case enums_1.ModulesNameEnum.ONBOARDING_PARTNER:
166
+ case enums_1.ModulesNameEnum.ONBOARDING_MERCHANT:
167
+ return 'ONBOARDING';
168
+ default:
169
+ return _this.moduleName || '';
170
+ }
171
+ };
172
+ this.getHeaders = function () {
173
+ return {
174
+ Authorization: _this.authConfig.authToken || '',
175
+ 'Content-Type': 'application/json',
176
+ };
177
+ };
178
+ this.getAuthUrl = function (path) {
179
+ var _a;
180
+ var authApiUrl = (_a = _this.authConfig.authApiUrl) === null || _a === void 0 ? void 0 : _a.trim();
181
+ if (!authApiUrl) {
182
+ throw new Error('authConfig.authApiUrl is required(Web SDK)');
183
+ }
184
+ return "".concat(authApiUrl.replace(/\/$/, '')).concat(path);
185
+ };
186
+ this.parseJsonResponse = function (response, url, label) { return __awaiter(_this, void 0, void 0, function () {
187
+ var responseText, contentType;
188
+ return __generator(this, function (_a) {
189
+ switch (_a.label) {
190
+ case 0: return [4 /*yield*/, response.text()];
191
+ case 1:
192
+ responseText = _a.sent();
193
+ if (!response.ok) {
194
+ throw new Error("".concat(label, " Error Response(Web SDK): ").concat(response.status, " ").concat(response.statusText, ". URL: ").concat(url, ". Response: ").concat(responseText.slice(0, 200)));
195
+ }
196
+ contentType = response.headers.get('content-type') || '';
197
+ if (!contentType.includes('application/json')) {
198
+ throw new Error("".concat(label, " expected JSON response(Web SDK). URL: ").concat(url, ". Content-Type: ").concat(contentType || 'unknown', ". Response: ").concat(responseText.slice(0, 200)));
199
+ }
200
+ try {
201
+ return [2 /*return*/, JSON.parse(responseText)];
202
+ }
203
+ catch (error) {
204
+ throw new Error("".concat(label, " JSON parse failed(Web SDK). URL: ").concat(url, ". Response: ").concat(responseText.slice(0, 200)));
205
+ }
206
+ return [2 /*return*/];
207
+ }
208
+ });
209
+ }); };
210
+ this.createAuthError = function (label, url, error) {
211
+ if (error instanceof Error && error.message.includes('(Web SDK)')) {
212
+ return error;
213
+ }
214
+ var message = error instanceof Error ? error.message : String(error);
215
+ var browserHint = message.includes('Failed to fetch')
216
+ ? ' This usually means the browser blocked the request because of CORS, the URL is unreachable, or the request was blocked before a response was returned.'
217
+ : '';
218
+ return new Error("".concat(label, " Request Failed(Web SDK). URL: ").concat(url, ".").concat(browserHint));
219
+ };
220
+ this.authConfig = authConfig;
221
+ this.moduleName = componentName;
222
+ }
223
+ return DefaultAuthProvider;
224
+ }());
225
+ exports.default = DefaultAuthProvider;
@@ -0,0 +1,27 @@
1
+ import { IQueryBuilderParams } from "../interfaces/utils.interfaces";
2
+ /**
3
+ * Constructs a query string from an object of query parameters.
4
+ * Each key-value pair in the object is transformed into a query parameter
5
+ * in the format "key=value". Parameters with null, undefined, or empty values
6
+ * are omitted. The parameters are joined with "&", and the query string starts
7
+ * with "?" if there are any valid parameters.
8
+ *
9
+ * @param queryObj - An optional object containing base query parameters.
10
+ * @returns The constructed query string, or an empty string if no valid parameters exist.
11
+ */
12
+ export declare const buildQuery: (queryObj?: IQueryBuilderParams) => string;
13
+ /**
14
+ * Checks if a given data is valid, i.e., it is not null, undefined, or an empty string.
15
+ * @param {any} data The data to check.
16
+ * @returns {boolean} True if the data is valid, false otherwise.
17
+ */
18
+ export declare const isDataValid: (data: any) => boolean;
19
+ /**
20
+ * This Function help to build valid object from object by eliminating null, undefined, black value of key from object.
21
+ * @param obj Optional Object type.
22
+ * @returns Valid Object or undefined
23
+ */
24
+ export declare const buildValidObject: (obj?: {
25
+ [key: string]: any;
26
+ }) => any;
27
+ //# sourceMappingURL=common.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.utils.d.ts","sourceRoot":"","sources":["../../src/utils/common.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAGnE;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,GAAI,WAAW,mBAAmB,WAuBxD,CAAC;AAGF;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,GAAG,KAAG,OAMvC,CAAC;AAGF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,QA+C5D,CAAA"}
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildValidObject = exports.isDataValid = exports.buildQuery = void 0;
4
+ /**
5
+ * Constructs a query string from an object of query parameters.
6
+ * Each key-value pair in the object is transformed into a query parameter
7
+ * in the format "key=value". Parameters with null, undefined, or empty values
8
+ * are omitted. The parameters are joined with "&", and the query string starts
9
+ * with "?" if there are any valid parameters.
10
+ *
11
+ * @param queryObj - An optional object containing base query parameters.
12
+ * @returns The constructed query string, or an empty string if no valid parameters exist.
13
+ */
14
+ var buildQuery = function (queryObj) {
15
+ if (queryObj && typeof queryObj === 'object') {
16
+ var keys_1 = Object.keys(queryObj);
17
+ var totalLength_1 = keys_1.length;
18
+ var query_1 = keys_1.length ? '?' : '';
19
+ keys_1.forEach(function (key, ind) {
20
+ var nextInd = ind + 1;
21
+ var presentObjVal = queryObj[key];
22
+ var nextObjVal = queryObj[keys_1[nextInd]];
23
+ if (nextInd < totalLength_1 && (0, exports.isDataValid)(presentObjVal)) {
24
+ var q = query_1 + key + '=' + presentObjVal;
25
+ if ((0, exports.isDataValid)(nextObjVal))
26
+ query_1 = q + '&';
27
+ else
28
+ query_1 = q;
29
+ }
30
+ else if ((0, exports.isDataValid)(presentObjVal)) {
31
+ query_1 = query_1 + key + '=' + presentObjVal;
32
+ }
33
+ });
34
+ return query_1;
35
+ }
36
+ return '';
37
+ };
38
+ exports.buildQuery = buildQuery;
39
+ /**
40
+ * Checks if a given data is valid, i.e., it is not null, undefined, or an empty string.
41
+ * @param {any} data The data to check.
42
+ * @returns {boolean} True if the data is valid, false otherwise.
43
+ */
44
+ var isDataValid = function (data) {
45
+ if (data === undefined || data === null || data === '')
46
+ return false;
47
+ if (typeof data === 'number' && Number.isNaN(data))
48
+ return false;
49
+ if (typeof data === 'string' && data.trim() === '')
50
+ return false;
51
+ if (typeof data === 'boolean')
52
+ return true;
53
+ return true;
54
+ };
55
+ exports.isDataValid = isDataValid;
56
+ /**
57
+ * This Function help to build valid object from object by eliminating null, undefined, black value of key from object.
58
+ * @param obj Optional Object type.
59
+ * @returns Valid Object or undefined
60
+ */
61
+ var buildValidObject = function (obj) {
62
+ var isValid = function (data) {
63
+ return (data !== undefined &&
64
+ data !== null &&
65
+ !(Array.isArray(data) && data.length === 0) &&
66
+ !(typeof data === 'object' && Object.keys(data).length === 0) &&
67
+ !(typeof data === 'string' && data.trim() === ''));
68
+ };
69
+ if (!obj || typeof obj !== 'object') {
70
+ return undefined; // Return undefined if input is empty or not an object
71
+ }
72
+ var newObject = {};
73
+ for (var key in obj) {
74
+ if (obj.hasOwnProperty(key)) {
75
+ var value = obj[key];
76
+ if (isValid(value)) {
77
+ if (Array.isArray(value)) {
78
+ // Process each element in the array
79
+ var validElements = value
80
+ .filter(function (elem) { return isValid(elem); })
81
+ .map(exports.buildValidObject)
82
+ .filter(function (elem) { return isValid(elem); });
83
+ if (validElements.length) {
84
+ newObject[key] = validElements;
85
+ }
86
+ }
87
+ else if (typeof value === 'object') {
88
+ // Recursively process nested objects
89
+ var nestedValid = (0, exports.buildValidObject)(value);
90
+ if (isValid(nestedValid)) {
91
+ newObject[key] = nestedValid;
92
+ }
93
+ }
94
+ else {
95
+ newObject[key] = value;
96
+ }
97
+ }
98
+ }
99
+ }
100
+ return Object.keys(newObject).length ? newObject : undefined;
101
+ };
102
+ exports.buildValidObject = buildValidObject;
@@ -0,0 +1,2 @@
1
+ export declare const isDateExpired: (tokenExpiry: string | Date | number | null | undefined) => boolean;
2
+ //# sourceMappingURL=date.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date.utils.d.ts","sourceRoot":"","sources":["../../src/utils/date.utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,GAAI,aAAa,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,KAAG,OAwBtF,CAAC"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isDateExpired = void 0;
4
+ var isDateExpired = function (tokenExpiry) {
5
+ if (!tokenExpiry)
6
+ return true;
7
+ var expiryDate;
8
+ // Normalize input
9
+ if (tokenExpiry instanceof Date) {
10
+ expiryDate = tokenExpiry;
11
+ }
12
+ else if (typeof tokenExpiry === 'number') {
13
+ expiryDate = new Date(tokenExpiry); // timestamp
14
+ }
15
+ else if (typeof tokenExpiry === 'string') {
16
+ var normalized = tokenExpiry
17
+ .trim()
18
+ .replace(' ', 'T'); // handle "2026-12-01 10:00:00"
19
+ expiryDate = new Date(normalized);
20
+ }
21
+ else {
22
+ return true;
23
+ }
24
+ // Invalid date check
25
+ if (isNaN(expiryDate.getTime()))
26
+ return true;
27
+ return Date.now() > expiryDate.getTime();
28
+ };
29
+ exports.isDateExpired = isDateExpired;
@@ -0,0 +1,6 @@
1
+ import { ModulesNameEnum } from '../common/enums';
2
+ import { INuveiSdkConfig } from '../interfaces/index';
3
+ export declare const getEnvironmentBaseUrl: (environment?: string) => string;
4
+ export declare const getModulePath: (componentName: ModulesNameEnum) => string;
5
+ export declare const resolveIframeUrl: (componentName: ModulesNameEnum, config: INuveiSdkConfig) => string;
6
+ //# sourceMappingURL=iframe-url.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iframe-url.utils.d.ts","sourceRoot":"","sources":["../../src/utils/iframe-url.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAgBpD,eAAO,MAAM,qBAAqB,GAAI,cAAa,MAAe,KAAG,MAEpE,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,eAAe,eAAe,KAAG,MAE9D,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAC3B,eAAe,eAAe,EAC9B,QAAQ,eAAe,KACtB,MASF,CAAC"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.resolveIframeUrl = exports.getModulePath = exports.getEnvironmentBaseUrl = void 0;
5
+ var enums_1 = require("../common/enums");
6
+ var common_utils_1 = require("./common.utils");
7
+ var ENVIRONMENT_BASE_URLS = {
8
+ local: 'http://localhost:4000',
9
+ dev: 'https://ignite-dev.nuvei.com',
10
+ preprod: 'https://ignite-preprod.nuvei.com',
11
+ prod: 'https://ignite.nuvei.com',
12
+ };
13
+ var MODULE_PATHS = (_a = {},
14
+ _a[enums_1.ModulesNameEnum.ONBOARDING_PARTNER] = '/_onboarding/partner/application',
15
+ _a[enums_1.ModulesNameEnum.ONBOARDING_MERCHANT] = '/_onboarding/merchant/application',
16
+ _a[enums_1.ModulesNameEnum.DOCUTILITY] = '',
17
+ _a);
18
+ var getEnvironmentBaseUrl = function (environment) {
19
+ if (environment === void 0) { environment = 'prod'; }
20
+ return ENVIRONMENT_BASE_URLS[environment] || ENVIRONMENT_BASE_URLS.prod;
21
+ };
22
+ exports.getEnvironmentBaseUrl = getEnvironmentBaseUrl;
23
+ var getModulePath = function (componentName) {
24
+ var _a;
25
+ return (_a = MODULE_PATHS[componentName]) !== null && _a !== void 0 ? _a : '';
26
+ };
27
+ exports.getModulePath = getModulePath;
28
+ var resolveIframeUrl = function (componentName, config) {
29
+ var baseUrl = config.iframeBaseUrl || (0, exports.getEnvironmentBaseUrl)(config.environment);
30
+ var path = (0, exports.getModulePath)(componentName);
31
+ var queryParams = (0, common_utils_1.buildQuery)({
32
+ // requestId: config.requestId,
33
+ // frontendAccessToken: accessToken,
34
+ });
35
+ return "".concat(baseUrl).concat(path).concat(queryParams);
36
+ };
37
+ exports.resolveIframeUrl = resolveIframeUrl;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Recursively checks if any value in a given value is valid, i.e., it is not null, undefined, or an empty string.
3
+ * This function also checks for primitive values, arrays, and objects.
4
+ *
5
+ * @param value The value to check.
6
+ * @returns True if any value in the given value is valid, false otherwise.
7
+ */
8
+ export declare function isObjectHasAnyValidValue(value: any): boolean;
9
+ /**
10
+ * Updates an object at a given path with a new value.
11
+ *
12
+ * @param {Object} obj - The object to update.
13
+ * @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.
14
+ * @param {*} value - The new value to set at the given path.
15
+ * @returns {Object} A deep clone of the original object with the updated value.
16
+ */
17
+ export declare function updateObjectByPath(obj: any, path: string, value: any): any;
18
+ /**
19
+ * Builds an object tree from a flat object with dot notation keys.
20
+ * @param {Record<string, string>} currentObject - A flat object with dot notation keys.
21
+ * @returns {Record<string, any>} - An object tree built from the flat object.
22
+ */
23
+ export declare const buildObjectTreeFromDotNotationObject: (currentObject: Record<string, string>) => Record<string, any>;
24
+ /**
25
+ * Given an object and a path, returns the value at that path in the object.
26
+ *
27
+ * @example
28
+ * getValueByPath({ a: { b: 'c' } }, 'a.b') // 'c'
29
+ * getValueByPath({ a: 'b' }, 'a.b') // undefined
30
+ * @param {Object} obj - object to search
31
+ * @param {string} path - path to search in the object
32
+ * @returns {*} value at the given path or undefined
33
+ */
34
+ export declare function getValueByPath(obj: any, path: string): any;
35
+ /**
36
+ * Flattens an object into a single-level object with dot notation keys.
37
+ * If the object is an array, each element is recursively processed.
38
+ * If the object is an object, each key is recursively processed.
39
+ * Primitive values are added to the output object under their respective dot notation key.
40
+ * @param {any} obj - The object to flatten
41
+ * @param {string} parentPath - The parent path to use when generating the dot notation key
42
+ * @param {Record<string, any>} out - The output object to add flattened values to
43
+ * @returns {Record<string, any>} - The flattened object
44
+ */
45
+ export declare function flattenToDotNotation(obj: any, parentPath?: string, out?: Record<string, any>): Record<string, any>;
46
+ /**
47
+ * Deeply merges two objects together.
48
+ * If two objects have the same key and the values are both objects,
49
+ * the objects are merged recursively. If the values are not objects,
50
+ * the value from the second object is used.
51
+ * @param {any} obj1 - The first object to merge
52
+ * @param {any} obj2 - The second object to merge
53
+ * @returns {any} The merged object
54
+ */
55
+ export declare function deepMerge(obj1: any, obj2: any): any;
56
+ //# sourceMappingURL=object.utils.d.ts.map