@skedulo/pulse-solution-services 0.0.7 → 0.0.9
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/CHANGELOG.md +12 -0
- package/README.md +139 -23
- package/dist/clients/artifact-client.js +1 -1
- package/dist/clients/base-client.js +1 -1
- package/dist/clients/config-var-client.js +1 -1
- package/dist/clients/graphql-client.js +1 -1
- package/dist/constants/graphql-constants.js +1 -0
- package/dist/constants/index.js +1 -1
- package/dist/core/execution-context.js +1 -1
- package/dist/core/execution-options.js +1 -0
- package/dist/core/index.js +1 -1
- package/dist/core/request-header-constants.js +1 -0
- package/dist/index.d.ts +327 -118
- package/dist/interfaces/api-client.js +1 -0
- package/dist/interfaces/index.js +1 -1
- package/dist/interfaces/lock-service-interfaces.js +1 -0
- package/dist/interfaces/locking-service-interfaces.js +1 -0
- package/dist/services/batch-processor/fetching-strategies/cursor-based-fetching-strategy.js +1 -1
- package/dist/services/batch-processor/fetching-strategies/date-based-fetching-strategy.js +1 -1
- package/dist/services/cache/cache-service.js +1 -1
- package/dist/services/graph-batch/configs/graph-batch-config.d.ts +33 -0
- package/dist/services/graph-batch/configs/graph-batch-config.js +1 -0
- package/dist/services/graph-batch/configs/unique-graph-batch-config.d.ts +39 -0
- package/dist/services/graph-batch/configs/unique-graph-batch-config.js +1 -0
- package/dist/services/graph-batch/graph-batch.d.ts +56 -0
- package/dist/services/graph-batch/graph-batch.js +1 -0
- package/dist/services/graph-batch/index.d.ts +5 -0
- package/dist/services/graph-batch/index.js +1 -0
- package/dist/services/graph-batch/pagination-strategy.d.ts +5 -0
- package/dist/services/graph-batch/pagination-strategy.js +1 -0
- package/dist/services/graph-batch/unique-graph-batch.d.ts +28 -0
- package/dist/services/graph-batch/unique-graph-batch.js +1 -0
- package/dist/services/graphql/graphql-query-builder.d.ts +6 -4
- package/dist/services/graphql/graphql-query-builder.js +1 -1
- package/dist/services/graphql/graphql-service.d.ts +20 -13
- package/dist/services/graphql/graphql-service.js +1 -1
- package/dist/services/graphql/queries.d.ts +5 -4
- package/dist/services/graphql/queries.js +1 -1
- package/dist/services/index.js +1 -1
- package/dist/services/lock-service.js +1 -0
- package/dist/services/locking-service.js +1 -0
- package/dist/services/resource-availability/builder/data-service.d.ts +2 -1
- package/dist/services/resource-availability/builder/data-service.js +1 -1
- package/dist/utils/datetime-utils.js +1 -1
- package/package.json +9 -5
- package/yarn.lock +402 -199
- package/dist/constants/tenant-objects.js +0 -1
- package/dist/services/data-service.js +0 -1
- package/dist/services/resource-availability/object-factory.d.ts +0 -13
- package/dist/services/resource-availability/object-factory.js +0 -1
- package/dist/services/resource-availability/resource-availability-service.d.ts +0 -7
- package/dist/services/resource-availability/resource-availability-service.js +0 -1
- package/dist/services/resource-availability/resource-builder.d.ts +0 -16
- package/dist/services/resource-availability/resource-builder.js +0 -1
- package/dist/services/resource-availability/resource-query-service.d.ts +0 -7
- package/dist/services/resource-availability/resource-query-service.js +0 -1
- package/dist/services/resource-availability/resource-validator.d.ts +0 -29
- package/dist/services/resource-availability/resource-validator.js +0 -1
- /package/dist/{interfaces/resource-availability.js → core/base-config.js} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [v0.0.9] - 2025-02-28
|
|
4
|
+
### Added
|
|
5
|
+
- Lock Service, Unique Batch
|
|
6
|
+
|
|
7
|
+
## [v0.0.8] - 2025-02-17
|
|
8
|
+
### Added
|
|
9
|
+
- GraphBatch
|
|
10
|
+
|
|
11
|
+
### Deprecated
|
|
12
|
+
- BatchOrchestrator
|
|
13
|
+
|
|
14
|
+
|
|
3
15
|
## [v0.0.7] - 2025-02-13
|
|
4
16
|
### Added
|
|
5
17
|
- Geo API Client, Geo Service, Resource Builder, Resource Validator
|
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
- [Config Features (Feature Flags) Client](#config-features-feature-flags-client)
|
|
14
14
|
- [Mobile Notification Client](#mobile-notification-client)
|
|
15
15
|
- [Configuration Templates](#configuration-templates)
|
|
16
|
-
- [
|
|
16
|
+
- [Geo API Client](#geo-api-client)
|
|
17
17
|
- [Artifact Client](#artifact-client)
|
|
18
18
|
- [GraphQL Service](#graphql-service)
|
|
19
19
|
- [Query Data](#query-data)
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
- [Resource Validator](#resource-validator)
|
|
26
26
|
- [GeoService](#geoservice)
|
|
27
27
|
- [Batch Service](#batch-service)
|
|
28
|
+
- [Lock Service](#lock-service)
|
|
28
29
|
- [Cache Service](#cache-service)
|
|
29
30
|
- [Logging Utils](#logging-utils)
|
|
30
31
|
|
|
@@ -47,13 +48,22 @@ yarn add @skedulo/pulse-solution-services
|
|
|
47
48
|
|
|
48
49
|
**From a function**
|
|
49
50
|
```javascript
|
|
50
|
-
const context = ExecutionContext.fromContext(
|
|
51
|
+
const context = ExecutionContext.fromContext(skedContext, {
|
|
52
|
+
requestSource: "my-cool-project",
|
|
53
|
+
userAgent: "my-cool-function"
|
|
54
|
+
});
|
|
51
55
|
```
|
|
56
|
+
|
|
57
|
+
The `requestSource` and `userAgent` options are important for observability and debugging, as they set the value for the `X-Skedulo-Source` and `User-Agent` headers that are automatically included in all requests made within this context.
|
|
58
|
+
|
|
52
59
|
**From other execution contexts**
|
|
53
60
|
```javascript
|
|
54
61
|
const context = ExecutionContext.fromCredentials({
|
|
55
62
|
apiServer: user.apiBasePath,
|
|
56
63
|
apiToken: user.accessToken,
|
|
64
|
+
}, {
|
|
65
|
+
requestSource: "my-cool-project",
|
|
66
|
+
userAgent: "my-cool-function"
|
|
57
67
|
});
|
|
58
68
|
```
|
|
59
69
|
Once initialized, the context object provides access to the various services detailed in subsequent sections.
|
|
@@ -95,11 +105,13 @@ const updatedVocabularyItem = await context.vocabularyClient.updateVocabularyIte
|
|
|
95
105
|
#### GraphQL Client
|
|
96
106
|
Executes GraphQL queries and mutations against `/graphql/graphql`.
|
|
97
107
|
```javascript
|
|
98
|
-
const queryResult = await context.graphqlClient.
|
|
108
|
+
const queryResult = await context.graphqlClient.execute(queryString, {readOnly: true});
|
|
99
109
|
```
|
|
100
110
|
|
|
101
111
|
#### Config Variable Client
|
|
112
|
+
|
|
102
113
|
Provides CRUD and search methods for managing configuration variables.
|
|
114
|
+
|
|
103
115
|
```javascript
|
|
104
116
|
// Calls /configuration/extension endpoint to create a configuration var
|
|
105
117
|
await context.configVarClient.create({
|
|
@@ -108,8 +120,12 @@ await context.configVarClient.create({
|
|
|
108
120
|
configType: "plain-text",
|
|
109
121
|
description: "TEST_DESCRIPTION",
|
|
110
122
|
});
|
|
123
|
+
|
|
111
124
|
// Gets a config var
|
|
112
125
|
const config = await context.configVarClient.get('TEST_KEY');
|
|
126
|
+
|
|
127
|
+
// Deletes a config var
|
|
128
|
+
const config = await context.configVarClient.delete('TEST_KEY');
|
|
113
129
|
```
|
|
114
130
|
|
|
115
131
|
#### Org Preferences Client
|
|
@@ -378,12 +394,16 @@ await client.delete(
|
|
|
378
394
|
#### Query data
|
|
379
395
|
```javascript
|
|
380
396
|
// Create a query builder for the Resources object
|
|
381
|
-
const queryBuilder = context.newQueryBuilder(
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
397
|
+
const queryBuilder = context.newQueryBuilder({
|
|
398
|
+
objectName: 'Resources',
|
|
399
|
+
operationName: 'fetchJobWithJobAllocations',
|
|
400
|
+
readOnly: true
|
|
401
|
+
});
|
|
402
|
+
queryBuilder.withFields(['UID', 'Name'])
|
|
403
|
+
.withFilter('IsActive == true')
|
|
404
|
+
.withLimit(1)
|
|
405
|
+
.withOffset(1)
|
|
406
|
+
.withOrderBy('Name ASC');
|
|
387
407
|
// Add a child query for Job Allocations
|
|
388
408
|
queryBuilder.withChildQuery('JobAllocations')
|
|
389
409
|
.withFields(['UID', 'Name'])
|
|
@@ -401,6 +421,9 @@ console.log(queryResult.pageInfo.hasNextPage); // true
|
|
|
401
421
|
console.log(queryResult.endCursor); // Mg==
|
|
402
422
|
console.log(queryResult.endOffset); // 1
|
|
403
423
|
```
|
|
424
|
+
|
|
425
|
+
The `X-Graphql-Operation` header is added to all GraphQL requests and contains the value of `operationName`.
|
|
426
|
+
|
|
404
427
|
#### Update data
|
|
405
428
|
```javascript
|
|
406
429
|
const recordsToUpdate = queryResult.records.map((record) => {
|
|
@@ -409,8 +432,17 @@ const recordsToUpdate = queryResult.records.map((record) => {
|
|
|
409
432
|
Name: record.Name + " - Updated"
|
|
410
433
|
}
|
|
411
434
|
});
|
|
412
|
-
const updateResult = await context.graphqlService.
|
|
435
|
+
const updateResult = await context.graphqlService.mutate({
|
|
436
|
+
objectName: 'Resources',
|
|
437
|
+
operation: GraphqlOperations.UPDATE,
|
|
438
|
+
operationName: 'updateResources',
|
|
439
|
+
records: recordsToUpdate,
|
|
440
|
+
bulkOperation: true // optional
|
|
441
|
+
});
|
|
413
442
|
```
|
|
443
|
+
|
|
444
|
+
The `bulkOperation` and `readOnly` options help optimize large-scale mutations and read-heavy queries. When enabled, they automatically add the `X-Skedulo-Bulk-Operation` (for mutations) and `X-Skedulo-Read-Only` (for queries) headers to improve performance.
|
|
445
|
+
|
|
414
446
|
#### Pagination with offset
|
|
415
447
|
```javascript
|
|
416
448
|
while(queryResult.pageInfo.hasNextPage) {
|
|
@@ -462,7 +494,7 @@ The Resource Validator takes a list of resources and jobs, and determines which
|
|
|
462
494
|
```javascript
|
|
463
495
|
// Fetch jobs using GraphQL
|
|
464
496
|
const jobQueryResult = await context
|
|
465
|
-
.newQueryBuilder(
|
|
497
|
+
.newQueryBuilder({ objectName: "Jobs", operationName: "fetchJobs", readOnly: true })
|
|
466
498
|
.withLimit(2)
|
|
467
499
|
.withFields(TenantObjects.Jobs.Fields)
|
|
468
500
|
.execute();
|
|
@@ -576,27 +608,111 @@ if (suggestions) {
|
|
|
576
608
|
}
|
|
577
609
|
```
|
|
578
610
|
|
|
611
|
+
### Lock Service
|
|
612
|
+
The Lock Service provides a locking mechanism to prevent concurrent execution of critical processes, such as batch jobs. It ensures that only one instance of a process can proceed at a time by using configuration variables with expiration timestamps.
|
|
613
|
+
```javascript
|
|
614
|
+
// Acquire a lock, auto release after 5 minutes
|
|
615
|
+
const lockAcquired = await context.lockService.acquireLock({
|
|
616
|
+
name: 'MY_LOCK',
|
|
617
|
+
ttl: 5 * 60 * 1000, // 5 minutes
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
// Release a lock
|
|
621
|
+
await context.lockService.releaseLock('MY_LOCK');
|
|
622
|
+
```
|
|
623
|
+
|
|
579
624
|
### Batch Service
|
|
580
625
|
The Batch Service offers a flexible and scalable solution for large-scale data processing.
|
|
626
|
+
|
|
627
|
+
#### How to Use
|
|
628
|
+
1. Create a subclass of GraphBatch that encapsulates the specific logic for your batch job.
|
|
629
|
+
2. Override the `start` method to return a configured GraphQLQueryBuilder object. This builder should set up the query fields, filters, and any required ordering.
|
|
630
|
+
3. Override the `execute` method to implement the logic to process each batch of records (e.g., updates, deletes, logging).
|
|
631
|
+
4. Optionally override the `finish` method to perform any final cleanup, such as logging the results or sending notifications.
|
|
632
|
+
5. Run the batch.
|
|
633
|
+
|
|
634
|
+
#### Example
|
|
635
|
+
Below is an example of bulk job update.
|
|
581
636
|
```javascript
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
637
|
+
import {
|
|
638
|
+
GraphBatch,
|
|
639
|
+
GraphqlOperations,
|
|
640
|
+
GraphQLQueryBuilder,
|
|
641
|
+
} from "@skedulo/pulse-solution-services";
|
|
642
|
+
|
|
643
|
+
export class BulkJobUpdate extends GraphBatch {
|
|
644
|
+
public result: string[] = [];
|
|
645
|
+
|
|
646
|
+
// This method is called once at the beginning of the batch process.
|
|
647
|
+
protected async start(): Promise<GraphQLQueryBuilder> {
|
|
648
|
+
const queryBuilder = this.context
|
|
649
|
+
.newQueryBuilder({objectName: "Jobs", operationName: "fetchJobsWithRegion"})
|
|
650
|
+
.withFields(["UID", "Name", "Start"])
|
|
651
|
+
.withOrderBy("Name ASC");
|
|
652
|
+
queryBuilder.withParentQuery("Region").withFields(["UID", "Name"]);
|
|
653
|
+
|
|
654
|
+
return queryBuilder;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// This method is called for each batch of records.
|
|
658
|
+
protected async execute(records: any[]): Promise<void> {
|
|
659
|
+
|
|
660
|
+
const recordsToUpdate = records.map((record) => ({
|
|
661
|
+
UID: record.UID,
|
|
662
|
+
Description: `${record.Name} scheduled for ${new Date(record.Start).toLocaleDateString("en-GB")} in ${record.Region.Name}`,
|
|
663
|
+
}));
|
|
664
|
+
await this.context.graphqlService.mutate({
|
|
665
|
+
objectName: "Jobs",
|
|
666
|
+
operation: GraphqlOperations.UPDATE,
|
|
667
|
+
operationName: "updateJobs",
|
|
668
|
+
records: recordsToUpdate
|
|
669
|
+
});
|
|
670
|
+
this.result.push(...records.map((record) => record.Name));
|
|
671
|
+
}
|
|
590
672
|
|
|
673
|
+
// This method is called once at the end of the batch process.
|
|
674
|
+
protected async finish(): Promise<void> {
|
|
675
|
+
this.context.logger.info(`Processed ${this.result.length} records.`);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
Run the batch
|
|
681
|
+
```javascript
|
|
591
682
|
const context = ExecutionContext.fromCredentials({
|
|
592
683
|
apiServer: user.apiBasePath,
|
|
593
684
|
apiToken: user.user.accessToken,
|
|
594
685
|
});
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
686
|
+
const batch = new BulkJobUpdate(context, {
|
|
687
|
+
batchSize: 10,
|
|
688
|
+
maxBatches: 10,
|
|
689
|
+
strategy: PaginationStrategy.CURSOR,
|
|
690
|
+
delaySeconds: 1,
|
|
691
|
+
});
|
|
692
|
+
await batch.run();
|
|
693
|
+
```
|
|
694
|
+
|
|
695
|
+
#### Unique Batch
|
|
696
|
+
The Unique Batch ensures that only one instance runs at a time. It leverages the Lock Service to prevent concurrent executions. The default lock duration is 16 minutes, configurable via the `lockTtl` setting.
|
|
697
|
+
|
|
698
|
+
**Implementation**
|
|
699
|
+
|
|
700
|
+
To create a unique batch, extend the `UniqueGraphBatch` class, everything else remains the same as a regular `GraphBatch`.
|
|
701
|
+
|
|
702
|
+
```javascript
|
|
703
|
+
export class UniqueBulkJobUpdate extends UniqueGraphBatch {
|
|
704
|
+
```
|
|
705
|
+
**Run a unique batch**
|
|
706
|
+
```javascript
|
|
707
|
+
const batch = new UniqueBulkJobUpdate(context, {
|
|
708
|
+
batchSize: 10,
|
|
709
|
+
maxBatches: 10,
|
|
710
|
+
strategy: PaginationStrategy.CURSOR,
|
|
711
|
+
delaySeconds: 1,
|
|
712
|
+
lockTtl: 5 * 60 * 1000, // 5 minutes - optional
|
|
598
713
|
});
|
|
599
|
-
|
|
714
|
+
batch.run(); // Runs successfully
|
|
715
|
+
batch.run(); // Fails (lock still active)
|
|
600
716
|
```
|
|
601
717
|
|
|
602
718
|
### Cache Service
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,i,n){return new(i||(i=Promise))((function(o,r){function s(t){try{d(n.next(t))}catch(t){r(t)}}function a(t){try{d(n.throw(t))}catch(t){r(t)}}function d(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,a)}d((n=n.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ArtifactClient=void 0;const constants_1=require("../constants"),base_client_1=require("./base-client");class ArtifactClient extends base_client_1.BaseClient{constructor(t,e){super(t),this.artifactType=e,this.baseEndpoint=`artifacts/${this.artifactType}`}list(){return __awaiter(this,void 0,void 0,(function*(){return this.performRequest({endpoint:this.baseEndpoint})}))}get(){return __awaiter(this,arguments,void 0,(function*(t={}){return this.performRequest({endpoint:this.buildEndpoint(t)})}))}create(t,e){return __awaiter(this,void 0,void 0,(function*(){return this.performRequest({method:constants_1.HttpMethod.POST,endpoint:this.buildEndpoint(t),body:e})}))}update(t,e){return __awaiter(this,void 0,void 0,(function*(){return this.performRequest({method:constants_1.HttpMethod.PUT,endpoint:this.buildEndpoint(t),body:e})}))}delete(t){return __awaiter(this,void 0,void 0,(function*(){yield this.performRequest({method:constants_1.HttpMethod.DELETE,endpoint:this.buildEndpoint(t)})}))}buildEndpoint(t){const{objectName:e,viewTypeName:i,name:n,scope:o}=t;let r=this.baseEndpoint;return e&&(r+=`/${e}`),i&&(r+=`/${i}`),n&&(r+=`/${n}`),o&&(r+=`/${o}`),r}}exports.ArtifactClient=ArtifactClient;
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,i,n){return new(i||(i=Promise))((function(o,r){function s(t){try{d(n.next(t))}catch(t){r(t)}}function a(t){try{d(n.throw(t))}catch(t){r(t)}}function d(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,a)}d((n=n.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ArtifactClient=void 0;const constants_1=require("../constants"),base_client_1=require("./base-client");class ArtifactClient extends base_client_1.BaseClient{constructor(t,e,i={}){super(t,i),this.artifactType=e,this.baseEndpoint=`artifacts/${this.artifactType}`}list(){return __awaiter(this,void 0,void 0,(function*(){return this.performRequest({endpoint:this.baseEndpoint})}))}get(){return __awaiter(this,arguments,void 0,(function*(t={}){return this.performRequest({endpoint:this.buildEndpoint(t)})}))}create(t,e){return __awaiter(this,void 0,void 0,(function*(){return this.performRequest({method:constants_1.HttpMethod.POST,endpoint:this.buildEndpoint(t),body:e})}))}update(t,e){return __awaiter(this,void 0,void 0,(function*(){return this.performRequest({method:constants_1.HttpMethod.PUT,endpoint:this.buildEndpoint(t),body:e})}))}delete(t){return __awaiter(this,void 0,void 0,(function*(){yield this.performRequest({method:constants_1.HttpMethod.DELETE,endpoint:this.buildEndpoint(t)})}))}buildEndpoint(t){const{objectName:e,viewTypeName:i,name:n,scope:o}=t;let r=this.baseEndpoint;return e&&(r+=`/${e}`),i&&(r+=`/${i}`),n&&(r+=`/${n}`),o&&(r+=`/${o}`),r}}exports.ArtifactClient=ArtifactClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __decorate=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,
|
|
1
|
+
"use strict";var __decorate=this&&this.__decorate||function(e,t,n,r){var o,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(i<3?o(s):i>3?o(t,n,s):o(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s},__metadata=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},__awaiter=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.BaseClient=void 0;const request_header_constants_1=require("../core/request-header-constants"),logging_1=require("../logging");class BaseClient{constructor(e,t={}){this.config=e,this.executionOptions=t}performRequest(e){return __awaiter(this,arguments,void 0,(function*({method:e="GET",endpoint:t,headers:n={},body:r,queryParams:o},i=this.executionOptions){try{const s=Object.assign(Object.assign({},this.getHeaders(i)),n),a=this.buildUrl(t,o),c=yield fetch(a,{method:e,headers:s,body:r&&"GET"!==e?JSON.stringify(r):void 0});let u;const d=c.headers.get("content-type");if(d&&d.includes("application/json")?(u=yield c.json(),u.result&&(u=u.result)):u=yield c.text(),!c.ok)throw new Error(`HTTP error! Status: ${c.status}. Response: ${JSON.stringify(u)}`);return u}catch(e){throw this.handleException(e),e}}))}getHeaders(e){var t,n;const r={Authorization:`Bearer ${this.config.apiToken}`,"Content-Type":"application/json"},o=e.requestSource||(null===(t=this.executionOptions)||void 0===t?void 0:t.requestSource),i=e.userAgent||(null===(n=this.executionOptions)||void 0===n?void 0:n.userAgent);return o&&(r[request_header_constants_1.REQUEST_HEADERS.X_SKEDULO_SOURCE]=o),i&&(r[request_header_constants_1.REQUEST_HEADERS.USER_AGENT]=i),r}buildUrl(e,t){const n=new URL(`${this.config.apiServer}/${e}`);return t&&Object.entries(t).forEach((([e,t])=>{n.searchParams.append(e,t)})),n.toString()}handleException(e){}}exports.BaseClient=BaseClient,__decorate([(0,logging_1.LogMethod)(),__metadata("design:type",Function),__metadata("design:paramtypes",[Object,Object]),__metadata("design:returntype",Promise)],BaseClient.prototype,"performRequest",null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))((function(o,r){function s(t){try{d(i.next(t))}catch(t){r(t)}}function a(t){try{d(i.throw(t))}catch(t){r(t)}}function d(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}d((i=i.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConfigVarClient=void 0;const constants_1=require("../constants"),base_client_1=require("./base-client");class ConfigVarClient extends base_client_1.BaseClient{create(t){return __awaiter(this,void 0,void 0,(function*(){return yield this.performRequest({method:constants_1.HttpMethod.POST,endpoint:constants_1.TENANT_ENDPOINTS.CONFIG_VAR.CREATE,body:t})}))}get(t){return __awaiter(this,void 0,void 0,(function*(){return yield this.performRequest({endpoint:constants_1.TENANT_ENDPOINTS.CONFIG_VAR.GET(t)})}))}update(t){return __awaiter(this,void 0,void 0,(function*(){const e=t.key||"";return
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))((function(o,r){function s(t){try{d(i.next(t))}catch(t){r(t)}}function a(t){try{d(i.throw(t))}catch(t){r(t)}}function d(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}d((i=i.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConfigVarClient=void 0;const constants_1=require("../constants"),base_client_1=require("./base-client");class ConfigVarClient extends base_client_1.BaseClient{create(t){return __awaiter(this,void 0,void 0,(function*(){return yield this.performRequest({method:constants_1.HttpMethod.POST,endpoint:constants_1.TENANT_ENDPOINTS.CONFIG_VAR.CREATE,body:t})}))}get(t){return __awaiter(this,void 0,void 0,(function*(){return yield this.performRequest({endpoint:constants_1.TENANT_ENDPOINTS.CONFIG_VAR.GET(t)})}))}update(t){return __awaiter(this,void 0,void 0,(function*(){const e=t.key||"";delete t.key;const n={};return void 0!==t.value&&(n.value=t.value),void 0!==t.description&&(n.description=t.description),void 0!==t.expiryDate&&(n.expiryDate=t.expiryDate),void 0!==t.status&&(n.status=t.status),yield this.performRequest({method:constants_1.HttpMethod.PATCH,endpoint:constants_1.TENANT_ENDPOINTS.CONFIG_VAR.UPDATE(e),body:n})}))}upsert(t){return __awaiter(this,void 0,void 0,(function*(){try{return yield this.update(Object.assign({},t))}catch(e){return yield this.create(t)}}))}search(t){return __awaiter(this,void 0,void 0,(function*(){return yield this.performRequest({method:constants_1.HttpMethod.POST,endpoint:constants_1.TENANT_ENDPOINTS.CONFIG_VAR.SEARCH,body:{pageSize:t&&t<1e3?t:1e3}})}))}delete(t){return __awaiter(this,void 0,void 0,(function*(){return yield this.performRequest({method:constants_1.HttpMethod.DELETE,endpoint:constants_1.TENANT_ENDPOINTS.CONFIG_VAR.DELETE(t)})}))}}exports.ConfigVarClient=ConfigVarClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,n,
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(i,s){function a(t){try{c(r.next(t))}catch(t){s(t)}}function o(t){try{c(r.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,o)}c((r=r.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.GraphQLClient=void 0;const constants_1=require("../constants"),http_1=require("../constants/http"),base_client_1=require("./base-client");class GraphQLClient extends base_client_1.BaseClient{execute(t){return __awaiter(this,arguments,void 0,(function*(t,e={}){return yield this.performRequest({method:http_1.HttpMethod.POST,endpoint:constants_1.TENANT_ENDPOINTS.GRAPHQL,body:{query:t},headers:e})}))}}exports.GraphQLClient=GraphQLClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var GraphqlOperations;Object.defineProperty(exports,"__esModule",{value:!0}),exports.GraphqlOperations=void 0,function(e){e.INSERT="insert",e.UPDATE="update",e.DELETE="delete",e.UPSERT="upsert"}(GraphqlOperations||(exports.GraphqlOperations=GraphqlOperations={}));
|
package/dist/constants/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(t,e,r,o){void 0===o&&(o=r);var
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(t,e,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(e,r);n&&!("get"in n?!e.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,o,n)}:function(t,e,r,o){void 0===o&&(o=r),t[o]=e[r]}),__exportStar=this&&this.__exportStar||function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||__createBinding(e,t,r)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./artifact-constants"),exports),__exportStar(require("./config-var-constants"),exports),__exportStar(require("./graphql-constants"),exports),__exportStar(require("./http"),exports),__exportStar(require("./mobile-notification-constants"),exports),__exportStar(require("./tenant-endpoints"),exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ExecutionContext=void 0;const function_utilities_1=require("@skedulo/function-utilities"),artifact_client_1=require("../clients/artifact-client"),availability_api_client_1=require("../clients/availability-api-client"),config_features_client_1=require("../clients/config-features-client"),config_template_client_1=require("../clients/config-template-client"),config_var_client_1=require("../clients/config-var-client"),geo_api_client_1=require("../clients/geo-api-client"),graphql_client_1=require("../clients/graphql-client"),metadata_client_1=require("../clients/metadata-client"),mobile_notification_client_1=require("../clients/mobile-notification-client"),org_preference_client_1=require("../clients/org-preference-client"),vocabulary_client_1=require("../clients/vocabulary-client"),logger_1=__importDefault(require("../logging/logger")),cache_service_1=require("../services/cache/cache-service"),storage_1=require("../services/cache/storage"),geoservice_1=require("../services/geoservice"),graphql_1=require("../services/graphql"),metadata_service_1=require("../services/metadata-service"),data_service_1=require("../services/resource-availability/builder/data-service"),resource_availability_service_1=require("../services/resource-availability/builder/resource-availability-service"),resource_builder_1=require("../services/resource-availability/builder/resource-builder"),utils_1=require("../utils");class ExecutionContext{constructor(e){this.logger=logger_1.default,this.services=new Map,this.skedContext=e,this.contextData={},this.baseConfig={apiToken:e.auth.token,apiServer:e.auth.baseUrl}}static fromContext(e){return new ExecutionContext(e)}static fromCredentials(e){const
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ExecutionContext=void 0;const function_utilities_1=require("@skedulo/function-utilities"),clients_1=require("../clients"),artifact_client_1=require("../clients/artifact-client"),availability_api_client_1=require("../clients/availability-api-client"),config_features_client_1=require("../clients/config-features-client"),config_template_client_1=require("../clients/config-template-client"),config_var_client_1=require("../clients/config-var-client"),geo_api_client_1=require("../clients/geo-api-client"),graphql_client_1=require("../clients/graphql-client"),metadata_client_1=require("../clients/metadata-client"),mobile_notification_client_1=require("../clients/mobile-notification-client"),org_preference_client_1=require("../clients/org-preference-client"),vocabulary_client_1=require("../clients/vocabulary-client"),logger_1=__importDefault(require("../logging/logger")),cache_service_1=require("../services/cache/cache-service"),storage_1=require("../services/cache/storage"),geoservice_1=require("../services/geoservice"),graphql_1=require("../services/graphql"),lock_service_1=require("../services/lock-service"),metadata_service_1=require("../services/metadata-service"),data_service_1=require("../services/resource-availability/builder/data-service"),resource_availability_service_1=require("../services/resource-availability/builder/resource-availability-service"),resource_builder_1=require("../services/resource-availability/builder/resource-builder"),utils_1=require("../utils"),request_header_constants_1=require("./request-header-constants");class ExecutionContext{constructor(e,i={}){this.logger=logger_1.default,this.services=new Map,this.skedContext=e,this.contextData={},this._executionOptions=i,this.baseConfig={apiToken:e.auth.token,apiServer:e.auth.baseUrl}}static fromContext(e,i={}){return new ExecutionContext(e,i)}static fromCredentials(e,i={}){const t={Authorization:`Bearer ${e.apiToken}`,[request_header_constants_1.REQUEST_HEADERS.SKED_API_SERVER]:e.apiServer},r=(0,function_utilities_1.createSkedContext)(t),n=new ExecutionContext(r,i);return n.baseConfig=Object.assign(Object.assign({},e),n.baseConfig),n}set executionOptions(e){this._executionOptions=Object.assign(Object.assign({},this._executionOptions),e)}get executionOptions(){return this._executionOptions}getOrCreateService(e,i){return this.services.has(e)||this.services.set(e,i()),this.services.get(e)}get configHelper(){return this.getOrCreateService("configHelper",(()=>new utils_1.ConfigHelper(this.skedContext.configVars)))}get baseClient(){return this.getOrCreateService("baseClient",(()=>new clients_1.BaseClient(this.baseConfig,this.executionOptions)))}get graphqlClient(){return this.getOrCreateService("graphqlClient",(()=>new graphql_client_1.GraphQLClient(this.baseConfig,this.executionOptions)))}get graphqlService(){return this.getOrCreateService("graphqlService",(()=>new graphql_1.GraphQLService(this.graphqlClient)))}get metadataClient(){return this.getOrCreateService("metadataClient",(()=>new metadata_client_1.MetadataClient(this.baseConfig,this.executionOptions)))}get metadataService(){return this.getOrCreateService("metadataService",(()=>new metadata_service_1.MetadataService(this.metadataClient)))}get vocabularyClient(){return this.getOrCreateService("vocabularyClient",(()=>new vocabulary_client_1.VocabularyClient(this.baseConfig,this.executionOptions)))}get orgPreferencesClient(){return this.getOrCreateService("orgPreferencesClient",(()=>new org_preference_client_1.OrgPreferenceClient(this.baseConfig,this.executionOptions)))}get configTemplateClient(){return this.getOrCreateService("configTemplateClient",(()=>new config_template_client_1.ConfigTemplateClient(this.baseConfig,this.executionOptions)))}get configFeaturesClient(){return this.getOrCreateService("configFeaturesClient",(()=>new config_features_client_1.ConfigFeaturesClient(this.baseConfig,this.executionOptions)))}get configVarClient(){return this.getOrCreateService("configVarClient",(()=>new config_var_client_1.ConfigVarClient(this.baseConfig,this.executionOptions)))}get mobileNotificationClient(){return this.getOrCreateService("mobileNotificationClient",(()=>new mobile_notification_client_1.MobileNotificationClient(this.baseConfig,this.executionOptions)))}get geoAPIClient(){return this.getOrCreateService("geoAPIClient",(()=>new geo_api_client_1.GeoAPIClient(this.baseConfig,this.executionOptions)))}get availabilityAPIClient(){return this.getOrCreateService("availabilityAPIClient",(()=>new availability_api_client_1.AvailabilityAPIClient(this.baseConfig,this.executionOptions)))}get geoService(){return this.getOrCreateService("geoService",(()=>new geoservice_1.GeoService(this.geoAPIClient)))}get lockService(){return this.getOrCreateService("lockService",(()=>new lock_service_1.LockService(this.configVarClient)))}get configVarCache(){return this.getOrCreateService("configVarCache",(()=>new cache_service_1.CacheService(new storage_1.ConfigVarCacheStorage(this.configVarClient))))}get inMemoryCache(){return this.getOrCreateService("inMemoryCache",(()=>{const e=new cache_service_1.CacheService(new storage_1.InMemoryCacheStorage);return e.setSecondaryCache(this.configVarCache),e}))}get resourceAvailabilityService(){return this.getOrCreateService("resourceAvailabilityService",(()=>new resource_availability_service_1.ResourceAvailabilityService(this.availabilityAPIClient)))}get dataService(){return this.getOrCreateService("dataService",(()=>new data_service_1.DataService(this.graphqlService)))}get resourceBuilder(){return this.getOrCreateService("resourceBuilder",(()=>new resource_builder_1.ResourceBuilder(this.dataService,this.resourceAvailabilityService)))}newQueryBuilder(e){const i=new graphql_1.GraphQLQueryBuilder(e);return i.setGraphqlService(this.graphqlService),i}newArtifactClient(e){return this.getOrCreateService(`${e}Client`,(()=>new artifact_client_1.ArtifactClient(this.baseConfig,e,this.executionOptions)))}dispose(){this.services.clear()}}exports.ExecutionContext=ExecutionContext;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ExecutionOptions=void 0;class ExecutionOptions{constructor(t){this.requestSource="",this.userAgent="",t&&Object.assign(this,t)}}exports.ExecutionOptions=ExecutionOptions;
|
package/dist/core/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,i)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),__exportStar=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||__createBinding(t,e,r)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./entity-factory"),exports),__exportStar(require("./execution-context"),exports),__exportStar(require("./execution-options"),exports),__exportStar(require("./request-header-constants"),exports),__exportStar(require("./tenant-entities"),exports),__exportStar(require("./tenant-objects"),exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.REQUEST_HEADERS=void 0,exports.REQUEST_HEADERS={X_SKEDULO_BULK_OPERATION:"X-Skedulo-Bulk-Operation",X_SKEDULO_READ_ONLY:"X-Skedulo-Read-Only",X_SKEDULO_SOURCE:"X-Skedulo-Source",X_GRAPHQL_OPERATION:"X-Graphql-Operation",SKED_FUNCTION_EXECUTION_TYPE:"Sked-Function-Execution-Type",SKED_API_SERVER:"sked-api-server",USER_AGENT:"User-Agent"};
|