@optimizely/ocp-cli 1.0.0-beta.2
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/LICENSE +201 -0
- package/README.md +18 -0
- package/bin/opti.js +3 -0
- package/dist/commands/accounts/Whoami.d.ts +3 -0
- package/dist/commands/accounts/Whoami.js +34 -0
- package/dist/commands/accounts/Whoami.js.map +1 -0
- package/dist/commands/accounts/Whois.d.ts +6 -0
- package/dist/commands/accounts/Whois.js +65 -0
- package/dist/commands/accounts/Whois.js.map +1 -0
- package/dist/commands/app/BaseBuildCommand.d.ts +23 -0
- package/dist/commands/app/BaseBuildCommand.js +227 -0
- package/dist/commands/app/BaseBuildCommand.js.map +1 -0
- package/dist/commands/app/Init.d.ts +20 -0
- package/dist/commands/app/Init.js +285 -0
- package/dist/commands/app/Init.js.map +1 -0
- package/dist/commands/app/Logs.d.ts +19 -0
- package/dist/commands/app/Logs.js +230 -0
- package/dist/commands/app/Logs.js.map +1 -0
- package/dist/commands/app/Package.d.ts +4 -0
- package/dist/commands/app/Package.js +51 -0
- package/dist/commands/app/Package.js.map +1 -0
- package/dist/commands/app/Prepare.d.ts +8 -0
- package/dist/commands/app/Prepare.js +112 -0
- package/dist/commands/app/Prepare.js.map +1 -0
- package/dist/commands/app/Register.d.ts +7 -0
- package/dist/commands/app/Register.js +58 -0
- package/dist/commands/app/Register.js.map +1 -0
- package/dist/commands/app/Validate.d.ts +4 -0
- package/dist/commands/app/Validate.js +27 -0
- package/dist/commands/app/Validate.js.map +1 -0
- package/dist/commands/availability/List.d.ts +4 -0
- package/dist/commands/availability/List.js +47 -0
- package/dist/commands/availability/List.js.map +1 -0
- package/dist/commands/directory/Info.d.ts +7 -0
- package/dist/commands/directory/Info.js +92 -0
- package/dist/commands/directory/Info.js.map +1 -0
- package/dist/commands/directory/Install.d.ts +6 -0
- package/dist/commands/directory/Install.js +54 -0
- package/dist/commands/directory/Install.js.map +1 -0
- package/dist/commands/directory/List.d.ts +8 -0
- package/dist/commands/directory/List.js +102 -0
- package/dist/commands/directory/List.js.map +1 -0
- package/dist/commands/directory/ListFunctions.d.ts +7 -0
- package/dist/commands/directory/ListFunctions.js +77 -0
- package/dist/commands/directory/ListFunctions.js.map +1 -0
- package/dist/commands/directory/ListGlobalFunctions.d.ts +6 -0
- package/dist/commands/directory/ListGlobalFunctions.js +72 -0
- package/dist/commands/directory/ListGlobalFunctions.js.map +1 -0
- package/dist/commands/directory/ListInstalls.d.ts +8 -0
- package/dist/commands/directory/ListInstalls.js +81 -0
- package/dist/commands/directory/ListInstalls.js.map +1 -0
- package/dist/commands/directory/Publish.d.ts +8 -0
- package/dist/commands/directory/Publish.js +180 -0
- package/dist/commands/directory/Publish.js.map +1 -0
- package/dist/commands/directory/Status.d.ts +5 -0
- package/dist/commands/directory/Status.js +60 -0
- package/dist/commands/directory/Status.js.map +1 -0
- package/dist/commands/directory/Uninstall.d.ts +6 -0
- package/dist/commands/directory/Uninstall.js +50 -0
- package/dist/commands/directory/Uninstall.js.map +1 -0
- package/dist/commands/directory/Unpublish.d.ts +10 -0
- package/dist/commands/directory/Unpublish.js +181 -0
- package/dist/commands/directory/Unpublish.js.map +1 -0
- package/dist/commands/directory/Uprade.d.ts +8 -0
- package/dist/commands/directory/Uprade.js +100 -0
- package/dist/commands/directory/Uprade.js.map +1 -0
- package/dist/commands/env/GetEnvironment.d.ts +3 -0
- package/dist/commands/env/GetEnvironment.js +28 -0
- package/dist/commands/env/GetEnvironment.js.map +1 -0
- package/dist/commands/env/SetEnvironment.d.ts +4 -0
- package/dist/commands/env/SetEnvironment.js +63 -0
- package/dist/commands/env/SetEnvironment.js.map +1 -0
- package/dist/commands/jobs/List.d.ts +21 -0
- package/dist/commands/jobs/List.js +268 -0
- package/dist/commands/jobs/List.js.map +1 -0
- package/dist/commands/jobs/RuntimeStatus.d.ts +5 -0
- package/dist/commands/jobs/RuntimeStatus.js +65 -0
- package/dist/commands/jobs/RuntimeStatus.js.map +1 -0
- package/dist/commands/jobs/Terminate.d.ts +5 -0
- package/dist/commands/jobs/Terminate.js +45 -0
- package/dist/commands/jobs/Terminate.js.map +1 -0
- package/dist/commands/jobs/Trigger.d.ts +8 -0
- package/dist/commands/jobs/Trigger.js +58 -0
- package/dist/commands/jobs/Trigger.js.map +1 -0
- package/dist/commands/review/List.d.ts +5 -0
- package/dist/commands/review/List.js +81 -0
- package/dist/commands/review/List.js.map +1 -0
- package/dist/commands/review/Open.d.ts +4 -0
- package/dist/commands/review/Open.js +42 -0
- package/dist/commands/review/Open.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/AppContext.d.ts +9 -0
- package/dist/lib/AppContext.js +43 -0
- package/dist/lib/AppContext.js.map +1 -0
- package/dist/lib/AppPackager.d.ts +8 -0
- package/dist/lib/AppPackager.js +40 -0
- package/dist/lib/AppPackager.js.map +1 -0
- package/dist/lib/AppUpdater.d.ts +9 -0
- package/dist/lib/AppUpdater.js +155 -0
- package/dist/lib/AppUpdater.js.map +1 -0
- package/dist/lib/AppUploader.d.ts +8 -0
- package/dist/lib/AppUploader.js +36 -0
- package/dist/lib/AppUploader.js.map +1 -0
- package/dist/lib/Config.d.ts +15 -0
- package/dist/lib/Config.js +47 -0
- package/dist/lib/Config.js.map +1 -0
- package/dist/lib/EnvironmentalOutput.d.ts +1 -0
- package/dist/lib/EnvironmentalOutput.js +21 -0
- package/dist/lib/EnvironmentalOutput.js.map +1 -0
- package/dist/lib/Moria.d.ts +51 -0
- package/dist/lib/Moria.js +30 -0
- package/dist/lib/Moria.js.map +1 -0
- package/dist/lib/MoriaApi.d.ts +22 -0
- package/dist/lib/MoriaApi.js +75 -0
- package/dist/lib/MoriaApi.js.map +1 -0
- package/dist/lib/Rivendell.d.ts +351 -0
- package/dist/lib/Rivendell.js +328 -0
- package/dist/lib/Rivendell.js.map +1 -0
- package/dist/lib/RivendellApi.d.ts +22 -0
- package/dist/lib/RivendellApi.js +90 -0
- package/dist/lib/RivendellApi.js.map +1 -0
- package/dist/lib/Shards.d.ts +3 -0
- package/dist/lib/Shards.js +34 -0
- package/dist/lib/Shards.js.map +1 -0
- package/dist/lib/StringUtils.d.ts +1 -0
- package/dist/lib/StringUtils.js +9 -0
- package/dist/lib/StringUtils.js.map +1 -0
- package/dist/lib/TeminalPassthru.d.ts +5 -0
- package/dist/lib/TeminalPassthru.js +12 -0
- package/dist/lib/TeminalPassthru.js.map +1 -0
- package/dist/lib/TerminalConfirm.d.ts +3 -0
- package/dist/lib/TerminalConfirm.js +26 -0
- package/dist/lib/TerminalConfirm.js.map +1 -0
- package/dist/lib/TerminalInput.d.ts +32 -0
- package/dist/lib/TerminalInput.js +207 -0
- package/dist/lib/TerminalInput.js.map +1 -0
- package/dist/lib/TerminalMenu.d.ts +34 -0
- package/dist/lib/TerminalMenu.js +186 -0
- package/dist/lib/TerminalMenu.js.map +1 -0
- package/dist/lib/TerminalOutput.d.ts +5 -0
- package/dist/lib/TerminalOutput.js +12 -0
- package/dist/lib/TerminalOutput.js.map +1 -0
- package/dist/lib/TerminalSpinner.d.ts +15 -0
- package/dist/lib/TerminalSpinner.js +71 -0
- package/dist/lib/TerminalSpinner.js.map +1 -0
- package/dist/lib/build.d.ts +5 -0
- package/dist/lib/build.js +35 -0
- package/dist/lib/build.js.map +1 -0
- package/dist/lib/checkForUpdate.d.ts +2 -0
- package/dist/lib/checkForUpdate.js +58 -0
- package/dist/lib/checkForUpdate.js.map +1 -0
- package/dist/lib/dev/app.d.ts +8 -0
- package/dist/lib/dev/app.js +53 -0
- package/dist/lib/dev/app.js.map +1 -0
- package/dist/lib/dev/index.d.ts +1 -0
- package/dist/lib/dev/index.js +14 -0
- package/dist/lib/dev/index.js.map +1 -0
- package/dist/lib/dev/logger.d.ts +15 -0
- package/dist/lib/dev/logger.js +58 -0
- package/dist/lib/dev/logger.js.map +1 -0
- package/dist/lib/die.d.ts +5 -0
- package/dist/lib/die.js +14 -0
- package/dist/lib/die.js.map +1 -0
- package/dist/lib/directoryExists.d.ts +1 -0
- package/dist/lib/directoryExists.js +9 -0
- package/dist/lib/directoryExists.js.map +1 -0
- package/dist/lib/formatBuildState.d.ts +2 -0
- package/dist/lib/formatBuildState.js +23 -0
- package/dist/lib/formatBuildState.js.map +1 -0
- package/dist/lib/formatError.d.ts +1 -0
- package/dist/lib/formatError.js +45 -0
- package/dist/lib/formatError.js.map +1 -0
- package/dist/lib/formatJobStatus.d.ts +3 -0
- package/dist/lib/formatJobStatus.js +28 -0
- package/dist/lib/formatJobStatus.js.map +1 -0
- package/dist/lib/formatReviewStatus.d.ts +4 -0
- package/dist/lib/formatReviewStatus.js +28 -0
- package/dist/lib/formatReviewStatus.js.map +1 -0
- package/dist/lib/formatTimstamp.d.ts +1 -0
- package/dist/lib/formatTimstamp.js +25 -0
- package/dist/lib/formatTimstamp.js.map +1 -0
- package/dist/lib/formatVersionState.d.ts +2 -0
- package/dist/lib/formatVersionState.js +35 -0
- package/dist/lib/formatVersionState.js.map +1 -0
- package/dist/lib/gatherAppEnv.d.ts +3 -0
- package/dist/lib/gatherAppEnv.js +71 -0
- package/dist/lib/gatherAppEnv.js.map +1 -0
- package/dist/lib/handleInterrupt.d.ts +1 -0
- package/dist/lib/handleInterrupt.js +17 -0
- package/dist/lib/handleInterrupt.js.map +1 -0
- package/dist/lib/jobRuntime.d.ts +3 -0
- package/dist/lib/jobRuntime.js +16 -0
- package/dist/lib/jobRuntime.js.map +1 -0
- package/dist/lib/parseDate.d.ts +2 -0
- package/dist/lib/parseDate.js +26 -0
- package/dist/lib/parseDate.js.map +1 -0
- package/dist/lib/templating/TemplateRenderer.d.ts +13 -0
- package/dist/lib/templating/TemplateRenderer.js +62 -0
- package/dist/lib/templating/TemplateRenderer.js.map +1 -0
- package/dist/lib/templating/fetchTemplatesManifest.d.ts +1 -0
- package/dist/lib/templating/fetchTemplatesManifest.js +10 -0
- package/dist/lib/templating/fetchTemplatesManifest.js.map +1 -0
- package/dist/lib/templating/types.d.ts +27 -0
- package/dist/lib/templating/types.js +3 -0
- package/dist/lib/templating/types.js.map +1 -0
- package/dist/oo-cli.manifest.json +1142 -0
- package/dist/test/setup.d.ts +0 -0
- package/dist/test/setup.js +4 -0
- package/dist/test/setup.js.map +1 -0
- package/package.json +94 -0
- package/src/commands/accounts/Whoami.ts +19 -0
- package/src/commands/accounts/Whois.ts +51 -0
- package/src/commands/app/BaseBuildCommand.ts +266 -0
- package/src/commands/app/Init.ts +303 -0
- package/src/commands/app/Logs.ts +241 -0
- package/src/commands/app/Package.ts +39 -0
- package/src/commands/app/Prepare.ts +108 -0
- package/src/commands/app/Register.ts +41 -0
- package/src/commands/app/Validate.ts +13 -0
- package/src/commands/availability/List.ts +37 -0
- package/src/commands/directory/Info.ts +83 -0
- package/src/commands/directory/Install.ts +37 -0
- package/src/commands/directory/List.ts +96 -0
- package/src/commands/directory/ListFunctions.ts +60 -0
- package/src/commands/directory/ListGlobalFunctions.ts +54 -0
- package/src/commands/directory/ListInstalls.ts +73 -0
- package/src/commands/directory/Publish.ts +179 -0
- package/src/commands/directory/Status.ts +45 -0
- package/src/commands/directory/Uninstall.ts +32 -0
- package/src/commands/directory/Unpublish.ts +173 -0
- package/src/commands/directory/Uprade.ts +85 -0
- package/src/commands/env/GetEnvironment.ts +14 -0
- package/src/commands/env/SetEnvironment.ts +52 -0
- package/src/commands/jobs/List.ts +278 -0
- package/src/commands/jobs/RuntimeStatus.ts +49 -0
- package/src/commands/jobs/Terminate.ts +29 -0
- package/src/commands/jobs/Trigger.ts +41 -0
- package/src/commands/review/List.ts +76 -0
- package/src/commands/review/Open.ts +28 -0
- package/src/index.ts +15 -0
- package/src/lib/AppContext.ts +47 -0
- package/src/lib/AppPackager.ts +47 -0
- package/src/lib/AppUpdater.ts +177 -0
- package/src/lib/AppUploader.ts +39 -0
- package/src/lib/Config.ts +60 -0
- package/src/lib/EnvironmentalOutput.ts +18 -0
- package/src/lib/Moria.ts +66 -0
- package/src/lib/MoriaApi.ts +86 -0
- package/src/lib/Rivendell.ts +572 -0
- package/src/lib/RivendellApi.ts +99 -0
- package/src/lib/Shards.ts +37 -0
- package/src/lib/StringUtils.ts +4 -0
- package/src/lib/TeminalPassthru.ts +7 -0
- package/src/lib/TerminalConfirm.ts +27 -0
- package/src/lib/TerminalInput.ts +236 -0
- package/src/lib/TerminalMenu.ts +221 -0
- package/src/lib/TerminalOutput.ts +7 -0
- package/src/lib/TerminalSpinner.ts +76 -0
- package/src/lib/build.ts +36 -0
- package/src/lib/checkForUpdate.ts +63 -0
- package/src/lib/dev/app.ts +58 -0
- package/src/lib/dev/index.ts +1 -0
- package/src/lib/dev/logger.ts +77 -0
- package/src/lib/die.ts +10 -0
- package/src/lib/directoryExists.ts +5 -0
- package/src/lib/formatBuildState.ts +20 -0
- package/src/lib/formatError.ts +39 -0
- package/src/lib/formatJobStatus.ts +24 -0
- package/src/lib/formatReviewStatus.ts +27 -0
- package/src/lib/formatTimstamp.ts +21 -0
- package/src/lib/formatVersionState.ts +31 -0
- package/src/lib/gatherAppEnv.ts +75 -0
- package/src/lib/handleInterrupt.ts +13 -0
- package/src/lib/jobRuntime.ts +12 -0
- package/src/lib/parseDate.ts +21 -0
- package/src/lib/templating/TemplateRenderer.ts +65 -0
- package/src/lib/templating/fetchTemplatesManifest.ts +6 -0
- package/src/lib/templating/types.ts +30 -0
- package/src/test/setup.ts +2 -0
- package/src/types/columnify.d.ts +27 -0
- package/src/types/gitignore-parser.d.ts +11 -0
package/src/lib/Moria.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {MoriaApi} from './MoriaApi';
|
|
2
|
+
import { Rivendell } from './Rivendell';
|
|
3
|
+
|
|
4
|
+
export namespace Moria {
|
|
5
|
+
|
|
6
|
+
export interface LogEntryContext {
|
|
7
|
+
appId?: string;
|
|
8
|
+
appVersion?: string;
|
|
9
|
+
trackerId?: string;
|
|
10
|
+
installId?: string;
|
|
11
|
+
entryPoint?: string;
|
|
12
|
+
requestId?: string;
|
|
13
|
+
jobId?: string;
|
|
14
|
+
buildId?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface LoggingSearchCriteria {
|
|
18
|
+
context: LogEntryContext;
|
|
19
|
+
start?: number;
|
|
20
|
+
end?: number;
|
|
21
|
+
audience?: Audience;
|
|
22
|
+
level?: LogLevel;
|
|
23
|
+
pageSize?: number;
|
|
24
|
+
cursor?: string;
|
|
25
|
+
terms?: string[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface LoggingSearchResult {
|
|
29
|
+
cursor: string;
|
|
30
|
+
entries: LogEntry[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface LogEntry {
|
|
34
|
+
id: string;
|
|
35
|
+
level: LogLevel;
|
|
36
|
+
time: number;
|
|
37
|
+
message: string;
|
|
38
|
+
context: LogEntryContext;
|
|
39
|
+
audience: Audience;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export enum Audience {
|
|
43
|
+
USER = 'USER',
|
|
44
|
+
DEVELOPER = 'DEVELOPER',
|
|
45
|
+
ZAIUS = 'ZAIUS'
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export enum LogLevel {
|
|
49
|
+
INFO = 'INFO',
|
|
50
|
+
DEBUG = 'DEBUG',
|
|
51
|
+
WARN = 'WARN',
|
|
52
|
+
ERROR = 'ERROR'
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Search for LogEntries using the supplied criteria.
|
|
57
|
+
* @param criteria
|
|
58
|
+
*/
|
|
59
|
+
export async function searchLogging(
|
|
60
|
+
criteria: LoggingSearchCriteria,
|
|
61
|
+
shard: Rivendell.Shard
|
|
62
|
+
): Promise<LoggingSearchResult> {
|
|
63
|
+
const response = await MoriaApi.post<LoggingSearchResult>(shard, 'logging/search', criteria);
|
|
64
|
+
return response.body;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import fetch, {RequestInit, Response} from 'node-fetch';
|
|
2
|
+
import {Rivendell} from './Rivendell';
|
|
3
|
+
|
|
4
|
+
export type Method = 'POST' | 'PUT' | 'PATCH' | 'GET' | 'DELETE';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Low level http handler for interacting with the Moria api.
|
|
8
|
+
*/
|
|
9
|
+
export namespace MoriaApi {
|
|
10
|
+
|
|
11
|
+
interface ApiResponse<T = any> {
|
|
12
|
+
response: Response;
|
|
13
|
+
body: T;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class ApiError extends Error {
|
|
17
|
+
constructor(message: string, public responseText: string, public response?: Response) {
|
|
18
|
+
super(message);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function get<T>(shard: Rivendell.Shard, uri: string): Promise<ApiResponse<T>> {
|
|
23
|
+
return request(shard, 'GET', uri);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function post<T>(shard: Rivendell.Shard, uri: string, body: any): Promise<ApiResponse<T>> {
|
|
27
|
+
return request(shard, 'POST', uri, body);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function put<T>(shard: Rivendell.Shard, uri: string, body: any): Promise<ApiResponse<T>> {
|
|
31
|
+
return request(shard, 'PUT', uri, body);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function request<T>(
|
|
35
|
+
shard: Rivendell.Shard,
|
|
36
|
+
method: Method,
|
|
37
|
+
uri: string,
|
|
38
|
+
body?: any
|
|
39
|
+
): Promise<ApiResponse<T>> {
|
|
40
|
+
const url = `${shard.url}/${uri}`;
|
|
41
|
+
const requestPayload: RequestInit = { method };
|
|
42
|
+
|
|
43
|
+
requestPayload.headers = {
|
|
44
|
+
'Authorization': `Bearer ${await Rivendell.jwt(shard.id)}`
|
|
45
|
+
};
|
|
46
|
+
if (body && method !== 'GET') {
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
requestPayload.headers['content-type'] = 'application/json';
|
|
49
|
+
requestPayload.body = JSON.stringify(body);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const response = await fetch(url, requestPayload);
|
|
53
|
+
const responseText = await response.text();
|
|
54
|
+
|
|
55
|
+
if (response.status < 200 || response.status >= 300) {
|
|
56
|
+
const errorMsg = `Received a ${response.status} from OCP: ${getErrorMessage(response.status)}`;
|
|
57
|
+
throw new ApiError(errorMsg, responseText, response);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
response,
|
|
62
|
+
body: responseText ? JSON.parse(responseText) : ''
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function getErrorMessage(code: number): string {
|
|
67
|
+
switch (code) {
|
|
68
|
+
case 400:
|
|
69
|
+
return 'Bad request.';
|
|
70
|
+
case 403:
|
|
71
|
+
return 'Access denied.';
|
|
72
|
+
case 404:
|
|
73
|
+
return 'Not found.';
|
|
74
|
+
case 500:
|
|
75
|
+
return 'Internal service error.';
|
|
76
|
+
case 502:
|
|
77
|
+
return 'Bad gateway';
|
|
78
|
+
case 503:
|
|
79
|
+
return 'Service unavailable. Please try again.';
|
|
80
|
+
case 504:
|
|
81
|
+
return 'Request timed out. Please try again.';
|
|
82
|
+
default:
|
|
83
|
+
return 'Unhandled error.';
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,572 @@
|
|
|
1
|
+
import {RivendellApi} from './RivendellApi';
|
|
2
|
+
import {AppContext} from './AppContext';
|
|
3
|
+
import {DotenvParseOutput} from 'dotenv';
|
|
4
|
+
|
|
5
|
+
export namespace Rivendell {
|
|
6
|
+
|
|
7
|
+
export enum AppVersionState {
|
|
8
|
+
NEW = 'NEW',
|
|
9
|
+
PUBLISHED = 'PUBLISHED',
|
|
10
|
+
BUILD_FAILED = 'BUILD_FAILED',
|
|
11
|
+
STARTING = 'STARTING',
|
|
12
|
+
START_FAILED = 'START_FAILED',
|
|
13
|
+
RUNNING = 'RUNNING',
|
|
14
|
+
UPGRADING_RUNTIME = 'UPGRADING_RUNTIME',
|
|
15
|
+
STOPPING = 'STOPPING',
|
|
16
|
+
STOP_FAILED = 'STOP_FAILED',
|
|
17
|
+
STOPPED = 'STOPPED'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export enum ReviewStatus {
|
|
21
|
+
NOT_STARTED = 'NOT_STARTED',
|
|
22
|
+
IN_REVIEW = 'IN_REVIEW',
|
|
23
|
+
APPROVED = 'APPROVED',
|
|
24
|
+
NOT_REQUIRED = 'NOT_REQUIRED'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export enum BuildState {
|
|
28
|
+
NEW = 'NEW',
|
|
29
|
+
QUEUED = 'QUEUED',
|
|
30
|
+
RUNNING = 'RUNNING',
|
|
31
|
+
FINISHED = 'FINISHED'
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export enum BuildMode {
|
|
35
|
+
VALIDATE = 'VALIDATE',
|
|
36
|
+
PUBLISH = 'PUBLISH'
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export enum BuildStatus {
|
|
40
|
+
SUCCESS = 'SUCCESS',
|
|
41
|
+
FAILURE = 'FAILURE',
|
|
42
|
+
ERROR = 'ERROR'
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export enum DeploymentStage {
|
|
46
|
+
TEST = 'TEST',
|
|
47
|
+
PRODUCTION = 'PRODUCTION'
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export enum JobStatus {
|
|
51
|
+
PENDING = 'PENDING',
|
|
52
|
+
SCHEDULED = 'SCHEDULED',
|
|
53
|
+
RUNNING = 'RUNNING',
|
|
54
|
+
COMPLETE = 'COMPLETE',
|
|
55
|
+
ERROR = 'ERROR',
|
|
56
|
+
TERMINATED = 'TERMINATED'
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export enum JobTriggerType {
|
|
60
|
+
IMMEDIATE = 'IMMEDIATE',
|
|
61
|
+
RECURRING = 'RECURRING'
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface AppVersionId {
|
|
65
|
+
appId: string;
|
|
66
|
+
version: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface Build {
|
|
70
|
+
id: number;
|
|
71
|
+
appVersionId: AppVersionId;
|
|
72
|
+
mode: BuildMode;
|
|
73
|
+
state: BuildState;
|
|
74
|
+
status?: BuildStatus;
|
|
75
|
+
errors?: string[];
|
|
76
|
+
queuedAt?: string;
|
|
77
|
+
runningAt?: string;
|
|
78
|
+
finishedAt?: string;
|
|
79
|
+
dependencySet?: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface App {
|
|
83
|
+
id: string;
|
|
84
|
+
name: string;
|
|
85
|
+
createdAt: string;
|
|
86
|
+
updatedAt: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface AppVersion {
|
|
90
|
+
id: AppVersionId;
|
|
91
|
+
manifestJson: string;
|
|
92
|
+
packageUrl: string;
|
|
93
|
+
state: string;
|
|
94
|
+
reviewStatus?: string;
|
|
95
|
+
stage: string;
|
|
96
|
+
image: string;
|
|
97
|
+
createdAt: string;
|
|
98
|
+
updatedAt: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface AppInstallation {
|
|
102
|
+
id: number;
|
|
103
|
+
appId: string;
|
|
104
|
+
version: string;
|
|
105
|
+
accountId: number;
|
|
106
|
+
trackerId: string;
|
|
107
|
+
createdAt: string;
|
|
108
|
+
updatedAt: string;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface Job {
|
|
112
|
+
id: string;
|
|
113
|
+
accountId: number;
|
|
114
|
+
trackerId: string;
|
|
115
|
+
status: JobStatus;
|
|
116
|
+
definition: JobDefinition;
|
|
117
|
+
errors: string;
|
|
118
|
+
triggeredAt: string;
|
|
119
|
+
scheduledAt: string;
|
|
120
|
+
startedAt: string;
|
|
121
|
+
completedAt: string;
|
|
122
|
+
terminatedAt: string;
|
|
123
|
+
createdAt: string;
|
|
124
|
+
updatedAt: string;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export interface JobRuntimeStatus {
|
|
128
|
+
status: string;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface JobDefinition {
|
|
132
|
+
id: string;
|
|
133
|
+
appId: string;
|
|
134
|
+
version: string;
|
|
135
|
+
function: string;
|
|
136
|
+
parameters: string;
|
|
137
|
+
trigger: JobTriggerType;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface Webhook {
|
|
141
|
+
id: string;
|
|
142
|
+
url: string;
|
|
143
|
+
attributes: WebhookAttributes;
|
|
144
|
+
createdAt: string;
|
|
145
|
+
updatedAt?: string;
|
|
146
|
+
deletedAt?: string;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface WebhookAttributes {
|
|
150
|
+
appId: string;
|
|
151
|
+
appVersion: string;
|
|
152
|
+
appInstallId?: number;
|
|
153
|
+
taskName: string;
|
|
154
|
+
internal: boolean;
|
|
155
|
+
enabled: boolean;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export interface AppVersionSearchCriteria {
|
|
159
|
+
appId?: string;
|
|
160
|
+
version?: string;
|
|
161
|
+
appName?: string;
|
|
162
|
+
states?: AppVersionState[];
|
|
163
|
+
reviewStatuses?: ReviewStatus[];
|
|
164
|
+
stages?: DeploymentStage[];
|
|
165
|
+
categories?: Set<string>;
|
|
166
|
+
sorts?: Sort[];
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export interface AppInstallationSearchCriteria {
|
|
170
|
+
appId?: string;
|
|
171
|
+
version?: string;
|
|
172
|
+
trackerIds?: string[];
|
|
173
|
+
sorts?: Sort[];
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface WebhookSearchCriteria {
|
|
177
|
+
appId?: string;
|
|
178
|
+
appInstallId?: number;
|
|
179
|
+
includeInternal?: boolean;
|
|
180
|
+
includeDisabled?: boolean;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export interface JobSearchCriteria {
|
|
184
|
+
appId: string;
|
|
185
|
+
versions?: string[];
|
|
186
|
+
trackerIds?: string[];
|
|
187
|
+
states?: JobStatus[];
|
|
188
|
+
functions?: string[];
|
|
189
|
+
minDurationMillis?: number;
|
|
190
|
+
sort?: Sort[];
|
|
191
|
+
limit?: number;
|
|
192
|
+
start?: number;
|
|
193
|
+
end?: number;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export interface AppReview {
|
|
197
|
+
url: string;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export enum SortDirection {
|
|
201
|
+
ASC = 'ASC',
|
|
202
|
+
DESC = 'DESC'
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export interface Sort {
|
|
206
|
+
field: string;
|
|
207
|
+
direction?: SortDirection;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export enum Audience {
|
|
211
|
+
USER = 'USER',
|
|
212
|
+
DEVELOPER = 'DEVELOPER',
|
|
213
|
+
ZAIUS = 'ZAIUS'
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export interface AwsCredentials {
|
|
217
|
+
accessKeyId: string;
|
|
218
|
+
secretAccessKey: string;
|
|
219
|
+
sessionToken: string;
|
|
220
|
+
expiration: string;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export interface Account {
|
|
224
|
+
id: number;
|
|
225
|
+
trackerId: string;
|
|
226
|
+
name: string;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export interface DeveloperApp {
|
|
230
|
+
id: string;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export interface Developer {
|
|
234
|
+
id: string;
|
|
235
|
+
email: string;
|
|
236
|
+
role: string;
|
|
237
|
+
vendor: string;
|
|
238
|
+
personal_apps: DeveloperApp[];
|
|
239
|
+
vendor_apps: DeveloperApp[];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export interface Shard {
|
|
243
|
+
id: string;
|
|
244
|
+
description: string;
|
|
245
|
+
url: string;
|
|
246
|
+
live: boolean;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export interface JwtResponse {
|
|
250
|
+
jwt: string;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export interface JwtHeader {
|
|
254
|
+
kid: string;
|
|
255
|
+
typ: string;
|
|
256
|
+
alg: string;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export interface JwtPayload {
|
|
260
|
+
aud: string;
|
|
261
|
+
exp: number;
|
|
262
|
+
iss: string;
|
|
263
|
+
sub: string;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export interface Jwt {
|
|
267
|
+
token: string;
|
|
268
|
+
header: JwtHeader;
|
|
269
|
+
payload: JwtPayload;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function path(shard: string, endpoint: string) {
|
|
273
|
+
return `${shard}/${endpoint}`.replace(/^\//, '');
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export async function searchAccounts(term: string, shard: string): Promise<Account[]> {
|
|
277
|
+
const response = await RivendellApi.get<Account[]>(
|
|
278
|
+
path(shard, `accounts/search?term=${encodeURIComponent(term)}`));
|
|
279
|
+
return response.body;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export async function whoami(): Promise<Developer> {
|
|
283
|
+
const response = await RivendellApi.get<Developer>('developers/me');
|
|
284
|
+
return response.body;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Register a new App.
|
|
289
|
+
* @param appId
|
|
290
|
+
* @param name
|
|
291
|
+
*/
|
|
292
|
+
export async function registerApp(appId: string, name: string, personalApp: boolean, shard: string): Promise<App> {
|
|
293
|
+
const response = await RivendellApi.post<App>(path(shard, 'apps'), {appId, name, personalApp});
|
|
294
|
+
return response.body;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Fetch an App by identifier.
|
|
299
|
+
* @param appId
|
|
300
|
+
*/
|
|
301
|
+
export async function fetchApp(appId: string, shard = ''): Promise<App> {
|
|
302
|
+
const response = await RivendellApi.get<App>(path(shard, `apps/${appId}`));
|
|
303
|
+
return response.body;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Get app version review url.
|
|
308
|
+
* @param appId
|
|
309
|
+
*/
|
|
310
|
+
export async function getReviewUrl(appVersion: string): Promise<AppReview> {
|
|
311
|
+
const response = await RivendellApi.get<AppReview>(`reviews/${appVersion}`);
|
|
312
|
+
return response.body;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Search for AppVersions using the supplied criteria.
|
|
317
|
+
* @param criteria
|
|
318
|
+
*/
|
|
319
|
+
export async function searchAppVersions(criteria: AppVersionSearchCriteria, shard: string): Promise<AppVersion[]> {
|
|
320
|
+
const response = await RivendellApi.post<AppVersion[]>(path(shard, 'versions/search'), criteria);
|
|
321
|
+
return response.body;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Fetch an AppVersion by identifier.
|
|
326
|
+
* @param appContext
|
|
327
|
+
*/
|
|
328
|
+
export async function fetchAppVersion(appContext: AppContext, shard: string): Promise<AppVersion> {
|
|
329
|
+
const response = await RivendellApi.get<AppVersion>(
|
|
330
|
+
path(shard, `versions/${appContext.appId}@${appContext.version}`));
|
|
331
|
+
return response.body;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Register a new app version.
|
|
336
|
+
*/
|
|
337
|
+
export async function registerAppVersion(
|
|
338
|
+
appId: string,
|
|
339
|
+
version: string,
|
|
340
|
+
packageUrl: string,
|
|
341
|
+
appEnvValues: DotenvParseOutput,
|
|
342
|
+
usePreviousAppEnvValues: boolean,
|
|
343
|
+
shard: string
|
|
344
|
+
): Promise<AppVersion> {
|
|
345
|
+
const response = await RivendellApi.post<AppVersion>(
|
|
346
|
+
path(shard, 'versions'), {appId, version, packageUrl, appEnvValues, usePreviousAppEnvValues});
|
|
347
|
+
return response.body;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Register a new app version.
|
|
352
|
+
*/
|
|
353
|
+
export async function updateAppVersion(
|
|
354
|
+
appId: string,
|
|
355
|
+
version: string,
|
|
356
|
+
packageUrl: string,
|
|
357
|
+
appEnvValues: DotenvParseOutput,
|
|
358
|
+
usePreviousAppEnvValues: boolean,
|
|
359
|
+
shard: string
|
|
360
|
+
): Promise<AppVersion> {
|
|
361
|
+
const response = await RivendellApi.put<AppVersion>(
|
|
362
|
+
path(shard, `versions/${appId}@${version}`), {packageUrl, appEnvValues, usePreviousAppEnvValues});
|
|
363
|
+
return response.body;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Review an app version.
|
|
368
|
+
*/
|
|
369
|
+
export async function reviewAppVersion(
|
|
370
|
+
appId: string,
|
|
371
|
+
version: string
|
|
372
|
+
): Promise<void> {
|
|
373
|
+
const appVersionId = `${appId}@${version}`;
|
|
374
|
+
await RivendellApi.post('reviews', appVersionId);
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Search for AppVersions using the supplied criteria.
|
|
378
|
+
* @param criteria
|
|
379
|
+
*/
|
|
380
|
+
export async function searchAppInstallations(
|
|
381
|
+
criteria: AppInstallationSearchCriteria,
|
|
382
|
+
shard: string
|
|
383
|
+
): Promise<AppInstallation[]> {
|
|
384
|
+
const response = await RivendellApi.post<AppInstallation[]>(path(shard, 'installations/search'), criteria);
|
|
385
|
+
return response.body;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Search for Webhooks using the supplied criteria.
|
|
390
|
+
* @param criteria
|
|
391
|
+
*/
|
|
392
|
+
export async function searchWebhooks(criteria: WebhookSearchCriteria, shard: string): Promise<Webhook[]> {
|
|
393
|
+
const response = await RivendellApi.post<Webhook[]>(path(shard, 'webhooks/search'), criteria);
|
|
394
|
+
return response.body;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Loads a single AppInstallation.
|
|
399
|
+
* @param appId
|
|
400
|
+
* @param trackerId
|
|
401
|
+
*/
|
|
402
|
+
export async function fetchAppInstallation(appId: string, trackerId: string, shard = ''): Promise<AppInstallation> {
|
|
403
|
+
const response = await searchAppInstallations({appId, trackerIds: [trackerId]}, shard);
|
|
404
|
+
if (response.length !== 1) {
|
|
405
|
+
throw new Error(`Installation of ${appId} not found for ${trackerId}`);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
return response[0];
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Trigger an installation.
|
|
413
|
+
*/
|
|
414
|
+
export async function install(
|
|
415
|
+
appId: string,
|
|
416
|
+
version: string,
|
|
417
|
+
trackerId: string,
|
|
418
|
+
shard: string)
|
|
419
|
+
: Promise<AppInstallation> {
|
|
420
|
+
const response = await RivendellApi.post<AppInstallation>(
|
|
421
|
+
path(shard, 'installations'), {appId, version, trackerId});
|
|
422
|
+
return response.body;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Trigger an uninstall.
|
|
427
|
+
*/
|
|
428
|
+
export async function uninstall(appInstallationId: number, shard: string): Promise<void> {
|
|
429
|
+
await RivendellApi.request('DELETE', path(shard, `installations/${appInstallationId}`));
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Request an upgrade.
|
|
434
|
+
*/
|
|
435
|
+
export async function upgrade(
|
|
436
|
+
appInstallationId: number,
|
|
437
|
+
appId: string,
|
|
438
|
+
version: string,
|
|
439
|
+
shard: string
|
|
440
|
+
): Promise<void> {
|
|
441
|
+
await RivendellApi.put(path(shard, `installations/${appInstallationId}`), {appId, version});
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Trigger a publish.
|
|
446
|
+
*/
|
|
447
|
+
export async function publish(appId: string, version: string, shard: string): Promise<void> {
|
|
448
|
+
await RivendellApi.request('PATCH', path(shard, `versions/${appId}@${version}`), {state: AppVersionState.RUNNING});
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Trigger a unpublish.
|
|
453
|
+
*/
|
|
454
|
+
export async function unpublish(appId: string, version: string, shard: string): Promise<void> {
|
|
455
|
+
await RivendellApi.request('PATCH', path(shard, `versions/${appId}@${version}`), {state: AppVersionState.STOPPED});
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Fetch a build by id.
|
|
460
|
+
*/
|
|
461
|
+
export async function fetchBuild(id: number): Promise<Build> {
|
|
462
|
+
const response = await RivendellApi.get<Build>(`builds/${id}`);
|
|
463
|
+
return response.body;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Trigger a build.
|
|
468
|
+
*/
|
|
469
|
+
export async function build(appId: string, version: string): Promise<Build> {
|
|
470
|
+
const response = await RivendellApi.post<Build>('builds', {appId, version});
|
|
471
|
+
return response.body;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Trigger a verification.
|
|
476
|
+
*/
|
|
477
|
+
export async function verify(appId: string, version: string): Promise<Build> {
|
|
478
|
+
const response = await RivendellApi.post<Build>('verifications', {appId, version});
|
|
479
|
+
return response.body;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Fetch temp credentials to upload to s3.
|
|
484
|
+
*/
|
|
485
|
+
export async function uploadCredentials(
|
|
486
|
+
vendor: string,
|
|
487
|
+
appId: string,
|
|
488
|
+
version: string,
|
|
489
|
+
checksum: string
|
|
490
|
+
): Promise<AwsCredentials> {
|
|
491
|
+
const response = await RivendellApi.post<AwsCredentials>('tokens', {vendor, appId, version, checksum});
|
|
492
|
+
return response.body;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* List shards.
|
|
497
|
+
*/
|
|
498
|
+
export async function shards(): Promise<Shard[]> {
|
|
499
|
+
const response = await RivendellApi.get<Shard[]>('shards');
|
|
500
|
+
const me = await Rivendell.whoami();
|
|
501
|
+
return response.body.filter((s) => me.role === 'administrator' || s.live);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Search Jobs.
|
|
506
|
+
*/
|
|
507
|
+
export async function searchJobs(criteria: JobSearchCriteria, shard: string): Promise<Job[]> {
|
|
508
|
+
const response = await RivendellApi.post<Job[]>(path(shard, 'jobs/search'), criteria);
|
|
509
|
+
return response.body;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Terminate Jobs
|
|
514
|
+
*/
|
|
515
|
+
export async function terminateJob(jobId: string, shard: string): Promise<void> {
|
|
516
|
+
await RivendellApi.delete_(path(shard, `jobs/${jobId}`));
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Trigger a Job
|
|
521
|
+
*/
|
|
522
|
+
export async function triggerJob(
|
|
523
|
+
appId: string,
|
|
524
|
+
jobName: string,
|
|
525
|
+
trackerId: string,
|
|
526
|
+
parameters: string,
|
|
527
|
+
shard: string
|
|
528
|
+
): Promise<Job> {
|
|
529
|
+
const body = {appId, jobName, trackerId, parameters};
|
|
530
|
+
const response = await RivendellApi.post<Job>(path(shard, 'jobs'), body);
|
|
531
|
+
return response.body;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* Fetch a Job
|
|
536
|
+
*/
|
|
537
|
+
export async function fetchJob(jobId: string, shard: string): Promise<Job> {
|
|
538
|
+
const response = await RivendellApi.get<Job>(path(shard, `jobs/${jobId}`));
|
|
539
|
+
return response.body;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Fetch a jobs runtimeStatus
|
|
544
|
+
*/
|
|
545
|
+
export async function fetchJobRuntimeStatus(jobId: string, shard: string): Promise<JobRuntimeStatus> {
|
|
546
|
+
const response = await RivendellApi.get<JobRuntimeStatus>(path(shard, `jobs/${jobId}/runtimeStatus`));
|
|
547
|
+
return response.body;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* Get Moria JWT for this developer.
|
|
552
|
+
*/
|
|
553
|
+
let cachedJwt: Jwt;
|
|
554
|
+
export async function jwt(shard: string): Promise<string> {
|
|
555
|
+
const now = new Date();
|
|
556
|
+
if (!cachedJwt || cachedJwt.payload.exp * 1000 - now.getTime() <= 60) {
|
|
557
|
+
const response = await RivendellApi.get<JwtResponse>(path(shard, 'tokens/jwt'));
|
|
558
|
+
cachedJwt = parseJwt(response.body.jwt);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
return cachedJwt.token;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
function parseJwt(token: string): Jwt {
|
|
565
|
+
const parts = token.split('.');
|
|
566
|
+
return {
|
|
567
|
+
token,
|
|
568
|
+
header: JSON.parse(Buffer.from(parts[0], 'base64').toString()),
|
|
569
|
+
payload: JSON.parse(Buffer.from(parts[1], 'base64').toString())
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
}
|