@awell-health/awell-extensions 1.0.154 → 1.0.156
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/extensions/markdown.json +3 -3
- package/dist/extensions/transform/index.js +1 -0
- package/dist/extensions/transform/index.js.map +1 -1
- package/dist/extensions/transform/v1/actions/index.d.ts +1 -0
- package/dist/extensions/transform/v1/actions/index.js +3 -1
- package/dist/extensions/transform/v1/actions/index.js.map +1 -1
- package/dist/extensions/transform/v1/actions/parseNumberToTextWithDictionary/config/dataPoints.d.ts +6 -0
- package/dist/extensions/transform/v1/actions/parseNumberToTextWithDictionary/config/dataPoints.js +10 -0
- package/dist/extensions/transform/v1/actions/parseNumberToTextWithDictionary/config/dataPoints.js.map +1 -0
- package/dist/extensions/transform/v1/actions/parseNumberToTextWithDictionary/config/fields.d.ts +29 -0
- package/dist/extensions/transform/v1/actions/parseNumberToTextWithDictionary/config/fields.js +43 -0
- package/dist/extensions/transform/v1/actions/parseNumberToTextWithDictionary/config/fields.js.map +1 -0
- package/dist/extensions/transform/v1/actions/parseNumberToTextWithDictionary/config/index.d.ts +2 -0
- package/dist/extensions/transform/v1/actions/parseNumberToTextWithDictionary/config/index.js +9 -0
- package/dist/extensions/transform/v1/actions/parseNumberToTextWithDictionary/config/index.js.map +1 -0
- package/dist/extensions/transform/v1/actions/parseNumberToTextWithDictionary/index.d.ts +1 -0
- package/dist/extensions/transform/v1/actions/parseNumberToTextWithDictionary/index.js +6 -0
- package/dist/extensions/transform/v1/actions/parseNumberToTextWithDictionary/index.js.map +1 -0
- package/dist/extensions/transform/v1/actions/parseNumberToTextWithDictionary/parseNumberToTextWithDictionary.d.ts +4 -0
- package/dist/extensions/transform/v1/actions/parseNumberToTextWithDictionary/parseNumberToTextWithDictionary.js +74 -0
- package/dist/extensions/transform/v1/actions/parseNumberToTextWithDictionary/parseNumberToTextWithDictionary.js.map +1 -0
- package/dist/extensions/transform/v1/actions/parseNumberToTextWithDictionary/parseNumberToTextWithDictionary.test.d.ts +1 -0
- package/dist/extensions/transform/v1/actions/parseNumberToTextWithDictionary/parseNumberToTextWithDictionary.test.js +93 -0
- package/dist/extensions/transform/v1/actions/parseNumberToTextWithDictionary/parseNumberToTextWithDictionary.test.js.map +1 -0
- package/package.json +1 -1
@@ -28,7 +28,7 @@
|
|
28
28
|
"changelog": "# CM.com changelog\n"
|
29
29
|
},
|
30
30
|
"collectData": {
|
31
|
-
"readme": "---\ntitle: Advanced data collection\ndescription: Collect data from your users using a variety of input types and data sources\n---\n\nThis extension allows you to collect data from your users using a variety of more advanced input types and data sources.\n\n## Extension settings\n\nIn order to set up this extension, no settings are required.\n\n## Custom Actions\n\n###
|
31
|
+
"readme": "---\ntitle: Advanced data collection\ndescription: Collect data from your users using a variety of input types and data sources\n---\n\nThis extension allows you to collect data from your users using a variety of more advanced input types and data sources.\n\n## Extension settings\n\nIn order to set up this extension, no settings are required.\n\n## Custom Actions\n\n### Dynamic choice selector\n\nStandard select questions in Awell forms have a discrete set of choices to select from that are defined at the time that the form is created. If the list of choices to present to your responders isn't known at the time the form is being built, or changes often, this action allows you to load choices dynamically from a remote data source.\n\nDynamically-loaded choices must adhere to the following format in a list form (i.e. an array):\n\n```json\n{\n \"id\": \"unique-id\",\n \"label\": \"Choice label\",\n \"value\": \"Choice value\"\n}\n```\n\nAdditionally, you can specify a free text search field (`Options - Search query param` field) to allow users to search through the choices. This is optional but highly recommended. If not specified, the choices will be fetched on question load and presented in a static list that cannot be filtered.\n\nAs an example, using the endpoint `https://example.com/choices` with a query parameter `search` (e.g. `https://example.com/choices?search=QUERY` where `QUERY` is whatever the user typed into the input), then the API is expected to return the choices based on that match the search term.\n\nWe recommend that your search logic returns an _alphabetically-sorted_ list of all options where the _lowercase_ label names _contain_ the _lowercase_ search term.\n\n```js\n// Example search logic\nconst searchTerm = req.query.search\nconst results = []\n\noptions.forEach((option) => {\n if (option.label.toLowerCase().includes(searchTerm.toLowerCase())) {\n results.push({\n label: option.label,\n value: option.value,\n id: option.id,\n })\n }\n})\n\nconst sortedResults = results.sort((a, b) => a.label.localeCompare(b.label))\nres.json(results)\n```\n",
|
32
32
|
"changelog": "# Collect Data changelog\n"
|
33
33
|
},
|
34
34
|
"docuSign": {
|
@@ -96,8 +96,8 @@
|
|
96
96
|
"changelog": "# Sendgrid changelog\n\n## July 7, 2023\n\nAdded \"Add Email to Suppression Lists\" and \"Remove Email from Suppression Lists\" actions.\n\n## July 15, 2023\n\nUpdated \"Add or Update Contact\" acction to create a datapoint of the Job ID.\n\nAdded \"Check Import Status\" action.\n\n## July 27, 2023\n\nAdds \"Finished At\" data point to the importStatus action."
|
97
97
|
},
|
98
98
|
"transform": {
|
99
|
-
"readme": "---\ntitle: Transform\ndescription: Transform is an extension with utility functions that allows you to transform or parse data to a format of your liking\n---\n\n# Transform\n\nTransform is an extension on Awell's Marketplace with utility functions that allows you to transform data from one type to another. These functions are particularly useful e.g. when system A works with IDs that are numbers but system B works with IDs that are strings.\n\n## Custom Actions\n\n### Parse number to text\n\nTransform or parse a number to text (string).\n\n### Parse text to number\n\nTransform or parse text (string) to a number. Will return NaN if the input data is not an actual number.\n\n### Parse date to unix timestamp\n\nTransform or parse a date to a unix timestamp.\n\n### Parse unix timestamp to unix date\n\nTransform or parse a unix timestamp to a date.\n\n",
|
100
|
-
"changelog": "# Transform changelog"
|
99
|
+
"readme": "---\ntitle: Transform\ndescription: Transform is an extension with utility functions that allows you to transform or parse data to a format of your liking\n---\n\n# Transform\n\nTransform is an extension on Awell's Marketplace with utility functions that allows you to transform data from one type to another. These functions are particularly useful e.g. when system A works with IDs that are numbers but system B works with IDs that are strings.\n\n## Custom Actions\n\n### Parse number to text\n\nTransform or parse a number to text (string).\n\n### Parse text to number\n\nTransform or parse text (string) to a number. Will return NaN if the input data is not an actual number.\n\n### Parse date to unix timestamp\n\nTransform or parse a date to a unix timestamp.\n\n### Parse unix timestamp to unix date\n\nTransform or parse a unix timestamp to a date.\n\n## Parse number to text with dictionary\n\nTransform or parse a number to a string using a dictionary. Useful for when you have numeric data points but want to map them to strings based on a dictionary. When the action is called with a number that does not have a corresponding mapping in the provided dictionary, it simply returns the number itself as a string. \n\nThe dictionary should be structured in JSON format with string keys mapping to string values. Each key represents a number (as a string), and each value is the corresponding text representation.\n\n**Example:**\n```json\n{\n \"0\": \"Male\",\n \"1\": \"Female\",\n \"2\": \"Not known\",\n // ... other number mappings ...\n}\n\n",
|
100
|
+
"changelog": "# Transform changelog\n\n## January 2024\n\n- Added \"Parse number to text with dictionary\" action"
|
101
101
|
},
|
102
102
|
"twilio": {
|
103
103
|
"readme": "---\ntitle: Twilio\ndescription: Twilio is a customer engagement platform used by hundreds of thousands of businesses and more than ten million developers worldwide to build unique, personalized experiences for their customers.\n---\n# Twilio\n\nTwilio is a customer engagement platform used by hundreds of thousands of businesses and more than ten million developers worldwide to build unique, personalized experiences for their customers.\n\nThey are known for democratizing channels like voice, text, chat, video, and email through APIs, making it easy for every organization to build meaningful interactions with customers on the channels they prefer.\n\n## Extension settings\n\nIn order to set up this extension, you will need:\n\n1. A Twilio API key or auth token which can be found in the Twilio console.\n2. Your account SID which can be found in the Twilio console.\n3. A phone number to send the message from. This must be a Twilio phone number that you own.\n\n## Custom Actions\n\n### Send SMS\n\nSend an SMS with Twilio to a recipient of your liking.\n",
|
@@ -18,6 +18,7 @@ exports.Transform = {
|
|
18
18
|
parseNumberToText: actions_1.parseNumberToText,
|
19
19
|
parseTextToNumber: actions_1.parseTextToNumber,
|
20
20
|
parseUnixTimestampToDate: actions_1.parseUnixTimestampToDate,
|
21
|
+
parseNumberToTextWithDictionary: actions_1.parseNumberToTextWithDictionary,
|
21
22
|
},
|
22
23
|
settings: settings_1.settings,
|
23
24
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../extensions/transform/index.ts"],"names":[],"mappings":";;;AACA,mEAAoE;AACpE,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../extensions/transform/index.ts"],"names":[],"mappings":";;;AACA,mEAAoE;AACpE,0CAMqB;AACrB,yCAAqC;AAExB,QAAA,SAAS,GAAc;IAClC,GAAG,EAAE,WAAW;IAChB,KAAK,EAAE,WAAW;IAClB,QAAQ,EACN,mLAAmL;IACrL,WAAW,EACT,qIAAqI;IACvI,QAAQ,EAAE,0BAAQ,CAAC,IAAI;IACvB,MAAM,EAAE;QACN,UAAU,EAAE,4BAAU,CAAC,KAAK;KAC7B;IACD,OAAO,EAAE;QACP,wBAAwB,EAAxB,kCAAwB;QACxB,iBAAiB,EAAjB,2BAAiB;QACjB,iBAAiB,EAAjB,2BAAiB;QACjB,wBAAwB,EAAxB,kCAAwB;QACxB,+BAA+B,EAA/B,yCAA+B;KAChC;IACD,QAAQ,EAAR,mBAAQ;CACT,CAAA"}
|
@@ -2,3 +2,4 @@ export { parseTextToNumber } from './parseTextToNumber';
|
|
2
2
|
export { parseDateToUnixTimestamp } from './parseDateToUnixTimestamp';
|
3
3
|
export { parseNumberToText } from './parseNumberToText';
|
4
4
|
export { parseUnixTimestampToDate } from './parseUnixTimestampToDate';
|
5
|
+
export { parseNumberToTextWithDictionary } from './parseNumberToTextWithDictionary';
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.parseUnixTimestampToDate = exports.parseNumberToText = exports.parseDateToUnixTimestamp = exports.parseTextToNumber = void 0;
|
3
|
+
exports.parseNumberToTextWithDictionary = exports.parseUnixTimestampToDate = exports.parseNumberToText = exports.parseDateToUnixTimestamp = exports.parseTextToNumber = void 0;
|
4
4
|
var parseTextToNumber_1 = require("./parseTextToNumber");
|
5
5
|
Object.defineProperty(exports, "parseTextToNumber", { enumerable: true, get: function () { return parseTextToNumber_1.parseTextToNumber; } });
|
6
6
|
var parseDateToUnixTimestamp_1 = require("./parseDateToUnixTimestamp");
|
@@ -9,4 +9,6 @@ var parseNumberToText_1 = require("./parseNumberToText");
|
|
9
9
|
Object.defineProperty(exports, "parseNumberToText", { enumerable: true, get: function () { return parseNumberToText_1.parseNumberToText; } });
|
10
10
|
var parseUnixTimestampToDate_1 = require("./parseUnixTimestampToDate");
|
11
11
|
Object.defineProperty(exports, "parseUnixTimestampToDate", { enumerable: true, get: function () { return parseUnixTimestampToDate_1.parseUnixTimestampToDate; } });
|
12
|
+
var parseNumberToTextWithDictionary_1 = require("./parseNumberToTextWithDictionary");
|
13
|
+
Object.defineProperty(exports, "parseNumberToTextWithDictionary", { enumerable: true, get: function () { return parseNumberToTextWithDictionary_1.parseNumberToTextWithDictionary; } });
|
12
14
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../extensions/transform/v1/actions/index.ts"],"names":[],"mappings":";;;AAAA,yDAAuD;AAA9C,sHAAA,iBAAiB,OAAA;AAC1B,uEAAqE;AAA5D,oIAAA,wBAAwB,OAAA;AACjC,yDAAuD;AAA9C,sHAAA,iBAAiB,OAAA;AAC1B,uEAAqE;AAA5D,oIAAA,wBAAwB,OAAA"}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../extensions/transform/v1/actions/index.ts"],"names":[],"mappings":";;;AAAA,yDAAuD;AAA9C,sHAAA,iBAAiB,OAAA;AAC1B,uEAAqE;AAA5D,oIAAA,wBAAwB,OAAA;AACjC,yDAAuD;AAA9C,sHAAA,iBAAiB,OAAA;AAC1B,uEAAqE;AAA5D,oIAAA,wBAAwB,OAAA;AACjC,qFAAmF;AAA1E,kJAAA,+BAA+B,OAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"dataPoints.js","sourceRoot":"","sources":["../../../../../../../extensions/transform/v1/actions/parseNumberToTextWithDictionary/config/dataPoints.ts"],"names":[],"mappings":";;;AAEa,QAAA,UAAU,GAAG;IACxB,IAAI,EAAE;QACJ,GAAG,EAAE,MAAM;QACX,SAAS,EAAE,QAAQ;KACpB;CAC4C,CAAA"}
|
package/dist/extensions/transform/v1/actions/parseNumberToTextWithDictionary/config/fields.d.ts
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import { FieldType } from '@awell-health/extensions-core';
|
3
|
+
export declare const fields: {
|
4
|
+
number: {
|
5
|
+
id: string;
|
6
|
+
label: string;
|
7
|
+
description: string;
|
8
|
+
type: FieldType.NUMERIC;
|
9
|
+
required: true;
|
10
|
+
};
|
11
|
+
dictionary: {
|
12
|
+
id: string;
|
13
|
+
label: string;
|
14
|
+
description: string;
|
15
|
+
type: FieldType.JSON;
|
16
|
+
required: true;
|
17
|
+
};
|
18
|
+
};
|
19
|
+
export declare const DictionarySchema: z.ZodEffects<z.ZodString, Record<string, any>, string>;
|
20
|
+
export declare const FieldsValidationSchema: z.ZodObject<{
|
21
|
+
number: z.ZodUnion<[z.ZodNumber, z.ZodNaN]>;
|
22
|
+
dictionary: z.ZodEffects<z.ZodString, Record<string, any>, string>;
|
23
|
+
}, "strip", z.ZodTypeAny, {
|
24
|
+
number: number;
|
25
|
+
dictionary: Record<string, any>;
|
26
|
+
}, {
|
27
|
+
number: number;
|
28
|
+
dictionary: string;
|
29
|
+
}>;
|
@@ -0,0 +1,43 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.FieldsValidationSchema = exports.DictionarySchema = exports.fields = void 0;
|
4
|
+
const zod_1 = require("zod");
|
5
|
+
const extensions_core_1 = require("@awell-health/extensions-core");
|
6
|
+
const lodash_1 = require("lodash");
|
7
|
+
exports.fields = {
|
8
|
+
number: {
|
9
|
+
id: 'number',
|
10
|
+
label: 'Number',
|
11
|
+
description: 'The number you want to parse to a text (string)',
|
12
|
+
type: extensions_core_1.FieldType.NUMERIC,
|
13
|
+
required: true,
|
14
|
+
},
|
15
|
+
dictionary: {
|
16
|
+
id: 'dictionary',
|
17
|
+
label: 'Dictionary',
|
18
|
+
description: 'A JSON dictionary where each string key represents a number and maps to a corresponding string/text value',
|
19
|
+
type: extensions_core_1.FieldType.JSON,
|
20
|
+
required: true,
|
21
|
+
},
|
22
|
+
};
|
23
|
+
exports.DictionarySchema = zod_1.z
|
24
|
+
.string()
|
25
|
+
.transform((dict, ctx) => {
|
26
|
+
if ((0, lodash_1.isNil)(dict) || (0, lodash_1.isEmpty)(dict))
|
27
|
+
return {};
|
28
|
+
try {
|
29
|
+
return JSON.parse(dict);
|
30
|
+
}
|
31
|
+
catch (e) {
|
32
|
+
ctx.addIssue({
|
33
|
+
code: 'custom',
|
34
|
+
message: 'Invalid dictionary. Must be a valid key-value pair JSON object.',
|
35
|
+
});
|
36
|
+
return zod_1.z.NEVER;
|
37
|
+
}
|
38
|
+
});
|
39
|
+
exports.FieldsValidationSchema = zod_1.z.object({
|
40
|
+
number: zod_1.z.union([zod_1.z.number(), zod_1.z.nan()]),
|
41
|
+
dictionary: exports.DictionarySchema,
|
42
|
+
});
|
43
|
+
//# sourceMappingURL=fields.js.map
|
package/dist/extensions/transform/v1/actions/parseNumberToTextWithDictionary/config/fields.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"fields.js","sourceRoot":"","sources":["../../../../../../../extensions/transform/v1/actions/parseNumberToTextWithDictionary/config/fields.ts"],"names":[],"mappings":";;;AAAA,6BAAwC;AACxC,mEAAqE;AACrE,mCAAuC;AAE1B,QAAA,MAAM,GAAG;IACpB,MAAM,EAAE;QACN,EAAE,EAAE,QAAQ;QACZ,KAAK,EAAE,QAAQ;QACf,WAAW,EAAE,iDAAiD;QAC9D,IAAI,EAAE,2BAAS,CAAC,OAAO;QACvB,QAAQ,EAAE,IAAI;KACf;IACD,UAAU,EAAE;QACV,EAAE,EAAE,YAAY;QAChB,KAAK,EAAE,YAAY;QACnB,WAAW,EACT,2GAA2G;QAC7G,IAAI,EAAE,2BAAS,CAAC,IAAI;QACpB,QAAQ,EAAE,IAAI;KACf;CAC8B,CAAA;AAEpB,QAAA,gBAAgB,GAAG,OAAC;KAC9B,MAAM,EAAE;KACR,SAAS,CAAC,CAAC,IAAI,EAAE,GAAG,EAAuB,EAAE;IAC5C,IAAI,IAAA,cAAK,EAAC,IAAI,CAAC,IAAI,IAAA,gBAAO,EAAC,IAAI,CAAC;QAAE,OAAO,EAAE,CAAA;IAC3C,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;KACxB;IAAC,OAAO,CAAC,EAAE;QACV,GAAG,CAAC,QAAQ,CAAC;YACX,IAAI,EAAE,QAAQ;YACd,OAAO,EACL,iEAAiE;SACpE,CAAC,CAAA;QACF,OAAO,OAAC,CAAC,KAAK,CAAA;KACf;AACH,CAAC,CAAC,CAAA;AAES,QAAA,sBAAsB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC7C,MAAM,EAAE,OAAC,CAAC,KAAK,CAAC,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,GAAG,EAAE,CAAC,CAAC;IACtC,UAAU,EAAE,wBAAgB;CACqB,CAAC,CAAA"}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.dataPoints = exports.FieldsValidationSchema = exports.fields = void 0;
|
4
|
+
var fields_1 = require("./fields");
|
5
|
+
Object.defineProperty(exports, "fields", { enumerable: true, get: function () { return fields_1.fields; } });
|
6
|
+
Object.defineProperty(exports, "FieldsValidationSchema", { enumerable: true, get: function () { return fields_1.FieldsValidationSchema; } });
|
7
|
+
var dataPoints_1 = require("./dataPoints");
|
8
|
+
Object.defineProperty(exports, "dataPoints", { enumerable: true, get: function () { return dataPoints_1.dataPoints; } });
|
9
|
+
//# sourceMappingURL=index.js.map
|
package/dist/extensions/transform/v1/actions/parseNumberToTextWithDictionary/config/index.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../extensions/transform/v1/actions/parseNumberToTextWithDictionary/config/index.ts"],"names":[],"mappings":";;;AAAA,mCAAyD;AAAhD,gGAAA,MAAM,OAAA;AAAE,gHAAA,sBAAsB,OAAA;AACvC,2CAAyC;AAAhC,wGAAA,UAAU,OAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
export { parseNumberToTextWithDictionary } from './parseNumberToTextWithDictionary';
|
@@ -0,0 +1,6 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.parseNumberToTextWithDictionary = void 0;
|
4
|
+
var parseNumberToTextWithDictionary_1 = require("./parseNumberToTextWithDictionary");
|
5
|
+
Object.defineProperty(exports, "parseNumberToTextWithDictionary", { enumerable: true, get: function () { return parseNumberToTextWithDictionary_1.parseNumberToTextWithDictionary; } });
|
6
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../extensions/transform/v1/actions/parseNumberToTextWithDictionary/index.ts"],"names":[],"mappings":";;;AAAA,qFAAmF;AAA1E,kJAAA,+BAA+B,OAAA"}
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import { type Action } from '@awell-health/extensions-core';
|
2
|
+
import { type settings } from '../../../settings';
|
3
|
+
import { dataPoints, fields } from './config';
|
4
|
+
export declare const parseNumberToTextWithDictionary: Action<typeof fields, typeof settings, keyof typeof dataPoints>;
|
@@ -0,0 +1,74 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.parseNumberToTextWithDictionary = void 0;
|
4
|
+
const extensions_core_1 = require("@awell-health/extensions-core");
|
5
|
+
const config_1 = require("./config");
|
6
|
+
const zod_validation_error_1 = require("zod-validation-error");
|
7
|
+
const zod_1 = require("zod");
|
8
|
+
exports.parseNumberToTextWithDictionary = {
|
9
|
+
key: 'parseNumberToTextWithDictionary',
|
10
|
+
title: 'Parse number to text with dictionary',
|
11
|
+
description: 'Transform or parse a number to text based on a dictionary.',
|
12
|
+
category: extensions_core_1.Category.DATA,
|
13
|
+
fields: config_1.fields,
|
14
|
+
dataPoints: config_1.dataPoints,
|
15
|
+
previewable: true,
|
16
|
+
onActivityCreated: async (payload, onComplete, onError) => {
|
17
|
+
try {
|
18
|
+
const { fields: { number, dictionary }, } = (0, extensions_core_1.validate)({
|
19
|
+
schema: zod_1.z.object({
|
20
|
+
fields: config_1.FieldsValidationSchema,
|
21
|
+
}),
|
22
|
+
payload,
|
23
|
+
});
|
24
|
+
const getStringFromDictionary = () => {
|
25
|
+
const key = number.toString();
|
26
|
+
/**
|
27
|
+
* Get string value from the dict.
|
28
|
+
* If no mapping is found in dict, return the number as a string
|
29
|
+
*/
|
30
|
+
const output = Object.prototype.hasOwnProperty.call(dictionary, key)
|
31
|
+
? dictionary[key]
|
32
|
+
: key;
|
33
|
+
return String(output);
|
34
|
+
};
|
35
|
+
await onComplete({
|
36
|
+
data_points: {
|
37
|
+
text: getStringFromDictionary(),
|
38
|
+
},
|
39
|
+
});
|
40
|
+
}
|
41
|
+
catch (err) {
|
42
|
+
if (err instanceof zod_1.ZodError) {
|
43
|
+
const error = (0, zod_validation_error_1.fromZodError)(err);
|
44
|
+
await onError({
|
45
|
+
events: [
|
46
|
+
{
|
47
|
+
date: new Date().toISOString(),
|
48
|
+
text: { en: error.name },
|
49
|
+
error: {
|
50
|
+
category: 'WRONG_INPUT',
|
51
|
+
message: `${error.message}`,
|
52
|
+
},
|
53
|
+
},
|
54
|
+
],
|
55
|
+
});
|
56
|
+
return;
|
57
|
+
}
|
58
|
+
const error = err;
|
59
|
+
await onError({
|
60
|
+
events: [
|
61
|
+
{
|
62
|
+
date: new Date().toISOString(),
|
63
|
+
text: { en: 'Something went wrong while orchestration the action' },
|
64
|
+
error: {
|
65
|
+
category: 'SERVER_ERROR',
|
66
|
+
message: error.message,
|
67
|
+
},
|
68
|
+
},
|
69
|
+
],
|
70
|
+
});
|
71
|
+
}
|
72
|
+
},
|
73
|
+
};
|
74
|
+
//# sourceMappingURL=parseNumberToTextWithDictionary.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"parseNumberToTextWithDictionary.js","sourceRoot":"","sources":["../../../../../../extensions/transform/v1/actions/parseNumberToTextWithDictionary/parseNumberToTextWithDictionary.ts"],"names":[],"mappings":";;;AACA,mEAAkE;AAElE,qCAAqE;AACrE,+DAAmD;AACnD,6BAAiC;AAEpB,QAAA,+BAA+B,GAIxC;IACF,GAAG,EAAE,iCAAiC;IACtC,KAAK,EAAE,sCAAsC;IAC7C,WAAW,EAAE,4DAA4D;IACzE,QAAQ,EAAE,0BAAQ,CAAC,IAAI;IACvB,MAAM,EAAN,eAAM;IACN,UAAU,EAAV,mBAAU;IACV,WAAW,EAAE,IAAI;IACjB,iBAAiB,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE;QACxD,IAAI;YACF,MAAM,EACJ,MAAM,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,GAC/B,GAAG,IAAA,0BAAQ,EAAC;gBACX,MAAM,EAAE,OAAC,CAAC,MAAM,CAAC;oBACf,MAAM,EAAE,+BAAsB;iBAC/B,CAAC;gBACF,OAAO;aACR,CAAC,CAAA;YAEF,MAAM,uBAAuB,GAAG,GAAW,EAAE;gBAC3C,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAA;gBAE7B;;;mBAGG;gBACH,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC;oBAClE,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC;oBACjB,CAAC,CAAC,GAAG,CAAA;gBAEP,OAAO,MAAM,CAAC,MAAM,CAAC,CAAA;YACvB,CAAC,CAAA;YAED,MAAM,UAAU,CAAC;gBACf,WAAW,EAAE;oBACX,IAAI,EAAE,uBAAuB,EAAE;iBAChC;aACF,CAAC,CAAA;SACH;QAAC,OAAO,GAAG,EAAE;YACZ,IAAI,GAAG,YAAY,cAAQ,EAAE;gBAC3B,MAAM,KAAK,GAAG,IAAA,mCAAY,EAAC,GAAG,CAAC,CAAA;gBAC/B,MAAM,OAAO,CAAC;oBACZ,MAAM,EAAE;wBACN;4BACE,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;4BAC9B,IAAI,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC,IAAI,EAAE;4BACxB,KAAK,EAAE;gCACL,QAAQ,EAAE,aAAa;gCACvB,OAAO,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE;6BAC5B;yBACF;qBACF;iBACF,CAAC,CAAA;gBACF,OAAM;aACP;YAED,MAAM,KAAK,GAAG,GAAY,CAAA;YAC1B,MAAM,OAAO,CAAC;gBACZ,MAAM,EAAE;oBACN;wBACE,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;wBAC9B,IAAI,EAAE,EAAE,EAAE,EAAE,qDAAqD,EAAE;wBACnE,KAAK,EAAE;4BACL,QAAQ,EAAE,cAAc;4BACxB,OAAO,EAAE,KAAK,CAAC,OAAO;yBACvB;qBACF;iBACF;aACF,CAAC,CAAA;SACH;IACH,CAAC;CACF,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,93 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const _1 = require(".");
|
4
|
+
const tests_1 = require("../../../../../src/tests");
|
5
|
+
describe('Transform - Parse number to text with dictionary', () => {
|
6
|
+
const onComplete = jest.fn();
|
7
|
+
const onError = jest.fn();
|
8
|
+
beforeEach(() => {
|
9
|
+
jest.clearAllMocks();
|
10
|
+
});
|
11
|
+
test('Should parse number to text if mapping is found in dict', async () => {
|
12
|
+
const mockOnActivityCreateParams = (0, tests_1.generateTestPayload)({
|
13
|
+
fields: {
|
14
|
+
number: 1,
|
15
|
+
dictionary: JSON.stringify({
|
16
|
+
'1': 'hello world',
|
17
|
+
}),
|
18
|
+
},
|
19
|
+
settings: {},
|
20
|
+
});
|
21
|
+
await _1.parseNumberToTextWithDictionary.onActivityCreated(mockOnActivityCreateParams, onComplete, onError);
|
22
|
+
expect(onComplete).toBeCalledWith({
|
23
|
+
data_points: {
|
24
|
+
text: 'hello world',
|
25
|
+
},
|
26
|
+
});
|
27
|
+
});
|
28
|
+
test('Should parse NaN to text', async () => {
|
29
|
+
const mockOnActivityCreateParams = (0, tests_1.generateTestPayload)({
|
30
|
+
fields: {
|
31
|
+
number: NaN,
|
32
|
+
dictionary: JSON.stringify({
|
33
|
+
'1': 'hello world',
|
34
|
+
}),
|
35
|
+
},
|
36
|
+
settings: {},
|
37
|
+
});
|
38
|
+
await _1.parseNumberToTextWithDictionary.onActivityCreated(mockOnActivityCreateParams, onComplete, onError);
|
39
|
+
expect(onComplete).toBeCalledWith({
|
40
|
+
data_points: {
|
41
|
+
text: 'NaN',
|
42
|
+
},
|
43
|
+
});
|
44
|
+
});
|
45
|
+
test('Should parse number to text if no mapping is found in the dictionary', async () => {
|
46
|
+
const mockOnActivityCreateParams = (0, tests_1.generateTestPayload)({
|
47
|
+
fields: {
|
48
|
+
number: 1,
|
49
|
+
dictionary: JSON.stringify({
|
50
|
+
'2': 'hello world',
|
51
|
+
}),
|
52
|
+
},
|
53
|
+
settings: {},
|
54
|
+
});
|
55
|
+
await _1.parseNumberToTextWithDictionary.onActivityCreated(mockOnActivityCreateParams, onComplete, onError);
|
56
|
+
expect(onComplete).toBeCalledWith({
|
57
|
+
data_points: {
|
58
|
+
text: '1',
|
59
|
+
},
|
60
|
+
});
|
61
|
+
});
|
62
|
+
test('Should parse number to text if dictionary is emtpy', async () => {
|
63
|
+
const mockOnActivityCreateParams = (0, tests_1.generateTestPayload)({
|
64
|
+
fields: {
|
65
|
+
number: 2,
|
66
|
+
dictionary: JSON.stringify({}),
|
67
|
+
},
|
68
|
+
settings: {},
|
69
|
+
});
|
70
|
+
await _1.parseNumberToTextWithDictionary.onActivityCreated(mockOnActivityCreateParams, onComplete, onError);
|
71
|
+
expect(onComplete).toBeCalledWith({
|
72
|
+
data_points: {
|
73
|
+
text: '2',
|
74
|
+
},
|
75
|
+
});
|
76
|
+
});
|
77
|
+
test('Should parse number to text even if dictionary has number value', async () => {
|
78
|
+
const mockOnActivityCreateParams = (0, tests_1.generateTestPayload)({
|
79
|
+
fields: {
|
80
|
+
number: 2,
|
81
|
+
dictionary: JSON.stringify({ 2: 5 }),
|
82
|
+
},
|
83
|
+
settings: {},
|
84
|
+
});
|
85
|
+
await _1.parseNumberToTextWithDictionary.onActivityCreated(mockOnActivityCreateParams, onComplete, onError);
|
86
|
+
expect(onComplete).toBeCalledWith({
|
87
|
+
data_points: {
|
88
|
+
text: '5',
|
89
|
+
},
|
90
|
+
});
|
91
|
+
});
|
92
|
+
});
|
93
|
+
//# sourceMappingURL=parseNumberToTextWithDictionary.test.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"parseNumberToTextWithDictionary.test.js","sourceRoot":"","sources":["../../../../../../extensions/transform/v1/actions/parseNumberToTextWithDictionary/parseNumberToTextWithDictionary.test.ts"],"names":[],"mappings":";;AAAA,wBAAmD;AACnD,oDAA8D;AAE9D,QAAQ,CAAC,kDAAkD,EAAE,GAAG,EAAE;IAChE,MAAM,UAAU,GAAG,IAAI,CAAC,EAAE,EAAE,CAAA;IAC5B,MAAM,OAAO,GAAG,IAAI,CAAC,EAAE,EAAE,CAAA;IAEzB,UAAU,CAAC,GAAG,EAAE;QACd,IAAI,CAAC,aAAa,EAAE,CAAA;IACtB,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,yDAAyD,EAAE,KAAK,IAAI,EAAE;QACzE,MAAM,0BAA0B,GAAG,IAAA,2BAAmB,EAAC;YACrD,MAAM,EAAE;gBACN,MAAM,EAAE,CAAC;gBACT,UAAU,EAA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