@partium/js-sdk 14.4.1 → 14.5.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 (153) hide show
  1. package/catalog/index.js +1 -21
  2. package/catalog/models/catalog-image-info.js +1 -22
  3. package/catalog/models/catalog-image.js +1 -40
  4. package/catalog/models/upsert-catalog-images-dto.js +1 -3
  5. package/catalog/models/upsert-images-result.js +1 -3
  6. package/catalog/services/images.service.js +1 -62
  7. package/core/constants/constants.d.ts +1 -0
  8. package/core/constants/constants.js +1 -16
  9. package/core/decorators/injection-identifier.js +1 -19
  10. package/core/factories/paginated-request-service.factory.js +1 -33
  11. package/core/index.js +1 -63
  12. package/core/integration-defaults/http/fetch-api-http-error-helper.js +1 -129
  13. package/core/integration-defaults/http/file-transfer/axios-file-transfer.service.js +1 -138
  14. package/core/integration-defaults/http/file-transfer/fetch-api-file-transfer.service.js +1 -210
  15. package/core/integration-defaults/http/handle-axios-error-helper.js +1 -79
  16. package/core/integration-defaults/http/https-client/axios-https-client.service.js +1 -182
  17. package/core/integration-defaults/http/https-client/fetch-api-https-client.service.js +1 -198
  18. package/core/integration-defaults/http/js-oauth-keycloak-https.service.js +1 -32
  19. package/core/integration-defaults/js-p-file.js +1 -36
  20. package/core/integration-defaults/session/js-oauth-api-key-session.service.js +1 -206
  21. package/core/integration-defaults/session/js-oauth-keycloak-auth-config.js +1 -64
  22. package/core/integration-defaults/session/js-oauth-keycloak-session.service.js +1 -257
  23. package/core/integration-defaults/web-device-status.service.js +1 -125
  24. package/core/integration-defaults/web-file.service.js +1 -135
  25. package/core/integration-defaults/web-indexeddb.service.js +1 -142
  26. package/core/integration-defaults/web-local-storage.service.js +1 -310
  27. package/core/models/api-object.js +1 -16
  28. package/core/models/auth-config.js +1 -72
  29. package/core/models/device-info.js +1 -34
  30. package/core/models/error.js +1 -107
  31. package/core/models/formatted-string.js +1 -14
  32. package/core/models/i18n-map.js +1 -61
  33. package/core/models/i18n-string.js +1 -35
  34. package/core/models/log.js +1 -137
  35. package/core/models/organization.js +1 -159
  36. package/core/models/p-file.js +1 -23
  37. package/core/models/paginated-list.js +1 -41
  38. package/core/models/partium-config.js +1 -43
  39. package/core/models/user-token.js +1 -11
  40. package/core/models/user.js +1 -89
  41. package/core/services/backend-status.service.js +1 -147
  42. package/core/services/base-login-init.service.js +1 -57
  43. package/core/services/base.service.js +1 -37
  44. package/core/services/device-status.service.interface.js +1 -117
  45. package/core/services/file.service.interface.js +1 -61
  46. package/core/services/http/file-transfer/file-transfer.service.interface.js +1 -125
  47. package/core/services/http/https-client/https-client.service.interface.js +1 -152
  48. package/core/services/http/https.service.interface.d.ts +3 -1
  49. package/core/services/http/https.service.interface.js +1 -294
  50. package/core/services/http/oauth-https.service.js +1 -218
  51. package/core/services/local-storage.service.interface.js +1 -378
  52. package/core/services/log.service.js +1 -139
  53. package/core/services/organization.service.js +1 -202
  54. package/core/services/paginated-request.service.js +1 -154
  55. package/core/services/recent-parts.service.js +1 -194
  56. package/core/services/service-provider.js +1 -114
  57. package/core/services/session/oauth-session.service.js +1 -104
  58. package/core/services/session/session.service.interface.js +1 -367
  59. package/core/utils/general-helper.js +1 -110
  60. package/data/index.js +1 -44
  61. package/data/models/announcement.js +1 -70
  62. package/data/models/assembly-hierarchy-node-breadcrumb.js +1 -51
  63. package/data/models/assembly-hierarchy-node.js +1 -46
  64. package/data/models/attribute.js +1 -106
  65. package/data/models/csa-request-search.js +1 -46
  66. package/data/models/csa-request-status.js +1 -51
  67. package/data/models/csa-request.js +1 -112
  68. package/data/models/document.js +1 -17
  69. package/data/models/filter-key.js +1 -36
  70. package/data/models/filter-option-value.js +1 -41
  71. package/data/models/image.js +1 -77
  72. package/data/models/inquiry.js +1 -71
  73. package/data/models/mounting-location.js +1 -58
  74. package/data/models/multiple-expert-searches.js +1 -40
  75. package/data/models/part-enrichment-data.js +1 -50
  76. package/data/models/part.d.ts +1 -1
  77. package/data/models/part.js +1 -168
  78. package/data/models/shopping-cart.js +1 -60
  79. package/data/services/announcement.service.js +1 -89
  80. package/data/services/assembly-hierarchy-nodes.service.js +1 -193
  81. package/data/services/csa-helper.service.js +1 -158
  82. package/data/services/customer-service-assistance.service.js +1 -276
  83. package/data/services/filter.service.js +1 -97
  84. package/data/services/inquiry.service.js +1 -68
  85. package/data/services/part-attribute.service.js +1 -118
  86. package/data/services/part-enrichment.service.js +1 -56
  87. package/data/services/part.service.js +1 -182
  88. package/data/services/related-parts.service.js +1 -83
  89. package/data/services/shopping-cart.service.js +1 -152
  90. package/datacuration/index.d.ts +4 -0
  91. package/datacuration/index.js +2 -0
  92. package/datacuration/models/image-submission-request.d.ts +55 -0
  93. package/datacuration/models/image-submission-request.js +2 -0
  94. package/datacuration/models/submitted-image-response.d.ts +27 -0
  95. package/datacuration/models/submitted-image-response.js +2 -0
  96. package/datacuration/services/image-submission.service.d.ts +26 -0
  97. package/datacuration/services/image-submission.service.js +2 -0
  98. package/find/index.js +1 -51
  99. package/find/models/assets/asset.js +1 -32
  100. package/find/models/search-filter.js +1 -205
  101. package/find/models/search-input.js +1 -3
  102. package/find/models/search-output.js +1 -3
  103. package/find/models/search-result-status.js +1 -40
  104. package/find/models/search-session-log-object.js +1 -22
  105. package/find/models/search-status/cv-search-status.js +1 -22
  106. package/find/models/search-status/search-filter-status.js +1 -36
  107. package/find/models/search-status/search-status.js +1 -56
  108. package/find/models/search-status/tag-search-status.js +1 -23
  109. package/find/models/search-status/text-search-status.js +1 -18
  110. package/find/models/search-tag.js +1 -16
  111. package/find/models/smart-filter.js +1 -49
  112. package/find/models/tagable/i18n-tagable.js +1 -37
  113. package/find/models/tagable/tagable-base.js +1 -22
  114. package/find/models/tagable/tagable.js +1 -37
  115. package/find/models/text-search-config.js +1 -70
  116. package/find/models/text-search-manipulator.js +1 -90
  117. package/find/models/text-search-result-item/text-search-error.js +1 -12
  118. package/find/models/text-search-result-item/text-search-result-item-document.js +1 -34
  119. package/find/models/text-search-result-item/text-search-result-item-part.js +1 -36
  120. package/find/models/text-search-result-item/text-search-result-item-recent-query.js +1 -35
  121. package/find/models/text-search-result-item/text-search-result-item-unknown.js +1 -38
  122. package/find/models/text-search-result-item/text-search-result-item.js +1 -22
  123. package/find/services/asset.service.js +1 -348
  124. package/find/services/filter-uploaders/filter-uploader.js +1 -3
  125. package/find/services/filter-uploaders/update-filters-uploader.js +1 -77
  126. package/find/services/filter-uploaders/update-filters.model.js +1 -7
  127. package/find/services/search/cv-search.service.js +1 -214
  128. package/find/services/search/recent-text-search-queries.service.js +1 -260
  129. package/find/services/search/search-result.service.js +1 -539
  130. package/find/services/search/search.service.js +1 -514
  131. package/find/services/search/tag-search.service.js +1 -124
  132. package/find/services/search/text-search.service.js +1 -316
  133. package/find/services/search-filter.service.js +1 -292
  134. package/find/utils/search-helper.js +1 -75
  135. package/gen/sdk-version.d.ts +1 -1
  136. package/gen/sdk-version.js +1 -5
  137. package/index.d.ts +2 -0
  138. package/index.js +1 -392
  139. package/management/index.js +1 -21
  140. package/management/models/api-key-list-response.js +1 -3
  141. package/management/models/api-key-type.js +1 -9
  142. package/management/models/api-key.js +1 -3
  143. package/management/services/api-key.service.js +1 -53
  144. package/ocr/index.js +1 -20
  145. package/ocr/models/detect-response.js +1 -3
  146. package/ocr/models/detected-text-entry.js +1 -3
  147. package/ocr/services/ocr.service.js +1 -59
  148. package/package.json +1 -1
  149. package/user-data/index.js +1 -21
  150. package/user-data/models/part-with-nullable.js +1 -3
  151. package/user-data/models/request-list/request-list.js +1 -63
  152. package/user-data/services/favorite/favorite.service.js +1 -108
  153. package/user-data/services/request-list/request-list.service.js +1 -133
