@quantumbpm/sdk 1.2.0 → 2.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 +93 -34
- package/dist/auth.d.ts +19 -14
- package/dist/auth.js +62 -84
- package/dist/bpmn.d.ts +83 -21
- package/dist/bpmn.js +61 -33
- package/dist/dmn.d.ts +0 -6
- package/dist/dmn.js +1 -15
- package/dist/generated/RawClient.js +2 -2
- package/dist/generated/core/OpenAPI.js +2 -2
- package/dist/generated/index.d.ts +9 -2
- package/dist/generated/index.js +8 -4
- package/dist/generated/models/BpmnActivityState.d.ts +85 -0
- package/dist/generated/models/BpmnActivityState.js +18 -0
- package/dist/generated/models/BpmnElementStatistics.d.ts +36 -0
- package/dist/generated/models/BpmnElementStatistics.js +17 -0
- package/dist/generated/models/BpmnExternalJobPaginatedResponse.d.ts +2 -2
- package/dist/generated/models/BpmnExternalJobPaginatedResponse.js +1 -1
- package/dist/generated/models/BpmnHistoryPage.d.ts +15 -0
- package/dist/generated/models/BpmnHistoryPage.js +3 -0
- package/dist/generated/models/BpmnIncident.d.ts +17 -17
- package/dist/generated/models/BpmnIncident.js +11 -11
- package/dist/generated/models/BpmnIncidentRecord.d.ts +10 -18
- package/dist/generated/models/BpmnIncidentRecord.js +6 -6
- package/dist/generated/models/BpmnIncidentRecordPaginatedResponse.d.ts +2 -2
- package/dist/generated/models/BpmnIncidentRecordPaginatedResponse.js +1 -1
- package/dist/generated/models/BpmnInstance.d.ts +21 -29
- package/dist/generated/models/BpmnInstance.js +1 -17
- package/dist/generated/models/BpmnInstancePaginatedResponse.d.ts +2 -2
- package/dist/generated/models/BpmnInstancePaginatedResponse.js +1 -1
- package/dist/generated/models/BpmnInstanceState.d.ts +49 -16
- package/dist/generated/models/BpmnInstanceState.js +1 -1
- package/dist/generated/models/BpmnInstanceStatus.d.ts +10 -0
- package/dist/generated/models/BpmnInstanceStatus.js +19 -0
- package/dist/generated/models/BpmnProcessDefinition.d.ts +5 -5
- package/dist/generated/models/BpmnProcessDefinition.js +1 -1
- package/dist/generated/models/BpmnProcessVersion.d.ts +9 -9
- package/dist/generated/models/BpmnProcessVersion.js +1 -1
- package/dist/generated/models/BpmnUserTaskPaginatedResponse.d.ts +2 -2
- package/dist/generated/models/BpmnUserTaskPaginatedResponse.js +1 -1
- package/dist/generated/models/CorrelationKeyNumber.d.ts +1 -1
- package/dist/generated/models/CorrelationKeyNumber.js +1 -1
- package/dist/generated/models/CorrelationKeys.d.ts +7 -6
- package/dist/generated/models/CorrelationKeys.js +1 -1
- package/dist/generated/models/CreateDefinitionRequest.d.ts +1 -5
- package/dist/generated/models/CreateDefinitionRequest.js +1 -1
- package/dist/generated/models/CursorPage.d.ts +12 -0
- package/dist/generated/models/CursorPage.js +3 -0
- package/dist/generated/models/DecisionSummary.d.ts +2 -2
- package/dist/generated/models/DecisionSummary.js +1 -1
- package/dist/generated/models/DecisionVersion.d.ts +25 -0
- package/dist/generated/models/DecisionVersion.js +3 -0
- package/dist/generated/models/DecisionVersionList.d.ts +7 -0
- package/dist/generated/models/DecisionVersionList.js +3 -0
- package/dist/generated/models/Definition.d.ts +16 -8
- package/dist/generated/models/Definition.js +1 -1
- package/dist/generated/models/Error.d.ts +8 -2
- package/dist/generated/models/Error.js +6 -2
- package/dist/generated/models/EvaluateStoredRequest.d.ts +6 -4
- package/dist/generated/models/EvaluateStoredRequest.js +1 -1
- package/dist/generated/models/EvaluationResult.d.ts +6 -0
- package/dist/generated/models/EvaluationResult.js +1 -1
- package/dist/generated/models/Execution.d.ts +30 -9
- package/dist/generated/models/Execution.js +1 -1
- package/dist/generated/models/ExternalJob.d.ts +9 -9
- package/dist/generated/models/ExternalJob.js +1 -1
- package/dist/generated/models/ExternalJobBatchResponse.d.ts +2 -2
- package/dist/generated/models/ExternalJobBatchResponse.js +1 -1
- package/dist/generated/models/JoinArrivals.d.ts +8 -0
- package/dist/generated/models/JoinArrivals.js +3 -0
- package/dist/generated/models/PollBpmnJobRequest.d.ts +1 -1
- package/dist/generated/models/PollBpmnJobRequest.js +1 -1
- package/dist/generated/models/StartBpmnInstanceRequest.d.ts +6 -2
- package/dist/generated/models/StartBpmnInstanceRequest.js +1 -1
- package/dist/generated/models/SuspendBpmnInstanceRequest.d.ts +1 -1
- package/dist/generated/models/SuspendBpmnInstanceRequest.js +1 -1
- package/dist/generated/models/SuspensionEntry.d.ts +2 -2
- package/dist/generated/models/SuspensionEntry.js +1 -1
- package/dist/generated/models/UpdateDefinitionRequest.d.ts +1 -5
- package/dist/generated/models/UpdateDefinitionRequest.js +1 -1
- package/dist/generated/models/UpdateUserTaskAssignmentRequest.d.ts +11 -4
- package/dist/generated/models/UpdateUserTaskAssignmentRequest.js +1 -1
- package/dist/generated/models/UserTask.d.ts +15 -11
- package/dist/generated/models/UserTask.js +1 -1
- package/dist/generated/services/BpmnService.d.ts +191 -94
- package/dist/generated/services/BpmnService.js +300 -119
- package/dist/generated/services/DefaultService.d.ts +118 -118
- package/dist/generated/services/DefaultService.js +156 -160
- package/dist/index.d.ts +8 -8
- package/dist/index.js +7 -7
- package/dist/tracing.js +2 -2
- package/dist/workers.d.ts +41 -7
- package/dist/workers.js +186 -53
- package/package.json +2 -4
- package/src/auth.test.ts +128 -0
- package/src/auth.ts +67 -64
- package/src/bpmn.ts +131 -43
- package/src/dmn.ts +0 -19
- package/src/generated/RawClient.ts +1 -1
- package/src/generated/core/OpenAPI.ts +1 -1
- package/src/generated/index.ts +9 -2
- package/src/generated/models/BpmnActivityState.ts +90 -0
- package/src/generated/models/BpmnElementStatistics.ts +41 -0
- package/src/generated/models/BpmnExternalJobPaginatedResponse.ts +2 -2
- package/src/generated/models/BpmnHistoryPage.ts +20 -0
- package/src/generated/models/BpmnIncident.ts +17 -17
- package/src/generated/models/BpmnIncidentRecord.ts +10 -18
- package/src/generated/models/BpmnIncidentRecordPaginatedResponse.ts +2 -2
- package/src/generated/models/BpmnInstance.ts +21 -29
- package/src/generated/models/BpmnInstancePaginatedResponse.ts +2 -2
- package/src/generated/models/BpmnInstanceState.ts +49 -16
- package/src/generated/models/BpmnInstanceStatus.ts +14 -0
- package/src/generated/models/BpmnProcessDefinition.ts +5 -5
- package/src/generated/models/BpmnProcessVersion.ts +9 -9
- package/src/generated/models/BpmnUserTaskPaginatedResponse.ts +2 -2
- package/src/generated/models/CorrelationKeyNumber.ts +1 -1
- package/src/generated/models/CorrelationKeys.ts +7 -6
- package/src/generated/models/CreateDefinitionRequest.ts +1 -5
- package/src/generated/models/CursorPage.ts +17 -0
- package/src/generated/models/DecisionSummary.ts +2 -2
- package/src/generated/models/DecisionVersion.ts +30 -0
- package/src/generated/models/DecisionVersionList.ts +12 -0
- package/src/generated/models/Definition.ts +16 -8
- package/src/generated/models/Error.ts +8 -2
- package/src/generated/models/EvaluateStoredRequest.ts +6 -4
- package/src/generated/models/EvaluationResult.ts +6 -0
- package/src/generated/models/Execution.ts +30 -9
- package/src/generated/models/ExternalJob.ts +9 -9
- package/src/generated/models/ExternalJobBatchResponse.ts +2 -2
- package/src/generated/models/JoinArrivals.ts +13 -0
- package/src/generated/models/PollBpmnJobRequest.ts +1 -1
- package/src/generated/models/StartBpmnInstanceRequest.ts +6 -2
- package/src/generated/models/SuspendBpmnInstanceRequest.ts +1 -1
- package/src/generated/models/SuspensionEntry.ts +2 -2
- package/src/generated/models/UpdateDefinitionRequest.ts +1 -5
- package/src/generated/models/UpdateUserTaskAssignmentRequest.ts +11 -4
- package/src/generated/models/UserTask.ts +15 -11
- package/src/generated/services/BpmnService.ts +357 -140
- package/src/generated/services/DefaultService.ts +178 -189
- package/src/index.test.ts +77 -31
- package/src/index.ts +13 -6
- package/src/tracing.ts +1 -1
- package/src/workers.test.ts +280 -3
- package/src/workers.ts +200 -60
- package/dist/generated/models/CreateProjectRequest.d.ts +0 -9
- package/dist/generated/models/CreateProjectRequest.js +0 -3
- package/src/generated/models/CreateProjectRequest.ts +0 -14
package/src/auth.test.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import * as http from 'http';
|
|
2
|
+
import { AddressInfo } from 'net';
|
|
3
|
+
|
|
4
|
+
import { ClientCredentialsTokenProvider, ClientCredentialsOptions } from './auth';
|
|
5
|
+
|
|
6
|
+
interface TokenStub {
|
|
7
|
+
url: string;
|
|
8
|
+
forms: URLSearchParams[];
|
|
9
|
+
contentTypes: (string | undefined)[];
|
|
10
|
+
close(): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Answers every request with status and the body built by respond, which
|
|
14
|
+
// receives the 1-based request number.
|
|
15
|
+
async function startStub(status: number, respond: (n: number) => string): Promise<TokenStub> {
|
|
16
|
+
const forms: URLSearchParams[] = [];
|
|
17
|
+
const contentTypes: (string | undefined)[] = [];
|
|
18
|
+
const server = http.createServer((req, res) => {
|
|
19
|
+
let body = '';
|
|
20
|
+
req.on('data', (chunk) => { body += chunk; });
|
|
21
|
+
req.on('end', () => {
|
|
22
|
+
forms.push(new URLSearchParams(body));
|
|
23
|
+
contentTypes.push(req.headers['content-type']);
|
|
24
|
+
res.writeHead(status, { 'Content-Type': 'application/json' });
|
|
25
|
+
res.end(respond(forms.length));
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
await new Promise<void>((resolve) => server.listen(0, '127.0.0.1', resolve));
|
|
29
|
+
const { port } = server.address() as AddressInfo;
|
|
30
|
+
return {
|
|
31
|
+
url: `http://127.0.0.1:${port}/token`,
|
|
32
|
+
forms,
|
|
33
|
+
contentTypes,
|
|
34
|
+
close: () => new Promise((resolve) => server.close(() => resolve())),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const tokenJson = (expiresIn: string) => (n: number) =>
|
|
39
|
+
`{"access_token":"token-${n}","token_type":"Bearer"${expiresIn}}`;
|
|
40
|
+
|
|
41
|
+
function provider(stub: TokenStub, extra: Partial<ClientCredentialsOptions> = {}) {
|
|
42
|
+
return new ClientCredentialsTokenProvider({
|
|
43
|
+
tokenUrl: stub.url,
|
|
44
|
+
clientId: 'my-client',
|
|
45
|
+
clientSecret: 'my-secret',
|
|
46
|
+
...extra,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
describe('ClientCredentialsTokenProvider', () => {
|
|
51
|
+
let stub: TokenStub;
|
|
52
|
+
|
|
53
|
+
afterEach(async () => {
|
|
54
|
+
await stub?.close();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('sends the grant with scopes and audience', async () => {
|
|
58
|
+
stub = await startStub(200, tokenJson(',"expires_in":3600'));
|
|
59
|
+
await provider(stub, { scopes: ['openid', 'bpm.api'], audience: 'quantumbpm-api' }).getToken();
|
|
60
|
+
|
|
61
|
+
expect(stub.contentTypes[0]).toBe('application/x-www-form-urlencoded');
|
|
62
|
+
expect(Object.fromEntries(stub.forms[0])).toEqual({
|
|
63
|
+
grant_type: 'client_credentials',
|
|
64
|
+
client_id: 'my-client',
|
|
65
|
+
client_secret: 'my-secret',
|
|
66
|
+
scope: 'openid bpm.api',
|
|
67
|
+
audience: 'quantumbpm-api',
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('omits scope and audience when not set', async () => {
|
|
72
|
+
stub = await startStub(200, tokenJson(',"expires_in":3600'));
|
|
73
|
+
await provider(stub, { scopes: [] }).getToken();
|
|
74
|
+
|
|
75
|
+
expect(Object.fromEntries(stub.forms[0])).toEqual({
|
|
76
|
+
grant_type: 'client_credentials',
|
|
77
|
+
client_id: 'my-client',
|
|
78
|
+
client_secret: 'my-secret',
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test.each([
|
|
83
|
+
['a number', ',"expires_in":3600'],
|
|
84
|
+
['a numeric string', ',"expires_in":"3600"'],
|
|
85
|
+
['missing', ''],
|
|
86
|
+
])('reuses the cached token when expires_in is %s', async (_name, expiresIn) => {
|
|
87
|
+
stub = await startStub(200, tokenJson(expiresIn));
|
|
88
|
+
const p = provider(stub);
|
|
89
|
+
|
|
90
|
+
expect(await p.getToken()).toBe('token-1');
|
|
91
|
+
expect(await p.getToken()).toBe('token-1');
|
|
92
|
+
expect(stub.forms).toHaveLength(1);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('refreshes a token near expiry', async () => {
|
|
96
|
+
// 30 seconds is inside the 60 second refresh margin.
|
|
97
|
+
stub = await startStub(200, tokenJson(',"expires_in":30'));
|
|
98
|
+
const p = provider(stub);
|
|
99
|
+
|
|
100
|
+
expect(await p.getToken()).toBe('token-1');
|
|
101
|
+
expect(await p.getToken()).toBe('token-2');
|
|
102
|
+
expect(stub.forms).toHaveLength(2);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('parallel callers share one request', async () => {
|
|
106
|
+
stub = await startStub(200, tokenJson(',"expires_in":3600'));
|
|
107
|
+
const p = provider(stub);
|
|
108
|
+
|
|
109
|
+
const tokens = await Promise.all(Array.from({ length: 5 }, () => p.getToken()));
|
|
110
|
+
|
|
111
|
+
expect(tokens).toEqual(Array(5).fill('token-1'));
|
|
112
|
+
expect(stub.forms).toHaveLength(1);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('rejects with the status and body on 401', async () => {
|
|
116
|
+
stub = await startStub(401, () => '{"error":"invalid_client"}');
|
|
117
|
+
|
|
118
|
+
await expect(provider(stub).getToken()).rejects.toThrow(/401.*invalid_client/);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('requires tokenUrl, clientId and clientSecret', () => {
|
|
122
|
+
expect(() => new ClientCredentialsTokenProvider({
|
|
123
|
+
tokenUrl: 'http://127.0.0.1:1/token',
|
|
124
|
+
clientId: 'my-client',
|
|
125
|
+
clientSecret: '',
|
|
126
|
+
})).toThrow(/required/);
|
|
127
|
+
});
|
|
128
|
+
});
|
package/src/auth.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Authentication helpers
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* - ZitadelTokenProvider: service-account JWT-bearer flow against Zitadel,
|
|
6
|
-
* with in-memory token caching.
|
|
7
|
-
* - StaticTokenProvider: returns the same bearer token on every call.
|
|
2
|
+
* Authentication helpers: the TokenProvider interface, ClientCredentialsTokenProvider
|
|
3
|
+
* for any OIDC provider, and StaticTokenProvider for a fixed bearer token.
|
|
8
4
|
*/
|
|
9
|
-
import * as fs from 'fs';
|
|
10
|
-
import * as jwt from 'jsonwebtoken';
|
|
11
5
|
import axios from 'axios';
|
|
12
6
|
|
|
13
7
|
import { RawClient } from './generated/RawClient';
|
|
@@ -26,79 +20,88 @@ export class StaticTokenProvider implements TokenProvider {
|
|
|
26
20
|
}
|
|
27
21
|
}
|
|
28
22
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
/** Options for ClientCredentialsTokenProvider. */
|
|
24
|
+
export interface ClientCredentialsOptions {
|
|
25
|
+
/** The identity provider's OAuth 2.0 token endpoint. */
|
|
26
|
+
tokenUrl: string;
|
|
27
|
+
clientId: string;
|
|
28
|
+
clientSecret: string;
|
|
29
|
+
/** Sent space-joined as the `scope` parameter. Empty sends none. */
|
|
30
|
+
scopes?: string[];
|
|
31
|
+
/** Sent as the `audience` parameter when set. Some providers, such as Auth0, require it. */
|
|
32
|
+
audience?: string;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
const REFRESH_MARGIN_MS = 60_000;
|
|
36
|
+
const DEFAULT_LIFETIME_S = 300;
|
|
37
|
+
|
|
35
38
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
+
* Fetches access tokens from any OIDC provider with the OAuth 2.0 client
|
|
40
|
+
* credentials grant. The token is cached until less than 60 seconds of its
|
|
41
|
+
* lifetime remain, and parallel callers share one in-flight request.
|
|
39
42
|
*/
|
|
40
|
-
export class
|
|
43
|
+
export class ClientCredentialsTokenProvider implements TokenProvider {
|
|
41
44
|
private accessToken: string | null = null;
|
|
42
45
|
private expiresAt = 0;
|
|
43
|
-
private
|
|
44
|
-
private readonly issuer: string;
|
|
45
|
-
private readonly scopes: string[];
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @param keyFile Path to the service-account JSON Key file from Zitadel.
|
|
49
|
-
* @param issuer Zitadel instance base URL (e.g. https://auth.quantumbpm.com).
|
|
50
|
-
* @param projectId Zitadel project ID. When provided, adds the audience
|
|
51
|
-
* scope so issued tokens are accepted by the API.
|
|
52
|
-
*/
|
|
53
|
-
constructor(keyFile: string, issuer: string, projectId?: string) {
|
|
54
|
-
const content = fs.readFileSync(keyFile, 'utf-8');
|
|
55
|
-
this.keyData = JSON.parse(content) as ZitadelKeyFile;
|
|
56
|
-
this.issuer = issuer.replace(/\/$/, '');
|
|
46
|
+
private inFlight: Promise<string> | null = null;
|
|
57
47
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
'
|
|
61
|
-
'urn:zitadel:iam:user:resourceowner',
|
|
62
|
-
'urn:zitadel:iam:org:projects:roles',
|
|
63
|
-
];
|
|
64
|
-
if (projectId) {
|
|
65
|
-
scopes.push(`urn:zitadel:iam:org:project:id:${projectId}:aud`);
|
|
48
|
+
constructor(private readonly options: ClientCredentialsOptions) {
|
|
49
|
+
if (!options.tokenUrl || !options.clientId || !options.clientSecret) {
|
|
50
|
+
throw new Error('quantumbpm: tokenUrl, clientId and clientSecret are required');
|
|
66
51
|
}
|
|
67
|
-
this.scopes = scopes;
|
|
68
52
|
}
|
|
69
53
|
|
|
70
54
|
async getToken(): Promise<string> {
|
|
71
|
-
if (this.accessToken && Date.now() < this.expiresAt -
|
|
55
|
+
if (this.accessToken && Date.now() < this.expiresAt - REFRESH_MARGIN_MS) {
|
|
72
56
|
return this.accessToken;
|
|
73
57
|
}
|
|
58
|
+
if (!this.inFlight) {
|
|
59
|
+
this.inFlight = this.fetchToken().finally(() => {
|
|
60
|
+
this.inFlight = null;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return this.inFlight;
|
|
64
|
+
}
|
|
74
65
|
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
this.keyData.key,
|
|
85
|
-
{ algorithm: 'RS256', keyid: this.keyData.keyId },
|
|
86
|
-
);
|
|
66
|
+
private async fetchToken(): Promise<string> {
|
|
67
|
+
const { tokenUrl, clientId, clientSecret, scopes, audience } = this.options;
|
|
68
|
+
const form = new URLSearchParams({
|
|
69
|
+
grant_type: 'client_credentials',
|
|
70
|
+
client_id: clientId,
|
|
71
|
+
client_secret: clientSecret,
|
|
72
|
+
});
|
|
73
|
+
if (scopes && scopes.length > 0) form.set('scope', scopes.join(' '));
|
|
74
|
+
if (audience) form.set('audience', audience);
|
|
87
75
|
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
assertion,
|
|
94
|
-
}),
|
|
95
|
-
{
|
|
96
|
-
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
76
|
+
const requestedAt = Date.now();
|
|
77
|
+
const response = await axios.post<string>(tokenUrl, form.toString(), {
|
|
78
|
+
headers: {
|
|
79
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
80
|
+
Accept: 'application/json',
|
|
97
81
|
},
|
|
98
|
-
|
|
82
|
+
responseType: 'text',
|
|
83
|
+
validateStatus: () => true,
|
|
84
|
+
});
|
|
85
|
+
if (response.status < 200 || response.status > 299) {
|
|
86
|
+
throw new Error(`quantumbpm: token request failed (${response.status}): ${response.data}`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let body: { access_token?: unknown; expires_in?: unknown };
|
|
90
|
+
try {
|
|
91
|
+
body = JSON.parse(response.data);
|
|
92
|
+
} catch {
|
|
93
|
+
throw new Error(`quantumbpm: token response is not JSON: ${response.data}`);
|
|
94
|
+
}
|
|
95
|
+
if (typeof body.access_token !== 'string' || !body.access_token) {
|
|
96
|
+
throw new Error('quantumbpm: token response has no access_token');
|
|
97
|
+
}
|
|
98
|
+
const expiresIn = body.expires_in == null ? DEFAULT_LIFETIME_S : Number(body.expires_in);
|
|
99
|
+
if (!Number.isFinite(expiresIn)) {
|
|
100
|
+
throw new Error(`quantumbpm: token response has an invalid expires_in: ${body.expires_in}`);
|
|
101
|
+
}
|
|
99
102
|
|
|
100
|
-
this.accessToken =
|
|
101
|
-
this.expiresAt =
|
|
103
|
+
this.accessToken = body.access_token;
|
|
104
|
+
this.expiresAt = requestedAt + expiresIn * 1000;
|
|
102
105
|
return this.accessToken;
|
|
103
106
|
}
|
|
104
107
|
}
|
package/src/bpmn.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { RawClient } from './generated/RawClient';
|
|
2
|
+
import { BpmnActivityState } from './generated/models/BpmnActivityState';
|
|
3
|
+
import { BpmnHistoryPage } from './generated/models/BpmnHistoryPage';
|
|
2
4
|
import { BpmnInstancePaginatedResponse } from './generated/models/BpmnInstancePaginatedResponse';
|
|
3
5
|
import { BpmnInstanceChildrenResponse } from './generated/models/BpmnInstanceChildrenResponse';
|
|
4
6
|
import { BpmnInstanceState } from './generated/models/BpmnInstanceState';
|
|
5
7
|
import { BpmnProcessSummaryPaginatedResponse } from './generated/models/BpmnProcessSummaryPaginatedResponse';
|
|
8
|
+
import { BpmnProcessVersion } from './generated/models/BpmnProcessVersion';
|
|
6
9
|
import { BpmnProcessVersionPaginatedResponse } from './generated/models/BpmnProcessVersionPaginatedResponse';
|
|
7
10
|
import { BpmnResourceDetail } from './generated/models/BpmnResourceDetail';
|
|
8
11
|
import { BpmnResourcePaginatedResponse } from './generated/models/BpmnResourcePaginatedResponse';
|
|
@@ -17,10 +20,13 @@ import { Vars } from './variables';
|
|
|
17
20
|
|
|
18
21
|
/** Re-exported entity types so callers don't depend on the generated package. */
|
|
19
22
|
export type {
|
|
23
|
+
BpmnActivityState,
|
|
24
|
+
BpmnHistoryPage,
|
|
20
25
|
BpmnInstancePaginatedResponse,
|
|
21
26
|
BpmnInstanceChildrenResponse,
|
|
22
27
|
BpmnInstanceState,
|
|
23
28
|
BpmnProcessSummaryPaginatedResponse,
|
|
29
|
+
BpmnProcessVersion,
|
|
24
30
|
BpmnProcessVersionPaginatedResponse,
|
|
25
31
|
BpmnResourceDetail,
|
|
26
32
|
BpmnResourcePaginatedResponse,
|
|
@@ -37,9 +43,20 @@ export interface PageOptions {
|
|
|
37
43
|
pageSize?: number;
|
|
38
44
|
}
|
|
39
45
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
/** Paging of a list the API pages by cursor. */
|
|
47
|
+
export interface CursorOptions {
|
|
48
|
+
/** The `pagination.nextCursor` of the page before, omitted for the first page. */
|
|
49
|
+
cursor?: string;
|
|
50
|
+
/** Most rows per page, 20 by default and 100 at most. */
|
|
51
|
+
limit?: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface InstanceListOptions extends CursorOptions {
|
|
55
|
+
/** Instances of every version of this process id, unless `version` names one. */
|
|
56
|
+
processId?: string;
|
|
57
|
+
/** Instances of this version of `processId`. Ignored without `processId`. */
|
|
58
|
+
version?: number;
|
|
59
|
+
status?: 'RUNNING' | 'COMPLETED' | 'FAILED' | 'CANCELED' | 'TERMINATED';
|
|
43
60
|
/**
|
|
44
61
|
* Filter by incident presence. `true` shows only instances that
|
|
45
62
|
* need operator attention; `false` excludes them; omit for all.
|
|
@@ -56,14 +73,30 @@ export interface InstanceListOptions extends PageOptions {
|
|
|
56
73
|
*/
|
|
57
74
|
createdAfter?: string;
|
|
58
75
|
/**
|
|
59
|
-
*
|
|
76
|
+
* Prefix filter on the caller-supplied correlation key set
|
|
60
77
|
* at startInstance time.
|
|
61
78
|
*/
|
|
62
79
|
businessId?: string;
|
|
80
|
+
/** `true` keeps only test runs, `false` leaves them out. Omit for both. */
|
|
81
|
+
draft?: boolean;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The due date range and order of a user task list. */
|
|
85
|
+
export interface UserTaskScheduleOptions extends CursorOptions {
|
|
86
|
+
/** Tasks due at or after this time (RFC 3339). */
|
|
87
|
+
dueAfter?: string;
|
|
88
|
+
/** Tasks due before this time (RFC 3339). With `status: 'CREATED'` and now, the overdue tasks. */
|
|
89
|
+
dueBefore?: string;
|
|
90
|
+
/**
|
|
91
|
+
* `created` lists the newest first, the default. `dueDate` lists the
|
|
92
|
+
* soonest due first, `priority` the highest priority first. A cursor
|
|
93
|
+
* continues only a list of the same sort.
|
|
94
|
+
*/
|
|
95
|
+
sort?: 'created' | 'dueDate' | 'priority';
|
|
63
96
|
}
|
|
64
97
|
|
|
65
|
-
export interface UserTaskListOptions extends
|
|
66
|
-
|
|
98
|
+
export interface UserTaskListOptions extends UserTaskScheduleOptions {
|
|
99
|
+
instanceId?: string;
|
|
67
100
|
status?: 'CREATED' | 'COMPLETED' | 'CANCELED' | 'FAILED';
|
|
68
101
|
assignee?: string;
|
|
69
102
|
candidateUser?: string;
|
|
@@ -82,6 +115,18 @@ export interface StartInstanceOptions {
|
|
|
82
115
|
* DMN execution emitted by the resulting process.
|
|
83
116
|
*/
|
|
84
117
|
businessId?: string;
|
|
118
|
+
/** Deployed version to start, the latest when omitted. startTestInstance ignores it. */
|
|
119
|
+
version?: number;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Which window of an instance's history to read. Omit both seqs for the newest entries. */
|
|
123
|
+
export interface HistoryOptions {
|
|
124
|
+
/** Read the entries from this seq on, to follow a running instance. Takes precedence over `beforeSeq`. */
|
|
125
|
+
fromSeq?: number;
|
|
126
|
+
/** Read the newest entries before this seq, to walk back. */
|
|
127
|
+
beforeSeq?: number;
|
|
128
|
+
/** Most entries per page. */
|
|
129
|
+
limit?: number;
|
|
85
130
|
}
|
|
86
131
|
|
|
87
132
|
export interface ProcessListOptions extends PageOptions {
|
|
@@ -140,9 +185,9 @@ export class BpmnClient {
|
|
|
140
185
|
}
|
|
141
186
|
|
|
142
187
|
/**
|
|
143
|
-
*
|
|
144
|
-
* the
|
|
145
|
-
*
|
|
188
|
+
* Deploy a draft. After this returns, the resource's `processes` field
|
|
189
|
+
* lists the process versions it deployed, and startInstance can start
|
|
190
|
+
* them by process ID.
|
|
146
191
|
*/
|
|
147
192
|
async deployResource(resourceId: string): Promise<void> {
|
|
148
193
|
await this.raw.bpmn.deployBpmnResource(this.projectId, resourceId);
|
|
@@ -155,10 +200,10 @@ export class BpmnClient {
|
|
|
155
200
|
variables: vars.toWireMap() as any,
|
|
156
201
|
businessId: opts.businessId,
|
|
157
202
|
});
|
|
158
|
-
if (!resp.
|
|
159
|
-
throw new Error('bpmn: startTestInstance returned no
|
|
203
|
+
if (!resp.instanceID) {
|
|
204
|
+
throw new Error('bpmn: startTestInstance returned no instanceID');
|
|
160
205
|
}
|
|
161
|
-
return resp.
|
|
206
|
+
return resp.instanceID;
|
|
162
207
|
}
|
|
163
208
|
|
|
164
209
|
/** Lint a BPMN XML document without storing or deploying it. */
|
|
@@ -183,68 +228,92 @@ export class BpmnClient {
|
|
|
183
228
|
|
|
184
229
|
// --- Instances ----------------------------------------------------------
|
|
185
230
|
|
|
186
|
-
/**
|
|
187
|
-
|
|
231
|
+
/**
|
|
232
|
+
* Launch a new instance of a deployed process, its latest version unless
|
|
233
|
+
* `opts.version` names one. Returns the instance ID.
|
|
234
|
+
*/
|
|
235
|
+
async startInstance(processId: string, vars: Vars, opts: StartInstanceOptions = {}): Promise<string> {
|
|
188
236
|
const resp = await this.raw.default.startBpmnInstance(this.projectId, {
|
|
189
|
-
|
|
237
|
+
processID: processId,
|
|
238
|
+
version: opts.version,
|
|
190
239
|
variables: vars.toWireMap() as any,
|
|
191
240
|
businessId: opts.businessId,
|
|
192
241
|
});
|
|
193
|
-
if (!resp.
|
|
194
|
-
throw new Error('bpmn: startInstance returned no
|
|
242
|
+
if (!resp.instanceID) {
|
|
243
|
+
throw new Error('bpmn: startInstance returned no instanceID');
|
|
195
244
|
}
|
|
196
|
-
return resp.
|
|
245
|
+
return resp.instanceID;
|
|
197
246
|
}
|
|
198
247
|
|
|
199
248
|
/** Full runtime state of an instance. */
|
|
200
|
-
async getInstance(
|
|
201
|
-
return this.raw.default.getBpmnInstance(this.projectId,
|
|
249
|
+
async getInstance(instanceId: string): Promise<BpmnInstanceState> {
|
|
250
|
+
return this.raw.default.getBpmnInstance(this.projectId, instanceId);
|
|
202
251
|
}
|
|
203
252
|
|
|
204
253
|
/** Terminate a running instance. */
|
|
205
|
-
async cancelInstance(
|
|
206
|
-
await this.raw.default.cancelBpmnInstance(this.projectId,
|
|
254
|
+
async cancelInstance(instanceId: string): Promise<void> {
|
|
255
|
+
await this.raw.default.cancelBpmnInstance(this.projectId, instanceId);
|
|
207
256
|
}
|
|
208
257
|
|
|
209
|
-
/**
|
|
258
|
+
/**
|
|
259
|
+
* Page of instances in the project, newest first. Pass the page's
|
|
260
|
+
* `pagination.nextCursor` as `cursor` for the next one. It is absent on
|
|
261
|
+
* the last page.
|
|
262
|
+
*/
|
|
210
263
|
async listInstances(opts: InstanceListOptions = {}): Promise<BpmnInstancePaginatedResponse> {
|
|
211
|
-
// Generated signature order: (projectId,
|
|
212
|
-
//
|
|
213
|
-
// Positional call - keep the order in sync with the regenerated client.
|
|
264
|
+
// Generated signature order: (projectId, status, hasIncident,
|
|
265
|
+
// suspended, createdAfter, businessId, processId, version, draft,
|
|
266
|
+
// cursor, limit). Positional call - keep the order in sync with the regenerated client.
|
|
214
267
|
return this.raw.default.listBpmnInstances(
|
|
215
268
|
this.projectId,
|
|
216
|
-
opts.definitionId,
|
|
217
269
|
opts.status,
|
|
218
270
|
opts.hasIncident,
|
|
219
271
|
opts.suspended,
|
|
220
272
|
opts.createdAfter,
|
|
221
273
|
opts.businessId,
|
|
222
|
-
opts.
|
|
223
|
-
opts.
|
|
274
|
+
opts.processId,
|
|
275
|
+
opts.version,
|
|
276
|
+
opts.draft,
|
|
277
|
+
opts.cursor,
|
|
278
|
+
opts.limit,
|
|
224
279
|
);
|
|
225
280
|
}
|
|
226
281
|
|
|
227
282
|
/** Children spawned via CallActivity. */
|
|
228
|
-
async getInstanceChildren(
|
|
229
|
-
return this.raw.bpmn.getBpmnInstanceChildren(this.projectId,
|
|
283
|
+
async getInstanceChildren(instanceId: string): Promise<BpmnInstanceChildrenResponse> {
|
|
284
|
+
return this.raw.bpmn.getBpmnInstanceChildren(this.projectId, instanceId);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Page of an instance's history, oldest first, for a running or an ended
|
|
289
|
+
* instance. Page entries leave out `inputs` and `outputs`, which
|
|
290
|
+
* getInstanceHistoryEntry() reads.
|
|
291
|
+
*/
|
|
292
|
+
async getInstanceHistory(instanceId: string, opts: HistoryOptions = {}): Promise<BpmnHistoryPage> {
|
|
293
|
+
return this.raw.bpmn.getBpmnInstanceHistory(this.projectId, instanceId, opts.fromSeq, opts.beforeSeq, opts.limit);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** One history entry with its inputs and outputs. */
|
|
297
|
+
async getInstanceHistoryEntry(instanceId: string, seq: number): Promise<BpmnActivityState> {
|
|
298
|
+
return this.raw.bpmn.getBpmnInstanceHistoryEntry(this.projectId, instanceId, seq);
|
|
230
299
|
}
|
|
231
300
|
|
|
232
301
|
/** Current variables of an instance. */
|
|
233
|
-
async getInstanceVariables(
|
|
234
|
-
const resp = await this.raw.bpmn.getBpmnInstanceVariables(this.projectId,
|
|
302
|
+
async getInstanceVariables(instanceId: string): Promise<Vars> {
|
|
303
|
+
const resp = await this.raw.bpmn.getBpmnInstanceVariables(this.projectId, instanceId);
|
|
235
304
|
return Vars.fromWireMap(resp.variables);
|
|
236
305
|
}
|
|
237
306
|
|
|
238
307
|
/** Merge variables into the instance scope. */
|
|
239
|
-
async updateInstanceVariables(
|
|
240
|
-
await this.raw.bpmn.updateBpmnInstanceVariables(this.projectId,
|
|
308
|
+
async updateInstanceVariables(instanceId: string, vars: Vars): Promise<void> {
|
|
309
|
+
await this.raw.bpmn.updateBpmnInstanceVariables(this.projectId, instanceId, {
|
|
241
310
|
variables: (vars.toWireMap() ?? {}) as any,
|
|
242
311
|
});
|
|
243
312
|
}
|
|
244
313
|
|
|
245
314
|
/** Resolve an incident, optionally merging supplementary variables. */
|
|
246
|
-
async resolveIncident(
|
|
247
|
-
await this.raw.bpmn.resolveBpmnIncident(this.projectId,
|
|
315
|
+
async resolveIncident(instanceId: string, incidentId: string, vars: Vars = new Vars()): Promise<void> {
|
|
316
|
+
await this.raw.bpmn.resolveBpmnIncident(this.projectId, instanceId, incidentId, {
|
|
248
317
|
variables: vars.toWireMap() as any,
|
|
249
318
|
});
|
|
250
319
|
}
|
|
@@ -270,23 +339,37 @@ export class BpmnClient {
|
|
|
270
339
|
|
|
271
340
|
// --- User tasks ---------------------------------------------------------
|
|
272
341
|
|
|
342
|
+
/**
|
|
343
|
+
* Page of user tasks in the project. Pass the page's
|
|
344
|
+
* `pagination.nextCursor` as `cursor` for the next one.
|
|
345
|
+
*/
|
|
273
346
|
async listUserTasks(opts: UserTaskListOptions = {}): Promise<BpmnUserTaskPaginatedResponse> {
|
|
274
347
|
return this.raw.bpmn.listBpmnUserTasks(
|
|
275
348
|
this.projectId,
|
|
276
|
-
opts.
|
|
349
|
+
opts.instanceId,
|
|
277
350
|
opts.status,
|
|
278
351
|
opts.assignee,
|
|
279
352
|
opts.candidateUser,
|
|
280
353
|
opts.candidateGroup,
|
|
281
354
|
opts.businessId,
|
|
282
|
-
opts.
|
|
283
|
-
opts.
|
|
355
|
+
opts.dueAfter,
|
|
356
|
+
opts.dueBefore,
|
|
357
|
+
opts.sort,
|
|
358
|
+
opts.cursor,
|
|
359
|
+
opts.limit,
|
|
284
360
|
);
|
|
285
361
|
}
|
|
286
362
|
|
|
287
|
-
/**
|
|
288
|
-
async listUserTasksForCaller(opts:
|
|
289
|
-
return this.raw.bpmn.listBpmnUserTasksForCaller(
|
|
363
|
+
/** Page of the user tasks the caller may claim or has already claimed. */
|
|
364
|
+
async listUserTasksForCaller(opts: UserTaskScheduleOptions = {}): Promise<BpmnUserTaskPaginatedResponse> {
|
|
365
|
+
return this.raw.bpmn.listBpmnUserTasksForCaller(
|
|
366
|
+
this.projectId,
|
|
367
|
+
opts.dueAfter,
|
|
368
|
+
opts.dueBefore,
|
|
369
|
+
opts.sort,
|
|
370
|
+
opts.cursor,
|
|
371
|
+
opts.limit,
|
|
372
|
+
);
|
|
290
373
|
}
|
|
291
374
|
|
|
292
375
|
async getUserTask(executionKey: string): Promise<UserTask> {
|
|
@@ -331,4 +414,9 @@ export class BpmnClient {
|
|
|
331
414
|
opts.createdAfter,
|
|
332
415
|
);
|
|
333
416
|
}
|
|
417
|
+
|
|
418
|
+
/** One deployed version of a process id with its instance counts and suspension state. */
|
|
419
|
+
async getProcessVersion(processId: string, version: number, opts: { createdAfter?: string } = {}): Promise<BpmnProcessVersion> {
|
|
420
|
+
return this.raw.bpmn.getBpmnProcessVersion(this.projectId, processId, version, opts.createdAfter);
|
|
421
|
+
}
|
|
334
422
|
}
|
package/src/dmn.ts
CHANGED
|
@@ -66,25 +66,6 @@ export class DmnClient {
|
|
|
66
66
|
);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
/**
|
|
70
|
-
* Run a stored DMN definition addressed by its platform UUID. Prefer
|
|
71
|
-
* evaluate() (by definitions ID) for normal use; this overload is for
|
|
72
|
-
* callers that already hold a specific version pointer.
|
|
73
|
-
*/
|
|
74
|
-
async evaluateById(
|
|
75
|
-
definitionId: string,
|
|
76
|
-
vars: Vars,
|
|
77
|
-
opts: EvaluateOptions = {},
|
|
78
|
-
): Promise<DmnResult> {
|
|
79
|
-
return this.raw.default.evaluateStored(this.projectId, definitionId, {
|
|
80
|
-
context: vars.toFeelContext(),
|
|
81
|
-
version: opts.version,
|
|
82
|
-
decisions: opts.decisions,
|
|
83
|
-
decisionServices: opts.decisionServices,
|
|
84
|
-
businessId: opts.businessId,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
69
|
/** Run ad-hoc DMN XML against an input context. The XML is not stored. */
|
|
89
70
|
async evaluateDesign(
|
|
90
71
|
xml: string,
|
|
@@ -15,7 +15,7 @@ export class RawClient {
|
|
|
15
15
|
constructor(config?: Partial<OpenAPIConfig>, HttpRequest: HttpRequestConstructor = AxiosHttpRequest) {
|
|
16
16
|
this.request = new HttpRequest({
|
|
17
17
|
BASE: config?.BASE ?? '',
|
|
18
|
-
VERSION: config?.VERSION ?? '
|
|
18
|
+
VERSION: config?.VERSION ?? '2.0.1',
|
|
19
19
|
WITH_CREDENTIALS: config?.WITH_CREDENTIALS ?? false,
|
|
20
20
|
CREDENTIALS: config?.CREDENTIALS ?? 'include',
|
|
21
21
|
TOKEN: config?.TOKEN,
|