@veloceapps/api 8.0.0-195 → 8.0.0-197

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.
@@ -3,13 +3,13 @@ import { HttpParams, HttpHeaders, HttpErrorResponse, HttpClientModule } from '@a
3
3
  import * as i0 from '@angular/core';
4
4
  import { Injectable, NgModule } from '@angular/core';
5
5
  import * as i1 from '@veloceapps/core';
6
- import { uiDefinitionFromDTO, ConfigurationContextMode, isLegacyDocumentTemplate, DocxTemplater, QuoteDraft, StringUtils, Expression, toLatestFlow, isDefined, Operator, ModelTranslatorUtils, ProductModelsContainer, ModelUtils, EntityUtil, RuleGroupTypes, parseJsonSafely, uiDefinitionToDTO, BaseHttpService, XrayService } from '@veloceapps/core';
6
+ import { uiDefinitionFromDTO, ConfigurationContextMode, isLegacyDocumentTemplate, DocxTemplater, QuoteDraft, StringUtils, Expression, toLatestFlow, isDefined, Operator, isApexError, isCanvasError, ModelTranslatorUtils, ProductModelsContainer, ModelUtils, EntityUtil, RuleGroupTypes, parseJsonSafely, uiDefinitionToDTO, BaseHttpService, XrayService } from '@veloceapps/core';
7
7
  import { noop, throwError, of, zip, forkJoin, map as map$1, from, catchError as catchError$1, switchMap as switchMap$1 } from 'rxjs';
8
8
  import { map, catchError, tap, switchMap, defaultIfEmpty } from 'rxjs/operators';
9
- import * as i2 from 'primeng/api';
9
+ import * as i1$2 from 'primeng/api';
10
10
  import { CurrencyPipe } from '@angular/common';
11
11
  import * as _ from 'lodash';
12
- import { omit } from 'lodash';
12
+ import { isArray, omit } from 'lodash';
13
13
  import moment from 'moment';
14
14
 
15
15
  class AccountApiService {
@@ -630,11 +630,11 @@ class ConfigurationSettingsApiService {
630
630
  });
631
631
  }
632
632
  }
633
- ConfigurationSettingsApiService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationSettingsApiService, deps: [{ token: i1.BaseHttpService }, { token: i2.MessageService }], target: i0.ɵɵFactoryTarget.Injectable });
633
+ ConfigurationSettingsApiService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationSettingsApiService, deps: [{ token: i1.BaseHttpService }, { token: i1$2.MessageService }], target: i0.ɵɵFactoryTarget.Injectable });
634
634
  ConfigurationSettingsApiService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationSettingsApiService });
635
635
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ConfigurationSettingsApiService, decorators: [{
636
636
  type: Injectable
637
- }], ctorParameters: function () { return [{ type: i1.BaseHttpService }, { type: i2.MessageService }]; } });
637
+ }], ctorParameters: function () { return [{ type: i1.BaseHttpService }, { type: i1$2.MessageService }]; } });
638
638
 
639
639
  class ContextApiService {
640
640
  constructor(httpService) {
@@ -1552,11 +1552,53 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1552
1552
  type: Injectable
1553
1553
  }], ctorParameters: function () { return [{ type: i1.BaseHttpService }]; } });
1554
1554
 
