@partium/js-sdk 14.0.2 → 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.
Files changed (142) hide show
  1. package/catalog/index.js +21 -1
  2. package/catalog/models/catalog-image-info.js +22 -1
  3. package/catalog/models/catalog-image.js +40 -1
  4. package/catalog/models/upsert-catalog-images-dto.js +3 -1
  5. package/catalog/models/upsert-images-result.js +3 -1
  6. package/catalog/services/images.service.js +62 -1
  7. package/core/constants/constants.js +16 -1
  8. package/core/decorators/injection-identifier.js +19 -1
  9. package/core/factories/paginated-request-service.factory.js +33 -1
  10. package/core/index.js +63 -1
  11. package/core/integration-defaults/http/fetch-api-http-error-helper.js +129 -1
  12. package/core/integration-defaults/http/file-transfer/axios-file-transfer.service.js +138 -1
  13. package/core/integration-defaults/http/file-transfer/fetch-api-file-transfer.service.js +210 -1
  14. package/core/integration-defaults/http/handle-axios-error-helper.js +79 -1
  15. package/core/integration-defaults/http/https-client/axios-https-client.service.js +182 -1
  16. package/core/integration-defaults/http/https-client/fetch-api-https-client.service.js +198 -1
  17. package/core/integration-defaults/http/js-oauth-keycloak-https.service.js +32 -1
  18. package/core/integration-defaults/js-p-file.js +36 -1
  19. package/core/integration-defaults/session/js-oauth-api-key-session.service.js +206 -1
  20. package/core/integration-defaults/session/js-oauth-keycloak-auth-config.js +64 -1
  21. package/core/integration-defaults/session/js-oauth-keycloak-session.service.js +257 -1
  22. package/core/integration-defaults/web-device-status.service.js +125 -1
  23. package/core/integration-defaults/web-file.service.js +135 -1
  24. package/core/integration-defaults/web-indexeddb.service.js +142 -1
  25. package/core/integration-defaults/web-local-storage.service.js +310 -1
  26. package/core/models/api-object.js +16 -1
  27. package/core/models/auth-config.js +72 -1
  28. package/core/models/device-info.js +34 -1
  29. package/core/models/error.js +107 -1
  30. package/core/models/formatted-string.js +14 -1
  31. package/core/models/i18n-map.js +61 -1
  32. package/core/models/i18n-string.js +35 -1
  33. package/core/models/log.js +137 -1
  34. package/core/models/organization.js +159 -1
  35. package/core/models/p-file.js +23 -1
  36. package/core/models/paginated-list.js +41 -1
  37. package/core/models/partium-config.js +43 -1
  38. package/core/models/user-token.js +11 -1
  39. package/core/models/user.js +88 -1
  40. package/core/services/backend-status.service.js +147 -1
  41. package/core/services/base-login-init.service.js +57 -1
  42. package/core/services/base.service.js +37 -1
  43. package/core/services/device-status.service.interface.js +117 -1
  44. package/core/services/file.service.interface.js +61 -1
  45. package/core/services/http/file-transfer/file-transfer.service.interface.js +125 -1
  46. package/core/services/http/https-client/https-client.service.interface.js +152 -1
  47. package/core/services/http/https.service.interface.js +294 -1
  48. package/core/services/http/oauth-https.service.js +218 -1
  49. package/core/services/local-storage.service.interface.js +378 -1
  50. package/core/services/log.service.js +139 -1
  51. package/core/services/organization.service.js +202 -1
  52. package/core/services/paginated-request.service.js +160 -1
  53. package/core/services/recent-parts.service.js +194 -1
  54. package/core/services/service-provider.js +114 -1
  55. package/core/services/session/oauth-session.service.js +104 -1
  56. package/core/services/session/session.service.interface.js +367 -1
  57. package/core/utils/general-helper.js +110 -1
  58. package/data/index.js +44 -1
  59. package/data/models/announcement.js +70 -1
  60. package/data/models/assembly-hierarchy-node-breadcrumb.js +51 -1
  61. package/data/models/assembly-hierarchy-node.js +46 -1
  62. package/data/models/attribute.js +106 -1
  63. package/data/models/csa-request-search.js +46 -1
  64. package/data/models/csa-request-status.js +51 -1
  65. package/data/models/csa-request.js +112 -1
  66. package/data/models/document.js +17 -1
  67. package/data/models/filter-key.js +36 -1
  68. package/data/models/filter-option-value.js +41 -1
  69. package/data/models/image.d.ts +6 -1
  70. package/data/models/image.js +77 -1
  71. package/data/models/inquiry.js +71 -1
  72. package/data/models/mounting-location.js +58 -1
  73. package/data/models/multiple-expert-searches.js +40 -1
  74. package/data/models/part-enrichment-data.js +50 -1
  75. package/data/models/part.js +168 -1
  76. package/data/models/shopping-cart.js +60 -1
  77. package/data/services/announcement.service.js +89 -1
  78. package/data/services/assembly-hierarchy-nodes.service.js +193 -1
  79. package/data/services/csa-helper.service.js +158 -1
  80. package/data/services/customer-service-assistance.service.js +276 -1
  81. package/data/services/filter.service.js +97 -1
  82. package/data/services/inquiry.service.js +68 -1
  83. package/data/services/part-attribute.service.js +118 -1
  84. package/data/services/part-enrichment.service.js +56 -1
  85. package/data/services/part.service.js +182 -1
  86. package/data/services/related-parts.service.js +83 -1
  87. package/data/services/shopping-cart.service.js +152 -1
  88. package/find/index.js +51 -1
  89. package/find/models/assets/asset.js +32 -1
  90. package/find/models/search-filter.js +205 -1
  91. package/find/models/search-input.js +3 -1
  92. package/find/models/search-output.js +3 -1
  93. package/find/models/search-result-status.js +40 -1
  94. package/find/models/search-session-log-object.js +22 -1
  95. package/find/models/search-status/cv-search-status.js +22 -1
  96. package/find/models/search-status/search-filter-status.js +36 -1
  97. package/find/models/search-status/search-status.js +56 -1
  98. package/find/models/search-status/tag-search-status.js +23 -1
  99. package/find/models/search-status/text-search-status.js +18 -1
  100. package/find/models/search-tag.js +16 -1
  101. package/find/models/smart-filter.js +49 -1
  102. package/find/models/tagable/i18n-tagable.js +37 -1
  103. package/find/models/tagable/tagable-base.js +22 -1
  104. package/find/models/tagable/tagable.js +37 -1
  105. package/find/models/text-search-config.js +70 -1
  106. package/find/models/text-search-manipulator.js +90 -1
  107. package/find/models/text-search-result-item/text-search-error.js +12 -1
  108. package/find/models/text-search-result-item/text-search-result-item-document.js +34 -1
  109. package/find/models/text-search-result-item/text-search-result-item-part.js +36 -1
  110. package/find/models/text-search-result-item/text-search-result-item-recent-query.js +35 -1
  111. package/find/models/text-search-result-item/text-search-result-item-unknown.js +38 -1
  112. package/find/models/text-search-result-item/text-search-result-item.js +22 -1
  113. package/find/services/asset.service.js +348 -1
  114. package/find/services/filter-uploaders/filter-uploader.js +3 -1
  115. package/find/services/filter-uploaders/update-filters-uploader.js +77 -1
  116. package/find/services/filter-uploaders/update-filters.model.js +7 -1
  117. package/find/services/search/cv-search.service.js +214 -1
  118. package/find/services/search/recent-text-search-queries.service.js +260 -1
  119. package/find/services/search/search-result.service.js +539 -1
  120. package/find/services/search/search.service.js +514 -1
  121. package/find/services/search/tag-search.service.js +124 -1
  122. package/find/services/search/text-search.service.js +316 -1
  123. package/find/services/search-filter.service.js +292 -1
  124. package/find/utils/search-helper.js +75 -1
  125. package/gen/sdk-version.d.ts +1 -1
  126. package/gen/sdk-version.js +5 -1
  127. package/index.js +392 -1
  128. package/management/index.js +21 -1
  129. package/management/models/api-key-list-response.js +3 -1
  130. package/management/models/api-key-type.js +9 -1
  131. package/management/models/api-key.js +3 -1
  132. package/management/services/api-key.service.js +53 -1
  133. package/ocr/index.js +20 -1
  134. package/ocr/models/detect-response.js +3 -1
  135. package/ocr/models/detected-text-entry.js +3 -1
  136. package/ocr/services/ocr.service.js +59 -1
  137. package/package.json +1 -1
  138. package/user-data/index.js +21 -1
  139. package/user-data/models/part-with-nullable.js +3 -1
  140. package/user-data/models/request-list/request-list.js +63 -1
  141. package/user-data/services/favorite/favorite.service.js +108 -1
  142. 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";var __extends=this&&this.__extends||function(){var e=function(r,t){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])},e(r,t)};return function(r,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function o(){this.constructor=r}e(r,t),r.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}}();Object.defineProperty(exports,"__esModule",{value:!0}),exports.JSOauthKeycloakSessionService=void 0;var rxjs_1=require("rxjs"),querystring=require("query-string"),oauth_session_service_1=require("../../services/session/oauth-session.service"),operators_1=require("rxjs/operators"),https_client_service_interface_1=require("../../services/http/https-client/https-client.service.interface"),user_1=require("../../models/user"),error_1=require("../../models/error"),base64=require("base-64"),user_token_1=require("../../models/user-token"),JSOauthKeycloakSessionService=function(e){function r(r){var t=e.call(this,r)||this;return t._status={accessToken:void 0,accessTokenExpiration:void 0,accessTokenCreateDate:void 0,authenticated:!1,refreshToken:void 0},t.status$=new rxjs_1.BehaviorSubject(t._status),t}return __extends(r,e),r.prototype.onCreate=function(){e.prototype.onCreate.call(this),this.httpsClientService=this.serviceProvider.getService(https_client_service_interface_1.HttpsClientService)},r.prototype.getStatus=function(){return this.status$.asObservable()},r.prototype.login=function(e){var r=this;if(e.activeSession)return this.reuseActiveSession(e.activeSession),this.sessionSetup();if(e.apiKey){var t=this.authenticationConfig,o=this.parseApiKey(e.apiKey),s=o.email,n=o.password,i=t.realm,a=t.clientId,c="".concat(t.baseUrl,"/auth/realms/").concat(i,"/protocol/openid-connect/token"),u=querystring.stringify({client_id:a,grant_type:"password",scope:"openid",username:s,password:n});return this.httpsClientService.post(c,u,null,{"Content-type":"application/x-www-form-urlencoded"}).pipe((0,operators_1.catchError)((function(e){return r.handleError(e)})),(0,operators_1.tap)((function(e){if(e.error)throw console.error(e.error,e.error_description),r.resetToken(),r.sessionEnded(),r.createSdkError(e);r.updateTokenFromResponse(e)})),(0,operators_1.mergeMap)((function(){return r.sessionSetup()})))}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"))},r.prototype.refresh=function(){var e=this;if(this._status&&this._status.refreshToken){var r=this.authenticationConfig,t=this.authenticationConfig,o=t.realm,s=t.clientId,n="".concat(r.baseUrl,"/auth/realms/").concat(o,"/protocol/openid-connect/token"),i=querystring.stringify({client_id:s,grant_type:"refresh_token",refresh_token:this._status.refreshToken});return this.httpsClientService.post(n,i,null,{"Content-type":"application/x-www-form-urlencoded"}).pipe((0,operators_1.catchError)((function(r){return e.handleError(r)})),(0,operators_1.map)((function(r){if(r.error)throw console.error(r.error,r.error_description),e.resetToken(),e.sessionEnded(),e.createSdkError(r);e.updateTokenFromResponse(r)})))}return this.resetToken(),this.sessionEnded(),(0,rxjs_1.throwError)(this.createSdkError(null,"Could not refresh because there was no refresh token"))},r.prototype.logout=function(){var e=this;if(this._status&&this._status.refreshToken){var r=this.authenticationConfig,t=this.authenticationConfig,o=t.realm,s=t.clientId,n="".concat(r.baseUrl,"/auth/realms/").concat(o,"/protocol/openid-connect/logout"),i=querystring.stringify({client_id:s,grant_type:"refresh_token",refresh_token:this._status.refreshToken});return this.httpsClientService.post(n,i,null,{"Content-type":"application/x-www-form-urlencoded"}).pipe((0,operators_1.catchError)((function(r){return e.handleError(r)})),(0,operators_1.map)((function(){e.resetToken(),e.sessionEnded()})))}return this.resetToken(),this.sessionEnded(),(0,rxjs_1.of)(void 0)},r.prototype.reuseActiveSession=function(e){this.updateToken(e)},r.prototype.updateTokenFromResponse=function(e){var r=new Date(Date.now()+1e3*e.expires_in);this.updateToken({accessToken:e.access_token,accessTokenExpiration:r,accessTokenCreateDate:new Date,authenticated:!0,refreshToken:e.refresh_token})},r.prototype.updateToken=function(e){this.tokenUpdated(e.accessToken,e.accessTokenExpiration);var r=(0,user_token_1.createUserToken)(e.accessToken),t=user_1.User.createFromToken(r);this.setUser(t),this._status=e,this.status$.next(this._status)},r.prototype.resetToken=function(){this.tokenUpdated(null,null),this.setUser(null),this._status={accessToken:void 0,accessTokenExpiration:void 0,accessTokenCreateDate:void 0,authenticated:!1,refreshToken:void 0},this.status$.next(this._status)},r.prototype.handleError=function(e){return e instanceof error_1.SdkError?e.code===error_1.SDK_ERROR_CODES.BAD_REQUEST&&e.detail&&e.detail.response&&e.detail.response.data&&"unauthorized_client"===e.detail.response.data.error?(0,rxjs_1.throwError)(new error_1.SdkError(error_1.SDK_ERROR_CODES.INVALID_AUTH_CONFIG,e.detail,"Unauthorized Keycloak client.")):(0,rxjs_1.throwError)(e):(0,rxjs_1.throwError)(this.createSdkError(e))},r.prototype.createSdkError=function(e,r){return new error_1.SdkError(error_1.SDK_ERROR_CODES.OAUTH_ERROR,e,r)},r.prototype.parseApiKey=function(e){try{var r=JSON.parse(base64.decode(e));if(!r.email||!r.password)throw"Invalid API Key";return r}catch(e){throw new error_1.SdkError(error_1.SDK_ERROR_CODES.INVALID_API_KEY_FORMAT,null,"The provided api-key has an invalid format.")}},r}(oauth_session_service_1.OauthSessionService);exports.JSOauthKeycloakSessionService=JSOauthKeycloakSessionService;
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";var __extends=this&&this.__extends||function(){var e=function(n,t){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])},e(n,t)};return function(n,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=n}e(n,t),n.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}}(),__awaiter=this&&this.__awaiter||function(e,n,t,r){return new(t||(t=Promise))((function(i,o){function u(e){try{c(r.next(e))}catch(e){o(e)}}function a(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var n;e.done?i(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(u,a)}c((r=r.apply(e,n||[])).next())}))},__generator=this&&this.__generator||function(e,n){var t,r,i,o,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(c){return function(a){if(t)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(u=0)),u;)try{if(t=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(i=u.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){u.label=a[1];break}if(6===a[0]&&u.label<i[1]){u.label=i[1],i=a;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(a);break}i[2]&&u.ops.pop(),u.trys.pop();continue}a=n.call(e,u)}catch(e){a=[6,e],r=0}finally{t=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.WebDeviceStatusService=void 0;var device_info_1=require("../models/device-info"),device_status_service_interface_1=require("../services/device-status.service.interface"),pro_enterprise_1=require("@ua-parser-js/pro-enterprise"),WebDeviceStatusService=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.isConnectionAvailable=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(e){return[2,window.navigator.onLine]}))}))},n.prototype.getDeviceInfo=function(){return __awaiter(this,void 0,void 0,(function(){var e,n,t,r,i,o,u,a,c,l,s;return __generator(this,(function(v){return e=new pro_enterprise_1.UAParser,n=e.getResult(),[2,new device_info_1.DeviceInfo({manufacturer:null===(t=null==n?void 0:n.device)||void 0===t?void 0:t.vendor,model:null===(r=null==n?void 0:n.device)||void 0===r?void 0:r.model,os:null===(i=null==n?void 0:n.os)||void 0===i?void 0:i.name,osVersion:null===(o=null==n?void 0:n.os)||void 0===o?void 0:o.version,deviceType:this.getDeviceType(n),deviceLanguage:window.navigator.language,appVersionCode:window.appVersion,appVersionName:window.appVersion,browserName:null===(u=null==n?void 0:n.browser)||void 0===u?void 0:u.name,browserVersion:null===(a=null==n?void 0:n.browser)||void 0===a?void 0:a.version,cpuArchitecture:null===(c=null==n?void 0:n.cpu)||void 0===c?void 0:c.architecture,engineName:null===(l=null==n?void 0:n.engine)||void 0===l?void 0:l.name,engineVersion:null===(s=null==n?void 0:n.engine)||void 0===s?void 0:s.version})]}))}))},n.prototype.getDeviceType=function(e){var n;switch(null===(n=null==e?void 0:e.device)||void 0===n?void 0:n.type){case"mobile":return"mobile";case"tablet":return"tablet";default:return"desktop"}},n}(device_status_service_interface_1.DeviceStatusService);exports.WebDeviceStatusService=WebDeviceStatusService;
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";var __extends=this&&this.__extends||function(){var e=function(r,t){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])},e(r,t)};return function(r,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=r}e(r,t),r.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}}(),__awaiter=this&&this.__awaiter||function(e,r,t,n){return new(t||(t=Promise))((function(i,o){function a(e){try{u(n.next(e))}catch(e){o(e)}}function c(e){try{u(n.throw(e))}catch(e){o(e)}}function u(e){var r;e.done?i(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(a,c)}u((n=n.apply(e,r||[])).next())}))},__generator=this&&this.__generator||function(e,r){var t,n,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function c(c){return function(u){return function(c){if(t)throw new TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(t=1,n&&(i=2&c[0]?n.return:c[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,c[1])).done)return i;switch(n=0,i&&(c=[2&c[0],i.value]),c[0]){case 0:case 1:i=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,n=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==c[0]&&2!==c[0])){a=0;continue}if(3===c[0]&&(!i||c[1]>i[0]&&c[1]<i[3])){a.label=c[1];break}if(6===c[0]&&a.label<i[1]){a.label=i[1],i=c;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(c);break}i[2]&&a.ops.pop(),a.trys.pop();continue}c=r.call(e,a)}catch(e){c=[6,e],n=0}finally{t=i=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,u])}}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.WebFileService=void 0;var file_service_interface_1=require("../services/file.service.interface"),p_file_1=require("../models/p-file"),error_1=require("../models/error"),WebFileService=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return __extends(r,e),r.prototype.getMIMEFromBlob=function(e){return __awaiter(this,void 0,void 0,(function(){var r,t,n,i;return __generator(this,(function(o){switch(o.label){case 0:return t=Uint8Array.bind,[4,e.arrayBuffer()];case 1:for(r=new(t.apply(Uint8Array,[void 0,o.sent(),0,4])),n="",i=0;i<r.length;i++)n+=r[i].toString(16);switch(n){case"89504e47":return[2,"image/png"];case"47494638":return[2,"image/gif"];case"ffd8ffe0":case"ffd8ffe1":case"ffd8ffe2":case"ffd8ffe3":case"ffd8ffe8":return[2,"image/jpeg"];default:return[2,e.type||"unknown"]}return[2]}}))}))},r.prototype.getFileType=function(e){return __awaiter(this,void 0,void 0,(function(){var r;return __generator(this,(function(t){switch(t.label){case 0:return[4,this.getMIMEFromBlob(e.file)];case 1:switch(r=t.sent(),r.replace(/\/.*/,"")){case"image":return[2,p_file_1.PFileType.IMAGE];case"text":return[2,p_file_1.PFileType.TEXT];default:return[2,p_file_1.PFileType.UNKNOWN]}return[2]}}))}))},r.prototype.getImageDimensions=function(e){var r=URL.createObjectURL(e.file);return new Promise((function(e,t){var n=new Image;n.onload=function(){e([n.width,n.height])},n.onerror=function(){t(new error_1.SdkError(error_1.SDK_ERROR_CODES.INVALID_FILE_TYPE,{},"Invalid file type"))},n.src=r}))},r}(file_service_interface_1.FileService);exports.WebFileService=WebFileService;
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