@beseif-solutions/prow-core 0.3.10 → 0.3.12

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/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; } });
@@ -102,8 +102,10 @@ export type SelectFieldChoice<Values = string | number | boolean | File, Extend
102
102
  key: string;
103
103
  value: Values;
104
104
  } & Extend;
105
+ declare const RICH_TEXT_PROPS: readonly ["bold", "italic", "underline", "strike", "code", "heading", "blockquote", "codeBlock", "bulletList", "orderedList", "horizontalRule", "hardBreak"];
105
106
  type CustomDisplayTextField = {
106
107
  format: `textarea` | `rich-text` | `markdown`;
108
+ props?: typeof RICH_TEXT_PROPS[number][];
107
109
  };
108
110
  type IDETextField = {
109
111
  format: `code`;
@@ -9,6 +9,20 @@ 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
+ const RICH_TEXT_PROPS = [
13
+ `bold`,
14
+ `italic`,
15
+ `underline`,
16
+ `strike`,
17
+ `code`,
18
+ `heading`,
19
+ `blockquote`,
20
+ `codeBlock`,
21
+ `bulletList`,
22
+ `orderedList`,
23
+ `horizontalRule`,
24
+ `hardBreak`,
25
+ ];
12
26
  const conditionSchema = () => joi_1.default.object({
13
27
  condition: joi_1.default.object().required(),
14
28
  overrides: joi_1.default.object().required(),
@@ -93,6 +107,11 @@ const stringInputFieldSchema = () => joi_1.default.object({
93
107
  then: joi_1.default.string(),
94
108
  otherwise: joi_1.default.forbidden(),
95
109
  }),
110
+ props: joi_1.default.when(`format`, {
111
+ is: joi_1.default.valid(`textarea`, `markdown`, `rich-text`),
112
+ then: joi_1.default.array().items(joi_1.default.string().valid(...RICH_TEXT_PROPS)),
113
+ otherwise: joi_1.default.forbidden(),
114
+ }),
96
115
  }));
97
116
  const numberInputFieldSchema = () => joi_1.default.object({
98
117
  default: defaultSchema(joi_1.default.number()),
@@ -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 }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beseif-solutions/prow-core",
3
- "version": "0.3.10",
3
+ "version": "0.3.12",
4
4
  "description": "Prow core functionalities and classes",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
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';
@@ -156,8 +156,24 @@ export type SelectFieldChoice<Values = string | number | boolean | File, Extend
156
156
  } & Extend;
157
157
 
158
158
  /* custom display configuration */
159
+ const RICH_TEXT_PROPS = [
160
+ `bold`,
161
+ `italic`,
162
+ `underline`,
163
+ `strike`,
164
+ `code`,
165
+ `heading`,
166
+ `blockquote`,
167
+ `codeBlock`,
168
+ `bulletList`,
169
+ `orderedList`,
170
+ `horizontalRule`,
171
+ `hardBreak`,
172
+ ] as const;
173
+
159
174
  type CustomDisplayTextField = {
160
175
  format: `textarea` | `rich-text` | `markdown`,
176
+ props?: typeof RICH_TEXT_PROPS[number][];
161
177
  };
162
178
 
163
179
  type IDETextField = {
@@ -291,6 +307,13 @@ const stringInputFieldSchema = () =>
291
307
  then: Joi.string(),
292
308
  otherwise: Joi.forbidden(),
293
309
  }),
310
+ props: Joi.when(`format`, {
311
+ is: Joi.valid(`textarea`, `markdown`, `rich-text`),
312
+ then: Joi.array().items(
313
+ Joi.string().valid(...RICH_TEXT_PROPS)
314
+ ),
315
+ otherwise: Joi.forbidden(),
316
+ }),
294
317
  })
295
318
  );
296
319
 
@@ -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`],