@skedulo/pulse-solution-services 0.0.8 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +47 -4
  3. package/dist/clients/base-client.js +1 -1
  4. package/dist/clients/config-var-client.js +1 -1
  5. package/dist/clients/graphql-client.js +1 -1
  6. package/dist/core/execution-context.js +1 -1
  7. package/dist/core/index.js +1 -1
  8. package/dist/index.d.ts +70 -30
  9. package/dist/interfaces/index.js +1 -1
  10. package/dist/interfaces/lock-service-interfaces.js +1 -0
  11. package/dist/interfaces/locking-service-interfaces.js +1 -0
  12. package/dist/services/cache/cache-service.js +1 -1
  13. package/dist/services/graph-batch/configs/graph-batch-config.d.ts +18 -0
  14. package/dist/services/graph-batch/configs/graph-batch-config.js +1 -0
  15. package/dist/services/graph-batch/configs/unique-graph-batch-config.d.ts +16 -0
  16. package/dist/services/graph-batch/configs/unique-graph-batch-config.js +1 -0
  17. package/dist/services/graph-batch/graph-batch.d.ts +1 -1
  18. package/dist/services/graph-batch/graph-batch.js +1 -1
  19. package/dist/services/graph-batch/index.d.ts +3 -1
  20. package/dist/services/graph-batch/index.js +1 -1
  21. package/dist/services/graph-batch/unique-graph-batch.d.ts +28 -0
  22. package/dist/services/graph-batch/unique-graph-batch.js +1 -0
  23. package/dist/services/lock-service.js +1 -0
  24. package/dist/services/locking-service.js +1 -0
  25. package/dist/utils/datetime-utils.js +1 -1
  26. package/package.json +7 -6
  27. package/yarn.lock +382 -207
  28. package/dist/core/request-context.js +0 -1
  29. package/dist/services/graph-batch/graph-batch-config.d.ts +0 -34
  30. package/dist/services/graph-batch/graph-batch-config.js +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.0.10] - 2025-02-03
4
+ ### Changed
5
+ - Minor changes
6
+
7
+ ## [v0.0.9] - 2025-02-28
8
+ ### Added
9
+ - Lock Service, Unique Batch
10
+
3
11
  ## [v0.0.8] - 2025-02-17
4
12
  ### Added
5
13
  - GraphBatch
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
- - [Geoservices Client](#geoservices-client)
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,10 +48,10 @@ yarn add @skedulo/pulse-solution-services
47
48
 
48
49
  **From a function**
49
50
  ```javascript
50
- const context = ExecutionContext.fromContext(skedToken, {
51
+ const context = ExecutionContext.fromContext(skedContext, {
51
52
  requestSource: "my-cool-project",
52
53
  userAgent: "my-cool-function"
53
- } as ExecutionOptions);
54
+ });
54
55
  ```
55
56
 
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.
@@ -63,7 +64,7 @@ const context = ExecutionContext.fromCredentials({
63
64
  }, {
64
65
  requestSource: "my-cool-project",
65
66
  userAgent: "my-cool-function"
66
- } as ExecutionOptions);
67
+ });
67
68
  ```
68
69
  Once initialized, the context object provides access to the various services detailed in subsequent sections.
69
70
  ### API Clients
@@ -108,7 +109,9 @@ const queryResult = await context.graphqlClient.execute(queryString, {readOnly:
108
109
  ```
109
110
 
110
111
  #### Config Variable Client
112
+
111
113
  Provides CRUD and search methods for managing configuration variables.
114
+
112
115
  ```javascript
113
116
  // Calls /configuration/extension endpoint to create a configuration var
114
117
  await context.configVarClient.create({
@@ -117,8 +120,12 @@ await context.configVarClient.create({
117
120
  configType: "plain-text",
118
121
  description: "TEST_DESCRIPTION",
119
122
  });
123
+
120
124
  // Gets a config var
121
125
  const config = await context.configVarClient.get('TEST_KEY');
126
+
127
+ // Deletes a config var
128
+ const config = await context.configVarClient.delete('TEST_KEY');
122
129
  ```
123
130
 
124
131
  #### Org Preferences Client
@@ -601,6 +608,19 @@ if (suggestions) {
601
608
  }
602
609
  ```
603
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
+
604
624
  ### Batch Service
605
625
  The Batch Service offers a flexible and scalable solution for large-scale data processing.
606
626
 
@@ -672,6 +692,29 @@ const batch = new BulkJobUpdate(context, {
672
692
  await batch.run();
673
693
  ```
674
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
713
+ });
714
+ batch.run(); // Runs successfully
715
+ batch.run(); // Fails (lock still active)
716
+ ```
717
+
675
718
  ### Cache Service
676
719
  The Cache Service enables efficient data sharing between function executions and improves performance by reducing redundant operations and API calls.
677
720
  ```javascript
@@ -1 +1 @@
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
+ "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 this.handleResponseData(u),u}catch(e){throw this.handleException(e),e}}))}handleResponseData(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=e.startsWith("http")?new URL(e):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 delete t.key,yield this.performRequest({method:constants_1.HttpMethod.PATCH,endpoint:constants_1.TENANT_ENDPOINTS.CONFIG_VAR.UPDATE(e),body:{value:t.value,description:t.description}})}))}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
+ "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,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;
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(i,a){function s(t){try{c(r.next(t))}catch(t){a(t)}}function o(t){try{c(r.throw(t))}catch(t){a(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(s,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})}))}handleResponseData(t){if(!t.data&&t.errors)throw new Error(`GraphQL error: ${JSON.stringify(t.errors)}`)}}exports.GraphQLClient=GraphQLClient;
@@ -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"),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"),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 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;
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;
@@ -1 +1 @@
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("./request-header-constants"),exports),__exportStar(require("./tenant-entities"),exports),__exportStar(require("./tenant-objects"),exports);
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);
package/dist/index.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
- import { z } from 'zod';
4
-
5
3
  /**
6
4
  * Interface representing the structure of metadata for an object.
7
5
  */