@@ -1,140 +1,2 @@
1
1
  // Copyright © 2022-2025 Partium, Inc. DBA Partium
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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
- return c > 3 && r && Object.defineProperty(target, key, r), r;
23
- };
24
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
25
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
26
- return new (P || (P = Promise))(function (resolve, reject) {
27
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
28
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
29
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
30
- step((generator = generator.apply(thisArg, _arguments || [])).next());
31
- });
32
- };
33
- var __generator = (this && this.__generator) || function (thisArg, body) {
34
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
35
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
36
- function verb(n) { return function (v) { return step([n, v]); }; }
37
- function step(op) {
38
- if (f) throw new TypeError("Generator is already executing.");
39
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
40
- 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;
41
- if (y = 0, t) op = [op[0] & 2, t.value];
42
- switch (op[0]) {
43
- case 0: case 1: t = op; break;
44
- case 4: _.label++; return { value: op[1], done: false };
45
- case 5: _.label++; y = op[1]; op = [0]; continue;
46
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
47
- default:
48
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
49
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
50
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
51
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
52
- if (t[2]) _.ops.pop();
53
- _.trys.pop(); continue;
54
- }
55
- op = body.call(thisArg, _);
56
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
57
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
58
- }
59
- };
60
- Object.defineProperty(exports, "__esModule", { value: true });
61
- exports.LogServiceImpl = void 0;
62
- var rxjs_1 = require("rxjs");
63
- var operators_1 = require("rxjs/operators");
64
- var injection_identifier_1 = require("../decorators/injection-identifier");
65
- var https_service_interface_1 = require("./http/https.service.interface");
66
- var log_1 = require("../models/log");
67
- var general_helper_1 = require("../utils/general-helper");
68
- var base_login_init_service_1 = require("./base-login-init.service");
69
- var LogServiceImpl = /** @class */ (function (_super) {
70
- __extends(LogServiceImpl, _super);
71
- function LogServiceImpl() {
72
- var _this = _super !== null && _super.apply(this, arguments) || this;
73
- /**
74
- * An observable (and its source) over the logged eventLogs. Useful for hook
75
- * the logging without catching the subscription. For example, on unit testing.
76
- */
77
- _this.loggedEventSource = new rxjs_1.Subject();
78
- _this.loggedEvent$ = _this.loggedEventSource.asObservable();
79
- return _this;
80
- }
81
- /**
82
- * Initializes the LogService and configures it based on the passed Partium configuration.
83
- */
84
- LogServiceImpl.prototype.init = function (config, userEmail, currentOrganization$) {
85
- var _a;
86
- _super.prototype.init.call(this, config, userEmail, currentOrganization$);
87
- this.externalUserId = (_a = config.authenticationConfig) === null || _a === void 0 ? void 0 : _a.externalUserId;
88
- return (0, rxjs_1.of)(undefined); // resolve
89
- };
90
- LogServiceImpl.prototype.onCreate = function () {
91
- this.httpsService = this.serviceProvider.getService(https_service_interface_1.HttpsService);
92
- };
93
- LogServiceImpl.prototype.logEvent = function (eventLog) {
94
- var _this = this;
95
- if (eventLog.data) {
96
- var snakeCaseData = (0, general_helper_1.camelToSnake)(eventLog.data);
97
- eventLog.data = snakeCaseData;
98
- }
99
- eventLog.externalUserId = this.externalUserId;
100
- var adapter = (0, log_1.eventLogRequestResponseAdapter)(eventLog);
101
- return (0, rxjs_1.from)(this.createRequestBody(eventLog)).pipe((0, operators_1.mergeMap)(function (requestBody) {
102
- return _this.httpsService.post('events/', requestBody, null, https_service_interface_1.BACKEND_SERVICE.LOG);
103
- }), (0, operators_1.tap)(function () {
104
- console.log('Logged event: ', eventLog);
105
- }), (0, operators_1.map)(adapter), (0, operators_1.tap)(function (logEvent) { return _this.loggedEventSource.next(logEvent); }));
106
- };
107
- /**
108
- * Create the log request body
109
- *
110
- * @param eventLog: EventLog
111
- *
112
- * @returns Promise<EventLogRequestBody>
113
- */
114
- LogServiceImpl.prototype.createRequestBody = function (eventLog) {
115
- return __awaiter(this, void 0, void 0, function () {
116
- var first_org_id;
117
- return __generator(this, function (_a) {
118
- switch (_a.label) {
119
- case 0: return [4 /*yield*/, (0, rxjs_1.firstValueFrom)(this.currentOrganization$)];
120
- case 1:
121
- first_org_id = (_a.sent()).partiumId;
122
- return [2 /*return*/, {
123
- version: eventLog.version,
124
- organization_id: eventLog.organizationId || first_org_id,
125
- interface: eventLog.interface,
126
- event: eventLog.event,
127
- external_user_id: eventLog.externalUserId,
128
- data: eventLog.data,
129
- }];
130
- }
131
- });
132
- });
133
- };
134
- LogServiceImpl = __decorate([
135
- (0, injection_identifier_1.InjectionIdentifier)('LogService')
136
- ], LogServiceImpl);
137
- return LogServiceImpl;
138
- }(base_login_init_service_1.BaseLoginInitService));
139
- exports.LogServiceImpl = LogServiceImpl;
140
- //# sourceMappingURL=log.service.js.map
2
+ "use strict";var __extends=this&&this.__extends||function(){var e=function(t,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},e(t,r)};return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),__decorate=this&&this.__decorate||function(e,t,r,n){var o,i=arguments.length,a=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,n);else for(var c=e.length-1;c>=0;c--)(o=e[c])&&(a=(i<3?o(a):i>3?o(t,r,a):o(t,r))||a);return i>3&&a&&Object.defineProperty(t,r,a),a},__awaiter=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{s(n.next(e))}catch(e){i(e)}}function c(e){try{s(n.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,c)}s((n=n.apply(e,t||[])).next())}))},__generator=this&&this.__generator||function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(s){return function(c){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&c[0]?n.return:c[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,c[1])).done)return o;switch(n=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=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(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],n=0}finally{r=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,s])}}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.LogServiceImpl=void 0;var rxjs_1=require("rxjs"),operators_1=require("rxjs/operators"),injection_identifier_1=require("../decorators/injection-identifier"),https_service_interface_1=require("./http/https.service.interface"),log_1=require("../models/log"),general_helper_1=require("../utils/general-helper"),base_login_init_service_1=require("./base-login-init.service"),LogServiceImpl=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.loggedEventSource=new rxjs_1.Subject,t.loggedEvent$=t.loggedEventSource.asObservable(),t}return __extends(t,e),t.prototype.init=function(t,r,n){var o;return e.prototype.init.call(this,t,r,n),this.externalUserId=null===(o=t.authenticationConfig)||void 0===o?void 0:o.externalUserId,(0,rxjs_1.of)(void 0)},t.prototype.onCreate=function(){this.httpsService=this.serviceProvider.getService(https_service_interface_1.HttpsService)},t.prototype.logEvent=function(e){var t=this;if(e.data){var r=(0,general_helper_1.camelToSnake)(e.data);e.data=r}e.externalUserId=this.externalUserId;var n=(0,log_1.eventLogRequestResponseAdapter)(e);return(0,rxjs_1.from)(this.createRequestBody(e)).pipe((0,operators_1.mergeMap)((function(e){return t.httpsService.post("events/",e,null,https_service_interface_1.BACKEND_SERVICE.LOG)})),(0,operators_1.tap)((function(){console.log("Logged event: ",e)})),(0,operators_1.map)(n),(0,operators_1.tap)((function(e){return t.loggedEventSource.next(e)})))},t.prototype.createRequestBody=function(e){return __awaiter(this,void 0,void 0,(function(){var t;return __generator(this,(function(r){switch(r.label){case 0:return[4,(0,rxjs_1.firstValueFrom)(this.currentOrganization$)];case 1:return t=r.sent().partiumId,[2,{version:e.version,organization_id:e.organizationId||t,interface:e.interface,event:e.event,external_user_id:e.externalUserId,data:e.data}]}}))}))},t=__decorate([(0,injection_identifier_1.InjectionIdentifier)("LogService")],t)}(base_login_init_service_1.BaseLoginInitService);exports.LogServiceImpl=LogServiceImpl;
@@ -1,203 +1,2 @@
1
1
  // Copyright © 2022-2025 Partium, Inc. DBA Partium
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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
- return c > 3 && r && Object.defineProperty(target, key, r), r;
23
- };
24
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
25
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
26
- return new (P || (P = Promise))(function (resolve, reject) {
27
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
28
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
29
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
30
- step((generator = generator.apply(thisArg, _arguments || [])).next());
31
- });
32
- };
33
- var __generator = (this && this.__generator) || function (thisArg, body) {
34
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
35
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
36
- function verb(n) { return function (v) { return step([n, v]); }; }
37
- function step(op) {
38
- if (f) throw new TypeError("Generator is already executing.");
39
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
40
- 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;
41
- if (y = 0, t) op = [op[0] & 2, t.value];
42
- switch (op[0]) {
43
- case 0: case 1: t = op; break;
44
- case 4: _.label++; return { value: op[1], done: false };
45
- case 5: _.label++; y = op[1]; op = [0]; continue;
46
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
47
- default:
48
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
49
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
50
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
51
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
52
- if (t[2]) _.ops.pop();
53
- _.trys.pop(); continue;
54
- }
55
- op = body.call(thisArg, _);
56
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
57
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
58
- }
59
- };
60
- Object.defineProperty(exports, "__esModule", { value: true });
61
- exports.OrganizationService = void 0;
62
- var rxjs_1 = require("rxjs");
63
- var operators_1 = require("rxjs/operators");
64
- var injection_identifier_1 = require("../decorators/injection-identifier");
65
- var organization_1 = require("../models/organization");
66
- var base_service_1 = require("./base.service");
67
- var https_service_interface_1 = require("./http/https.service.interface");
68
- var OrganizationService = /** @class */ (function (_super) {
69
- __extends(OrganizationService, _super);
70
- function OrganizationService(serviceProvider) {
71
- var _this = _super.call(this, serviceProvider) || this;
72
- _this.organizations$ = new rxjs_1.ReplaySubject(1);
73
- return _this;
74
- }
75
- OrganizationService.prototype.onCreate = function () {
76
- this.httpsService = this.serviceProvider.getService(https_service_interface_1.HttpsService);
77
- };
78
- /**
79
- * initializes the service by requesting the backend to get the organizations, and caching them
80
- * should be called whenever the logged-in user and his associated organization changes (i.e. on login)
81
- */
82
- OrganizationService.prototype.init = function () {
83
- return __awaiter(this, void 0, void 0, function () {
84
- var res;
85
- return __generator(this, function (_a) {
86
- switch (_a.label) {
87
- case 0:
88
- console.log('OrganizationService - init');
89
- return [4 /*yield*/, this.getOrganizationsRequest()];
90
- case 1:
91
- res = _a.sent();
92
- this.organizations$.next(res.map(function (organization) { return new organization_1.Organization(organization); }));
93
- console.log("..initialized organization.service (organizations: ".concat(res.length, ")"));
94
- return [2 /*return*/];
95
- }
96
- });
97
- });
98
- };
99
- /**
100
- * gets all organizations of the logged-in user is associated with
101
- */
102
- OrganizationService.prototype.getOrganizations = function () {
103
- return __awaiter(this, void 0, void 0, function () {
104
- return __generator(this, function (_a) {
105
- return [2 /*return*/, this.organizations$.pipe((0, operators_1.take)(1)).toPromise()];
106
- });
107
- });
108
- };
109
- /**
110
- * Gets the first organization of the organization that the logged-in user is associated with, which does not need
111
- * additional authentication.
112
- */
113
- OrganizationService.prototype.getFirstOrganization = function () {
114
- return __awaiter(this, void 0, void 0, function () {
115
- var organizations;
116
- return __generator(this, function (_a) {
117
- switch (_a.label) {
118
- case 0: return [4 /*yield*/, this.getOrganizations()];
119
- case 1:
120
- organizations = _a.sent();
121
- return [2 /*return*/, organizations.find(function (organization) { return !organization.requiresAdditionalAuthentication; }) || organizations[0]];
122
- }
123
- });
124
- });
125
- };
126
- /**
127
- * gets an organization by id
128
- * @param string // organization id
129
- * @param includeSubOrgs // if true, the organizations sub-orgs will also be included in the response
130
- * @returns Promise<Organization>
131
- */
132
- OrganizationService.prototype.getOrganization = function (organizationId_1) {
133
- return __awaiter(this, arguments, void 0, function (organizationId, includeSubOrgs) {
134
- if (includeSubOrgs === void 0) { includeSubOrgs = false; }
135
- return __generator(this, function (_a) {
136
- return [2 /*return*/, this.httpsService
137
- .get("organizations-ui/".concat(organizationId), [{ includeSubOrgs: includeSubOrgs }], https_service_interface_1.BACKEND_SERVICE.DATA)
138
- .pipe((0, operators_1.map)(function (response) { return organization_1.Organization.fromAPIResponse(response); }))
139
- .toPromise()];
140
- });
141
- });
142
- };
143
- /**
144
- * gets the first 100 organizations for the current user by roles
145
- * @param string[] // roles
146
- * @returns Promise<Organization>
147
- * @deprecated use getOrganizationsListByRoles instead
148
- */
149
- OrganizationService.prototype.getOrganizationsByRoles = function (roles) {
150
- return __awaiter(this, void 0, void 0, function () {
151
- return __generator(this, function (_a) {
152
- return [2 /*return*/, this.httpsService
153
- .get("organizations", [{ roles: roles.join(',') }], https_service_interface_1.BACKEND_SERVICE.DATA)
154
- .pipe((0, operators_1.map)(function (response) {
155
- var organizations = response['results'] || [];
156
- return organizations.map(function (backendOrg) { return organization_1.Organization.fromAPIResponse(backendOrg); });
157
- }))
158
- .toPromise()];
159
- });
160
- });
161
- };
162
- /**
163
- * gets all organizations for the current user by roles with reduced organization data. It makes multiple requests to retrieve all the organizations.
164
- * @param string[] // roles
165
- * @param pageSize // number
166
- * @returns Observable<Organization>
167
- */
168
- OrganizationService.prototype.getOrganizationsListByRoles = function (roles, pageSize) {
169
- var _this = this;
170
- if (pageSize === void 0) { pageSize = 1000; }
171
- var url = 'organizations-list';
172
- return this.httpsService.get(url, [{ roles: roles.join(','), page_size: pageSize }], https_service_interface_1.BACKEND_SERVICE.DATA).pipe((0, operators_1.expand)(function (response) {
173
- var nextPage = !!(response['pagination'] && response['pagination']['next']);
174
- var nextPageNumber = parseInt(response['pagination']['page']) + 1;
175
- return nextPage
176
- ? _this.httpsService.get(url, [{ roles: roles.join(','), page_size: pageSize, page: nextPageNumber }], https_service_interface_1.BACKEND_SERVICE.DATA)
177
- : rxjs_1.EMPTY;
178
- }), (0, operators_1.reduce)(function (acc, current) { return acc.concat(current.results); }, []), (0, operators_1.takeWhile)(function (response) {
179
- return response !== null;
180
- }, true), (0, operators_1.map)(function (response) {
181
- var organizations = response || [];
182
- return organizations.map(function (backendOrg) { return organization_1.Organization.fromAPIResponse(backendOrg); });
183
- }));
184
- };
185
- OrganizationService.prototype.getOrganizationsRequest = function () {
186
- return __awaiter(this, void 0, void 0, function () {
187
- return __generator(this, function (_a) {
188
- return [2 /*return*/, this.httpsService
189
- .get('organizations-ui', [{ includeSubOrgs: true }], https_service_interface_1.BACKEND_SERVICE.DATA)
190
- .pipe((0, operators_1.map)(function (response) {
191
- return response.map(function (backendOrg) { return organization_1.Organization.fromAPIResponse(backendOrg); });
192
- }))
193
- .toPromise()];
194
- });
195
- });
196
- };
197
- OrganizationService = __decorate([
198
- (0, injection_identifier_1.InjectionIdentifier)('OrganizationService')
199
- ], OrganizationService);
200
- return OrganizationService;
201
- }(base_service_1.BaseService));
202
- exports.OrganizationService = OrganizationService;
203
- //# sourceMappingURL=organization.service.js.map
2
+ "use strict";var __extends=this&&this.__extends||function(){var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},t(e,r)};return function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),__decorate=this&&this.__decorate||function(t,e,r,n){var i,o=arguments.length,a=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,r,n);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(a=(o<3?i(a):o>3?i(e,r,a):i(e,r))||a);return o>3&&a&&Object.defineProperty(e,r,a),a},__awaiter=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function a(t){try{c(n.next(t))}catch(t){o(t)}}function s(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,s)}c((n=n.apply(t,e||[])).next())}))},__generator=this&&this.__generator||function(t,e){var r,n,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(s){return function(c){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){a.label=s[1];break}if(6===s[0]&&a.label<i[1]){a.label=i[1],i=s;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(s);break}i[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],n=0}finally{r=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.OrganizationService=void 0;var rxjs_1=require("rxjs"),operators_1=require("rxjs/operators"),injection_identifier_1=require("../decorators/injection-identifier"),organization_1=require("../models/organization"),base_service_1=require("./base.service"),https_service_interface_1=require("./http/https.service.interface"),OrganizationService=function(t){function e(e){var r=t.call(this,e)||this;return r.organizations$=new rxjs_1.ReplaySubject(1),r}return __extends(e,t),e.prototype.onCreate=function(){this.httpsService=this.serviceProvider.getService(https_service_interface_1.HttpsService)},e.prototype.init=function(){return __awaiter(this,void 0,void 0,(function(){var t;return __generator(this,(function(e){switch(e.label){case 0:return console.log("OrganizationService - init"),[4,this.getOrganizationsRequest()];case 1:return t=e.sent(),this.organizations$.next(t.map((function(t){return new organization_1.Organization(t)}))),console.log("..initialized organization.service (organizations: ".concat(t.length,")")),[2]}}))}))},e.prototype.getOrganizations=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){return[2,this.organizations$.pipe((0,operators_1.take)(1)).toPromise()]}))}))},e.prototype.getFirstOrganization=function(){return __awaiter(this,void 0,void 0,(function(){var t;return __generator(this,(function(e){switch(e.label){case 0:return[4,this.getOrganizations()];case 1:return[2,(t=e.sent()).find((function(t){return!t.requiresAdditionalAuthentication}))||t[0]]}}))}))},e.prototype.getOrganization=function(t){return __awaiter(this,arguments,void 0,(function(t,e){return void 0===e&&(e=!1),__generator(this,(function(r){return[2,this.httpsService.get("organizations-ui/".concat(t),[{includeSubOrgs:e}],https_service_interface_1.BACKEND_SERVICE.DATA).pipe((0,operators_1.map)((function(t){return organization_1.Organization.fromAPIResponse(t)}))).toPromise()]}))}))},e.prototype.getOrganizationsByRoles=function(t){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(e){return[2,this.httpsService.get("organizations",[{roles:t.join(",")}],https_service_interface_1.BACKEND_SERVICE.DATA).pipe((0,operators_1.map)((function(t){return(t.results||[]).map((function(t){return organization_1.Organization.fromAPIResponse(t)}))}))).toPromise()]}))}))},e.prototype.getOrganizationsListByRoles=function(t,e){var r=this;void 0===e&&(e=1e3);var n="organizations-list";return this.httpsService.get(n,[{roles:t.join(","),page_size:e}],https_service_interface_1.BACKEND_SERVICE.DATA).pipe((0,operators_1.expand)((function(i){var o=!(!i.pagination||!i.pagination.next),a=parseInt(i.pagination.page)+1;return o?r.httpsService.get(n,[{roles:t.join(","),page_size:e,page:a}],https_service_interface_1.BACKEND_SERVICE.DATA):rxjs_1.EMPTY})),(0,operators_1.reduce)((function(t,e){return t.concat(e.results)}),[]),(0,operators_1.takeWhile)((function(t){return null!==t}),!0),(0,operators_1.map)((function(t){return(t||[]).map((function(t){return organization_1.Organization.fromAPIResponse(t)}))})))},e.prototype.getOrganizationsRequest=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){return[2,this.httpsService.get("organizations-ui",[{includeSubOrgs:!0}],https_service_interface_1.BACKEND_SERVICE.DATA).pipe((0,operators_1.map)((function(t){return t.map((function(t){return organization_1.Organization.fromAPIResponse(t)}))}))).toPromise()]}))}))},e=__decorate([(0,injection_identifier_1.InjectionIdentifier)("OrganizationService")],e)}(base_service_1.BaseService);exports.OrganizationService=OrganizationService;
@@ -1,155 +1,2 @@
1
1
  // Copyright © 2022-2025 Partium, Inc. DBA Partium
