@partium/js-sdk 14.0.3 → 14.2.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 (143) 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.d.ts +2 -1
  40. package/core/models/user.js +89 -1
  41. package/core/services/backend-status.service.js +147 -1
  42. package/core/services/base-login-init.service.js +57 -1
  43. package/core/services/base.service.js +37 -1
  44. package/core/services/device-status.service.interface.js +117 -1
  45. package/core/services/file.service.interface.js +61 -1
  46. package/core/services/http/file-transfer/file-transfer.service.interface.js +125 -1
  47. package/core/services/http/https-client/https-client.service.interface.js +152 -1
  48. package/core/services/http/https.service.interface.js +294 -1
  49. package/core/services/http/oauth-https.service.js +218 -1
  50. package/core/services/local-storage.service.interface.js +378 -1
  51. package/core/services/log.service.js +139 -1
  52. package/core/services/organization.service.js +202 -1
  53. package/core/services/paginated-request.service.js +160 -1
  54. package/core/services/recent-parts.service.js +194 -1
  55. package/core/services/service-provider.js +114 -1
  56. package/core/services/session/oauth-session.service.js +104 -1
  57. package/core/services/session/session.service.interface.js +367 -1
  58. package/core/utils/general-helper.js +110 -1
  59. package/data/index.js +44 -1
  60. package/data/models/announcement.js +70 -1
  61. package/data/models/assembly-hierarchy-node-breadcrumb.js +51 -1
  62. package/data/models/assembly-hierarchy-node.js +46 -1
  63. package/data/models/attribute.js +106 -1
  64. package/data/models/csa-request-search.js +46 -1
  65. package/data/models/csa-request-status.js +51 -1
  66. package/data/models/csa-request.js +112 -1
  67. package/data/models/document.js +17 -1
  68. package/data/models/filter-key.js +36 -1
  69. package/data/models/filter-option-value.js +41 -1
  70. package/data/models/image.d.ts +3 -1
  71. package/data/models/image.js +77 -1
  72. package/data/models/inquiry.js +71 -1
  73. package/data/models/mounting-location.js +58 -1
  74. package/data/models/multiple-expert-searches.js +40 -1
  75. package/data/models/part-enrichment-data.js +50 -1
  76. package/data/models/part.js +168 -1
  77. package/data/models/shopping-cart.js +60 -1
  78. package/data/services/announcement.service.js +89 -1
  79. package/data/services/assembly-hierarchy-nodes.service.js +193 -1
  80. package/data/services/csa-helper.service.js +158 -1
  81. package/data/services/customer-service-assistance.service.js +276 -1
  82. package/data/services/filter.service.js +97 -1
  83. package/data/services/inquiry.service.js +68 -1
  84. package/data/services/part-attribute.service.js +118 -1
  85. package/data/services/part-enrichment.service.js +56 -1
  86. package/data/services/part.service.js +182 -1
  87. package/data/services/related-parts.service.js +83 -1
  88. package/data/services/shopping-cart.service.js +152 -1
  89. package/find/index.js +51 -1
  90. package/find/models/assets/asset.js +32 -1
  91. package/find/models/search-filter.js +205 -1
  92. package/find/models/search-input.js +3 -1
  93. package/find/models/search-output.js +3 -1
  94. package/find/models/search-result-status.js +40 -1
  95. package/find/models/search-session-log-object.js +22 -1
  96. package/find/models/search-status/cv-search-status.js +22 -1
  97. package/find/models/search-status/search-filter-status.js +36 -1
  98. package/find/models/search-status/search-status.js +56 -1
  99. package/find/models/search-status/tag-search-status.js +23 -1
  100. package/find/models/search-status/text-search-status.js +18 -1
  101. package/find/models/search-tag.js +16 -1
  102. package/find/models/smart-filter.js +49 -1
  103. package/find/models/tagable/i18n-tagable.js +37 -1
  104. package/find/models/tagable/tagable-base.js +22 -1
  105. package/find/models/tagable/tagable.js +37 -1
  106. package/find/models/text-search-config.js +70 -1
  107. package/find/models/text-search-manipulator.js +90 -1
  108. package/find/models/text-search-result-item/text-search-error.js +12 -1
  109. package/find/models/text-search-result-item/text-search-result-item-document.js +34 -1
  110. package/find/models/text-search-result-item/text-search-result-item-part.js +36 -1
  111. package/find/models/text-search-result-item/text-search-result-item-recent-query.js +35 -1
  112. package/find/models/text-search-result-item/text-search-result-item-unknown.js +38 -1
  113. package/find/models/text-search-result-item/text-search-result-item.js +22 -1
  114. package/find/services/asset.service.js +348 -1
  115. package/find/services/filter-uploaders/filter-uploader.js +3 -1
  116. package/find/services/filter-uploaders/update-filters-uploader.js +77 -1
  117. package/find/services/filter-uploaders/update-filters.model.js +7 -1
  118. package/find/services/search/cv-search.service.js +214 -1
  119. package/find/services/search/recent-text-search-queries.service.js +260 -1
  120. package/find/services/search/search-result.service.js +539 -1
  121. package/find/services/search/search.service.js +514 -1
  122. package/find/services/search/tag-search.service.js +124 -1
  123. package/find/services/search/text-search.service.js +316 -1
  124. package/find/services/search-filter.service.js +292 -1
  125. package/find/utils/search-helper.js +75 -1
  126. package/gen/sdk-version.d.ts +1 -1
  127. package/gen/sdk-version.js +5 -1
  128. package/index.js +392 -1
  129. package/management/index.js +21 -1
  130. package/management/models/api-key-list-response.js +3 -1
  131. package/management/models/api-key-type.js +9 -1
  132. package/management/models/api-key.js +3 -1
  133. package/management/services/api-key.service.js +53 -1
  134. package/ocr/index.js +20 -1
  135. package/ocr/models/detect-response.js +3 -1
  136. package/ocr/models/detected-text-entry.js +3 -1
  137. package/ocr/services/ocr.service.js +59 -1
  138. package/package.json +1 -1
  139. package/user-data/index.js +21 -1
  140. package/user-data/models/part-with-nullable.js +3 -1
  141. package/user-data/models/request-list/request-list.js +63 -1
  142. package/user-data/services/favorite/favorite.service.js +108 -1
  143. package/user-data/services/request-list/request-list.service.js +133 -1
