@quantum-hub/qhub-service 1.0.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/README.md +44 -0
- package/dist/client.d.ts +19 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +61 -0
- package/dist/datapool.d.ts +12 -0
- package/dist/datapool.d.ts.map +1 -0
- package/dist/datapool.js +13 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Kipu Quantum Hub Service SDK
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
The package can be installed using `npm`:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @quantum-hub/qhub-service
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
const serviceEndpoint = "..."
|
|
15
|
+
const accessKeyId = "..."
|
|
16
|
+
const secretAccessKey = "..."
|
|
17
|
+
|
|
18
|
+
// Create a new client instance
|
|
19
|
+
const client = new HubServiceClient(serviceEndpoint, accessKeyId, secretAccessKey)
|
|
20
|
+
|
|
21
|
+
// List all service executions
|
|
22
|
+
const serviceExecutions = await client.api().getServiceExecutions()
|
|
23
|
+
|
|
24
|
+
// Start a new service execution
|
|
25
|
+
let serviceExecution = await client.api().startExecution({n_coin_tosses: 2, shots: 100}, {timeoutInSeconds: 60})
|
|
26
|
+
|
|
27
|
+
// Check the status of the service execution
|
|
28
|
+
serviceExecution = await client.api().getStatus({id: serviceExecution.id!})
|
|
29
|
+
|
|
30
|
+
// Wait for the service execution to finish
|
|
31
|
+
const finalStates = ["SUCCEEDED", "CANCELLED", "FAILED"]
|
|
32
|
+
while (!finalStates.includes(serviceExecution.status!)) {
|
|
33
|
+
serviceExecution = await client.api().getStatus({id: serviceExecution.id!})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Get the result of the service execution
|
|
37
|
+
const result = await client.api().getResult({id: serviceExecution.id!})
|
|
38
|
+
|
|
39
|
+
// Get the logs of the service execution
|
|
40
|
+
const logs = await client.api().getLogs({id: serviceExecution.id!})
|
|
41
|
+
|
|
42
|
+
// Cancel the service execution if it is still pending or running
|
|
43
|
+
await client.api().cancelExecution({id: serviceExecution.id!})
|
|
44
|
+
```
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { HubServiceClient as BaseHubServiceClient } from '@quantum-hub/qhub-api/service';
|
|
2
|
+
type ServiceApiClient = InstanceType<typeof BaseHubServiceClient>['serviceApi'];
|
|
3
|
+
export declare const DEFAULT_TOKEN_ENDPOINT = "https://gateway.hub.kipu-quantum.com/token";
|
|
4
|
+
export declare class HubServiceAuth {
|
|
5
|
+
private accessToken;
|
|
6
|
+
private readonly accessKeyId;
|
|
7
|
+
private readonly secretAccessKey;
|
|
8
|
+
private readonly tokenEndpoint;
|
|
9
|
+
constructor(accessKeyId: string, secretAccessKey: string, tokenEndpoint?: string);
|
|
10
|
+
getAccessToken(): Promise<string>;
|
|
11
|
+
private fetchAccessToken;
|
|
12
|
+
}
|
|
13
|
+
export declare class HubServiceClient {
|
|
14
|
+
private _api;
|
|
15
|
+
constructor(serviceEndpoint: string, accessKeyId?: string, secretAccessKey?: string, tokenEndpoint?: string);
|
|
16
|
+
api(): ServiceApiClient;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,gBAAgB,IAAI,oBAAoB,EAAC,MAAM,+BAA+B,CAAA;AAEtF,KAAK,gBAAgB,GAAG,YAAY,CAAC,OAAO,oBAAoB,CAAC,CAAC,YAAY,CAAC,CAAA;AAE/E,eAAO,MAAM,sBAAsB,+CAA+C,CAAA;AAElF,qBAAa,cAAc;IACzB,OAAO,CAAC,WAAW,CAAyB;IAC5C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAQ;IACpC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAQ;IACxC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAQ;gBAE1B,WAAW,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,aAAa,GAAE,MAA+B;IAMlG,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAYvC,OAAO,CAAC,gBAAgB;CAiBzB;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,IAAI,CAAsB;gBAEtB,eAAe,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,EAAE,aAAa,GAAE,MAA+B;IAe5H,GAAG,IAAI,gBAAgB;CAG/B"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ClientCredentials } from 'simple-oauth2';
|
|
2
|
+
import { HubServiceClient as BaseHubServiceClient } from '@quantum-hub/qhub-api/service';
|
|
3
|
+
export const DEFAULT_TOKEN_ENDPOINT = 'https://gateway.hub.kipu-quantum.com/token';
|
|
4
|
+
export class HubServiceAuth {
|
|
5
|
+
accessToken;
|
|
6
|
+
accessKeyId;
|
|
7
|
+
secretAccessKey;
|
|
8
|
+
tokenEndpoint;
|
|
9
|
+
constructor(accessKeyId, secretAccessKey, tokenEndpoint = DEFAULT_TOKEN_ENDPOINT) {
|
|
10
|
+
this.accessKeyId = accessKeyId;
|
|
11
|
+
this.secretAccessKey = secretAccessKey;
|
|
12
|
+
this.tokenEndpoint = tokenEndpoint;
|
|
13
|
+
}
|
|
14
|
+
async getAccessToken() {
|
|
15
|
+
if (!this.accessToken) {
|
|
16
|
+
this.accessToken = await this.fetchAccessToken();
|
|
17
|
+
}
|
|
18
|
+
if (this.accessToken.expired()) {
|
|
19
|
+
this.accessToken = await this.accessToken.refresh();
|
|
20
|
+
}
|
|
21
|
+
return this.accessToken.token.access_token;
|
|
22
|
+
}
|
|
23
|
+
fetchAccessToken() {
|
|
24
|
+
const client = new ClientCredentials({
|
|
25
|
+
auth: {
|
|
26
|
+
tokenHost: this.tokenEndpoint,
|
|
27
|
+
tokenPath: '/token',
|
|
28
|
+
},
|
|
29
|
+
client: {
|
|
30
|
+
id: this.accessKeyId,
|
|
31
|
+
secret: this.secretAccessKey,
|
|
32
|
+
},
|
|
33
|
+
options: {
|
|
34
|
+
authorizationMethod: 'body',
|
|
35
|
+
bodyFormat: 'form'
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return client.getToken({});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export class HubServiceClient {
|
|
42
|
+
_api;
|
|
43
|
+
constructor(serviceEndpoint, accessKeyId, secretAccessKey, tokenEndpoint = DEFAULT_TOKEN_ENDPOINT) {
|
|
44
|
+
if (accessKeyId && secretAccessKey) {
|
|
45
|
+
const auth = new HubServiceAuth(accessKeyId, secretAccessKey, tokenEndpoint);
|
|
46
|
+
this._api = new BaseHubServiceClient({
|
|
47
|
+
environment: () => serviceEndpoint,
|
|
48
|
+
token: async () => auth.getAccessToken(),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
this._api = new BaseHubServiceClient({
|
|
53
|
+
environment: () => serviceEndpoint,
|
|
54
|
+
token: async () => Math.random().toString(36).slice(2),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
api() {
|
|
59
|
+
return this._api.serviceApi;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare enum ReferenceType {
|
|
2
|
+
DATAPOOL = "DATAPOOL"
|
|
3
|
+
}
|
|
4
|
+
export interface DataPoolReference {
|
|
5
|
+
id: string;
|
|
6
|
+
ref: ReferenceType;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Factory function to create DataPoolReference objects with ref always set to DATAPOOL.
|
|
10
|
+
*/
|
|
11
|
+
export declare function withDataPoolReference(id: string): DataPoolReference;
|
|
12
|
+
//# sourceMappingURL=datapool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datapool.d.ts","sourceRoot":"","sources":["../src/datapool.ts"],"names":[],"mappings":"AAAA,oBAAY,aAAa;IACvB,QAAQ,aAAa;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAA;IACV,GAAG,EAAE,aAAa,CAAA;CACnB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,MAAM,GAAG,iBAAiB,CAKnE"}
|
package/dist/datapool.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export var ReferenceType;
|
|
2
|
+
(function (ReferenceType) {
|
|
3
|
+
ReferenceType["DATAPOOL"] = "DATAPOOL";
|
|
4
|
+
})(ReferenceType || (ReferenceType = {}));
|
|
5
|
+
/**
|
|
6
|
+
* Factory function to create DataPoolReference objects with ref always set to DATAPOOL.
|
|
7
|
+
*/
|
|
8
|
+
export function withDataPoolReference(id) {
|
|
9
|
+
return {
|
|
10
|
+
id,
|
|
11
|
+
ref: ReferenceType.DATAPOOL,
|
|
12
|
+
};
|
|
13
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA"}
|
package/dist/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@quantum-hub/qhub-service",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "SDK to interact with managed services on the Kipu Quantum Hub.",
|
|
5
|
+
"author": "Kipu Quantum GmbH",
|
|
6
|
+
"contributors": [
|
|
7
|
+
"Harzenetter, Lukas <lukas.harzenetter@kipu-quantum.com>",
|
|
8
|
+
"Wurster, Michael <michael.wurster@kipu-quantum.com>"
|
|
9
|
+
],
|
|
10
|
+
"license": "Apache-2.0",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "shx rm -rf dist && tsc -b",
|
|
17
|
+
"lint": "eslint",
|
|
18
|
+
"test": "vitest"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@quantum-hub/qhub-api": "^1",
|
|
22
|
+
"simple-oauth2": "^5"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/node": "^22",
|
|
26
|
+
"@types/simple-oauth2": "^5",
|
|
27
|
+
"dotenv": "^17",
|
|
28
|
+
"eslint": "^9",
|
|
29
|
+
"shx": "^0.4.0",
|
|
30
|
+
"typescript": "^5",
|
|
31
|
+
"typescript-eslint": "^8",
|
|
32
|
+
"vitest": "^4"
|
|
33
|
+
},
|
|
34
|
+
"private": false,
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
}
|
|
38
|
+
}
|