@beseif-solutions/prow-core 0.3.8 → 0.3.10
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 +5 -5
- package/dist/entities/commons.d.ts +7 -4
- package/dist/entities/events.d.ts +12 -12
- package/dist/entities/source.d.ts +5 -1
- package/dist/minified-utils/protocol.js +65 -81
- package/package.json +1 -1
- package/src/core.ts +4 -5
- package/src/entities/commons.ts +7 -4
- package/src/entities/events.ts +14 -19
- package/src/entities/source.ts +6 -1
- package/src/minified-utils/protocol.ts +56 -70
package/dist/core.d.ts
CHANGED
|
@@ -3,16 +3,16 @@ import Joi from "joi";
|
|
|
3
3
|
import lodash from "lodash";
|
|
4
4
|
import moment from "moment-timezone";
|
|
5
5
|
import { FromCatalog, FromDirectory, T } from "./minified-utils/locales";
|
|
6
|
-
|
|
6
|
+
import { SourceConfig } from "./entities/source";
|
|
7
7
|
export type SourceFunctions = {
|
|
8
|
-
register: <
|
|
8
|
+
register: <SC extends SourceConfig = SourceConfig>(source: SC[`id`], sandbox: boolean, data: SC[`fields`]) => Promise<{
|
|
9
9
|
id: string;
|
|
10
10
|
}>;
|
|
11
|
-
consume: <
|
|
11
|
+
consume: <SC extends SourceConfig = SourceConfig>(source: SC[`id`], sandbox: boolean) => Promise<{
|
|
12
12
|
id: string;
|
|
13
|
-
data:
|
|
13
|
+
data: SC[`fields`];
|
|
14
14
|
}[]>;
|
|
15
|
-
unregister: (source:
|
|
15
|
+
unregister: <SC extends SourceConfig = SourceConfig>(source: SC[`id`], sandbox: boolean, id: string) => Promise<void>;
|
|
16
16
|
};
|
|
17
17
|
export type Core = {
|
|
18
18
|
axios: AxiosInstance;
|
|
@@ -5,17 +5,20 @@ export type CoreConfig = {
|
|
|
5
5
|
credentials?: Record<string, any>;
|
|
6
6
|
outputs?: any;
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
type Configuration<Config extends CoreConfig> = ({
|
|
9
9
|
sandbox: boolean;
|
|
10
10
|
organization?: string;
|
|
11
11
|
} & (Config[`inputs`] extends undefined ? {} : {
|
|
12
12
|
inputs: Config[`inputs`];
|
|
13
13
|
}) & (Config[`credentials`] extends undefined ? {} : {
|
|
14
14
|
credentials: Config[`credentials`];
|
|
15
|
-
}))
|
|
16
|
-
type
|
|
15
|
+
}));
|
|
16
|
+
export type CoreFunction<Config extends CoreConfig = {}> = ((core: Core, configuration: Configuration<Config>) => Promise<Config[`outputs`]>) | ((core: Core, configuration: Configuration<Config>) => Config[`outputs`]);
|
|
17
|
+
type CommonConfig = Pick<CoreConfig, `credentials`> & {
|
|
18
|
+
id?: string;
|
|
19
|
+
};
|
|
17
20
|
export type Common<Config extends CommonConfig = {}> = {
|
|
18
|
-
id: string;
|
|
21
|
+
id: Config[`id`] extends string ? Config[`id`] : string;
|
|
19
22
|
helpers?: Record<string, CoreFunction<{
|
|
20
23
|
credentials: Config[`credentials`];
|
|
21
24
|
inputs: any;
|
|
@@ -58,6 +58,9 @@ export type Request = {
|
|
|
58
58
|
body: Record<string, any>;
|
|
59
59
|
raw: string;
|
|
60
60
|
};
|
|
61
|
+
type SourcePreferences<Config extends EventConfig> = Config[`sources`] extends string[] ? {
|
|
62
|
+
sources: Record<Config[`sources`][number], boolean>;
|
|
63
|
+
} : {};
|
|
61
64
|
export type ImmediateTrigger<Config extends SetupEventConfig> = CommonEvents<Config> & {
|
|
62
65
|
type: `trigger`;
|
|
63
66
|
immediate: true;
|
|
@@ -115,7 +118,7 @@ export type ImmediateTrigger<Config extends SetupEventConfig> = CommonEvents<Con
|
|
|
115
118
|
fields: Config[`fields`];
|
|
116
119
|
request: Request;
|
|
117
120
|
setup?: Config[`setup`];
|
|
118
|
-
}
|
|
121
|
+
} & SourcePreferences<Config>;
|
|
119
122
|
outputs: {
|
|
120
123
|
records: Config[`outputs`][];
|
|
121
124
|
flags: Partial<Record<Config[`flags`][`outputs`][number], true>>;
|
|
@@ -127,7 +130,7 @@ export type ImmediateTrigger<Config extends SetupEventConfig> = CommonEvents<Con
|
|
|
127
130
|
fields: Config[`fields`];
|
|
128
131
|
link: string;
|
|
129
132
|
setup?: any;
|
|
130
|
-
}
|
|
133
|
+
} & SourcePreferences<Config>;
|
|
131
134
|
outputs: {
|
|
132
135
|
done: boolean;
|
|
133
136
|
};
|
|
@@ -138,7 +141,7 @@ export type ImmediateTrigger<Config extends SetupEventConfig> = CommonEvents<Con
|
|
|
138
141
|
fields: Config[`fields`];
|
|
139
142
|
last_schedule: string;
|
|
140
143
|
limit?: number;
|
|
141
|
-
}
|
|
144
|
+
} & SourcePreferences<Config>;
|
|
142
145
|
outputs: {
|
|
143
146
|
records: Config[`outputs`][];
|
|
144
147
|
flags: Partial<Record<Config[`flags`][`outputs`][number], true>>;
|
|
@@ -157,7 +160,7 @@ export type ScheduledTrigger<Config extends EventConfig> = CommonEvents<Config>
|
|
|
157
160
|
fields: Config[`fields`];
|
|
158
161
|
last_schedule: string;
|
|
159
162
|
limit?: number;
|
|
160
|
-
}
|
|
163
|
+
} & SourcePreferences<Config>;
|
|
161
164
|
outputs: {
|
|
162
165
|
records: Config[`outputs`][];
|
|
163
166
|
flags: Partial<Record<Config[`flags`][`outputs`][number], true>>;
|
|
@@ -184,12 +187,12 @@ export type SyncAction<Config extends MemoryEventConfig> = CommonEvents<Config>
|
|
|
184
187
|
fields: Config[`fields`];
|
|
185
188
|
flags: Partial<Record<Config[`flags`][`inputs`][number], true>>;
|
|
186
189
|
memory?: Config[`memory`];
|
|
187
|
-
}
|
|
190
|
+
} & SourcePreferences<Config>;
|
|
188
191
|
outputs: StandardOutput<Config> | MemoryOutput<Config>;
|
|
189
192
|
}>;
|
|
190
193
|
};
|
|
191
194
|
};
|
|
192
|
-
export type AsyncAction<Config extends
|
|
195
|
+
export type AsyncAction<Config extends MemoryEventConfig> = CommonEvents<Config> & {
|
|
193
196
|
type: `action`;
|
|
194
197
|
inputs: [DefaultConnectableEvent<Config[`flags`][`inputs`][number]>, ...AdditionalConnectableEvent<Config[`flags`][`inputs`][number]>[]];
|
|
195
198
|
outputs: [DefaultConnectableEvent<Config[`flags`][`outputs`][number]>, ...(AdditionalConnectableEvent<Config[`flags`][`outputs`][number]> | ErrorConnectableEvent<Config[`flags`][`outputs`][number]>)[]];
|
|
@@ -201,9 +204,8 @@ export type AsyncAction<Config extends SetupEventConfig & MemoryEventConfig> = C
|
|
|
201
204
|
fields: Config[`fields`];
|
|
202
205
|
flags: Partial<Record<Config[`flags`][`inputs`][number], true>>;
|
|
203
206
|
link: string;
|
|
204
|
-
setup?: Config[`setup`];
|
|
205
207
|
memory?: Config[`memory`];
|
|
206
|
-
}
|
|
208
|
+
} & SourcePreferences<Config>;
|
|
207
209
|
outputs: {
|
|
208
210
|
done: boolean;
|
|
209
211
|
memory?: Config[`memory`];
|
|
@@ -214,9 +216,8 @@ export type AsyncAction<Config extends SetupEventConfig & MemoryEventConfig> = C
|
|
|
214
216
|
inputs: {
|
|
215
217
|
fields: Config[`fields`];
|
|
216
218
|
request: Request;
|
|
217
|
-
setup?: Config[`setup`];
|
|
218
219
|
memory?: Config[`memory`];
|
|
219
|
-
}
|
|
220
|
+
} & SourcePreferences<Config>;
|
|
220
221
|
outputs: StandardOutput<Config>;
|
|
221
222
|
}>;
|
|
222
223
|
fire?: CoreFunction<{
|
|
@@ -224,9 +225,8 @@ export type AsyncAction<Config extends SetupEventConfig & MemoryEventConfig> = C
|
|
|
224
225
|
inputs: {
|
|
225
226
|
fields: Config[`fields`];
|
|
226
227
|
link: string;
|
|
227
|
-
setup?: Config[`setup`];
|
|
228
228
|
memory?: Config[`memory`];
|
|
229
|
-
}
|
|
229
|
+
} & SourcePreferences<Config>;
|
|
230
230
|
outputs: {
|
|
231
231
|
done: boolean;
|
|
232
232
|
};
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import Joi from "joi";
|
|
2
2
|
import { Field } from "../minified-utils/fields";
|
|
3
3
|
import { Common } from "./commons";
|
|
4
|
-
export type
|
|
4
|
+
export type SourceConfig = {
|
|
5
|
+
id: string;
|
|
6
|
+
fields: Record<string, any>;
|
|
7
|
+
};
|
|
8
|
+
export type Source<Config extends SourceConfig = SourceConfig> = Common<Config> & {
|
|
5
9
|
model: "source";
|
|
6
10
|
sandbox: boolean;
|
|
7
11
|
fields: Field[];
|
|
@@ -7,7 +7,6 @@ exports.Protocol = void 0;
|
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
8
|
const joi_1 = __importDefault(require("joi"));
|
|
9
9
|
const lodash_1 = __importDefault(require("lodash"));
|
|
10
|
-
const moment_timezone_1 = __importDefault(require("moment-timezone"));
|
|
11
10
|
const core_1 = require("../core");
|
|
12
11
|
const provider_1 = require("../entities/provider");
|
|
13
12
|
const locales_1 = require("./locales");
|
|
@@ -45,88 +44,73 @@ const localeListSchema = joi_1.default.object({
|
|
|
45
44
|
command: joi_1.default.string().valid(`list:locales`).required(),
|
|
46
45
|
}).required();
|
|
47
46
|
const commandSchema = joi_1.default.alternatives(invokeSchema, credentialListSchema, actionListSchema, triggerListSchema, sourceListSchema, localeListSchema);
|
|
48
|
-
const API_SOURCES = (provider, configuration, context) =>
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
47
|
+
const API_SOURCES = (provider, configuration, context) => {
|
|
48
|
+
const REQ_CONFIG = {
|
|
49
|
+
baseURL: configuration.host,
|
|
50
|
+
headers: {
|
|
51
|
+
"x-prow-provider": provider.id,
|
|
52
|
+
"x-prow-version": provider.version,
|
|
53
|
+
"x-prow-token": configuration.token,
|
|
54
|
+
"x-prow-organization": context.organization,
|
|
55
|
+
"x-active-workspace": `${context.workspace}`,
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
register: async (source, sandbox, data) => {
|
|
60
|
+
try {
|
|
61
|
+
const { data: [created] } = await axios_1.default.post(`/feu/v1/sources`, {
|
|
62
|
+
provider: provider.id,
|
|
63
|
+
version: provider.version,
|
|
64
|
+
source: source,
|
|
65
|
+
sandbox: sandbox,
|
|
66
|
+
data: data,
|
|
67
|
+
}, REQ_CONFIG);
|
|
68
|
+
if (!created || !created.uuid) {
|
|
69
|
+
throw new Error(`Source registration failed`);
|
|
70
|
+
}
|
|
71
|
+
return { id: created.uuid };
|
|
68
72
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
catch (e) {
|
|
72
|
-
throw e;
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
unregister: async (source, sandbox, id) => {
|
|
76
|
-
try {
|
|
77
|
-
const { data: [get] } = await axios_1.default.post(`/api/v1/sources/list`, {
|
|
78
|
-
organization: context.organization,
|
|
79
|
-
workspace: context.workspace,
|
|
80
|
-
provider: provider.id,
|
|
81
|
-
version: provider.version,
|
|
82
|
-
source: source,
|
|
83
|
-
sandbox: sandbox,
|
|
84
|
-
uuid: id,
|
|
85
|
-
}, {
|
|
86
|
-
baseURL: configuration.host,
|
|
87
|
-
headers: {
|
|
88
|
-
"X-Internal-Token": configuration.token,
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
-
if (!get) {
|
|
92
|
-
throw new Error(`Source with ID ${id} not found`);
|
|
73
|
+
catch (e) {
|
|
74
|
+
throw e;
|
|
93
75
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
76
|
+
},
|
|
77
|
+
unregister: async (source, sandbox, id) => {
|
|
78
|
+
try {
|
|
79
|
+
const { data: [get] } = await axios_1.default.post(`/feu/v1/sources/list`, {
|
|
80
|
+
provider: provider.id,
|
|
81
|
+
version: provider.version,
|
|
82
|
+
source: source,
|
|
83
|
+
sandbox: sandbox,
|
|
84
|
+
uuid: id,
|
|
85
|
+
}, REQ_CONFIG);
|
|
86
|
+
if (!get) {
|
|
87
|
+
throw new Error(`Source with ID ${id} not found`);
|
|
88
|
+
}
|
|
89
|
+
await axios_1.default.delete(`/feu/v1/sources/${get.id}`, REQ_CONFIG);
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
throw e;
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
consume: async (source, sandbox) => {
|
|
96
|
+
try {
|
|
97
|
+
const { data: sources } = await axios_1.default.post(`/feu/v1/sources/list`, {
|
|
98
|
+
provider: provider.id,
|
|
99
|
+
version: provider.version,
|
|
100
|
+
source: source,
|
|
101
|
+
sandbox: sandbox,
|
|
102
|
+
}, REQ_CONFIG);
|
|
103
|
+
return sources.map((s) => ({
|
|
104
|
+
id: s.uuid,
|
|
105
|
+
data: s.data,
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
throw e;
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
};
|
|
130
114
|
class Protocol {
|
|
131
115
|
constructor(provider, configuration) {
|
|
132
116
|
this.evaluate = async (req) => {
|
package/package.json
CHANGED
package/src/core.ts
CHANGED
|
@@ -3,13 +3,12 @@ import Joi from "joi";
|
|
|
3
3
|
import lodash from "lodash";
|
|
4
4
|
import moment from "moment-timezone";
|
|
5
5
|
import { FromCatalog, FromDirectory, i18n, T } from "./minified-utils/locales";
|
|
6
|
-
|
|
7
|
-
type SyncOrAsync<T> = T | Promise<T>;
|
|
6
|
+
import { SourceConfig } from "./entities/source";
|
|
8
7
|
|
|
9
8
|
export type SourceFunctions = {
|
|
10
|
-
register: <
|
|
11
|
-
consume: <
|
|
12
|
-
unregister: (source:
|
|
9
|
+
register: <SC extends SourceConfig = SourceConfig>(source: SC[`id`], sandbox: boolean, data: SC[`fields`]) => Promise<{ id: string }>,
|
|
10
|
+
consume: <SC extends SourceConfig = SourceConfig>(source: SC[`id`], sandbox: boolean) => Promise<{ id: string, data: SC[`fields`] }[]>,
|
|
11
|
+
unregister: <SC extends SourceConfig = SourceConfig>(source: SC[`id`], sandbox: boolean, id: string) => Promise<void>,
|
|
13
12
|
};
|
|
14
13
|
|
|
15
14
|
const FALLBACK_SOURCES: SourceFunctions = {
|
package/src/entities/commons.ts
CHANGED
|
@@ -7,7 +7,7 @@ export type CoreConfig = {
|
|
|
7
7
|
outputs?: any,
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
type Configuration<Config extends CoreConfig> = ({
|
|
11
11
|
sandbox: boolean,
|
|
12
12
|
organization?: string,
|
|
13
13
|
} & (
|
|
@@ -20,13 +20,16 @@ export type CoreFunction<Config extends CoreConfig = {}> = (core: Core, configur
|
|
|
20
20
|
{} :
|
|
21
21
|
{ credentials: Config[`credentials`] }
|
|
22
22
|
)
|
|
23
|
-
)
|
|
23
|
+
);
|
|
24
24
|
|
|
25
|
+
export type CoreFunction<Config extends CoreConfig = {}> =
|
|
26
|
+
((core: Core, configuration: Configuration<Config>) => Promise<Config[`outputs`]>)
|
|
27
|
+
| ((core: Core, configuration: Configuration<Config>) => Config[`outputs`]);
|
|
25
28
|
|
|
26
|
-
type CommonConfig = Pick<CoreConfig, `credentials
|
|
29
|
+
type CommonConfig = Pick<CoreConfig, `credentials`> & { id?: string };
|
|
27
30
|
|
|
28
31
|
export type Common<Config extends CommonConfig = {}> = {
|
|
29
|
-
id: string,
|
|
32
|
+
id: Config[`id`] extends string ? Config[`id`] : string,
|
|
30
33
|
helpers?: Record<string, CoreFunction<{ credentials: Config[`credentials`], inputs: any, outputs: any }>>,
|
|
31
34
|
};
|
|
32
35
|
|
package/src/entities/events.ts
CHANGED
|
@@ -70,6 +70,11 @@ export type Request = {
|
|
|
70
70
|
raw: string,
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
+
type SourcePreferences<Config extends EventConfig> =
|
|
74
|
+
Config[`sources`] extends string[]
|
|
75
|
+
? { sources: Record<Config[`sources`][number], boolean> }
|
|
76
|
+
: {};
|
|
77
|
+
|
|
73
78
|
export type ImmediateTrigger<Config extends SetupEventConfig> = CommonEvents<Config> & {
|
|
74
79
|
type: `trigger`,
|
|
75
80
|
immediate: true,
|
|
@@ -97,17 +102,17 @@ export type ImmediateTrigger<Config extends SetupEventConfig> = CommonEvents<Con
|
|
|
97
102
|
}>,
|
|
98
103
|
handle: CoreFunction<{
|
|
99
104
|
credentials: Config[`credentials`],
|
|
100
|
-
inputs: { fields: Config[`fields`], request: Request, setup?: Config[`setup`] }
|
|
105
|
+
inputs: { fields: Config[`fields`], request: Request, setup?: Config[`setup`] } & SourcePreferences<Config>,
|
|
101
106
|
outputs: { records: Config[`outputs`][], flags: Partial<Record<Config[`flags`][`outputs`][number], true>> },
|
|
102
107
|
}>,
|
|
103
108
|
fire?: CoreFunction<{
|
|
104
109
|
credentials: Config[`credentials`],
|
|
105
|
-
inputs: { fields: Config[`fields`], link: string, setup?: any }
|
|
110
|
+
inputs: { fields: Config[`fields`], link: string, setup?: any } & SourcePreferences<Config>,
|
|
106
111
|
outputs: { done: boolean },
|
|
107
112
|
}>,
|
|
108
113
|
poll?: CoreFunction<{
|
|
109
114
|
credentials: Config[`credentials`],
|
|
110
|
-
inputs: { fields: Config[`fields`], last_schedule: string, limit?: number }
|
|
115
|
+
inputs: { fields: Config[`fields`], last_schedule: string, limit?: number } & SourcePreferences<Config>,
|
|
111
116
|
outputs: { records: Config[`outputs`][], flags: Partial<Record<Config[`flags`][`outputs`][number], true>> },
|
|
112
117
|
}>,
|
|
113
118
|
},
|
|
@@ -120,7 +125,7 @@ export type ScheduledTrigger<Config extends EventConfig> = CommonEvents<Config>
|
|
|
120
125
|
functions: {
|
|
121
126
|
poll: CoreFunction<{
|
|
122
127
|
credentials: Config[`credentials`],
|
|
123
|
-
inputs: { fields: Config[`fields`], last_schedule: string, limit?: number }
|
|
128
|
+
inputs: { fields: Config[`fields`], last_schedule: string, limit?: number } & SourcePreferences<Config>,
|
|
124
129
|
outputs: { records: Config[`outputs`][], flags: Partial<Record<Config[`flags`][`outputs`][number], true>> },
|
|
125
130
|
}>,
|
|
126
131
|
},
|
|
@@ -144,41 +149,31 @@ export type SyncAction<Config extends MemoryEventConfig> = CommonEvents<Config>
|
|
|
144
149
|
functions: {
|
|
145
150
|
execute: CoreFunction<{
|
|
146
151
|
credentials: Config[`credentials`],
|
|
147
|
-
inputs: { fields: Config[`fields`], flags: Partial<Record<Config[`flags`][`inputs`][number], true>>, memory?: Config[`memory`] }
|
|
152
|
+
inputs: { fields: Config[`fields`], flags: Partial<Record<Config[`flags`][`inputs`][number], true>>, memory?: Config[`memory`] } & SourcePreferences<Config>,
|
|
148
153
|
outputs: StandardOutput<Config> | MemoryOutput<Config>,
|
|
149
154
|
}>,
|
|
150
155
|
},
|
|
151
156
|
};
|
|
152
157
|
|
|
153
|
-
export type AsyncAction<Config extends
|
|
158
|
+
export type AsyncAction<Config extends MemoryEventConfig> = CommonEvents<Config> & {
|
|
154
159
|
type: `action`,
|
|
155
160
|
inputs: [DefaultConnectableEvent<Config[`flags`][`inputs`][number]>, ...AdditionalConnectableEvent<Config[`flags`][`inputs`][number]>[]],
|
|
156
161
|
outputs: [DefaultConnectableEvent<Config[`flags`][`outputs`][number]>, ...(AdditionalConnectableEvent<Config[`flags`][`outputs`][number]> | ErrorConnectableEvent<Config[`flags`][`outputs`][number]>)[]],
|
|
157
162
|
async: true,
|
|
158
163
|
functions: {
|
|
159
|
-
// mount?: CoreFunction<{
|
|
160
|
-
// credentials: Config[`credentials`],
|
|
161
|
-
// inputs: { fields: Config[`fields`], link: string },
|
|
162
|
-
// outputs: { done: boolean, setup?: Config[`setup`] },
|
|
163
|
-
// }>,
|
|
164
|
-
// unmount?: CoreFunction<{
|
|
165
|
-
// credentials: Config[`credentials`],
|
|
166
|
-
// inputs: { fields: Config[`fields`], link: string, setup?: Config[`setup`] },
|
|
167
|
-
// outputs: { done: boolean },
|
|
168
|
-
// }>,
|
|
169
164
|
execute: CoreFunction<{
|
|
170
165
|
credentials: Config[`credentials`],
|
|
171
|
-
inputs: { fields: Config[`fields`], flags: Partial<Record<Config[`flags`][`inputs`][number], true>>, link: string,
|
|
166
|
+
inputs: { fields: Config[`fields`], flags: Partial<Record<Config[`flags`][`inputs`][number], true>>, link: string, memory?: Config[`memory`] } & SourcePreferences<Config>,
|
|
172
167
|
outputs: { done: boolean, memory?: Config[`memory`] },
|
|
173
168
|
}>,
|
|
174
169
|
handle: CoreFunction<{
|
|
175
170
|
credentials: Config[`credentials`],
|
|
176
|
-
inputs: { fields: Config[`fields`], request: Request,
|
|
171
|
+
inputs: { fields: Config[`fields`], request: Request, memory?: Config[`memory`] } & SourcePreferences<Config>,
|
|
177
172
|
outputs: StandardOutput<Config>,
|
|
178
173
|
}>,
|
|
179
174
|
fire?: CoreFunction<{
|
|
180
175
|
credentials: Config[`credentials`],
|
|
181
|
-
inputs: { fields: Config[`fields`], link: string,
|
|
176
|
+
inputs: { fields: Config[`fields`], link: string, memory?: Config[`memory`] } & SourcePreferences<Config>,
|
|
182
177
|
outputs: { done: boolean },
|
|
183
178
|
}>,
|
|
184
179
|
},
|
package/src/entities/source.ts
CHANGED
|
@@ -2,7 +2,12 @@ import Joi from "joi";
|
|
|
2
2
|
import { Field, fieldsSchema } from "../minified-utils/fields";
|
|
3
3
|
import { Common, commonSchema } from "./commons";
|
|
4
4
|
|
|
5
|
-
export type
|
|
5
|
+
export type SourceConfig = {
|
|
6
|
+
id: string,
|
|
7
|
+
fields: Record<string, any>,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type Source<Config extends SourceConfig = SourceConfig> = Common<Config> & {
|
|
6
11
|
model: "source",
|
|
7
12
|
sandbox: boolean,
|
|
8
13
|
fields: Field[],
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import Joi from "joi";
|
|
3
3
|
import _ from "lodash";
|
|
4
|
-
import moment from "moment-timezone";
|
|
5
4
|
import { core, SourceFunctions } from "../core";
|
|
6
5
|
import { Credentials } from "../entities/credentials";
|
|
7
6
|
import { Action, Trigger } from "../entities/events";
|
|
@@ -56,76 +55,63 @@ const commandSchema = Joi.alternatives(
|
|
|
56
55
|
localeListSchema,
|
|
57
56
|
);
|
|
58
57
|
|
|
59
|
-
const API_SOURCES = (provider: Provider, configuration: Protocol.SourcesConfiguration, context: { organization: string, workspace: number }): SourceFunctions =>
|
|
60
|
-
register: async (source, sandbox, data) => {
|
|
61
|
-
try {
|
|
62
|
-
const { data: [created] } = await axios.post(`/api/v1/sources`, {
|
|
63
|
-
organization: context.organization,
|
|
64
|
-
workspace: context.workspace,
|
|
65
|
-
provider: provider.id,
|
|
66
|
-
version: provider.version,
|
|
67
|
-
source: source,
|
|
68
|
-
sandbox: sandbox,
|
|
69
|
-
data: data,
|
|
70
|
-
created_date: moment().format(`YYYY-MM-DDTHH:mm:ssZ`),
|
|
71
|
-
}, {
|
|
72
|
-
baseURL: configuration.host,
|
|
73
|
-
headers: {
|
|
74
|
-
"X-Internal-Token": configuration.token,
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
if (!created || !created.uuid) { throw new Error(`Source registration failed`); }
|
|
78
|
-
return { id: created.uuid };
|
|
79
|
-
} catch (e) { throw e; }
|
|
80
|
-
},
|
|
81
|
-
unregister: async (source, sandbox, id) => {
|
|
82
|
-
try {
|
|
83
|
-
const { data: [get] } = await axios.post(`/api/v1/sources/list`, {
|
|
84
|
-
organization: context.organization,
|
|
85
|
-
workspace: context.workspace,
|
|
86
|
-
provider: provider.id,
|
|
87
|
-
version: provider.version,
|
|
88
|
-
source: source,
|
|
89
|
-
sandbox: sandbox,
|
|
90
|
-
uuid: id,
|
|
91
|
-
}, {
|
|
92
|
-
baseURL: configuration.host,
|
|
93
|
-
headers: {
|
|
94
|
-
"X-Internal-Token": configuration.token,
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
if (!get) { throw new Error(`Source with ID ${id} not found`); }
|
|
58
|
+
const API_SOURCES = (provider: Provider, configuration: Protocol.SourcesConfiguration, context: { organization: string, workspace: number }): SourceFunctions => {
|
|
98
59
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
60
|
+
const REQ_CONFIG = {
|
|
61
|
+
baseURL: configuration.host,
|
|
62
|
+
headers: {
|
|
63
|
+
"x-prow-provider": provider.id,
|
|
64
|
+
"x-prow-version": provider.version,
|
|
65
|
+
"x-prow-token": configuration.token,
|
|
66
|
+
"x-prow-organization": context.organization,
|
|
67
|
+
"x-active-workspace": `${context.workspace}`,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
register: async (source, sandbox, data) => {
|
|
73
|
+
try {
|
|
74
|
+
const { data: [created] } = await axios.post(`/feu/v1/sources`, {
|
|
75
|
+
provider: provider.id,
|
|
76
|
+
version: provider.version,
|
|
77
|
+
source: source,
|
|
78
|
+
sandbox: sandbox,
|
|
79
|
+
data: data,
|
|
80
|
+
}, REQ_CONFIG);
|
|
81
|
+
if (!created || !created.uuid) { throw new Error(`Source registration failed`); }
|
|
82
|
+
return { id: created.uuid };
|
|
83
|
+
} catch (e) { throw e; }
|
|
84
|
+
},
|
|
85
|
+
unregister: async (source, sandbox, id) => {
|
|
86
|
+
try {
|
|
87
|
+
const { data: [get] } = await axios.post(`/feu/v1/sources/list`, {
|
|
88
|
+
provider: provider.id,
|
|
89
|
+
version: provider.version,
|
|
90
|
+
source: source,
|
|
91
|
+
sandbox: sandbox,
|
|
92
|
+
uuid: id,
|
|
93
|
+
}, REQ_CONFIG);
|
|
94
|
+
if (!get) { throw new Error(`Source with ID ${id} not found`); }
|
|
95
|
+
|
|
96
|
+
await axios.delete(`/feu/v1/sources/${get.id}`, REQ_CONFIG);
|
|
97
|
+
} catch (e) { throw e; }
|
|
98
|
+
},
|
|
99
|
+
consume: async (source, sandbox) => {
|
|
100
|
+
try {
|
|
101
|
+
const { data: sources } = await axios.post(`/feu/v1/sources/list`, {
|
|
102
|
+
provider: provider.id,
|
|
103
|
+
version: provider.version,
|
|
104
|
+
source: source,
|
|
105
|
+
sandbox: sandbox,
|
|
106
|
+
}, REQ_CONFIG);
|
|
107
|
+
return sources.map((s) => ({
|
|
108
|
+
id: s.uuid,
|
|
109
|
+
data: s.data,
|
|
110
|
+
}));
|
|
111
|
+
} catch (e) { throw e; }
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
};
|
|
129
115
|
|
|
130
116
|
export class Protocol {
|
|
131
117
|
|