-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ts
396 lines (368 loc) · 11.3 KB
/
test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
import { IntunedClient } from "./src/index";
import {
AuthSessionCreateDoneResult,
AuthSessionCreateFailedResult,
AuthSessionCreateResult,
FileSource,
FileT,
} from "./src/models/components";
async function testJobs(client: IntunedClient, projectName: string) {
const jobId = "this-is-a-test";
const jobs = client.project.jobs;
await jobs.delete(projectName, jobId).catch(() => {});
const allJobs = await jobs.all(projectName);
console.log("Get all jobs", allJobs);
const job = await jobs.create(projectName, {
id: jobId,
configuration: {
runMode: "Order-Irrelevant",
},
sink: {
type: "webhook",
url: "https://webhook.site/7f1b3b7b-1b7b-4b7b-8b7b-9b7b7b7b7b7b",
headers: {
test: "test",
},
},
payload: [
{
apiName: "api",
parameters: {},
},
],
});
console.log("Create job", job);
const getJob = await jobs.one(projectName, jobId);
console.log("Get job", getJob);
const triggerJob1 = await jobs.trigger(projectName, jobId);
console.log("Trigger job 1", triggerJob1);
const runs1 = await jobs.runs.all(projectName, jobId);
console.log("Get runs 1", runs1);
const pauseJob = await jobs.pause(projectName, jobId);
console.log("Pause job", pauseJob);
const getJob2 = await jobs.one(projectName, jobId);
console.log("Get job 2", getJob2);
const triggerJob2 = await jobs
.trigger(projectName, jobId)
.catch((error) => error);
console.log("Trigger job 2", triggerJob2);
const resumeJob = await jobs.resume(projectName, jobId);
console.log("Resume job", resumeJob);
const triggerJob3 = await jobs
.trigger(projectName, jobId)
.catch((error) => error);
console.log("Trigger job 3", triggerJob3);
const runs2 = await jobs.runs.all(projectName, jobId);
console.log("Get runs 2", runs2);
runs2.sort((a, b) => a.startTime.getTime() - b.startTime.getTime());
const lastRun = runs2[runs2.length - 1];
const terminateRun = await jobs.runs.terminate(
projectName,
jobId,
lastRun!.id
);
console.log("Terminate run", terminateRun);
const deleteJob = await jobs.delete(projectName, jobId);
console.log("Delete job", deleteJob);
}
async function testQueues(client: IntunedClient, projectName: string) {
const queueId = "this-is-a-test";
const queues = client.project.queues;
// const queue = await queues.create(projectName, {
// configuration: {
// runMode: "Default",
// },
// authSession: {
// id: "new-session-1723983735880",
// },
// id: queueId,
// });
// console.log("Create queue", queue);
// const hmm = await queues.delete(projectName, queueId);
// console.log("Delete queue", hmm);
const allQueues = await queues.all(projectName);
console.log("Get all queues", allQueues);
const getQueue = await queues.one(projectName, queueId);
console.log("Get queue", getQueue);
const appendItem = await queues.items.append(projectName, queueId, {
apiName: "sample",
parameters: {},
});
// console.log("Append item", appendItem);
// // const deleteItem = await queues.items.delete(projectName, queueId, appendItem.runId);
// // console.log("Delete item", deleteItem);
// async function appendAndGetResult(apiName: string) {
// const appendItem = await queues.items.append(projectName, queueId, {
// apiName,
// parameters: {},
// });
// console.log("Append item", appendItem);
// while (true) {
// await new Promise((resolve) => setTimeout(resolve, 6000));
// const getResult = await queues.items.result(
// projectName,
// queueId,
// appendItem.runId
// );
// console.log("Get result", getResult);
// if (getResult.status === "completed" || getResult.status === "failed") {
// break;
// }
// }
// return appendItem.runId;
// }
// const [appendSuccess, appendFail] = await Promise.all([
// appendAndGetResult("api"),
// appendAndGetResult("api2"),
// ]);
// await queues.items
// .delete(projectName, queueId, appendSuccess)
// .catch((error) => console.log("Delete success item", error));
// await queues.items
// .delete(projectName, queueId, appendFail)
// .catch((error) => console.log("Delete fail item", error));
// const repeatItemAppend = await queues.repeatItems.append(
// projectName,
// queueId,
// {
// apiName: "api",
// parameters: {},
// repeat: "10 minutes",
// }
// );
// console.log("Repeat item append", repeatItemAppend);
// const repeatItemsGet = await queues.repeatItems.all(projectName, queueId);
// console.log("Get repeat items", repeatItemsGet);
// const repeatItemUpdate = await queues.repeatItems.update(
// projectName,
// queueId,
// repeatItemAppend.id,
// {
// apiName: "api",
// parameters: {},
// repeat: "20 minutes",
// }
// );
// console.log("Repeat item update", repeatItemUpdate);
// const repeatItemDelete = await queues.repeatItems.delete(
// projectName,
// queueId,
// repeatItemAppend.id
// );
// console.log("Repeat item delete", repeatItemDelete);
// const deleteQueue = await queues.delete(projectName, queueId);
// console.log("Delete queue", deleteQueue);
}
async function testRun(client: IntunedClient, projectName: string) {
const run = client.project.run;
async function sync() {
const syncRun = await run.sync(projectName, {
api: "api",
parameters: {},
});
console.log("Sync run", syncRun);
}
async function async() {
const startRun = await run.start(projectName, {
api: "api",
parameters: {},
});
console.log("Start run", startRun);
while (true) {
await new Promise((resolve) => setTimeout(resolve, 6000));
const getRun = await run.result(projectName, startRun.runId);
console.log("Get run", getRun);
if (getRun.status === "completed" || getRun.status === "failed") {
break;
}
}
}
await Promise.all([sync(), async()]);
}
const xx = {};
type x = typeof xx;
async function testAuthSessions(client: IntunedClient, projectName: string) {
const authSessions = client.project.authSessions;
const startCreate = await authSessions.create.start(projectName, {
authSessionDisplayName: "Test Auth Session",
parameters: {
test: "",
},
});
console.log("Start create auth session", startCreate);
let previousResult: AuthSessionCreateResult | undefined;
let result: AuthSessionCreateDoneResult | AuthSessionCreateFailedResult;
while (true) {
await new Promise((resolve) => setTimeout(resolve, 6000));
if (previousResult === undefined || previousResult.status === "pending") {
const getCreate = await authSessions.create.result(
projectName,
startCreate.operationId!
);
console.log("Get create auth session", getCreate);
previousResult = getCreate;
continue;
}
if (previousResult.status === "requested_more_info") {
const resumeCreate = await authSessions.create.resume(
projectName,
startCreate.operationId!,
{
infoRequestId: previousResult.id,
input: "anything",
}
);
console.log("Resume create", resumeCreate);
previousResult = undefined;
continue;
}
result = previousResult;
break;
}
const getAll = await authSessions.all(projectName);
console.log("Get all auth sessions", getAll);
if (result.status === "failed") {
return;
}
const getOne = await authSessions.one(projectName, result.authSessionId);
console.log("Get one auth session", getOne);
const deleteR = await authSessions.delete(projectName, result.authSessionId);
console.log("Delete auth session", deleteR);
}
async function testFiles(client: IntunedClient) {
const files = client.files;
const source: FileSource = {
type: "url",
data: "https://github.com/Intuned/file-api-eval/blob/main/pdf/pdf_example.pdf?raw=true",
};
const file: FileT = {
type: "pdf",
source,
};
async function markdownSync() {
const sync = await files.extractMarkdown.sync(file);
console.log("Markdown sync", sync);
}
async function markdownAsync() {
const start = await files.extractMarkdown.start(file);
console.log("Markdown start", start);
while (true) {
await new Promise((resolve) => setTimeout(resolve, 6000));
const get = await files.extractMarkdown.result(start.operationId);
console.log("Markdown get", get);
if (get.status === "completed" || get.status === "failed") {
break;
}
}
}
async function tablesSync() {
const sync = await files.extractTables.sync(file);
console.log("Tables sync", sync);
}
async function tablesAsync() {
const start = await files.extractTables.start(file);
console.log("Tables start", start);
while (true) {
await new Promise((resolve) => setTimeout(resolve, 6000));
const get = await files.extractTables.result(start.operationId);
console.log("Tables get", get);
if (get.status === "completed" || get.status === "failed") {
break;
}
}
}
const dataSchema = {
type: "object",
required: ["materialOrService", "title", "contractId"],
properties: {
materialOrService: {
type: "string",
enum: ["Material", "Service"],
description: "Material or Service",
},
title: {
type: "string",
},
contractIds: {
type: "array",
items: {
type: "string",
},
},
numberOfSuppliers: {
type: "number",
},
pCardEnabled: {
type: "boolean",
},
pCardAccepted: {
type: "boolean",
},
mscc: {
type: "boolean",
},
validityPeriod: {
type: "object",
required: ["start", "end"],
properties: {
start: {
type: "string",
format: "date",
},
end: {
type: "string",
format: "date",
},
},
},
pointOfContact: {
type: "string",
},
contactPhoneNumber: {
type: "string",
},
email: {
type: "string",
format: "email",
},
},
};
async function dataSync() {
const sync = await files.extractStructuredData.sync(file, dataSchema);
console.log("Data sync", sync);
}
async function dataAsync() {
const start = await files.extractStructuredData.start(file, dataSchema);
console.log("Data start", start);
while (true) {
await new Promise((resolve) => setTimeout(resolve, 6000));
const get = await files.extractStructuredData.result(start.operationId);
console.log("Data get", get);
if (get.status === "completed" || get.status === "failed") {
break;
}
}
}
await Promise.all([
markdownSync(),
markdownAsync(),
tablesSync(),
tablesAsync(),
dataSync(),
dataAsync(),
]);
}
async function main() {
const client = new IntunedClient({
serverURL: "http://dev.intuned.io/api/v1/workspace",
workspaceId: "3118faad-61c0-4206-a552-b0d692c58025",
apiKey: "in1_5ee03386c9e5b9ae9155e353ef7e64e9",
});
// const projectName = 'queue-test-integration';
// await testJobs(client, "ok");
await testQueues(client, "test-auth");
// await testRun(client, "ok");
// await testFiles(client);
// await testAuthSessions(client, "another-test");
}
main();