Skip to content

Commit a35f728

Browse files
authored
Merge pull request #13 from yepcode/feature/YEP-3018
YEP-3018 Fix and update rest methods
2 parents 4256b33 + 10cb6a1 commit a35f728

3 files changed

Lines changed: 186 additions & 13 deletions

File tree

src/api/types.ts

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@ export interface YepCodeApiConfig {
1212

1313
export interface CreateProcessInput {
1414
name: string;
15+
slug?: string;
1516
description?: string;
1617
readme?: string;
18+
programmingLanguage?: "JAVASCRIPT" | "PYTHON";
19+
sourceCode?: string;
20+
parametersSchema?: string;
21+
webhook?: WebhookInput;
1722
manifest?: ProcessManifestInput;
1823
settings?: SettingsInput;
1924
script?: CreateScriptInput;
@@ -51,7 +56,15 @@ export interface Execution {
5156
id: string;
5257
processId: string;
5358
scheduledId?: string;
54-
status: "CREATED" | "RUNNING" | "FINISHED" | "KILLED" | "REJECTED" | "ERROR";
59+
status:
60+
| "CREATED"
61+
| "QUEUED"
62+
| "DEQUEUED"
63+
| "RUNNING"
64+
| "FINISHED"
65+
| "KILLED"
66+
| "REJECTED"
67+
| "ERROR";
5568
timeline?: ExecutionTimeline;
5669
parameters?: {
5770
[name: string]: {
@@ -85,7 +98,15 @@ export interface ExecutionTimeline {
8598
events?: ExecutionTimelineEvent[];
8699
}
87100
export interface ExecutionTimelineEvent {
88-
status: "CREATED" | "RUNNING" | "FINISHED" | "KILLED" | "REJECTED" | "ERROR";
101+
status:
102+
| "CREATED"
103+
| "QUEUED"
104+
| "DEQUEUED"
105+
| "RUNNING"
106+
| "FINISHED"
107+
| "KILLED"
108+
| "REJECTED"
109+
| "ERROR";
89110
timestamp: string;
90111
explanation?: string;
91112
}
@@ -226,10 +247,12 @@ export interface TeamVariablesPaginatedResult {
226247
data?: TeamVariable[];
227248
}
228249
export interface UpdateProcessInput {
229-
name: string;
230-
slug: string;
250+
name?: string;
251+
slug?: string;
231252
description?: string;
232253
readme?: string;
254+
sourceCode?: string;
255+
parametersSchema?: string;
233256
script?: UpdateScriptInput;
234257
webhook?: WebhookInput;
235258
settings?: SettingsInput;
@@ -313,6 +336,8 @@ export interface Module {
313336

314337
export interface CreateModuleInput {
315338
name: string;
339+
programmingLanguage?: "JAVASCRIPT" | "PYTHON";
340+
sourceCode?: string;
316341
script?: {
317342
programmingLanguage?: string;
318343
sourceCode?: string;
@@ -321,6 +346,7 @@ export interface CreateModuleInput {
321346

322347
export interface UpdateModuleInput {
323348
name?: string;
349+
sourceCode?: string;
324350
script?: {
325351
programmingLanguage?: string;
326352
sourceCode?: string;
@@ -349,6 +375,10 @@ export interface VersionedModule {
349375
export interface PublishModuleInput {
350376
tag: string;
351377
comment?: string;
378+
sourceCode?: string;
379+
script?: {
380+
sourceCode?: string;
381+
};
352382
}
353383

354384
export interface VersionedModulesPaginatedResult {
@@ -392,10 +422,38 @@ export type StorageObject = {
392422
contentType: string;
393423
createdAt: string;
394424
updatedAt: string;
395-
link: URL;
425+
link: string;
396426
};
397427

398428
export type CreateStorageObjectInput = {
399429
name: string;
400430
file: File | Blob | Readable;
401431
};
432+
433+
/**
434+
* Auth
435+
*/
436+
export interface Token {
437+
access_token: string;
438+
expires_in: number;
439+
token_type: string;
440+
scope?: string;
441+
}
442+
443+
export interface ServiceAccountInput {
444+
name: string;
445+
}
446+
447+
export interface ServiceAccount {
448+
id: string;
449+
createdAt: string;
450+
updatedAt: string;
451+
name: string;
452+
clientId: string;
453+
clientSecret: string;
454+
}
455+
456+
export interface ServiceAccountsListResult {
457+
total: number;
458+
data: ServiceAccount[];
459+
}

src/api/yepcodeApi.ts

Lines changed: 121 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ import {
3333
VersionedModuleAliasesPaginatedResult,
3434
StorageObject,
3535
CreateStorageObjectInput,
36+
Token,
37+
ServiceAccountInput,
38+
ServiceAccount,
39+
ServiceAccountsListResult,
3640
} from "./types";
3741
import { Readable } from "stream";
3842

@@ -343,6 +347,23 @@ export class YepCodeApi {
343347
return this.request("POST", `/processes/${processId}/versions`, { data });
344348
}
345349

350+
async getProcessVersion(
351+
processId: string,
352+
versionId: string
353+
): Promise<VersionedProcess> {
354+
return this.request("GET", `/processes/${processId}/versions/${versionId}`);
355+
}
356+
357+
async deleteProcessVersion(
358+
processId: string,
359+
versionId: string
360+
): Promise<void> {
361+
return this.request(
362+
"DELETE",
363+
`/processes/${processId}/versions/${versionId}`
364+
);
365+
}
366+
346367
async getProcessVersionAliases(
347368
processId: string,
348369
params: {
@@ -361,6 +382,30 @@ export class YepCodeApi {
361382
return this.request("POST", `/processes/${processId}/aliases`, { data });
362383
}
363384

385+
async getProcessVersionAlias(
386+
processId: string,
387+
aliasId: string
388+
): Promise<VersionedProcessAlias> {
389+
return this.request("GET", `/processes/${processId}/aliases/${aliasId}`);
390+
}
391+
392+
async updateProcessVersionAlias(
393+
processId: string,
394+
aliasId: string,
395+
data: VersionedProcessAliasInput
396+
): Promise<VersionedProcessAlias> {
397+
return this.request("PATCH", `/processes/${processId}/aliases/${aliasId}`, {
398+
data,
399+
});
400+
}
401+
402+
async deleteProcessVersionAlias(
403+
processId: string,
404+
aliasId: string
405+
): Promise<void> {
406+
return this.request("DELETE", `/processes/${processId}/aliases/${aliasId}`);
407+
}
408+
364409
async getProcesses(
365410
params: {
366411
keywords?: string;
@@ -439,6 +484,8 @@ export class YepCodeApi {
439484
processId?: string;
440485
status?:
441486
| "CREATED"
487+
| "QUEUED"
488+
| "DEQUEUED"
442489
| "RUNNING"
443490
| "FINISHED"
444491
| "KILLED"
@@ -509,6 +556,13 @@ export class YepCodeApi {
509556
return this.request("PUT", `/schedules/${id}/resume`);
510557
}
511558

559+
async updateSchedule(
560+
id: string,
561+
data: ScheduledProcessInput
562+
): Promise<Schedule> {
563+
return this.request("PATCH", `/schedules/${id}`, { data });
564+
}
565+
512566
async getVariables(
513567
params: {
514568
page?: number;
@@ -580,6 +634,20 @@ export class YepCodeApi {
580634
return this.request("POST", `/modules/${moduleId}/versions`, { data });
581635
}
582636

637+
async getModuleVersion(
638+
moduleId: string,
639+
versionId: string
640+
): Promise<VersionedModule> {
641+
return this.request("GET", `/modules/${moduleId}/versions/${versionId}`);
642+
}
643+
644+
async deleteModuleVersion(
645+
moduleId: string,
646+
versionId: string
647+
): Promise<void> {
648+
return this.request("DELETE", `/modules/${moduleId}/versions/${versionId}`);
649+
}
650+
583651
async getModuleVersionAliases(
584652
moduleId: string,
585653
params: {
@@ -598,14 +666,36 @@ export class YepCodeApi {
598666
return this.request("POST", `/modules/${moduleId}/aliases`, { data });
599667
}
600668

601-
async getObjects(
602-
params: { prefix?: string } = {}
603-
): Promise<StorageObject[]> {
669+
async getModuleVersionAlias(
670+
moduleId: string,
671+
aliasId: string
672+
): Promise<VersionedModuleAlias> {
673+
return this.request("GET", `/modules/${moduleId}/aliases/${aliasId}`);
674+
}
675+
676+
async updateModuleVersionAlias(
677+
moduleId: string,
678+
aliasId: string,
679+
data: VersionedModuleAliasInput
680+
): Promise<VersionedModuleAlias> {
681+
return this.request("PATCH", `/modules/${moduleId}/aliases/${aliasId}`, {
682+
data,
683+
});
684+
}
685+
686+
async deleteModuleVersionAlias(
687+
moduleId: string,
688+
aliasId: string
689+
): Promise<void> {
690+
return this.request("DELETE", `/modules/${moduleId}/aliases/${aliasId}`);
691+
}
692+
693+
async getObjects(params: { prefix?: string } = {}): Promise<StorageObject[]> {
604694
return this.request("GET", "/storage/objects", { params });
605695
}
606696

607-
async getObject(name: string): Promise<Readable> {
608-
return this.request("GET", `/storage/objects/${name}`, {
697+
async getObject(filename: string): Promise<Readable> {
698+
return this.request("GET", `/storage/objects/${filename}`, {
609699
responseType: "stream",
610700
});
611701
}
@@ -642,15 +732,38 @@ export class YepCodeApi {
642732

643733
return this.request(
644734
"POST",
645-
`/storage/objects?name=${encodeURIComponent(data.name)}`,
735+
`/storage/objects?filename=${encodeURIComponent(data.name)}`,
646736
options
647737
);
648738
}
649739

650-
async deleteObject(name: string): Promise<void> {
740+
async deleteObject(filename: string): Promise<void> {
651741
return this.request(
652742
"DELETE",
653-
`/storage/objects/${encodeURIComponent(name)}`
743+
`/storage/objects/${encodeURIComponent(filename)}`
654744
);
655745
}
746+
747+
// Auth endpoints
748+
async getToken(apiToken: string): Promise<Token> {
749+
return this.request("POST", "/auth/token", {
750+
headers: {
751+
"x-api-token": apiToken,
752+
},
753+
});
754+
}
755+
756+
async getAllServiceAccounts(): Promise<ServiceAccountsListResult> {
757+
return this.request("GET", "/auth/service-accounts");
758+
}
759+
760+
async createServiceAccount(
761+
data: ServiceAccountInput
762+
): Promise<ServiceAccount> {
763+
return this.request("POST", "/auth/service-accounts", { data });
764+
}
765+
766+
async deleteServiceAccount(id: string): Promise<void> {
767+
return this.request("DELETE", `/auth/service-accounts/${id}`);
768+
}
656769
}

src/types/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export interface ExecutionData {
4343

4444
export type ExecutionStatus =
4545
| "CREATED"
46+
| "QUEUED"
47+
| "DEQUEUED"
4648
| "RUNNING"
4749
| "FINISHED"
4850
| "KILLED"

0 commit comments

Comments
 (0)