@beseif-solutions/prow-core 0.0.32 → 0.0.34
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/entities/events.d.ts +8 -1
- package/dist/entities/events.js +8 -1
- package/dist/entities/provider.d.ts +1 -2
- package/dist/entities/provider.js +2 -2
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -3
- package/dist/minified-utils/protocol.d.ts +1 -1
- package/dist/minified-utils/protocol.js +18 -15
- package/package.json +1 -1
- package/src/entities/events.ts +16 -2
- package/src/entities/provider.ts +3 -4
- package/src/index.ts +0 -1
- package/src/minified-utils/protocol.ts +22 -17
- package/dist/entities/category.d.ts +0 -1
- package/dist/entities/category.js +0 -20
- package/src/entities/category.ts +0 -9
|
@@ -29,7 +29,14 @@ type EventConfig = Pick<CoreConfig, `credentials` | `outputs`> & {
|
|
|
29
29
|
};
|
|
30
30
|
type CommonEvents<Config extends EventConfig = {}> = Common<Config> & {
|
|
31
31
|
model: `event`;
|
|
32
|
-
|
|
32
|
+
categorization: {
|
|
33
|
+
department: string;
|
|
34
|
+
category: string;
|
|
35
|
+
};
|
|
36
|
+
ui: {
|
|
37
|
+
group: string;
|
|
38
|
+
icon?: string;
|
|
39
|
+
};
|
|
33
40
|
credentials: string[];
|
|
34
41
|
sandbox: boolean;
|
|
35
42
|
fields: Field[];
|
package/dist/entities/events.js
CHANGED
|
@@ -22,7 +22,14 @@ const additionalConnectableEventSchema = () => joi_1.default.object({})
|
|
|
22
22
|
.concat(commonConnectableEventSchema());
|
|
23
23
|
const commonEventsSchema = () => joi_1.default.object({
|
|
24
24
|
model: joi_1.default.valid(`event`).required(),
|
|
25
|
-
|
|
25
|
+
categorization: joi_1.default.object({
|
|
26
|
+
department: joi_1.default.string().required(),
|
|
27
|
+
category: joi_1.default.string().required(),
|
|
28
|
+
}).required(),
|
|
29
|
+
ui: joi_1.default.object({
|
|
30
|
+
group: joi_1.default.string().required(),
|
|
31
|
+
icon: joi_1.default.string(),
|
|
32
|
+
}).required(),
|
|
26
33
|
credentials: joi_1.default.array().items((0, commons_1.idSchema)().optional()).required().min(0),
|
|
27
34
|
sandbox: joi_1.default.bool().required(),
|
|
28
35
|
fields: (0, fields_1.fieldsSchema)().required(),
|
|
@@ -5,10 +5,9 @@ import { Source } from "./source";
|
|
|
5
5
|
export type Provider = {
|
|
6
6
|
id: string;
|
|
7
7
|
model: `provider`;
|
|
8
|
-
categories: string[];
|
|
9
8
|
credentials: Record<string, Credentials>;
|
|
10
9
|
triggers: Record<string, Trigger>;
|
|
11
10
|
actions: Record<string, Action>;
|
|
12
|
-
sources
|
|
11
|
+
sources: Record<string, Source>;
|
|
13
12
|
};
|
|
14
13
|
export declare const providerSchema: () => Joi.ObjectSchema<any>;
|
|
@@ -12,7 +12,6 @@ const source_1 = require("./source");
|
|
|
12
12
|
const providerSchema = () => joi_1.default.object({
|
|
13
13
|
id: (0, commons_1.idSchema)(),
|
|
14
14
|
model: joi_1.default.valid(`provider`).required(),
|
|
15
|
-
categories: joi_1.default.array().items(joi_1.default.string()).min(1).required(),
|
|
16
15
|
credentials: joi_1.default.object()
|
|
17
16
|
.pattern((0, commons_1.idSchema)(), (0, credentials_1.credentialsSchema)())
|
|
18
17
|
.required(),
|
|
@@ -23,6 +22,7 @@ const providerSchema = () => joi_1.default.object({
|
|
|
23
22
|
.pattern((0, commons_1.idSchema)(), (0, events_1.actionSchema)())
|
|
24
23
|
.required(),
|
|
25
24
|
sources: joi_1.default.object()
|
|
26
|
-
.pattern((0, commons_1.idSchema)(), (0, source_1.sourceSchema)())
|
|
25
|
+
.pattern((0, commons_1.idSchema)(), (0, source_1.sourceSchema)())
|
|
26
|
+
.required(),
|
|
27
27
|
});
|
|
28
28
|
exports.providerSchema = providerSchema;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { Core, core } from './core';
|
|
2
|
-
export { getCategories } from './entities/category';
|
|
3
2
|
export { CoreFunction, idSchema } from './entities/commons';
|
|
4
3
|
export { Credentials, credentialsSchema, OAuthCredentials, oauthCredentialsSchema, SessionCredentials, sessionCredentialsSchema, StaticCredentials, staticCredentialsSchema } from './entities/credentials';
|
|
5
4
|
export { Action, actionOutputSchema, actionSchema, Event, eventSchema, ImmediateTrigger, immediateTriggerSchema, Request, ScheduledTrigger, scheduledTriggerSchema, Trigger, triggerOutputSchema, triggerSchema } from './entities/events';
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Protocol = exports.Properties = exports.localizeProperties = exports.localizeOutputs = exports.localizeInputs = exports.localizeFields = exports.i18n = exports.validate = exports.fieldsSchema = exports.fieldSchema = exports.extract = exports.providerSchema = exports.triggerSchema = exports.triggerOutputSchema = exports.scheduledTriggerSchema = exports.immediateTriggerSchema = exports.eventSchema = exports.actionSchema = exports.actionOutputSchema = exports.staticCredentialsSchema = exports.sessionCredentialsSchema = exports.oauthCredentialsSchema = exports.credentialsSchema = exports.idSchema = exports.
|
|
3
|
+
exports.Protocol = exports.Properties = exports.localizeProperties = exports.localizeOutputs = exports.localizeInputs = exports.localizeFields = exports.i18n = exports.validate = exports.fieldsSchema = exports.fieldSchema = exports.extract = exports.providerSchema = exports.triggerSchema = exports.triggerOutputSchema = exports.scheduledTriggerSchema = exports.immediateTriggerSchema = exports.eventSchema = exports.actionSchema = exports.actionOutputSchema = exports.staticCredentialsSchema = exports.sessionCredentialsSchema = exports.oauthCredentialsSchema = exports.credentialsSchema = exports.idSchema = exports.core = void 0;
|
|
4
4
|
var core_1 = require("./core");
|
|
5
5
|
Object.defineProperty(exports, "core", { enumerable: true, get: function () { return core_1.core; } });
|
|
6
|
-
var category_1 = require("./entities/category");
|
|
7
|
-
Object.defineProperty(exports, "getCategories", { enumerable: true, get: function () { return category_1.getCategories; } });
|
|
8
6
|
var commons_1 = require("./entities/commons");
|
|
9
7
|
Object.defineProperty(exports, "idSchema", { enumerable: true, get: function () { return commons_1.idSchema; } });
|
|
10
8
|
var credentials_1 = require("./entities/credentials");
|
|
@@ -6,7 +6,7 @@ export declare class Protocol {
|
|
|
6
6
|
evaluate: (req: Protocol.Command) => Promise<any>;
|
|
7
7
|
}
|
|
8
8
|
export declare namespace Protocol {
|
|
9
|
-
type Model = `action` | `trigger` | `
|
|
9
|
+
type Model = `action` | `trigger` | `credential`;
|
|
10
10
|
type Invoke = {
|
|
11
11
|
command: `invoke`;
|
|
12
12
|
model: Protocol.Model;
|
|
@@ -4,14 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Protocol = void 0;
|
|
7
|
+
const joi_1 = __importDefault(require("joi"));
|
|
7
8
|
const lodash_1 = __importDefault(require("lodash"));
|
|
9
|
+
const core_1 = require("../core");
|
|
8
10
|
const provider_1 = require("../entities/provider");
|
|
9
11
|
const locales_1 = require("./locales");
|
|
10
|
-
const core_1 = require("../core");
|
|
11
|
-
const joi_1 = __importDefault(require("joi"));
|
|
12
12
|
const invokeSchema = joi_1.default.object({
|
|
13
13
|
command: joi_1.default.string().valid(`invoke`).required(),
|
|
14
|
-
model: joi_1.default.string().valid(`action`, `trigger`, `
|
|
14
|
+
model: joi_1.default.string().valid(`action`, `trigger`, `credential`).required(),
|
|
15
15
|
id: joi_1.default.string().required(),
|
|
16
16
|
params: joi_1.default.object({
|
|
17
17
|
function: joi_1.default.string().required(),
|
|
@@ -49,16 +49,21 @@ class Protocol {
|
|
|
49
49
|
if (validation.error) {
|
|
50
50
|
throw new Error(`Invalid request: ${validation.error.message}`);
|
|
51
51
|
}
|
|
52
|
+
const serialize = (elem) => ({
|
|
53
|
+
...lodash_1.default.omit(elem, [`functions`, `helpers`]),
|
|
54
|
+
functions: Object.keys(elem.functions),
|
|
55
|
+
helpers: Object.keys(elem.helpers),
|
|
56
|
+
});
|
|
52
57
|
let response;
|
|
53
58
|
switch (req.command) {
|
|
54
59
|
case `list:actions`:
|
|
55
|
-
response = Object.values(this.provider.actions || {});
|
|
60
|
+
response = Object.values(this.provider.actions || {}).map(serialize);
|
|
56
61
|
break;
|
|
57
62
|
case `list:triggers`:
|
|
58
|
-
response = Object.values(this.provider.triggers || {});
|
|
63
|
+
response = Object.values(this.provider.triggers || {}).map(serialize);
|
|
59
64
|
break;
|
|
60
65
|
case `list:credentials`:
|
|
61
|
-
response = Object.values(this.provider.credentials || {});
|
|
66
|
+
response = Object.values(this.provider.credentials || {}).map(serialize);
|
|
62
67
|
break;
|
|
63
68
|
case `list:sources`:
|
|
64
69
|
response = Object.values(this.provider.sources || {});
|
|
@@ -74,22 +79,20 @@ class Protocol {
|
|
|
74
79
|
});
|
|
75
80
|
break;
|
|
76
81
|
case `invoke`:
|
|
77
|
-
const
|
|
78
|
-
if (!
|
|
79
|
-
|
|
80
|
-
status: 404,
|
|
81
|
-
body: JSON.stringify({ error: `Could not find ${req.model} with ID ${req.id}` }),
|
|
82
|
-
};
|
|
82
|
+
const elem = lodash_1.default.get(this.provider, `${req.model}s.${req.id}`);
|
|
83
|
+
if (!elem) {
|
|
84
|
+
throw new Error(`Could not find ${req.model} with ID ${req.id}`);
|
|
83
85
|
}
|
|
84
|
-
const
|
|
85
|
-
if (!
|
|
86
|
+
const func = lodash_1.default.get(elem, req.params.function);
|
|
87
|
+
if (!func || typeof func !== `function`) {
|
|
86
88
|
throw new Error(`Invalid function ${req.params.function}`);
|
|
87
89
|
}
|
|
88
90
|
const invokeInstance = (0, core_1.core)({
|
|
89
91
|
env: req.context.environment,
|
|
90
92
|
localization: req.context.localization,
|
|
93
|
+
sources: null,
|
|
91
94
|
});
|
|
92
|
-
response = await
|
|
95
|
+
response = await func(invokeInstance, req.params.configuration);
|
|
93
96
|
break;
|
|
94
97
|
default:
|
|
95
98
|
throw new Error(`Invalid command`);
|
package/package.json
CHANGED
package/src/entities/events.ts
CHANGED
|
@@ -37,7 +37,14 @@ type EventConfig = Pick<CoreConfig, `credentials` | `outputs`> & {
|
|
|
37
37
|
|
|
38
38
|
type CommonEvents<Config extends EventConfig = {}> = Common<Config> & {
|
|
39
39
|
model: `event`,
|
|
40
|
-
|
|
40
|
+
categorization: {
|
|
41
|
+
department: string,
|
|
42
|
+
category: string,
|
|
43
|
+
},
|
|
44
|
+
ui: {
|
|
45
|
+
group: string,
|
|
46
|
+
icon?: string,
|
|
47
|
+
},
|
|
41
48
|
credentials: string[],
|
|
42
49
|
sandbox: boolean,
|
|
43
50
|
fields: Field[],
|
|
@@ -143,7 +150,14 @@ const additionalConnectableEventSchema = () =>
|
|
|
143
150
|
const commonEventsSchema = () =>
|
|
144
151
|
Joi.object({
|
|
145
152
|
model: Joi.valid(`event`).required(),
|
|
146
|
-
|
|
153
|
+
categorization: Joi.object({
|
|
154
|
+
department: Joi.string().required(),
|
|
155
|
+
category: Joi.string().required(),
|
|
156
|
+
}).required(),
|
|
157
|
+
ui: Joi.object({
|
|
158
|
+
group: Joi.string().required(),
|
|
159
|
+
icon: Joi.string(),
|
|
160
|
+
}).required(),
|
|
147
161
|
credentials: Joi.array().items(idSchema().optional()).required().min(0),
|
|
148
162
|
sandbox: Joi.bool().required(),
|
|
149
163
|
fields: fieldsSchema().required(),
|
package/src/entities/provider.ts
CHANGED
|
@@ -7,18 +7,16 @@ import { Source, sourceSchema } from "./source";
|
|
|
7
7
|
export type Provider = {
|
|
8
8
|
id: string,
|
|
9
9
|
model: `provider`,
|
|
10
|
-
categories: string[],
|
|
11
10
|
credentials: Record<string, Credentials>,
|
|
12
11
|
triggers: Record<string, Trigger>,
|
|
13
12
|
actions: Record<string, Action>,
|
|
14
|
-
sources
|
|
13
|
+
sources: Record<string, Source>,
|
|
15
14
|
};
|
|
16
15
|
|
|
17
16
|
export const providerSchema = () =>
|
|
18
17
|
Joi.object({
|
|
19
18
|
id: idSchema(),
|
|
20
19
|
model: Joi.valid(`provider`).required(),
|
|
21
|
-
categories: Joi.array().items(Joi.string()).min(1).required(),
|
|
22
20
|
credentials: Joi.object()
|
|
23
21
|
.pattern(idSchema(), credentialsSchema())
|
|
24
22
|
.required(),
|
|
@@ -29,5 +27,6 @@ export const providerSchema = () =>
|
|
|
29
27
|
.pattern(idSchema(), actionSchema())
|
|
30
28
|
.required(),
|
|
31
29
|
sources: Joi.object()
|
|
32
|
-
.pattern(idSchema(), sourceSchema())
|
|
30
|
+
.pattern(idSchema(), sourceSchema())
|
|
31
|
+
.required(),
|
|
33
32
|
});
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { Core, core } from './core';
|
|
2
|
-
export { getCategories } from './entities/category';
|
|
3
2
|
export { CoreFunction, idSchema } from './entities/commons';
|
|
4
3
|
export { Credentials, credentialsSchema, OAuthCredentials, oauthCredentialsSchema, SessionCredentials, sessionCredentialsSchema, StaticCredentials, staticCredentialsSchema } from './entities/credentials';
|
|
5
4
|
export { Action, actionOutputSchema, actionSchema, Event, eventSchema, ImmediateTrigger, immediateTriggerSchema, Request, ScheduledTrigger, scheduledTriggerSchema, Trigger, triggerOutputSchema, triggerSchema } from './entities/events';
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import Joi from "joi";
|
|
1
2
|
import _ from "lodash";
|
|
3
|
+
import { core } from "../core";
|
|
4
|
+
import { Credentials } from "../entities/credentials";
|
|
5
|
+
import { Action, Trigger } from "../entities/events";
|
|
2
6
|
import { Provider, providerSchema } from "../entities/provider";
|
|
3
7
|
import { i18n } from "./locales";
|
|
4
|
-
import { core } from "../core";
|
|
5
|
-
import Joi from "joi";
|
|
6
8
|
|
|
7
9
|
const invokeSchema = Joi.object({
|
|
8
10
|
command: Joi.string().valid(`invoke`).required(),
|
|
9
|
-
model: Joi.string().valid(`action`, `trigger`, `
|
|
11
|
+
model: Joi.string().valid(`action`, `trigger`, `credential`).required(),
|
|
10
12
|
id: Joi.string().required(),
|
|
11
13
|
params: Joi.object({
|
|
12
14
|
function: Joi.string().required(),
|
|
@@ -67,16 +69,22 @@ export class Protocol {
|
|
|
67
69
|
const validation = commandSchema.validate(req);
|
|
68
70
|
if (validation.error) { throw new Error(`Invalid request: ${validation.error.message}`); }
|
|
69
71
|
|
|
72
|
+
const serialize = (elem: Action | Trigger | Credentials) => ({
|
|
73
|
+
..._.omit(elem, [`functions`, `helpers`]),
|
|
74
|
+
functions: Object.keys(elem.functions),
|
|
75
|
+
helpers: Object.keys(elem.helpers),
|
|
76
|
+
});
|
|
77
|
+
|
|
70
78
|
let response: any;
|
|
71
79
|
switch (req.command) {
|
|
72
80
|
case `list:actions`:
|
|
73
|
-
response = Object.values(this.provider.actions || {});
|
|
81
|
+
response = Object.values(this.provider.actions || {}).map(serialize);
|
|
74
82
|
break;
|
|
75
83
|
case `list:triggers`:
|
|
76
|
-
response = Object.values(this.provider.triggers || {});
|
|
84
|
+
response = Object.values(this.provider.triggers || {}).map(serialize);
|
|
77
85
|
break;
|
|
78
86
|
case `list:credentials`:
|
|
79
|
-
response = Object.values(this.provider.credentials || {});
|
|
87
|
+
response = Object.values(this.provider.credentials || {}).map(serialize);
|
|
80
88
|
break;
|
|
81
89
|
case `list:sources`:
|
|
82
90
|
response = Object.values(this.provider.sources || {});
|
|
@@ -92,23 +100,20 @@ export class Protocol {
|
|
|
92
100
|
});
|
|
93
101
|
break;
|
|
94
102
|
case `invoke`:
|
|
95
|
-
const
|
|
96
|
-
if (!
|
|
97
|
-
return {
|
|
98
|
-
status: 404,
|
|
99
|
-
body: JSON.stringify({ error: `Could not find ${req.model} with ID ${req.id}` }),
|
|
100
|
-
};
|
|
101
|
-
}
|
|
103
|
+
const elem = _.get(this.provider, `${req.model}s.${req.id}`);
|
|
104
|
+
if (!elem) { throw new Error(`Could not find ${req.model} with ID ${req.id}`); }
|
|
102
105
|
|
|
103
|
-
const
|
|
104
|
-
if (!
|
|
106
|
+
const func = _.get(elem, req.params.function);
|
|
107
|
+
if (!func || typeof func !== `function`) { throw new Error(`Invalid function ${req.params.function}`); }
|
|
105
108
|
|
|
106
109
|
const invokeInstance = core({
|
|
107
110
|
env: req.context.environment,
|
|
108
111
|
localization: req.context.localization,
|
|
112
|
+
// TODO: sources
|
|
113
|
+
sources: null,
|
|
109
114
|
});
|
|
110
115
|
|
|
111
|
-
response = await
|
|
116
|
+
response = await func(invokeInstance, req.params.configuration);
|
|
112
117
|
break;
|
|
113
118
|
default:
|
|
114
119
|
throw new Error(`Invalid command`);
|
|
@@ -121,7 +126,7 @@ export class Protocol {
|
|
|
121
126
|
|
|
122
127
|
export namespace Protocol {
|
|
123
128
|
|
|
124
|
-
export type Model = `action` | `trigger` | `
|
|
129
|
+
export type Model = `action` | `trigger` | `credential`;
|
|
125
130
|
|
|
126
131
|
export type Invoke = {
|
|
127
132
|
command: `invoke`,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const getCategories: () => Promise<string[]>;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getCategories = void 0;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const getCategories = async () => {
|
|
9
|
-
try {
|
|
10
|
-
const { data } = await axios_1.default.get(`https://dev-beseif.s3.eu-west-1.amazonaws.com/prow/categories.txt`);
|
|
11
|
-
if (!data || typeof data !== `string`) {
|
|
12
|
-
throw new Error(`Could not obtain category list`);
|
|
13
|
-
}
|
|
14
|
-
return data.split(`\n`).map((d) => d.trim()).filter((d) => d);
|
|
15
|
-
}
|
|
16
|
-
catch (e) {
|
|
17
|
-
throw e;
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
exports.getCategories = getCategories;
|
package/src/entities/category.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
|
|
3
|
-
export const getCategories = async (): Promise<string[]> => {
|
|
4
|
-
try {
|
|
5
|
-
const { data } = await axios.get(`https://dev-beseif.s3.eu-west-1.amazonaws.com/prow/categories.txt`);
|
|
6
|
-
if (!data || typeof data !== `string`) { throw new Error(`Could not obtain category list`); }
|
|
7
|
-
return data.split(`\n`).map((d) => d.trim()).filter((d) => d);
|
|
8
|
-
} catch (e) { throw e; }
|
|
9
|
-
};
|