1555
+ /**
1556
+ * Parses the response from Canvas and checks for errors.
1557
+ * - If an error is found, publishes an error message and returns the failover value.
1558
+ * - If no error is found, returns the parsed response.
1559
+ *
1560
+ * Note! The API call first goes to APEX before reaching the Canvas, so errors can originate from either APEX or Canvas.
1561
+ *
1562
+ * @param {string} response - The JSON string response from the Canvas call.
1563
+ * @param {T} failover - The value to return in case of error.
1564
+ * @returns {T | K} The parsed response or the failover value.
1565
+ *
1566
+ * @template T The expected type of the parsed response.
1567
+ * @template K The type of the failover value.
1568
+ *
1569
+ * @remarks If there's an Apex error, the response data can be an array.
1570
+ * In such cases, the function extracts the first element of the array.
1571
+ */
1572
+ const handleCanvasResponse = (response, failover, errorPublisher) => {
1573
+ const parsed = JSON.parse(response);
1574
+ const errorCandidate = isArray(parsed) ? parsed[0] : parsed;
1575
+ if (isApexError(errorCandidate)) {
1576
+ errorPublisher(errorCandidate.message);
1577
+ return failover;
1578
+ }
1579
+ if (isCanvasError(errorCandidate)) {
1580
+ errorPublisher(errorCandidate.error);
1581
+ return failover;
1582
+ }
1583
+ return parsed;
1584
+ };
1585
+
1555
1586
  class OrgInfoApiService {
1587
+ constructor(messageService) {
1588
+ this.messageService = messageService;
1589
+ /**
1590
+ * Shows an error message using the message service.
1591
+ *
1592
+ * @param {string} message - the error message to be published.
1593
+ */
1594
+ this.publishErrorMessage = (message) => {
1595
+ this.messageService.add({ severity: 'error', summary: message, sticky: true });
1596
+ };
1597
+ }
1556
1598
  getOrgInfo$() {
1557
1599
  try {
1558
1600
  return window.doCanvasCall && window.ORGANIZATION_ID
1559
- ? from(window.doCanvasCall(`org-info/${window.ORGANIZATION_ID}`)).pipe(map$1(data => JSON.parse(data)), catchError$1(() => of(undefined)))
1601
+ ? from(window.doCanvasCall(`org-info/${window.ORGANIZATION_ID}`, null)).pipe(map$1(response => handleCanvasResponse(response, undefined, this.publishErrorMessage)), catchError$1(() => of(undefined)))
1560
1602
  : of(undefined);
1561
1603
  }
1562
1604
  catch {
@@ -1566,7 +1608,7 @@ class OrgInfoApiService {
1566
1608
  getAvailableVersionsInfo$() {
1567
1609
  try {
1568
1610
  return window.doCanvasCall && window.ORGANIZATION_ID
1569
- ? from(window.doCanvasCall('versions/available', 'include_all=true')).pipe(map$1(data => JSON.parse(data)), catchError$1(() => of(undefined)))
1611
+ ? from(window.doCanvasCall('versions/available', 'include_all=true')).pipe(map$1(response => handleCanvasResponse(response, undefined, this.publishErrorMessage)), catchError$1(() => of(undefined)))
1570
1612
  : of(undefined);
1571
1613
  }
1572
1614
  catch {
@@ -1576,7 +1618,7 @@ class OrgInfoApiService {
1576
1618
  upgradeVersion$(targetVersion) {
1577
1619
  try {
1578
1620
  return window.doCanvasCall && window.ORGANIZATION_ID
1579
- ? from(window.doCanvasCall('versions/upgrade', `target_version=${targetVersion}`)).pipe(map$1(data => JSON.parse(data)), catchError$1(() => of(undefined)))
1621
+ ? from(window.doCanvasCall('versions/upgrade', `target_version=${targetVersion}`)).pipe(map$1(response => handleCanvasResponse(response, undefined, this.publishErrorMessage)), catchError$1(() => of(undefined)))
1580
1622
  : of(undefined);
1581
1623
  }
1582
1624
  catch {
@@ -1584,11 +1626,11 @@ class OrgInfoApiService {
1584
1626
  }
1585
1627
  }
1586
1628
  }
1587
- OrgInfoApiService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: OrgInfoApiService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1629
+ OrgInfoApiService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: OrgInfoApiService, deps: [{ token: i1$2.MessageService }], target: i0.ɵɵFactoryTarget.Injectable });
1588
1630
  OrgInfoApiService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: OrgInfoApiService });
1589
1631
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: OrgInfoApiService, decorators: [{
1590
1632
  type: Injectable
1591
- }] });
1633
+ }], ctorParameters: function () { return [{ type: i1$2.MessageService }]; } });
1592
1634
 
1593
1635
  class PicklistsApiService {
1594
1636
  constructor(baseHttpService) {
@@ -3262,68 +3304,93 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
3262
3304
  }], ctorParameters: function () { return [{ type: i1.BaseHttpService }]; } });
3263
3305
 
