@beseif-solutions/prow-core 0.3.9 → 0.3.11

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
@@ -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
- type SyncOrAsync<T> = T | Promise<T>;
6
+ import { SourceConfig } from "./entities/source";
7
7
  export type SourceFunctions = {
8
- register: <T>(source: string, sandbox: boolean, data: T) => SyncOrAsync<{
8
+ register: <SC extends SourceConfig = SourceConfig>(source: SC[`id`], sandbox: boolean, data: SC[`fields`]) => Promise<{
9
9
  id: string;
10
10
  }>;
11
- consume: <T>(source: string, sandbox: boolean) => SyncOrAsync<{
11
+ consume: <SC extends SourceConfig = SourceConfig>(source: SC[`id`], sandbox: boolean) => Promise<{
12
12
  id: string;
13
- data: T;
13
+ data: SC[`fields`];
14
14
  }[]>;
15
- unregister: (source: string, sandbox: boolean, id: string) => SyncOrAsync<void>;
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;
@@ -20,7 +20,7 @@ export type Core = {
20
20
  lodash: lodash.LoDashStatic;
21
21
  env: Record<string, any>;
22
22
  joi: Joi.Root;
23
- sources: SourceFunctions;
23
+ sources?: SourceFunctions;
24
24
  t: T;
25
25
  };
26
26
  type CoreOptions = {
@@ -14,9 +14,11 @@ type Configuration<Config extends CoreConfig> = ({
14
14
  credentials: Config[`credentials`];
15
15
  }));
16
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`>;
17
+ type CommonConfig = Pick<CoreConfig, `credentials`> & {
18
+ id?: string;
19
+ };
18
20
  export type Common<Config extends CommonConfig = {}> = {
19
- id: string;
21
+ id: Config[`id`] extends string ? Config[`id`] : string;
20
22
  helpers?: Record<string, CoreFunction<{
21
23
  credentials: Config[`credentials`];
22
24
  inputs: any;
@@ -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 Source = Common & {
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[];
package/dist/index.d.ts CHANGED
@@ -5,6 +5,6 @@ export { Action, actionOutputSchema, actionSchema, AsyncAction, Event, eventSche
5
5
  export { Provider, providerSchema } from './entities/provider';
6
6
  export { Source } from './entities/source';
7
7
  export { alter, Condition, extract, Field, fieldSchema, fieldsSchema, File, SelectFieldChoice, validate, ValidationResult } from './minified-utils/fields';
8
- export { i18n, LocalizedField, LocalizedProperties, localizeFields, localizeGroup, localizeInputs, localizeOutputs, localizeProperties } from './minified-utils/locales';
8
+ export { DEFAULT_LOCALE, 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';
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.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;
3
+ exports.Protocol = exports.Properties = exports.localizeProperties = exports.localizeOutputs = exports.localizeInputs = exports.localizeGroup = exports.localizeFields = exports.i18n = exports.DEFAULT_LOCALE = 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");
@@ -28,6 +28,7 @@ Object.defineProperty(exports, "fieldSchema", { enumerable: true, get: function
28
28
  Object.defineProperty(exports, "fieldsSchema", { enumerable: true, get: function () { return fields_1.fieldsSchema; } });
29
29
  Object.defineProperty(exports, "validate", { enumerable: true, get: function () { return fields_1.validate; } });
30
30
  var locales_1 = require("./minified-utils/locales");
31
+ Object.defineProperty(exports, "DEFAULT_LOCALE", { enumerable: true, get: function () { return locales_1.DEFAULT_LOCALE; } });
31
32
  Object.defineProperty(exports, "i18n", { enumerable: true, get: function () { return locales_1.i18n; } });
32
33
  Object.defineProperty(exports, "localizeFields", { enumerable: true, get: function () { return locales_1.localizeFields; } });
33
34
  Object.defineProperty(exports, "localizeGroup", { enumerable: true, get: function () { return locales_1.localizeGroup; } });
@@ -11,10 +11,13 @@ export type LocalizedField = {
11
11
  export type LocalizedProperties = {
12
12
  name: string;
13
13
  description: string;
14
+ help?: Record<string, string>;
14
15
  };
15
16
  type TOptions = {
16
17
  fallback?: boolean;
18
+ optional?: boolean;
17
19
  };
20
+ export declare const DEFAULT_LOCALE = "en";
18
21
  export declare const validateDirectory: (directory: string) => boolean;
19
22
  type Common = {
20
23
  locale?: string;
@@ -27,7 +30,7 @@ export type FromDirectory = Common & {
27
30
  locale?: string;
28
31
  write?: boolean;
29
32
  };
30
- export type T = (code: string, opts?: TOptions) => string;
33
+ export type T = <S = string>(code: string, opts?: TOptions) => S;
31
34
  export declare const i18n: (options: FromCatalog | FromDirectory) => {
32
35
  t: T;
33
36
  i18n: I18n.I18n;
@@ -3,12 +3,12 @@ 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.localizeOutputs = exports.localizeInputs = exports.localizeGroup = exports.localizeProperties = exports.localizeFields = exports.i18n = exports.validateDirectory = void 0;
6
+ exports.localizeOutputs = exports.localizeInputs = exports.localizeGroup = exports.localizeProperties = exports.localizeFields = exports.i18n = exports.validateDirectory = exports.DEFAULT_LOCALE = void 0;
7
7
  const i18n_1 = __importDefault(require("i18n"));
8
8
  const lodash_1 = __importDefault(require("lodash"));
9
9
  const fs_1 = __importDefault(require("fs"));
10
10
  const path_1 = __importDefault(require("path"));
11
- const DEFAULT_LOCALE = `en`;
11
+ exports.DEFAULT_LOCALE = `en`;
12
12
  const validateDirectory = (directory) => {
13
13
  try {
14
14
  if (!fs_1.default.existsSync(directory)) {
@@ -31,47 +31,57 @@ exports.validateDirectory = validateDirectory;
31
31
  const i18n = (options) => {
32
32
  try {
33
33
  const common = {
34
- defaultLocale: DEFAULT_LOCALE,
34
+ defaultLocale: exports.DEFAULT_LOCALE,
35
35
  objectNotation: true,
36
36
  autoReload: false,
37
37
  missingKeyFn: () => ``,
38
38
  };
39
- const requestedLocale = options.locale || DEFAULT_LOCALE;
40
- let i18nInstance;
39
+ const requestedLocale = options.locale || exports.DEFAULT_LOCALE;
40
+ let configuration;
41
41
  let activeLocale;
42
42
  if (`directory` in options) {
43
43
  if (!(0, exports.validateDirectory)(options.directory)) {
44
44
  throw new Error(`Invalid directory: ${options.directory}`);
45
45
  }
46
46
  const availableLocales = fs_1.default.readdirSync(options.directory).map((file) => path_1.default.basename(file, path_1.default.extname(file)));
47
- activeLocale = availableLocales.includes(requestedLocale) ? requestedLocale : DEFAULT_LOCALE;
48
- i18nInstance = new i18n_1.default.I18n({
47
+ activeLocale = availableLocales.includes(requestedLocale) ? requestedLocale : exports.DEFAULT_LOCALE;
48
+ configuration = {
49
49
  ...common,
50
50
  locales: availableLocales,
51
51
  directory: options.directory,
52
52
  updateFiles: options.write,
53
53
  syncFiles: true,
54
- });
54
+ };
55
55
  }
56
56
  else if (`catalog` in options) {
57
57
  activeLocale = requestedLocale;
58
- i18nInstance = new i18n_1.default.I18n({
58
+ configuration = {
59
59
  ...common,
60
60
  locales: [requestedLocale],
61
61
  staticCatalog: {
62
62
  [requestedLocale]: options.catalog,
63
63
  },
64
- });
64
+ };
65
65
  }
66
66
  else {
67
67
  throw new Error(`Invalid options provided for i18n function`);
68
68
  }
69
+ const i18nInstance = new i18n_1.default.I18n(configuration);
69
70
  i18nInstance.setLocale(activeLocale);
70
71
  return {
71
72
  t: (code, opts = {}) => {
73
+ if (opts.optional) {
74
+ i18nInstance.configure({
75
+ ...configuration,
76
+ missingKeyFn: () => undefined,
77
+ });
78
+ }
72
79
  let response = i18nInstance.__(code);
73
80
  if (!response && opts.fallback) {
74
- response = i18nInstance.__({ phrase: code, locale: DEFAULT_LOCALE });
81
+ response = i18nInstance.__({ phrase: code, locale: exports.DEFAULT_LOCALE });
82
+ }
83
+ if (opts.optional) {
84
+ i18nInstance.configure(configuration);
75
85
  }
76
86
  return response;
77
87
  },
@@ -107,10 +117,14 @@ const localizeFields = (t, element) => {
107
117
  return response;
108
118
  };
109
119
  exports.localizeFields = localizeFields;
110
- const localizeProperties = (t, element) => ({
111
- name: t(`${element.id}.name`, { fallback: true }),
112
- description: t(`${element.id}.description`),
113
- });
120
+ const localizeProperties = (t, element) => {
121
+ const help = t(`${element.id}.help`, { fallback: true, optional: true });
122
+ return {
123
+ name: t(`${element.id}.name`, { fallback: true }),
124
+ description: t(`${element.id}.description`),
125
+ ...help && { help: help },
126
+ };
127
+ };
114
128
  exports.localizeProperties = localizeProperties;
115
129
  const localizeGroup = (t, element) => ({
116
130
  name: t(`ui.groups.${element.ui.group}.name`, { fallback: true }),
@@ -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
- register: async (source, sandbox, data) => {
50
- try {
51
- const { data: [created] } = await axios_1.default.post(`/api/v1/sources`, {
52
- organization: context.organization,
53
- workspace: context.workspace,
54
- provider: provider.id,
55
- version: provider.version,
56
- source: source,
57
- sandbox: sandbox,
58
- data: data,
59
- created_date: (0, moment_timezone_1.default)().format(`YYYY-MM-DDTHH:mm:ssZ`),
60
- }, {
61
- baseURL: configuration.host,
62
- headers: {
63
- "X-Internal-Token": configuration.token,
64
- },
65
- });
66
- if (!created || !created.uuid) {
67
- throw new Error(`Source registration failed`);
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
- return { id: created.uuid };
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
- await axios_1.default.delete(`/api/v1/sources/${get.id}`, {
95
- baseURL: configuration.host,
96
- headers: {
97
- "X-Internal-Token": configuration.token,
98
- },
99
- });
100
- }
101
- catch (e) {
102
- throw e;
103
- }
104
- },
105
- consume: async (source, sandbox) => {
106
- try {
107
- const { data: sources } = await axios_1.default.post(`/api/v1/sources/list`, {
108
- organization: context.organization,
109
- workspace: context.workspace,
110
- provider: provider.id,
111
- version: provider.version,
112
- source: source,
113
- sandbox: sandbox,
114
- }, {
115
- baseURL: configuration.host,
116
- headers: {
117
- "X-Internal-Token": configuration.token,
118
- },
119
- });
120
- return sources.map((s) => ({
121
- id: s.uuid,
122
- data: s.data,
123
- }));
124
- }
125
- catch (e) {
126
- throw e;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beseif-solutions/prow-core",
3
- "version": "0.3.9",
3
+ "version": "0.3.11",
4
4
  "description": "Prow core functionalities and classes",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
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: <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>,
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 = {
@@ -30,7 +29,7 @@ export type Core = {
30
29
  lodash: lodash.LoDashStatic,
31
30
  env: Record<string, any>,
32
31
  joi: Joi.Root,
33
- sources: SourceFunctions,
32
+ sources?: SourceFunctions,
34
33
  t: T,
35
34
  };
36
35
 
@@ -26,10 +26,10 @@ export type CoreFunction<Config extends CoreConfig = {}> =
26
26
  ((core: Core, configuration: Configuration<Config>) => Promise<Config[`outputs`]>)
27
27
  | ((core: Core, configuration: Configuration<Config>) => Config[`outputs`]);
28
28
 
29
- type CommonConfig = Pick<CoreConfig, `credentials`>;
29
+ type CommonConfig = Pick<CoreConfig, `credentials`> & { id?: string };
30
30
 
31
31
  export type Common<Config extends CommonConfig = {}> = {
32
- id: string,
32
+ id: Config[`id`] extends string ? Config[`id`] : string,
33
33
  helpers?: Record<string, CoreFunction<{ credentials: Config[`credentials`], inputs: any, outputs: any }>>,
34
34
  };
35
35
 
@@ -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 Source = Common & {
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[],
package/src/index.ts CHANGED
@@ -5,6 +5,6 @@ export { Action, actionOutputSchema, actionSchema, AsyncAction, Event, eventSche
5
5
  export { Provider, providerSchema } from './entities/provider';
6
6
  export { Source } from './entities/source';
7
7
  export { alter, Condition, extract, Field, fieldSchema, fieldsSchema, File, SelectFieldChoice, validate, ValidationResult } from './minified-utils/fields';
8
- export { i18n, LocalizedField, LocalizedProperties, localizeFields, localizeGroup, localizeInputs, localizeOutputs, localizeProperties } from './minified-utils/locales';
8
+ export { DEFAULT_LOCALE, 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';
@@ -16,11 +16,12 @@ export type LocalizedField = {
16
16
  export type LocalizedProperties = {
17
17
  name: string,
18
18
  description: string,
19
+ help?: Record<string, string>,
19
20
  };
20
21
 
21
- type TOptions = { fallback?: boolean };
22
+ type TOptions = { fallback?: boolean, optional?: boolean };
22
23
 
23
- const DEFAULT_LOCALE = `en`;
24
+ export const DEFAULT_LOCALE = `en`;
24
25
 
25
26
  export const validateDirectory = (directory: string): boolean => {
26
27
  try {
@@ -54,7 +55,7 @@ export type FromDirectory = Common & {
54
55
  write?: boolean,
55
56
  };
56
57
 
57
- export type T = (code: string, opts?: TOptions) => string;
58
+ export type T = <S = string>(code: string, opts?: TOptions) => S;
58
59
 
59
60
  export const i18n = (options: FromCatalog | FromDirectory): { t: T, i18n: I18n.I18n } => {
60
61
  try {
@@ -68,7 +69,7 @@ export const i18n = (options: FromCatalog | FromDirectory): { t: T, i18n: I18n.I
68
69
 
69
70
  const requestedLocale = options.locale || DEFAULT_LOCALE;
70
71
 
71
- let i18nInstance: I18n.I18n;
72
+ let configuration: I18n.ConfigurationOptions;
72
73
  let activeLocale: string;
73
74
  if (`directory` in options) {
74
75
  // validate directory
@@ -79,36 +80,50 @@ export const i18n = (options: FromCatalog | FromDirectory): { t: T, i18n: I18n.I
79
80
  activeLocale = availableLocales.includes(requestedLocale) ? requestedLocale : DEFAULT_LOCALE;
80
81
 
81
82
  // create i18n instance
82
- i18nInstance = new I18n.I18n({
83
+ configuration = {
83
84
  ...common,
84
85
  locales: availableLocales,
85
86
  directory: options.directory,
86
87
  updateFiles: options.write,
87
88
  syncFiles: true,
88
- });
89
+ };
89
90
  } else if (`catalog` in options) {
90
91
  // get active locale
91
92
  activeLocale = requestedLocale;
92
93
 
93
94
  // create i18n instance
94
- i18nInstance = new I18n.I18n({
95
+ configuration = {
95
96
  ...common,
96
97
  locales: [requestedLocale],
97
98
  staticCatalog: {
98
99
  [requestedLocale]: options.catalog,
99
100
  },
100
- });
101
+ };
101
102
  } else { throw new Error(`Invalid options provided for i18n function`); }
102
103
 
104
+ const i18nInstance = new I18n.I18n(configuration);
103
105
  i18nInstance.setLocale(activeLocale);
104
106
 
105
107
  return {
106
108
  t: (code: string, opts: TOptions = {}) => {
109
+
110
+ if (opts.optional) {
111
+ i18nInstance.configure({
112
+ ...configuration,
113
+ missingKeyFn: () => undefined,
114
+ });
115
+ }
116
+
107
117
  let response = i18nInstance.__(code);
108
118
  if (!response && opts.fallback) {
109
119
  response = i18nInstance.__({ phrase: code, locale: DEFAULT_LOCALE });
110
120
  }
111
- return response;
121
+
122
+ if (opts.optional) {
123
+ i18nInstance.configure(configuration);
124
+ }
125
+
126
+ return response as any;
112
127
  },
113
128
  i18n: i18nInstance,
114
129
  };
@@ -152,10 +167,14 @@ export const localizeFields = (
152
167
  export const localizeProperties = (
153
168
  t: ReturnType<typeof i18n>[`t`],
154
169
  element: Action | Trigger | Credentials | Provider | Source,
155
- ): LocalizedProperties => ({
156
- name: t(`${element.id}.name`, { fallback: true }),
157
- description: t(`${element.id}.description`),
158
- });
170
+ ): LocalizedProperties => {
171
+ const help = t<Record<string, any>>(`${element.id}.help`, { fallback: true, optional: true });
172
+ return {
173
+ name: t(`${element.id}.name`, { fallback: true }),
174
+ description: t(`${element.id}.description`),
175
+ ...help && { help: help },
176
+ };
177
+ };
159
178
 
160
179
  export const localizeGroup = (
161
180
  t: ReturnType<typeof i18n>[`t`],
@@ -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
- await axios.delete(`/api/v1/sources/${get.id}`, {
100
- baseURL: configuration.host,
101
- headers: {
102
- "X-Internal-Token": configuration.token,
103
- },
104
- });
105
- } catch (e) { throw e; }
106
- },
107
- consume: async (source, sandbox) => {
108
- try {
109
- const { data: sources } = await axios.post(`/api/v1/sources/list`, {
110
- organization: context.organization,
111
- workspace: context.workspace,
112
- provider: provider.id,
113
- version: provider.version,
114
- source: source,
115
- sandbox: sandbox,
116
- }, {
117
- baseURL: configuration.host,
118
- headers: {
119
- "X-Internal-Token": configuration.token,
120
- },
121
- });
122
- return sources.map((s) => ({
123
- id: s.uuid,
124
- data: s.data,
125
- }));
126
- } catch (e) { throw e; }
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