@limetech/n8n-nodes-lime 3.2.2 → 3.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/nodes/lime-crm/index.d.ts +1 -0
  3. package/dist/nodes/lime-crm/index.js +1 -0
  4. package/dist/nodes/lime-crm/index.js.map +1 -1
  5. package/dist/nodes/lime-crm/methods/resourceMapping.js +5 -1
  6. package/dist/nodes/lime-crm/methods/resourceMapping.js.map +1 -1
  7. package/dist/nodes/lime-crm/resources/data/operations/createSingleObject.operation.js +2 -2
  8. package/dist/nodes/lime-crm/resources/data/operations/createSingleObject.operation.js.map +1 -1
  9. package/dist/nodes/lime-crm/resources/data/operations/deleteSingleObject.operation.js +2 -2
  10. package/dist/nodes/lime-crm/resources/data/operations/deleteSingleObject.operation.js.map +1 -1
  11. package/dist/nodes/lime-crm/resources/data/operations/getManyObjects.operation.js +2 -1
  12. package/dist/nodes/lime-crm/resources/data/operations/getManyObjects.operation.js.map +1 -1
  13. package/dist/nodes/lime-crm/resources/data/operations/getSingleFile.operation.js +2 -2
  14. package/dist/nodes/lime-crm/resources/data/operations/getSingleFile.operation.js.map +1 -1
  15. package/dist/nodes/lime-crm/resources/data/operations/getSingleObject.operation.js +2 -2
  16. package/dist/nodes/lime-crm/resources/data/operations/getSingleObject.operation.js.map +1 -1
  17. package/dist/nodes/lime-crm/resources/data/operations/updateSingleObject.operation.js +2 -2
  18. package/dist/nodes/lime-crm/resources/data/operations/updateSingleObject.operation.js.map +1 -1
  19. package/dist/nodes/lime-crm/resources/metadata/operations/getSingleFileMetadata.operation.js +2 -2
  20. package/dist/nodes/lime-crm/resources/metadata/operations/getSingleFileMetadata.operation.js.map +1 -1
  21. package/dist/nodes/lime-crm/resources/metadata/operations/getSingleLimetype.operation.js +2 -2
  22. package/dist/nodes/lime-crm/resources/metadata/operations/getSingleLimetype.operation.js.map +1 -1
  23. package/dist/nodes/lime-crm/serializers/commons.d.ts +6 -0
  24. package/dist/nodes/lime-crm/serializers/commons.js +12 -0
  25. package/dist/nodes/lime-crm/serializers/commons.js.map +1 -0
  26. package/dist/nodes/lime-crm/serializers/index.d.ts +2 -0
  27. package/dist/nodes/lime-crm/serializers/index.js +8 -0
  28. package/dist/nodes/lime-crm/serializers/index.js.map +1 -0
  29. package/dist/nodes/lime-crm/serializers/resourceMapperSerializer.d.ts +2 -0
  30. package/dist/nodes/lime-crm/serializers/resourceMapperSerializer.js +42 -0
  31. package/dist/nodes/lime-crm/serializers/resourceMapperSerializer.js.map +1 -0
  32. package/dist/tsconfig.tsbuildinfo +1 -1
  33. package/nodes/lime-crm/index.ts +1 -0
  34. package/nodes/lime-crm/methods/resourceMapping.ts +9 -3
  35. package/nodes/lime-crm/resources/data/operations/createSingleObject.operation.ts +2 -2
  36. package/nodes/lime-crm/resources/data/operations/deleteSingleObject.operation.ts +2 -2
  37. package/nodes/lime-crm/resources/data/operations/getManyObjects.operation.ts +3 -1
  38. package/nodes/lime-crm/resources/data/operations/getSingleFile.operation.ts +2 -2
  39. package/nodes/lime-crm/resources/data/operations/getSingleObject.operation.ts +2 -2
  40. package/nodes/lime-crm/resources/data/operations/updateSingleObject.operation.ts +2 -2
  41. package/nodes/lime-crm/resources/metadata/operations/getSingleFileMetadata.operation.ts +2 -2
  42. package/nodes/lime-crm/resources/metadata/operations/getSingleLimetype.operation.ts +2 -2
  43. package/nodes/lime-crm/serializers/commons.ts +32 -0
  44. package/nodes/lime-crm/serializers/index.ts +2 -0
  45. package/nodes/lime-crm/serializers/resourceMapperSerializer.ts +110 -0
  46. package/package.json +1 -1
