n8n-nodes-hudu 1.3.5 → 1.4.1
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/README.md +28 -12
- package/dist/nodes/Hudu/Hudu.node.js +2 -18
- package/dist/nodes/Hudu/Hudu.node.js.map +1 -1
- package/dist/nodes/Hudu/Hudu.node.ts +2 -30
- package/dist/nodes/Hudu/descriptions/asset_layout_fields.description.js +38 -32
- package/dist/nodes/Hudu/descriptions/asset_layout_fields.description.js.map +1 -1
- package/dist/nodes/Hudu/descriptions/asset_layout_fields.description.ts +450 -446
- package/dist/nodes/Hudu/descriptions/asset_layouts.description.js +112 -18
- package/dist/nodes/Hudu/descriptions/asset_layouts.description.js.map +1 -1
- package/dist/nodes/Hudu/descriptions/asset_layouts.description.ts +112 -18
- package/dist/nodes/Hudu/descriptions/assets.description.js +100 -123
- package/dist/nodes/Hudu/descriptions/assets.description.js.map +1 -1
- package/dist/nodes/Hudu/descriptions/assets.description.ts +587 -609
- package/dist/nodes/Hudu/descriptions/index.js +0 -3
- package/dist/nodes/Hudu/descriptions/index.js.map +1 -1
- package/dist/nodes/Hudu/descriptions/index.ts +0 -3
- package/dist/nodes/Hudu/descriptions/resources.js +0 -12
- package/dist/nodes/Hudu/descriptions/resources.js.map +1 -1
- package/dist/nodes/Hudu/descriptions/resources.ts +0 -12
- package/dist/nodes/Hudu/optionLoaders/asset_layouts/getAssetLayoutFields.js +122 -70
- package/dist/nodes/Hudu/optionLoaders/asset_layouts/getAssetLayoutFields.js.map +1 -1
- package/dist/nodes/Hudu/optionLoaders/asset_layouts/getAssetLayoutFields.ts +143 -107
- package/dist/nodes/Hudu/optionLoaders/asset_layouts/index.js +0 -1
- package/dist/nodes/Hudu/optionLoaders/asset_layouts/index.js.map +1 -1
- package/dist/nodes/Hudu/optionLoaders/asset_layouts/index.ts +0 -1
- package/dist/nodes/Hudu/optionLoaders/assets/index.js +1 -2
- package/dist/nodes/Hudu/optionLoaders/assets/index.js.map +1 -1
- package/dist/nodes/Hudu/optionLoaders/assets/index.ts +1 -2
- package/dist/nodes/Hudu/resources/asset_layout_fields/asset_layout_fields.handler.js +32 -75
- package/dist/nodes/Hudu/resources/asset_layout_fields/asset_layout_fields.handler.js.map +1 -1
- package/dist/nodes/Hudu/resources/asset_layout_fields/asset_layout_fields.handler.ts +43 -139
- package/dist/nodes/Hudu/resources/asset_layouts/asset_layouts.handler.js +9 -11
- package/dist/nodes/Hudu/resources/asset_layouts/asset_layouts.handler.js.map +1 -1
- package/dist/nodes/Hudu/resources/asset_layouts/asset_layouts.handler.ts +12 -12
- package/dist/nodes/Hudu/resources/assets/assets.handler.js +116 -56
- package/dist/nodes/Hudu/resources/assets/assets.handler.js.map +1 -1
- package/dist/nodes/Hudu/resources/assets/assets.handler.ts +171 -60
- package/dist/nodes/Hudu/resources/assets/assets.types.ts +43 -43
- package/dist/nodes/Hudu/resources/index.js +0 -6
- package/dist/nodes/Hudu/resources/index.js.map +1 -1
- package/dist/nodes/Hudu/resources/index.ts +0 -12
- package/dist/nodes/Hudu/resources/procedures/procedures.handler.js +1 -3
- package/dist/nodes/Hudu/resources/procedures/procedures.handler.js.map +1 -1
- package/dist/nodes/Hudu/resources/procedures/procedures.handler.ts +1 -3
- package/dist/nodes/Hudu/utils/assetFieldUtils.js +273 -0
- package/dist/nodes/Hudu/utils/assetFieldUtils.js.map +1 -0
- package/dist/nodes/Hudu/utils/assetFieldUtils.ts +437 -0
- package/dist/nodes/Hudu/utils/constants.js +1 -0
- package/dist/nodes/Hudu/utils/constants.js.map +1 -1
- package/dist/nodes/Hudu/utils/constants.ts +1 -0
- package/dist/nodes/Hudu/utils/debugConfig.js +4 -1
- package/dist/nodes/Hudu/utils/debugConfig.js.map +1 -1
- package/dist/nodes/Hudu/utils/debugConfig.ts +6 -1
- package/dist/nodes/Hudu/utils/errorParser.js +57 -0
- package/dist/nodes/Hudu/utils/errorParser.js.map +1 -0
- package/dist/nodes/Hudu/utils/errorParser.ts +90 -0
- package/dist/nodes/Hudu/utils/fieldErrorUtils.js +17 -0
- package/dist/nodes/Hudu/utils/fieldErrorUtils.js.map +1 -0
- package/dist/nodes/Hudu/utils/fieldErrorUtils.ts +57 -0
- package/dist/nodes/Hudu/utils/fieldTypeUtils.js +145 -0
- package/dist/nodes/Hudu/utils/fieldTypeUtils.js.map +1 -0
- package/dist/nodes/Hudu/utils/fieldTypeUtils.ts +220 -0
- package/dist/nodes/Hudu/utils/index.js +3 -0
- package/dist/nodes/Hudu/utils/index.js.map +1 -1
- package/dist/nodes/Hudu/utils/index.ts +25 -19
- package/dist/nodes/Hudu/utils/requestUtils.js +71 -24
- package/dist/nodes/Hudu/utils/requestUtils.js.map +1 -1
- package/dist/nodes/Hudu/utils/requestUtils.ts +88 -26
- package/package.json +1 -1
- package/dist/nodes/Hudu/descriptions/HuduAssetCustomFieldDescription.js +0 -75
- package/dist/nodes/Hudu/descriptions/HuduAssetCustomFieldDescription.js.map +0 -1
- package/dist/nodes/Hudu/descriptions/HuduAssetCustomFieldDescription.ts +0 -73
- package/dist/nodes/Hudu/descriptions/HuduAssetLinkFieldDescription.js +0 -77
- package/dist/nodes/Hudu/descriptions/HuduAssetLinkFieldDescription.js.map +0 -1
- package/dist/nodes/Hudu/descriptions/HuduAssetLinkFieldDescription.ts +0 -75
- package/dist/nodes/Hudu/descriptions/HuduAssetStandardFieldDescription.js +0 -74
- package/dist/nodes/Hudu/descriptions/HuduAssetStandardFieldDescription.js.map +0 -1
- package/dist/nodes/Hudu/descriptions/HuduAssetStandardFieldDescription.ts +0 -72
- package/dist/nodes/Hudu/optionLoaders/asset_layouts/getAssetLinkFields.js +0 -51
- package/dist/nodes/Hudu/optionLoaders/asset_layouts/getAssetLinkFields.js.map +0 -1
- package/dist/nodes/Hudu/optionLoaders/asset_layouts/getAssetLinkFields.ts +0 -70
- package/dist/nodes/Hudu/optionLoaders/assets/getAssetCustomFields.js +0 -71
- package/dist/nodes/Hudu/optionLoaders/assets/getAssetCustomFields.js.map +0 -1
- package/dist/nodes/Hudu/optionLoaders/assets/getAssetCustomFields.ts +0 -80
- package/dist/nodes/Hudu/optionLoaders/assets/getLinkableAssets.js +0 -117
- package/dist/nodes/Hudu/optionLoaders/assets/getLinkableAssets.js.map +0 -1
- package/dist/nodes/Hudu/optionLoaders/assets/getLinkableAssets.ts +0 -147
- package/dist/nodes/Hudu/resources/assetCustomField/assetCustomField.handler.js +0 -222
- package/dist/nodes/Hudu/resources/assetCustomField/assetCustomField.handler.js.map +0 -1
- package/dist/nodes/Hudu/resources/assetCustomField/assetCustomField.handler.ts +0 -293
- package/dist/nodes/Hudu/resources/assetCustomField/assetCustomField.types.js +0 -3
- package/dist/nodes/Hudu/resources/assetCustomField/assetCustomField.types.js.map +0 -1
- package/dist/nodes/Hudu/resources/assetCustomField/assetCustomField.types.ts +0 -1
- package/dist/nodes/Hudu/resources/assetLinkField/assetLinkField.handler.js +0 -262
- package/dist/nodes/Hudu/resources/assetLinkField/assetLinkField.handler.js.map +0 -1
- package/dist/nodes/Hudu/resources/assetLinkField/assetLinkField.handler.ts +0 -363
- package/dist/nodes/Hudu/resources/assetLinkField/assetLinkField.types.js +0 -3
- package/dist/nodes/Hudu/resources/assetLinkField/assetLinkField.types.js.map +0 -1
- package/dist/nodes/Hudu/resources/assetLinkField/assetLinkField.types.ts +0 -1
- package/dist/nodes/Hudu/resources/assetStandardField/assetStandardField.handler.js +0 -93
- package/dist/nodes/Hudu/resources/assetStandardField/assetStandardField.handler.js.map +0 -1
- package/dist/nodes/Hudu/resources/assetStandardField/assetStandardField.handler.ts +0 -141
- package/dist/nodes/Hudu/resources/assetStandardField/assetStandardField.types.js +0 -3
- package/dist/nodes/Hudu/resources/assetStandardField/assetStandardField.types.js.map +0 -1
- package/dist/nodes/Hudu/resources/assetStandardField/assetStandardField.types.ts +0 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { NodeApiError } from 'n8n-workflow';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Parses a Hudu API error message to extract meaningful details
|
|
5
|
+
* @param error The NodeApiError from the API
|
|
6
|
+
* @returns A user-friendly error message with specific details
|
|
7
|
+
*/
|
|
8
|
+
export function parseHuduApiError(error: NodeApiError): string {
|
|
9
|
+
if (!error) {
|
|
10
|
+
return 'An unknown error occurred';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// NodeApiError stores detailed messages in the description field, not message
|
|
14
|
+
const message = error.description || error.message || 'An unknown error occurred';
|
|
15
|
+
|
|
16
|
+
// Try to extract JSON from the error message
|
|
17
|
+
// Format is typically: "422 - {"error":"Invalid custom fields","details":["Invalid field names: 361, 363"]}"
|
|
18
|
+
const jsonMatch = message.match(/\{.*\}$/);
|
|
19
|
+
|
|
20
|
+
if (jsonMatch) {
|
|
21
|
+
try {
|
|
22
|
+
const errorData = JSON.parse(jsonMatch[0]);
|
|
23
|
+
|
|
24
|
+
if (errorData.error) {
|
|
25
|
+
let parsedMessage = errorData.error;
|
|
26
|
+
|
|
27
|
+
if (errorData.details && Array.isArray(errorData.details)) {
|
|
28
|
+
const detailsString = errorData.details.join(', ');
|
|
29
|
+
parsedMessage += `. Details: ${detailsString}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return parsedMessage;
|
|
33
|
+
}
|
|
34
|
+
} catch (parseError) {
|
|
35
|
+
// If JSON parsing fails, fall through to default handling
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// If we can't parse the JSON, try to extract just the status code and return a cleaner message
|
|
40
|
+
const statusMatch = message.match(/^(\d{3})\s*-\s*/);
|
|
41
|
+
if (statusMatch) {
|
|
42
|
+
const statusCode = statusMatch[1];
|
|
43
|
+
const remainingMessage = message.replace(statusMatch[0], '').trim();
|
|
44
|
+
|
|
45
|
+
// If there's a meaningful message after the status code, use it
|
|
46
|
+
if (remainingMessage && remainingMessage !== '{}') {
|
|
47
|
+
return `HTTP ${statusCode}: ${remainingMessage}`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Otherwise, provide a generic message based on status code
|
|
51
|
+
switch (statusCode) {
|
|
52
|
+
case '422':
|
|
53
|
+
return 'Unprocessable Entity: The request was well-formed but contains semantic errors';
|
|
54
|
+
case '400':
|
|
55
|
+
return 'Bad Request: The request was malformed or contains invalid parameters';
|
|
56
|
+
case '404':
|
|
57
|
+
return 'Not Found: The requested resource does not exist';
|
|
58
|
+
case '401':
|
|
59
|
+
return 'Unauthorized: Invalid or missing API credentials';
|
|
60
|
+
case '403':
|
|
61
|
+
return 'Forbidden: You do not have permission to access this resource';
|
|
62
|
+
default:
|
|
63
|
+
return `HTTP ${statusCode}: ${remainingMessage || 'An error occurred'}`;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// If all else fails, return the original message
|
|
68
|
+
return message;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Parses a Hudu API error with additional context for specific operations
|
|
73
|
+
* @param error The NodeApiError from the API
|
|
74
|
+
* @param operation The operation that was being performed (e.g., 'create', 'update')
|
|
75
|
+
* @param context Additional context about what was being processed
|
|
76
|
+
* @returns A user-friendly error message with operation context
|
|
77
|
+
*/
|
|
78
|
+
export function parseHuduApiErrorWithContext(
|
|
79
|
+
error: NodeApiError,
|
|
80
|
+
operation: string,
|
|
81
|
+
context?: string
|
|
82
|
+
): string {
|
|
83
|
+
const baseMessage = parseHuduApiError(error);
|
|
84
|
+
|
|
85
|
+
// Add operation context
|
|
86
|
+
const operationText = operation ? ` during ${operation} operation` : '';
|
|
87
|
+
const contextText = context ? ` (${context})` : '';
|
|
88
|
+
|
|
89
|
+
return `${baseMessage}${operationText}${contextText}`;
|
|
90
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createFieldValidationError = exports.createAssetNotFoundError = exports.createFieldMappingError = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
function createFieldMappingError(fieldIdentifier, reason, context, itemIndex) {
|
|
6
|
+
return new n8n_workflow_1.NodeOperationError(context, `Field mapping error for '${fieldIdentifier}': ${reason}`, { itemIndex });
|
|
7
|
+
}
|
|
8
|
+
exports.createFieldMappingError = createFieldMappingError;
|
|
9
|
+
function createAssetNotFoundError(assetId, context, itemIndex) {
|
|
10
|
+
return new n8n_workflow_1.NodeOperationError(context, `Asset with ID '${assetId}' not found.`, { itemIndex });
|
|
11
|
+
}
|
|
12
|
+
exports.createAssetNotFoundError = createAssetNotFoundError;
|
|
13
|
+
function createFieldValidationError(fieldIdentifier, fieldType, context, itemIndex) {
|
|
14
|
+
return new n8n_workflow_1.NodeOperationError(context, `Validation failed for field '${fieldIdentifier}' of type '${fieldType}'.`, { itemIndex });
|
|
15
|
+
}
|
|
16
|
+
exports.createFieldValidationError = createFieldValidationError;
|
|
17
|
+
//# sourceMappingURL=fieldErrorUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fieldErrorUtils.js","sourceRoot":"","sources":["../../../../../src/nodes/Hudu/utils/fieldErrorUtils.ts"],"names":[],"mappings":";;;AACA,+CAAkD;AAWlD,SAAgB,uBAAuB,CACrC,eAAuB,EACvB,MAAc,EACd,OAAc,EACd,SAAkB;IAGlB,OAAO,IAAI,iCAAkB,CAAC,OAAO,EAAE,4BAA4B,eAAe,MAAM,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;AACnH,CAAC;AARD,0DAQC;AAUD,SAAgB,wBAAwB,CACtC,OAAe,EACf,OAAc,EACd,SAAkB;IAGlB,OAAO,IAAI,iCAAkB,CAAC,OAAO,EAAE,kBAAkB,OAAO,cAAc,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;AACjG,CAAC;AAPD,4DAOC;AAWD,SAAgB,0BAA0B,CACxC,eAAuB,EACvB,SAAiB,EACjB,OAAc,EACd,SAAkB;IAGlB,OAAO,IAAI,iCAAkB,CAAC,OAAO,EAAE,gCAAgC,eAAe,cAAc,SAAS,IAAI,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;AACpI,CAAC;AARD,gEAQC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { INode } from 'n8n-workflow';
|
|
2
|
+
import { NodeOperationError } from 'n8n-workflow';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Creates a NodeOperationError for field mapping errors.
|
|
6
|
+
*
|
|
7
|
+
* @param fieldIdentifier The field label or ID
|
|
8
|
+
* @param reason The reason for the error
|
|
9
|
+
* @param context The n8n node context
|
|
10
|
+
* @param itemIndex Optional item index for error context
|
|
11
|
+
* @returns NodeOperationError
|
|
12
|
+
*/
|
|
13
|
+
export function createFieldMappingError(
|
|
14
|
+
fieldIdentifier: string,
|
|
15
|
+
reason: string,
|
|
16
|
+
context: INode,
|
|
17
|
+
itemIndex?: number
|
|
18
|
+
): NodeOperationError {
|
|
19
|
+
// TODO: Implement detailed error message and logging
|
|
20
|
+
return new NodeOperationError(context, `Field mapping error for '${fieldIdentifier}': ${reason}`, { itemIndex });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Creates a NodeOperationError for asset not found errors.
|
|
25
|
+
*
|
|
26
|
+
* @param assetId The asset ID
|
|
27
|
+
* @param context The n8n node context
|
|
28
|
+
* @param itemIndex Optional item index for error context
|
|
29
|
+
* @returns NodeOperationError
|
|
30
|
+
*/
|
|
31
|
+
export function createAssetNotFoundError(
|
|
32
|
+
assetId: number,
|
|
33
|
+
context: INode,
|
|
34
|
+
itemIndex?: number
|
|
35
|
+
): NodeOperationError {
|
|
36
|
+
// TODO: Implement detailed error message and logging
|
|
37
|
+
return new NodeOperationError(context, `Asset with ID '${assetId}' not found.`, { itemIndex });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Creates a NodeOperationError for field validation errors.
|
|
42
|
+
*
|
|
43
|
+
* @param fieldIdentifier The field label or ID
|
|
44
|
+
* @param fieldType The type of the field
|
|
45
|
+
* @param context The n8n node context
|
|
46
|
+
* @param itemIndex Optional item index for error context
|
|
47
|
+
* @returns NodeOperationError
|
|
48
|
+
*/
|
|
49
|
+
export function createFieldValidationError(
|
|
50
|
+
fieldIdentifier: string,
|
|
51
|
+
fieldType: string,
|
|
52
|
+
context: INode,
|
|
53
|
+
itemIndex?: number
|
|
54
|
+
): NodeOperationError {
|
|
55
|
+
// TODO: Implement detailed error message and logging
|
|
56
|
+
return new NodeOperationError(context, `Validation failed for field '${fieldIdentifier}' of type '${fieldType}'.`, { itemIndex });
|
|
57
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getExpectedJavaScriptType = exports.isFieldTypeUpdatable = exports.normaliseFieldType = exports.detectFieldType = exports.isLinkField = exports.isCustomField = exports.isStandardField = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const STANDARD_ASSET_FIELDS = [
|
|
6
|
+
'name',
|
|
7
|
+
'primary_serial',
|
|
8
|
+
'primary_mail',
|
|
9
|
+
'primary_model',
|
|
10
|
+
'primary_manufacturer',
|
|
11
|
+
'hostname',
|
|
12
|
+
'notes',
|
|
13
|
+
'asset_layout_id',
|
|
14
|
+
'company_id',
|
|
15
|
+
'archived',
|
|
16
|
+
'created_at',
|
|
17
|
+
'updated_at',
|
|
18
|
+
'slug',
|
|
19
|
+
'url',
|
|
20
|
+
];
|
|
21
|
+
function isStandardField(fieldName) {
|
|
22
|
+
return STANDARD_ASSET_FIELDS.includes(fieldName);
|
|
23
|
+
}
|
|
24
|
+
exports.isStandardField = isStandardField;
|
|
25
|
+
function isCustomField(field) {
|
|
26
|
+
if (!field || typeof field !== 'object') {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
if (!field.field_type || typeof field.field_type !== 'string') {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (field.field_type === constants_1.ASSET_LAYOUT_FIELD_TYPES.ASSET_TAG) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
const customFieldTypes = [
|
|
36
|
+
constants_1.ASSET_LAYOUT_FIELD_TYPES.TEXT,
|
|
37
|
+
constants_1.ASSET_LAYOUT_FIELD_TYPES.RICH_TEXT,
|
|
38
|
+
constants_1.ASSET_LAYOUT_FIELD_TYPES.HEADING,
|
|
39
|
+
constants_1.ASSET_LAYOUT_FIELD_TYPES.CHECKBOX,
|
|
40
|
+
constants_1.ASSET_LAYOUT_FIELD_TYPES.WEBSITE,
|
|
41
|
+
constants_1.ASSET_LAYOUT_FIELD_TYPES.PASSWORD,
|
|
42
|
+
constants_1.ASSET_LAYOUT_FIELD_TYPES.NUMBER,
|
|
43
|
+
constants_1.ASSET_LAYOUT_FIELD_TYPES.DATE,
|
|
44
|
+
constants_1.ASSET_LAYOUT_FIELD_TYPES.LIST_SELECT,
|
|
45
|
+
constants_1.ASSET_LAYOUT_FIELD_TYPES.EMBED,
|
|
46
|
+
constants_1.ASSET_LAYOUT_FIELD_TYPES.EMAIL,
|
|
47
|
+
constants_1.ASSET_LAYOUT_FIELD_TYPES.PHONE,
|
|
48
|
+
constants_1.ASSET_LAYOUT_FIELD_TYPES.ADDRESS_DATA,
|
|
49
|
+
constants_1.ASSET_LAYOUT_FIELD_TYPES.DROPDOWN,
|
|
50
|
+
constants_1.ASSET_LAYOUT_FIELD_TYPES.RELATION,
|
|
51
|
+
];
|
|
52
|
+
return customFieldTypes.includes(field.field_type);
|
|
53
|
+
}
|
|
54
|
+
exports.isCustomField = isCustomField;
|
|
55
|
+
function isLinkField(field) {
|
|
56
|
+
if (!field || typeof field !== 'object') {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
return field.field_type === constants_1.ASSET_LAYOUT_FIELD_TYPES.ASSET_TAG;
|
|
60
|
+
}
|
|
61
|
+
exports.isLinkField = isLinkField;
|
|
62
|
+
function detectFieldType(field) {
|
|
63
|
+
if (field.label && typeof field.label === 'string' && isStandardField(field.label)) {
|
|
64
|
+
return 'standard';
|
|
65
|
+
}
|
|
66
|
+
if (isLinkField(field)) {
|
|
67
|
+
return 'link';
|
|
68
|
+
}
|
|
69
|
+
if (isCustomField(field)) {
|
|
70
|
+
return 'custom';
|
|
71
|
+
}
|
|
72
|
+
return 'custom';
|
|
73
|
+
}
|
|
74
|
+
exports.detectFieldType = detectFieldType;
|
|
75
|
+
function normaliseFieldType(fieldType) {
|
|
76
|
+
if (!fieldType || typeof fieldType !== 'string') {
|
|
77
|
+
return constants_1.ASSET_LAYOUT_FIELD_TYPES.TEXT;
|
|
78
|
+
}
|
|
79
|
+
const normalised = fieldType.trim();
|
|
80
|
+
const typeMap = {
|
|
81
|
+
'checkbox': constants_1.ASSET_LAYOUT_FIELD_TYPES.CHECKBOX,
|
|
82
|
+
'CheckBox': constants_1.ASSET_LAYOUT_FIELD_TYPES.CHECKBOX,
|
|
83
|
+
'check_box': constants_1.ASSET_LAYOUT_FIELD_TYPES.CHECKBOX,
|
|
84
|
+
'text': constants_1.ASSET_LAYOUT_FIELD_TYPES.TEXT,
|
|
85
|
+
'Text': constants_1.ASSET_LAYOUT_FIELD_TYPES.TEXT,
|
|
86
|
+
'richtext': constants_1.ASSET_LAYOUT_FIELD_TYPES.RICH_TEXT,
|
|
87
|
+
'RichText': constants_1.ASSET_LAYOUT_FIELD_TYPES.RICH_TEXT,
|
|
88
|
+
'rich_text': constants_1.ASSET_LAYOUT_FIELD_TYPES.RICH_TEXT,
|
|
89
|
+
'number': constants_1.ASSET_LAYOUT_FIELD_TYPES.NUMBER,
|
|
90
|
+
'Number': constants_1.ASSET_LAYOUT_FIELD_TYPES.NUMBER,
|
|
91
|
+
'date': constants_1.ASSET_LAYOUT_FIELD_TYPES.DATE,
|
|
92
|
+
'Date': constants_1.ASSET_LAYOUT_FIELD_TYPES.DATE,
|
|
93
|
+
'website': constants_1.ASSET_LAYOUT_FIELD_TYPES.WEBSITE,
|
|
94
|
+
'Website': constants_1.ASSET_LAYOUT_FIELD_TYPES.WEBSITE,
|
|
95
|
+
'password': constants_1.ASSET_LAYOUT_FIELD_TYPES.PASSWORD,
|
|
96
|
+
'Password': constants_1.ASSET_LAYOUT_FIELD_TYPES.PASSWORD,
|
|
97
|
+
'email': constants_1.ASSET_LAYOUT_FIELD_TYPES.EMAIL,
|
|
98
|
+
'Email': constants_1.ASSET_LAYOUT_FIELD_TYPES.EMAIL,
|
|
99
|
+
'phone': constants_1.ASSET_LAYOUT_FIELD_TYPES.PHONE,
|
|
100
|
+
'Phone': constants_1.ASSET_LAYOUT_FIELD_TYPES.PHONE,
|
|
101
|
+
'assettag': constants_1.ASSET_LAYOUT_FIELD_TYPES.ASSET_TAG,
|
|
102
|
+
'AssetTag': constants_1.ASSET_LAYOUT_FIELD_TYPES.ASSET_TAG,
|
|
103
|
+
'asset_tag': constants_1.ASSET_LAYOUT_FIELD_TYPES.ASSET_TAG,
|
|
104
|
+
'listselect': constants_1.ASSET_LAYOUT_FIELD_TYPES.LIST_SELECT,
|
|
105
|
+
'ListSelect': constants_1.ASSET_LAYOUT_FIELD_TYPES.LIST_SELECT,
|
|
106
|
+
'list_select': constants_1.ASSET_LAYOUT_FIELD_TYPES.LIST_SELECT,
|
|
107
|
+
'dropdown': constants_1.ASSET_LAYOUT_FIELD_TYPES.DROPDOWN,
|
|
108
|
+
'Dropdown': constants_1.ASSET_LAYOUT_FIELD_TYPES.DROPDOWN,
|
|
109
|
+
'relation': constants_1.ASSET_LAYOUT_FIELD_TYPES.RELATION,
|
|
110
|
+
'Relation': constants_1.ASSET_LAYOUT_FIELD_TYPES.RELATION,
|
|
111
|
+
'embed': constants_1.ASSET_LAYOUT_FIELD_TYPES.EMBED,
|
|
112
|
+
'Embed': constants_1.ASSET_LAYOUT_FIELD_TYPES.EMBED,
|
|
113
|
+
'heading': constants_1.ASSET_LAYOUT_FIELD_TYPES.HEADING,
|
|
114
|
+
'Heading': constants_1.ASSET_LAYOUT_FIELD_TYPES.HEADING,
|
|
115
|
+
'addressdata': constants_1.ASSET_LAYOUT_FIELD_TYPES.ADDRESS_DATA,
|
|
116
|
+
'AddressData': constants_1.ASSET_LAYOUT_FIELD_TYPES.ADDRESS_DATA,
|
|
117
|
+
'address_data': constants_1.ASSET_LAYOUT_FIELD_TYPES.ADDRESS_DATA,
|
|
118
|
+
};
|
|
119
|
+
return typeMap[normalised] || normalised;
|
|
120
|
+
}
|
|
121
|
+
exports.normaliseFieldType = normaliseFieldType;
|
|
122
|
+
function isFieldTypeUpdatable(fieldType) {
|
|
123
|
+
const unsupportedTypes = [
|
|
124
|
+
constants_1.ASSET_LAYOUT_FIELD_TYPES.DROPDOWN,
|
|
125
|
+
constants_1.ASSET_LAYOUT_FIELD_TYPES.HEADING,
|
|
126
|
+
];
|
|
127
|
+
const normalisedType = normaliseFieldType(fieldType);
|
|
128
|
+
return !unsupportedTypes.includes(normalisedType);
|
|
129
|
+
}
|
|
130
|
+
exports.isFieldTypeUpdatable = isFieldTypeUpdatable;
|
|
131
|
+
function getExpectedJavaScriptType(fieldType) {
|
|
132
|
+
const normalisedType = normaliseFieldType(fieldType);
|
|
133
|
+
switch (normalisedType) {
|
|
134
|
+
case constants_1.ASSET_LAYOUT_FIELD_TYPES.CHECKBOX:
|
|
135
|
+
return 'boolean';
|
|
136
|
+
case constants_1.ASSET_LAYOUT_FIELD_TYPES.NUMBER:
|
|
137
|
+
return 'number';
|
|
138
|
+
case constants_1.ASSET_LAYOUT_FIELD_TYPES.ADDRESS_DATA:
|
|
139
|
+
return 'object';
|
|
140
|
+
default:
|
|
141
|
+
return 'string';
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.getExpectedJavaScriptType = getExpectedJavaScriptType;
|
|
145
|
+
//# sourceMappingURL=fieldTypeUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|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AAgB,oBAAoB,CAAC,SAAiB;IACpD,MAAM,gBAAgB,GAAa;QACjC,oCAAwB,CAAC,QAAQ;QACjC,oCAAwB,CAAC,OAAO;KACjC,CAAC;IAEF,MAAM,cAAc,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;IACrD,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;AACpD,CAAC;AARD,oDAQC;AASD,SAAgB,yBAAyB,CAAC,SAAiB;IACzD,MAAM,cAAc,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAErD,QAAQ,cAAc,EAAE;QACtB,KAAK,oCAAwB,CAAC,QAAQ;YACpC,OAAO,SAAS,CAAC;QACnB,KAAK,oCAAwB,CAAC,MAAM;YAClC,OAAO,QAAQ,CAAC;QAClB,KAAK,oCAAwB,CAAC,YAAY;YACxC,OAAO,QAAQ,CAAC;QAClB;YACE,OAAO,QAAQ,CAAC;KACnB;AACH,CAAC;AAbD,8DAaC"}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import type { IDataObject } from 'n8n-workflow';
|
|
2
|
+
import { ASSET_LAYOUT_FIELD_TYPES } from './constants';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Standard asset fields that are top-level properties of the asset object.
|
|
6
|
+
* These fields don't require snake_case conversion and are directly accessible.
|
|
7
|
+
*/
|
|
8
|
+
const STANDARD_ASSET_FIELDS = [
|
|
9
|
+
'name',
|
|
10
|
+
'primary_serial',
|
|
11
|
+
'primary_mail',
|
|
12
|
+
'primary_model',
|
|
13
|
+
'primary_manufacturer',
|
|
14
|
+
'hostname',
|
|
15
|
+
'notes',
|
|
16
|
+
'asset_layout_id',
|
|
17
|
+
'company_id',
|
|
18
|
+
'archived',
|
|
19
|
+
'created_at',
|
|
20
|
+
'updated_at',
|
|
21
|
+
'slug',
|
|
22
|
+
'url',
|
|
23
|
+
] as const;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Determines if a field name corresponds to a standard asset field.
|
|
27
|
+
* Standard fields are top-level properties of the asset object.
|
|
28
|
+
*
|
|
29
|
+
* @param fieldName The field name to check
|
|
30
|
+
* @returns True if the field is a standard asset field
|
|
31
|
+
*/
|
|
32
|
+
export function isStandardField(fieldName: string): boolean {
|
|
33
|
+
return STANDARD_ASSET_FIELDS.includes(fieldName as any);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Determines if a field object represents a custom field.
|
|
38
|
+
* Custom fields are defined in asset layouts and appear in the asset.fields array.
|
|
39
|
+
* They have field_type properties that are not 'AssetTag'.
|
|
40
|
+
*
|
|
41
|
+
* @param field The field object to check
|
|
42
|
+
* @returns True if the field is a custom field
|
|
43
|
+
*/
|
|
44
|
+
export function isCustomField(field: IDataObject): boolean {
|
|
45
|
+
if (!field || typeof field !== 'object') {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Must have a field_type property
|
|
50
|
+
if (!field.field_type || typeof field.field_type !== 'string') {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Must not be an AssetTag (which is a link field)
|
|
55
|
+
if (field.field_type === ASSET_LAYOUT_FIELD_TYPES.ASSET_TAG) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Must be a recognised custom field type
|
|
60
|
+
const customFieldTypes = [
|
|
61
|
+
ASSET_LAYOUT_FIELD_TYPES.TEXT,
|
|
62
|
+
ASSET_LAYOUT_FIELD_TYPES.RICH_TEXT,
|
|
63
|
+
ASSET_LAYOUT_FIELD_TYPES.HEADING,
|
|
64
|
+
ASSET_LAYOUT_FIELD_TYPES.CHECKBOX,
|
|
65
|
+
ASSET_LAYOUT_FIELD_TYPES.WEBSITE,
|
|
66
|
+
ASSET_LAYOUT_FIELD_TYPES.PASSWORD,
|
|
67
|
+
ASSET_LAYOUT_FIELD_TYPES.NUMBER,
|
|
68
|
+
ASSET_LAYOUT_FIELD_TYPES.DATE,
|
|
69
|
+
ASSET_LAYOUT_FIELD_TYPES.LIST_SELECT,
|
|
70
|
+
ASSET_LAYOUT_FIELD_TYPES.EMBED,
|
|
71
|
+
ASSET_LAYOUT_FIELD_TYPES.EMAIL,
|
|
72
|
+
ASSET_LAYOUT_FIELD_TYPES.PHONE,
|
|
73
|
+
ASSET_LAYOUT_FIELD_TYPES.ADDRESS_DATA,
|
|
74
|
+
ASSET_LAYOUT_FIELD_TYPES.DROPDOWN,
|
|
75
|
+
ASSET_LAYOUT_FIELD_TYPES.RELATION,
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
return customFieldTypes.includes(field.field_type as any);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Determines if a field object represents a link field (AssetTag).
|
|
83
|
+
* Link fields connect assets to other assets and have special handling.
|
|
84
|
+
*
|
|
85
|
+
* @param field The field object to check
|
|
86
|
+
* @returns True if the field is a link field
|
|
87
|
+
*/
|
|
88
|
+
export function isLinkField(field: IDataObject): boolean {
|
|
89
|
+
if (!field || typeof field !== 'object') {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return field.field_type === ASSET_LAYOUT_FIELD_TYPES.ASSET_TAG;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Detects the type of a field based on its properties.
|
|
98
|
+
* This is used for field classification in resource mappers and validation.
|
|
99
|
+
*
|
|
100
|
+
* @param field The field object to analyse
|
|
101
|
+
* @returns The detected field type: 'standard', 'custom', or 'link'
|
|
102
|
+
*/
|
|
103
|
+
export function detectFieldType(field: IDataObject): 'standard' | 'custom' | 'link' {
|
|
104
|
+
// Check if it's a standard field by name
|
|
105
|
+
if (field.label && typeof field.label === 'string' && isStandardField(field.label)) {
|
|
106
|
+
return 'standard';
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Check if it's a link field
|
|
110
|
+
if (isLinkField(field)) {
|
|
111
|
+
return 'link';
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Check if it's a custom field
|
|
115
|
+
if (isCustomField(field)) {
|
|
116
|
+
return 'custom';
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Default to custom for unknown field types
|
|
120
|
+
return 'custom';
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Normalises field type strings to handle case variations and aliases.
|
|
125
|
+
* This ensures consistent field type handling across the application.
|
|
126
|
+
*
|
|
127
|
+
* @param fieldType The field type string to normalise
|
|
128
|
+
* @returns The normalised field type string
|
|
129
|
+
*/
|
|
130
|
+
export function normaliseFieldType(fieldType: string): string {
|
|
131
|
+
if (!fieldType || typeof fieldType !== 'string') {
|
|
132
|
+
return ASSET_LAYOUT_FIELD_TYPES.TEXT; // Default fallback
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Handle case variations
|
|
136
|
+
const normalised = fieldType.trim();
|
|
137
|
+
|
|
138
|
+
// Map common variations to standard types
|
|
139
|
+
const typeMap: Record<string, string> = {
|
|
140
|
+
'checkbox': ASSET_LAYOUT_FIELD_TYPES.CHECKBOX,
|
|
141
|
+
'CheckBox': ASSET_LAYOUT_FIELD_TYPES.CHECKBOX,
|
|
142
|
+
'check_box': ASSET_LAYOUT_FIELD_TYPES.CHECKBOX,
|
|
143
|
+
'text': ASSET_LAYOUT_FIELD_TYPES.TEXT,
|
|
144
|
+
'Text': ASSET_LAYOUT_FIELD_TYPES.TEXT,
|
|
145
|
+
'richtext': ASSET_LAYOUT_FIELD_TYPES.RICH_TEXT,
|
|
146
|
+
'RichText': ASSET_LAYOUT_FIELD_TYPES.RICH_TEXT,
|
|
147
|
+
'rich_text': ASSET_LAYOUT_FIELD_TYPES.RICH_TEXT,
|
|
148
|
+
'number': ASSET_LAYOUT_FIELD_TYPES.NUMBER,
|
|
149
|
+
'Number': ASSET_LAYOUT_FIELD_TYPES.NUMBER,
|
|
150
|
+
'date': ASSET_LAYOUT_FIELD_TYPES.DATE,
|
|
151
|
+
'Date': ASSET_LAYOUT_FIELD_TYPES.DATE,
|
|
152
|
+
'website': ASSET_LAYOUT_FIELD_TYPES.WEBSITE,
|
|
153
|
+
'Website': ASSET_LAYOUT_FIELD_TYPES.WEBSITE,
|
|
154
|
+
'password': ASSET_LAYOUT_FIELD_TYPES.PASSWORD,
|
|
155
|
+
'Password': ASSET_LAYOUT_FIELD_TYPES.PASSWORD,
|
|
156
|
+
'email': ASSET_LAYOUT_FIELD_TYPES.EMAIL,
|
|
157
|
+
'Email': ASSET_LAYOUT_FIELD_TYPES.EMAIL,
|
|
158
|
+
'phone': ASSET_LAYOUT_FIELD_TYPES.PHONE,
|
|
159
|
+
'Phone': ASSET_LAYOUT_FIELD_TYPES.PHONE,
|
|
160
|
+
'assettag': ASSET_LAYOUT_FIELD_TYPES.ASSET_TAG,
|
|
161
|
+
'AssetTag': ASSET_LAYOUT_FIELD_TYPES.ASSET_TAG,
|
|
162
|
+
'asset_tag': ASSET_LAYOUT_FIELD_TYPES.ASSET_TAG,
|
|
163
|
+
'listselect': ASSET_LAYOUT_FIELD_TYPES.LIST_SELECT,
|
|
164
|
+
'ListSelect': ASSET_LAYOUT_FIELD_TYPES.LIST_SELECT,
|
|
165
|
+
'list_select': ASSET_LAYOUT_FIELD_TYPES.LIST_SELECT,
|
|
166
|
+
'dropdown': ASSET_LAYOUT_FIELD_TYPES.DROPDOWN,
|
|
167
|
+
'Dropdown': ASSET_LAYOUT_FIELD_TYPES.DROPDOWN,
|
|
168
|
+
'relation': ASSET_LAYOUT_FIELD_TYPES.RELATION,
|
|
169
|
+
'Relation': ASSET_LAYOUT_FIELD_TYPES.RELATION,
|
|
170
|
+
'embed': ASSET_LAYOUT_FIELD_TYPES.EMBED,
|
|
171
|
+
'Embed': ASSET_LAYOUT_FIELD_TYPES.EMBED,
|
|
172
|
+
'heading': ASSET_LAYOUT_FIELD_TYPES.HEADING,
|
|
173
|
+
'Heading': ASSET_LAYOUT_FIELD_TYPES.HEADING,
|
|
174
|
+
'addressdata': ASSET_LAYOUT_FIELD_TYPES.ADDRESS_DATA,
|
|
175
|
+
'AddressData': ASSET_LAYOUT_FIELD_TYPES.ADDRESS_DATA,
|
|
176
|
+
'address_data': ASSET_LAYOUT_FIELD_TYPES.ADDRESS_DATA,
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// Return mapped type or original if no mapping found
|
|
180
|
+
return typeMap[normalised] || normalised;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Validates that a field type is supported for updates.
|
|
185
|
+
* Some legacy field types (like Dropdown) cannot be updated via the API.
|
|
186
|
+
*
|
|
187
|
+
* @param fieldType The field type to validate
|
|
188
|
+
* @returns True if the field type supports updates
|
|
189
|
+
*/
|
|
190
|
+
export function isFieldTypeUpdatable(fieldType: string): boolean {
|
|
191
|
+
const unsupportedTypes: string[] = [
|
|
192
|
+
ASSET_LAYOUT_FIELD_TYPES.DROPDOWN, // Legacy field type
|
|
193
|
+
ASSET_LAYOUT_FIELD_TYPES.HEADING, // Display-only field
|
|
194
|
+
];
|
|
195
|
+
|
|
196
|
+
const normalisedType = normaliseFieldType(fieldType);
|
|
197
|
+
return !unsupportedTypes.includes(normalisedType);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Gets the expected JavaScript type for a given Hudu field type.
|
|
202
|
+
* This is used for validation and transformation in resource mappers.
|
|
203
|
+
*
|
|
204
|
+
* @param fieldType The Hudu field type
|
|
205
|
+
* @returns The expected JavaScript type
|
|
206
|
+
*/
|
|
207
|
+
export function getExpectedJavaScriptType(fieldType: string): string {
|
|
208
|
+
const normalisedType = normaliseFieldType(fieldType);
|
|
209
|
+
|
|
210
|
+
switch (normalisedType) {
|
|
211
|
+
case ASSET_LAYOUT_FIELD_TYPES.CHECKBOX:
|
|
212
|
+
return 'boolean';
|
|
213
|
+
case ASSET_LAYOUT_FIELD_TYPES.NUMBER:
|
|
214
|
+
return 'number';
|
|
215
|
+
case ASSET_LAYOUT_FIELD_TYPES.ADDRESS_DATA:
|
|
216
|
+
return 'object'; // Address object
|
|
217
|
+
default:
|
|
218
|
+
return 'string'; // Most fields, including AssetTag, Relation, Date, and ListSelect, default to string
|
|
219
|
+
}
|
|
220
|
+
}
|
|
@@ -19,4 +19,7 @@ __exportStar(require("./requestUtils"), exports);
|
|
|
19
19
|
__exportStar(require("./filterUtils"), exports);
|
|
20
20
|
__exportStar(require("./constants"), exports);
|
|
21
21
|
__exportStar(require("./validation"), exports);
|
|
22
|
+
__exportStar(require("./fieldTypeUtils"), exports);
|
|
23
|
+
__exportStar(require("./assetFieldUtils"), exports);
|
|
24
|
+
__exportStar(require("./fieldErrorUtils"), exports);
|
|
22
25
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/nodes/Hudu/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/nodes/Hudu/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAiBA,8CAA4B;AAC5B,iDAA+B;AAC/B,gDAA8B;AAC9B,8CAA4B;AAC5B,+CAA6B;AAC7B,mDAAiC;AACjC,oDAAkC;AAClC,oDAAkC"}
|
|
@@ -1,19 +1,25 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Central export point for Hudu integration utilities
|
|
3
|
-
*
|
|
4
|
-
* Exports:
|
|
5
|
-
* - Date utilities (dateUtils.ts)
|
|
6
|
-
* - HTTP request utilities (requestUtils.ts)
|
|
7
|
-
* - Filter utilities (filterUtils.ts)
|
|
8
|
-
* - Constants and configuration (constants.ts)
|
|
9
|
-
* - Validation utilities (validation.ts)
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export * from './
|
|
19
|
-
export * from './
|
|
1
|
+
/**
|
|
2
|
+
* Central export point for Hudu integration utilities
|
|
3
|
+
*
|
|
4
|
+
* Exports:
|
|
5
|
+
* - Date utilities (dateUtils.ts)
|
|
6
|
+
* - HTTP request utilities (requestUtils.ts)
|
|
7
|
+
* - Filter utilities (filterUtils.ts)
|
|
8
|
+
* - Constants and configuration (constants.ts)
|
|
9
|
+
* - Validation utilities (validation.ts)
|
|
10
|
+
* - Field type utilities (fieldTypeUtils.ts)
|
|
11
|
+
* - Asset field utilities (assetFieldUtils.ts)
|
|
12
|
+
* - Field error utilities (fieldErrorUtils.ts)
|
|
13
|
+
*
|
|
14
|
+
* Import all utilities from this file using:
|
|
15
|
+
* import { functionName } from '../../utils';
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export * from './dateUtils';
|
|
19
|
+
export * from './requestUtils';
|
|
20
|
+
export * from './filterUtils';
|
|
21
|
+
export * from './constants';
|
|
22
|
+
export * from './validation';
|
|
23
|
+
export * from './fieldTypeUtils';
|
|
24
|
+
export * from './assetFieldUtils';
|
|
25
|
+
export * from './fieldErrorUtils';
|