@partium/js-sdk 14.0.3 → 14.1.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/catalog/index.js +21 -1
- package/catalog/models/catalog-image-info.js +22 -1
- package/catalog/models/catalog-image.js +40 -1
- package/catalog/models/upsert-catalog-images-dto.js +3 -1
- package/catalog/models/upsert-images-result.js +3 -1
- package/catalog/services/images.service.js +62 -1
- package/core/constants/constants.js +16 -1
- package/core/decorators/injection-identifier.js +19 -1
- package/core/factories/paginated-request-service.factory.js +33 -1
- package/core/index.js +63 -1
- package/core/integration-defaults/http/fetch-api-http-error-helper.js +129 -1
- package/core/integration-defaults/http/file-transfer/axios-file-transfer.service.js +138 -1
- package/core/integration-defaults/http/file-transfer/fetch-api-file-transfer.service.js +210 -1
- package/core/integration-defaults/http/handle-axios-error-helper.js +79 -1
- package/core/integration-defaults/http/https-client/axios-https-client.service.js +182 -1
- package/core/integration-defaults/http/https-client/fetch-api-https-client.service.js +198 -1
- package/core/integration-defaults/http/js-oauth-keycloak-https.service.js +32 -1
- package/core/integration-defaults/js-p-file.js +36 -1
- package/core/integration-defaults/session/js-oauth-api-key-session.service.js +206 -1
- package/core/integration-defaults/session/js-oauth-keycloak-auth-config.js +64 -1
- package/core/integration-defaults/session/js-oauth-keycloak-session.service.js +257 -1
- package/core/integration-defaults/web-device-status.service.js +125 -1
- package/core/integration-defaults/web-file.service.js +135 -1
- package/core/integration-defaults/web-indexeddb.service.js +142 -1
- package/core/integration-defaults/web-local-storage.service.js +310 -1
- package/core/models/api-object.js +16 -1
- package/core/models/auth-config.js +72 -1
- package/core/models/device-info.js +34 -1
- package/core/models/error.js +107 -1
- package/core/models/formatted-string.js +14 -1
- package/core/models/i18n-map.js +61 -1
- package/core/models/i18n-string.js +35 -1
- package/core/models/log.js +137 -1
- package/core/models/organization.js +159 -1
- package/core/models/p-file.js +23 -1
- package/core/models/paginated-list.js +41 -1
- package/core/models/partium-config.js +43 -1
- package/core/models/user-token.js +11 -1
- package/core/models/user.js +88 -1
- package/core/services/backend-status.service.js +147 -1
- package/core/services/base-login-init.service.js +57 -1
- package/core/services/base.service.js +37 -1
- package/core/services/device-status.service.interface.js +117 -1
- package/core/services/file.service.interface.js +61 -1
- package/core/services/http/file-transfer/file-transfer.service.interface.js +125 -1
- package/core/services/http/https-client/https-client.service.interface.js +152 -1
- package/core/services/http/https.service.interface.js +294 -1
- package/core/services/http/oauth-https.service.js +218 -1
- package/core/services/local-storage.service.interface.js +378 -1
- package/core/services/log.service.js +139 -1
- package/core/services/organization.service.js +202 -1
- package/core/services/paginated-request.service.js +160 -1
- package/core/services/recent-parts.service.js +194 -1
- package/core/services/service-provider.js +114 -1
- package/core/services/session/oauth-session.service.js +104 -1
- package/core/services/session/session.service.interface.js +367 -1
- package/core/utils/general-helper.js +110 -1
- package/data/index.js +44 -1
- package/data/models/announcement.js +70 -1
- package/data/models/assembly-hierarchy-node-breadcrumb.js +51 -1
- package/data/models/assembly-hierarchy-node.js +46 -1
- package/data/models/attribute.js +106 -1
- package/data/models/csa-request-search.js +46 -1
- package/data/models/csa-request-status.js +51 -1
- package/data/models/csa-request.js +112 -1
- package/data/models/document.js +17 -1
- package/data/models/filter-key.js +36 -1
- package/data/models/filter-option-value.js +41 -1
- package/data/models/image.d.ts +3 -1
- package/data/models/image.js +77 -1
- package/data/models/inquiry.js +71 -1
- package/data/models/mounting-location.js +58 -1
- package/data/models/multiple-expert-searches.js +40 -1
- package/data/models/part-enrichment-data.js +50 -1
- package/data/models/part.js +168 -1
- package/data/models/shopping-cart.js +60 -1
- package/data/services/announcement.service.js +89 -1
- package/data/services/assembly-hierarchy-nodes.service.js +193 -1
- package/data/services/csa-helper.service.js +158 -1
- package/data/services/customer-service-assistance.service.js +276 -1
- package/data/services/filter.service.js +97 -1
- package/data/services/inquiry.service.js +68 -1
- package/data/services/part-attribute.service.js +118 -1
- package/data/services/part-enrichment.service.js +56 -1
- package/data/services/part.service.js +182 -1
- package/data/services/related-parts.service.js +83 -1
- package/data/services/shopping-cart.service.js +152 -1
- package/find/index.js +51 -1
- package/find/models/assets/asset.js +32 -1
- package/find/models/search-filter.js +205 -1
- package/find/models/search-input.js +3 -1
- package/find/models/search-output.js +3 -1
- package/find/models/search-result-status.js +40 -1
- package/find/models/search-session-log-object.js +22 -1
- package/find/models/search-status/cv-search-status.js +22 -1
- package/find/models/search-status/search-filter-status.js +36 -1
- package/find/models/search-status/search-status.js +56 -1
- package/find/models/search-status/tag-search-status.js +23 -1
- package/find/models/search-status/text-search-status.js +18 -1
- package/find/models/search-tag.js +16 -1
- package/find/models/smart-filter.js +49 -1
- package/find/models/tagable/i18n-tagable.js +37 -1
- package/find/models/tagable/tagable-base.js +22 -1
- package/find/models/tagable/tagable.js +37 -1
- package/find/models/text-search-config.js +70 -1
- package/find/models/text-search-manipulator.js +90 -1
- package/find/models/text-search-result-item/text-search-error.js +12 -1
- package/find/models/text-search-result-item/text-search-result-item-document.js +34 -1
- package/find/models/text-search-result-item/text-search-result-item-part.js +36 -1
- package/find/models/text-search-result-item/text-search-result-item-recent-query.js +35 -1
- package/find/models/text-search-result-item/text-search-result-item-unknown.js +38 -1
- package/find/models/text-search-result-item/text-search-result-item.js +22 -1
- package/find/services/asset.service.js +348 -1
- package/find/services/filter-uploaders/filter-uploader.js +3 -1
- package/find/services/filter-uploaders/update-filters-uploader.js +77 -1
- package/find/services/filter-uploaders/update-filters.model.js +7 -1
- package/find/services/search/cv-search.service.js +214 -1
- package/find/services/search/recent-text-search-queries.service.js +260 -1
- package/find/services/search/search-result.service.js +539 -1
- package/find/services/search/search.service.js +514 -1
- package/find/services/search/tag-search.service.js +124 -1
- package/find/services/search/text-search.service.js +316 -1
- package/find/services/search-filter.service.js +292 -1
- package/find/utils/search-helper.js +75 -1
- package/gen/sdk-version.d.ts +1 -1
- package/gen/sdk-version.js +5 -1
- package/index.js +392 -1
- package/management/index.js +21 -1
- package/management/models/api-key-list-response.js +3 -1
- package/management/models/api-key-type.js +9 -1
- package/management/models/api-key.js +3 -1
- package/management/services/api-key.service.js +53 -1
- package/ocr/index.js +20 -1
- package/ocr/models/detect-response.js +3 -1
- package/ocr/models/detected-text-entry.js +3 -1
- package/ocr/services/ocr.service.js +59 -1
- package/package.json +1 -1
- package/user-data/index.js +21 -1
- package/user-data/models/part-with-nullable.js +3 -1
- package/user-data/models/request-list/request-list.js +63 -1
- package/user-data/services/favorite/favorite.service.js +108 -1
- package/user-data/services/request-list/request-list.service.js +133 -1
|
@@ -1,2 +1,258 @@
|
|
|
1
1
|
// Copyright © 2022-2025 Partium, Inc. DBA Partium
|
|
2
|
-
"use strict";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __extends = (this && this.__extends) || (function () {
|
|
4
|
+
var extendStatics = function (d, b) {
|
|
5
|
+
extendStatics = Object.setPrototypeOf ||
|
|
6
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
7
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
8
|
+
return extendStatics(d, b);
|
|
9
|
+
};
|
|
10
|
+
return function (d, b) {
|
|
11
|
+
if (typeof b !== "function" && b !== null)
|
|
12
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
13
|
+
extendStatics(d, b);
|
|
14
|
+
function __() { this.constructor = d; }
|
|
15
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
16
|
+
};
|
|
17
|
+
})();
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.JSOauthKeycloakSessionService = void 0;
|
|
20
|
+
var rxjs_1 = require("rxjs");
|
|
21
|
+
var querystring = require("query-string");
|
|
22
|
+
var oauth_session_service_1 = require("../../services/session/oauth-session.service");
|
|
23
|
+
var operators_1 = require("rxjs/operators");
|
|
24
|
+
var https_client_service_interface_1 = require("../../services/http/https-client/https-client.service.interface");
|
|
25
|
+
var user_1 = require("../../models/user");
|
|
26
|
+
var error_1 = require("../../models/error");
|
|
27
|
+
var base64 = require("base-64");
|
|
28
|
+
var user_token_1 = require("../../models/user-token");
|
|
29
|
+
/**
|
|
30
|
+
* Keycloak-specific implementation of the OauthSessionService for
|
|
31
|
+
* web-based Applications.
|
|
32
|
+
*/
|
|
33
|
+
var JSOauthKeycloakSessionService = /** @class */ (function (_super) {
|
|
34
|
+
__extends(JSOauthKeycloakSessionService, _super);
|
|
35
|
+
function JSOauthKeycloakSessionService(serviceProvider) {
|
|
36
|
+
var _this = _super.call(this, serviceProvider) || this;
|
|
37
|
+
_this._status = {
|
|
38
|
+
accessToken: undefined,
|
|
39
|
+
accessTokenExpiration: undefined,
|
|
40
|
+
accessTokenCreateDate: undefined,
|
|
41
|
+
authenticated: false,
|
|
42
|
+
refreshToken: undefined
|
|
43
|
+
};
|
|
44
|
+
_this.status$ = new rxjs_1.BehaviorSubject(_this._status);
|
|
45
|
+
return _this;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Called when the service is initialized
|
|
49
|
+
*/
|
|
50
|
+
JSOauthKeycloakSessionService.prototype.onCreate = function () {
|
|
51
|
+
_super.prototype.onCreate.call(this);
|
|
52
|
+
this.httpsClientService = this.serviceProvider.getService(https_client_service_interface_1.HttpsClientService);
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Get an observable that always sends the OauthStatus every time
|
|
56
|
+
* it changes.
|
|
57
|
+
*
|
|
58
|
+
* @returns Observable<OauthStatus> observable that resolves with the OauthStatus, every time it changes
|
|
59
|
+
*/
|
|
60
|
+
JSOauthKeycloakSessionService.prototype.getStatus = function () {
|
|
61
|
+
return this.status$.asObservable();
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Login user and resolves on success
|
|
65
|
+
*
|
|
66
|
+
* @param config the oauthLoginConfiguration
|
|
67
|
+
*/
|
|
68
|
+
JSOauthKeycloakSessionService.prototype.login = function (config) {
|
|
69
|
+
var _this = this;
|
|
70
|
+
if (config.activeSession) { // instead of logging in with an api-key, the user already logged in to keycloak via another channel (eg direct)
|
|
71
|
+
this.reuseActiveSession(config.activeSession);
|
|
72
|
+
return this.sessionSetup();
|
|
73
|
+
}
|
|
74
|
+
else if (config.apiKey) {
|
|
75
|
+
var authConfig = this.authenticationConfig;
|
|
76
|
+
var _a = this.parseApiKey(config.apiKey), email = _a.email, password = _a.password;
|
|
77
|
+
var realm = authConfig.realm, clientId = authConfig.clientId;
|
|
78
|
+
var url = "".concat(authConfig.baseUrl, "/auth/realms/").concat(realm, "/protocol/openid-connect/token");
|
|
79
|
+
var body = querystring.stringify({
|
|
80
|
+
client_id: clientId,
|
|
81
|
+
grant_type: 'password',
|
|
82
|
+
scope: 'openid',
|
|
83
|
+
username: email,
|
|
84
|
+
password: password
|
|
85
|
+
});
|
|
86
|
+
return this.httpsClientService.post(url, body, null, { 'Content-type': 'application/x-www-form-urlencoded' })
|
|
87
|
+
.pipe((0, operators_1.catchError)(function (error) { return _this.handleError(error); }), (0, operators_1.tap)(function (oauthResponse) {
|
|
88
|
+
if (oauthResponse.error) {
|
|
89
|
+
console.error(oauthResponse.error, oauthResponse.error_description);
|
|
90
|
+
_this.resetToken();
|
|
91
|
+
_this.sessionEnded();
|
|
92
|
+
throw _this.createSdkError(oauthResponse);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
_this.updateTokenFromResponse(oauthResponse);
|
|
96
|
+
}
|
|
97
|
+
}), (0, operators_1.mergeMap)(function () {
|
|
98
|
+
return _this.sessionSetup();
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
return (0, rxjs_1.throwError)(new error_1.SdkError(error_1.SDK_ERROR_CODES.INVALID_LOGIN_CONFIG, null, 'Neither an api key nor an active session was provided'));
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Refresh session and Access token with the refresh token
|
|
107
|
+
*/
|
|
108
|
+
JSOauthKeycloakSessionService.prototype.refresh = function () {
|
|
109
|
+
var _this = this;
|
|
110
|
+
if (this._status && this._status.refreshToken) {
|
|
111
|
+
var authConfig = this.authenticationConfig;
|
|
112
|
+
var _a = this.authenticationConfig, realm = _a.realm, clientId = _a.clientId;
|
|
113
|
+
var url = "".concat(authConfig.baseUrl, "/auth/realms/").concat(realm, "/protocol/openid-connect/token");
|
|
114
|
+
var body = querystring.stringify({
|
|
115
|
+
client_id: clientId,
|
|
116
|
+
grant_type: 'refresh_token',
|
|
117
|
+
refresh_token: this._status.refreshToken
|
|
118
|
+
});
|
|
119
|
+
return this.httpsClientService.post(url, body, null, { 'Content-type': 'application/x-www-form-urlencoded' })
|
|
120
|
+
.pipe((0, operators_1.catchError)(function (error) { return _this.handleError(error); }), (0, operators_1.map)(function (oauthResponse) {
|
|
121
|
+
if (oauthResponse.error) {
|
|
122
|
+
console.error(oauthResponse.error, oauthResponse.error_description);
|
|
123
|
+
_this.resetToken();
|
|
124
|
+
_this.sessionEnded();
|
|
125
|
+
throw _this.createSdkError(oauthResponse);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
_this.updateTokenFromResponse(oauthResponse);
|
|
129
|
+
}
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
this.resetToken();
|
|
134
|
+
this.sessionEnded();
|
|
135
|
+
return (0, rxjs_1.throwError)(this.createSdkError(null, 'Could not refresh because there was no refresh token'));
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Logout the current user-session
|
|
140
|
+
*/
|
|
141
|
+
JSOauthKeycloakSessionService.prototype.logout = function () {
|
|
142
|
+
var _this = this;
|
|
143
|
+
if (this._status && this._status.refreshToken) {
|
|
144
|
+
var authConfig = this.authenticationConfig;
|
|
145
|
+
var _a = this.authenticationConfig, realm = _a.realm, clientId = _a.clientId;
|
|
146
|
+
var url = "".concat(authConfig.baseUrl, "/auth/realms/").concat(realm, "/protocol/openid-connect/logout");
|
|
147
|
+
var body = querystring.stringify({
|
|
148
|
+
client_id: clientId,
|
|
149
|
+
grant_type: 'refresh_token',
|
|
150
|
+
refresh_token: this._status.refreshToken
|
|
151
|
+
});
|
|
152
|
+
return this.httpsClientService.post(url, body, null, {
|
|
153
|
+
'Content-type': 'application/x-www-form-urlencoded',
|
|
154
|
+
// 'Authorization': `Bearer ${access_token}`
|
|
155
|
+
})
|
|
156
|
+
.pipe((0, operators_1.catchError)(function (error) { return _this.handleError(error); }), (0, operators_1.map)(function () {
|
|
157
|
+
_this.resetToken();
|
|
158
|
+
_this.sessionEnded();
|
|
159
|
+
}));
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
this.resetToken();
|
|
163
|
+
this.sessionEnded();
|
|
164
|
+
return (0, rxjs_1.of)(void 0);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Instead of logging in with an api-key, the user already logged in to keycloak via another channel (eg direct)
|
|
169
|
+
* -> reuse this existing session instead of creating a new one.
|
|
170
|
+
* (Used to prevent that the API-key needs to be exposed in the app and sent to the SDK without encryption)
|
|
171
|
+
*
|
|
172
|
+
* @param activeSession data about the active session (session-token, ...)
|
|
173
|
+
*/
|
|
174
|
+
JSOauthKeycloakSessionService.prototype.reuseActiveSession = function (activeSession) {
|
|
175
|
+
this.updateToken(activeSession);
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* Update the current access token from a keycloak response.
|
|
179
|
+
* Should be called after successful login or refresh
|
|
180
|
+
*/
|
|
181
|
+
JSOauthKeycloakSessionService.prototype.updateTokenFromResponse = function (keycloakResponse) {
|
|
182
|
+
var accessTokenExpiration = new Date(Date.now() + (keycloakResponse.expires_in * 1000));
|
|
183
|
+
this.updateToken({
|
|
184
|
+
accessToken: keycloakResponse.access_token,
|
|
185
|
+
accessTokenExpiration: accessTokenExpiration,
|
|
186
|
+
accessTokenCreateDate: new Date(),
|
|
187
|
+
authenticated: true,
|
|
188
|
+
refreshToken: keycloakResponse.refresh_token
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Update the current access token
|
|
193
|
+
* Should be called after successful login, refresh or session reuse
|
|
194
|
+
*/
|
|
195
|
+
JSOauthKeycloakSessionService.prototype.updateToken = function (sessionStatus) {
|
|
196
|
+
this.tokenUpdated(sessionStatus.accessToken, sessionStatus.accessTokenExpiration);
|
|
197
|
+
var decodedToken = (0, user_token_1.createUserToken)(sessionStatus.accessToken);
|
|
198
|
+
var user = user_1.User.createFromToken(decodedToken);
|
|
199
|
+
this.setUser(user);
|
|
200
|
+
this._status = sessionStatus;
|
|
201
|
+
this.status$.next(this._status);
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* Reset the current access token
|
|
205
|
+
* Called on logout or failing login/refresh
|
|
206
|
+
*/
|
|
207
|
+
JSOauthKeycloakSessionService.prototype.resetToken = function () {
|
|
208
|
+
this.tokenUpdated(null, null);
|
|
209
|
+
this.setUser(null);
|
|
210
|
+
this._status = {
|
|
211
|
+
accessToken: undefined,
|
|
212
|
+
accessTokenExpiration: undefined,
|
|
213
|
+
accessTokenCreateDate: undefined,
|
|
214
|
+
authenticated: false,
|
|
215
|
+
refreshToken: undefined
|
|
216
|
+
};
|
|
217
|
+
this.status$.next(this._status);
|
|
218
|
+
};
|
|
219
|
+
JSOauthKeycloakSessionService.prototype.handleError = function (error) {
|
|
220
|
+
if (error instanceof error_1.SdkError) {
|
|
221
|
+
if (error.code === error_1.SDK_ERROR_CODES.BAD_REQUEST) {
|
|
222
|
+
if (error.detail && error.detail['response'] && error.detail['response']['data']) {
|
|
223
|
+
switch (error.detail['response']['data']['error']) {
|
|
224
|
+
case 'unauthorized_client':
|
|
225
|
+
return (0, rxjs_1.throwError)(new error_1.SdkError(error_1.SDK_ERROR_CODES.INVALID_AUTH_CONFIG, error.detail, 'Unauthorized Keycloak client.'));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
// default error handling: if we already receive a SdkError we rethrow it
|
|
230
|
+
return (0, rxjs_1.throwError)(error);
|
|
231
|
+
}
|
|
232
|
+
// if error is not a SdkError we create a a new SdkError with type OAUTH_ERROR
|
|
233
|
+
return (0, rxjs_1.throwError)(this.createSdkError(error));
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* Creates an appropiate SdkError from the input error
|
|
237
|
+
* @param error
|
|
238
|
+
* @returns SdkError
|
|
239
|
+
*/
|
|
240
|
+
JSOauthKeycloakSessionService.prototype.createSdkError = function (error, msg) {
|
|
241
|
+
return new error_1.SdkError(error_1.SDK_ERROR_CODES.OAUTH_ERROR, error, msg);
|
|
242
|
+
};
|
|
243
|
+
JSOauthKeycloakSessionService.prototype.parseApiKey = function (apiKey) {
|
|
244
|
+
try {
|
|
245
|
+
var json = JSON.parse(base64.decode(apiKey));
|
|
246
|
+
if (!json['email'] || !json['password']) {
|
|
247
|
+
throw 'Invalid API Key';
|
|
248
|
+
}
|
|
249
|
+
return json;
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
throw new error_1.SdkError(error_1.SDK_ERROR_CODES.INVALID_API_KEY_FORMAT, null, 'The provided api-key has an invalid format.');
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
return JSOauthKeycloakSessionService;
|
|
256
|
+
}(oauth_session_service_1.OauthSessionService));
|
|
257
|
+
exports.JSOauthKeycloakSessionService = JSOauthKeycloakSessionService;
|
|
258
|
+
//# sourceMappingURL=js-oauth-keycloak-session.service.js.map
|
|
@@ -1,2 +1,126 @@
|
|
|
1
1
|
// Copyright © 2022-2025 Partium, Inc. DBA Partium
|
|
2
|
-
"use strict";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __extends = (this && this.__extends) || (function () {
|
|
4
|
+
var extendStatics = function (d, b) {
|
|
5
|
+
extendStatics = Object.setPrototypeOf ||
|
|
6
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
7
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
8
|
+
return extendStatics(d, b);
|
|
9
|
+
};
|
|
10
|
+
return function (d, b) {
|
|
11
|
+
if (typeof b !== "function" && b !== null)
|
|
12
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
13
|
+
extendStatics(d, b);
|
|
14
|
+
function __() { this.constructor = d; }
|
|
15
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
16
|
+
};
|
|
17
|
+
})();
|
|
18
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
19
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
20
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
21
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
22
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
23
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
24
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
28
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
29
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
30
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
31
|
+
function step(op) {
|
|
32
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
33
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
34
|
+
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;
|
|
35
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
36
|
+
switch (op[0]) {
|
|
37
|
+
case 0: case 1: t = op; break;
|
|
38
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
39
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
40
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
41
|
+
default:
|
|
42
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
43
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
44
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
45
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
46
|
+
if (t[2]) _.ops.pop();
|
|
47
|
+
_.trys.pop(); continue;
|
|
48
|
+
}
|
|
49
|
+
op = body.call(thisArg, _);
|
|
50
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
51
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
|
+
exports.WebDeviceStatusService = void 0;
|
|
56
|
+
var device_info_1 = require("../models/device-info");
|
|
57
|
+
var device_status_service_interface_1 = require("../services/device-status.service.interface");
|
|
58
|
+
var pro_enterprise_1 = require("@ua-parser-js/pro-enterprise");
|
|
59
|
+
/**
|
|
60
|
+
* Implementation of the DeviceStatusService for Web-based applications.
|
|
61
|
+
*/
|
|
62
|
+
var WebDeviceStatusService = /** @class */ (function (_super) {
|
|
63
|
+
__extends(WebDeviceStatusService, _super);
|
|
64
|
+
function WebDeviceStatusService() {
|
|
65
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Returns Promise that resolves with true if connection to a network is available.
|
|
69
|
+
* (Usually the internet, but for intranet-only systems it can also be only intranet)
|
|
70
|
+
*
|
|
71
|
+
* @returns promise that resolves with true or false, depending on network-connection is available or not
|
|
72
|
+
*/
|
|
73
|
+
WebDeviceStatusService.prototype.isConnectionAvailable = function () {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
75
|
+
return __generator(this, function (_a) {
|
|
76
|
+
return [2 /*return*/, window.navigator.onLine];
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Returns Promise that resolves with a DeviceInfo object, containing
|
|
82
|
+
* information about the device and the installation.
|
|
83
|
+
* Used for logging.
|
|
84
|
+
*
|
|
85
|
+
* @returns Promise that resolves with DeviceInfo
|
|
86
|
+
*/
|
|
87
|
+
WebDeviceStatusService.prototype.getDeviceInfo = function () {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
89
|
+
var uaParser, parseResult;
|
|
90
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
91
|
+
return __generator(this, function (_k) {
|
|
92
|
+
uaParser = new pro_enterprise_1.UAParser();
|
|
93
|
+
parseResult = uaParser.getResult();
|
|
94
|
+
return [2 /*return*/, new device_info_1.DeviceInfo({
|
|
95
|
+
manufacturer: (_a = parseResult === null || parseResult === void 0 ? void 0 : parseResult.device) === null || _a === void 0 ? void 0 : _a.vendor, // (optional)
|
|
96
|
+
model: (_b = parseResult === null || parseResult === void 0 ? void 0 : parseResult.device) === null || _b === void 0 ? void 0 : _b.model, // (optional)
|
|
97
|
+
os: (_c = parseResult === null || parseResult === void 0 ? void 0 : parseResult.os) === null || _c === void 0 ? void 0 : _c.name, // (optional)
|
|
98
|
+
osVersion: (_d = parseResult === null || parseResult === void 0 ? void 0 : parseResult.os) === null || _d === void 0 ? void 0 : _d.version, // (optional)
|
|
99
|
+
deviceType: this.getDeviceType(parseResult),
|
|
100
|
+
deviceLanguage: window.navigator.language, // (optional)
|
|
101
|
+
appVersionCode: window['appVersion'], // (optional) can be customized outside of the SDK to log an app version
|
|
102
|
+
appVersionName: window['appVersion'], // (optional) can be customized outside of the SDK to log an app version
|
|
103
|
+
browserName: (_e = parseResult === null || parseResult === void 0 ? void 0 : parseResult.browser) === null || _e === void 0 ? void 0 : _e.name, // (optional)
|
|
104
|
+
browserVersion: (_f = parseResult === null || parseResult === void 0 ? void 0 : parseResult.browser) === null || _f === void 0 ? void 0 : _f.version, // (optional)
|
|
105
|
+
cpuArchitecture: (_g = parseResult === null || parseResult === void 0 ? void 0 : parseResult.cpu) === null || _g === void 0 ? void 0 : _g.architecture, // (optional)
|
|
106
|
+
engineName: (_h = parseResult === null || parseResult === void 0 ? void 0 : parseResult.engine) === null || _h === void 0 ? void 0 : _h.name, // (optional)
|
|
107
|
+
engineVersion: (_j = parseResult === null || parseResult === void 0 ? void 0 : parseResult.engine) === null || _j === void 0 ? void 0 : _j.version, // (optional)
|
|
108
|
+
})];
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
WebDeviceStatusService.prototype.getDeviceType = function (parseResult) {
|
|
113
|
+
var _a;
|
|
114
|
+
switch ((_a = parseResult === null || parseResult === void 0 ? void 0 : parseResult.device) === null || _a === void 0 ? void 0 : _a.type) {
|
|
115
|
+
case 'mobile':
|
|
116
|
+
return 'mobile';
|
|
117
|
+
case 'tablet':
|
|
118
|
+
return 'tablet';
|
|
119
|
+
default:
|
|
120
|
+
return 'desktop';
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
return WebDeviceStatusService;
|
|
124
|
+
}(device_status_service_interface_1.DeviceStatusService));
|
|
125
|
+
exports.WebDeviceStatusService = WebDeviceStatusService;
|
|
126
|
+
//# sourceMappingURL=web-device-status.service.js.map
|
|
@@ -1,2 +1,136 @@
|
|
|
1
1
|
// Copyright © 2022-2025 Partium, Inc. DBA Partium
|
|
2
|
-
"use strict";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __extends = (this && this.__extends) || (function () {
|
|
4
|
+
var extendStatics = function (d, b) {
|
|
5
|
+
extendStatics = Object.setPrototypeOf ||
|
|
6
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
7
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
8
|
+
return extendStatics(d, b);
|
|
9
|
+
};
|
|
10
|
+
return function (d, b) {
|
|
11
|
+
if (typeof b !== "function" && b !== null)
|
|
12
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
13
|
+
extendStatics(d, b);
|
|
14
|
+
function __() { this.constructor = d; }
|
|
15
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
16
|
+
};
|
|
17
|
+
})();
|
|
18
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
19
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
20
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
21
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
22
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
23
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
24
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
28
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
29
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
30
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
31
|
+
function step(op) {
|
|
32
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
33
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
34
|
+
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;
|
|
35
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
36
|
+
switch (op[0]) {
|
|
37
|
+
case 0: case 1: t = op; break;
|
|
38
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
39
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
40
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
41
|
+
default:
|
|
42
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
43
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
44
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
45
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
46
|
+
if (t[2]) _.ops.pop();
|
|
47
|
+
_.trys.pop(); continue;
|
|
48
|
+
}
|
|
49
|
+
op = body.call(thisArg, _);
|
|
50
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
51
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
|
+
exports.WebFileService = void 0;
|
|
56
|
+
var file_service_interface_1 = require("../services/file.service.interface");
|
|
57
|
+
var p_file_1 = require("../models/p-file");
|
|
58
|
+
var error_1 = require("../models/error");
|
|
59
|
+
var WebFileService = /** @class */ (function (_super) {
|
|
60
|
+
__extends(WebFileService, _super);
|
|
61
|
+
function WebFileService() {
|
|
62
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
63
|
+
}
|
|
64
|
+
WebFileService.prototype.getMIMEFromBlob = function (blob) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
+
var arr, _a, header, i;
|
|
67
|
+
return __generator(this, function (_b) {
|
|
68
|
+
switch (_b.label) {
|
|
69
|
+
case 0:
|
|
70
|
+
_a = Uint8Array.bind;
|
|
71
|
+
return [4 /*yield*/, blob.arrayBuffer()];
|
|
72
|
+
case 1:
|
|
73
|
+
arr = new (_a.apply(Uint8Array, [void 0, _b.sent(), 0, 4]))();
|
|
74
|
+
header = '';
|
|
75
|
+
for (i = 0; i < arr.length; i++) {
|
|
76
|
+
header += arr[i].toString(16);
|
|
77
|
+
}
|
|
78
|
+
// It can be completed with that list: https://en.wikipedia.org/wiki/List_of_file_signatures
|
|
79
|
+
switch (header) {
|
|
80
|
+
case '89504e47':
|
|
81
|
+
return [2 /*return*/, 'image/png'];
|
|
82
|
+
case '47494638':
|
|
83
|
+
return [2 /*return*/, 'image/gif'];
|
|
84
|
+
case 'ffd8ffe0':
|
|
85
|
+
case 'ffd8ffe1':
|
|
86
|
+
case 'ffd8ffe2':
|
|
87
|
+
case 'ffd8ffe3':
|
|
88
|
+
case 'ffd8ffe8':
|
|
89
|
+
return [2 /*return*/, 'image/jpeg'];
|
|
90
|
+
default:
|
|
91
|
+
return [2 /*return*/, blob.type || 'unknown'];
|
|
92
|
+
}
|
|
93
|
+
return [2 /*return*/];
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
WebFileService.prototype.getFileType = function (pFile) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
100
|
+
var mimeEssence, mimeType;
|
|
101
|
+
return __generator(this, function (_a) {
|
|
102
|
+
switch (_a.label) {
|
|
103
|
+
case 0: return [4 /*yield*/, this.getMIMEFromBlob(pFile.file)];
|
|
104
|
+
case 1:
|
|
105
|
+
mimeEssence = _a.sent();
|
|
106
|
+
mimeType = mimeEssence.replace(/\/.*/, '');
|
|
107
|
+
switch (mimeType) {
|
|
108
|
+
case 'image':
|
|
109
|
+
return [2 /*return*/, p_file_1.PFileType.IMAGE];
|
|
110
|
+
case 'text':
|
|
111
|
+
return [2 /*return*/, p_file_1.PFileType.TEXT];
|
|
112
|
+
default:
|
|
113
|
+
return [2 /*return*/, p_file_1.PFileType.UNKNOWN];
|
|
114
|
+
}
|
|
115
|
+
return [2 /*return*/];
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
WebFileService.prototype.getImageDimensions = function (pFile) {
|
|
121
|
+
var imageUrl = URL.createObjectURL(pFile.file);
|
|
122
|
+
return new Promise(function (resolve, reject) {
|
|
123
|
+
var image = new Image();
|
|
124
|
+
image.onload = function () {
|
|
125
|
+
resolve([image.width, image.height]);
|
|
126
|
+
};
|
|
127
|
+
image.onerror = function () {
|
|
128
|
+
reject(new error_1.SdkError(error_1.SDK_ERROR_CODES.INVALID_FILE_TYPE, {}, 'Invalid file type'));
|
|
129
|
+
};
|
|
130
|
+
image.src = imageUrl;
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
return WebFileService;
|
|
134
|
+
}(file_service_interface_1.FileService));
|
|
135
|
+
exports.WebFileService = WebFileService;
|
|
136
|
+
//# sourceMappingURL=web-file.service.js.map
|