@beseif-solutions/prow-core 0.0.39 → 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.
@@ -3,23 +3,23 @@ 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.extract = exports.validate = exports.fieldsSchema = exports.fieldSchema = void 0;
6
+ exports.extract = exports.validate = exports.alter = exports.fieldsSchema = exports.fieldSchema = void 0;
7
7
  const joi_1 = __importDefault(require("joi"));
8
8
  const lodash_1 = __importDefault(require("lodash"));
9
9
  const moment_timezone_1 = __importDefault(require("moment-timezone"));
10
10
  const context_1 = __importDefault(require("./context"));
11
11
  const where_1 = require("./where");
12
12
  const conditionSchema = () => joi_1.default.object({
13
- condition: joi_1.default.object(),
14
- overrides: joi_1.default.object(),
15
- show: joi_1.default.bool(),
16
- }).xor(`overrides`, `show`);
13
+ condition: joi_1.default.object().required(),
14
+ overrides: joi_1.default.object().required(),
15
+ });
17
16
  const commonFieldSchema = () => joi_1.default.object({
18
17
  key: joi_1.default.string().required(),
19
18
  altered_by: joi_1.default.array().items(conditionSchema()),
20
19
  disabled: joi_1.default.bool(),
21
20
  required: joi_1.default.bool(),
22
21
  as_password: joi_1.default.bool(),
22
+ show: joi_1.default.bool(),
23
23
  show_label: joi_1.default.bool().default(true),
24
24
  as_array: joi_1.default.bool(),
25
25
  array_min: joi_1.default.when(`as_array`, {
@@ -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()),
@@ -173,7 +178,7 @@ const fileReplacer = (field) => ({
173
178
  },
174
179
  ],
175
180
  default: field.default,
176
- ...lodash_1.default.pick(field, [`altered_by`, `disabled`, `required`, `as_password`, `show_label`, `as_array`, `array_min`, `array_max`, `array_length`]),
181
+ ...lodash_1.default.pick(field, [`altered_by`, `disabled`, `required`, `as_password`, `show`, `show_label`, `as_array`, `array_min`, `array_max`, `array_length`]),
177
182
  });
178
183
  const fileInputFieldSchema = () => joi_1.default.object({
179
184
  default: defaultSchema(fileSchema()),
@@ -235,6 +240,9 @@ const getSimpleFieldSchema = (field) => {
235
240
  switch (field.type) {
236
241
  case `any`:
237
242
  typeSchema = anySchema();
243
+ if (field.allow_nullish) {
244
+ typeSchema = typeSchema.allow(null, ``, 0, undefined);
245
+ }
238
246
  break;
239
247
  case `boolean`:
240
248
  typeSchema = joi_1.default.bool();
@@ -303,11 +311,13 @@ const getSimpleFieldSchema = (field) => {
303
311
  if (field.max) {
304
312
  typeSchema = typeSchema.max(field.max);
305
313
  }
306
- if (field.float) {
307
- typeSchema = typeSchema.precision(field.decimals || 2);
308
- }
309
- else {
310
- 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
+ }
311
321
  }
312
322
  break;
313
323
  case `dict`:
@@ -366,10 +376,13 @@ const getObjectFieldSchema = (field, items) => {
366
376
  return getGeneralSchema(field, schema);
367
377
  };
368
378
  const getGeneralSchema = (field, schema) => {
379
+ if (field.required) {
380
+ schema = schema.required();
381
+ }
369
382
  if (field.disabled) {
370
383
  schema = schema.forbidden();
371
384
  }
372
- return field.required ? schema.required() : schema;
385
+ return schema;
373
386
  };
374
387
  const convertPath = (parts) => parts.map((p, i) => typeof p === `string` ? (i === 0 ? p : `.${p}`) : `[${p}]`).join(``);
375
388
  const secure = async (field, validation) => field.as_password ? lodash_1.default.omit(validation, [`value`, `original`]) : validation;
@@ -389,9 +402,31 @@ const relative_condition = (condition, relative) => {
389
402
  throw e;
390
403
  }
391
404
  };
405
+ const alter = (field, relative, data) => {
406
+ const cloned = lodash_1.default.cloneDeep(field);
407
+ for (const alteration of cloned.altered_by) {
408
+ const condition = relative_condition(alteration.condition, relative);
409
+ const matches = (0, where_1.where)(data, [condition]);
410
+ if (matches) {
411
+ lodash_1.default.assign(cloned, alteration.overrides);
412
+ }
413
+ }
414
+ return cloned;
415
+ };
416
+ exports.alter = alter;
392
417
  const recursive_schema = async (field, data, options) => {
393
418
  try {
394
- const newField = field.type === `file` ? fileReplacer(field) : lodash_1.default.cloneDeep(field);
419
+ let newField = lodash_1.default.cloneDeep(field);
420
+ if (newField.altered_by?.length > 0) {
421
+ newField = (0, exports.alter)(newField, options.relative, data);
422
+ if (options.alter) {
423
+ delete newField.altered_by;
424
+ }
425
+ }
426
+ const alteredField = lodash_1.default.cloneDeep(newField);
427
+ if (newField.type === `file`) {
428
+ newField = fileReplacer(newField);
429
+ }
395
430
  const relativeKey = options.relative ?
396
431
  options.relative.endsWith(`]`) ?
397
432
  options.array ? options.relative : `${options.relative}.${newField.key}`
@@ -405,7 +440,7 @@ const recursive_schema = async (field, data, options) => {
405
440
  const itemSchemas = [];
406
441
  if (lodash_1.default.isArray(resolved)) {
407
442
  for (let i = 0; i < (resolved || []).length; i++) {
408
- const itemSchema = await recursive_schema(lodash_1.default.omit(newField, [`as_array`, `array_min`, `array_max`, `array_length`]), data, { relative: `${relativeKey}[${i}]`, array: true, context: options.context });
443
+ const { schema: itemSchema } = await recursive_schema(lodash_1.default.omit(newField, [`as_array`, `array_min`, `array_max`, `array_length`]), data, { alter: false, relative: `${relativeKey}[${i}]`, array: true, context: options.context });
409
444
  if (itemSchema) {
410
445
  itemSchemas.push(itemSchema);
411
446
  }
@@ -414,16 +449,17 @@ const recursive_schema = async (field, data, options) => {
414
449
  calculatedSchema = getArrayFieldSchema(newField, itemSchemas);
415
450
  }
416
451
  else if (newField.type === `dict` && newField.items) {
417
- const itemSchemas = [];
452
+ const items = [];
418
453
  if (lodash_1.default.isObject(resolved)) {
419
454
  for (const item of newField.items) {
420
- const itemSchema = await recursive_schema(item, data, { relative: relativeKey, context: options.context });
421
- if (itemSchema) {
422
- itemSchemas.push({ key: item.key, schema: itemSchema });
455
+ const recursive = await recursive_schema(item, data, { alter: options.alter && true, relative: relativeKey, context: options.context });
456
+ if (recursive) {
457
+ items.push({ key: item.key, schema: recursive.schema, field: recursive.field });
423
458
  }
424
459
  }
425
460
  }
426
- calculatedSchema = getObjectFieldSchema(newField, itemSchemas);
461
+ calculatedSchema = getObjectFieldSchema(newField, items);
462
+ newField.items = items.map((i) => i.field);
427
463
  }
428
464
  else {
429
465
  calculatedSchema = getSimpleFieldSchema(newField);
@@ -431,27 +467,14 @@ const recursive_schema = async (field, data, options) => {
431
467
  if (!calculatedSchema) {
432
468
  throw new Error(`Could not resolve schema for field ${newField.key}`);
433
469
  }
434
- if (newField.altered_by?.length > 0) {
435
- let hide = false;
436
- for (const alteration of newField.altered_by) {
437
- const condition = relative_condition(alteration.condition, options.relative);
438
- const matches = (0, where_1.where)(data, [condition]);
439
- if (matches) {
440
- if (`overrides` in alteration) {
441
- lodash_1.default.assign(newField, alteration.overrides);
442
- }
443
- else if (`show` in alteration) {
444
- hide = !alteration.show;
445
- }
446
- }
447
- }
448
- delete newField.altered_by;
449
- if (hide) {
450
- lodash_1.default.unset(data, relativeKey);
451
- return;
452
- }
470
+ if (typeof newField.show === `boolean` && !newField.show) {
471
+ lodash_1.default.unset(data, relativeKey);
472
+ return;
473
+ }
474
+ else if (newField.disabled) {
475
+ lodash_1.default.unset(data, relativeKey);
453
476
  }
454
- return calculatedSchema;
477
+ return { schema: calculatedSchema, field: field.type === `file` ? alteredField : newField };
455
478
  }
456
479
  catch (e) {
457
480
  throw e;
@@ -463,12 +486,15 @@ const validate_internal = async (fields, data, options) => {
463
486
  for (const field of fields) {
464
487
  const value = lodash_1.default.get(data, field.key, field.default);
465
488
  const cloned = lodash_1.default.cloneDeep(data);
466
- const schema = await recursive_schema(field, cloned, { context: options.context });
489
+ const recursive = await recursive_schema(field, cloned, { alter: true, context: options.context });
490
+ if (!recursive) {
491
+ continue;
492
+ }
467
493
  const resolved = lodash_1.default.get(cloned, field.key, field.default);
468
494
  let validation;
469
495
  let error;
470
496
  try {
471
- validation = await schema.validateAsync(resolved, { abortEarly: false });
497
+ validation = await recursive.schema.validateAsync(resolved, { abortEarly: false });
472
498
  }
473
499
  catch (e) {
474
500
  error = e;
@@ -495,7 +521,7 @@ const validate_internal = async (fields, data, options) => {
495
521
  }
496
522
  response.valid && (response.valid = error ? false : true);
497
523
  response.fields.push({
498
- ...field,
524
+ ...recursive.field,
499
525
  ...options.secure ? await secure(field, extended) : extended,
500
526
  });
501
527
  }
@@ -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.0.39",
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,
@@ -33,9 +34,18 @@ type EventConfig = Pick<CoreConfig, `credentials` | `outputs`> & {
33
34
  outputs: string[],
34
35
  },
35
36
  sources?: string[],
37
+ fields?: Record<string, any>,
36
38
  };
37
39
 
38
- type CommonEvents<Config extends EventConfig = {}> = Common<Config> & {
40
+ type SetupEventConfig = EventConfig & {
41
+ setup?: Record<string, any>,
42
+ };
43
+
44
+ type MemoryEventConfig = EventConfig & {
45
+ memory?: Record<string, any>,
46
+ };
47
+
48
+ type CommonEvents<Config extends EventConfig = { fields: Record<string, any> }> = Common<Config> & {
39
49
  model: `event`,
40
50
  categorization: {
41
51
  department: string,
@@ -59,75 +69,116 @@ export type Request = {
59
69
  body: any,
60
70
  };
61
71
 
62
- export type ImmediateTrigger<Config extends EventConfig = {}> = CommonEvents<Config> & {
72
+ export type ImmediateTrigger<Config extends SetupEventConfig = { fields: Record<string, any>, setup: Record<string, any> }> = CommonEvents<Config> & {
63
73
  type: `trigger`,
64
74
  immediate: true,
65
75
  outputs: [DefaultConnectableEvent<Config[`flags`][`outputs`][number]>],
66
76
  functions: {
67
77
  mount?: CoreFunction<{
68
78
  credentials: Config[`credentials`],
69
- inputs: { fields: Record<string, any>, link: string },
70
- outputs: { done: boolean, setup?: any },
79
+ inputs: { fields: Config[`fields`], link: string },
80
+ outputs: { done: boolean, setup?: Config[`setup`] },
71
81
  }>,
72
82
  unmount?: CoreFunction<{
73
83
  credentials: Config[`credentials`],
74
- inputs: { fields: Record<string, any>, link: string, setup?: any },
84
+ inputs: { fields: Config[`fields`], link: string, setup?: Config[`setup`] },
75
85
  outputs: { done: boolean },
76
86
  }>,
77
87
  challenge?: CoreFunction<{
78
88
  credentials: Config[`credentials`],
79
- inputs: { fields: Record<string, any>, link: string, request: Request, setup?: any },
89
+ inputs: { fields: Config[`fields`], link: string, request: Request, setup?: Config[`setup`] },
80
90
  outputs: { done: boolean, response?: any },
81
91
  }>,
82
92
  handle: CoreFunction<{
83
93
  credentials: Config[`credentials`],
84
- inputs: { fields: Record<string, any>, request: Request, setup?: any },
94
+ inputs: { fields: Config[`fields`], request: Request, setup?: Config[`setup`] },
85
95
  outputs: { records: Config[`outputs`][], flags: Partial<Record<Config[`flags`][`outputs`][number], true>> },
86
96
  }>,
87
97
  fire?: CoreFunction<{
88
98
  credentials: Config[`credentials`],
89
- inputs: { fields: Record<string, any>, link: string, setup?: any },
99
+ inputs: { fields: Config[`fields`], link: string, setup?: any },
90
100
  outputs: { done: boolean },
91
101
  }>,
92
102
  poll?: CoreFunction<{
93
103
  credentials: Config[`credentials`],
94
- inputs: { fields: Record<string, any>, last_schedule?: string, limit?: number },
104
+ inputs: { fields: Config[`fields`], last_schedule?: string, limit?: number },
95
105
  outputs: { records: Config[`outputs`][], flags: Partial<Record<Config[`flags`][`outputs`][number], true>> },
96
106
  }>,
97
107
  },
98
108
  };
99
109
 
100
- export type ScheduledTrigger<Config extends EventConfig = {}> = CommonEvents<Config> & {
110
+ export type ScheduledTrigger<Config extends EventConfig = { fields: Record<string, any> }> = CommonEvents<Config> & {
101
111
  type: `trigger`,
102
112
  immediate: false,
103
113
  outputs: [DefaultConnectableEvent<Config[`flags`][`outputs`][number]>],
104
114
  functions: {
105
115
  poll: CoreFunction<{
106
116
  credentials: Config[`credentials`],
107
- inputs: { fields: Record<string, any>, last_schedule?: string, limit?: number },
117
+ inputs: { fields: Config[`fields`], last_schedule?: string, limit?: number },
108
118
  outputs: { records: Config[`outputs`][], flags: Partial<Record<Config[`flags`][`outputs`][number], true>> },
109
119
  }>,
110
120
  },
111
121
  };
112
122
 
113
- export type Trigger<Config extends EventConfig = {}> =
123
+ export type Trigger<Config extends EventConfig = { fields: Record<string, any> }> =
114
124
  | ImmediateTrigger<Config>
115
125
  | ScheduledTrigger<Config>;
116
126
 
117
- export type Action<Config extends EventConfig = {}> = 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> & {
118
135
  type: `action`,
119
136
  inputs: [DefaultConnectableEvent<Config[`flags`][`inputs`][number]>, ...AdditionalConnectableEvent<Config[`flags`][`inputs`][number]>[]],
120
137
  outputs: [DefaultConnectableEvent<Config[`flags`][`outputs`][number]>, ...(AdditionalConnectableEvent<Config[`flags`][`outputs`][number]> | ErrorConnectableEvent<Config[`flags`][`outputs`][number]>)[]],
121
138
  functions: {
122
139
  execute: CoreFunction<{
123
140
  credentials: Config[`credentials`],
124
- inputs: { fields: Record<string, any>, flags: Partial<Record<Config[`flags`][`inputs`][number], true>> },
125
- outputs: { output: Config[`outputs`], flags: Partial<Record<Config[`flags`][`outputs`][number], true>> },
141
+ inputs: { fields: Config[`fields`], flags: Partial<Record<Config[`flags`][`inputs`][number], true>>, memory?: Config[`memory`] },
142
+ outputs: StandardOutput<Config> | MemoryOutput<Config>,
126
143
  }>,
127
144
  },
128
145
  };
129
146
 
130
- export type Event<Config extends EventConfig = {}> =
147
+ export type AsyncAction<Config extends SetupEventConfig = { fields: Record<string, any>, setup: Record<string, any> }> = CommonEvents<Config> & {
148
+ type: `action`,
149
+ inputs: [DefaultConnectableEvent<Config[`flags`][`inputs`][number]>, ...AdditionalConnectableEvent<Config[`flags`][`inputs`][number]>[]],
150
+ outputs: [DefaultConnectableEvent<Config[`flags`][`outputs`][number]>, ...(AdditionalConnectableEvent<Config[`flags`][`outputs`][number]> | ErrorConnectableEvent<Config[`flags`][`outputs`][number]>)[]],
151
+ async: true,
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
+ }>,
163
+ execute: CoreFunction<{
164
+ credentials: Config[`credentials`],
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 },
177
+ }>,
178
+ },
179
+ };
180
+
181
+ export type Event<Config extends EventConfig = { fields: Record<string, any> }> =
131
182
  | Action<Config>
132
183
  | Trigger<Config>;
133
184
 
@@ -218,7 +269,7 @@ export const immediateTriggerSchema = () =>
218
269
  export const triggerSchema = () =>
219
270
  Joi.alternatives(scheduledTriggerSchema(), immediateTriggerSchema());
220
271
 
221
- export const actionSchema = () =>
272
+ export const syncActionSchema = () =>
222
273
  Joi.object({
223
274
  type: Joi.valid(`action`).required(),
224
275
  inputs: Joi.array()
@@ -243,6 +294,39 @@ export const actionSchema = () =>
243
294
  .concat(commonSchema())
244
295
  .concat(commonEventsSchema());
245
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
+
246
330
  export const eventSchema = () =>
247
331
  Joi.alternatives(triggerSchema(), actionSchema());
248
332
 
@@ -256,12 +340,25 @@ export const triggerOutputSchema = () =>
256
340
  });
257
341
 
258
342
  export const actionOutputSchema = () =>
259
- Joi.object({
260
- output: Joi.alternatives(
261
- Joi.array(),
262
- Joi.object(),
263
- ).required(),
264
- flags: Joi.object()
265
- .pattern(Joi.string(), Joi.valid(true))
266
- .required(),
267
- });
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,10 +1,10 @@
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
- export { extract, Field, fieldSchema, fieldsSchema, File, SelectFieldChoice, validate, ValidationResult } from './minified-utils/fields';
7
+ export { alter, extract, Field, fieldSchema, fieldsSchema, File, SelectFieldChoice, validate, ValidationResult } from './minified-utils/fields';
8
8
  export { i18n, LocalizedField, LocalizedProperties, localizeFields, localizeGroup, localizeInputs, localizeOutputs, localizeProperties } from './minified-utils/locales';
9
9
  export { Properties } from './minified-utils/properties';
10
10
  export { Protocol } from './minified-utils/protocol';