@partium/js-sdk 14.4.0 → 14.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/catalog/index.js +1 -21
- package/catalog/models/catalog-image-info.js +1 -22
- package/catalog/models/catalog-image.js +1 -40
- package/catalog/models/upsert-catalog-images-dto.js +1 -3
- package/catalog/models/upsert-images-result.js +1 -3
- package/catalog/services/images.service.js +1 -62
- package/core/constants/constants.d.ts +1 -0
- package/core/constants/constants.js +1 -16
- package/core/decorators/injection-identifier.js +1 -19
- package/core/factories/paginated-request-service.factory.js +1 -33
- package/core/index.js +1 -63
- package/core/integration-defaults/http/fetch-api-http-error-helper.js +1 -129
- package/core/integration-defaults/http/file-transfer/axios-file-transfer.service.js +1 -138
- package/core/integration-defaults/http/file-transfer/fetch-api-file-transfer.service.js +1 -210
- package/core/integration-defaults/http/handle-axios-error-helper.js +1 -79
- package/core/integration-defaults/http/https-client/axios-https-client.service.js +1 -182
- package/core/integration-defaults/http/https-client/fetch-api-https-client.service.js +1 -198
- package/core/integration-defaults/http/js-oauth-keycloak-https.service.js +1 -32
- package/core/integration-defaults/js-p-file.js +1 -36
- package/core/integration-defaults/session/js-oauth-api-key-session.service.js +1 -206
- package/core/integration-defaults/session/js-oauth-keycloak-auth-config.js +1 -64
- package/core/integration-defaults/session/js-oauth-keycloak-session.service.js +1 -257
- package/core/integration-defaults/web-device-status.service.js +1 -125
- package/core/integration-defaults/web-file.service.js +1 -135
- package/core/integration-defaults/web-indexeddb.service.js +1 -142
- package/core/integration-defaults/web-local-storage.service.js +1 -310
- package/core/models/api-object.js +1 -16
- package/core/models/auth-config.js +1 -72
- package/core/models/device-info.js +1 -34
- package/core/models/error.js +1 -107
- package/core/models/formatted-string.js +1 -14
- package/core/models/i18n-map.js +1 -61
- package/core/models/i18n-string.js +1 -35
- package/core/models/log.js +1 -137
- package/core/models/organization.js +1 -159
- package/core/models/p-file.js +1 -23
- package/core/models/paginated-list.js +1 -41
- package/core/models/partium-config.js +1 -43
- package/core/models/user-token.js +1 -11
- package/core/models/user.js +1 -89
- package/core/services/backend-status.service.js +1 -147
- package/core/services/base-login-init.service.js +1 -57
- package/core/services/base.service.js +1 -37
- package/core/services/device-status.service.interface.js +1 -117
- package/core/services/file.service.interface.js +1 -61
- package/core/services/http/file-transfer/file-transfer.service.interface.js +1 -125
- package/core/services/http/https-client/https-client.service.interface.js +1 -152
- package/core/services/http/https.service.interface.d.ts +3 -1
- package/core/services/http/https.service.interface.js +1 -294
- package/core/services/http/oauth-https.service.js +1 -218
- package/core/services/local-storage.service.interface.js +1 -378
- package/core/services/log.service.js +1 -139
- package/core/services/organization.service.js +1 -202
- package/core/services/paginated-request.service.js +1 -164
- package/core/services/recent-parts.service.js +1 -194
- package/core/services/service-provider.js +1 -114
- package/core/services/session/oauth-session.service.js +1 -104
- package/core/services/session/session.service.interface.js +1 -367
- package/core/utils/general-helper.js +1 -110
- package/data/index.js +1 -44
- package/data/models/announcement.js +1 -70
- package/data/models/assembly-hierarchy-node-breadcrumb.js +1 -51
- package/data/models/assembly-hierarchy-node.js +1 -46
- package/data/models/attribute.js +1 -106
- package/data/models/csa-request-search.js +1 -46
- package/data/models/csa-request-status.js +1 -51
- package/data/models/csa-request.js +1 -112
- package/data/models/document.js +1 -17
- package/data/models/filter-key.js +1 -36
- package/data/models/filter-option-value.js +1 -41
- package/data/models/image.js +1 -77
- package/data/models/inquiry.js +1 -71
- package/data/models/mounting-location.js +1 -58
- package/data/models/multiple-expert-searches.js +1 -40
- package/data/models/part-enrichment-data.js +1 -50
- package/data/models/part.d.ts +1 -1
- package/data/models/part.js +1 -168
- package/data/models/shopping-cart.js +1 -60
- package/data/services/announcement.service.js +1 -89
- package/data/services/assembly-hierarchy-nodes.service.js +1 -193
- package/data/services/csa-helper.service.js +1 -158
- package/data/services/customer-service-assistance.service.js +1 -276
- package/data/services/filter.service.js +1 -97
- package/data/services/inquiry.service.js +1 -68
- package/data/services/part-attribute.service.js +1 -118
- package/data/services/part-enrichment.service.js +1 -56
- package/data/services/part.service.js +1 -182
- package/data/services/related-parts.service.js +1 -83
- package/data/services/shopping-cart.service.js +1 -152
- package/datacuration/index.d.ts +2 -0
- package/datacuration/index.js +2 -0
- package/datacuration/models/image-submission-request.d.ts +55 -0
- package/datacuration/models/image-submission-request.js +2 -0
- package/datacuration/models/submitted-image-response.d.ts +27 -0
- package/datacuration/models/submitted-image-response.js +2 -0
- package/datacuration/services/image-submission.service.d.ts +26 -0
- package/datacuration/services/image-submission.service.js +2 -0
- package/find/index.js +1 -51
- package/find/models/assets/asset.js +1 -32
- package/find/models/search-filter.js +1 -205
- package/find/models/search-input.js +1 -3
- package/find/models/search-output.js +1 -3
- package/find/models/search-result-status.js +1 -40
- package/find/models/search-session-log-object.js +1 -22
- package/find/models/search-status/cv-search-status.js +1 -22
- package/find/models/search-status/search-filter-status.js +1 -36
- package/find/models/search-status/search-status.js +1 -56
- package/find/models/search-status/tag-search-status.js +1 -23
- package/find/models/search-status/text-search-status.js +1 -18
- package/find/models/search-tag.js +1 -16
- package/find/models/smart-filter.js +1 -49
- package/find/models/tagable/i18n-tagable.js +1 -37
- package/find/models/tagable/tagable-base.js +1 -22
- package/find/models/tagable/tagable.js +1 -37
- package/find/models/text-search-config.js +1 -70
- package/find/models/text-search-manipulator.js +1 -90
- package/find/models/text-search-result-item/text-search-error.js +1 -12
- package/find/models/text-search-result-item/text-search-result-item-document.js +1 -34
- package/find/models/text-search-result-item/text-search-result-item-part.js +1 -36
- package/find/models/text-search-result-item/text-search-result-item-recent-query.js +1 -35
- package/find/models/text-search-result-item/text-search-result-item-unknown.js +1 -38
- package/find/models/text-search-result-item/text-search-result-item.js +1 -22
- package/find/services/asset.service.js +1 -348
- package/find/services/filter-uploaders/filter-uploader.js +1 -3
- package/find/services/filter-uploaders/update-filters-uploader.js +1 -77
- package/find/services/filter-uploaders/update-filters.model.js +1 -7
- package/find/services/search/cv-search.service.js +1 -214
- package/find/services/search/recent-text-search-queries.service.js +1 -260
- package/find/services/search/search-result.service.js +1 -539
- package/find/services/search/search.service.js +1 -514
- package/find/services/search/tag-search.service.js +1 -124
- package/find/services/search/text-search.service.js +1 -316
- package/find/services/search-filter.service.js +1 -292
- package/find/utils/search-helper.js +1 -75
- package/gen/sdk-version.d.ts +1 -1
- package/gen/sdk-version.js +1 -5
- package/index.d.ts +2 -0
- package/index.js +1 -392
- package/management/index.js +1 -21
- package/management/models/api-key-list-response.js +1 -3
- package/management/models/api-key-type.js +1 -9
- package/management/models/api-key.js +1 -3
- package/management/services/api-key.service.js +1 -53
- package/ocr/index.js +1 -20
- package/ocr/models/detect-response.js +1 -3
- package/ocr/models/detected-text-entry.js +1 -3
- package/ocr/services/ocr.service.js +1 -59
- package/package.json +1 -1
- package/user-data/index.js +1 -21
- package/user-data/models/part-with-nullable.js +1 -3
- package/user-data/models/request-list/request-list.js +1 -63
- package/user-data/services/favorite/favorite.service.js +1 -108
- 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,165 +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.isInitialPageLoaded()) {
|
|
82
|
-
return (0, rxjs_1.throwError)(new error_1.SdkError(error_1.SDK_ERROR_CODES.INITIAL_ITEMS_NOT_YET_LOADED, null));
|
|
83
|
-
}
|
|
84
|
-
if (this.cursorPaginationEnabled) {
|
|
85
|
-
// For cursor pagination, check if nextPage is available
|
|
86
|
-
if (!this.paginatedList.nextPage) {
|
|
87
|
-
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'));
|
|
88
|
-
}
|
|
89
|
-
// Use the nextPage URL directly without incrementing pageIdx
|
|
90
|
-
return this.loadPage(this.paginatedList.currentPageIdx);
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
// For regular pagination, check if we are at the last page
|
|
94
|
-
if (this.paginatedList.currentPageIdx >= this.paginatedList.totalPages) {
|
|
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
|
-
return this.loadPage(this.paginatedList.currentPageIdx + 1);
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
PaginatedRequestServiceImpl.prototype.loadPage = function (pageIdx) {
|
|
101
|
-
var _this = this;
|
|
102
|
-
return (0, rxjs_1.of)(undefined).pipe((0, operators_1.tap)(function () {
|
|
103
|
-
_this.pageLoading = true;
|
|
104
|
-
}), (0, operators_1.mergeMap)(function () {
|
|
105
|
-
return _this.fetchPaginatedListFromServer(pageIdx).pipe((0, operators_1.catchError)(function (error) {
|
|
106
|
-
_this.pageLoading = false;
|
|
107
|
-
console.log('Error while loading items from server.', error);
|
|
108
|
-
return (0, rxjs_1.throwError)(error);
|
|
109
|
-
}));
|
|
110
|
-
}), (0, operators_1.tap)(function () {
|
|
111
|
-
_this.pageLoading = false;
|
|
112
|
-
}), (0, operators_1.map)(function (list) {
|
|
113
|
-
if (_this.concatResult && _this.paginatedList && list) {
|
|
114
|
-
return _this.concatenateItems(_this.paginatedList, list);
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
return list;
|
|
118
|
-
}
|
|
119
|
-
}), (0, operators_1.tap)(function (list) {
|
|
120
|
-
// we assign a cloned list for the state to avoid manipulation from outside
|
|
121
|
-
_this.paginatedList = list.clone();
|
|
122
|
-
}));
|
|
123
|
-
};
|
|
124
|
-
/**
|
|
125
|
-
* Fetch page of paginated list from server
|
|
126
|
-
*
|
|
127
|
-
* @param pageIdx which page to fetch
|
|
128
|
-
* @returns Observable that resolves with the PaginatedList object of the requested page
|
|
129
|
-
*/
|
|
130
|
-
PaginatedRequestServiceImpl.prototype.fetchPaginatedListFromServer = function (pageIdx) {
|
|
131
|
-
var _this = this;
|
|
132
|
-
var _a;
|
|
133
|
-
var requestUrl;
|
|
134
|
-
var requestParams;
|
|
135
|
-
if (this.cursorPaginationEnabled && ((_a = this.paginatedList) === null || _a === void 0 ? void 0 : _a.nextPage)) {
|
|
136
|
-
requestUrl = this.paginatedList.nextPage;
|
|
137
|
-
requestParams = [];
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
requestUrl = this.url;
|
|
141
|
-
requestParams = __spreadArray(__spreadArray([], this.urlParams, true), [
|
|
142
|
-
__assign({}, (!!this.cursorPaginationEnabled ? { paginator: 'cursor' } : { page: pageIdx })),
|
|
143
|
-
], false);
|
|
144
|
-
}
|
|
145
|
-
return this.httpsService
|
|
146
|
-
.get(requestUrl, requestParams, this.backendService)
|
|
147
|
-
.pipe((0, operators_1.map)(function (res) {
|
|
148
|
-
var items = res['results'].map(function (resItem) { return _this.createObject(resItem); });
|
|
149
|
-
var list = new paginated_list_1.PaginatedList(items, pageIdx || undefined, !!res['pagination']['items_count'] || res['pagination']['items_count'] === 0
|
|
150
|
-
? Math.ceil(res['pagination']['items_count'] / _this.pageSize)
|
|
151
|
-
: undefined, _this.pageSize, res['pagination']['next'] || undefined, res['pagination']['previous'] || undefined, _this.cursorPaginationEnabled);
|
|
152
|
-
return list;
|
|
153
|
-
}));
|
|
154
|
-
};
|
|
155
|
-
PaginatedRequestServiceImpl.prototype.concatenateItems = function (oldList, newList) {
|
|
156
|
-
newList.items = oldList.items.concat(newList.items);
|
|
157
|
-
return newList;
|
|
158
|
-
};
|
|
159
|
-
PaginatedRequestServiceImpl.prototype.removeUrlParam = function (urlParams, paramToRemove) {
|
|
160
|
-
return urlParams.filter(function (urlParam) { return !urlParam[paramToRemove]; });
|
|
161
|
-
};
|
|
162
|
-
return PaginatedRequestServiceImpl;
|
|
163
|
-
}());
|
|
164
|
-
exports.PaginatedRequestServiceImpl = PaginatedRequestServiceImpl;
|
|
165
|
-
//# 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;
|