@beseif-solutions/prow-core 0.0.16
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/core.d.ts +21 -0
- package/dist/core.js +46 -0
- package/dist/entities/category.d.ts +1 -0
- package/dist/entities/category.js +20 -0
- package/dist/entities/commons.d.ts +26 -0
- package/dist/entities/commons.js +15 -0
- package/dist/entities/credentials.d.ts +85 -0
- package/dist/entities/credentials.js +48 -0
- package/dist/entities/events.d.ts +131 -0
- package/dist/entities/events.js +82 -0
- package/dist/entities/provider.d.ts +12 -0
- package/dist/entities/provider.js +25 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +33 -0
- package/dist/minified-utils/context.d.ts +6 -0
- package/dist/minified-utils/context.js +55 -0
- package/dist/minified-utils/env.d.ts +13 -0
- package/dist/minified-utils/env.js +96 -0
- package/dist/minified-utils/fields.d.ts +128 -0
- package/dist/minified-utils/fields.js +458 -0
- package/dist/minified-utils/locales.d.ts +27 -0
- package/dist/minified-utils/locales.js +88 -0
- package/dist/minified-utils/proxy.d.ts +9 -0
- package/dist/minified-utils/proxy.js +55 -0
- package/dist/minified-utils/types.d.ts +11 -0
- package/dist/minified-utils/types.js +2 -0
- package/dist/minified-utils/utils.d.ts +1 -0
- package/dist/minified-utils/utils.js +26 -0
- package/dist/minified-utils/where.d.ts +40 -0
- package/dist/minified-utils/where.js +265 -0
- package/package.json +44 -0
- package/src/core.ts +56 -0
- package/src/entities/category.ts +9 -0
- package/src/entities/commons.ts +40 -0
- package/src/entities/credentials.ts +131 -0
- package/src/entities/events.ts +198 -0
- package/src/entities/provider.ts +29 -0
- package/src/index.ts +8 -0
- package/src/minified-utils/context.ts +56 -0
- package/src/minified-utils/env.ts +90 -0
- package/src/minified-utils/fields.ts +628 -0
- package/src/minified-utils/locales.ts +124 -0
- package/src/minified-utils/proxy.ts +44 -0
- package/src/minified-utils/types.ts +18 -0
- package/src/minified-utils/utils.ts +18 -0
- package/src/minified-utils/where.ts +330 -0
- package/tsconfig.json +21 -0
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import _ from "lodash";
|
|
3
|
+
import moment from "moment-timezone";
|
|
4
|
+
import { Env } from "./minified-utils/env";
|
|
5
|
+
import { i18n } from "./minified-utils/locales";
|
|
6
|
+
import Joi from "joi";
|
|
7
|
+
export type Core = {
|
|
8
|
+
axios: typeof axios;
|
|
9
|
+
moment: typeof moment;
|
|
10
|
+
lodash: typeof _;
|
|
11
|
+
env: Env;
|
|
12
|
+
t: ReturnType<typeof i18n>[`t`];
|
|
13
|
+
joi: typeof Joi;
|
|
14
|
+
};
|
|
15
|
+
type CoreOptions = {
|
|
16
|
+
path: string;
|
|
17
|
+
debug?: boolean;
|
|
18
|
+
locale?: string;
|
|
19
|
+
};
|
|
20
|
+
export declare const core: (options: CoreOptions) => Core;
|
|
21
|
+
export {};
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
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.core = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
9
|
+
const moment_timezone_1 = __importDefault(require("moment-timezone"));
|
|
10
|
+
const proxy_1 = require("./minified-utils/proxy");
|
|
11
|
+
const env_1 = require("./minified-utils/env");
|
|
12
|
+
const locales_1 = require("./minified-utils/locales");
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
const joi_1 = __importDefault(require("joi"));
|
|
15
|
+
const axiosLogs = (method, debug = false) => ({
|
|
16
|
+
before: (name, [url]) => {
|
|
17
|
+
if (debug) {
|
|
18
|
+
console.log(`> [${method}]`, url);
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
after: (name, response) => {
|
|
22
|
+
if (debug) {
|
|
23
|
+
console.log(`< [${method}]`, response.config.url, response.status);
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
error: (name, error) => {
|
|
27
|
+
if (debug) {
|
|
28
|
+
console.log(`< [${method}]`, error.config.url, error.status);
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
const core = (options) => ({
|
|
33
|
+
axios: (0, proxy_1.accessProxy)(axios_1.default, {
|
|
34
|
+
get: (0, proxy_1.logProxy)(`axios.get`, axios_1.default.get, axiosLogs(`GET`, options.debug)),
|
|
35
|
+
post: (0, proxy_1.logProxy)(`axios.post`, axios_1.default.post, axiosLogs(`POST`, options.debug)),
|
|
36
|
+
put: (0, proxy_1.logProxy)(`axios.put`, axios_1.default.put, axiosLogs(`PUT`, options.debug)),
|
|
37
|
+
patch: (0, proxy_1.logProxy)(`axios.patch`, axios_1.default.patch, axiosLogs(`PATCH`, options.debug)),
|
|
38
|
+
delete: (0, proxy_1.logProxy)(`axios.delete`, axios_1.default.delete, axiosLogs(`DELETE`, options.debug)),
|
|
39
|
+
}),
|
|
40
|
+
moment: moment_timezone_1.default,
|
|
41
|
+
lodash: lodash_1.default,
|
|
42
|
+
env: new env_1.Env(options.path),
|
|
43
|
+
t: (0, locales_1.i18n)(path_1.default.join(options.path, `/locales`), { locale: options.locale }).t,
|
|
44
|
+
joi: joi_1.default,
|
|
45
|
+
});
|
|
46
|
+
exports.core = core;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getCategories: () => Promise<string[]>;
|
|
@@ -0,0 +1,20 @@
|
|
|
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());
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
throw e;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
exports.getCategories = getCategories;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import Joi from "joi";
|
|
2
|
+
import { Core } from "../core";
|
|
3
|
+
export type CoreConfig = {
|
|
4
|
+
inputs?: Record<string, any>;
|
|
5
|
+
credentials?: Record<string, any>;
|
|
6
|
+
outputs?: Record<string, any>;
|
|
7
|
+
};
|
|
8
|
+
export type CoreFunction<Config extends CoreConfig = {}> = (core: Core, configuration: ({
|
|
9
|
+
sandbox: boolean;
|
|
10
|
+
} & (Config[`inputs`] extends undefined ? {} : {
|
|
11
|
+
inputs: Config[`inputs`];
|
|
12
|
+
}) & (Config[`credentials`] extends undefined ? {} : {
|
|
13
|
+
credentials: Config[`credentials`];
|
|
14
|
+
}))) => Promise<Config[`outputs`]>;
|
|
15
|
+
type CommonConfig = Pick<CoreConfig, `credentials`>;
|
|
16
|
+
export type Common<Config extends CommonConfig = {}> = {
|
|
17
|
+
id: string;
|
|
18
|
+
helpers?: Record<string, CoreFunction<{
|
|
19
|
+
credentials: Config[`credentials`];
|
|
20
|
+
inputs: any;
|
|
21
|
+
outputs: any;
|
|
22
|
+
}>>;
|
|
23
|
+
};
|
|
24
|
+
export declare const idSchema: () => Joi.StringSchema<string>;
|
|
25
|
+
export declare const commonSchema: () => Joi.ObjectSchema<any>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
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.commonSchema = exports.idSchema = void 0;
|
|
7
|
+
const joi_1 = __importDefault(require("joi"));
|
|
8
|
+
const idSchema = () => joi_1.default.string().required().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/);
|
|
9
|
+
exports.idSchema = idSchema;
|
|
10
|
+
const commonSchema = () => joi_1.default.object({
|
|
11
|
+
id: (0, exports.idSchema)(),
|
|
12
|
+
helpers: joi_1.default.object()
|
|
13
|
+
.pattern(joi_1.default.string(), joi_1.default.function()),
|
|
14
|
+
});
|
|
15
|
+
exports.commonSchema = commonSchema;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import Joi from "joi";
|
|
2
|
+
import { Field } from "../minified-utils/fields";
|
|
3
|
+
import { Common, CoreConfig, CoreFunction } from "./commons";
|
|
4
|
+
type CredentialsConfig = Pick<CoreConfig, `credentials`>;
|
|
5
|
+
type CommonCredentials<Config extends CredentialsConfig = {}> = Common<Config> & {
|
|
6
|
+
model: `credentials`;
|
|
7
|
+
sandbox: boolean;
|
|
8
|
+
functions: {
|
|
9
|
+
check: CoreFunction<{
|
|
10
|
+
credentials: Config[`credentials`];
|
|
11
|
+
inputs: undefined;
|
|
12
|
+
outputs: {
|
|
13
|
+
valid: boolean;
|
|
14
|
+
};
|
|
15
|
+
}>;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export type OAuthCredentials<Config extends CredentialsConfig = {}> = CommonCredentials<Config> & {
|
|
19
|
+
type: `oauth`;
|
|
20
|
+
functions: {
|
|
21
|
+
oauth: CoreFunction<{
|
|
22
|
+
credentials: undefined;
|
|
23
|
+
inputs: {
|
|
24
|
+
redirect: string;
|
|
25
|
+
};
|
|
26
|
+
outputs: {
|
|
27
|
+
action: string;
|
|
28
|
+
method: string;
|
|
29
|
+
body: Record<string, any>;
|
|
30
|
+
};
|
|
31
|
+
}>;
|
|
32
|
+
connect: CoreFunction<{
|
|
33
|
+
credentials: undefined;
|
|
34
|
+
inputs: {
|
|
35
|
+
redirect: string;
|
|
36
|
+
code: string;
|
|
37
|
+
};
|
|
38
|
+
outputs: {
|
|
39
|
+
username?: string;
|
|
40
|
+
credentials: Config[`credentials`];
|
|
41
|
+
};
|
|
42
|
+
}>;
|
|
43
|
+
refresh: CoreFunction<{
|
|
44
|
+
credentials: Config[`credentials`];
|
|
45
|
+
inputs: undefined;
|
|
46
|
+
outputs: {
|
|
47
|
+
username?: string;
|
|
48
|
+
credentials: Config[`credentials`];
|
|
49
|
+
};
|
|
50
|
+
}>;
|
|
51
|
+
disconnect: CoreFunction<{
|
|
52
|
+
credentials: Config[`credentials`];
|
|
53
|
+
inputs: undefined;
|
|
54
|
+
outputs: {
|
|
55
|
+
done: true;
|
|
56
|
+
};
|
|
57
|
+
}>;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
export type SessionCredentials<Config extends CredentialsConfig = {}> = CommonCredentials<Config> & {
|
|
61
|
+
type: `session`;
|
|
62
|
+
fields: Field[];
|
|
63
|
+
functions: {
|
|
64
|
+
connect: CoreFunction<{
|
|
65
|
+
credentials: undefined;
|
|
66
|
+
inputs: {
|
|
67
|
+
fields: Record<string, any>;
|
|
68
|
+
};
|
|
69
|
+
outputs: {
|
|
70
|
+
username?: string;
|
|
71
|
+
credentials: Config[`credentials`];
|
|
72
|
+
};
|
|
73
|
+
}>;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
export type StaticCredentials<Config extends CredentialsConfig = {}> = CommonCredentials<Config> & {
|
|
77
|
+
type: `static`;
|
|
78
|
+
fields: Field[];
|
|
79
|
+
};
|
|
80
|
+
export type Credentials<Config extends CredentialsConfig = {}> = OAuthCredentials<Config> | StaticCredentials<Config> | SessionCredentials<Config>;
|
|
81
|
+
export declare const oauthCredentialsSchema: () => Joi.ObjectSchema<any>;
|
|
82
|
+
export declare const sessionCredentialsSchema: () => Joi.ObjectSchema<any>;
|
|
83
|
+
export declare const staticCredentialsSchema: () => Joi.ObjectSchema<any>;
|
|
84
|
+
export declare const credentialsSchema: () => Joi.AlternativesSchema<any>;
|
|
85
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
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.credentialsSchema = exports.staticCredentialsSchema = exports.sessionCredentialsSchema = exports.oauthCredentialsSchema = void 0;
|
|
7
|
+
const joi_1 = __importDefault(require("joi"));
|
|
8
|
+
const fields_1 = require("../minified-utils/fields");
|
|
9
|
+
const commons_1 = require("./commons");
|
|
10
|
+
const commonCredentialsSchema = () => joi_1.default.object({
|
|
11
|
+
model: joi_1.default.valid(`credentials`).required(),
|
|
12
|
+
sandbox: joi_1.default.bool().required(),
|
|
13
|
+
functions: joi_1.default.object({
|
|
14
|
+
check: joi_1.default.function().required(),
|
|
15
|
+
}).required(),
|
|
16
|
+
});
|
|
17
|
+
const oauthCredentialsSchema = () => joi_1.default.object({
|
|
18
|
+
type: joi_1.default.valid(`oauth`).required(),
|
|
19
|
+
functions: joi_1.default.object({
|
|
20
|
+
oauth: joi_1.default.function().required(),
|
|
21
|
+
connect: joi_1.default.function().required(),
|
|
22
|
+
refresh: joi_1.default.function().required(),
|
|
23
|
+
disconnect: joi_1.default.function().required(),
|
|
24
|
+
}).required(),
|
|
25
|
+
})
|
|
26
|
+
.concat(commonCredentialsSchema())
|
|
27
|
+
.concat((0, commons_1.commonSchema)());
|
|
28
|
+
exports.oauthCredentialsSchema = oauthCredentialsSchema;
|
|
29
|
+
const sessionCredentialsSchema = () => joi_1.default.object({
|
|
30
|
+
type: joi_1.default.valid(`session`).required(),
|
|
31
|
+
functions: joi_1.default.object({
|
|
32
|
+
connect: joi_1.default.function().required(),
|
|
33
|
+
}).required(),
|
|
34
|
+
})
|
|
35
|
+
.concat(commonCredentialsSchema())
|
|
36
|
+
.concat((0, commons_1.commonSchema)());
|
|
37
|
+
exports.sessionCredentialsSchema = sessionCredentialsSchema;
|
|
38
|
+
const staticCredentialsSchema = () => joi_1.default.object({
|
|
39
|
+
type: joi_1.default.valid(`static`).required(),
|
|
40
|
+
fields: (0, fields_1.fieldsSchema)()
|
|
41
|
+
.required()
|
|
42
|
+
.min(1),
|
|
43
|
+
})
|
|
44
|
+
.concat(commonCredentialsSchema())
|
|
45
|
+
.concat((0, commons_1.commonSchema)());
|
|
46
|
+
exports.staticCredentialsSchema = staticCredentialsSchema;
|
|
47
|
+
const credentialsSchema = () => joi_1.default.alternatives(exports.oauthCredentialsSchema, exports.staticCredentialsSchema, exports.sessionCredentialsSchema);
|
|
48
|
+
exports.credentialsSchema = credentialsSchema;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { Request } from "express";
|
|
2
|
+
import Joi from "joi";
|
|
3
|
+
import { Field } from "../minified-utils/fields";
|
|
4
|
+
import { Common, CoreConfig, CoreFunction } from "./commons";
|
|
5
|
+
type CommonConnectableEvent<Keys extends string = string> = {
|
|
6
|
+
key: Keys;
|
|
7
|
+
};
|
|
8
|
+
type DefaultConnectableEvent<Keys extends string = string> = CommonConnectableEvent<Keys> & {
|
|
9
|
+
default: true;
|
|
10
|
+
};
|
|
11
|
+
type ErrorConnectableEvent<Keys extends string = string> = CommonConnectableEvent<Keys> & {
|
|
12
|
+
error: true;
|
|
13
|
+
};
|
|
14
|
+
type AdditionalConnectableEvent<Keys extends string = string> = CommonConnectableEvent<Keys> & {};
|
|
15
|
+
export type ConnectableEvent<Keys extends string = string> = DefaultConnectableEvent<Keys> | ErrorConnectableEvent<Keys> | AdditionalConnectableEvent<Keys>;
|
|
16
|
+
type EventConfig = Pick<CoreConfig, `credentials` | `outputs`> & {
|
|
17
|
+
flags?: {
|
|
18
|
+
inputs?: string[];
|
|
19
|
+
outputs: string[];
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
type CommonEvents<Config extends EventConfig = {}> = Common<Config> & {
|
|
23
|
+
model: `event`;
|
|
24
|
+
categories: string[];
|
|
25
|
+
credentials: string[];
|
|
26
|
+
sandbox: boolean;
|
|
27
|
+
fields: Field[];
|
|
28
|
+
examples: EventConfig[`outputs`][];
|
|
29
|
+
};
|
|
30
|
+
export type ImmediateTrigger<Config extends EventConfig = {}> = CommonEvents<Config> & {
|
|
31
|
+
type: `trigger`;
|
|
32
|
+
immediate: true;
|
|
33
|
+
outputs: [DefaultConnectableEvent<Config[`flags`][`outputs`][number]>];
|
|
34
|
+
functions: {
|
|
35
|
+
mount?: CoreFunction<{
|
|
36
|
+
credentials: Config[`credentials`];
|
|
37
|
+
inputs: {
|
|
38
|
+
fields: Record<string, any>;
|
|
39
|
+
};
|
|
40
|
+
outputs: {
|
|
41
|
+
done: boolean;
|
|
42
|
+
};
|
|
43
|
+
}>;
|
|
44
|
+
unmount?: CoreFunction<{
|
|
45
|
+
credentials: Config[`credentials`];
|
|
46
|
+
inputs: {
|
|
47
|
+
fields: Record<string, any>;
|
|
48
|
+
};
|
|
49
|
+
outputs: {
|
|
50
|
+
done: boolean;
|
|
51
|
+
};
|
|
52
|
+
}>;
|
|
53
|
+
handle: CoreFunction<{
|
|
54
|
+
credentials: Config[`credentials`];
|
|
55
|
+
inputs: {
|
|
56
|
+
fields: Record<string, any>;
|
|
57
|
+
request: Request;
|
|
58
|
+
};
|
|
59
|
+
outputs: {
|
|
60
|
+
records: Config[`outputs`][];
|
|
61
|
+
flags: Partial<Record<Config[`flags`][`outputs`][number], true>>;
|
|
62
|
+
};
|
|
63
|
+
}>;
|
|
64
|
+
fire?: CoreFunction<{
|
|
65
|
+
credentials: Config[`credentials`];
|
|
66
|
+
inputs: {
|
|
67
|
+
fields: Record<string, any>;
|
|
68
|
+
};
|
|
69
|
+
outputs: {
|
|
70
|
+
done: boolean;
|
|
71
|
+
};
|
|
72
|
+
}>;
|
|
73
|
+
poll?: CoreFunction<{
|
|
74
|
+
credentials: Config[`credentials`];
|
|
75
|
+
inputs: {
|
|
76
|
+
fields: Record<string, any>;
|
|
77
|
+
last_schedule?: string;
|
|
78
|
+
limit?: number;
|
|
79
|
+
};
|
|
80
|
+
outputs: {
|
|
81
|
+
records: Config[`outputs`][];
|
|
82
|
+
flags: Partial<Record<Config[`flags`][`outputs`][number], true>>;
|
|
83
|
+
};
|
|
84
|
+
}>;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
export type ScheduledTrigger<Config extends EventConfig = {}> = CommonEvents<Config> & {
|
|
88
|
+
type: `trigger`;
|
|
89
|
+
immediate: false;
|
|
90
|
+
outputs: [DefaultConnectableEvent<Config[`flags`][`outputs`][number]>];
|
|
91
|
+
functions: {
|
|
92
|
+
poll: CoreFunction<{
|
|
93
|
+
credentials: Config[`credentials`];
|
|
94
|
+
inputs: {
|
|
95
|
+
fields: Record<string, any>;
|
|
96
|
+
last_schedule?: string;
|
|
97
|
+
limit?: number;
|
|
98
|
+
};
|
|
99
|
+
outputs: {
|
|
100
|
+
records: Config[`outputs`][];
|
|
101
|
+
flags: Partial<Record<Config[`flags`][`outputs`][number], true>>;
|
|
102
|
+
};
|
|
103
|
+
}>;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
export type Trigger<Config extends EventConfig = {}> = ImmediateTrigger<Config> | ScheduledTrigger<Config>;
|
|
107
|
+
export type Action<Config extends EventConfig = {}> = CommonEvents<Config> & {
|
|
108
|
+
type: `action`;
|
|
109
|
+
inputs: [DefaultConnectableEvent<Config[`flags`][`inputs`][number]>, ...AdditionalConnectableEvent<Config[`flags`][`inputs`][number]>[]];
|
|
110
|
+
outputs: [DefaultConnectableEvent<Config[`flags`][`outputs`][number]>, ...(AdditionalConnectableEvent<Config[`flags`][`outputs`][number]> | ErrorConnectableEvent<Config[`flags`][`outputs`][number]>)[]];
|
|
111
|
+
functions: {
|
|
112
|
+
execute: CoreFunction<{
|
|
113
|
+
credentials: Config[`credentials`];
|
|
114
|
+
inputs: {
|
|
115
|
+
fields: Record<string, any>;
|
|
116
|
+
flags: Partial<Record<Config[`flags`][`inputs`][number], true>>;
|
|
117
|
+
};
|
|
118
|
+
outputs: {
|
|
119
|
+
output: Config[`outputs`];
|
|
120
|
+
flags: Partial<Record<Config[`flags`][`outputs`][number], true>>;
|
|
121
|
+
};
|
|
122
|
+
}>;
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
export type Event<Config extends EventConfig = {}> = Action<Config> | Trigger<Config>;
|
|
126
|
+
export declare const scheduledTriggerSchema: () => Joi.ObjectSchema<any>;
|
|
127
|
+
export declare const immediateTriggerSchema: () => Joi.ObjectSchema<any>;
|
|
128
|
+
export declare const triggerSchema: () => Joi.AlternativesSchema<any>;
|
|
129
|
+
export declare const actionSchema: () => Joi.ObjectSchema<any>;
|
|
130
|
+
export declare const eventSchema: () => Joi.AlternativesSchema<any>;
|
|
131
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
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.eventSchema = exports.actionSchema = exports.triggerSchema = exports.immediateTriggerSchema = exports.scheduledTriggerSchema = void 0;
|
|
7
|
+
const joi_1 = __importDefault(require("joi"));
|
|
8
|
+
const fields_1 = require("../minified-utils/fields");
|
|
9
|
+
const commons_1 = require("./commons");
|
|
10
|
+
const commonConnectableEventSchema = () => joi_1.default.object({
|
|
11
|
+
key: joi_1.default.string().required(),
|
|
12
|
+
});
|
|
13
|
+
const defaultConnectableEventSchema = () => joi_1.default.object({
|
|
14
|
+
default: joi_1.default.valid(true).required(),
|
|
15
|
+
})
|
|
16
|
+
.concat(commonConnectableEventSchema());
|
|
17
|
+
const errorConnectableEventSchema = () => joi_1.default.object({
|
|
18
|
+
error: joi_1.default.valid(true).required(),
|
|
19
|
+
})
|
|
20
|
+
.concat(commonConnectableEventSchema());
|
|
21
|
+
const additionalConnectableEventSchema = () => joi_1.default.object({})
|
|
22
|
+
.concat(commonConnectableEventSchema());
|
|
23
|
+
const commonEventsSchema = () => joi_1.default.object({
|
|
24
|
+
model: joi_1.default.valid(`event`).required(),
|
|
25
|
+
categories: joi_1.default.array().items(joi_1.default.string()).required(),
|
|
26
|
+
credentials: joi_1.default.array().items((0, commons_1.idSchema)().optional()).required().min(0),
|
|
27
|
+
sandbox: joi_1.default.bool().required(),
|
|
28
|
+
fields: (0, fields_1.fieldsSchema)().required(),
|
|
29
|
+
examples: joi_1.default.array(),
|
|
30
|
+
});
|
|
31
|
+
const scheduledTriggerSchema = () => joi_1.default.object({
|
|
32
|
+
type: joi_1.default.valid(`trigger`).required(),
|
|
33
|
+
immediate: joi_1.default.valid(false).required(),
|
|
34
|
+
outputs: joi_1.default.array()
|
|
35
|
+
.length(1)
|
|
36
|
+
.items(defaultConnectableEventSchema())
|
|
37
|
+
.required(),
|
|
38
|
+
functions: joi_1.default.object({
|
|
39
|
+
poll: joi_1.default.function().required(),
|
|
40
|
+
}).required(),
|
|
41
|
+
})
|
|
42
|
+
.concat((0, commons_1.commonSchema)())
|
|
43
|
+
.concat(commonEventsSchema());
|
|
44
|
+
exports.scheduledTriggerSchema = scheduledTriggerSchema;
|
|
45
|
+
const immediateTriggerSchema = () => joi_1.default.object({
|
|
46
|
+
type: joi_1.default.valid(`trigger`).required(),
|
|
47
|
+
immediate: joi_1.default.valid(true).required(),
|
|
48
|
+
outputs: joi_1.default.array()
|
|
49
|
+
.items(defaultConnectableEventSchema())
|
|
50
|
+
.length(1)
|
|
51
|
+
.required(),
|
|
52
|
+
functions: joi_1.default.object({
|
|
53
|
+
mount: joi_1.default.function(),
|
|
54
|
+
unmount: joi_1.default.function(),
|
|
55
|
+
handle: joi_1.default.function().required(),
|
|
56
|
+
poll: joi_1.default.function(),
|
|
57
|
+
}).required(),
|
|
58
|
+
})
|
|
59
|
+
.concat((0, commons_1.commonSchema)())
|
|
60
|
+
.concat(commonEventsSchema());
|
|
61
|
+
exports.immediateTriggerSchema = immediateTriggerSchema;
|
|
62
|
+
const triggerSchema = () => joi_1.default.alternatives((0, exports.scheduledTriggerSchema)(), (0, exports.immediateTriggerSchema)());
|
|
63
|
+
exports.triggerSchema = triggerSchema;
|
|
64
|
+
const actionSchema = () => joi_1.default.object({
|
|
65
|
+
type: joi_1.default.valid(`action`).required(),
|
|
66
|
+
inputs: joi_1.default.array()
|
|
67
|
+
.items(defaultConnectableEventSchema().required(), additionalConnectableEventSchema())
|
|
68
|
+
.min(1)
|
|
69
|
+
.required(),
|
|
70
|
+
outputs: joi_1.default.array()
|
|
71
|
+
.items(defaultConnectableEventSchema().required(), errorConnectableEventSchema().optional(), additionalConnectableEventSchema().optional())
|
|
72
|
+
.min(1)
|
|
73
|
+
.required(),
|
|
74
|
+
functions: joi_1.default.object({
|
|
75
|
+
execute: joi_1.default.function().required(),
|
|
76
|
+
}).required(),
|
|
77
|
+
})
|
|
78
|
+
.concat((0, commons_1.commonSchema)())
|
|
79
|
+
.concat(commonEventsSchema());
|
|
80
|
+
exports.actionSchema = actionSchema;
|
|
81
|
+
const eventSchema = () => joi_1.default.alternatives((0, exports.triggerSchema)(), (0, exports.actionSchema)());
|
|
82
|
+
exports.eventSchema = eventSchema;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Joi from "joi";
|
|
2
|
+
import { Credentials } from "./credentials";
|
|
3
|
+
import { Action, Trigger } from "./events";
|
|
4
|
+
export type Provider = {
|
|
5
|
+
id: string;
|
|
6
|
+
model: `provider`;
|
|
7
|
+
categories: string[];
|
|
8
|
+
credentials: Record<string, Credentials>;
|
|
9
|
+
triggers: Record<string, Trigger>;
|
|
10
|
+
actions: Record<string, Action>;
|
|
11
|
+
};
|
|
12
|
+
export declare const providerSchema: () => Joi.ObjectSchema<any>;
|
|
@@ -0,0 +1,25 @@
|
|
|
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.providerSchema = void 0;
|
|
7
|
+
const joi_1 = __importDefault(require("joi"));
|
|
8
|
+
const credentials_1 = require("./credentials");
|
|
9
|
+
const events_1 = require("./events");
|
|
10
|
+
const commons_1 = require("./commons");
|
|
11
|
+
const providerSchema = () => joi_1.default.object({
|
|
12
|
+
id: (0, commons_1.idSchema)(),
|
|
13
|
+
model: joi_1.default.valid(`provider`).required(),
|
|
14
|
+
categories: joi_1.default.array().items(joi_1.default.string()).required(),
|
|
15
|
+
credentials: joi_1.default.object()
|
|
16
|
+
.pattern((0, commons_1.idSchema)(), (0, credentials_1.credentialsSchema)())
|
|
17
|
+
.required(),
|
|
18
|
+
triggers: joi_1.default.object()
|
|
19
|
+
.pattern((0, commons_1.idSchema)(), (0, events_1.triggerSchema)())
|
|
20
|
+
.required(),
|
|
21
|
+
actions: joi_1.default.object()
|
|
22
|
+
.pattern((0, commons_1.idSchema)(), (0, events_1.actionSchema)())
|
|
23
|
+
.required(),
|
|
24
|
+
});
|
|
25
|
+
exports.providerSchema = providerSchema;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { Core, core } from './core';
|
|
2
|
+
export { getCategories } from './entities/category';
|
|
3
|
+
export { CoreFunction, idSchema } from './entities/commons';
|
|
4
|
+
export { Credentials, OAuthCredentials, StaticCredentials, SessionCredentials, credentialsSchema, oauthCredentialsSchema, staticCredentialsSchema, sessionCredentialsSchema } from './entities/credentials';
|
|
5
|
+
export { Action, Event, ImmediateTrigger, ScheduledTrigger, Trigger, actionSchema, eventSchema, immediateTriggerSchema, scheduledTriggerSchema, triggerSchema } from './entities/events';
|
|
6
|
+
export { Provider, providerSchema } from './entities/provider';
|
|
7
|
+
export { Field, SelectFieldChoice, ValidationResult, extract, fieldSchema, fieldsSchema, validate } from './minified-utils/fields';
|
|
8
|
+
export { i18n, localizeFields, localizeInputs, localizeOutputs, localizeProperties } from './minified-utils/locales';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.localizeProperties = exports.localizeOutputs = exports.localizeInputs = exports.localizeFields = exports.i18n = exports.validate = exports.fieldsSchema = exports.fieldSchema = exports.extract = exports.providerSchema = exports.triggerSchema = exports.scheduledTriggerSchema = exports.immediateTriggerSchema = exports.eventSchema = exports.actionSchema = exports.sessionCredentialsSchema = exports.staticCredentialsSchema = exports.oauthCredentialsSchema = exports.credentialsSchema = exports.idSchema = exports.getCategories = exports.core = void 0;
|
|
4
|
+
var core_1 = require("./core");
|
|
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
|
+
var commons_1 = require("./entities/commons");
|
|
9
|
+
Object.defineProperty(exports, "idSchema", { enumerable: true, get: function () { return commons_1.idSchema; } });
|
|
10
|
+
var credentials_1 = require("./entities/credentials");
|
|
11
|
+
Object.defineProperty(exports, "credentialsSchema", { enumerable: true, get: function () { return credentials_1.credentialsSchema; } });
|
|
12
|
+
Object.defineProperty(exports, "oauthCredentialsSchema", { enumerable: true, get: function () { return credentials_1.oauthCredentialsSchema; } });
|
|
13
|
+
Object.defineProperty(exports, "staticCredentialsSchema", { enumerable: true, get: function () { return credentials_1.staticCredentialsSchema; } });
|
|
14
|
+
Object.defineProperty(exports, "sessionCredentialsSchema", { enumerable: true, get: function () { return credentials_1.sessionCredentialsSchema; } });
|
|
15
|
+
var events_1 = require("./entities/events");
|
|
16
|
+
Object.defineProperty(exports, "actionSchema", { enumerable: true, get: function () { return events_1.actionSchema; } });
|
|
17
|
+
Object.defineProperty(exports, "eventSchema", { enumerable: true, get: function () { return events_1.eventSchema; } });
|
|
18
|
+
Object.defineProperty(exports, "immediateTriggerSchema", { enumerable: true, get: function () { return events_1.immediateTriggerSchema; } });
|
|
19
|
+
Object.defineProperty(exports, "scheduledTriggerSchema", { enumerable: true, get: function () { return events_1.scheduledTriggerSchema; } });
|
|
20
|
+
Object.defineProperty(exports, "triggerSchema", { enumerable: true, get: function () { return events_1.triggerSchema; } });
|
|
21
|
+
var provider_1 = require("./entities/provider");
|
|
22
|
+
Object.defineProperty(exports, "providerSchema", { enumerable: true, get: function () { return provider_1.providerSchema; } });
|
|
23
|
+
var fields_1 = require("./minified-utils/fields");
|
|
24
|
+
Object.defineProperty(exports, "extract", { enumerable: true, get: function () { return fields_1.extract; } });
|
|
25
|
+
Object.defineProperty(exports, "fieldSchema", { enumerable: true, get: function () { return fields_1.fieldSchema; } });
|
|
26
|
+
Object.defineProperty(exports, "fieldsSchema", { enumerable: true, get: function () { return fields_1.fieldsSchema; } });
|
|
27
|
+
Object.defineProperty(exports, "validate", { enumerable: true, get: function () { return fields_1.validate; } });
|
|
28
|
+
var locales_1 = require("./minified-utils/locales");
|
|
29
|
+
Object.defineProperty(exports, "i18n", { enumerable: true, get: function () { return locales_1.i18n; } });
|
|
30
|
+
Object.defineProperty(exports, "localizeFields", { enumerable: true, get: function () { return locales_1.localizeFields; } });
|
|
31
|
+
Object.defineProperty(exports, "localizeInputs", { enumerable: true, get: function () { return locales_1.localizeInputs; } });
|
|
32
|
+
Object.defineProperty(exports, "localizeOutputs", { enumerable: true, get: function () { return locales_1.localizeOutputs; } });
|
|
33
|
+
Object.defineProperty(exports, "localizeProperties", { enumerable: true, get: function () { return locales_1.localizeProperties; } });
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
const handlebars_1 = __importDefault(require("handlebars"));
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
class Context {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.resolve = (source, data) => {
|
|
11
|
+
let isObject = false;
|
|
12
|
+
let unresolved;
|
|
13
|
+
if (lodash_1.default.isNull(source) || lodash_1.default.isUndefined(source)) {
|
|
14
|
+
return source;
|
|
15
|
+
}
|
|
16
|
+
if (lodash_1.default.isObject(source) || lodash_1.default.isArray(source)) {
|
|
17
|
+
isObject = true;
|
|
18
|
+
unresolved = JSON.stringify(source);
|
|
19
|
+
}
|
|
20
|
+
else if (typeof source === `string`) {
|
|
21
|
+
unresolved = source;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return source;
|
|
25
|
+
}
|
|
26
|
+
if (!unresolved.includes(`{{`)) {
|
|
27
|
+
return source;
|
|
28
|
+
}
|
|
29
|
+
const template = handlebars_1.default.compile(unresolved);
|
|
30
|
+
const resolved = template(data);
|
|
31
|
+
return isObject ? JSON.parse(resolved) : resolved;
|
|
32
|
+
};
|
|
33
|
+
handlebars_1.default.registerHelper({
|
|
34
|
+
eq: (v1, v2) => v1 === v2,
|
|
35
|
+
ne: (v1, v2) => v1 !== v2,
|
|
36
|
+
lt: (v1, v2) => v1 < v2,
|
|
37
|
+
gt: (v1, v2) => v1 > v2,
|
|
38
|
+
lte: (v1, v2) => v1 <= v2,
|
|
39
|
+
gte: (v1, v2) => v1 >= v2,
|
|
40
|
+
and: (v1, v2) => v1 && v2,
|
|
41
|
+
or: (v1, v2) => v1 || v2,
|
|
42
|
+
"+": (v1, v2) => v1 + v2,
|
|
43
|
+
"-": (v1, v2) => v1 - v2,
|
|
44
|
+
"*": (v1, v2) => v1 * v2,
|
|
45
|
+
"/": (v1, v2) => v1 / v2,
|
|
46
|
+
"sum": (v1, v2) => v1 + v2,
|
|
47
|
+
"subtract": (v1, v2) => v1 - v2,
|
|
48
|
+
"multiply": (v1, v2) => v1 * v2,
|
|
49
|
+
"divide": (v1, v2) => v1 / v2,
|
|
50
|
+
"abs": (v1) => Math.abs(v1),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const context = new Context();
|
|
55
|
+
exports.default = context;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type ReadOptions = {
|
|
2
|
+
create?: boolean;
|
|
3
|
+
};
|
|
4
|
+
export declare class Env {
|
|
5
|
+
private readonly filepath;
|
|
6
|
+
private readonly env;
|
|
7
|
+
private readonly getEnv;
|
|
8
|
+
constructor(root: string);
|
|
9
|
+
readonly read: (name: string, options?: ReadOptions) => Promise<string>;
|
|
10
|
+
readonly write: (name: string, value: string) => Promise<void>;
|
|
11
|
+
private readonly prompt;
|
|
12
|
+
}
|
|
13
|
+
export {};
|