@quantum-hub/qhub-service 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +15 -3
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type HubService, HubServiceClient as BaseHubServiceClient } from '@quantum-hub/qhub-api/service';
|
|
2
1
|
import { HubPlatformClient as BaseHubPlatformClient } from '@quantum-hub/qhub-api/platform';
|
|
2
|
+
import { type HubService, HubServiceClient as BaseHubServiceClient } from '@quantum-hub/qhub-api/service';
|
|
3
3
|
import { type DataPoolGrant } from './datapool.js';
|
|
4
4
|
type ServiceApiClient = InstanceType<typeof BaseHubServiceClient>['serviceApi'];
|
|
5
5
|
type DataPoolGrantsClient = InstanceType<typeof BaseHubPlatformClient>['dataPoolGrants'];
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,IAAI,qBAAqB,EAAC,MAAM,gCAAgC,CAAA;AACzF,OAAO,EAAC,KAAK,UAAU,EAAE,gBAAgB,IAAI,oBAAoB,EAAC,MAAM,+BAA+B,CAAA;AAEvG,OAAO,EAAC,KAAK,aAAa,EAAgB,MAAM,eAAe,CAAA;AAE/D,KAAK,gBAAgB,GAAG,YAAY,CAAC,OAAO,oBAAoB,CAAC,CAAC,YAAY,CAAC,CAAA;AAC/E,KAAK,oBAAoB,GAAG,YAAY,CAAC,OAAO,qBAAqB,CAAC,CAAC,gBAAgB,CAAC,CAAA;AAExF,eAAO,MAAM,sBAAsB,+CAA+C,CAAA;AAOlF,MAAM,WAAW,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EAAE,UAAU,GACrB,OAAO,CAAC,UAAU,CAAC,gBAAgB,CAAC;YAwBzB,aAAa;CAkB5B"}
|
package/dist/client.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { ClientCredentials } from 'simple-oauth2';
|
|
2
|
-
import { HubServiceClient as BaseHubServiceClient } from '@quantum-hub/qhub-api/service';
|
|
3
1
|
import { HubPlatformClient as BaseHubPlatformClient } from '@quantum-hub/qhub-api/platform';
|
|
2
|
+
import { HubServiceClient as BaseHubServiceClient } from '@quantum-hub/qhub-api/service';
|
|
3
|
+
import { ClientCredentials } from 'simple-oauth2';
|
|
4
4
|
import { ReferenceType } from './datapool.js';
|
|
5
5
|
export const DEFAULT_TOKEN_ENDPOINT = 'https://gateway.hub.kipu-quantum.com/token';
|
|
6
6
|
const GRANT_CACHE_BUFFER_SECONDS = 30;
|
|
7
|
+
const PARENT_EXECUTION_TOKEN_ENV = 'KQH_SERVICE_EXECUTION_TOKEN';
|
|
8
|
+
const PARENT_EXECUTION_TOKEN_HEADER = 'X-Parent-Execution-Token';
|
|
7
9
|
export class HubPlatformClient {
|
|
8
10
|
_client;
|
|
9
11
|
_organizationId;
|
|
@@ -63,17 +65,20 @@ export class HubServiceClient {
|
|
|
63
65
|
_platform;
|
|
64
66
|
_grantCache = new Map();
|
|
65
67
|
constructor(serviceEndpoint, accessKeyId, secretAccessKey, tokenEndpoint = DEFAULT_TOKEN_ENDPOINT, platformClient) {
|
|
68
|
+
const headers = resolveParentExecutionTokenHeader();
|
|
66
69
|
if (accessKeyId && secretAccessKey) {
|
|
67
70
|
const auth = new HubServiceAuth(accessKeyId, secretAccessKey, tokenEndpoint);
|
|
68
71
|
this._api = new BaseHubServiceClient({
|
|
69
72
|
environment: () => serviceEndpoint,
|
|
70
73
|
token: async () => auth.getAccessToken(),
|
|
74
|
+
...(headers ? { headers } : {}),
|
|
71
75
|
});
|
|
72
76
|
}
|
|
73
77
|
else {
|
|
74
78
|
this._api = new BaseHubServiceClient({
|
|
75
79
|
environment: () => serviceEndpoint,
|
|
76
80
|
token: async () => Math.random().toString(36).slice(2),
|
|
81
|
+
...(headers ? { headers } : {}),
|
|
77
82
|
});
|
|
78
83
|
}
|
|
79
84
|
this._platform = platformClient;
|
|
@@ -105,7 +110,7 @@ export class HubServiceClient {
|
|
|
105
110
|
if (cached && Date.now() / 1000 < cached.expiry - GRANT_CACHE_BUFFER_SECONDS) {
|
|
106
111
|
return cached.token;
|
|
107
112
|
}
|
|
108
|
-
const grant = await this._platform.dataPoolGrants.
|
|
113
|
+
const grant = await this._platform.dataPoolGrants.createDataPoolGrant(datapoolId, {
|
|
109
114
|
applicationId,
|
|
110
115
|
permission,
|
|
111
116
|
'X-OrganizationId': this._platform.organizationId,
|
|
@@ -116,6 +121,13 @@ export class HubServiceClient {
|
|
|
116
121
|
return token;
|
|
117
122
|
}
|
|
118
123
|
}
|
|
124
|
+
function resolveParentExecutionTokenHeader() {
|
|
125
|
+
const token = process.env[PARENT_EXECUTION_TOKEN_ENV];
|
|
126
|
+
if (!token) {
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
return { [PARENT_EXECUTION_TOKEN_HEADER]: token };
|
|
130
|
+
}
|
|
119
131
|
function parseJwtExpiry(token) {
|
|
120
132
|
const payload = token.split('.')[1];
|
|
121
133
|
const decoded = JSON.parse(atob(payload));
|