@beseif-solutions/prow-core 0.1.0 → 0.2.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/core.d.ts CHANGED
@@ -5,14 +5,14 @@ import moment from "moment-timezone";
5
5
  import { FromCatalog, FromDirectory, T } from "./minified-utils/locales";
6
6
  type SyncOrAsync<T> = T | Promise<T>;
7
7
  export type SourceFunctions = {
8
- register: <T>(source: string, data: T) => SyncOrAsync<{
8
+ register: <T>(source: string, sandbox: boolean, data: T) => SyncOrAsync<{
9
9
  id: string;
10
10
  }>;
11
- consume: <T>(source: string) => SyncOrAsync<{
11
+ consume: <T>(source: string, sandbox: boolean) => SyncOrAsync<{
12
12
  id: string;
13
13
  data: T;
14
14
  }[]>;
15
- unregister: (source: string, id: string) => SyncOrAsync<void>;
15
+ unregister: (source: string, sandbox: boolean, id: string) => SyncOrAsync<void>;
16
16
  };
17
17
  export type Core = {
18
18
  axios: AxiosStatic;
@@ -12,7 +12,7 @@ export type CoreFunction<Config extends CoreConfig = {}> = (core: Core, configur
12
12
  inputs: Config[`inputs`];
13
13
  }) & (Config[`credentials`] extends undefined ? {} : {
14
14
  credentials: Config[`credentials`];
15
- }))) => Promise<Config[`outputs`]>;
15
+ }))) => Promise<Config[`outputs`]> | Config[`outputs`];
16
16
  type CommonConfig = Pick<CoreConfig, `credentials`>;
