@magda/minion-framework 2.3.3 → 3.0.0-alpha.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/Crawler.d.ts +8 -8
- package/dist/Crawler.js +62 -99
- package/dist/Crawler.js.map +1 -1
- package/dist/MinionOptions.d.ts +6 -5
- package/dist/MinionOptions.js +1 -2
- package/dist/buildWebhookConfig.d.ts +2 -2
- package/dist/buildWebhookConfig.js +4 -7
- package/dist/buildWebhookConfig.js.map +1 -1
- package/dist/commonYargs.d.ts +10 -10
- package/dist/commonYargs.js +31 -37
- package/dist/commonYargs.js.map +1 -1
- package/dist/getWebhookUrl.d.ts +1 -1
- package/dist/getWebhookUrl.js +2 -5
- package/dist/getWebhookUrl.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +111 -127
- package/dist/index.js.map +1 -1
- package/dist/isWebhookRegistered.d.ts +2 -2
- package/dist/isWebhookRegistered.js +14 -31
- package/dist/isWebhookRegistered.js.map +1 -1
- package/dist/registerWebhook.d.ts +5 -5
- package/dist/registerWebhook.js +33 -50
- package/dist/registerWebhook.js.map +1 -1
- package/dist/resumeWebhook.d.ts +3 -3
- package/dist/resumeWebhook.js +8 -22
- package/dist/resumeWebhook.js.map +1 -1
- package/dist/setupRecrawlEndpoint.d.ts +30 -30
- package/dist/setupRecrawlEndpoint.js +46 -45
- package/dist/setupRecrawlEndpoint.js.map +1 -1
- package/dist/setupWebhookEndpoint.d.ts +2 -2
- package/dist/setupWebhookEndpoint.js +22 -47
- package/dist/setupWebhookEndpoint.js.map +1 -1
- package/dist/startApiEndpoints.d.ts +1 -1
- package/dist/startApiEndpoints.js +4 -10
- package/dist/startApiEndpoints.js.map +1 -1
- package/dist/test/Crawler.spec.js +77 -93
- package/dist/test/Crawler.spec.js.map +1 -1
- package/dist/test/baseSpec.d.ts +10 -10
- package/dist/test/baseSpec.js +23 -25
- package/dist/test/baseSpec.js.map +1 -1
- package/dist/test/fakeArgv.d.ts +3 -3
- package/dist/test/fakeArgv.js +6 -6
- package/dist/test/fakeArgv.js.map +1 -1
- package/dist/test/makePromiseQueryable.d.ts +2 -2
- package/dist/test/makePromiseQueryable.js +2 -5
- package/dist/test/makePromiseQueryable.js.map +1 -1
- package/dist/test/registry.spec.js +27 -32
- package/dist/test/registry.spec.js.map +1 -1
- package/dist/test/setupRecrawlEndpoint.spec.js +29 -43
- package/dist/test/setupRecrawlEndpoint.spec.js.map +1 -1
- package/dist/test/startup.spec.js +33 -38
- package/dist/test/startup.spec.js.map +1 -1
- package/dist/test/webhooks.spec.js +43 -43
- package/dist/test/webhooks.spec.js.map +1 -1
- package/package.json +33 -21
package/dist/index.js
CHANGED
|
@@ -1,132 +1,116 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import express from "express";
|
|
2
|
+
import Registry from "@magda/typescript-common/dist/registry/AuthorizedRegistryClient.js";
|
|
3
|
+
import setupWebhookEndpoint from "./setupWebhookEndpoint.js";
|
|
4
|
+
import setupRecrawlEndpoint from "./setupRecrawlEndpoint.js";
|
|
5
|
+
import startApiEndpoints from "./startApiEndpoints.js";
|
|
6
|
+
import isWebhookRegistered from "./isWebhookRegistered.js";
|
|
7
|
+
import registerWebhook from "./registerWebhook.js";
|
|
8
|
+
import resumeWebhook from "./resumeWebhook.js";
|
|
9
|
+
import Crawler from "./Crawler.js";
|
|
10
|
+
import AuthorizedTenantClient from "@magda/typescript-common/dist/tenant-api/AuthorizedTenantClient.js";
|
|
11
|
+
import { MAGDA_ADMIN_PORTAL_ID } from "@magda/typescript-common/dist/registry/TenantConsts.js";
|
|
12
|
+
import { MAGDA_SYSTEM_ID } from "@magda/typescript-common/dist/registry/TenantConsts.js";
|
|
13
|
+
export default async function minion(options) {
|
|
14
|
+
checkOptions(options);
|
|
15
|
+
const registry = new Registry({
|
|
16
|
+
baseUrl: options.argv.registryUrl,
|
|
17
|
+
jwtSecret: options.argv.jwtSecret,
|
|
18
|
+
userId: options.argv.userId,
|
|
19
|
+
maxRetries: options.maxRetries,
|
|
20
|
+
tenantId: MAGDA_SYSTEM_ID
|
|
9
21
|
});
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const crawler = new Crawler_1.default(registry, options);
|
|
47
|
-
options.express = options.express || (() => express_1.default());
|
|
48
|
-
const server = options.express();
|
|
49
|
-
server.use(require("body-parser").json({ limit: "50mb" }));
|
|
50
|
-
server.get("/healthz", (request, response) => {
|
|
51
|
-
response.status(200).send("OK");
|
|
52
|
-
});
|
|
53
|
-
setupWebhookEndpoint_1.default(server, options, registry);
|
|
54
|
-
setupRecrawlEndpoint_1.default(server, options, crawler);
|
|
55
|
-
startApiEndpoints_1.default(server, options);
|
|
56
|
-
yield putAspectDefs();
|
|
57
|
-
const webhookRegistered = yield isWebhookRegistered_1.default(options, registry);
|
|
58
|
-
if (webhookRegistered) {
|
|
59
|
-
console.info("Webhook is already registered");
|
|
60
|
-
yield resumeWebhook_1.default(options, registry);
|
|
61
|
-
} else
|
|
62
|
-
{
|
|
63
|
-
console.info("No webhook was registered");
|
|
64
|
-
yield registerWebhook_1.default(options, registry);
|
|
65
|
-
yield crawler.start();
|
|
22
|
+
const tenantClient = options.argv.enableMultiTenant ?
|
|
23
|
+
new AuthorizedTenantClient({
|
|
24
|
+
urlStr: options.argv.tenantUrl,
|
|
25
|
+
maxRetries: 1,
|
|
26
|
+
secondsBetweenRetries: 1,
|
|
27
|
+
jwtSecret: options.argv.jwtSecret,
|
|
28
|
+
userId: options.argv.userId
|
|
29
|
+
}) :
|
|
30
|
+
null;
|
|
31
|
+
const crawler = new Crawler(registry, options);
|
|
32
|
+
options.express = options.express || (() => express());
|
|
33
|
+
const server = options.express();
|
|
34
|
+
server.use(express.json({ limit: "50mb" }));
|
|
35
|
+
server.get("/healthz", (request, response) => {
|
|
36
|
+
response.status(200).send("OK");
|
|
37
|
+
});
|
|
38
|
+
setupWebhookEndpoint(server, options, registry);
|
|
39
|
+
setupRecrawlEndpoint(server, options, crawler);
|
|
40
|
+
startApiEndpoints(server, options);
|
|
41
|
+
await putAspectDefs();
|
|
42
|
+
const webhookRegistered = await isWebhookRegistered(options, registry);
|
|
43
|
+
if (webhookRegistered) {
|
|
44
|
+
console.info("Webhook is already registered");
|
|
45
|
+
await resumeWebhook(options, registry);
|
|
46
|
+
} else
|
|
47
|
+
{
|
|
48
|
+
console.info("No webhook was registered");
|
|
49
|
+
await registerWebhook(options, registry);
|
|
50
|
+
await crawler.start();
|
|
51
|
+
}
|
|
52
|
+
function checkOptions(options) {
|
|
53
|
+
let listenPort = options?.argv?.listenPort;
|
|
54
|
+
listenPort =
|
|
55
|
+
typeof listenPort === "number" ? listenPort : parseInt(listenPort);
|
|
56
|
+
if (listenPort <= 0 || listenPort > 65535 || isNaN(listenPort)) {
|
|
57
|
+
throw new Error(`Default port of ${options.argv.listenPort} is invalid`);
|
|
66
58
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
throw new Error(`Default port of ${options.argv.listenPort} is invalid`);
|
|
70
|
-
}
|
|
71
|
-
if (options.id === "") {
|
|
72
|
-
throw new Error(`id is unspecified`);
|
|
73
|
-
}
|
|
74
|
-
if (options.argv.internalUrl === "") {
|
|
75
|
-
throw new Error(`Internal url is unspecified`);
|
|
76
|
-
}
|
|
77
|
-
if (options.argv.registryUrl === "") {
|
|
78
|
-
throw new Error(`Registry url is unspecified`);
|
|
79
|
-
}
|
|
80
|
-
if (options.argv.jwtSecret === "") {
|
|
81
|
-
throw new Error(`JWT secret is unspecified`);
|
|
82
|
-
}
|
|
83
|
-
if (options.argv.userId === "") {
|
|
84
|
-
throw new Error(`User id is unspecified`);
|
|
85
|
-
}
|
|
86
|
-
const containsBlank = strings => strings.some(string => string === "");
|
|
87
|
-
if (containsBlank(options.aspects)) {
|
|
88
|
-
throw new Error(`Aspects ${options.aspects} contains a blank aspect`);
|
|
89
|
-
}
|
|
90
|
-
if (containsBlank(options.optionalAspects)) {
|
|
91
|
-
throw new Error(`Aspects ${options.optionalAspects} contains a blank aspect`);
|
|
92
|
-
}
|
|
59
|
+
if (options.id === "") {
|
|
60
|
+
throw new Error(`id is unspecified`);
|
|
93
61
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const aspectDefsToAdd = options.writeAspectDefs;
|
|
97
|
-
console.info(`Adding aspect defs ${aspectDefsToAdd.map(def => def.name)}`);
|
|
98
|
-
// If magda is deployed in multi-tenant mode, any datasets from any new tenants created
|
|
99
|
-
// after this call will be not be processed. To process them, run the minion again.
|
|
100
|
-
const tenantIds = options.argv.enableMultiTenant ?
|
|
101
|
-
yield tenantClient.getTenants().then(tenants => {
|
|
102
|
-
return tenants.map(t => t.id);
|
|
103
|
-
}) :
|
|
104
|
-
[];
|
|
105
|
-
// We always create aspect definition for tenant with ID of MAGDA_ADMIN_PORTAL_ID
|
|
106
|
-
// because a minion does not know if magda is deployed in single- or multi-tenant mode.
|
|
107
|
-
// This approach will slightly increase the number of entries in the aspects table but
|
|
108
|
-
// make the implementation simple.
|
|
109
|
-
const theTenantIds = tenantIds.concat(TenantConsts_1.MAGDA_ADMIN_PORTAL_ID);
|
|
110
|
-
const addPromises = aspectDefsToAdd.map(aspectDef => {
|
|
111
|
-
theTenantIds.map(id => registry.putAspectDefinition(aspectDef, id));
|
|
112
|
-
});
|
|
113
|
-
return Promise.all(addPromises).
|
|
114
|
-
then(failIfErrors).
|
|
115
|
-
then(result => {
|
|
116
|
-
console.info("Successfully added aspect defs");
|
|
117
|
-
return result;
|
|
118
|
-
});
|
|
119
|
-
});
|
|
62
|
+
if (options.argv.internalUrl === "") {
|
|
63
|
+
throw new Error(`Internal url is unspecified`);
|
|
120
64
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (failed.length > 0) {
|
|
124
|
-
throw failed[0];
|
|
125
|
-
} else
|
|
126
|
-
{
|
|
127
|
-
return results;
|
|
128
|
-
}
|
|
65
|
+
if (options.argv.registryUrl === "") {
|
|
66
|
+
throw new Error(`Registry url is unspecified`);
|
|
129
67
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
68
|
+
if (options.argv.jwtSecret === "") {
|
|
69
|
+
throw new Error(`JWT secret is unspecified`);
|
|
70
|
+
}
|
|
71
|
+
if (options.argv.userId === "") {
|
|
72
|
+
throw new Error(`User id is unspecified`);
|
|
73
|
+
}
|
|
74
|
+
const containsBlank = (strings) => strings.some((string) => string === "");
|
|
75
|
+
if (containsBlank(options.aspects)) {
|
|
76
|
+
throw new Error(`Aspects ${options.aspects} contains a blank aspect`);
|
|
77
|
+
}
|
|
78
|
+
if (containsBlank(options.optionalAspects)) {
|
|
79
|
+
throw new Error(`Aspects ${options.optionalAspects} contains a blank aspect`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async function putAspectDefs() {
|
|
83
|
+
const aspectDefsToAdd = options.writeAspectDefs;
|
|
84
|
+
console.info(`Adding aspect defs ${aspectDefsToAdd.map((def) => def.name)}`);
|
|
85
|
+
// If magda is deployed in multi-tenant mode, any datasets from any new tenants created
|
|
86
|
+
// after this call will be not be processed. To process them, run the minion again.
|
|
87
|
+
const tenantIds = options.argv.enableMultiTenant ?
|
|
88
|
+
await tenantClient.getTenants().then((tenants) => {
|
|
89
|
+
return tenants.map((t) => t.id);
|
|
90
|
+
}) :
|
|
91
|
+
[];
|
|
92
|
+
// We always create aspect definition for tenant with ID of MAGDA_ADMIN_PORTAL_ID
|
|
93
|
+
// because a minion does not know if magda is deployed in single- or multi-tenant mode.
|
|
94
|
+
// This approach will slightly increase the number of entries in the aspects table but
|
|
95
|
+
// make the implementation simple.
|
|
96
|
+
const theTenantIds = tenantIds.concat(MAGDA_ADMIN_PORTAL_ID);
|
|
97
|
+
const addPromises = aspectDefsToAdd.map((aspectDef) => {
|
|
98
|
+
theTenantIds.map((id) => registry.putAspectDefinition(aspectDef, id));
|
|
99
|
+
});
|
|
100
|
+
return Promise.all(addPromises).
|
|
101
|
+
then(failIfErrors).
|
|
102
|
+
then((result) => {
|
|
103
|
+
console.info("Successfully added aspect defs");
|
|
104
|
+
return result;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function failIfErrors(results) {
|
|
108
|
+
const failed = results.filter((result) => result instanceof Error);
|
|
109
|
+
if (failed.length > 0) {
|
|
110
|
+
throw failed[0];
|
|
111
|
+
} else
|
|
112
|
+
{
|
|
113
|
+
return results;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,QAAQ,MAAM,kEAAkE,CAAC;AAExF,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,iBAAiB,MAAM,wBAAwB,CAAC;AACvD,OAAO,mBAAmB,MAAM,0BAA0B,CAAC;AAC3D,OAAO,eAAe,MAAM,sBAAsB,CAAC;AACnD,O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;YACtD,CAAC,CAAC,MAAM,YAAY,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC,CAAC,OAAiB,EAAE,EAAE;gBACvD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YACpC,CAAC,CAAC;YACJ,CAAC,CAAC,EAAE,CAAC;QAET,iFAAiF;QACjF,uFAAuF;QACvF,sFAAsF;QACtF,kCAAkC;QAClC,MAAM,YAAY,GAAa,SAAS,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC;QACvE,MAAM,WAAW,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE;YAClD,YAAY,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CACpB,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,EAAE,CAAC,CAC9C,CAAC;QACN,CAAC,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;aAC1B,IAAI,CAAC,YAAY,CAAC;aAClB,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YACb,OAAO,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;YAC/C,OAAO,MAAM,CAAC;QAClB,CAAC,CAAC,CAAC;IACX,CAAC;IAED,SAAS,YAAY,CAAI,OAAyB;QAC9C,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CACzB,CAAC,MAAiB,EAAE,EAAE,CAAC,MAAM,YAAY,KAAK,CACjD,CAAC;QAEF,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YACnB,MAAM,MAAM,CAAC,CAAC,CAAC,CAAC;SACnB;aAAM;YACH,OAAO,OAAO,CAAC;SAClB;IACL,CAAC;AACL,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import Registry from "@magda/typescript-common/dist/registry/AuthorizedRegistryClient";
|
|
2
|
-
import MinionOptions from "./MinionOptions";
|
|
1
|
+
import Registry from "@magda/typescript-common/dist/registry/AuthorizedRegistryClient.js";
|
|
2
|
+
import MinionOptions from "./MinionOptions.js";
|
|
3
3
|
export default function isWebhookRegistered(options: MinionOptions, registry: Registry): Promise<boolean>;
|
|
@@ -1,31 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const lodash_1 = require("lodash");
|
|
16
|
-
const buildWebhookConfig_1 = __importDefault(require("./buildWebhookConfig"));
|
|
17
|
-
const getWebhookUrl_1 = __importDefault(require("./getWebhookUrl"));
|
|
18
|
-
function isWebhookRegistered(options, registry) {
|
|
19
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
const maybeHook = yield registry.getHook(options.id);
|
|
21
|
-
if (maybeHook instanceof Error) {
|
|
22
|
-
throw maybeHook;
|
|
23
|
-
}
|
|
24
|
-
const newWebhookConfig = buildWebhookConfig_1.default(options);
|
|
25
|
-
return maybeHook.
|
|
26
|
-
map(hook => lodash_1.isEqual(hook.config, newWebhookConfig) &&
|
|
27
|
-
hook.url === getWebhookUrl_1.default(options)).
|
|
28
|
-
valueOr(false);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
exports.default = isWebhookRegistered;
|
|
1
|
+
import isEqual from "lodash/isEqual.js";
|
|
2
|
+
import buildWebhookConfig from "./buildWebhookConfig.js";
|
|
3
|
+
import getWebhookUrl from "./getWebhookUrl.js";
|
|
4
|
+
export default async function isWebhookRegistered(options, registry) {
|
|
5
|
+
const maybeHook = await registry.getHook(options.id);
|
|
6
|
+
if (maybeHook instanceof Error) {
|
|
7
|
+
throw maybeHook;
|
|
8
|
+
}
|
|
9
|
+
const newWebhookConfig = buildWebhookConfig(options);
|
|
10
|
+
return maybeHook.
|
|
11
|
+
map((hook) => isEqual(hook.config, newWebhookConfig) &&
|
|
12
|
+
hook.url === getWebhookUrl(options)).
|
|
13
|
+
valueOr(false);
|
|
14
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isWebhookRegistered.js","sourceRoot":"","sources":["../src/isWebhookRegistered.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"isWebhookRegistered.js","sourceRoot":"","sources":["../src/isWebhookRegistered.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,mBAAmB,CAAC;AAKxC,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AACzD,OAAO,aAAa,MAAM,oBAAoB,CAAC;AAE/C,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,mBAAmB,CAC7C,OAAsB,EACtB,QAAkB;IAElB,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAErD,IAAI,SAAS,YAAY,KAAK,EAAE;QAC5B,MAAM,SAAS,CAAC;KACnB;IAED,MAAM,gBAAgB,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAErD,OAAO,SAAS;SACX,GAAG,CACA,CAAC,IAAI,EAAE,EAAE,CACL,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,gBAAgB,CAAC;QACtC,IAAI,CAAC,GAAG,KAAK,aAAa,CAAC,OAAO,CAAC,CAC1C;SACA,OAAO,CAAC,KAAK,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { WebHook } from "@magda/typescript-common/dist/generated/registry/api";
|
|
2
|
-
import Registry from "@magda/typescript-common/dist/registry/AuthorizedRegistryClient";
|
|
3
|
-
import MinionOptions from "./MinionOptions";
|
|
4
|
-
export
|
|
5
|
-
export default function registerNewWebhook(options: MinionOptions, registry: Registry): Promise<WebHook | import("
|
|
1
|
+
import { WebHook } from "@magda/typescript-common/dist/generated/registry/api.js";
|
|
2
|
+
import Registry from "@magda/typescript-common/dist/registry/AuthorizedRegistryClient.js";
|
|
3
|
+
import MinionOptions from "./MinionOptions.js";
|
|
4
|
+
export type NeedsCrawl = Promise<boolean>;
|
|
5
|
+
export default function registerNewWebhook(options: MinionOptions, registry: Registry): Promise<WebHook | import("magda-typescript-common/src/ServerError.js").default>;
|
package/dist/registerWebhook.js
CHANGED
|
@@ -1,51 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
console.info("Registering webhook");
|
|
20
|
-
const webHookConfig = buildWebhookConfig_1.default(options);
|
|
21
|
-
const newWebHook = {
|
|
22
|
-
id: options.id,
|
|
23
|
-
name: options.id,
|
|
24
|
-
active: true,
|
|
25
|
-
url: getWebhookUrl_1.default(options),
|
|
26
|
-
eventTypes: [
|
|
27
|
-
"CreateRecord",
|
|
28
|
-
"CreateAspectDefinition",
|
|
29
|
-
"CreateRecordAspect",
|
|
30
|
-
"PatchRecord",
|
|
31
|
-
"PatchAspectDefinition",
|
|
32
|
-
"PatchRecordAspect"],
|
|
1
|
+
import getWebhookUrl from "./getWebhookUrl.js";
|
|
2
|
+
import buildWebhookConfig from "./buildWebhookConfig.js";
|
|
3
|
+
export default async function registerNewWebhook(options, registry) {
|
|
4
|
+
console.info("Registering webhook");
|
|
5
|
+
const webHookConfig = buildWebhookConfig(options);
|
|
6
|
+
const newWebHook = {
|
|
7
|
+
id: options.id,
|
|
8
|
+
name: options.id,
|
|
9
|
+
active: true,
|
|
10
|
+
url: getWebhookUrl(options),
|
|
11
|
+
eventTypes: [
|
|
12
|
+
"CreateRecord",
|
|
13
|
+
"CreateAspectDefinition",
|
|
14
|
+
"CreateRecordAspect",
|
|
15
|
+
"PatchRecord",
|
|
16
|
+
"PatchAspectDefinition",
|
|
17
|
+
"PatchRecordAspect"],
|
|
33
18
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
exports.default = registerNewWebhook;
|
|
19
|
+
config: webHookConfig,
|
|
20
|
+
lastEvent: null,
|
|
21
|
+
isWaitingForResponse: false,
|
|
22
|
+
enabled: true,
|
|
23
|
+
lastRetryTime: null,
|
|
24
|
+
retryCount: 0,
|
|
25
|
+
isRunning: null,
|
|
26
|
+
isProcessing: null,
|
|
27
|
+
ownerId: undefined,
|
|
28
|
+
createTime: undefined,
|
|
29
|
+
creatorId: undefined,
|
|
30
|
+
editTime: undefined,
|
|
31
|
+
editorId: undefined
|
|
32
|
+
};
|
|
33
|
+
return registry.putHook(newWebHook);
|
|
34
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerWebhook.js","sourceRoot":"","sources":["../src/registerWebhook.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"registerWebhook.js","sourceRoot":"","sources":["../src/registerWebhook.ts"],"names":[],"mappings":"AAIA,OAAO,aAAa,MAAM,oBAAoB,CAAC;AAC/C,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AAIzD,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,kBAAkB,CAC5C,OAAsB,EACtB,QAAkB;IAElB,OAAO,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;IAEpC,MAAM,aAAa,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAElD,MAAM,UAAU,GAAY;QACxB,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,IAAI,EAAE,OAAO,CAAC,EAAE;QAChB,MAAM,EAAE,IAAI;QACZ,GAAG,EAAE,aAAa,CAAC,OAAO,CAAC;QAC3B,UAAU,EAAE;YACR,cAAc;YACd,wBAAwB;YACxB,oBAAoB;YACpB,aAAa;YACb,uBAAuB;YACvB,mBAAmB;SACtB;QACD,MAAM,EAAE,aAAa;QACrB,SAAS,EAAE,IAAI;QACf,oBAAoB,EAAE,KAAK;QAC3B,OAAO,EAAE,IAAI;QACb,aAAa,EAAE,IAAI;QACnB,UAAU,EAAE,CAAC;QACb,SAAS,EAAE,IAAI;QACf,YAAY,EAAE,IAAI;QAClB,OAAO,EAAE,SAAS;QAClB,UAAU,EAAE,SAAS;QACrB,SAAS,EAAE,SAAS;QACpB,QAAQ,EAAE,SAAS;QACnB,QAAQ,EAAE,SAAS;KACtB,CAAC;IAEF,OAAO,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AACxC,CAAC"}
|
package/dist/resumeWebhook.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Registry from "@magda/typescript-common/dist/registry/AuthorizedRegistryClient";
|
|
2
|
-
import MinionOptions from "./MinionOptions";
|
|
3
|
-
export
|
|
1
|
+
import Registry from "@magda/typescript-common/dist/registry/AuthorizedRegistryClient.js";
|
|
2
|
+
import MinionOptions from "./MinionOptions.js";
|
|
3
|
+
export type NeedsCrawl = Promise<boolean>;
|
|
4
4
|
export default function resumeWebhook(options: MinionOptions, registry: Registry): Promise<void>;
|
package/dist/resumeWebhook.js
CHANGED
|
@@ -1,22 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
function resumeWebhook(options, registry) {
|
|
13
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
-
console.info(`Attempting to resume webhook ${options.id}`);
|
|
15
|
-
const resumeResult = yield registry.resumeHook(options.id, false, null, true);
|
|
16
|
-
if (resumeResult instanceof Error) {
|
|
17
|
-
throw resumeResult;
|
|
18
|
-
}
|
|
19
|
-
console.info(`Successfully resumed webhook - last event id was ${resumeResult.lastEventIdReceived}`);
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
exports.default = resumeWebhook;
|
|
1
|
+
export default async function resumeWebhook(options, registry) {
|
|
2
|
+
console.info(`Attempting to resume webhook ${options.id}`);
|
|
3
|
+
const resumeResult = await registry.resumeHook(options.id, false, null, true);
|
|
4
|
+
if (resumeResult instanceof Error) {
|
|
5
|
+
throw resumeResult;
|
|
6
|
+
}
|
|
7
|
+
console.info(`Successfully resumed webhook - last event id was ${resumeResult.lastEventIdReceived}`);
|
|
8
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resumeWebhook.js","sourceRoot":"","sources":["../src/resumeWebhook.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resumeWebhook.js","sourceRoot":"","sources":["../src/resumeWebhook.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,aAAa,CACvC,OAAsB,EACtB,QAAkB;IAElB,OAAO,CAAC,IAAI,CAAC,gCAAgC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;IAE3D,MAAM,YAAY,GAAG,MAAM,QAAQ,CAAC,UAAU,CAC1C,OAAO,CAAC,EAAE,EACV,KAAK,EACL,IAAI,EACJ,IAAI,CACP,CAAC;IAEF,IAAI,YAAY,YAAY,KAAK,EAAE;QAC/B,MAAM,YAAY,CAAC;KACtB;IAED,OAAO,CAAC,IAAI,CACR,oDAAoD,YAAY,CAAC,mBAAmB,EAAE,CACzF,CAAC;AACN,CAAC"}
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import MinionOptions from "./MinionOptions";
|
|
1
|
+
import MinionOptions from "./MinionOptions.js";
|
|
2
2
|
import { Application } from "express";
|
|
3
|
-
import Crawler from "./Crawler";
|
|
3
|
+
import Crawler from "./Crawler.js";
|
|
4
4
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
* @apiDefine GenericErrorMinionJson
|
|
6
|
+
* @apiError (Error 500 JSON Response Body) {Boolean} isSuccess Whether or not the operation is successfully done.
|
|
7
|
+
* @apiError (Error 500 JSON Response Body) {Boolean} [isNewCrawler] indicate Whether it's a new cralwer process or existing crawling process is still no-going.
|
|
8
|
+
* @apiError (Error 500 JSON Response Body) {String} errorMessage Free text error message. Only available when `isSuccess`=`false`
|
|
9
|
+
* @apiErrorExample {json} Response:
|
|
10
|
+
* {
|
|
11
|
+
* isSuccess: false,
|
|
12
|
+
* errorMessage: "Unknown Error"
|
|
13
|
+
* }
|
|
14
|
+
*/
|
|
15
15
|
export interface recrawlResponse {
|
|
16
16
|
isSuccess: boolean;
|
|
17
17
|
isNewCrawler?: boolean;
|
|
18
|
-
errorMessage?: string;
|
|
19
|
-
|
|
18
|
+
errorMessage?: string;
|
|
19
|
+
}
|
|
20
20
|
export interface crawlerProgress {
|
|
21
21
|
isSuccess: boolean;
|
|
22
22
|
errorMessage?: string;
|
|
23
23
|
progress?: {
|
|
24
24
|
isCrawling: boolean;
|
|
25
25
|
crawlingPageToken: string;
|
|
26
|
-
crawledRecordNumber: number;
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
crawledRecordNumber: number;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
29
|
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
30
|
+
* @apiGroup Minions
|
|
31
|
+
* @api {post} /v0/minions/recrawl Make the minion recrawl the registry
|
|
32
|
+
*
|
|
33
|
+
* @apiDescription Make the minion recrawl the registry
|
|
34
|
+
*
|
|
35
|
+
* @apiSuccess (Success 200) {json} Response the minion recrawl status
|
|
36
|
+
* @apiSuccessExample {json} Response:
|
|
37
|
+
* {
|
|
38
|
+
* isSuccess: true,
|
|
39
|
+
* isNewCrawler: true
|
|
40
|
+
* }
|
|
41
|
+
* @apiUse GenericErrorMinionJson
|
|
42
|
+
*/
|
|
43
43
|
export default function setupRecrawlEndpoint(server: Application, options: MinionOptions, crawler: Crawler): void;
|