@@ -7,3 +7,4 @@ export * from './resources/admin';
7
7
  export * from './transport';
8
8
  export * from './LimeCrmNode.node';
9
9
  export * from './LimeCrmTrigger.node';
10
+ export * from './serializers';
@@ -9,7 +9,7 @@ import {
9
9
  } from 'n8n-workflow';
10
10
  import { getProperties } from '../transport';
11
11
  import { LimetypeProperty } from '../models';
12
-
12
+ import { serializeResourceMapperValues } from '../serializers';
13
13
  /**
14
14
  * A map of Lime CRM field types to n8n native types
15
15
  */
@@ -19,6 +19,8 @@ const LimeCrmTypeToFieldType = new Map(
19
19
  yesno: 'boolean',
20
20
  decimal: 'number',
21
21
  number: 'number',
22
+ time: 'dateTime',
23
+ date: 'dateTime',
22
24
  })
23
25
  );
24
26
 
@@ -98,7 +100,6 @@ async function getMappingColumns(
98
100
  }),
99
101
  };
100
102
  }
101
-
102
103
  /**
103
104
  * Parse resource mapper fields from n8n workflow
104
105
  * @param context - Node execution context
@@ -117,7 +118,12 @@ export function parseResourceMapperFields(
117
118
  i
118
119
  ) as ResourceMapperValue;
119
120
 
120
- return propertiesInput.value as IDataObject;
121
+ const parsedData = propertiesInput.value as IDataObject;
122
+
123
+ return serializeResourceMapperValues(
124
+ parsedData,
125
+ propertiesInput.schema
126
+ ) as IDataObject;
121
127
  }
122
128
 
123
129
  /**
@@ -16,10 +16,10 @@ import { parseResourceMapperFields } from '../../../methods';
16
16
  * @public
17
17
  */
18
18
  export const description = {
19
- name: 'Create Single Object',
19
+ name: 'Create an Object',
20
20
  value: 'createSingleObject',
21
21
  description: 'Create a single new object',
22
- action: 'Create single object',
22
+ action: 'Create an object',
23
23
  };
24
24
 
25
25
  /**
@@ -10,10 +10,10 @@ import { WorkflowResponse } from '../../../../response';
10
10
  * @public
11
11
  */
12
12
  export const description = {
13
- name: 'Delete Single Object',
13
+ name: 'Delete an Object',
14
14
  value: 'deleteSingleObject',
15
15
  description: 'Delete one specific object',
16
- action: 'Delete single object',
16
+ action: 'Delete an object',
17
17
  };
18
18
 
19
19
  /**
@@ -199,7 +199,9 @@ export const properties: INodeProperties[] = [
199
199
  name: 'limit',
200
200
  type: 'number',
201
201
  default: DEFAULT_API_OBJECT_LIMIT,
202
- description: 'The maximum number of records to return',
202
+ description:
203
+ 'The maximum number of objects to return. Leaving an empty input or specifying "0" will return ' +
204
+ 'all objects.',
203
205
  displayOptions: {
204
206
  show: {
205
207
  resource: [DATA_RESOURCE],
@@ -13,10 +13,10 @@ import { DATA_RESOURCE } from '../../../models';
13
13
  * @public
14
14
  */
15
15
  export const description = {
16
- name: 'Get Single File',
16
+ name: 'Get a File',
17
17
  value: 'getSingleFile',
18
18
  description: 'Get the file data for one specific file',
19
- action: 'Get single file',
19
+ action: 'Get a file',
20
20
  };
21
21
 
22
22
  /**
@@ -10,10 +10,10 @@ import { WorkflowFileResponse } from '../../../../response';
10
10
  * @public
11
11
  */