2
- "use strict";
3
- var __assign = (this && this.__assign) || function () {
4
- __assign = Object.assign || function(t) {
5
- for (var s, i = 1, n = arguments.length; i < n; i++) {
6
- s = arguments[i];
7
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
8
- t[p] = s[p];
9
- }
10
- return t;
11
- };
12
- return __assign.apply(this, arguments);
13
- };
14
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
15
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
16
- if (ar || !(i in from)) {
17
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
18
- ar[i] = from[i];
19
- }
20
- }
21
- return to.concat(ar || Array.prototype.slice.call(from));
22
- };
23
- Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.PaginatedRequestServiceImpl = void 0;
25
- var rxjs_1 = require("rxjs");
26
- var operators_1 = require("rxjs/operators");
27
- var error_1 = require("../models/error");
28
- var https_service_interface_1 = require("./http/https.service.interface");
29
- var paginated_list_1 = require("../models/paginated-list");
30
- var PaginatedRequestServiceImpl = /** @class */ (function () {
31
- function PaginatedRequestServiceImpl(createObject, httpsService, url, backendService, urlParams, pageSize, cursorPaginationEnabled) {
32
- if (backendService === void 0) { backendService = https_service_interface_1.BACKEND_SERVICE.DATA; }
33
- if (urlParams === void 0) { urlParams = []; }
34
- if (pageSize === void 0) { pageSize = 25; }
35
- if (cursorPaginationEnabled === void 0) { cursorPaginationEnabled = false; }
36
- this.pageSize = -1;
37
- this.concatResult = true;
38
- this.initialPageLoaded = false; // becomes true as soon as the first page of items has finished loading
39
- this.pageLoading = false;
40
- this.cursorPaginationEnabled = false;
41
- this.createObject = createObject;
42
- this.httpsService = httpsService;
43
- this.url = url;
44
- this.backendService = backendService;
45
- this.pageSize = pageSize;
46
- this.cursorPaginationEnabled = cursorPaginationEnabled;
47
- this.urlParams = __spreadArray(__spreadArray([], urlParams, true), [
48
- {
49
- page_size: this.pageSize,
50
- },
51
- ], false);
52
- }
53
- PaginatedRequestServiceImpl.prototype.loadInitialPage = function (concatResult) {
54
- var _this = this;
55
- if (concatResult === void 0) { concatResult = true; }
56
- this.concatResult = concatResult;
57
- return this.loadPage(1).pipe((0, operators_1.tap)(function () { return (_this.initialPageLoaded = true); }));
58
- };
59
- PaginatedRequestServiceImpl.prototype.getPaginatedList = function (concatResult) {
60
- if (concatResult === void 0) { concatResult = true; }
61
- return this.loadInitialPage(concatResult);
62
- };
63
- PaginatedRequestServiceImpl.prototype.getLoadedPaginatedList = function () {
64
- return this.paginatedList;
65
- };
66
- PaginatedRequestServiceImpl.prototype.isInitialPageLoaded = function () {
67
- return (this.initialPageLoaded &&
68
- this.paginatedList &&
69
- (this.paginatedList.currentPageIdx >= 1 || (this.paginatedList.items.length >= 0 && this.cursorPaginationEnabled)));
70
- };
71
- PaginatedRequestServiceImpl.prototype.isPageLoading = function () {
72
- return this.pageLoading;
73
- };
74
- PaginatedRequestServiceImpl.prototype.hasMoreResultsAvailable = function () {
75
- if (this.cursorPaginationEnabled) {
76
- return this.paginatedList && !!this.paginatedList.nextPage;
77
- }
78
- return this.paginatedList && this.paginatedList.moreResultsAvailable();
79
- };
80
- PaginatedRequestServiceImpl.prototype.loadMore = function () {
81
- if (this.cursorPaginationEnabled) {
82
- var url = new URL(this.paginatedList.nextPage);
83
- var urlParams = new URLSearchParams(url.search);
84
- var cursor = urlParams.get('cursor');
85
- this.urlParams = this.removeUrlParam(this.urlParams, 'cursor');
86
- this.urlParams = __spreadArray(__spreadArray([], this.urlParams, true), [{ cursor: cursor }], false);
87
- return this.loadPage(null);
88
- }
89
- if (!this.isInitialPageLoaded()) {
90
- // no search active/initial result not yet returned
91
- return (0, rxjs_1.throwError)(new error_1.SdkError(error_1.SDK_ERROR_CODES.INITIAL_ITEMS_NOT_YET_LOADED, null));
92
- }
93
- else if (this.paginatedList.currentPageIdx >= this.paginatedList.totalPages) {
94
- // can't load more pages, end reached
95
- return (0, rxjs_1.throwError)(new error_1.SdkError(error_1.SDK_ERROR_CODES.NO_MORE_ITEMS_AVAILABLE, null, 'can not load more items, last page reached'));
96
- }
97
- else {
98
- return this.loadPage(this.paginatedList.currentPageIdx + 1);
99
- }
100
- };
101
- PaginatedRequestServiceImpl.prototype.loadPage = function (pageIdx) {
102
- var _this = this;
103
- return (0, rxjs_1.of)(undefined).pipe((0, operators_1.tap)(function () {
104
- _this.pageLoading = true;
105
- }), (0, operators_1.mergeMap)(function () {
106
- return _this.fetchPaginatedListFromServer(pageIdx).pipe((0, operators_1.catchError)(function (error) {
107
- _this.pageLoading = false;
108
- console.log('Error while loading items from server.', error);
109
- return (0, rxjs_1.throwError)(error);
110
- }));
111
- }), (0, operators_1.tap)(function () {
112
- _this.pageLoading = false;
113
- }), (0, operators_1.map)(function (list) {
114
- if (_this.concatResult && _this.paginatedList && list) {
115
- return _this.concatenateItems(_this.paginatedList, list);
116
- }
117
- else {
118
- return list;
119
- }
120
- }), (0, operators_1.tap)(function (list) {
121
- // we assign a cloned list for the state to avoid manipulation from outside
122
- _this.paginatedList = list.clone();
123
- }));
124
- };
125
- /**
126
- * Fetch page of paginated list from server
127
- *
128
- * @param pageIdx which page to fetch
129
- * @returns Observable that resolves with the PaginatedList object of the requested page
130
- */
131
- PaginatedRequestServiceImpl.prototype.fetchPaginatedListFromServer = function (pageIdx) {
132
- var _this = this;
133
- return this.httpsService
134
- .get(this.url, __spreadArray(__spreadArray([], this.urlParams, true), [
135
- __assign({}, (!!this.cursorPaginationEnabled ? { paginator: 'cursor' } : { page: pageIdx })),
136
- ], false), this.backendService)
137
- .pipe((0, operators_1.map)(function (res) {
138
- var items = res['results'].map(function (resItem) { return _this.createObject(resItem); });
139
- var list = new paginated_list_1.PaginatedList(items, pageIdx || undefined, !!res['pagination']['items_count'] || res['pagination']['items_count'] === 0
140
- ? Math.ceil(res['pagination']['items_count'] / _this.pageSize)
141
- : undefined, _this.pageSize, res['pagination']['next'] || undefined, res['pagination']['previous'] || undefined, _this.cursorPaginationEnabled);
142
- return list;
143
- }));
144
- };
145
- PaginatedRequestServiceImpl.prototype.concatenateItems = function (oldList, newList) {
146
- newList.items = oldList.items.concat(newList.items);
147
- return newList;
148
- };
149
- PaginatedRequestServiceImpl.prototype.removeUrlParam = function (urlParams, paramToRemove) {
150
- return urlParams.filter(function (urlParam) { return !urlParam[paramToRemove]; });
151
- };
152
- return PaginatedRequestServiceImpl;
153
- }());
154
- exports.PaginatedRequestServiceImpl = PaginatedRequestServiceImpl;
155
- //# sourceMappingURL=paginated-request.service.js.map
2
+ "use strict";var __assign=this&&this.__assign||function(){return __assign=Object.assign||function(t){for(var e,r=1,i=arguments.length;r<i;r++)for(var a in e=arguments[r])Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t},__assign.apply(this,arguments)},__spreadArray=this&&this.__spreadArray||function(t,e,r){if(r||2===arguments.length)for(var i,a=0,n=e.length;a<n;a++)!i&&a in e||(i||(i=Array.prototype.slice.call(e,0,a)),i[a]=e[a]);return t.concat(i||Array.prototype.slice.call(e))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaginatedRequestServiceImpl=void 0;var rxjs_1=require("rxjs"),operators_1=require("rxjs/operators"),error_1=require("../models/error"),https_service_interface_1=require("./http/https.service.interface"),paginated_list_1=require("../models/paginated-list"),PaginatedRequestServiceImpl=function(){function t(t,e,r,i,a,n,s){void 0===i&&(i=https_service_interface_1.BACKEND_SERVICE.DATA),void 0===a&&(a=[]),void 0===n&&(n=25),void 0===s&&(s=!1),this.pageSize=-1,this.concatResult=!0,this.initialPageLoaded=!1,this.pageLoading=!1,this.cursorPaginationEnabled=!1,this.createObject=t,this.httpsService=e,this.url=r,this.backendService=i,this.pageSize=n,this.cursorPaginationEnabled=s,this.urlParams=__spreadArray(__spreadArray([],a,!0),[{page_size:this.pageSize}],!1)}return t.prototype.loadInitialPage=function(t){var e=this;return void 0===t&&(t=!0),this.concatResult=t,this.loadPage(1).pipe((0,operators_1.tap)((function(){return e.initialPageLoaded=!0})))},t.prototype.getPaginatedList=function(t){return void 0===t&&(t=!0),this.loadInitialPage(t)},t.prototype.getLoadedPaginatedList=function(){return this.paginatedList},t.prototype.isInitialPageLoaded=function(){return this.initialPageLoaded&&this.paginatedList&&(this.paginatedList.currentPageIdx>=1||this.paginatedList.items.length>=0&&this.cursorPaginationEnabled)},t.prototype.isPageLoading=function(){return this.pageLoading},t.prototype.hasMoreResultsAvailable=function(){return this.cursorPaginationEnabled?this.paginatedList&&!!this.paginatedList.nextPage:this.paginatedList&&this.paginatedList.moreResultsAvailable()},t.prototype.loadMore=function(){if(this.cursorPaginationEnabled){var t=new URL(this.paginatedList.nextPage),e=new URLSearchParams(t.search).get("cursor");return this.urlParams=this.removeUrlParam(this.urlParams,"cursor"),this.urlParams=__spreadArray(__spreadArray([],this.urlParams,!0),[{cursor:e}],!1),this.loadPage(null)}return this.isInitialPageLoaded()?this.paginatedList.currentPageIdx>=this.paginatedList.totalPages?(0,rxjs_1.throwError)(new error_1.SdkError(error_1.SDK_ERROR_CODES.NO_MORE_ITEMS_AVAILABLE,null,"can not load more items, last page reached")):this.loadPage(this.paginatedList.currentPageIdx+1):(0,rxjs_1.throwError)(new error_1.SdkError(error_1.SDK_ERROR_CODES.INITIAL_ITEMS_NOT_YET_LOADED,null))},t.prototype.loadPage=function(t){var e=this;return(0,rxjs_1.of)(void 0).pipe((0,operators_1.tap)((function(){e.pageLoading=!0})),(0,operators_1.mergeMap)((function(){return e.fetchPaginatedListFromServer(t).pipe((0,operators_1.catchError)((function(t){return e.pageLoading=!1,console.log("Error while loading items from server.",t),(0,rxjs_1.throwError)(t)})))})),(0,operators_1.tap)((function(){e.pageLoading=!1})),(0,operators_1.map)((function(t){return e.concatResult&&e.paginatedList&&t?e.concatenateItems(e.paginatedList,t):t})),(0,operators_1.tap)((function(t){e.paginatedList=t.clone()})))},t.prototype.fetchPaginatedListFromServer=function(t){var e=this;return this.httpsService.get(this.url,__spreadArray(__spreadArray([],this.urlParams,!0),[__assign({},this.cursorPaginationEnabled?{paginator:"cursor"}:{page:t})],!1),this.backendService).pipe((0,operators_1.map)((function(r){var i=r.results.map((function(t){return e.createObject(t)}));return new paginated_list_1.PaginatedList(i,t||void 0,r.pagination.items_count||0===r.pagination.items_count?Math.ceil(r.pagination.items_count/e.pageSize):void 0,e.pageSize,r.pagination.next||void 0,r.pagination.previous||void 0,e.cursorPaginationEnabled)})))},t.prototype.concatenateItems=function(t,e){return e.items=t.items.concat(e.items),e},t.prototype.removeUrlParam=function(t,e){return t.filter((function(t){return!t[e]}))},t}();exports.PaginatedRequestServiceImpl=PaginatedRequestServiceImpl;