@@ -57,7 +55,12 @@ export interface BaseConfig {
57
55
  apiToken: string;
58
56
  internalApiToken?: string;
59
57
  }
60
- declare class ExecutionOptions {
58
+ /**
59
+ * Represents execution options for GraphQL requests.
60
+ * This class encapsulates metadata and execution settings
61
+ * that enhance observability, performance, and request tracking.
62
+ */
63
+ export declare class ExecutionOptions {
61
64
  /**
62
65
  * Identifies the origin of the request (e.g., the system, application, or project that initiated the call).
63
66
  * Helps in tracking and debugging requests across different systems.
@@ -107,7 +110,8 @@ export declare class BaseClient {
107
110
  * @returns {Promise<T>} - The parsed response data.
108
111
  * @throws {Error} - If the request fails or the response is not OK.
109
112
  */
110
- protected performRequest<T = any>({ method, endpoint, headers, body, queryParams }: RequestParams, executionOptions?: Partial<ExecutionOptions>): Promise<T>;
113
+ performRequest<T = any>({ method, endpoint, headers, body, queryParams }: RequestParams, executionOptions?: Partial<ExecutionOptions>): Promise<T>;
114
+ protected handleResponseData(response: Response): void;
111
115
  /**
112
116
  * Constructs the headers for API requests.
113
117
  * @returns {Record<string, string>} - The headers including authorization and content type.
@@ -219,6 +223,7 @@ export interface ConfigVar {
219
223
  value: string;
220
224
  description?: string;
221
225
  status?: "active" | "inactive" | "expired";
226
+ expiryDate?: string;
222
227
  updatedBy?: string;
223
228
  createdBy?: string;
224
229
  createdAt?: string;
@@ -231,32 +236,26 @@ export interface ConfigVar {
231
236
  export declare class ConfigVarClient extends BaseClient {
232
237
  /**
233
238
  * Creates a new configuration variable.
234
- * @param {ConfigVar} configVar - The configuration variable to create.
235
- * @returns {Promise<ConfigVar>} - The created configuration variable.
236
239
  */
237
240
  create(configVar: ConfigVar): Promise<ConfigVar>;
238
241
  /**
239
242
  * Retrieves a configuration variable by key.
240
- * @param {string} key - The key of the configuration variable.
241
- * @returns {Promise<ConfigVar>} - The retrieved configuration variable.
242
243
  */
243
244
  get(key: string): Promise<ConfigVar>;
244
245
  /**
245
246
  * Updates an existing configuration variable.
246
- * @param {ConfigVar} configVar - The configuration variable with updated values. Only the value and description can be updated.
247
- * @returns {Promise<ConfigVar>} - A promise that resolves when the update is complete.
248
247
  */
249
248
  update(configVar: ConfigVar): Promise<ConfigVar>;
249
+ /**
250
+ * Upsert a configuration variable. If the configuration variable does not exist, it will be created.
251
+ */
252
+ upsert(configVar: ConfigVar): Promise<ConfigVar>;
250
253
  /**
251
254
  * Searches for configuration variables with pagination.
252
- * @param {number} [pageSize] - The number of results per page (default max is 1000).
253
- * @returns {Promise<ConfigVar[]>} - A list of configuration variables.
254
255
  */
255
256
  search(pageSize?: number): Promise<ConfigVar[]>;
256
257
  /**
257
258
  * Deletes a configuration variable by key.
258
- * @param {string} key - The key of the configuration variable to delete.
259
- * @returns {Promise<string>} - A response indicating the result of the delete operation.
260
259
  */
261
260
  delete(key: string): Promise<string>;
262
261
  }
@@ -423,6 +422,7 @@ export declare class GraphQLClient extends BaseClient {
423
422
  * @throws {Error} - If the request fails or if there are errors in the response.
424
423
  */
425
424
  execute(graphqlQuery: string, headers?: Record<string, string>): Promise<GraphQlResponse>;
425
+ protected handleResponseData(responseData: any): void;
426
426
  }
427
427
  /**
428
428
  * OrgPreferencesClient class to handle API requests related to organization preferences.
@@ -856,6 +856,11 @@ declare class VocabularyClient extends BaseClient {
856
856
  */
857
857
  updateVocabularyItem(schemaName: string, fieldName: string, value: string, item: VocabularyItem): Promise<VocabularyItem>;
858
858
  }
859
+ export interface LockInfo {
860
+ name: string;
861
+ ttl: number;
862
+ description?: string;
863
+ }
859
864
  declare const logger: import("winston").Logger;