12
12
  export const description = {
13
- name: 'Get Single Object',
13
+ name: 'Get an Object',
14
14
  value: 'getSingleObject',
15
15
  description: 'Get one specific object',
16
- action: 'Get single object',
16
+ action: 'Get an object',
17
17
  };
18
18
 
19
19
  /**
@@ -15,10 +15,10 @@ import { parseResourceMapperFields } from '../../../methods';
15
15
  * @public
16
16
  */
17
17
  export const description = {
18
- name: 'Update Single Object',
18
+ name: 'Update an Object',
19
19
  value: 'updateSingleObject',
20
20
  description: 'Update one specific object',
21
- action: 'Update single object',
21
+ action: 'Update an object',
22
22
  };
23
23
 
24
24
  /**
@@ -14,10 +14,10 @@ import { handleWorkflowError } from '../../../../errorHandling';
14
14
  * @public
15
15
  */
16
16
  export const description = {
17
- name: 'Get Single File Metadata',
17
+ name: 'Get File Metadata',
18
18
  value: 'getSingleFileMetadata',
19
19
  description: 'Get the metadata for a single file',
20
- action: 'Get single file metadata',
20
+ action: 'Get file metadata',
21
21
  };
22
22
 
23
23
  /**
@@ -9,10 +9,10 @@ import { WorkflowResponse } from '../../../../response';
9
9
  * @public
10
10
  */
11
11
  export const description = {
12
- name: 'Get Single Limetype',
12
+ name: 'Get a Limetype',
13
13
  value: 'getSingleLimetype',
14
14
  description: 'Get details about a specific Limetype',
15
- action: 'Get single Limetype',
15
+ action: 'Get a Limetype',
16
16
  };
17
17
 
