@oneblink/sdk-core 7.4.0-beta.1 → 7.4.0-beta.3
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/freshdeskService.d.ts +32 -0
- package/dist/freshdeskService.js +184 -0
- package/dist/freshdeskService.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { FreshdeskTypes, SubmissionEventTypes } from '@oneblink/types';
|
|
2
|
+
import { ResourceDefinition, ResourceDefinitionChoice } from './types/resource-definitions';
|
|
3
|
+
export declare const multilineFieldType = "custom_paragraph";
|
|
4
|
+
export declare const emailFieldType = "default_requester";
|
|
5
|
+
export declare const textFieldTypes: string[];
|
|
6
|
+
export declare const numberFieldTypes: string[];
|
|
7
|
+
export declare const dateFieldType = "custom_date";
|
|
8
|
+
export declare const checkboxFieldType = "custom_checkbox";
|
|
9
|
+
export declare const choiceFieldTypes: string[];
|
|
10
|
+
export type FreshdeskFieldDefinition = ResourceDefinition<SubmissionEventTypes.BaseFreshdeskSubmissionEventFieldMapping> | FreshdeskDependentField;
|
|
11
|
+
export type FreshdeskFieldCategory = ResourceDefinitionChoice & {
|
|
12
|
+
subCategories: Array<ResourceDefinitionChoice & {
|
|
13
|
+
items: Array<ResourceDefinitionChoice>;
|
|
14
|
+
}>;
|
|
15
|
+
};
|
|
16
|
+
export type FreshdeskDependentField = {
|
|
17
|
+
type: 'DEPENDENT_FIELD';
|
|
18
|
+
id: string;
|
|
19
|
+
isRequired: boolean;
|
|
20
|
+
displayName: string;
|
|
21
|
+
freshdeskFieldName: string;
|
|
22
|
+
choices: FreshdeskFieldCategory[];
|
|
23
|
+
};
|
|
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[];
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setFreshdeskFieldOptions = exports.generateFreshdeskTicketFieldDefinitions = exports.choiceFieldTypes = exports.checkboxFieldType = exports.dateFieldType = exports.numberFieldTypes = exports.textFieldTypes = exports.emailFieldType = exports.multilineFieldType = void 0;
|
|
4
|
+
exports.multilineFieldType = 'custom_paragraph';
|
|
5
|
+
exports.emailFieldType = 'default_requester';
|
|
6
|
+
exports.textFieldTypes = [
|
|
7
|
+
exports.multilineFieldType,
|
|
8
|
+
'custom_text',
|
|
9
|
+
'default_subject',
|
|
10
|
+
exports.emailFieldType,
|
|
11
|
+
];
|
|
12
|
+
exports.numberFieldTypes = ['custom_number', 'custom_decimal'];
|
|
13
|
+
exports.dateFieldType = 'custom_date';
|
|
14
|
+
exports.checkboxFieldType = 'custom_checkbox';
|
|
15
|
+
exports.choiceFieldTypes = [
|
|
16
|
+
'custom_dropdown',
|
|
17
|
+
exports.checkboxFieldType,
|
|
18
|
+
'default_priority',
|
|
19
|
+
'default_status',
|
|
20
|
+
'default_source',
|
|
21
|
+
'default_ticket_type',
|
|
22
|
+
'default_agent',
|
|
23
|
+
'default_group',
|
|
24
|
+
];
|
|
25
|
+
function generateFreshdeskTicketFieldDefinitions(fields) {
|
|
26
|
+
return setFreshdeskFieldOptions(fields).reduce((memo, freshdeskField) => {
|
|
27
|
+
var _a;
|
|
28
|
+
const isCheckboxField = freshdeskField.type === exports.checkboxFieldType;
|
|
29
|
+
const isRequired = freshdeskField.required_for_customers ||
|
|
30
|
+
freshdeskField.name === 'ticket_type';
|
|
31
|
+
const isTextField = exports.textFieldTypes.includes(freshdeskField.type);
|
|
32
|
+
const isMultilineTextField = freshdeskField.type === exports.multilineFieldType;
|
|
33
|
+
const isEmailField = freshdeskField.type === exports.emailFieldType;
|
|
34
|
+
const isDateField = freshdeskField.type === exports.dateFieldType;
|
|
35
|
+
const isNumberField = exports.numberFieldTypes.includes(freshdeskField.type);
|
|
36
|
+
const isChoiceField = exports.choiceFieldTypes.includes(freshdeskField.type);
|
|
37
|
+
const baseField = {
|
|
38
|
+
id: freshdeskField.id.toString(),
|
|
39
|
+
displayName: freshdeskField.label_for_customers,
|
|
40
|
+
isRequired,
|
|
41
|
+
freshdeskFieldName: freshdeskField.name,
|
|
42
|
+
};
|
|
43
|
+
if (isCheckboxField) {
|
|
44
|
+
memo.push({
|
|
45
|
+
type: 'BOOLEAN',
|
|
46
|
+
...baseField,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
else if (isDateField) {
|
|
50
|
+
memo.push({
|
|
51
|
+
type: 'DATE',
|
|
52
|
+
...baseField,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
else if (isNumberField) {
|
|
56
|
+
memo.push({
|
|
57
|
+
type: 'NUMBER',
|
|
58
|
+
...baseField,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
else if (isEmailField) {
|
|
62
|
+
memo.push({
|
|
63
|
+
type: 'EMAIL',
|
|
64
|
+
...baseField,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
else if (isMultilineTextField) {
|
|
68
|
+
memo.push({
|
|
69
|
+
type: 'TEXT_MULTI_LINE',
|
|
70
|
+
...baseField,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
else if (isTextField) {
|
|
74
|
+
memo.push({
|
|
75
|
+
type: 'TEXT_SINGLE_LINE',
|
|
76
|
+
...baseField,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
else if (freshdeskField.options && isChoiceField) {
|
|
80
|
+
memo.push({
|
|
81
|
+
type: 'CHOICE_SINGLE',
|
|
82
|
+
...baseField,
|
|
83
|
+
choices: freshdeskField.options,
|
|
84
|
+
checkIsFormElementSupported(formElementWithOptions) {
|
|
85
|
+
if (freshdeskField.type === 'nested_field') {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
return (formElementWithOptions.freshdeskFieldName === freshdeskField.name);
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
else if (freshdeskField.type === 'nested_field' &&
|
|
93
|
+
((_a = freshdeskField.options) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
94
|
+
const choices = freshdeskField.options.reduce((categoriesMemo, category) => {
|
|
95
|
+
var _a;
|
|
96
|
+
const subCategories = (_a = category.options) === null || _a === void 0 ? void 0 : _a.reduce((subCategoriesMemo, subCategory) => {
|
|
97
|
+
var _a;
|
|
98
|
+
if ((_a = subCategory.options) === null || _a === void 0 ? void 0 : _a.length) {
|
|
99
|
+
subCategoriesMemo.push({
|
|
100
|
+
value: subCategory.value,
|
|
101
|
+
label: subCategory.label,
|
|
102
|
+
items: subCategory.options.map(({ value, label }) => ({
|
|
103
|
+
value,
|
|
104
|
+
label,
|
|
105
|
+
})),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return subCategoriesMemo;
|
|
109
|
+
}, []);
|
|
110
|
+
if (subCategories === null || subCategories === void 0 ? void 0 : subCategories.length) {
|
|
111
|
+
categoriesMemo.push({
|
|
112
|
+
value: category.value,
|
|
113
|
+
label: category.label,
|
|
114
|
+
subCategories,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return categoriesMemo;
|
|
118
|
+
}, []);
|
|
119
|
+
if (choices.length) {
|
|
120
|
+
memo.push({
|
|
121
|
+
type: 'DEPENDENT_FIELD',
|
|
122
|
+
...baseField,
|
|
123
|
+
choices,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return memo;
|
|
128
|
+
}, []);
|
|
129
|
+
}
|
|
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;
|
|
184
|
+
//# sourceMappingURL=freshdeskService.js.map
|
|
@@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E,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/dist/index.d.ts
CHANGED
|
@@ -109,3 +109,13 @@ export * as webhookSubscriptionService from './webhookSubscriptionService';
|
|
|
109
109
|
* ```
|
|
110
110
|
*/
|
|
111
111
|
export * as sharepointService from './sharepointService';
|
|
112
|
+
/**
|
|
113
|
+
* ## Freshdesk Service
|
|
114
|
+
*
|
|
115
|
+
* Helper functions for handling Freshdesk
|
|
116
|
+
*
|
|
117
|
+
* ```js
|
|
118
|
+
* import { freshdeskService } from '@oneblink/sdk-core'
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export * as freshdeskService from './freshdeskService';
|
package/dist/index.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.sharepointService = exports.webhookSubscriptionService = exports.fileUploadService = exports.schedulingService = exports.paymentService = exports.abnService = exports.userService = exports.typeCastService = exports.submissionService = exports.conditionalLogicService = exports.formElementsService = exports.resourceDefinitionTypes = void 0;
|
|
26
|
+
exports.freshdeskService = exports.sharepointService = exports.webhookSubscriptionService = exports.fileUploadService = exports.schedulingService = exports.paymentService = exports.abnService = exports.userService = exports.typeCastService = exports.submissionService = exports.conditionalLogicService = exports.formElementsService = exports.resourceDefinitionTypes = void 0;
|
|
27
27
|
exports.resourceDefinitionTypes = __importStar(require("./types/resource-definitions"));
|
|
28
28
|
/**
|
|
29
29
|
* ## Form Elements Service
|
|
@@ -135,4 +135,14 @@ exports.webhookSubscriptionService = __importStar(require("./webhookSubscription
|
|
|
135
135
|
* ```
|
|
136
136
|
*/
|
|
137
137
|
exports.sharepointService = __importStar(require("./sharepointService"));
|
|
138
|
+
/**
|
|
139
|
+
* ## Freshdesk Service
|
|
140
|
+
*
|
|
141
|
+
* Helper functions for handling Freshdesk
|
|
142
|
+
*
|
|
143
|
+
* ```js
|
|
144
|
+
* import { freshdeskService } from '@oneblink/sdk-core'
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
exports.freshdeskService = __importStar(require("./freshdeskService"));
|
|
138
148
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wFAAuE;AACvE;;;;;;;;GAQG;AACH,6EAA4D;AAC5D;;;;;;;;GAQG;AACH,qFAAoE;AACpE;;;;;;;;GAQG;AACH,yEAAwD;AACxD;;;;;;;;GAQG;AACH,qEAAoD;AACpD;;;;;;;;GAQG;AACH,6DAA4C;AAC5C;;;;;;;;GAQG;AACH,2DAA0C;AAC1C;;;;;;;;GAQG;AACH,mEAAkD;AAClD;;;;;;;;GAQG;AACH,yEAAwD;AACxD;;;;;;;;GAQG;AACH,yEAAwD;AACxD;;;;;;;;GAQG;AACH,2FAA0E;AAC1E;;;;;;;;GAQG;AACH,yEAAwD","sourcesContent":["export * as resourceDefinitionTypes from './types/resource-definitions'\n/**\n * ## Form Elements Service\n *\n * Helper functions for handling form elements\n *\n * ```js\n * import { formElementsService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as formElementsService from './formElementsService'\n/**\n * ## Conditional Logic Service\n *\n * Helper functions for handling conditional logic\n *\n * ```js\n * import { conditionalLogicService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as conditionalLogicService from './conditionalLogicService'\n/**\n * ## Submission Service\n *\n * Helper functions for handling form submission data\n *\n * ```js\n * import { submissionService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as submissionService from './submissionService'\n/**\n * ## Submission Service\n *\n * Helper functions for casting types\n *\n * ```js\n * import { typeCastService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as typeCastService from './typeCastService'\n/**\n * ## User Service\n *\n * Helper functions for handling users\n *\n * ```js\n * import { userService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as userService from './userService'\n/**\n * ## ABN Service\n *\n * Helper functions for handling ABN Records\n *\n * ```js\n * import { abnService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as abnService from './abnService'\n/**\n * ## Payment Service\n *\n * Helper functions for payments\n *\n * ```js\n * import { paymentService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as paymentService from './paymentService'\n/**\n * ## Scheduling Service\n *\n * Helper functions for scheduling\n *\n * ```js\n * import { schedulingService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as schedulingService from './schedulingService'\n/**\n * ## File Upload Service\n *\n * Helper functions for handling file uploads\n *\n * ```js\n * import { fileUploadService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as fileUploadService from './fileUploadService'\n/**\n * ## Webhook Subscription Service\n *\n * Helper functions for handling Webhook subscriptions\n *\n * ```js\n * import { webhookSubscriptionService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as webhookSubscriptionService from './webhookSubscriptionService'\n/**\n * ## SharePoint Service\n *\n * Helper functions for handling SharePoint\n *\n * ```js\n * import { sharepointService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as sharepointService from './sharepointService'\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wFAAuE;AACvE;;;;;;;;GAQG;AACH,6EAA4D;AAC5D;;;;;;;;GAQG;AACH,qFAAoE;AACpE;;;;;;;;GAQG;AACH,yEAAwD;AACxD;;;;;;;;GAQG;AACH,qEAAoD;AACpD;;;;;;;;GAQG;AACH,6DAA4C;AAC5C;;;;;;;;GAQG;AACH,2DAA0C;AAC1C;;;;;;;;GAQG;AACH,mEAAkD;AAClD;;;;;;;;GAQG;AACH,yEAAwD;AACxD;;;;;;;;GAQG;AACH,yEAAwD;AACxD;;;;;;;;GAQG;AACH,2FAA0E;AAC1E;;;;;;;;GAQG;AACH,yEAAwD;AAExD;;;;;;;;GAQG;AACH,uEAAsD","sourcesContent":["export * as resourceDefinitionTypes from './types/resource-definitions'\n/**\n * ## Form Elements Service\n *\n * Helper functions for handling form elements\n *\n * ```js\n * import { formElementsService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as formElementsService from './formElementsService'\n/**\n * ## Conditional Logic Service\n *\n * Helper functions for handling conditional logic\n *\n * ```js\n * import { conditionalLogicService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as conditionalLogicService from './conditionalLogicService'\n/**\n * ## Submission Service\n *\n * Helper functions for handling form submission data\n *\n * ```js\n * import { submissionService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as submissionService from './submissionService'\n/**\n * ## Submission Service\n *\n * Helper functions for casting types\n *\n * ```js\n * import { typeCastService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as typeCastService from './typeCastService'\n/**\n * ## User Service\n *\n * Helper functions for handling users\n *\n * ```js\n * import { userService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as userService from './userService'\n/**\n * ## ABN Service\n *\n * Helper functions for handling ABN Records\n *\n * ```js\n * import { abnService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as abnService from './abnService'\n/**\n * ## Payment Service\n *\n * Helper functions for payments\n *\n * ```js\n * import { paymentService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as paymentService from './paymentService'\n/**\n * ## Scheduling Service\n *\n * Helper functions for scheduling\n *\n * ```js\n * import { schedulingService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as schedulingService from './schedulingService'\n/**\n * ## File Upload Service\n *\n * Helper functions for handling file uploads\n *\n * ```js\n * import { fileUploadService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as fileUploadService from './fileUploadService'\n/**\n * ## Webhook Subscription Service\n *\n * Helper functions for handling Webhook subscriptions\n *\n * ```js\n * import { webhookSubscriptionService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as webhookSubscriptionService from './webhookSubscriptionService'\n/**\n * ## SharePoint Service\n *\n * Helper functions for handling SharePoint\n *\n * ```js\n * import { sharepointService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as sharepointService from './sharepointService'\n\n/**\n * ## Freshdesk Service\n *\n * Helper functions for handling Freshdesk\n *\n * ```js\n * import { freshdeskService } from '@oneblink/sdk-core'\n * ```\n */\nexport * as freshdeskService from './freshdeskService'\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-beta.
|
|
4
|
+
"version": "7.4.0-beta.3",
|
|
5
5
|
"author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/oneblink/sdk-core-js/issues"
|