860
865
  export declare class CacheService<T> {
861
866
  private storage;
@@ -1091,6 +1096,12 @@ export declare class GraphQLQueryBuilder {
1091
1096
  */
1092
1097
  toString(): string;
1093
1098
  }
1099
+ declare class LockService {
1100
+ private configVarClient;
1101
+ constructor(configVarClient: ConfigVarClient);
1102
+ acquireLock(lockInfo: LockInfo): Promise<boolean>;
1103
+ releaseLock(name: string): Promise<void>;
1104
+ }
1094
1105
  export declare class ResourceQueryParam {
1095
1106
  resourceIds?: Set<string>;
1096
1107
  regionIds?: Set<string>;
@@ -1221,6 +1232,7 @@ export declare class ExecutionContext {
1221
1232
  get geoAPIClient(): GeoAPIClient;
1222
1233
  get availabilityAPIClient(): AvailabilityAPIClient;
1223
1234
  get geoService(): GeoService;
1235
+ get lockService(): LockService;
1224
1236
  get configVarCache(): CacheService<any>;
1225
1237
  get inMemoryCache(): CacheService<any>;
1226
1238
  get resourceAvailabilityService(): ResourceAvailabilityService;
@@ -1353,30 +1365,34 @@ export declare enum PaginationStrategy {
1353
1365
  * Default configuration values for `GraphBatchConfig`.
1354
1366
  */
1355
1367
  export declare const DEFAULT_GRAPH_BATCH_CONFIG: GraphBatchConfig;
1356
- declare const GraphBatchConfigSchema: z.ZodObject<{
1357
- strategy: z.ZodNativeEnum<typeof PaginationStrategy>;
1358
- batchSize: z.ZodDefault<z.ZodNumber>;
1359
- maxBatches: z.ZodDefault<z.ZodNumber>;
1360
- delaySeconds: z.ZodDefault<z.ZodNumber>;
1361
- }, "strip", z.ZodTypeAny, {
1368
+ /**
1369
+ * Configuration options for `GraphBatch`.
1370
+ */
1371
+ export interface GraphBatchConfig {
1362
1372
  strategy: PaginationStrategy;
1363
1373
  batchSize: number;
1364
1374
  maxBatches: number;
1365
1375
  delaySeconds: number;
1366
- }, {
1367
- strategy: PaginationStrategy;
1368
- batchSize?: number | undefined;
1369
- maxBatches?: number | undefined;
1370
- delaySeconds?: number | undefined;
1371
- }>;
1372
- /**
1373
- * Configuration options for `GraphBatch`.
1374
- */
1375
- export type GraphBatchConfig = z.infer<typeof GraphBatchConfigSchema>;
1376
+ }
1376
1377
  /**
1377
1378
  * Merges user-provided config with default values.
1378
1379
  */
1379
1380
  export declare function initializeConfig(config: Partial<GraphBatchConfig> | undefined): GraphBatchConfig;
1381
+ /**
1382
+ * Default configuration values for `UniqueGraphBatchConfig`.
1383
+ */
1384
+ export declare const DEFAULT_UNIQUE_GRAPH_BATCH_CONFIG: UniqueGraphBatchConfig;
1385
+ /**
1386
+ * Configuration options for `UniqueGraphBatch`.
1387
+ */
1388
+ export interface UniqueGraphBatchConfig extends GraphBatchConfig {
1389
+ name?: string;
1390
+ lockTtl?: number;
1391
+ }
1392
+ /**
1393
+ * Merges user-provided config with default values for `UniqueGraphBatch`.
1394
+ */
1395
+ export declare function initializeUniqueConfig(config: Partial<UniqueGraphBatchConfig> | undefined): UniqueGraphBatchConfig;
1380
1396
  /**
1381
1397
  * Base class for batch processing with pagination support.
1382
1398
  */
@@ -1429,6 +1445,30 @@ export declare abstract class GraphBatch {
1429
1445
  */
1430
1446
  protected delay(ms: number): Promise<void>;
1431
1447
  }
1448
+ /**
1449
+ * UniqueGraphBatch ensures that only one instance of a batch with the same name can run at a time.
1450
+ */
1451
+ export declare class UniqueGraphBatch extends GraphBatch {
1452
+ private name;
1453
+ private lockTtl;
1454
+ constructor(context: ExecutionContext, config?: Partial<UniqueGraphBatchConfig>);
1455
+ /**
1456
+ * Runs the batch process with lock enforcement.
1457
+ */
1458
+ run(): Promise<void>;
1459
+ /**
1460
+ * Abstract method implementation - Initialize query builder.
1461
+ */
1462
+ protected start(): Promise<GraphQLQueryBuilder>;
1463
+ /**
1464
+ * Abstract method implementation - Process batch records.
1465
+ */
1466
+ protected execute(records: any[]): Promise<void>;
1467
+ /**
1468
+ * Overrides the finish method to ensure lock cleanup.
1469
+ */
1470
+ protected finish(): Promise<void>;
1471
+ }
1432
1472
  export interface ResourceValidationOption {
1433
1473
  checkAvailability: boolean;
1434
1474
  checkConflict: boolean;
@@ -1 +1 @@
1
- "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,i){void 0===i&&(i=t);var o=Object.getOwnPropertyDescriptor(r,t);o&&!("get"in o?!r.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,i,o)}:function(e,r,t,i){void 0===i&&(i=t),e[i]=r[t]}),__exportStar=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||__createBinding(r,e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("../core/tenant-entities"),exports),__exportStar(require("./api-client"),exports),__exportStar(require("./availability"),exports),__exportStar(require("./config-template"),exports),__exportStar(require("./config-var"),exports),__exportStar(require("./geoservice-interfaces"),exports),__exportStar(require("./graphql"),exports),__exportStar(require("./metadata"),exports),__exportStar(require("./mobile-notification"),exports);
1
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,i){void 0===i&&(i=t);var o=Object.getOwnPropertyDescriptor(r,t);o&&!("get"in o?!r.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,i,o)}:function(e,r,t,i){void 0===i&&(i=t),e[i]=r[t]}),__exportStar=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||__createBinding(r,e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("../core/tenant-entities"),exports),__exportStar(require("./api-client"),exports),__exportStar(require("./availability"),exports),__exportStar(require("./config-template"),exports),__exportStar(require("./config-var"),exports),__exportStar(require("./geoservice-interfaces"),exports),__exportStar(require("./graphql"),exports),__exportStar(require("./lock-service-interfaces"),exports),__exportStar(require("./metadata"),exports),__exportStar(require("./mobile-notification"),exports);
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});
@@ -1 +1 @@
1
- "use strict";var __decorate=this&&this.__decorate||function(e,t,a,r){var i,n=arguments.length,o=n<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,a):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,a,r);else for(var c=e.length-1;c>=0;c--)(i=e[c])&&(o=(n<3?i(o):n>3?i(t,a,o):i(t,a))||o);return n>3&&o&&Object.defineProperty(t,a,o),o},__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,a,r){return new(a||(a=Promise))((function(i,n){function o(e){try{s(r.next(e))}catch(e){n(e)}}function c(e){try{s(r.throw(e))}catch(e){n(e)}}function s(e){var t;e.done?i(e.value):(t=e.value,t instanceof a?t:new a((function(e){e(t)}))).then(o,c)}s((r=r.apply(e,t||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.CacheService=void 0;const logging_1=require("../../logging"),KEY_PREFIX="Z_CACHE_",DEFAULT_TTL=36e5;class CacheService{constructor(e){this.storage=e}setSecondaryCache(e){this.secondaryCache=e}get(e,t){return __awaiter(this,void 0,void 0,(function*(){e=this.addPrefix(e);const a=yield this.storage.get(e);if(a)try{const t=JSON.parse(a);return t.expiresAt&&Date.now()>t.expiresAt?(yield this.delete(e),null):this.deserialize(t)}catch(e){return console.error("Cache deserialization failed:",e),null}if((null==t?void 0:t.useSecondaryCache)&&this.secondaryCache){const a=yield this.secondaryCache.get(e,t);return null!==a&&(yield this.set(e,a,{ttl:null==t?void 0:t.ttl})),a}return null}))}set(e,t,a){return __awaiter(this,void 0,void 0,(function*(){var r;e=this.addPrefix(e);const i={type:t instanceof Date?"date":typeof t,value:t,expiresAt:Date.now()+(null!==(r=null==a?void 0:a.ttl)&&void 0!==r?r:36e5)},n=JSON.stringify(i);yield this.storage.set(e,n),(null==a?void 0:a.useSecondaryCache)&&this.secondaryCache&&(yield this.secondaryCache.set(e,t,a))}))}delete(e){return __awaiter(this,void 0,void 0,(function*(){e=this.addPrefix(e),yield this.storage.delete(e)}))}clear(){return __awaiter(this,void 0,void 0,(function*(){yield this.storage.clear()}))}addPrefix(e){return e.startsWith("Z_CACHE_")?e:"Z_CACHE_"+e}deserialize(e){switch(e.type){case"number":return Number(e.value);case"boolean":return Boolean(e.value);case"object":return e.value;case"date":case"datetime":const t=new Date(e.value);return isNaN(t.getTime())?(console.error(`Invalid ${e.type} string:`,e.value),null):t;default:return String(e.value)}}}exports.CacheService=CacheService,__decorate([(0,logging_1.LogMethod)(),__metadata("design:type",Function),__metadata("design:paramtypes",[String,Object]),__metadata("design:returntype",Promise)],CacheService.prototype,"get",null),__decorate([(0,logging_1.LogMethod)(),__metadata("design:type",Function),__metadata("design:paramtypes",[String,Object,Object]),__metadata("design:returntype",Promise)],CacheService.prototype,"set",null);
1
+ "use strict";var __decorate=this&&this.__decorate||function(e,t,r,a){var i,n=arguments.length,o=n<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,r):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,r,a);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(o=(n<3?i(o):n>3?i(t,r,o):i(t,r))||o);return n>3&&o&&Object.defineProperty(t,r,o),o},__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,r,a){return new(r||(r=Promise))((function(i,n){function o(e){try{c(a.next(e))}catch(e){n(e)}}function s(e){try{c(a.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,s)}c((a=a.apply(e,t||[])).next())}))},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.CacheService=void 0;const logging_1=require("../../logging"),logger_1=__importDefault(require("../../logging/logger")),KEY_PREFIX="Z_CACHE_",DEFAULT_TTL=36e5;class CacheService{constructor(e){this.storage=e}setSecondaryCache(e){this.secondaryCache=e}get(e,t){return __awaiter(this,void 0,void 0,(function*(){e=this.addPrefix(e);const r=yield this.storage.get(e);if(r)try{const t=JSON.parse(r);return t.expiresAt&&Date.now()>t.expiresAt?(yield this.delete(e),null):this.deserialize(t)}catch(e){return logger_1.default.error("Cache deserialization failed:",e),null}if((null==t?void 0:t.useSecondaryCache)&&this.secondaryCache){const r=yield this.secondaryCache.get(e,t);return null!==r&&(yield this.set(e,r,{ttl:null==t?void 0:t.ttl})),r}return null}))}set(e,t,r){return __awaiter(this,void 0,void 0,(function*(){var a;e=this.addPrefix(e);const i={type:t instanceof Date?"date":typeof t,value:t,expiresAt:Date.now()+(null!==(a=null==r?void 0:r.ttl)&&void 0!==a?a:36e5)},n=JSON.stringify(i);yield this.storage.set(e,n),(null==r?void 0:r.useSecondaryCache)&&this.secondaryCache&&(yield this.secondaryCache.set(e,t,r))}))}delete(e){return __awaiter(this,void 0,void 0,(function*(){e=this.addPrefix(e),yield this.storage.delete(e)}))}clear(){return __awaiter(this,void 0,void 0,(function*(){yield this.storage.clear()}))}addPrefix(e){return e.startsWith("Z_CACHE_")?e:"Z_CACHE_"+e}deserialize(e){switch(e.type){case"number":return Number(e.value);case"boolean":return Boolean(e.value);case"object":return e.value;case"date":case"datetime":const t=new Date(e.value);return isNaN(t.getTime())?(logger_1.default.error(`Invalid ${e.type} string:`,e.value),null):t;default:return String(e.value)}}}exports.CacheService=CacheService,__decorate([(0,logging_1.LogMethod)(),__metadata("design:type",Function),__metadata("design:paramtypes",[String,Object]),__metadata("design:returntype",Promise)],CacheService.prototype,"get",null),__decorate([(0,logging_1.LogMethod)(),__metadata("design:type",Function),__metadata("design:paramtypes",[String,Object,Object]),__metadata("design:returntype",Promise)],CacheService.prototype,"set",null);
@@ -0,0 +1,18 @@
1
+ import { PaginationStrategy } from "../pagination-strategy";
2
+ /**
3
+ * Default configuration values for `GraphBatchConfig`.
4
+ */
5
+ export declare const DEFAULT_GRAPH_BATCH_CONFIG: GraphBatchConfig;
6
+ /**
7
+ * Configuration options for `GraphBatch`.
8
+ */
9
+ export interface GraphBatchConfig {
10
+ strategy: PaginationStrategy;
11
+ batchSize: number;
12
+ maxBatches: number;
13
+ delaySeconds: number;
14
+ }
15
+ /**
16
+ * Merges user-provided config with default values.
17
+ */
18
+ export declare function initializeConfig(config: Partial<GraphBatchConfig> | undefined): GraphBatchConfig;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DEFAULT_GRAPH_BATCH_CONFIG=void 0,exports.initializeConfig=initializeConfig;const pagination_strategy_1=require("../pagination-strategy");function initializeConfig(t){var a,e,i,n;return{strategy:null!==(a=null==t?void 0:t.strategy)&&void 0!==a?a:exports.DEFAULT_GRAPH_BATCH_CONFIG.strategy,batchSize:Math.min(Math.max(null!==(e=null==t?void 0:t.batchSize)&&void 0!==e?e:exports.DEFAULT_GRAPH_BATCH_CONFIG.batchSize,1),200),maxBatches:Math.min(Math.max(null!==(i=null==t?void 0:t.maxBatches)&&void 0!==i?i:exports.DEFAULT_GRAPH_BATCH_CONFIG.maxBatches,1),500),delaySeconds:Math.min(Math.max(null!==(n=null==t?void 0:t.delaySeconds)&&void 0!==n?n:exports.DEFAULT_GRAPH_BATCH_CONFIG.delaySeconds,0),15)}}exports.DEFAULT_GRAPH_BATCH_CONFIG={strategy:pagination_strategy_1.PaginationStrategy.NONE,batchSize:200,maxBatches:100,delaySeconds:0};
@@ -0,0 +1,16 @@
1
+ import { GraphBatchConfig } from "./graph-batch-config";
2
+ /**
3
+ * Default configuration values for `UniqueGraphBatchConfig`.
4
+ */
5
+ export declare const DEFAULT_UNIQUE_GRAPH_BATCH_CONFIG: UniqueGraphBatchConfig;
6
+ /**
7
+ * Configuration options for `UniqueGraphBatch`.
8
+ */
9
+ export interface UniqueGraphBatchConfig extends GraphBatchConfig {
10
+ name?: string;
11
+ lockTtl?: number;
12
+ }
13
+ /**
14
+ * Merges user-provided config with default values for `UniqueGraphBatch`.
15
+ */
16
+ export declare function initializeUniqueConfig(config: Partial<UniqueGraphBatchConfig> | undefined): UniqueGraphBatchConfig;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DEFAULT_UNIQUE_GRAPH_BATCH_CONFIG=void 0,exports.initializeUniqueConfig=initializeUniqueConfig;const graph_batch_config_1=require("./graph-batch-config");function initializeUniqueConfig(i){return Object.assign(Object.assign(Object.assign({},exports.DEFAULT_UNIQUE_GRAPH_BATCH_CONFIG),i),{lockTtl:void 0!==(null==i?void 0:i.lockTtl)?Math.max(i.lockTtl,1e3):exports.DEFAULT_UNIQUE_GRAPH_BATCH_CONFIG.lockTtl})}exports.DEFAULT_UNIQUE_GRAPH_BATCH_CONFIG=Object.assign(Object.assign({},graph_batch_config_1.DEFAULT_GRAPH_BATCH_CONFIG),{lockTtl:96e4,name:"UNIQUE-BATCH"});
@@ -1,7 +1,7 @@
1
1
  import { ExecutionContext } from "../../core";
2
2
  import { QueryResult } from "../../interfaces";
3
3
  import { GraphQLQueryBuilder } from "../graphql";
4
- import { GraphBatchConfig } from "./graph-batch-config";
4
+ import { GraphBatchConfig } from "./configs/graph-batch-config";
5
5
  /**
6
6
  * Base class for batch processing with pagination support.
7
7
  */
@@ -1 +1 @@
1
- "use strict";var __awaiter=this&&this.__awaiter||function(t,e,i,r){return new(i||(i=Promise))((function(a,s){function n(t){try{o(r.next(t))}catch(t){s(t)}}function h(t){try{o(r.throw(t))}catch(t){s(t)}}function o(t){var e;t.done?a(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(n,h)}o((r=r.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.GraphBatch=void 0;const graph_batch_config_1=require("./graph-batch-config"),pagination_strategy_1=require("./pagination-strategy");class GraphBatch{constructor(t,e){this.startTime=new Date,this.context=t,this.config=(0,graph_batch_config_1.initializeConfig)(e),this.startTime=new Date}run(){return __awaiter(this,void 0,void 0,(function*(){var t,e;if(this.queryBuilder=yield this.start(),!this.queryBuilder)throw new Error("Query builder was not defined in start().");this.queryBuilder.withLimit(this.config.batchSize);let i=0,r=!0;for(;r&&!this.isMaxBatchesReached(i)&&(this.queryResult=yield this.fetchNextPage(),this.queryResult.records&&0!==this.queryResult.records.length);)yield this.execute(this.queryResult.records),i++,r=null!==(e=null===(t=this.queryResult.pageInfo)||void 0===t?void 0:t.hasNextPage)&&void 0!==e&&e;yield Promise.all([]),yield this.finish()}))}finish(){return __awaiter(this,void 0,void 0,(function*(){this.context.logger.info("Batch process completed.")}))}fetchNextPage(){return __awaiter(this,void 0,void 0,(function*(){var t,e,i;switch(this.config.strategy){case pagination_strategy_1.PaginationStrategy.OFFSET:this.queryResult&&(null===(t=this.queryBuilder)||void 0===t||t.withOffset(this.queryResult.endOffset+1));break;case pagination_strategy_1.PaginationStrategy.CURSOR:this.queryResult&&(null===(e=this.queryBuilder)||void 0===e||e.withCursor(this.queryResult.endCursor));break;case pagination_strategy_1.PaginationStrategy.NONE:default:null===(i=this.queryBuilder)||void 0===i||i.withFilter(`LastModifiedDate < ${this.startTime.toISOString()}`)}return this.queryBuilder.execute()}))}isMaxBatchesReached(t){return!!this.config.maxBatches&&t>=this.config.maxBatches}delay(t){return __awaiter(this,void 0,void 0,(function*(){return new Promise((e=>setTimeout(e,t)))}))}}exports.GraphBatch=GraphBatch;
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(t,e,i,r){return new(i||(i=Promise))((function(a,s){function n(t){try{o(r.next(t))}catch(t){s(t)}}function h(t){try{o(r.throw(t))}catch(t){s(t)}}function o(t){var e;t.done?a(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(n,h)}o((r=r.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.GraphBatch=void 0;const graph_batch_config_1=require("./configs/graph-batch-config"),pagination_strategy_1=require("./pagination-strategy");class GraphBatch{constructor(t,e){this.startTime=new Date,this.context=t,this.config=(0,graph_batch_config_1.initializeConfig)(e),this.startTime=new Date}run(){return __awaiter(this,void 0,void 0,(function*(){var t,e;if(this.queryBuilder=yield this.start(),!this.queryBuilder)throw new Error("Query builder was not defined in start().");this.queryBuilder.withLimit(this.config.batchSize);let i=0,r=!0;for(;r&&!this.isMaxBatchesReached(i)&&(this.queryResult=yield this.fetchNextPage(),this.queryResult.records&&0!==this.queryResult.records.length);)yield this.execute(this.queryResult.records),i++,r=null!==(e=null===(t=this.queryResult.pageInfo)||void 0===t?void 0:t.hasNextPage)&&void 0!==e&&e;yield this.finish()}))}finish(){return __awaiter(this,void 0,void 0,(function*(){this.context.logger.info("Batch process completed.")}))}fetchNextPage(){return __awaiter(this,void 0,void 0,(function*(){var t,e,i;switch(this.config.strategy){case pagination_strategy_1.PaginationStrategy.OFFSET:this.queryResult&&(null===(t=this.queryBuilder)||void 0===t||t.withOffset(this.queryResult.endOffset+1));break;case pagination_strategy_1.PaginationStrategy.CURSOR:this.queryResult&&(null===(e=this.queryBuilder)||void 0===e||e.withCursor(this.queryResult.endCursor));break;case pagination_strategy_1.PaginationStrategy.NONE:default:null===(i=this.queryBuilder)||void 0===i||i.withFilter(`LastModifiedDate < ${this.startTime.toISOString()}`)}return this.queryBuilder.execute()}))}isMaxBatchesReached(t){return!!this.config.maxBatches&&t>=this.config.maxBatches}delay(t){return __awaiter(this,void 0,void 0,(function*(){return new Promise((e=>setTimeout(e,t)))}))}}exports.GraphBatch=GraphBatch;
@@ -1,3 +1,5 @@
1
+ export * from "./configs/graph-batch-config";
2
+ export * from "./configs/unique-graph-batch-config";
1
3
  export * from "./graph-batch";
2
- export * from "./graph-batch-config";
3
4
  export * from "./pagination-strategy";
5
+ export * from "./unique-graph-batch";
@@ -1 +1 @@
1
- "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,o)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=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("./graph-batch"),exports),__exportStar(require("./graph-batch-config"),exports),__exportStar(require("./pagination-strategy"),exports);
1
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,i){void 0===i&&(i=t);var o=Object.getOwnPropertyDescriptor(r,t);o&&!("get"in o?!r.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,i,o)}:function(e,r,t,i){void 0===i&&(i=t),e[i]=r[t]}),__exportStar=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||__createBinding(r,e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./configs/graph-batch-config"),exports),__exportStar(require("./configs/unique-graph-batch-config"),exports),__exportStar(require("./graph-batch"),exports),__exportStar(require("./pagination-strategy"),exports),__exportStar(require("./unique-graph-batch"),exports);
@@ -0,0 +1,28 @@
1
+ import { ExecutionContext } from "../../core/execution-context";
2
+ import { GraphQLQueryBuilder } from "../graphql";
3
+ import { UniqueGraphBatchConfig } from "./configs/unique-graph-batch-config";
4
+ import { GraphBatch } from "./graph-batch";
5
+ /**
6
+ * UniqueGraphBatch ensures that only one instance of a batch with the same name can run at a time.
7
+ */
8
+ export declare class UniqueGraphBatch extends GraphBatch {
9
+ private name;
10
+ private lockTtl;
11
+ constructor(context: ExecutionContext, config?: Partial<UniqueGraphBatchConfig>);
12
+ /**
13
+ * Runs the batch process with lock enforcement.
14
+ */
15
+ run(): Promise<void>;
16
+ /**
17
+ * Abstract method implementation - Initialize query builder.
18
+ */
19
+ protected start(): Promise<GraphQLQueryBuilder>;
20
+ /**
21
+ * Abstract method implementation - Process batch records.
22
+ */
23
+ protected execute(records: any[]): Promise<void>;
24
+ /**
25
+ * Overrides the finish method to ensure lock cleanup.
26
+ */
27
+ protected finish(): Promise<void>;
28
+ }
@@ -0,0 +1 @@
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(t,e,r,i){return new(r||(r=Promise))((function(n,a){function o(t){try{s(i.next(t))}catch(t){a(t)}}function c(t){try{s(i.throw(t))}catch(t){a(t)}}function s(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,c)}s((i=i.apply(t,e||[])).next())}))},__importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.UniqueGraphBatch=void 0;const logger_1=__importDefault(require("../../logging/logger")),graph_batch_1=require("./graph-batch");class UniqueGraphBatch extends graph_batch_1.GraphBatch{constructor(t,e){super(t,e),this.name=(null==e?void 0:e.name)||this.constructor.name,this.name=this.name.toUpperCase().replace(/[^A-Z0-9]/g,"_"),this.lockTtl=(null==e?void 0:e.lockTtl)||96e4}run(){const t=Object.create(null,{run:{get:()=>super.run}});return __awaiter(this,void 0,void 0,(function*(){const e={name:this.name,ttl:this.lockTtl,description:`Lock for batch process: ${this.name}`};try{if(!(yield this.context.lockService.acquireLock(e)))return void logger_1.default.error(`A batch with name '${this.name}' is already running.`);yield t.run.call(this)}catch(t){logger_1.default.error(`Error running batch with name '${this.name}': ${t.message}`)}finally{yield this.context.lockService.releaseLock(this.name)}}))}start(){return __awaiter(this,void 0,void 0,(function*(){throw new Error("Subclasses must implement the 'start' method.")}))}execute(t){return __awaiter(this,void 0,void 0,(function*(){throw new Error("Subclasses must implement the 'execute' method.")}))}finish(){const t=Object.create(null,{finish:{get:()=>super.finish}});return __awaiter(this,void 0,void 0,(function*(){yield t.finish.call(this)}))}}exports.UniqueGraphBatch=UniqueGraphBatch;
@@ -0,0 +1 @@
1
+ "use strict";var __decorate=this&&this.__decorate||function(e,t,r,i){var o,n=arguments.length,a=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,i);else for(var c=e.length-1;c>=0;c--)(o=e[c])&&(a=(n<3?o(a):n>3?o(t,r,a):o(t,r))||a);return n>3&&a&&Object.defineProperty(t,r,a),a},__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,r,i){return new(r||(r=Promise))((function(o,n){function a(e){try{l(i.next(e))}catch(e){n(e)}}function c(e){try{l(i.throw(e))}catch(e){n(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,c)}l((i=i.apply(e,t||[])).next())}))},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.LockService=void 0;const logging_1=require("../logging"),logger_1=__importDefault(require("../logging/logger")),KEY_PREFIX="Z_LOCK_";class LockService{constructor(e){this.configVarClient=e}acquireLock(e){return __awaiter(this,void 0,void 0,(function*(){const t="Z_LOCK_"+e.name,r=new Date(Date.now()+e.ttl).toISOString();try{let i=null;try{i=yield this.configVarClient.get(t)}catch(e){}if(i){if(i.expiryDate&&new Date<new Date(i.expiryDate))return!1;yield this.configVarClient.delete(t)}return yield this.configVarClient.create({key:t,value:e.name,configType:"plain-text",description:e.description,expiryDate:r}),!0}catch(t){return logger_1.default.error(`Failed to acquire lock: ${e.name}`),!1}}))}releaseLock(e){return __awaiter(this,void 0,void 0,(function*(){const t="Z_LOCK_"+e;try{let e=null;try{e=yield this.configVarClient.get(t)}catch(e){}e&&(yield this.configVarClient.delete(t))}catch(t){logger_1.default.error(`Failed to release lock: ${e}`)}}))}}exports.LockService=LockService,__decorate([(0,logging_1.LogMethod)(),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",Promise)],LockService.prototype,"acquireLock",null),__decorate([(0,logging_1.LogMethod)(),__metadata("design:type",Function),__metadata("design:paramtypes",[String]),__metadata("design:returntype",Promise)],LockService.prototype,"releaseLock",null);
@@ -0,0 +1 @@
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(r,c){function o(e){try{l(n.next(e))}catch(e){c(e)}}function a(e){try{l(n.throw(e))}catch(e){c(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.LockingService=void 0;const KEY_PREFIX="Z_LOCK_";class LockingService{constructor(e){this.configVarClient=e}acquireLock(e){return __awaiter(this,void 0,void 0,(function*(){const t="Z_LOCK_"+e.name,i=new Date(Date.now()+e.ttl).toISOString();try{let n=null;try{n=yield this.configVarClient.get(t)}catch(e){}if(n){if(n.expiryDate&&new Date<new Date(n.expiryDate))return!1;yield this.configVarClient.delete(t)}return yield this.configVarClient.create({key:t,value:e.name,configType:"plain-text",description:e.description,expiryDate:i}),!0}catch(t){return console.error(`Failed to acquire lock: ${e.name}`),!1}}))}releaseLock(e){return __awaiter(this,void 0,void 0,(function*(){const t="Z_LOCK_"+e;try{let e=null;try{e=yield this.configVarClient.get(t)}catch(e){}e&&(yield this.configVarClient.delete(t))}catch(t){console.error(`Failed to release lock: ${e}`)}}))}}exports.LockingService=LockingService;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DateTimeUtils=void 0;const luxon_1=require("luxon");class DateTimeUtils{static toTimezone(t,e){return this.switchTimezone(t,"UTC",e)}static switchTimezone(t,e,a){if(e===a)return t;return luxon_1.DateTime.fromJSDate(t,{zone:e}).setZone(a).toJSDate()}static addMinutes(t,e,a){return luxon_1.DateTime.fromJSDate(t,{zone:a}).plus({minutes:e}).toJSDate()}static addDays(t,e,a){return luxon_1.DateTime.fromJSDate(t,{zone:a}).plus({days:e}).toJSDate()}static addMonths(t,e,a){return luxon_1.DateTime.fromJSDate(t,{zone:a}).plus({months:e}).toJSDate()}static addYears(t,e,a){return luxon_1.DateTime.fromJSDate(t,{zone:a}).plus({years:e}).toJSDate()}static getDate(t,e){return luxon_1.DateTime.fromJSDate(t,{zone:e}).startOf("day").toJSDate()}static getDateFromIsoString(t){return luxon_1.DateTime.fromISO(t,{zone:"UTC"}).toJSDate()}static getDateTimeFromIsoString(t){return luxon_1.DateTime.fromISO(t,{zone:"UTC"}).toJSDate()}static getStartOfDate(t,e){const a="string"==typeof t?this.getDateFromIsoString(t):t;return luxon_1.DateTime.fromJSDate(a,{zone:e}).startOf("day").toJSDate()}static getEndOfDate(t,e){const a=this.getStartOfDate(t,e);return this.addDays(a,1,e)}static isIncluding(t,e){return t.start<=e.start&&t.finish>=e.finish}static isOverlapping(t,e){return t.start<e.finish&&t.finish>e.start}static mergeEvents(t){t.sort(((t,e)=>t.start.getTime()-e.start.getTime()));const e=[];let a=null;for(const i of t)a?new Date(a.finish)>=i.start?(a.finish=i.finish,a.eventType="merged",a.description=a.description?`${a.description}, ${a.name} merged with ${i.name}`:`${a.name} merged with ${i.name}`):(e.push(a),a=i):a=i;return a&&e.push(a),e}}exports.DateTimeUtils=DateTimeUtils;
1
+ "use strict";var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.DateTimeUtils=void 0;const dayjs_1=__importDefault(require("dayjs")),timezone_1=__importDefault(require("dayjs/plugin/timezone")),utc_1=__importDefault(require("dayjs/plugin/utc"));dayjs_1.default.extend(utc_1.default),dayjs_1.default.extend(timezone_1.default);class DateTimeUtils{static toTimezone(t,e){return(0,dayjs_1.default)(t).tz(e).toDate()}static switchTimezone(t,e,a){return e===a?t:(0,dayjs_1.default)(t).tz(e).tz(a).toDate()}static addMinutes(t,e,a){return(0,dayjs_1.default)(t).tz(a).add(e,"minute").toDate()}static addDays(t,e,a){return(0,dayjs_1.default)(t).tz(a).add(e,"day").toDate()}static addMonths(t,e,a){return(0,dayjs_1.default)(t).tz(a).add(e,"month").toDate()}static addYears(t,e,a){return(0,dayjs_1.default)(t).tz(a).add(e,"year").toDate()}static getDate(t,e){return(0,dayjs_1.default)(t).tz(e).startOf("day").toDate()}static getDateFromIsoString(t){return(0,dayjs_1.default)(t).utc().toDate()}static getDateTimeFromIsoString(t){return(0,dayjs_1.default)(t).utc().toDate()}static getStartOfDate(t,e){const a="string"==typeof t?this.getDateFromIsoString(t):t;return(0,dayjs_1.default)(a).tz(e).startOf("day").toDate()}static getEndOfDate(t,e){return this.addDays(this.getStartOfDate(t,e),1,e)}static isIncluding(t,e){return t.start<=e.start&&t.finish>=e.finish}static isOverlapping(t,e){return t.start<e.finish&&t.finish>e.start}static mergeEvents(t){t.sort(((t,e)=>t.start.getTime()-e.start.getTime()));const e=[];let a=null;for(const s of t)a?a.finish>=s.start?(a.finish=s.finish,a.eventType="merged",a.description=a.description?`${a.description}, ${a.name} merged with ${s.name}`:`${a.name} merged with ${s.name}`):(e.push(a),a=s):a=s;return a&&e.push(a),e}}exports.DateTimeUtils=DateTimeUtils;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skedulo/pulse-solution-services",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "A collection of services and utilities to support solution development on the Pulse platform.",
5
5
  "author": "Skedulo",
6
6
  "license": "MIT",
@@ -23,6 +23,7 @@
23
23
  ],
24
24
  "devDependencies": {
25
25
  "@tsconfig/node18": "^18.2.2",
26
+ "@types/uuid": "^10.0.0",
26
27
  "@typescript-eslint/eslint-plugin": "^8.11.0",
27
28
  "@typescript-eslint/parser": "^8.11.0",
28
29
  "dts-bundle-generator": "^9.5.1",
@@ -37,12 +38,12 @@
37
38
  },
38
39
  "dependencies": {
39
40
  "@skedulo/function-utilities": "^0.0.6",
40
- "@types/luxon": "^3.4.2",
41
- "luxon": "^3.5.0",
41
+ "dayjs": "^1.11.13",
42
42
  "p-queue": "^8.1.0",
43
+ "timezone": "^1.0.23",
43
44
  "typescript": "~5.6.3",
44
- "uuid": "^11.0.5",
45
- "winston": "^3.17.0",
46
- "zod": "^3.24.2"
45
+ "utc": "^0.1.0",
46
+ "uuid": "8",
47
+ "winston": "^3.17.0"
47
48
  }
48
49
  }