@@ -1,2 +1,140 @@
1
1
  // Copyright © 2022-2025 Partium, Inc. DBA Partium
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;
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
@@ -1,2 +1,203 @@
1
1
  // Copyright © 2022-2025 Partium, Inc. DBA Partium
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;
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
@@ -1,2 +1,161 @@
1
1
  // Copyright © 2022-2025 Partium, Inc. DBA Partium
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=this.paginatedList.nextPage.split("?"),e=new URLSearchParams(t[1]);return this.urlParams=this.removeUrlParam(this.urlParams,"cursor"),this.urlParams=__spreadArray(__spreadArray([],this.urlParams,!0),[{cursor:e.get("cursor")}],!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;
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
+ /* this.paginatedList.nextPage (the BE value) returns :
83
+ http://api.beta.partium.io/v3/assemblies?cursor=cj0xJnA9MzY2OTE2&max_depth=1&page_size=5&paginator=cursor&root_nodes=true
84
+ it does not work because we need:
85
+ https://api.beta.partium.io/1/_data/assemblies?cursor=cj0xJnA9MzY2OTE2&max_depth=1&page_size=5&paginator=cursor&root_nodes=true
86
+ we only need to append the cursor to the current url and not to fetch the whole url returned by the BE
87
+ TODO fix in FND-2382
88
+ */
89
+ var nextPageParams = this.paginatedList.nextPage.split('?');
90
+ var urlParams = new URLSearchParams(nextPageParams[1]);
91
+ this.urlParams = this.removeUrlParam(this.urlParams, 'cursor');
92
+ this.urlParams = __spreadArray(__spreadArray([], this.urlParams, true), [{ cursor: urlParams.get('cursor') }], false);
93
+ return this.loadPage(null);
94
+ }
95
+ if (!this.isInitialPageLoaded()) {
96
+ // no search active/initial result not yet returned
97
+ return (0, rxjs_1.throwError)(new error_1.SdkError(error_1.SDK_ERROR_CODES.INITIAL_ITEMS_NOT_YET_LOADED, null));
98
+ }
99
+ else if (this.paginatedList.currentPageIdx >= this.paginatedList.totalPages) {
100
+ // can't load more pages, end reached
101
+ 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'));
102
+ }
103
+ else {
104
+ return this.loadPage(this.paginatedList.currentPageIdx + 1);
105
+ }
106
+ };
107
+ PaginatedRequestServiceImpl.prototype.loadPage = function (pageIdx) {
108
+ var _this = this;
109
+ return (0, rxjs_1.of)(undefined).pipe((0, operators_1.tap)(function () {
110
+ _this.pageLoading = true;
111
+ }), (0, operators_1.mergeMap)(function () {
112
+ return _this.fetchPaginatedListFromServer(pageIdx).pipe((0, operators_1.catchError)(function (error) {
113
+ _this.pageLoading = false;
114
+ console.log('Error while loading items from server.', error);
115
+ return (0, rxjs_1.throwError)(error);
116
+ }));
117
+ }), (0, operators_1.tap)(function () {
118
+ _this.pageLoading = false;
119
+ }), (0, operators_1.map)(function (list) {
120
+ if (_this.concatResult && _this.paginatedList && list) {
121
+ return _this.concatenateItems(_this.paginatedList, list);
122
+ }
123
+ else {
124
+ return list;
125
+ }
126
+ }), (0, operators_1.tap)(function (list) {
127
+ // we assign a cloned list for the state to avoid manipulation from outside
128
+ _this.paginatedList = list.clone();
129
+ }));
130
+ };
131
+ /**
132
+ * Fetch page of paginated list from server
133
+ *
134
+ * @param pageIdx which page to fetch
135
+ * @returns Observable that resolves with the PaginatedList object of the requested page
136
+ */
137
+ PaginatedRequestServiceImpl.prototype.fetchPaginatedListFromServer = function (pageIdx) {
138
+ var _this = this;
139
+ return this.httpsService
140
+ .get(this.url, __spreadArray(__spreadArray([], this.urlParams, true), [
141
+ __assign({}, (!!this.cursorPaginationEnabled ? { paginator: 'cursor' } : { page: pageIdx })),
142
+ ], false), this.backendService)
143
+ .pipe((0, operators_1.map)(function (res) {
144
+ var items = res['results'].map(function (resItem) { return _this.createObject(resItem); });
145
+ var list = new paginated_list_1.PaginatedList(items, pageIdx || undefined, !!res['pagination']['items_count'] || res['pagination']['items_count'] === 0
146
+ ? Math.ceil(res['pagination']['items_count'] / _this.pageSize)
147
+ : undefined, _this.pageSize, res['pagination']['next'] || undefined, res['pagination']['previous'] || undefined, _this.cursorPaginationEnabled);
148
+ return list;
149
+ }));
150
+ };
151
+ PaginatedRequestServiceImpl.prototype.concatenateItems = function (oldList, newList) {
152
+ newList.items = oldList.items.concat(newList.items);
153
+ return newList;
154
+ };
155
+ PaginatedRequestServiceImpl.prototype.removeUrlParam = function (urlParams, paramToRemove) {
156
+ return urlParams.filter(function (urlParam) { return !urlParam[paramToRemove]; });
157
+ };
158
+ return PaginatedRequestServiceImpl;
159
+ }());
160
+ exports.PaginatedRequestServiceImpl = PaginatedRequestServiceImpl;
161
+ //# sourceMappingURL=paginated-request.service.js.map