3264
3306
  class SandboxManagerApiService {
3265
- constructor(http) {
3266
- this.http = http;
3267
- this.TOKEN_HEADER = `signed_request=${encodeURIComponent(window.SANDBOX_TOKEN ?? '')}` ?? '';
3268
- this.SANDBOX_URL_FALLBACK = 'https://sandbox-manager.velocecpq.com';
3269
- this.hostUrl = `${window.VELO_SANDBOX_API ?? this.SANDBOX_URL_FALLBACK}/clients`;
3307
+ constructor(messageService) {
3308
+ this.messageService = messageService;
3309
+ /**
3310
+ * Shows an error message using the message service.
3311
+ *
3312
+ * @param {string} message - the error message to be published.
3313
+ */
3314
+ this.publishErrorMessage = (message) => {
3315
+ this.messageService.add({ severity: 'error', summary: message, sticky: true });
3316
+ };
3270
3317
  }
3271
3318
  getSalesforceOrganizations$() {
3272
- return this.http.get(`${this.hostUrl}/${window.VELO_CLIENT}/orgs`, {
3273
- headers: {
3274
- 'Veloce-Token': this.TOKEN_HEADER,
3275
- },
3276
- });
3319
+ try {
3320
+ return window.doSandboxCall
3321
+ ? from(window.doSandboxCall('orgs', '', 'GET')).pipe(map$1(response => handleCanvasResponse(response, [], this.publishErrorMessage)), catchError$1(() => of([])))
3322
+ : of([]);
3323
+ }
3324
+ catch {
3325
+ return of([]);
3326
+ }
3277
3327
  }
3278
3328
  getAvailableSalesforceOrganizationSizes$() {
3279
- return this.http.get(`${this.hostUrl}/${window.VELO_CLIENT}/available-sizes`, {
3280
- headers: {
3281
- 'Veloce-Token': this.TOKEN_HEADER,
3282
- },
3283
- });
3329
+ try {
3330
+ return window.doSandboxCall
3331
+ ? from(window.doSandboxCall('available-sizes', '', 'GET')).pipe(map$1(response => handleCanvasResponse(response, {}, this.publishErrorMessage)), catchError$1(() => of({})))
3332
+ : of({});
3333
+ }
3334
+ catch {
3335
+ return of({});
3336
+ }
3284
3337
  }
3285
3338
  createSalesforceOrganization$(payload) {
3286
- return this.http.post(`${this.hostUrl}/${window.VELO_CLIENT}/orgs`, payload, {
3287
- headers: {
3288
- 'Veloce-Token': this.TOKEN_HEADER,
3289
- },
3290
- });
3339
+ try {
3340
+ return window.doSandboxCall
3341
+ ? from(window.doSandboxCall('orgs', JSON.stringify(payload), 'POST')).pipe(map$1(response => handleCanvasResponse(response, undefined, this.publishErrorMessage)), catchError$1(() => of(undefined)))
3342
+ : of(undefined);
3343
+ }
3344
+ catch (err) {
3345
+ return of(undefined);
3346
+ }
3291
3347
  }
3292
3348
  updateSalesforceOrganization$(payload) {
3293
- return this.http.post(`${this.hostUrl}/${window.VELO_CLIENT}/orgs/${payload.orgId}`, payload, {
3294
- headers: {
3295
- 'Veloce-Token': this.TOKEN_HEADER,
3296
- },
3297
- });
3349
+ try {
3350
+ return window.doSandboxCall
3351
+ ? from(window.doSandboxCall(`orgs/${payload.orgId}`, JSON.stringify(payload), 'POST')).pipe(map$1(response => handleCanvasResponse(response, undefined, this.publishErrorMessage)), catchError$1(() => of(undefined)))
3352
+ : of(undefined);
3353
+ }
3354
+ catch {
3355
+ return of(undefined);
3356
+ }
3298
3357
  }
3299
3358
  deleteSalesforceOrganization$(payload) {
3300
- return this.http.delete(`${this.hostUrl}/${window.VELO_CLIENT}/orgs/${payload.orgId}`, {
3301
- headers: {
3302
- 'Veloce-Token': this.TOKEN_HEADER,
3303
- },
3304
- });
3359
+ try {
3360
+ return window.doSandboxCall
3361
+ ? from(window.doSandboxCall(`orgs/${payload.orgId}`, '', 'DELETE')).pipe(map$1(response => handleCanvasResponse(response, undefined, this.publishErrorMessage)), catchError$1(() => of(undefined)))
3362
+ : of(undefined);
3363
+ }
3364
+ catch {
3365
+ return of(undefined);
3366
+ }
3305
3367
  }
3306
3368
  activateSalesforceOrganization$(payload) {
3307
- return this.http.post(`${this.hostUrl}/${window.VELO_CLIENT}/orgs/${payload.orgId}/activate`, {}, {
3308
- headers: {
3309
- 'Veloce-Token': this.TOKEN_HEADER,
3310
- },
3311
- });
3369
+ try {
3370
+ return window.doSandboxCall
3371
+ ? from(window.doSandboxCall(`orgs/${payload.orgId}/activate`, JSON.stringify({}), 'POST')).pipe(map$1(response => handleCanvasResponse(response, undefined, this.publishErrorMessage)), catchError$1(() => of(undefined)))
3372
+ : of(undefined);
3373
+ }
3374
+ catch {
3375
+ return of(undefined);
3376
+ }
3312
3377
  }
3313
3378
  deactivateSalesforceOrganization$(payload) {
3314
- return this.http.post(`${this.hostUrl}/${window.VELO_CLIENT}/orgs/${payload.orgId}/deactivate`, {}, {
3315
- headers: {
3316
- 'Veloce-Token': this.TOKEN_HEADER,
3317
- },
3318
- });
3379
+ try {
3380
+ return window.doSandboxCall
3381
+ ? from(window.doSandboxCall(`orgs/${payload.orgId}/deactivate`, JSON.stringify({}), 'POST')).pipe(map$1(response => handleCanvasResponse(response, undefined, this.publishErrorMessage)), catchError$1(() => of(undefined)))
3382
+ : of(undefined);
3383
+ }
3384
+ catch {
3385
+ return of(undefined);
3386
+ }
3319
3387
  }
3320
3388
  }
3321
- SandboxManagerApiService.MAX_RESULTS = 60;
3322
- SandboxManagerApiService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SandboxManagerApiService, deps: [{ token: i1$1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
3389
+ SandboxManagerApiService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SandboxManagerApiService, deps: [{ token: i1$2.MessageService }], target: i0.ɵɵFactoryTarget.Injectable });
3323
3390
  SandboxManagerApiService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SandboxManagerApiService });
3324
3391
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: SandboxManagerApiService, decorators: [{
3325
3392
  type: Injectable
3326
- }], ctorParameters: function () { return [{ type: i1$1.HttpClient }]; } });
3393
+ }], ctorParameters: function () { return [{ type: i1$2.MessageService }]; } });
3327
3394
 
3328
3395
  class ApiModule {
3329
3396
  }