@oneblink/sdk-core 7.4.0-beta.2 → 7.4.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.
|
@@ -22,3 +22,11 @@ export type FreshdeskDependentField = {
|
|
|
22
22
|
choices: FreshdeskFieldCategory[];
|
|
23
23
|
};
|
|
24
24
|
export declare function generateFreshdeskTicketFieldDefinitions(fields: FreshdeskTypes.FreshdeskField[]): FreshdeskFieldDefinition[];
|
|
25
|
+
/**
|
|
26
|
+
* This function is used to transform the `choices` property into the `options`
|
|
27
|
+
* property for freshdesk fields.
|
|
28
|
+
*
|
|
29
|
+
* @param fields
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
export declare function setFreshdeskFieldOptions(fields: FreshdeskTypes.FreshdeskField[]): FreshdeskTypes.FreshdeskField[];
|
package/dist/freshdeskService.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateFreshdeskTicketFieldDefinitions = exports.choiceFieldTypes = exports.checkboxFieldType = exports.dateFieldType = exports.numberFieldTypes = exports.textFieldTypes = exports.emailFieldType = exports.multilineFieldType = void 0;
|
|
3
|
+
exports.setFreshdeskFieldOptions = exports.generateFreshdeskTicketFieldDefinitions = exports.choiceFieldTypes = exports.checkboxFieldType = exports.dateFieldType = exports.numberFieldTypes = exports.textFieldTypes = exports.emailFieldType = exports.multilineFieldType = void 0;
|
|
4
4
|
exports.multilineFieldType = 'custom_paragraph';
|
|
5
5
|
exports.emailFieldType = 'default_requester';
|
|
6
6
|
exports.textFieldTypes = [
|
|
@@ -23,7 +23,7 @@ exports.choiceFieldTypes = [
|
|
|
23
23
|
'default_group',
|
|
24
24
|
];
|
|
25
25
|
function generateFreshdeskTicketFieldDefinitions(fields) {
|
|
26
|
-
return fields.reduce((memo, freshdeskField) => {
|
|
26
|
+
return setFreshdeskFieldOptions(fields).reduce((memo, freshdeskField) => {
|
|
27
27
|
var _a;
|
|
28
28
|
const isCheckboxField = freshdeskField.type === exports.checkboxFieldType;
|
|
29
29
|
const isRequired = freshdeskField.required_for_customers ||
|
|
@@ -128,4 +128,57 @@ function generateFreshdeskTicketFieldDefinitions(fields) {
|
|
|
128
128
|
}, []);
|
|
129
129
|
}
|
|
130
130
|
exports.generateFreshdeskTicketFieldDefinitions = generateFreshdeskTicketFieldDefinitions;
|
|
131
|
+
/**
|
|
132
|
+
* This function is used to transform the `choices` property into the `options`
|
|
133
|
+
* property for freshdesk fields.
|
|
134
|
+
*
|
|
135
|
+
* @param fields
|
|
136
|
+
* @returns
|
|
137
|
+
*/
|
|
138
|
+
function setFreshdeskFieldOptions(fields) {
|
|
139
|
+
for (const field of fields) {
|
|
140
|
+
const choices = field.choices;
|
|
141
|
+
if (!choices) {
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (Array.isArray(choices)) {
|
|
145
|
+
field.options = choices.map((choice) => ({
|
|
146
|
+
label: choice,
|
|
147
|
+
value: choice,
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
else if (typeof choices === 'object') {
|
|
151
|
+
field.options = Object.entries(choices).map(([key, value]) => {
|
|
152
|
+
if (typeof value === 'number') {
|
|
153
|
+
return {
|
|
154
|
+
label: key,
|
|
155
|
+
value,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
else if (Array.isArray(value)) {
|
|
159
|
+
return {
|
|
160
|
+
label: value[0],
|
|
161
|
+
value: parseInt(key),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
return {
|
|
166
|
+
label: key,
|
|
167
|
+
value: key,
|
|
168
|
+
options: Object.entries(value).map(([subCategory, items]) => ({
|
|
169
|
+
label: subCategory,
|
|
170
|
+
value: subCategory,
|
|
171
|
+
options: items.map((item) => ({
|
|
172
|
+
label: item,
|
|
173
|
+
value: item,
|
|
174
|
+
})),
|
|
175
|
+
})),
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return fields;
|
|
182
|
+
}
|
|
183
|
+
exports.setFreshdeskFieldOptions = setFreshdeskFieldOptions;
|
|
131
184
|
//# sourceMappingURL=freshdeskService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"freshdeskService.js","sourceRoot":"","sources":["../src/freshdeskService.ts"],"names":[],"mappings":";;;AAMa,QAAA,kBAAkB,GAAG,kBAAkB,CAAA;AACvC,QAAA,cAAc,GAAG,mBAAmB,CAAA;AACpC,QAAA,cAAc,GAAG;IAC5B,0BAAkB;IAClB,aAAa;IACb,iBAAiB;IACjB,sBAAc;CACf,CAAA;AAEY,QAAA,gBAAgB,GAAG,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAAA;AAEtD,QAAA,aAAa,GAAG,aAAa,CAAA;AAC7B,QAAA,iBAAiB,GAAG,iBAAiB,CAAA;AACrC,QAAA,gBAAgB,GAAG;IAC9B,iBAAiB;IACjB,yBAAiB;IACjB,kBAAkB;IAClB,gBAAgB;IAChB,gBAAgB;IAChB,qBAAqB;IACrB,eAAe;IACf,eAAe;CAChB,CAAA;AAuBD,SAAgB,uCAAuC,CACrD,MAAuC;IAEvC,OAAO,MAAM,CAAC,MAAM,CAA6B,CAAC,IAAI,EAAE,cAAc,EAAE,EAAE;;QACxE,MAAM,eAAe,GAAG,cAAc,CAAC,IAAI,KAAK,yBAAiB,CAAA;QACjE,MAAM,UAAU,GACd,cAAc,CAAC,sBAAsB;YACrC,cAAc,CAAC,IAAI,KAAK,aAAa,CAAA;QACvC,MAAM,WAAW,GAAG,sBAAc,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,CAAA;QAChE,MAAM,oBAAoB,GAAG,cAAc,CAAC,IAAI,KAAK,0BAAkB,CAAA;QACvE,MAAM,YAAY,GAAG,cAAc,CAAC,IAAI,KAAK,sBAAc,CAA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A;YACvB,CAAC,EACD,EAAE,CACH,CAAA;YAED,IAAI,OAAO,CAAC,MAAM,EAAE;gBAClB,IAAI,CAAC,IAAI,CAAC;oBACR,IAAI,EAAE,iBAAiB;oBACvB,GAAG,SAAS;oBACZ,OAAO;iBACR,CAAC,CAAA;aACH;SACF;QAED,OAAO,IAAI,CAAA;IACb,CAAC,EAAE,EAAE,CAAC,CAAA;AACR,CAAC;AAjHD,0FAiHC","sourcesContent":["import { FreshdeskTypes, SubmissionEventTypes } from '@oneblink/types'\nimport {\n ResourceDefinition,\n ResourceDefinitionChoice,\n} from './types/resource-definitions'\n\nexport const multilineFieldType = 'custom_paragraph'\nexport const emailFieldType = 'default_requester'\nexport const textFieldTypes = [\n multilineFieldType,\n 'custom_text',\n 'default_subject',\n emailFieldType,\n]\n\nexport const numberFieldTypes = ['custom_number', 'custom_decimal']\n\nexport const dateFieldType = 'custom_date'\nexport const checkboxFieldType = 'custom_checkbox'\nexport const choiceFieldTypes = [\n 'custom_dropdown',\n checkboxFieldType,\n 'default_priority',\n 'default_status',\n 'default_source',\n 'default_ticket_type',\n 'default_agent',\n 'default_group',\n]\n\nexport type FreshdeskFieldDefinition =\n | ResourceDefinition<SubmissionEventTypes.BaseFreshdeskSubmissionEventFieldMapping>\n | FreshdeskDependentField\n\nexport type FreshdeskFieldCategory = ResourceDefinitionChoice & {\n subCategories: Array<\n ResourceDefinitionChoice & {\n items: Array<ResourceDefinitionChoice>\n }\n >\n}\n\nexport type FreshdeskDependentField = {\n type: 'DEPENDENT_FIELD'\n id: string\n isRequired: boolean\n displayName: string\n freshdeskFieldName: string\n choices: FreshdeskFieldCategory[]\n}\n\nexport function generateFreshdeskTicketFieldDefinitions(\n fields: FreshdeskTypes.FreshdeskField[],\n) {\n return fields.reduce<FreshdeskFieldDefinition[]>((memo, freshdeskField) => {\n const isCheckboxField = freshdeskField.type === checkboxFieldType\n const isRequired =\n freshdeskField.required_for_customers ||\n freshdeskField.name === 'ticket_type'\n const isTextField = textFieldTypes.includes(freshdeskField.type)\n const isMultilineTextField = freshdeskField.type === multilineFieldType\n const isEmailField = freshdeskField.type === emailFieldType\n const isDateField = freshdeskField.type === dateFieldType\n const isNumberField = numberFieldTypes.includes(freshdeskField.type)\n const isChoiceField = choiceFieldTypes.includes(freshdeskField.type)\n\n const baseField = {\n id: freshdeskField.id.toString(),\n displayName: freshdeskField.label_for_customers,\n isRequired,\n freshdeskFieldName: freshdeskField.name,\n }\n if (isCheckboxField) {\n memo.push({\n type: 'BOOLEAN',\n ...baseField,\n })\n } else if (isDateField) {\n memo.push({\n type: 'DATE',\n ...baseField,\n })\n } else if (isNumberField) {\n memo.push({\n type: 'NUMBER',\n ...baseField,\n })\n } else if (isEmailField) {\n memo.push({\n type: 'EMAIL',\n ...baseField,\n })\n } else if (isMultilineTextField) {\n memo.push({\n type: 'TEXT_MULTI_LINE',\n ...baseField,\n })\n } else if (isTextField) {\n memo.push({\n type: 'TEXT_SINGLE_LINE',\n ...baseField,\n })\n } else if (freshdeskField.options && isChoiceField) {\n memo.push({\n type: 'CHOICE_SINGLE',\n ...baseField,\n choices: freshdeskField.options,\n checkIsFormElementSupported(formElementWithOptions) {\n if (freshdeskField.type === 'nested_field') {\n return false\n }\n\n return (\n formElementWithOptions.freshdeskFieldName === freshdeskField.name\n )\n },\n })\n } else if (\n freshdeskField.type === 'nested_field' &&\n freshdeskField.options?.length\n ) {\n const choices = freshdeskField.options.reduce<FreshdeskFieldCategory[]>(\n (categoriesMemo, category) => {\n const subCategories = category.options?.reduce<\n FreshdeskFieldCategory['subCategories']\n >((subCategoriesMemo, subCategory) => {\n if (subCategory.options?.length) {\n subCategoriesMemo.push({\n value: subCategory.value,\n label: subCategory.label,\n items: subCategory.options.map(({ value, label }) => ({\n value,\n label,\n })),\n })\n }\n\n return subCategoriesMemo\n }, [])\n\n if (subCategories?.length) {\n categoriesMemo.push({\n value: category.value,\n label: category.label,\n subCategories,\n })\n }\n\n return categoriesMemo\n },\n [],\n )\n\n if (choices.length) {\n memo.push({\n type: 'DEPENDENT_FIELD',\n ...baseField,\n choices,\n })\n }\n }\n\n return memo\n }, [])\n}\n"]}
|
|
1
|
+
{"version":3,"file":"freshdeskService.js","sourceRoot":"","sources":["../src/freshdeskService.ts"],"names":[],"mappings":";;;AAMa,QAAA,kBAAkB,GAAG,kBAAkB,CAAA;AACvC,QAAA,cAAc,GAAG,mBAAmB,CAAA;AACpC,QAAA,cAAc,GAAG;IAC5B,0BAAkB;IAClB,aAAa;IACb,iBAAiB;IACjB,sBAAc;CACf,CAAA;AAEY,QAAA,gBAAgB,GAAG,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAAA;AAEtD,QAAA,aAAa,GAAG,aAAa,CAAA;AAC7B,QAAA,iBAAiB,GAAG,iBAAiB,CAAA;AACrC,QAAA,gBAAgB,GAAG;IAC9B,iBAAiB;IACjB,yBAAiB;IACjB,kBAAkB;IAClB,gBAAgB;IAChB,gBAAgB;IAChB,qBAAqB;IACrB,eAAe;IACf,eAAe;CAChB,CAAA;AAuBD,SAAgB,uCAAuC,CACrD,MAAuC;IAEvC,OAAO,wBAAwB,CAAC,MAAM,CAAC,CAAC,MAAM,CAC5C,CAAC,IAAI,EAAE,cAAc,EAAE,EAAE;;QACvB,MAAM,eAAe,GAAG,cAAc,CAAC,IAAI,KAAK,yBAAiB,CAAA;QACjE,MAAM,UAAU,GACd,cAAc,CAAC,sBAAsB;YACrC,cAAc,CAAC,IAAI,KAAK,aAAa,CAAA;QACvC,MAAM,WAAW,GAAG,sBAAc,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,CAAA;QAChE,MAAM,oBAAoB,GAAG,cAAc,CAAC,IAAI,KAAK,0BAAkB,CAAA;QACvE,MAAM,YAAY,GAAG,cAAc,CAAC,IAAI,KAAK,sBAAc,CAAA;QAC3D,MAAM,WAAW,GAAG,cAAc,CAAC,IAAI,KAAK,qBAAa,CAAA;QACzD,MAAM,aAAa,GAAG,wBAAgB,CAAC,QAAQ,C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AAC;4BAC5D,KAAK,EAAE,WAAW;4BAClB,KAAK,EAAE,WAAW;4BAClB,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;gCAC5B,KAAK,EAAE,IAAI;gCACX,KAAK,EAAE,IAAI;6BACZ,CAAC,CAAC;yBACJ,CAAC,CAAC;qBACJ,CAAA;iBACF;YACH,CAAC,CAAC,CAAA;SACH;KACF;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AA3CD,4DA2CC","sourcesContent":["import { FreshdeskTypes, SubmissionEventTypes } from '@oneblink/types'\nimport {\n ResourceDefinition,\n ResourceDefinitionChoice,\n} from './types/resource-definitions'\n\nexport const multilineFieldType = 'custom_paragraph'\nexport const emailFieldType = 'default_requester'\nexport const textFieldTypes = [\n multilineFieldType,\n 'custom_text',\n 'default_subject',\n emailFieldType,\n]\n\nexport const numberFieldTypes = ['custom_number', 'custom_decimal']\n\nexport const dateFieldType = 'custom_date'\nexport const checkboxFieldType = 'custom_checkbox'\nexport const choiceFieldTypes = [\n 'custom_dropdown',\n checkboxFieldType,\n 'default_priority',\n 'default_status',\n 'default_source',\n 'default_ticket_type',\n 'default_agent',\n 'default_group',\n]\n\nexport type FreshdeskFieldDefinition =\n | ResourceDefinition<SubmissionEventTypes.BaseFreshdeskSubmissionEventFieldMapping>\n | FreshdeskDependentField\n\nexport type FreshdeskFieldCategory = ResourceDefinitionChoice & {\n subCategories: Array<\n ResourceDefinitionChoice & {\n items: Array<ResourceDefinitionChoice>\n }\n >\n}\n\nexport type FreshdeskDependentField = {\n type: 'DEPENDENT_FIELD'\n id: string\n isRequired: boolean\n displayName: string\n freshdeskFieldName: string\n choices: FreshdeskFieldCategory[]\n}\n\nexport function generateFreshdeskTicketFieldDefinitions(\n fields: FreshdeskTypes.FreshdeskField[],\n) {\n return setFreshdeskFieldOptions(fields).reduce<FreshdeskFieldDefinition[]>(\n (memo, freshdeskField) => {\n const isCheckboxField = freshdeskField.type === checkboxFieldType\n const isRequired =\n freshdeskField.required_for_customers ||\n freshdeskField.name === 'ticket_type'\n const isTextField = textFieldTypes.includes(freshdeskField.type)\n const isMultilineTextField = freshdeskField.type === multilineFieldType\n const isEmailField = freshdeskField.type === emailFieldType\n const isDateField = freshdeskField.type === dateFieldType\n const isNumberField = numberFieldTypes.includes(freshdeskField.type)\n const isChoiceField = choiceFieldTypes.includes(freshdeskField.type)\n\n const baseField = {\n id: freshdeskField.id.toString(),\n displayName: freshdeskField.label_for_customers,\n isRequired,\n freshdeskFieldName: freshdeskField.name,\n }\n if (isCheckboxField) {\n memo.push({\n type: 'BOOLEAN',\n ...baseField,\n })\n } else if (isDateField) {\n memo.push({\n type: 'DATE',\n ...baseField,\n })\n } else if (isNumberField) {\n memo.push({\n type: 'NUMBER',\n ...baseField,\n })\n } else if (isEmailField) {\n memo.push({\n type: 'EMAIL',\n ...baseField,\n })\n } else if (isMultilineTextField) {\n memo.push({\n type: 'TEXT_MULTI_LINE',\n ...baseField,\n })\n } else if (isTextField) {\n memo.push({\n type: 'TEXT_SINGLE_LINE',\n ...baseField,\n })\n } else if (freshdeskField.options && isChoiceField) {\n memo.push({\n type: 'CHOICE_SINGLE',\n ...baseField,\n choices: freshdeskField.options,\n checkIsFormElementSupported(formElementWithOptions) {\n if (freshdeskField.type === 'nested_field') {\n return false\n }\n\n return (\n formElementWithOptions.freshdeskFieldName === freshdeskField.name\n )\n },\n })\n } else if (\n freshdeskField.type === 'nested_field' &&\n freshdeskField.options?.length\n ) {\n const choices = freshdeskField.options.reduce<FreshdeskFieldCategory[]>(\n (categoriesMemo, category) => {\n const subCategories = category.options?.reduce<\n FreshdeskFieldCategory['subCategories']\n >((subCategoriesMemo, subCategory) => {\n if (subCategory.options?.length) {\n subCategoriesMemo.push({\n value: subCategory.value,\n label: subCategory.label,\n items: subCategory.options.map(({ value, label }) => ({\n value,\n label,\n })),\n })\n }\n\n return subCategoriesMemo\n }, [])\n\n if (subCategories?.length) {\n categoriesMemo.push({\n value: category.value,\n label: category.label,\n subCategories,\n })\n }\n\n return categoriesMemo\n },\n [],\n )\n\n if (choices.length) {\n memo.push({\n type: 'DEPENDENT_FIELD',\n ...baseField,\n choices,\n })\n }\n }\n\n return memo\n },\n [],\n )\n}\n\n/**\n * This function is used to transform the `choices` property into the `options`\n * property for freshdesk fields.\n *\n * @param fields\n * @returns\n */\nexport function setFreshdeskFieldOptions(\n fields: FreshdeskTypes.FreshdeskField[],\n): FreshdeskTypes.FreshdeskField[] {\n for (const field of fields) {\n const choices = field.choices\n if (!choices) {\n continue\n }\n if (Array.isArray(choices)) {\n field.options = choices.map((choice) => ({\n label: choice,\n value: choice,\n }))\n } else if (typeof choices === 'object') {\n field.options = Object.entries(choices).map(([key, value]) => {\n if (typeof value === 'number') {\n return {\n label: key,\n value,\n }\n } else if (Array.isArray(value)) {\n return {\n label: value[0],\n value: parseInt(key),\n }\n } else {\n return {\n label: key,\n value: key,\n options: Object.entries(value).map(([subCategory, items]) => ({\n label: subCategory,\n value: subCategory,\n options: items.map((item) => ({\n label: item,\n value: item,\n })),\n })),\n }\n }\n })\n }\n }\n return fields\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oneblink/sdk-core",
|
|
3
3
|
"description": "OneBlink SDK for JavaScript (works in Browsers and NodeJS)",
|
|
4
|
-
"version": "7.4.0
|
|
4
|
+
"version": "7.4.0",
|
|
5
5
|
"author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/oneblink/sdk-core-js/issues"
|