18
18
  /**
@@ -0,0 +1,32 @@
1
+ import { GenericValue, IDataObject } from 'n8n-workflow';
2
+
3
+ /**
4
+ * A type that represents a serialized value in the system.
5
+ * It can either be a GenericValue, which is a broad, flexible type,
6
+ * or an IDataObject, which is a structure adhering to a specific data format.
7
+ */
8
+ export type SerializedValue = GenericValue | IDataObject;
9
+
10
+ /**
11
+ * A type definition for a serializer function that transforms a value of type `GenericValue`
12
+ * into a value of type `SerializedValue`.
13
+ *
14
+ * This function is typically used to process and convert data into a desired format suitable
15
+ * for a specific application or context.
16
+ *
17
+ * @callback SerializerFn
18
+ * @param {GenericValue} value - The input value to be serialized or transformed.
19
+ * @returns {SerializedValue} - The resulting transformed value.
20
+ */
21
+ export type SerializerFn = (value: GenericValue) => SerializedValue;
22
+
23
+ /**
24
+ * Custom error class for serialization errors.
25
+ */
26
+ export class SerializerError extends Error {
27
+ constructor(message: string) {
28
+ super(message);
29
+ this.name = 'SerializerError';
30
+ Object.setPrototypeOf(this, SerializerError.prototype);
31
+ }
32
+ }
@@ -0,0 +1,2 @@
1
+ export { serializeResourceMapperValues } from './resourceMapperSerializer';
2
+ export { SerializerError } from './commons';
@@ -0,0 +1,110 @@
1
+ import { FieldType, IDataObject, ResourceMapperField } from 'n8n-workflow';
2
+ import { SerializerFn, SerializedValue, SerializerError } from './commons';
3
+
4
+ interface ResourceMapperFieldMap {
5
+ [id: string]: FieldType;
6
+ }
7
+
8
+ /**
9
+ * Serializes a given value into an ISO 8601 datetime string.
10
+ *
11
+ * This function accepts a value of type stringr, interprets it as a date,
12
+ * and converts it into a standardized ISO 8601 string representation of the datetime.
13
+ *
14
+ * Throws an error if the provided value is not of type string, or if
15
+ * the value cannot be successfully parsed into a valid date.
16
+ *
17
+ * @param value - The input value to be serialized, expected
18
+ * to represent a date. Must be a string.
19
+ * @throws {SerializerError} If the input value is not a string or does not represent a date.
20
+ * @returns The ISO 8601 formatted string representation of the datetime.
21
+ */
22
+ const serializeDatetime: SerializerFn = (value) => {
23
+ if (typeof value !== 'string') {
24
+ throw new SerializerError(
25
+ `Expected string as dateTime, got ${typeof value}`
26
+ );
27
+ }
28
+ const date = new Date(value);
29
+ if (Number.isNaN(date.getTime())) {
30
+ throw new SerializerError(`Invalid date value: ${String(value)}`);
31
+ }
32
+ return date.toISOString();
33
+ };
34
+
35
+ /**
36
+ * A mapping of field types to their corresponding serializer functions.
37
+ * This map is used to associate specific field types with the appropriate
38
+ * logic for serializing their values.
39
+ */
40
+ const SerializerMap: Partial<Record<FieldType, SerializerFn>> = {
41
+ dateTime: serializeDatetime,
42
+ };
43
+
44
+ /**
45
+ * Serializes the provided value using the serializer mapped to the specified Lime CRM type.
46
+ *
47
+ * This function retrieves a serializer associated with the given `limeCrmType` from
48
+ * the `SerializerMap`. If a serializer is found, it processes the `value`
49
+ * with the serializer and returns the serialized result. If no serializer is found
50
+ * for the specified type, the function returns the original value unchanged.
51
+ *
52
+ * @param value - The value to be serialized or returned as-is.
53
+ * @param type
54
+ * @returns - The serialized value or the original value if no
55
+ * serializer is found.
56
+ */
57
+ const getSerializedValue = (
58
+ value: SerializedValue,
59
+ type: FieldType
60
+ ): SerializedValue => {
61
+ const serializer = SerializerMap[type];
62
+ return serializer === undefined ? value : serializer(value);
63
+ };
64
+
65
+ /**
66
+ * Converts an array of resource mapper fields into a mapped object where
67
+ * the field IDs serve as keys and their corresponding types as values.
68
+ *
69
+ * @param schema - The input array of resource mapper fields.
70
+ * @returns An object mapping each field ID to its corresponding type.
71
+ */
72
+ const fetchResourceMapperFieldMap = (
73
+ schema: ResourceMapperField[]
74
+ ): ResourceMapperFieldMap => {
75
+ const resourceMapperFieldMap: ResourceMapperFieldMap = {};
76
+ for (const field of schema) {
77
+ if (field.type) {
78
+ resourceMapperFieldMap[field.id] = field.type;
79
+ }
80
+ }
81
+ return resourceMapperFieldMap;
82
+ };
83
+
84
+ /**
85
+ * Serializes resource mapper values based on the provided schema.
86
+ *
87
+ * This function takes a set of resource mapper values and a corresponding schema,
88
+ * and transforms the values into a serialized format as defined by the schema.
89
+ *
90
+ * @param resourceMapperValues - An object containing the key-value pairs of resource values to be serialized.
91
+ * @param resourceMapperSchema - An array defining the schema for serializing the resource values.
92
+ * @returns The serialized representation of the resource values, structured according to the provided schema.
93
+ */
94
+ export const serializeResourceMapperValues = (
95
+ resourceMapperValues: IDataObject,
96
+ resourceMapperSchema: ResourceMapperField[]
97
+ ): IDataObject => {
98
+ const serializedData: IDataObject = {};
99
+ const resourceMapperFieldMap =
100
+ fetchResourceMapperFieldMap(resourceMapperSchema);
101
+ for (const resourceMapperValue in resourceMapperValues) {
102
+ if (resourceMapperValues[resourceMapperValue] !== undefined) {
103
+ serializedData[resourceMapperValue] = getSerializedValue(
104
+ resourceMapperValues[resourceMapperValue],
105
+ resourceMapperFieldMap[resourceMapperValue]
106
+ );
107
+ }
108
+ }
109
+ return serializedData;
110
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@limetech/n8n-nodes-lime",
3
- "version": "3.2.2",
3
+ "version": "3.4.0",
4
4
  "description": "n8n node to connect to Lime CRM",
5
5
  "license": "Apache-2.0",
6
6
  "main": "nodes/index.ts",