anbaric-impl-cloud 1.21.5 → 1.23.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/dist/CloudApiClient.d.ts +8 -0
- package/dist/CloudApiClient.d.ts.map +1 -0
- package/{src/CloudApiClient.ts → dist/CloudApiClient.js} +16 -19
- package/dist/CloudApiClient.js.map +1 -0
- package/dist/CloudAuditor.d.ts +8 -0
- package/dist/CloudAuditor.d.ts.map +1 -0
- package/dist/CloudAuditor.js +21 -0
- package/dist/CloudAuditor.js.map +1 -0
- package/dist/CloudJobPersistence.d.ts +15 -0
- package/dist/CloudJobPersistence.d.ts.map +1 -0
- package/dist/CloudJobPersistence.js +39 -0
- package/dist/CloudJobPersistence.js.map +1 -0
- package/dist/CloudJsonStore.d.ts +14 -0
- package/dist/CloudJsonStore.d.ts.map +1 -0
- package/{src/CloudJsonStore.ts → dist/CloudJsonStore.js} +14 -25
- package/dist/CloudJsonStore.js.map +1 -0
- package/dist/CloudQueue.d.ts +9 -0
- package/dist/CloudQueue.d.ts.map +1 -0
- package/dist/CloudQueue.js +15 -0
- package/dist/CloudQueue.js.map +1 -0
- package/dist/CloudSecretStore.d.ts +13 -0
- package/dist/CloudSecretStore.d.ts.map +1 -0
- package/dist/CloudSecretStore.js +30 -0
- package/dist/CloudSecretStore.js.map +1 -0
- package/dist/CloudSessionResolver.d.ts +9 -0
- package/dist/CloudSessionResolver.d.ts.map +1 -0
- package/{src/CloudSessionResolver.ts → dist/CloudSessionResolver.js} +11 -12
- package/dist/CloudSessionResolver.js.map +1 -0
- package/dist/PushConsumer.d.ts +22 -0
- package/dist/PushConsumer.d.ts.map +1 -0
- package/dist/PushConsumer.js +110 -0
- package/dist/PushConsumer.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/package.json +15 -6
- package/src/CloudAuditor.ts +0 -28
- package/src/CloudJobPersistence.ts +0 -51
- package/src/CloudQueue.ts +0 -22
- package/src/CloudSecretStore.ts +0 -40
- package/src/PushConsumer.ts +0 -125
- package/src/index.ts +0 -7
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare class CloudApiClient {
|
|
2
|
+
private baseUrl;
|
|
3
|
+
constructor(baseUrl: string);
|
|
4
|
+
static defaultBaseUrl(): string;
|
|
5
|
+
request(method: string, path: string, body?: unknown): Promise<any>;
|
|
6
|
+
}
|
|
7
|
+
export { CloudApiClient };
|
|
8
|
+
//# sourceMappingURL=CloudApiClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CloudApiClient.d.ts","sourceRoot":"","sources":["../src/CloudApiClient.ts"],"names":[],"mappings":"AAIA,cAAM,cAAc;IAEJ,OAAO,CAAC,OAAO;IAA3B,YAAoB,OAAO,EAAG,MAAM,EAAI;IAExC,MAAM,CAAC,cAAc,IAAK,MAAM,CAE/B;IAEK,OAAO,CAAC,MAAM,EAAG,MAAM,EAAE,IAAI,EAAG,MAAM,EAAE,IAAI,CAAC,EAAG,OAAO,GAAI,OAAO,CAAC,GAAG,CAAC,CAuB5E;CAEJ;AAED,OAAO,EAAE,cAAc,EAAE,CAAA"}
|
|
@@ -1,40 +1,37 @@
|
|
|
1
1
|
const DEFAULT_BASE_URL = "http://localhost:8787";
|
|
2
2
|
const API_PREFIX = "/api/v2";
|
|
3
3
|
const APP_HEADER = "x-anbaric-app";
|
|
4
|
-
|
|
5
4
|
class CloudApiClient {
|
|
6
|
-
|
|
7
|
-
constructor(
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
baseUrl;
|
|
6
|
+
constructor(baseUrl) {
|
|
7
|
+
this.baseUrl = baseUrl;
|
|
8
|
+
}
|
|
9
|
+
static defaultBaseUrl() {
|
|
10
10
|
return process.env.ANBARIC_CLOUD_URL ?? DEFAULT_BASE_URL;
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
async request(method : string, path : string, body? : unknown) : Promise<any> {
|
|
12
|
+
async request(method, path, body) {
|
|
14
13
|
// Every request carries the calling app's id as an ambient header, so
|
|
15
14
|
// the platform can scope app-owned resources (documents, secrets) to it
|
|
16
15
|
// without the app id appearing in any URL.
|
|
17
|
-
const headers
|
|
16
|
+
const headers = {};
|
|
18
17
|
const appId = process.env.ANBARIC_APP_ID;
|
|
19
|
-
if (appId)
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
if (appId)
|
|
19
|
+
headers[APP_HEADER] = appId;
|
|
20
|
+
if (body !== undefined)
|
|
21
|
+
headers["content-type"] = "application/json";
|
|
22
22
|
const response = await fetch(`${this.baseUrl}${API_PREFIX}${path}`, {
|
|
23
23
|
method,
|
|
24
24
|
headers,
|
|
25
25
|
body: body === undefined ? undefined : JSON.stringify(body),
|
|
26
26
|
});
|
|
27
|
-
|
|
28
27
|
if (!response.ok) {
|
|
29
|
-
const problem = await response.json().catch(() => ({}))
|
|
28
|
+
const problem = await response.json().catch(() => ({}));
|
|
30
29
|
throw new Error(problem.error ?? `${method} ${path} failed with status ${response.status}`);
|
|
31
30
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
if (response.status === 204)
|
|
32
|
+
return undefined;
|
|
35
33
|
return response.json();
|
|
36
34
|
}
|
|
37
|
-
|
|
38
35
|
}
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
export { CloudApiClient };
|
|
37
|
+
//# sourceMappingURL=CloudApiClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CloudApiClient.js","sourceRoot":"","sources":["../src/CloudApiClient.ts"],"names":[],"mappings":"AAAA,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AACjD,MAAM,UAAU,GAAG,SAAS,CAAC;AAC7B,MAAM,UAAU,GAAG,eAAe,CAAC;AAEnC,MAAM,cAAc;IAEI,OAAO;IAA3B,YAAoB,OAAgB;uBAAhB,OAAO;IAAY,CAAC;IAExC,MAAM,CAA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sapi";
|
|
2
|
+
declare class CloudAuditor implements Auditor {
|
|
3
|
+
private client;
|
|
4
|
+
constructor(baseUrl?: string);
|
|
5
|
+
audit(appId: string | undefined, resourceType: string, resourceId: string, actor: Actor, interaction: Array<string>, description: string, details: any): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
export { CloudAuditor };
|
|
8
|
+
//# sourceMappingURL=CloudAuditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CloudAuditor.d.ts","sourceRoot":"","sources":["../src/CloudAuditor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAG7C,cAAM,YAAa,YAAW,OAAO;IAEjC,OAAO,CAAC,MAAM,CAAkB;IAEhC,YAAY,OAAO,GAAG,MAAwC,EAE7D;IAEK,KAAK,CAAC,KAAK,EAAG,MAAM,GAAG,SAAS,EAAE,YAAY,EAAG,MAAM,EAAE,UAAU,EAAG,MAAM,EAAE,KAAK,EAAG,KAAK,EACrF,WAAW,EAAG,KAAK,CAAC,MAAM,CAAC,EAAE,WAAW,EAAG,MAAM,EAAE,OAAO,EAAG,GAAG,GAAI,OAAO,CAAC,IAAI,CAAC,CAW5F;CAEJ;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CloudApiClient } from "./CloudApiClient.js";
|
|
2
|
+
class CloudAuditor {
|
|
3
|
+
client;
|
|
4
|
+
constructor(baseUrl = CloudApiClient.defaultBaseUrl()) {
|
|
5
|
+
this.client = new CloudApiClient(baseUrl);
|
|
6
|
+
}
|
|
7
|
+
async audit(appId, resourceType, resourceId, actor, interaction, description, details) {
|
|
8
|
+
await this.client.request("POST", "/audits", {
|
|
9
|
+
appId: appId || undefined,
|
|
10
|
+
resourceType,
|
|
11
|
+
resourceId,
|
|
12
|
+
actorId: actor.id,
|
|
13
|
+
actorType: actor.type,
|
|
14
|
+
interaction,
|
|
15
|
+
description,
|
|
16
|
+
details: details ?? null,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export { CloudAuditor };
|
|
21
|
+
//# sourceMappingURL=CloudAuditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CloudAuditor.js","sourceRoot":"","sources":["../src/CloudAuditor.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AAEnD,MAAM,YAAY;IAEN,MAAM,CAAkB;IAEhC,YAAY,OAAO,GAAY,cAAc,CAAC,cAAc,EAAE;QAC1D,IAAI,CAAC,MAAM,GAAG,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,KAA0B,EAAE,YAAqB,EAAE,UAAmB,EAAE,KAAa,EACrF,WAA2B,EAAE,WAAoB,EAAE,OAAa;QACxE,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE;YACzC,KAAK,EAAE,KAAK,IAAI,SAAS;YACzB,YAAY;YACZ,UAAU;YACV,OAAO,EAAE,KAAK,CAAC,EAAE;YACjB,SAAS,EAAE,KAAK,CAAC,IAAI;YACrB,WAAW;YACX,WAAW;YACX,OAAO,EAAE,OAAO,IAAI,IAAI;SAC3B,CAAC,CAAC;IACP,CAAC;CAEJ;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AppAware, Auditor, Job, JobPersistence } from "anbaric-tsapi";
|
|
2
|
+
declare class CloudJobPersistence extends JobPersistence implements AppAware {
|
|
3
|
+
private client;
|
|
4
|
+
constructor(baseUrl?: string, auditor?: Auditor);
|
|
5
|
+
getAppId(): string;
|
|
6
|
+
protected saveInternal(job: Job): Promise<void>;
|
|
7
|
+
protected retrieveInternal(id: string): Promise<Job>;
|
|
8
|
+
protected deleteInternal(id: string): Promise<void>;
|
|
9
|
+
protected listInternal(pageSize?: number, page?: number): Promise<Array<Job>>;
|
|
10
|
+
protected killInternal(id: string): Promise<void>;
|
|
11
|
+
protected killOlderThanInternal(lastUpdatedBefore: Date): Promise<number>;
|
|
12
|
+
protected countByStateInternal(): Promise<Array<JobPersistence.StateCount>>;
|
|
13
|
+
}
|
|
14
|
+
export { CloudJobPersistence };
|
|
15
|
+
//# sourceMappingURL=CloudJobPersistence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CloudJobPersistence.d.ts","sourceRoot":"","sources":["../src/CloudJobPersistence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,OAAO,EAAgB,GAAG,EAAE,cAAc,EAA2D,MAAM,eAAe,CAAC;AAG7I,cAAM,mBAAoB,SAAQ,cAAe,YAAW,QAAQ;IAEhE,OAAO,CAAC,MAAM,CAAkB;IAEhC,YAAY,OAAO,GAAG,MAAwC,EAAE,OAAO,GAAG,OAA2B,EAGpG;IAED,QAAQ,IAAK,MAAM,CAElB;IAED,UAAgB,YAAY,CAAC,GAAG,EAAG,GAAG,GAAI,OAAO,CAAC,IAAI,CAAC,CAEtD;IAED,UAAgB,gBAAgB,CAAC,EAAE,EAAG,MAAM,GAAI,OAAO,CAAC,GAAG,CAAC,CAG3D;IAED,UAAgB,cAAc,CAAC,EAAE,EAAG,MAAM,GAAI,OAAO,CAAC,IAAI,CAAC,CAE1D;IAED,UAAgB,YAAY,CAAC,QAAQ,GAAG,MAAY,EAAE,IAAI,GAAG,MAAU,GAAI,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAG7F;IAED,UAAgB,YAAY,CAAC,EAAE,EAAG,MAAM,GAAI,OAAO,CAAC,IAAI,CAAC,CAExD;IAED,UAAgB,qBAAqB,CAAC,iBAAiB,EAAG,IAAI,GAAI,OAAO,CAAC,MAAM,CAAC,CAGhF;IAED,UAAgB,oBAAoB,IAAK,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAGjF;CAEJ;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { currentAppId, JobPersistence, NoOpAuditor, deserializeJob, serializeJob } from "anbaric-tsapi";
|
|
2
|
+
import { CloudApiClient } from "./CloudApiClient.js";
|
|
3
|
+
class CloudJobPersistence extends JobPersistence {
|
|
4
|
+
client;
|
|
5
|
+
constructor(baseUrl = CloudApiClient.defaultBaseUrl(), auditor = new NoOpAuditor()) {
|
|
6
|
+
super(auditor);
|
|
7
|
+
this.client = new CloudApiClient(baseUrl);
|
|
8
|
+
}
|
|
9
|
+
getAppId() {
|
|
10
|
+
return currentAppId();
|
|
11
|
+
}
|
|
12
|
+
async saveInternal(job) {
|
|
13
|
+
await this.client.request("PUT", `/jobs/${encodeURIComponent(job.id)}`, serializeJob(job));
|
|
14
|
+
}
|
|
15
|
+
async retrieveInternal(id) {
|
|
16
|
+
const serialized = await this.client.request("GET", `/jobs/${encodeURIComponent(id)}`);
|
|
17
|
+
return deserializeJob(serialized);
|
|
18
|
+
}
|
|
19
|
+
async deleteInternal(id) {
|
|
20
|
+
await this.client.request("DELETE", `/jobs/${encodeURIComponent(id)}`);
|
|
21
|
+
}
|
|
22
|
+
async listInternal(pageSize = 100, page = 0) {
|
|
23
|
+
const serialized = await this.client.request("GET", `/jobs?pageSize=${pageSize}&page=${page}`);
|
|
24
|
+
return serialized.map(deserializeJob);
|
|
25
|
+
}
|
|
26
|
+
async killInternal(id) {
|
|
27
|
+
await this.client.request("POST", `/jobs/${encodeURIComponent(id)}/kill`, {});
|
|
28
|
+
}
|
|
29
|
+
async killOlderThanInternal(lastUpdatedBefore) {
|
|
30
|
+
const result = await this.client.request("POST", "/jobs/kill-old", { before: lastUpdatedBefore.toISOString() });
|
|
31
|
+
return result.killed;
|
|
32
|
+
}
|
|
33
|
+
async countByStateInternal() {
|
|
34
|
+
const result = await this.client.request("GET", "/jobs/stats");
|
|
35
|
+
return result.states;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export { CloudJobPersistence };
|
|
39
|
+
//# sourceMappingURL=CloudJobPersistence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CloudJobPersistence.js","sourceRoot":"","sources":["../src/CloudJobPersistence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,YAAY,EAAO,cAAc,EAAE,WAAW,EAAiB,cAAc,EAAE,YAAY,EAAC,MAAM,eAAe,CAAC;AAC7I,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AAEnD,MAAM,mBAAoB,SAAQ,cAAc;IAEpC,MAAM,CAAkB;IAEhC,YAAY,OAAO,GAAY,cAAc,CAAC,cAAc,EAAE,EAAE,OAAO,GAAa,IAAI,WAAW,EAAE;QACjG,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,QAAQ;QACJ,OAAO,YAAY,EAAE,CAAC;IAC1B,CAAC;IAES,KAAK,CAAC,YAAY,CAAC,GAAS;QAClC,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/F,CAAC;IAES,KAAK,CAAC,gBAAgB,CAAC,EAAW;QACxC,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,kBAAkB,CAAC,EAAE,CAAC,EAAE,CAAkB,CAAC;QACxG,OAAO,cAAc,CAAC,UAAU,CAAC,CAAC;IACtC,CAAC;IAES,KAAK,CAAC,cAAc,CAAC,EAAW;QACtC,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,kBAAkB,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAC3E,CAAC;IAES,KAAK,CAAC,YAAY,CAAC,QAAQ,GAAY,GAAG,EAAE,IAAI,GAAY,CAAC;QACnE,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,kBAAkB,QAAQ,SAAS,IAAI,EAAE,CAAyB,CAAC;QACvH,OAAO,UAAU,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAC1C,CAAC;IAES,KAAK,CAAC,YAAY,CAAC,EAAW;QACpC,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,SAAS,kBAAkB,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAClF,CAAC;IAES,KAAK,CAAC,qBAAqB,CAAC,iBAAwB;QAC1D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,gBAAgB,EAAE,EAAE,MAAM,EAAE,iBAAiB,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QAChH,OAAO,MAAM,CAAC,MAAM,CAAC;IACzB,CAAC;IAES,KAAK,CAAC,oBAAoB;QAChC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;QAC/D,OAAO,MAAM,CAAC,MAAM,CAAC;IACzB,CAAC;CAEJ;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AppAware, Auditor, JsonSchema, JsonStore } from "anbaric-tsapi";
|
|
2
|
+
declare class CloudJsonStore extends JsonStore implements AppAware {
|
|
3
|
+
private client;
|
|
4
|
+
private schema?;
|
|
5
|
+
constructor(collection: string, schema?: JsonSchema, baseUrl?: string, auditor?: Auditor);
|
|
6
|
+
getAppId(): string;
|
|
7
|
+
protected saveInternal(id: string, document: any): Promise<void>;
|
|
8
|
+
protected retrieveInternal(id: string): Promise<any>;
|
|
9
|
+
protected deleteInternal(id: string): Promise<void>;
|
|
10
|
+
protected listInternal(pageSize?: number, page?: number): Promise<Array<any>>;
|
|
11
|
+
private documentPath;
|
|
12
|
+
}
|
|
13
|
+
export { CloudJsonStore };
|
|
14
|
+
//# sourceMappingURL=CloudJsonStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CloudJsonStore.d.ts","sourceRoot":"","sources":["../src/CloudJsonStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,OAAO,EAAgB,UAAU,EAAE,SAAS,EAAgC,MAAM,eAAe,CAAC;AAGpH,cAAM,cAAe,SAAQ,SAAU,YAAW,QAAQ;IAEtD,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,MAAM,CAAC,CAAc;IAE7B,YAAY,UAAU,EAAG,MAAM,EAAE,MAAM,CAAC,EAAG,UAAU,EACzC,OAAO,GAAG,MAAwC,EAAE,OAAO,GAAG,OAA2B,EAIpG;IAED,QAAQ,IAAK,MAAM,CAElB;IAED,UAAgB,YAAY,CAAC,EAAE,EAAG,MAAM,EAAE,QAAQ,EAAG,GAAG,GAAI,OAAO,CAAC,IAAI,CAAC,CAQxE;IAED,UAAgB,gBAAgB,CAAC,EAAE,EAAG,MAAM,GAAI,OAAO,CAAC,GAAG,CAAC,CAE3D;IAED,UAAgB,cAAc,CAAC,EAAE,EAAG,MAAM,GAAI,OAAO,CAAC,IAAI,CAAC,CAE1D;IAED,UAAgB,YAAY,CAAC,QAAQ,GAAG,MAAY,EAAE,IAAI,GAAG,MAAU,GAAI,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAE7F;IAED,OAAO,CAAC,YAAY;CAIvB;AAED,OAAO,EAAE,cAAc,EAAE,CAAA"}
|
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {CloudApiClient} from "./CloudApiClient";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
private schema? : JsonSchema;
|
|
8
|
-
|
|
9
|
-
constructor(collection : string, schema? : JsonSchema,
|
|
10
|
-
baseUrl : string = CloudApiClient.defaultBaseUrl(), auditor : Auditor = new NoOpAuditor()) {
|
|
1
|
+
import { currentAppId, JsonStore, NoOpAuditor, validateDocument } from "anbaric-tsapi";
|
|
2
|
+
import { CloudApiClient } from "./CloudApiClient.js";
|
|
3
|
+
class CloudJsonStore extends JsonStore {
|
|
4
|
+
client;
|
|
5
|
+
schema;
|
|
6
|
+
constructor(collection, schema, baseUrl = CloudApiClient.defaultBaseUrl(), auditor = new NoOpAuditor()) {
|
|
11
7
|
super(auditor, collection);
|
|
12
8
|
this.schema = schema;
|
|
13
9
|
this.client = new CloudApiClient(baseUrl);
|
|
14
10
|
}
|
|
15
|
-
|
|
16
|
-
getAppId() : string {
|
|
11
|
+
getAppId() {
|
|
17
12
|
return currentAppId();
|
|
18
13
|
}
|
|
19
|
-
|
|
20
|
-
protected async saveInternal(id : string, document : any) : Promise<void> {
|
|
14
|
+
async saveInternal(id, document) {
|
|
21
15
|
if (this.schema) {
|
|
22
16
|
const violations = validateDocument(document, this.schema);
|
|
23
17
|
if (violations.length > 0) {
|
|
@@ -26,23 +20,18 @@ class CloudJsonStore extends JsonStore implements AppAware {
|
|
|
26
20
|
}
|
|
27
21
|
await this.client.request("PUT", this.documentPath(id), document);
|
|
28
22
|
}
|
|
29
|
-
|
|
30
|
-
protected async retrieveInternal(id : string) : Promise<any> {
|
|
23
|
+
async retrieveInternal(id) {
|
|
31
24
|
return this.client.request("GET", this.documentPath(id));
|
|
32
25
|
}
|
|
33
|
-
|
|
34
|
-
protected async deleteInternal(id : string) : Promise<void> {
|
|
26
|
+
async deleteInternal(id) {
|
|
35
27
|
await this.client.request("DELETE", this.documentPath(id));
|
|
36
28
|
}
|
|
37
|
-
|
|
38
|
-
protected async listInternal(pageSize : number = 100, page : number = 0) : Promise<Array<any>> {
|
|
29
|
+
async listInternal(pageSize = 100, page = 0) {
|
|
39
30
|
return this.client.request("GET", `/documents/${encodeURIComponent(this.collection)}?pageSize=${pageSize}&page=${page}`);
|
|
40
31
|
}
|
|
41
|
-
|
|
42
|
-
private documentPath(id : string) : string {
|
|
32
|
+
documentPath(id) {
|
|
43
33
|
return `/documents/${encodeURIComponent(this.collection)}/${encodeURIComponent(id)}`;
|
|
44
34
|
}
|
|
45
|
-
|
|
46
35
|
}
|
|
47
|
-
|
|
48
|
-
|
|
36
|
+
export { CloudJsonStore };
|
|
37
|
+
//# sourceMappingURL=CloudJsonStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CloudJsonStore.js","sourceRoot":"","sources":["../src/CloudJsonStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,YAAY,EAAc,SAAS,EAAE,WAAW,EAAE,gBAAgB,EAAC,MAAM,eAAe,CAAC;AACpH,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AAEnD,MAAM,cAAe,SAAQ,SAAS;IAE1B,MAAM,CAAkB;IACxB,MAAM,CAAe;IAE7B,YAAY,UAAmB,EAAE,MAAoB,EACzC,OAAO,GAAY,cAAc,CAAC,cAAc,EAAE,EAAE,OAAO,GAAa,IAAI,WAAW,EAAE;QACjG,KAAK,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,QAAQ;QACJ,OAAO,YAAY,EAAE,CAAC;IAC1B,CAAC;IAES,KAAK,CAAC,YAAY,CAAC,EAAW,EAAE,QAAc;QACpD,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YACd,MAAM,UAAU,GAAG,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YAC3D,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACxB,MAAM,IAAI,KAAK,CAAC,aAAa,EAAE,+BAA+B,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC3F,CAAC;QACL,CAAC;QACD,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;IACtE,CAAC;IAES,KAAK,CAAC,gBAAgB,CAAC,EAAW;QACxC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7D,CAAC;IAES,KAAK,CAAC,cAAc,CAAC,EAAW;QACtC,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC;IAC/D,CAAC;IAES,KAAK,CAAC,YAAY,CAAC,QAAQ,GAAY,GAAG,EAAE,IAAI,GAAY,CAAC;QACnE,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,cAAc,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,aAAa,QAAQ,SAAS,IAAI,EAAE,CAAC,CAAC;IAC7H,CAAC;IAEO,YAAY,CAAC,EAAW;QAC5B,OAAO,cAAc,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,kBAAkB,CAAC,EAAE,CAAC,EAAE,CAAC;IACzF,CAAC;CAEJ;AAED,OAAO,EAAE,cAAc,EAAE,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Queue } from "anbaric-tsapi";
|
|
2
|
+
declare class CloudQueue implements Queue {
|
|
3
|
+
private client;
|
|
4
|
+
constructor(baseUrl?: string);
|
|
5
|
+
enqueue(jobId: string, appId: string | undefined, workflowId: string): Promise<void>;
|
|
6
|
+
schedule(jobId: string, appId: string | undefined, workflowId: string, due: Date): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export { CloudQueue };
|
|
9
|
+
//# sourceMappingURL=CloudQueue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CloudQueue.d.ts","sourceRoot":"","sources":["../src/CloudQueue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,eAAe,CAAC;AAGpC,cAAM,UAAW,YAAW,KAAK;IAE7B,OAAO,CAAC,MAAM,CAAkB;IAEhC,YAAY,OAAO,GAAG,MAAwC,EAE7D;IAEK,OAAO,CAAC,KAAK,EAAG,MAAM,EAAE,KAAK,EAAG,MAAM,GAAG,SAAS,EAAE,UAAU,EAAG,MAAM,GAAI,OAAO,CAAC,IAAI,CAAC,CAE7F;IAEK,QAAQ,CAAC,KAAK,EAAG,MAAM,EAAE,KAAK,EAAG,MAAM,GAAG,SAAS,EAAE,UAAU,EAAG,MAAM,EAAE,GAAG,EAAG,IAAI,GAAI,OAAO,CAAC,IAAI,CAAC,CAE1G;CAEJ;AAED,OAAO,EAAE,UAAU,EAAE,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CloudApiClient } from "./CloudApiClient.js";
|
|
2
|
+
class CloudQueue {
|
|
3
|
+
client;
|
|
4
|
+
constructor(baseUrl = CloudApiClient.defaultBaseUrl()) {
|
|
5
|
+
this.client = new CloudApiClient(baseUrl);
|
|
6
|
+
}
|
|
7
|
+
async enqueue(jobId, appId, workflowId) {
|
|
8
|
+
await this.client.request("POST", "/queue/enqueue", { jobId, appId, workflowId });
|
|
9
|
+
}
|
|
10
|
+
async schedule(jobId, appId, workflowId, due) {
|
|
11
|
+
await this.client.request("POST", "/queue/schedule", { jobId, appId, workflowId, due: due.toISOString() });
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export { CloudQueue };
|
|
15
|
+
//# sourceMappingURL=CloudQueue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CloudQueue.js","sourceRoot":"","sources":["../src/CloudQueue.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AAEnD,MAAM,UAAU;IAEJ,MAAM,CAAkB;IAEhC,YAAY,OAAO,GAAY,cAAc,CAAC,cAAc,EAAE;QAC1D,IAAI,CAAC,MAAM,GAAG,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,KAAc,EAAE,KAA0B,EAAE,UAAmB;QACzE,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,gBAAgB,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC;IACtF,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,KAAc,EAAE,KAA0B,EAAE,UAAmB,EAAE,GAAU;QACtF,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,iBAAiB,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAC/G,CAAC;CAEJ;AAED,OAAO,EAAE,UAAU,EAAE,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AppAware, Auditor, SecretStore } from "anbaric-tsapi";
|
|
2
|
+
declare class CloudSecretStore extends SecretStore implements AppAware {
|
|
3
|
+
private client;
|
|
4
|
+
constructor(baseUrl?: string, auditor?: Auditor);
|
|
5
|
+
getAppId(): string;
|
|
6
|
+
protected saveInternal(name: string, value: string): Promise<void>;
|
|
7
|
+
protected retrieveInternal(name: string): Promise<string>;
|
|
8
|
+
protected deleteInternal(name: string): Promise<void>;
|
|
9
|
+
protected listInternal(): Promise<Array<string>>;
|
|
10
|
+
private secretPath;
|
|
11
|
+
}
|
|
12
|
+
export { CloudSecretStore };
|
|
13
|
+
//# sourceMappingURL=CloudSecretStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CloudSecretStore.d.ts","sourceRoot":"","sources":["../src/CloudSecretStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,OAAO,EAA6B,WAAW,EAAC,MAAM,eAAe,CAAC;AAGxF,cAAM,gBAAiB,SAAQ,WAAY,YAAW,QAAQ;IAE1D,OAAO,CAAC,MAAM,CAAkB;IAEhC,YAAY,OAAO,GAAG,MAAwC,EAAE,OAAO,GAAG,OAA2B,EAGpG;IAED,QAAQ,IAAK,MAAM,CAElB;IAED,UAAgB,YAAY,CAAC,IAAI,EAAG,MAAM,EAAE,KAAK,EAAG,MAAM,GAAI,OAAO,CAAC,IAAI,CAAC,CAE1E;IAED,UAAgB,gBAAgB,CAAC,IAAI,EAAG,MAAM,GAAI,OAAO,CAAC,MAAM,CAAC,CAGhE;IAED,UAAgB,cAAc,CAAC,IAAI,EAAG,MAAM,GAAI,OAAO,CAAC,IAAI,CAAC,CAE5D;IAED,UAAgB,YAAY,IAAK,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAEtD;IAED,OAAO,CAAC,UAAU;CAIrB;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { currentAppId, NoOpAuditor, SecretStore } from "anbaric-tsapi";
|
|
2
|
+
import { CloudApiClient } from "./CloudApiClient.js";
|
|
3
|
+
class CloudSecretStore extends SecretStore {
|
|
4
|
+
client;
|
|
5
|
+
constructor(baseUrl = CloudApiClient.defaultBaseUrl(), auditor = new NoOpAuditor()) {
|
|
6
|
+
super(auditor);
|
|
7
|
+
this.client = new CloudApiClient(baseUrl);
|
|
8
|
+
}
|
|
9
|
+
getAppId() {
|
|
10
|
+
return currentAppId();
|
|
11
|
+
}
|
|
12
|
+
async saveInternal(name, value) {
|
|
13
|
+
await this.client.request("PUT", this.secretPath(name), { value });
|
|
14
|
+
}
|
|
15
|
+
async retrieveInternal(name) {
|
|
16
|
+
const secret = await this.client.request("GET", this.secretPath(name));
|
|
17
|
+
return secret.value;
|
|
18
|
+
}
|
|
19
|
+
async deleteInternal(name) {
|
|
20
|
+
await this.client.request("DELETE", this.secretPath(name));
|
|
21
|
+
}
|
|
22
|
+
async listInternal() {
|
|
23
|
+
return this.client.request("GET", "/secrets");
|
|
24
|
+
}
|
|
25
|
+
secretPath(name) {
|
|
26
|
+
return `/secrets/${encodeURIComponent(name)}`;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export { CloudSecretStore };
|
|
30
|
+
//# sourceMappingURL=CloudSecretStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CloudSecretStore.js","sourceRoot":"","sources":["../src/CloudSecretStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,YAAY,EAAE,WAAW,EAAE,WAAW,EAAC,MAAM,eAAe,CAAC;AACxF,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AAEnD,MAAM,gBAAiB,SAAQ,WAAW;IAE9B,MAAM,CAAkB;IAEhC,YAAY,OAAO,GAAY,cAAc,CAAC,cAAc,EAAE,EAAE,OAAO,GAAa,IAAI,WAAW,EAAE;QACjG,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,QAAQ;QACJ,OAAO,YAAY,EAAE,CAAC;IAC1B,CAAC;IAES,KAAK,CAAC,YAAY,CAAC,IAAa,EAAE,KAAc;QACtD,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IACvE,CAAC;IAES,KAAK,CAAC,gBAAgB,CAAC,IAAa;QAC1C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAuB,CAAC;QAC7F,OAAO,MAAM,CAAC,KAAK,CAAC;IACxB,CAAC;IAES,KAAK,CAAC,cAAc,CAAC,IAAa;QACxC,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/D,CAAC;IAES,KAAK,CAAC,YAAY;QACxB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IAClD,CAAC;IAEO,UAAU,CAAC,IAAa;QAC5B,OAAO,YAAY,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;IAClD,CAAC;CAEJ;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ResolvedSession, SessionResolver } from "anbaric-tsapi";
|
|
2
|
+
import { CloudApiClient } from "./CloudApiClient.js";
|
|
3
|
+
declare class CloudSessionResolver implements SessionResolver {
|
|
4
|
+
private client;
|
|
5
|
+
constructor(client?: CloudApiClient);
|
|
6
|
+
resolve(sessionToken: string): Promise<ResolvedSession | undefined>;
|
|
7
|
+
}
|
|
8
|
+
export { CloudSessionResolver };
|
|
9
|
+
//# sourceMappingURL=CloudSessionResolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CloudSessionResolver.d.ts","sourceRoot":"","sources":["../src/CloudSessionResolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,eAAe,EAAC,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AAKnD,cAAM,oBAAqB,YAAW,eAAe;IAErC,OAAO,CAAC,MAAM;IAA1B,YAAoB,MAAM,GAAG,cAAoE,EAAI;IAE/F,OAAO,CAAC,YAAY,EAAG,MAAM,GAAI,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC,CAO1E;CAEJ;AAED,OAAO,EAAE,oBAAoB,EAAE,CAAA"}
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {CloudApiClient} from "./CloudApiClient";
|
|
3
|
-
|
|
1
|
+
import { CloudApiClient } from "./CloudApiClient.js";
|
|
4
2
|
/* Resolves a platform session token by asking the platform to verify it (an app
|
|
5
3
|
holds no signing secret). A rejected request - an invalid or expired token
|
|
6
4
|
answers 401 - resolves to undefined. */
|
|
7
|
-
class CloudSessionResolver
|
|
8
|
-
|
|
9
|
-
constructor(
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
class CloudSessionResolver {
|
|
6
|
+
client;
|
|
7
|
+
constructor(client = new CloudApiClient(CloudApiClient.defaultBaseUrl())) {
|
|
8
|
+
this.client = client;
|
|
9
|
+
}
|
|
10
|
+
async resolve(sessionToken) {
|
|
12
11
|
try {
|
|
13
12
|
const result = await this.client.request("POST", "/sessions/resolve", { session: sessionToken });
|
|
14
13
|
return { id: result.id, roles: result.roles ?? [], tenant: result.tenant };
|
|
15
|
-
}
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
16
|
return undefined;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
|
|
20
19
|
}
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
export { CloudSessionResolver };
|
|
21
|
+
//# sourceMappingURL=CloudSessionResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CloudSessionResolver.js","sourceRoot":"","sources":["../src/CloudSessionResolver.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AAEnD;;0CAE0C;AAC1C,MAAM,oBAAoB;IAEF,MAAM;IAA1B,YAAoB,MAAM,GAAoB,IAAI,cAAc,CAAC,cAAc,CAAC,cAAc,EAAE,CAAC;sBAA7E,MAAM;IAA0E,CAAC;IAErG,KAAK,CAAC,OAAO,CAAC,YAAqB;QAC/B,IAAI,CAAC;YACD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,mBAAmB,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,CAAC;YACjG,OAAO,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;QAC/E,CAAC;QAAC,MAAM,CAAC;YACL,OAAO,SAAS,CAAC;QACrB,CAAC;IACL,CAAC;CAEJ;AAED,OAAO,EAAE,oBAAoB,EAAE,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Consumer } from "anbaric-tsapi";
|
|
2
|
+
type ProcessJob = (jobId: string) => Promise<void>;
|
|
3
|
+
declare class PushConsumer implements Consumer {
|
|
4
|
+
private listenPort;
|
|
5
|
+
private subscribers;
|
|
6
|
+
private client;
|
|
7
|
+
private server?;
|
|
8
|
+
private listening?;
|
|
9
|
+
private boundPort?;
|
|
10
|
+
constructor(baseUrl?: string, listenPort?: number);
|
|
11
|
+
get port(): number | undefined;
|
|
12
|
+
private key;
|
|
13
|
+
subscribe(appId: string | undefined, workflowId: string, processJob: ProcessJob): void;
|
|
14
|
+
private register;
|
|
15
|
+
cleanUp(): Promise<void>;
|
|
16
|
+
private listen;
|
|
17
|
+
private handle;
|
|
18
|
+
private processAll;
|
|
19
|
+
private reply;
|
|
20
|
+
}
|
|
21
|
+
export { PushConsumer };
|
|
22
|
+
//# sourceMappingURL=PushConsumer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PushConsumer.d.ts","sourceRoot":"","sources":["../src/PushConsumer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,QAAQ,EAAe,MAAM,eAAe,CAAC;AAGrD,KAAK,UAAU,GAAG,CAAC,KAAK,EAAG,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAiBpD,cAAM,YAAa,YAAW,QAAQ;IAStB,OAAO,CAAC,UAAU;IAP9B,OAAO,CAAC,WAAW,CAAiC;IACpD,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,MAAM,CAAC,CAAU;IACzB,OAAO,CAAC,SAAS,CAAC,CAAiB;IACnC,OAAO,CAAC,SAAS,CAAC,CAAU;IAE5B,YAAY,OAAO,GAAG,MAAwC,EAC1C,UAAU,GAAG,MAA0D,EAE1F;IAED,IAAI,IAAI,IAAK,MAAM,GAAG,SAAS,CAE9B;IAID,OAAO,CAAC,GAAG;IAIX,SAAS,CAAC,KAAK,EAAG,MAAM,GAAG,SAAS,EAAE,UAAU,EAAG,MAAM,EAAE,UAAU,EAAG,UAAU,GAAI,IAAI,CAIzF;YAEa,QAAQ;IAShB,OAAO,IAAK,OAAO,CAAC,IAAI,CAAC,CAQ9B;IAED,OAAO,CAAC,MAAM;YAaA,MAAM;YAiBN,UAAU;IAYxB,OAAO,CAAC,KAAK;CAUhB;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import { CloudApiClient } from "./CloudApiClient.js";
|
|
3
|
+
const readBody = (request) => new Promise((resolve, reject) => {
|
|
4
|
+
const chunks = [];
|
|
5
|
+
request.on("data", chunk => chunks.push(chunk));
|
|
6
|
+
request.on("error", reject);
|
|
7
|
+
request.on("end", () => {
|
|
8
|
+
const raw = Buffer.concat(chunks).toString();
|
|
9
|
+
try {
|
|
10
|
+
resolve(raw.length === 0 ? undefined : JSON.parse(raw));
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
reject(error);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
class PushConsumer {
|
|
18
|
+
listenPort;
|
|
19
|
+
subscribers = new Map();
|
|
20
|
+
client;
|
|
21
|
+
server;
|
|
22
|
+
listening;
|
|
23
|
+
boundPort;
|
|
24
|
+
constructor(baseUrl = CloudApiClient.defaultBaseUrl(), listenPort = Number(process.env.ANBARIC_CONSUMER_PORT ?? 8788)) {
|
|
25
|
+
this.listenPort = listenPort;
|
|
26
|
+
this.client = new CloudApiClient(baseUrl);
|
|
27
|
+
}
|
|
28
|
+
get port() {
|
|
29
|
+
return this.boundPort;
|
|
30
|
+
}
|
|
31
|
+
// Subscribers are keyed by the (appId, workflowId) composite, encoded as a
|
|
32
|
+
// tuple so an app and a machine id can never collide.
|
|
33
|
+
key(appId, workflowId) {
|
|
34
|
+
return JSON.stringify([appId || null, workflowId]);
|
|
35
|
+
}
|
|
36
|
+
subscribe(appId, workflowId, processJob) {
|
|
37
|
+
this.subscribers.set(this.key(appId, workflowId), processJob);
|
|
38
|
+
if (!this.server)
|
|
39
|
+
this.listening = this.listen();
|
|
40
|
+
void this.register(appId, workflowId);
|
|
41
|
+
}
|
|
42
|
+
async register(appId, workflowId) {
|
|
43
|
+
try {
|
|
44
|
+
await this.listening;
|
|
45
|
+
const url = process.env.ANBARIC_CONSUMER_URL ?? `http://localhost:${this.boundPort}`;
|
|
46
|
+
await this.client.request("POST", "/consumers", { appId, workflowId, url });
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async cleanUp() {
|
|
52
|
+
this.subscribers.clear();
|
|
53
|
+
if (!this.server)
|
|
54
|
+
return;
|
|
55
|
+
await this.listening;
|
|
56
|
+
await new Promise((resolve, reject) => this.server.close(error => error ? reject(error) : resolve()));
|
|
57
|
+
this.server = undefined;
|
|
58
|
+
this.boundPort = undefined;
|
|
59
|
+
}
|
|
60
|
+
listen() {
|
|
61
|
+
this.server = createServer((request, response) => {
|
|
62
|
+
this.handle(request, response).catch(error => {
|
|
63
|
+
const message = error instanceof Error ? error.message : "Internal error";
|
|
64
|
+
this.reply(response, 500, { error: message });
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
return new Promise(resolve => this.server.listen(this.listenPort, () => {
|
|
68
|
+
this.boundPort = this.server.address().port;
|
|
69
|
+
resolve();
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
async handle(request, response) {
|
|
73
|
+
const url = new URL(request.url ?? "/", "http://localhost");
|
|
74
|
+
if (request.method === "POST" && url.pathname === "/process") {
|
|
75
|
+
const body = await readBody(request);
|
|
76
|
+
if (!body || !Array.isArray(body.messages)) {
|
|
77
|
+
return this.reply(response, 400, { error: "Expected a body of { messages : Array<QueueMessage> }" });
|
|
78
|
+
}
|
|
79
|
+
const messages = body.messages;
|
|
80
|
+
this.reply(response, 202, { accepted: messages.map(message => message.jobId) });
|
|
81
|
+
void this.processAll(messages);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
this.reply(response, 404, { error: "Not found" });
|
|
85
|
+
}
|
|
86
|
+
async processAll(messages) {
|
|
87
|
+
for (const message of messages) {
|
|
88
|
+
const processJob = this.subscribers.get(this.key(message.appId, message.workflowId));
|
|
89
|
+
if (!processJob)
|
|
90
|
+
continue;
|
|
91
|
+
try {
|
|
92
|
+
await processJob(message.jobId);
|
|
93
|
+
await this.client.request("POST", "/queue/confirm", message);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
reply(response, status, body) {
|
|
100
|
+
if (body === undefined) {
|
|
101
|
+
response.statusCode = status;
|
|
102
|
+
response.end();
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
response.writeHead(status, { "content-type": "application/json" });
|
|
106
|
+
response.end(JSON.stringify(body));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export { PushConsumer };
|
|
110
|
+
//# sourceMappingURL=PushConsumer.js.map
|
|
@@ -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,CAAC,QAAyB,EAAE,MAAe,EAAE,IAAe;QACrE,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACrB,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC;YAC7B,QAAQ,CAAC,GAAG,EAAE,CAAC;YACf,OAAO;QACX,CAAC;QACD,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC,CAAC;QACnE,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IACvC,CAAC;CAEJ;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./PushConsumer.js";
|
|
2
|
+
export * from "./CloudJobPersistence.js";
|
|
3
|
+
export * from "./CloudJsonStore.js";
|
|
4
|
+
export * from "./CloudSecretStore.js";
|
|
5
|
+
export * from "./CloudQueue.js";
|
|
6
|
+
export * from "./CloudAuditor.js";
|
|
7
|
+
export * from "./CloudSessionResolver.js";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./PushConsumer.js";
|
|
2
|
+
export * from "./CloudJobPersistence.js";
|
|
3
|
+
export * from "./CloudJsonStore.js";
|
|
4
|
+
export * from "./CloudSecretStore.js";
|
|
5
|
+
export * from "./CloudQueue.js";
|
|
6
|
+
export * from "./CloudAuditor.js";
|
|
7
|
+
export * from "./CloudSessionResolver.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,23 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "anbaric-impl-cloud",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.23.0",
|
|
4
4
|
"description": "Public client library for the Anbaric Cloud hosting API, providing JobPersistence and Queue implementations backed by the cloud service",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "chris@anbaric.ai",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"main": "
|
|
9
|
-
"types": "
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
10
17
|
"scripts": {
|
|
11
|
-
"test": "vitest run"
|
|
18
|
+
"test": "vitest run",
|
|
19
|
+
"build": "tsc -b tsconfig.build.json",
|
|
20
|
+
"prepublishOnly": "npm run build"
|
|
12
21
|
},
|
|
13
22
|
"dependencies": {
|
|
14
|
-
"anbaric-tsapi": "^1.
|
|
23
|
+
"anbaric-tsapi": "^1.23.0"
|
|
15
24
|
},
|
|
16
25
|
"devDependencies": {
|
|
17
26
|
"@types/node": "^26.2.0",
|
|
18
27
|
"typescript": "^7.0.2"
|
|
19
28
|
},
|
|
20
29
|
"files": [
|
|
21
|
-
"
|
|
30
|
+
"dist"
|
|
22
31
|
]
|
|
23
32
|
}
|
package/src/CloudAuditor.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import {Actor, Auditor} from "anbaric-tsapi";
|
|
2
|
-
import {CloudApiClient} from "./CloudApiClient";
|
|
3
|
-
|
|
4
|
-
class CloudAuditor implements Auditor {
|
|
5
|
-
|
|
6
|
-
private client : CloudApiClient;
|
|
7
|
-
|
|
8
|
-
constructor(baseUrl : string = CloudApiClient.defaultBaseUrl()) {
|
|
9
|
-
this.client = new CloudApiClient(baseUrl);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
async audit(appId : string | undefined, resourceType : string, resourceId : string, actor : Actor,
|
|
13
|
-
interaction : Array<string>, description : string, details : any) : Promise<void> {
|
|
14
|
-
await this.client.request("POST", "/audits", {
|
|
15
|
-
appId: appId || undefined,
|
|
16
|
-
resourceType,
|
|
17
|
-
resourceId,
|
|
18
|
-
actorId: actor.id,
|
|
19
|
-
actorType: actor.type,
|
|
20
|
-
interaction,
|
|
21
|
-
description,
|
|
22
|
-
details: details ?? null,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export { CloudAuditor }
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import {AppAware, Auditor, currentAppId, Job, JobPersistence, NoOpAuditor, SerializedJob, deserializeJob, serializeJob} from "anbaric-tsapi";
|
|
2
|
-
import {CloudApiClient} from "./CloudApiClient";
|
|
3
|
-
|
|
4
|
-
class CloudJobPersistence extends JobPersistence implements AppAware {
|
|
5
|
-
|
|
6
|
-
private client : CloudApiClient;
|
|
7
|
-
|
|
8
|
-
constructor(baseUrl : string = CloudApiClient.defaultBaseUrl(), auditor : Auditor = new NoOpAuditor()) {
|
|
9
|
-
super(auditor);
|
|
10
|
-
this.client = new CloudApiClient(baseUrl);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
getAppId() : string {
|
|
14
|
-
return currentAppId();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
protected async saveInternal(job : Job) : Promise<void> {
|
|
18
|
-
await this.client.request("PUT", `/jobs/${encodeURIComponent(job.id)}`, serializeJob(job));
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
protected async retrieveInternal(id : string) : Promise<Job> {
|
|
22
|
-
const serialized = await this.client.request("GET", `/jobs/${encodeURIComponent(id)}`) as SerializedJob;
|
|
23
|
-
return deserializeJob(serialized);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
protected async deleteInternal(id : string) : Promise<void> {
|
|
27
|
-
await this.client.request("DELETE", `/jobs/${encodeURIComponent(id)}`);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
protected async listInternal(pageSize : number = 100, page : number = 0) : Promise<Array<Job>> {
|
|
31
|
-
const serialized = await this.client.request("GET", `/jobs?pageSize=${pageSize}&page=${page}`) as Array<SerializedJob>;
|
|
32
|
-
return serialized.map(deserializeJob);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
protected async killInternal(id : string) : Promise<void> {
|
|
36
|
-
await this.client.request("POST", `/jobs/${encodeURIComponent(id)}/kill`, {});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
protected async killOlderThanInternal(lastUpdatedBefore : Date) : Promise<number> {
|
|
40
|
-
const result = await this.client.request("POST", "/jobs/kill-old", { before: lastUpdatedBefore.toISOString() });
|
|
41
|
-
return result.killed;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
protected async countByStateInternal() : Promise<Array<JobPersistence.StateCount>> {
|
|
45
|
-
const result = await this.client.request("GET", "/jobs/stats");
|
|
46
|
-
return result.states;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export { CloudJobPersistence }
|
package/src/CloudQueue.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import {Queue} from "anbaric-tsapi";
|
|
2
|
-
import {CloudApiClient} from "./CloudApiClient";
|
|
3
|
-
|
|
4
|
-
class CloudQueue implements Queue {
|
|
5
|
-
|
|
6
|
-
private client : CloudApiClient;
|
|
7
|
-
|
|
8
|
-
constructor(baseUrl : string = CloudApiClient.defaultBaseUrl()) {
|
|
9
|
-
this.client = new CloudApiClient(baseUrl);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
async enqueue(jobId : string, appId : string | undefined, workflowId : string) : Promise<void> {
|
|
13
|
-
await this.client.request("POST", "/queue/enqueue", { jobId, appId, workflowId });
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async schedule(jobId : string, appId : string | undefined, workflowId : string, due : Date) : Promise<void> {
|
|
17
|
-
await this.client.request("POST", "/queue/schedule", { jobId, appId, workflowId, due: due.toISOString() });
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export { CloudQueue }
|
package/src/CloudSecretStore.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import {AppAware, Auditor, currentAppId, NoOpAuditor, SecretStore} from "anbaric-tsapi";
|
|
2
|
-
import {CloudApiClient} from "./CloudApiClient";
|
|
3
|
-
|
|
4
|
-
class CloudSecretStore extends SecretStore implements AppAware {
|
|
5
|
-
|
|
6
|
-
private client : CloudApiClient;
|
|
7
|
-
|
|
8
|
-
constructor(baseUrl : string = CloudApiClient.defaultBaseUrl(), auditor : Auditor = new NoOpAuditor()) {
|
|
9
|
-
super(auditor);
|
|
10
|
-
this.client = new CloudApiClient(baseUrl);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
getAppId() : string {
|
|
14
|
-
return currentAppId();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
protected async saveInternal(name : string, value : string) : Promise<void> {
|
|
18
|
-
await this.client.request("PUT", this.secretPath(name), { value });
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
protected async retrieveInternal(name : string) : Promise<string> {
|
|
22
|
-
const secret = await this.client.request("GET", this.secretPath(name)) as { value : string };
|
|
23
|
-
return secret.value;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
protected async deleteInternal(name : string) : Promise<void> {
|
|
27
|
-
await this.client.request("DELETE", this.secretPath(name));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
protected async listInternal() : Promise<Array<string>> {
|
|
31
|
-
return this.client.request("GET", "/secrets");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
private secretPath(name : string) : string {
|
|
35
|
-
return `/secrets/${encodeURIComponent(name)}`;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export { CloudSecretStore }
|
package/src/PushConsumer.ts
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import {createServer, IncomingMessage, Server, ServerResponse} from "node:http";
|
|
2
|
-
import {AddressInfo} from "node:net";
|
|
3
|
-
import {Consumer, QueueMessage} from "anbaric-tsapi";
|
|
4
|
-
import {CloudApiClient} from "./CloudApiClient";
|
|
5
|
-
|
|
6
|
-
type ProcessJob = (jobId : string) => Promise<void>;
|
|
7
|
-
|
|
8
|
-
const readBody = (request : IncomingMessage) : Promise<any> =>
|
|
9
|
-
new Promise((resolve, reject) => {
|
|
10
|
-
const chunks : Array<Buffer> = [];
|
|
11
|
-
request.on("data", chunk => chunks.push(chunk));
|
|
12
|
-
request.on("error", reject);
|
|
13
|
-
request.on("end", () => {
|
|
14
|
-
const raw = Buffer.concat(chunks).toString();
|
|
15
|
-
try {
|
|
16
|
-
resolve(raw.length === 0 ? undefined : JSON.parse(raw));
|
|
17
|
-
} catch (error) {
|
|
18
|
-
reject(error);
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
class PushConsumer implements Consumer {
|
|
24
|
-
|
|
25
|
-
private subscribers = new Map<string, ProcessJob>();
|
|
26
|
-
private client : CloudApiClient;
|
|
27
|
-
private server? : Server;
|
|
28
|
-
private listening? : Promise<void>;
|
|
29
|
-
private boundPort? : number;
|
|
30
|
-
|
|
31
|
-
constructor(baseUrl : string = CloudApiClient.defaultBaseUrl(),
|
|
32
|
-
private listenPort : number = Number(process.env.ANBARIC_CONSUMER_PORT ?? 8788)) {
|
|
33
|
-
this.client = new CloudApiClient(baseUrl);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
get port() : number | undefined {
|
|
37
|
-
return this.boundPort;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Subscribers are keyed by the (appId, workflowId) composite, encoded as a
|
|
41
|
-
// tuple so an app and a machine id can never collide.
|
|
42
|
-
private key(appId : string | undefined, workflowId : string) : string {
|
|
43
|
-
return JSON.stringify([appId || null, workflowId]);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
subscribe(appId : string | undefined, workflowId : string, processJob : ProcessJob) : void {
|
|
47
|
-
this.subscribers.set(this.key(appId, workflowId), processJob);
|
|
48
|
-
if (!this.server) this.listening = this.listen();
|
|
49
|
-
void this.register(appId, workflowId);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
private async register(appId : string | undefined, workflowId : string) : Promise<void> {
|
|
53
|
-
try {
|
|
54
|
-
await this.listening;
|
|
55
|
-
const url = process.env.ANBARIC_CONSUMER_URL ?? `http://localhost:${this.boundPort}`;
|
|
56
|
-
await this.client.request("POST", "/consumers", { appId, workflowId, url });
|
|
57
|
-
} catch {
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async cleanUp() : Promise<void> {
|
|
62
|
-
this.subscribers.clear();
|
|
63
|
-
if (!this.server) return;
|
|
64
|
-
await this.listening;
|
|
65
|
-
await new Promise<void>((resolve, reject) =>
|
|
66
|
-
this.server!.close(error => error ? reject(error) : resolve()));
|
|
67
|
-
this.server = undefined;
|
|
68
|
-
this.boundPort = undefined;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
private listen() : Promise<void> {
|
|
72
|
-
this.server = createServer((request, response) => {
|
|
73
|
-
this.handle(request, response).catch(error => {
|
|
74
|
-
const message = error instanceof Error ? error.message : "Internal error";
|
|
75
|
-
this.reply(response, 500, { error: message });
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
return new Promise(resolve => this.server!.listen(this.listenPort, () => {
|
|
79
|
-
this.boundPort = (this.server!.address() as AddressInfo).port;
|
|
80
|
-
resolve();
|
|
81
|
-
}));
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
private async handle(request : IncomingMessage, response : ServerResponse) : Promise<void> {
|
|
85
|
-
const url = new URL(request.url ?? "/", "http://localhost");
|
|
86
|
-
|
|
87
|
-
if (request.method === "POST" && url.pathname === "/process") {
|
|
88
|
-
const body = await readBody(request);
|
|
89
|
-
if (!body || !Array.isArray(body.messages)) {
|
|
90
|
-
return this.reply(response, 400, { error: "Expected a body of { messages : Array<QueueMessage> }" });
|
|
91
|
-
}
|
|
92
|
-
const messages = body.messages as Array<QueueMessage>;
|
|
93
|
-
this.reply(response, 202, { accepted: messages.map(message => message.jobId) });
|
|
94
|
-
void this.processAll(messages);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
this.reply(response, 404, { error: "Not found" });
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
private async processAll(messages : Array<QueueMessage>) : Promise<void> {
|
|
102
|
-
for (const message of messages) {
|
|
103
|
-
const processJob = this.subscribers.get(this.key(message.appId, message.workflowId));
|
|
104
|
-
if (!processJob) continue;
|
|
105
|
-
try {
|
|
106
|
-
await processJob(message.jobId);
|
|
107
|
-
await this.client.request("POST", "/queue/confirm", message);
|
|
108
|
-
} catch {
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
private reply(response : ServerResponse, status : number, body? : unknown) : void {
|
|
114
|
-
if (body === undefined) {
|
|
115
|
-
response.statusCode = status;
|
|
116
|
-
response.end();
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
response.writeHead(status, { "content-type": "application/json" });
|
|
120
|
-
response.end(JSON.stringify(body));
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export { PushConsumer }
|
package/src/index.ts
DELETED