17
17
  export type Common<Config extends CommonConfig = {}> = {
18
18
  id: string;
@@ -1,6 +1,7 @@
1
1
  import Joi from "joi";
2
2
  import { Field } from "../minified-utils/fields";
3
3
  import { Common, CoreConfig, CoreFunction } from "./commons";
4
+ import { OneOrArray } from "../minified-utils/types";
4
5
  type CommonConnectableEvent<Keys extends string = string> = {
5
6
  key: Keys;
6
7
  };
@@ -28,6 +29,12 @@ type EventConfig = Pick<CoreConfig, `credentials` | `outputs`> & {
28
29
  sources?: string[];
29
30
  fields?: Record<string, any>;
30
31
  };
32
+ type SetupEventConfig = EventConfig & {
33
+ setup?: Record<string, any>;
34
+ };
35
+ type MemoryEventConfig = EventConfig & {
36
+ memory?: Record<string, any>;
37
+ };
31
38
  type CommonEvents<Config extends EventConfig = {
32
39
  fields: Record<string, any>;
33
40
  }> = Common<Config> & {
@@ -52,8 +59,9 @@ export type Request = {
52
59
  query: Record<string, string>;
53
60
  body: any;
54
61
  };
55
- export type ImmediateTrigger<Config extends EventConfig = {
62
+ export type ImmediateTrigger<Config extends SetupEventConfig = {
56
63
  fields: Record<string, any>;
64
+ setup: Record<string, any>;
57
65
  }> = CommonEvents<Config> & {
58
66
  type: `trigger`;
59
67
  immediate: true;
@@ -67,7 +75,7 @@ export type ImmediateTrigger<Config extends EventConfig = {
67
75
  };
68
76
  outputs: {
69
77
  done: boolean;
70
- setup?: any;
78
+ setup?: Config[`setup`];
71
79
  };
72
80
  }>;
73
81
  unmount?: CoreFunction<{
@@ -75,7 +83,7 @@ export type ImmediateTrigger<Config extends EventConfig = {
75
83
  inputs: {
76
84
  fields: Config[`fields`];
77
85
  link: string;
78
- setup?: any;
86
+ setup?: Config[`setup`];
79
87
  };
80
88
  outputs: {
81
89
  done: boolean;
@@ -87,7 +95,7 @@ export type ImmediateTrigger<Config extends EventConfig = {
87
95
  fields: Config[`fields`];
88
96
  link: string;
89
97
  request: Request;
90
- setup?: any;
98
+ setup?: Config[`setup`];
91
99
  };
92
100
  outputs: {
93
101
  done: boolean;
@@ -99,7 +107,7 @@ export type ImmediateTrigger<Config extends EventConfig = {
99
107
  inputs: {
100
108
  fields: Config[`fields`];
101
109
  request: Request;
102
- setup?: any;
110
+ setup?: Config[`setup`];
103
111
  };
104
112
  outputs: {
105
113
  records: Config[`outputs`][];
@@ -155,8 +163,18 @@ export type ScheduledTrigger<Config extends EventConfig = {
155
163
  export type Trigger<Config extends EventConfig = {
156
164
  fields: Record<string, any>;
157
165
  }> = ImmediateTrigger<Config> | ScheduledTrigger<Config>;
158
- export type Action<Config extends EventConfig = {
166
+ type StandardOutput<Config extends EventConfig> = {
167
+ output: OneOrArray<Config[`outputs`]>;
168
+ flags: Partial<Record<Config[`flags`][`outputs`][number], true>>;
169
+ };
170
+ type MemoryOutput<Config extends MemoryEventConfig = {
171
+ memory: Record<string, any>;
172
+ }> = {
173
+ memory: Config[`memory`];
174
+ } & (StandardOutput<Config> | {});
175
+ export type Action<Config extends MemoryEventConfig = {
159
176
  fields: Record<string, any>;
177
+ memory: Record<string, any>;
160
178
  }> = CommonEvents<Config> & {
161
179
  type: `action`;
162
180
  inputs: [DefaultConnectableEvent<Config[`flags`][`inputs`][number]>, ...AdditionalConnectableEvent<Config[`flags`][`inputs`][number]>[]];
@@ -167,10 +185,73 @@ export type Action<Config extends EventConfig = {
167
185
  inputs: {
168
186
  fields: Config[`fields`];
169
187
  flags: Partial<Record<Config[`flags`][`inputs`][number], true>>;
188
+ memory?: Config[`memory`];
189
+ };
190
+ outputs: StandardOutput<Config> | MemoryOutput<Config>;
191
+ }>;
192
+ };
193
+ };
194
+ export type AsyncAction<Config extends SetupEventConfig = {
195
+ fields: Record<string, any>;
196
+ setup: Record<string, any>;
197
+ }> = CommonEvents<Config> & {
198
+ type: `action`;
199
+ inputs: [DefaultConnectableEvent<Config[`flags`][`inputs`][number]>, ...AdditionalConnectableEvent<Config[`flags`][`inputs`][number]>[]];
200
+ outputs: [DefaultConnectableEvent<Config[`flags`][`outputs`][number]>, ...(AdditionalConnectableEvent<Config[`flags`][`outputs`][number]> | ErrorConnectableEvent<Config[`flags`][`outputs`][number]>)[]];
201
+ async: true;
202
+ functions: {
203
+ mount?: CoreFunction<{
204
+ credentials: Config[`credentials`];
205
+ inputs: {
206
+ fields: Config[`fields`];
207
+ link: string;
170
208
  };
171
209
  outputs: {
172
- output: Config[`outputs`];
173
- flags: Partial<Record<Config[`flags`][`outputs`][number], true>>;
210
+ done: boolean;
211
+ setup?: Config[`setup`];
212
+ };
213
+ }>;
214
+ unmount?: CoreFunction<{
215
+ credentials: Config[`credentials`];
216
+ inputs: {
217
+ fields: Config[`fields`];
218
+ link: string;
219
+ setup?: Config[`setup`];
220
+ };
221
+ outputs: {
222
+ done: boolean;
223
+ };
224
+ }>;
225
+ execute: CoreFunction<{
226
+ credentials: Config[`credentials`];
227
+ inputs: {
228
+ fields: Config[`fields`];
229
+ flags: Partial<Record<Config[`flags`][`inputs`][number], true>>;
230
+ setup?: Config[`setup`];
231
+ };
232
+ outputs: {
233
+ done: boolean;
234
+ setup?: Config[`setup`];
235
+ };
236
+ }>;
237
+ handle: CoreFunction<{
238
+ credentials: Config[`credentials`];
239
+ inputs: {
240
+ fields: Config[`fields`];
241
+ request: Request;
242
+ setup?: Config[`setup`];
243
+ };
244
+ outputs: StandardOutput<Config>;
245
+ }>;
246
+ fire?: CoreFunction<{
247
+ credentials: Config[`credentials`];
248
+ inputs: {
249
+ fields: Config[`fields`];
250
+ link: string;
251
+ setup?: Config[`setup`];
252
+ };
253
+ outputs: {
254
+ done: boolean;
174
255
  };
175
256
  }>;
176
257
  };
@@ -181,8 +262,10 @@ export type Event<Config extends EventConfig = {
181
262
  export declare const scheduledTriggerSchema: () => Joi.ObjectSchema<any>;
182
263
  export declare const immediateTriggerSchema: () => Joi.ObjectSchema<any>;
183
264
  export declare const triggerSchema: () => Joi.AlternativesSchema<any>;
184
- export declare const actionSchema: () => Joi.ObjectSchema<any>;
265
+ export declare const syncActionSchema: () => Joi.ObjectSchema<any>;
266
+ export declare const asyncActionSchema: () => Joi.ObjectSchema<any>;
267
+ export declare const actionSchema: () => Joi.AlternativesSchema<any>;
185
268
  export declare const eventSchema: () => Joi.AlternativesSchema<any>;
186
269
  export declare const triggerOutputSchema: () => Joi.ObjectSchema<any>;
187
- export declare const actionOutputSchema: () => Joi.ObjectSchema<any>;
270
+ export declare const actionOutputSchema: () => Joi.AlternativesSchema<any>;
188
271
  export {};
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.actionOutputSchema = exports.triggerOutputSchema = exports.eventSchema = exports.actionSchema = exports.triggerSchema = exports.immediateTriggerSchema = exports.scheduledTriggerSchema = void 0;
6
+ exports.actionOutputSchema = exports.triggerOutputSchema = exports.eventSchema = exports.actionSchema = exports.asyncActionSchema = exports.syncActionSchema = exports.triggerSchema = exports.immediateTriggerSchema = exports.scheduledTriggerSchema = void 0;
7
7
  const joi_1 = __importDefault(require("joi"));
8
8
  const fields_1 = require("../minified-utils/fields");
9
9
  const commons_1 = require("./commons");
@@ -79,7 +79,7 @@ const immediateTriggerSchema = () => joi_1.default.object({
79
79
  exports.immediateTriggerSchema = immediateTriggerSchema;
80
80
  const triggerSchema = () => joi_1.default.alternatives((0, exports.scheduledTriggerSchema)(), (0, exports.immediateTriggerSchema)());
81
81
  exports.triggerSchema = triggerSchema;
82
- const actionSchema = () => joi_1.default.object({
82
+ const syncActionSchema = () => joi_1.default.object({
83
83
  type: joi_1.default.valid(`action`).required(),
84
84
  inputs: joi_1.default.array()
85
85
  .items(defaultConnectableEventSchema().required(), additionalConnectableEventSchema())
@@ -95,6 +95,30 @@ const actionSchema = () => joi_1.default.object({
95
95
  })
96
96
  .concat((0, commons_1.commonSchema)())
97
97
  .concat(commonEventsSchema());
98
+ exports.syncActionSchema = syncActionSchema;
99
+ const asyncActionSchema = () => joi_1.default.object({
100
+ type: joi_1.default.valid(`action`).required(),
101
+ async: joi_1.default.valid(true).required(),
102
+ inputs: joi_1.default.array()
103
+ .items(defaultConnectableEventSchema().required(), additionalConnectableEventSchema())
104
+ .min(1)
105
+ .required(),
106
+ outputs: joi_1.default.array()
107
+ .items(defaultConnectableEventSchema().required(), errorConnectableEventSchema().optional(), additionalConnectableEventSchema().optional())
108
+ .min(1)
109
+ .required(),
110
+ functions: joi_1.default.object({
111
+ mount: joi_1.default.function(),
112
+ unmount: joi_1.default.function(),
113
+ execute: joi_1.default.function().required(),
114
+ handle: joi_1.default.function().required(),
115
+ fire: joi_1.default.function(),
116
+ }).required(),
117
+ })
118
+ .concat((0, commons_1.commonSchema)())
119
+ .concat(commonEventsSchema());
120
+ exports.asyncActionSchema = asyncActionSchema;
121
+ const actionSchema = () => joi_1.default.alternatives((0, exports.syncActionSchema)(), (0, exports.asyncActionSchema)());
98
122
  exports.actionSchema = actionSchema;
99
123
  const eventSchema = () => joi_1.default.alternatives((0, exports.triggerSchema)(), (0, exports.actionSchema)());
100
124
  exports.eventSchema = eventSchema;
@@ -106,10 +130,15 @@ const triggerOutputSchema = () => joi_1.default.object({
106
130
  .required(),
107
131
  });
108
132
  exports.triggerOutputSchema = triggerOutputSchema;
109
- const actionOutputSchema = () => joi_1.default.object({
133
+ const actionOutputSchema = () => joi_1.default.alternatives(joi_1.default.object({
110
134
  output: joi_1.default.alternatives(joi_1.default.array(), joi_1.default.object()).required(),
111
135
  flags: joi_1.default.object()
112
136
  .pattern(joi_1.default.string(), joi_1.default.valid(true))
113
137
  .required(),
114
- });
138
+ }), joi_1.default.object({
139
+ memory: joi_1.default.object().required(),
140
+ output: joi_1.default.alternatives(joi_1.default.array(), joi_1.default.object()),
141
+ flags: joi_1.default.object()
142
+ .pattern(joi_1.default.string(), joi_1.default.valid(true)),
143
+ }).and(`output`, `flags`));
115
144
  exports.actionOutputSchema = actionOutputSchema;
@@ -3,6 +3,7 @@ import { Field } from "../minified-utils/fields";
3
3
  import { Common } from "./commons";
4
4
  export type Source = Common & {
5
5
  model: "source";
6
+ sandbox: boolean;
6
7
  fields: Field[];
7
8
  };
8
9
  export declare const sourceSchema: () => Joi.ObjectSchema<any>;
@@ -9,6 +9,7 @@ const fields_1 = require("../minified-utils/fields");
9
9
  const commons_1 = require("./commons");
10
10
  const sourceSchema = () => joi_1.default.object({
11
11
  model: joi_1.default.valid(`source`).required(),
12
+ sandbox: joi_1.default.boolean().required(),
12
13
  fields: (0, fields_1.fieldsSchema)().required().min(1),
13
14
  }).concat((0, commons_1.commonSchema)());
14
15
  exports.sourceSchema = sourceSchema;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { Core, core } from './core';
2
2
  export { CoreFunction, idSchema } from './entities/commons';
3
3
  export { Credentials, credentialsSchema, OAuthCredentials, oauthCredentialsSchema, SessionCredentials, sessionCredentialsSchema, StaticCredentials, staticCredentialsSchema } from './entities/credentials';
4
- export { Action, actionOutputSchema, actionSchema, Event, eventSchema, ImmediateTrigger, immediateTriggerSchema, Request, ScheduledTrigger, scheduledTriggerSchema, Trigger, triggerOutputSchema, triggerSchema } from './entities/events';
4
+ export { Action, actionOutputSchema, actionSchema, AsyncAction, Event, eventSchema, ImmediateTrigger, immediateTriggerSchema, Request, ScheduledTrigger, scheduledTriggerSchema, syncActionSchema, Trigger, triggerOutputSchema, triggerSchema } from './entities/events';
5
5
  export { Provider, providerSchema } from './entities/provider';
6
6
  export { Source } from './entities/source';
7
7
  export { alter, extract, Field, fieldSchema, fieldsSchema, File, SelectFieldChoice, validate, ValidationResult } from './minified-utils/fields';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Protocol = exports.Properties = exports.localizeProperties = exports.localizeOutputs = exports.localizeInputs = exports.localizeGroup = exports.localizeFields = exports.i18n = exports.validate = exports.fieldsSchema = exports.fieldSchema = exports.extract = exports.alter = 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;
3
+ exports.Protocol = exports.Properties = exports.localizeProperties = exports.localizeOutputs = exports.localizeInputs = exports.localizeGroup = exports.localizeFields = exports.i18n = exports.validate = exports.fieldsSchema = exports.fieldSchema = exports.extract = exports.alter = exports.providerSchema = exports.triggerSchema = exports.triggerOutputSchema = exports.syncActionSchema = 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
6
  var commons_1 = require("./entities/commons");
@@ -16,6 +16,7 @@ Object.defineProperty(exports, "actionSchema", { enumerable: true, get: function
16
16
  Object.defineProperty(exports, "eventSchema", { enumerable: true, get: function () { return events_1.eventSchema; } });
17
17
  Object.defineProperty(exports, "immediateTriggerSchema", { enumerable: true, get: function () { return events_1.immediateTriggerSchema; } });
18
18
  Object.defineProperty(exports, "scheduledTriggerSchema", { enumerable: true, get: function () { return events_1.scheduledTriggerSchema; } });
19
+ Object.defineProperty(exports, "syncActionSchema", { enumerable: true, get: function () { return events_1.syncActionSchema; } });
19
20
  Object.defineProperty(exports, "triggerOutputSchema", { enumerable: true, get: function () { return events_1.triggerOutputSchema; } });
20
21
  Object.defineProperty(exports, "triggerSchema", { enumerable: true, get: function () { return events_1.triggerSchema; } });
21
22
  var provider_1 = require("./entities/provider");
@@ -38,7 +38,7 @@ type StringInputField<Extend = Record<never, never>> = {
38
38
  max?: number;
39
39
  regexp?: string;
40
40
  pattern?: `email` | `uri`;
41
- } & (SelectField<string, Extend> | TextareaField | RichTextField | {});
41
+ } & (SelectField<string, Extend> | CustomDisplayTextField | IDETextField | {});
42
42
  type NumberInputField<Extend = Record<never, never>> = {
43
43
  type: `number`;
44
44
  default?: number | number[];
@@ -48,7 +48,7 @@ type NumberInputField<Extend = Record<never, never>> = {
48
48
  float: true;
49
49
  decimals?: number;
50
50
  } | {
51
- float: false;
51
+ float?: false;
52
52
  }) & (SelectField<number, Extend> | {});
53
53
  type BooleanInputField<Extend = Record<never, never>> = {
54
54
  type: `boolean`;
@@ -101,11 +101,12 @@ export type SelectFieldChoice<Values = string | number | boolean | File, Extend
101
101
  key: string;
102
102
  value: Values;
103
103
  } & Extend;
104
- type TextareaField = {
105
- format: `textarea`;
104
+ type CustomDisplayTextField = {
105
+ format: `textarea` | `rich-text` | `markdown`;
106
106
  };
107
- type RichTextField = {
108
- format: `rich-text`;
107
+ type IDETextField = {
108
+ format: `code`;
109
+ language?: string;
109
110
  };
110
111
  type ValidationExtended = {
111
112
  original: any;
@@ -77,12 +77,17 @@ const stringInputFieldSchema = () => joi_1.default.object({
77
77
  pattern: joi_1.default.string().valid(`email`, `uri`),
78
78
  })
79
79
  .concat(joi_1.default.object({
80
- format: joi_1.default.string().valid(`select`, `textarea`, `rich-text`),
80
+ format: joi_1.default.string().valid(`select`, `textarea`, `rich-text`, `markdown`, `code`),
81
81
  choices: joi_1.default.when(`format`, {
82
82
  is: `select`,
83
83
  then: choicesSchema(joi_1.default.string()).required(),
84
84
  otherwise: joi_1.default.forbidden(),
85
85
  }),
86
+ language: joi_1.default.when(`format`, {
87
+ is: `code`,
88
+ then: joi_1.default.string(),
89
+ otherwise: joi_1.default.forbidden(),
90
+ }),
86
91
  }));
87
92
  const numberInputFieldSchema = () => joi_1.default.object({
88
93
  default: defaultSchema(joi_1.default.number()),
@@ -306,11 +311,13 @@ const getSimpleFieldSchema = (field) => {
306
311
  if (field.max) {
307
312
  typeSchema = typeSchema.max(field.max);
308
313
  }
309
- if (field.float) {
310
- typeSchema = typeSchema.precision(field.decimals || 2);
311
- }
312
- else {
313
- typeSchema = typeSchema.precision(0);
314
+ if (typeof field.float === `boolean`) {
315
+ if (field.float) {
316
+ typeSchema = typeSchema.precision(field.decimals || 2);
317
+ }
318
+ else {
319
+ typeSchema = typeSchema.precision(0);
320
+ }
314
321
  }
315
322
  break;
316
323
  case `dict`:
@@ -44,7 +44,7 @@ const localeListSchema = joi_1.default.object({
44
44
  }).required();
45
45
  const commandSchema = joi_1.default.alternatives(invokeSchema, credentialListSchema, actionListSchema, triggerListSchema, sourceListSchema, localeListSchema);
46
46
  const API_SOURCES = (provider, configuration, context) => ({
47
- register: async (source, data) => {
47
+ register: async (source, sandbox, data) => {
48
48
  try {
49
49
  const { data: [created] } = await axios_1.default.post(`/api/v1/sources`, {
50
50
  organization: context.organization,
@@ -52,6 +52,7 @@ const API_SOURCES = (provider, configuration, context) => ({
52
52
  provider: provider.id,
53
53
  version: provider.version,
54
54
  source: source,
55
+ sandbox: sandbox,
55
56
  data: data,
56
57
  created_date: (0, moment_timezone_1.default)().format(`YYYY-MM-DDTHH:mm:ssZ`),
57
58
  }, {
@@ -69,7 +70,7 @@ const API_SOURCES = (provider, configuration, context) => ({
69
70
  throw e;
70
71
  }
71
72
  },
72
- unregister: async (source, id) => {
73
+ unregister: async (source, sandbox, id) => {
73
74
  try {
74
75
  const { data: [get] } = await axios_1.default.post(`/api/v1/sources/list`, {
75
76
  organization: context.organization,
@@ -77,6 +78,7 @@ const API_SOURCES = (provider, configuration, context) => ({
77
78
  provider: provider.id,
78
79
  version: provider.version,
79
80
  source: source,
81
+ sandbox: sandbox,
80
82
  uuid: id,
81
83
  }, {
82
84
  baseURL: configuration.host,
@@ -98,7 +100,7 @@ const API_SOURCES = (provider, configuration, context) => ({
98
100
  throw e;
99
101
  }
100
102
  },
101
- consume: async (source) => {
103
+ consume: async (source, sandbox) => {
102
104
  try {
103
105
  const { data: sources } = await axios_1.default.post(`/api/v1/sources/list`, {
104
106
  organization: context.organization,
@@ -106,6 +108,7 @@ const API_SOURCES = (provider, configuration, context) => ({
106
108
  provider: provider.id,
107
109
  version: provider.version,
108
110
  source: source,
111
+ sandbox: sandbox,
109
112
  }, {
110
113
  baseURL: configuration.host,
111
114
  headers: {
@@ -9,3 +9,4 @@ export type DeepPartial<T extends Record<string, any>> = {
9
9
  [P in keyof T]?: T[P] extends Record<string, any> ? DeepPartial<T[P]> : T[P];
10
10
  };
11
11
  export type AsyncReturnType<T extends (...args: any[]) => any> = T extends (...args: any[]) => Promise<infer U> ? U : T extends (...args: any[]) => infer U ? U : any;
12
+ export type OneOrArray<T> = T | T[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beseif-solutions/prow-core",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Prow core functionalities and classes",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/core.ts CHANGED
@@ -7,9 +7,9 @@ import { FromCatalog, FromDirectory, i18n, T } from "./minified-utils/locales";
7
7
  type SyncOrAsync<T> = T | Promise<T>;
8
8
 
9
9
  export type SourceFunctions = {
10
- register: <T>(source: string, data: T) => SyncOrAsync<{ id: string }>,
11
- consume: <T>(source: string) => SyncOrAsync<{ id: string, data: T }[]>,
12
- unregister: (source: string, id: string) => SyncOrAsync<void>,
10
+ register: <T>(source: string, sandbox: boolean, data: T) => SyncOrAsync<{ id: string }>,
11
+ consume: <T>(source: string, sandbox: boolean) => SyncOrAsync<{ id: string, data: T }[]>,
12
+ unregister: (source: string, sandbox: boolean, id: string) => SyncOrAsync<void>,
13
13
  };
14
14
 
15
15
  const FALLBACK_SOURCES: SourceFunctions = {
@@ -20,7 +20,7 @@ export type CoreFunction<Config extends CoreConfig = {}> = (core: Core, configur
20
20
  {} :
21
21
  { credentials: Config[`credentials`] }
22
22
  )
23
- )) => Promise<Config[`outputs`]>;
23
+ )) => Promise<Config[`outputs`]> | Config[`outputs`];
24
24
 
25
25
 
26
26
  type CommonConfig = Pick<CoreConfig, `credentials`>;
@@ -1,6 +1,7 @@
1
1
  import Joi from "joi";
2
2
  import { Field, fieldsSchema } from "../minified-utils/fields";
3
3
  import { Common, commonSchema, CoreConfig, CoreFunction, idSchema } from "./commons";
4
+ import { OneOrArray } from "../minified-utils/types";
4
5
 
5
6
  type CommonConnectableEvent<Keys extends string = string> = {
6
7
  key: Keys,
@@ -36,6 +37,14 @@ type EventConfig = Pick<CoreConfig, `credentials` | `outputs`> & {
36
37
  fields?: Record<string, any>,
37
38
  };
38
39
 
40
+ type SetupEventConfig = EventConfig & {
41
+ setup?: Record<string, any>,
42
+ };
43
+
44
+ type MemoryEventConfig = EventConfig & {
45
+ memory?: Record<string, any>,
46
+ };
47
+
39
48
  type CommonEvents<Config extends EventConfig = { fields: Record<string, any> }> = Common<Config> & {
40
49
  model: `event`,
41
50
  categorization: {
@@ -60,7 +69,7 @@ export type Request = {
60
69
  body: any,
61
70
  };
62
71
 
63
- export type ImmediateTrigger<Config extends EventConfig = { fields: Record<string, any> }> = CommonEvents<Config> & {
72
+ export type ImmediateTrigger<Config extends SetupEventConfig = { fields: Record<string, any>, setup: Record<string, any> }> = CommonEvents<Config> & {
64
73
  type: `trigger`,
65
74
  immediate: true,
66
75
  outputs: [DefaultConnectableEvent<Config[`flags`][`outputs`][number]>],
@@ -68,21 +77,21 @@ export type ImmediateTrigger<Config extends EventConfig = { fields: Record<strin
68
77
  mount?: CoreFunction<{
69
78
  credentials: Config[`credentials`],
70
79
  inputs: { fields: Config[`fields`], link: string },
71
- outputs: { done: boolean, setup?: any },
80
+ outputs: { done: boolean, setup?: Config[`setup`] },
72
81
  }>,
73
82
  unmount?: CoreFunction<{
74
83
  credentials: Config[`credentials`],
75
- inputs: { fields: Config[`fields`], link: string, setup?: any },
84
+ inputs: { fields: Config[`fields`], link: string, setup?: Config[`setup`] },
76
85
  outputs: { done: boolean },
77
86
  }>,
78
87
  challenge?: CoreFunction<{
79
88
  credentials: Config[`credentials`],
80
- inputs: { fields: Config[`fields`], link: string, request: Request, setup?: any },
89
+ inputs: { fields: Config[`fields`], link: string, request: Request, setup?: Config[`setup`] },
81
90
  outputs: { done: boolean, response?: any },
82
91
  }>,
83
92
  handle: CoreFunction<{
84
93
  credentials: Config[`credentials`],
85
- inputs: { fields: Config[`fields`], request: Request, setup?: any },
94
+ inputs: { fields: Config[`fields`], request: Request, setup?: Config[`setup`] },
86
95
  outputs: { records: Config[`outputs`][], flags: Partial<Record<Config[`flags`][`outputs`][number], true>> },
87
96
  }>,
88
97
  fire?: CoreFunction<{
@@ -115,15 +124,56 @@ export type Trigger<Config extends EventConfig = { fields: Record<string, any> }
115
124
  | ImmediateTrigger<Config>
116
125
  | ScheduledTrigger<Config>;
117
126
 
118
- export type Action<Config extends EventConfig = { fields: Record<string, any> }> = CommonEvents<Config> & {
127
+ type StandardOutput<Config extends EventConfig> =
128
+ { output: OneOrArray<Config[`outputs`]>, flags: Partial<Record<Config[`flags`][`outputs`][number], true>> };
129
+
130
+ type MemoryOutput<Config extends MemoryEventConfig = { memory: Record<string, any> }> = {
131
+ memory: Config[`memory`],
132
+ } & (StandardOutput<Config> | {});
133
+
134
+ export type Action<Config extends MemoryEventConfig = { fields: Record<string, any>, memory: Record<string, any> }> = CommonEvents<Config> & {
135
+ type: `action`,
136
+ inputs: [DefaultConnectableEvent<Config[`flags`][`inputs`][number]>, ...AdditionalConnectableEvent<Config[`flags`][`inputs`][number]>[]],
137
+ outputs: [DefaultConnectableEvent<Config[`flags`][`outputs`][number]>, ...(AdditionalConnectableEvent<Config[`flags`][`outputs`][number]> | ErrorConnectableEvent<Config[`flags`][`outputs`][number]>)[]],
138
+ functions: {
139
+ execute: CoreFunction<{
140
+ credentials: Config[`credentials`],
141
+ inputs: { fields: Config[`fields`], flags: Partial<Record<Config[`flags`][`inputs`][number], true>>, memory?: Config[`memory`] },
142
+ outputs: StandardOutput<Config> | MemoryOutput<Config>,
143
+ }>,
144
+ },
145
+ };
146
+
147
+ export type AsyncAction<Config extends SetupEventConfig = { fields: Record<string, any>, setup: Record<string, any> }> = CommonEvents<Config> & {
119
148
  type: `action`,
120
149
  inputs: [DefaultConnectableEvent<Config[`flags`][`inputs`][number]>, ...AdditionalConnectableEvent<Config[`flags`][`inputs`][number]>[]],
121
150
  outputs: [DefaultConnectableEvent<Config[`flags`][`outputs`][number]>, ...(AdditionalConnectableEvent<Config[`flags`][`outputs`][number]> | ErrorConnectableEvent<Config[`flags`][`outputs`][number]>)[]],
151
+ async: true,
122
152
  functions: {
153
+ mount?: CoreFunction<{
154
+ credentials: Config[`credentials`],
155
+ inputs: { fields: Config[`fields`], link: string },
156
+ outputs: { done: boolean, setup?: Config[`setup`] },
157
+ }>,
158
+ unmount?: CoreFunction<{
159
+ credentials: Config[`credentials`],
160
+ inputs: { fields: Config[`fields`], link: string, setup?: Config[`setup`] },
161
+ outputs: { done: boolean },
162
+ }>,
123
163
  execute: CoreFunction<{
124
164
  credentials: Config[`credentials`],
125
- inputs: { fields: Config[`fields`], flags: Partial<Record<Config[`flags`][`inputs`][number], true>> },
126
- outputs: { output: Config[`outputs`], flags: Partial<Record<Config[`flags`][`outputs`][number], true>> },
165
+ inputs: { fields: Config[`fields`], flags: Partial<Record<Config[`flags`][`inputs`][number], true>>, setup?: Config[`setup`] },
166
+ outputs: { done: boolean, setup?: Config[`setup`] },
167
+ }>,
168
+ handle: CoreFunction<{
169
+ credentials: Config[`credentials`],
170
+ inputs: { fields: Config[`fields`], request: Request, setup?: Config[`setup`] },
171
+ outputs: StandardOutput<Config>,
172
+ }>,
173
+ fire?: CoreFunction<{
174
+ credentials: Config[`credentials`],
175
+ inputs: { fields: Config[`fields`], link: string, setup?: Config[`setup`] },
176
+ outputs: { done: boolean },
127
177
  }>,
128
178
  },
129
179
  };
@@ -219,7 +269,7 @@ export const immediateTriggerSchema = () =>
219
269
  export const triggerSchema = () =>
220
270
  Joi.alternatives(scheduledTriggerSchema(), immediateTriggerSchema());
221
271
 
222
- export const actionSchema = () =>
272
+ export const syncActionSchema = () =>
223
273
  Joi.object({
224
274
  type: Joi.valid(`action`).required(),
225
275
  inputs: Joi.array()
@@ -244,6 +294,39 @@ export const actionSchema = () =>
244
294
  .concat(commonSchema())
245
295
  .concat(commonEventsSchema());
246
296
 
297
+ export const asyncActionSchema = () =>
298
+ Joi.object({
299
+ type: Joi.valid(`action`).required(),
300
+ async: Joi.valid(true).required(),
301
+ inputs: Joi.array()
302
+ .items(
303
+ defaultConnectableEventSchema().required(),
304
+ additionalConnectableEventSchema(),
305
+ )
306
+ .min(1)
307
+ .required(),
308
+ outputs: Joi.array()
309
+ .items(
310
+ defaultConnectableEventSchema().required(),
311
+ errorConnectableEventSchema().optional(),
312
+ additionalConnectableEventSchema().optional(),
313
+ )
314
+ .min(1)
315
+ .required(),
316
+ functions: Joi.object({
317
+ mount: Joi.function(),
318
+ unmount: Joi.function(),
319
+ execute: Joi.function().required(),
320
+ handle: Joi.function().required(),
321
+ fire: Joi.function(),
322
+ }).required(),
323
+ })
324
+ .concat(commonSchema())
325
+ .concat(commonEventsSchema());
326
+
327
+ export const actionSchema = () =>
328
+ Joi.alternatives(syncActionSchema(), asyncActionSchema());
329
+
247
330
  export const eventSchema = () =>
248
331
  Joi.alternatives(triggerSchema(), actionSchema());
249
332
 
@@ -257,12 +340,25 @@ export const triggerOutputSchema = () =>
257
340
  });
258
341
 
259
342
  export const actionOutputSchema = () =>
260
- Joi.object({
261
- output: Joi.alternatives(
262
- Joi.array(),
263
- Joi.object(),
264
- ).required(),
265
- flags: Joi.object()
266
- .pattern(Joi.string(), Joi.valid(true))
267
- .required(),
268
- });
343
+ Joi.alternatives(
344
+ // standard output
345
+ Joi.object({
346
+ output: Joi.alternatives(
347
+ Joi.array(),
348
+ Joi.object(),
349
+ ).required(),
350
+ flags: Joi.object()
351
+ .pattern(Joi.string(), Joi.valid(true))
352
+ .required(),
353
+ }),
354
+ // memory output
355
+ Joi.object({
356
+ memory: Joi.object().required(),
357
+ output: Joi.alternatives(
358
+ Joi.array(),
359
+ Joi.object(),
360
+ ),
361
+ flags: Joi.object()
362
+ .pattern(Joi.string(), Joi.valid(true)),
363
+ }).and(`output`, `flags`),
364
+ );
@@ -4,11 +4,13 @@ import { Common, commonSchema } from "./commons";
4
4
 
5
5
  export type Source = Common & {
6
6
  model: "source",
7
+ sandbox: boolean,
7
8
  fields: Field[],
8
9
  };
9
10
 
10
11
  export const sourceSchema = () =>
11
12
  Joi.object({
12
13
  model: Joi.valid(`source`).required(),
14
+ sandbox: Joi.boolean().required(),
13
15
  fields: fieldsSchema().required().min(1),
14
16
  }).concat(commonSchema());
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { Core, core } from './core';
2
2
  export { CoreFunction, idSchema } from './entities/commons';
3
3
  export { Credentials, credentialsSchema, OAuthCredentials, oauthCredentialsSchema, SessionCredentials, sessionCredentialsSchema, StaticCredentials, staticCredentialsSchema } from './entities/credentials';
4
- export { Action, actionOutputSchema, actionSchema, Event, eventSchema, ImmediateTrigger, immediateTriggerSchema, Request, ScheduledTrigger, scheduledTriggerSchema, Trigger, triggerOutputSchema, triggerSchema } from './entities/events';
4
+ export { Action, actionOutputSchema, actionSchema, AsyncAction, Event, eventSchema, ImmediateTrigger, immediateTriggerSchema, Request, ScheduledTrigger, scheduledTriggerSchema, syncActionSchema, Trigger, triggerOutputSchema, triggerSchema } from './entities/events';
5
5
  export { Provider, providerSchema } from './entities/provider';
6
6
  export { Source } from './entities/source';
7
7
  export { alter, extract, Field, fieldSchema, fieldsSchema, File, SelectFieldChoice, validate, ValidationResult } from './minified-utils/fields';
@@ -61,8 +61,8 @@ type StringInputField<Extend = Record<never, never>> = {
61
61
  pattern?: `email` | `uri`,
62
62
  } & (
63
63
  | SelectField<string, Extend>
64
- | TextareaField
65
- | RichTextField
64
+ | CustomDisplayTextField
65
+ | IDETextField
66
66
  | {}
67
67
  );
68
68
 
@@ -73,7 +73,7 @@ type NumberInputField<Extend = Record<never, never>> = {
73
73
  max?: number,
74
74
  } & (
75
75
  | { float: true, decimals?: number }
76
- | { float: false }
76
+ | { float?: false }
77
77
  ) & (
78
78
  | SelectField<number, Extend>
79
79
  | {}
@@ -154,14 +154,14 @@ export type SelectFieldChoice<Values = string | number | boolean | File, Extend
154
154
  value: Values,
155
155
  } & Extend;
156
156
 
157
- /* textarea configuration */
158
- type TextareaField = {
159
- format: `textarea`,
157
+ /* custom display configuration */
158
+ type CustomDisplayTextField = {
159
+ format: `textarea` | `rich-text` | `markdown`,
160
160
  };
161
161
 
162
- /* rich text configuration */
163
- type RichTextField = {
164
- format: `rich-text`,
162
+ type IDETextField = {
163
+ format: `code`,
164
+ language?: string, // language for code highlighting
165
165
  };
166
166
 
167
167
  type ValidationExtended = {
@@ -274,12 +274,17 @@ const stringInputFieldSchema = () =>
274
274
  })
275
275
  .concat(
276
276
  Joi.object({
277
- format: Joi.string().valid(`select`, `textarea`, `rich-text`),
277
+ format: Joi.string().valid(`select`, `textarea`, `rich-text`, `markdown`, `code`),
278
278
  choices: Joi.when(`format`, {
279
279
  is: `select`,
280
280
  then: choicesSchema(Joi.string()).required(),
281
281
  otherwise: Joi.forbidden(),
282
282
  }),
283
+ language: Joi.when(`format`, {
284
+ is: `code`,
285
+ then: Joi.string(),
286
+ otherwise: Joi.forbidden(),
287
+ }),
283
288
  })
284
289
  );
285
290
 
@@ -507,11 +512,15 @@ const getSimpleFieldSchema = (field: Field) => {
507
512
  typeSchema = Joi.number();
508
513
  if (field.min) { typeSchema = (typeSchema as NumberSchema).min(field.min); }
509
514
  if (field.max) { typeSchema = (typeSchema as NumberSchema).max(field.max); }
510
- if (field.float) {
511
- typeSchema = (typeSchema as NumberSchema).precision(field.decimals || 2);
512
- } else {
513
- typeSchema = (typeSchema as NumberSchema).precision(0);
515
+ // don't check precision if float is not set
516
+ if (typeof field.float === `boolean`) {
517
+ if (field.float) {
518
+ typeSchema = (typeSchema as NumberSchema).precision(field.decimals || 2);
519
+ } else {
520
+ typeSchema = (typeSchema as NumberSchema).precision(0);
521
+ }
514
522
  }
523
+
515
524
  break;
516
525
  case `dict`:
517
526
  if (field.items) { throw new Error(`No simple field`); }
@@ -55,7 +55,7 @@ const commandSchema = Joi.alternatives(
55
55
  );
56
56
 
57
57
  const API_SOURCES = (provider: Provider, configuration: Protocol.SourcesConfiguration, context: { organization: string, workspace: number }): SourceFunctions => ({
58
- register: async (source, data) => {
58
+ register: async (source, sandbox, data) => {
59
59
  try {
60
60
  const { data: [created] } = await axios.post(`/api/v1/sources`, {
61
61
  organization: context.organization,
@@ -63,6 +63,7 @@ const API_SOURCES = (provider: Provider, configuration: Protocol.SourcesConfigur
63
63
  provider: provider.id,
64
64
  version: provider.version,
65
65
  source: source,
66
+ sandbox: sandbox,
66
67
  data: data,
67
68
  created_date: moment().format(`YYYY-MM-DDTHH:mm:ssZ`),
68
69
  }, {
@@ -75,7 +76,7 @@ const API_SOURCES = (provider: Provider, configuration: Protocol.SourcesConfigur
75
76
  return { id: created.uuid };
76
77
  } catch (e) { throw e; }
77
78
  },
78
- unregister: async (source, id) => {
79
+ unregister: async (source, sandbox, id) => {
79
80
  try {
80
81
  const { data: [get] } = await axios.post(`/api/v1/sources/list`, {
81
82
  organization: context.organization,
@@ -83,6 +84,7 @@ const API_SOURCES = (provider: Provider, configuration: Protocol.SourcesConfigur
83
84
  provider: provider.id,
84
85
  version: provider.version,
85
86
  source: source,
87
+ sandbox: sandbox,
86
88
  uuid: id,
87
89
  }, {
88
90
  baseURL: configuration.host,
@@ -100,7 +102,7 @@ const API_SOURCES = (provider: Provider, configuration: Protocol.SourcesConfigur
100
102
  });
101
103
  } catch (e) { throw e; }
102
104
  },
103
- consume: async (source) => {
105
+ consume: async (source, sandbox) => {
104
106
  try {
105
107
  const { data: sources } = await axios.post(`/api/v1/sources/list`, {
106
108
  organization: context.organization,
@@ -108,6 +110,7 @@ const API_SOURCES = (provider: Provider, configuration: Protocol.SourcesConfigur
108
110
  provider: provider.id,
109
111
  version: provider.version,
110
112
  source: source,
113
+ sandbox: sandbox,
111
114
  }, {
112
115
  baseURL: configuration.host,
113
116
  headers: {
@@ -15,4 +15,6 @@ export type DeepPartial<T extends Record<string, any>> = {
15
15
  export type AsyncReturnType<T extends (...args: any[]) => any> =
16
16
  T extends (...args: any[]) => Promise<infer U> ? U :
17
17
  T extends (...args: any[]) => infer U ? U :
18
- any;
18
+ any;
19
+
20
+ export type OneOrArray<T> = T | T[];