@limetech/n8n-nodes-lime 0.3.8 → 0.5.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.
- package/.prettierignore +3 -1
- package/CHANGELOG.md +100 -0
- package/README.md +1 -8
- package/credentials/LimeCrmApi.credentials.ts +6 -6
- package/dist/nodes/lime-crm/LimeCrmNode.node.js +13 -0
- package/dist/nodes/lime-crm/LimeCrmNode.node.js.map +1 -1
- package/dist/nodes/lime-crm/commons/constants.d.ts +1 -0
- package/dist/nodes/lime-crm/commons/constants.js +2 -1
- package/dist/nodes/lime-crm/commons/constants.js.map +1 -1
- package/dist/nodes/lime-crm/commons/index.d.ts +1 -1
- package/dist/nodes/lime-crm/commons/index.js +2 -1
- package/dist/nodes/lime-crm/commons/index.js.map +1 -1
- package/dist/nodes/lime-crm/resources/limeQuery/index.d.ts +6 -0
- package/dist/nodes/lime-crm/resources/limeQuery/index.js +66 -0
- package/dist/nodes/lime-crm/resources/limeQuery/index.js.map +1 -0
- package/dist/nodes/lime-crm/resources/limeQuery/operations/query.operation.d.ts +9 -0
- package/dist/nodes/lime-crm/resources/limeQuery/operations/query.operation.js +191 -0
- package/dist/nodes/lime-crm/resources/limeQuery/operations/query.operation.js.map +1 -0
- package/dist/nodes/lime-crm/resources/limeType/index.d.ts +3 -3
- package/dist/nodes/lime-crm/transport/index.d.ts +1 -0
- package/dist/nodes/lime-crm/transport/index.js +3 -1
- package/dist/nodes/lime-crm/transport/index.js.map +1 -1
- package/dist/nodes/lime-crm/transport/limeQuery.d.ts +10 -0
- package/dist/nodes/lime-crm/transport/limeQuery.js +15 -0
- package/dist/nodes/lime-crm/transport/limeQuery.js.map +1 -0
- package/dist/package.json +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/docker-compose.yml +9 -3
- package/nodes/fortnox/Fortnox.node.ts +3 -3
- package/nodes/fortnox/FortnoxTrigger.node.ts +2 -2
- package/nodes/lime-crm/LimeCrmNode.node.ts +54 -53
- package/nodes/lime-crm/LimeCrmTrigger.node.ts +17 -24
- package/nodes/lime-crm/commons/constants.ts +2 -2
- package/nodes/lime-crm/commons/files.ts +162 -0
- package/nodes/lime-crm/commons/index.ts +4 -3
- package/nodes/lime-crm/commons/webhook.ts +15 -3
- package/nodes/lime-crm/methods/getLimetypeProperties.ts +67 -0
- package/nodes/lime-crm/methods/getLimetypes.ts +21 -0
- package/nodes/lime-crm/methods/index.ts +6 -2
- package/nodes/lime-crm/model.ts +22 -0
- package/nodes/lime-crm/resources/data/index.ts +80 -0
- package/nodes/lime-crm/resources/{limeObject/operations/create.operation.ts → data/operations/createSingleObject.ts} +53 -30
- package/nodes/lime-crm/resources/{limeObject/operations/delete.operation.ts → data/operations/deleteSingleObject.ts} +15 -15
- package/nodes/lime-crm/resources/data/operations/getManyObjects.ts +356 -0
- package/nodes/lime-crm/resources/data/operations/getSingleFile.ts +138 -0
- package/nodes/lime-crm/resources/data/operations/getSingleObject.ts +83 -0
- package/nodes/lime-crm/resources/{limeObject/operations/update.operation.ts → data/operations/updateSingleObject.operation.ts} +51 -23
- package/nodes/lime-crm/resources/erpConnector/index.ts +3 -3
- package/nodes/lime-crm/resources/erpConnector/operations/transform.operation.ts +14 -14
- package/nodes/lime-crm/resources/erpConnector/transform.ts +3 -3
- package/nodes/lime-crm/resources/erpConnector/transformers/baseTransformer.ts +2 -2
- package/nodes/lime-crm/resources/erpConnector/transformers/fortnox.ts +8 -8
- package/nodes/lime-crm/resources/metadata/index.ts +57 -0
- package/nodes/lime-crm/resources/metadata/operations/getAllLimetypes.operation.ts +18 -0
- package/nodes/lime-crm/resources/metadata/operations/getSingleFileMetadata.ts +130 -0
- package/nodes/lime-crm/resources/metadata/operations/getSingleLimetype.ts +36 -0
- package/nodes/lime-crm/transport/commons.ts +14 -2
- package/nodes/lime-crm/transport/files.ts +155 -0
- package/nodes/lime-crm/transport/index.ts +14 -6
- package/nodes/lime-crm/transport/limeQuery.ts +26 -0
- package/nodes/lime-crm/transport/limeobjects.ts +79 -44
- package/nodes/lime-crm/transport/limetypes.ts +80 -24
- package/package.json +4 -3
- package/restore_script/README +42 -0
- package/restore_script/api_key_download.txt +0 -0
- package/restore_script/api_key_upload.txt +0 -0
- package/restore_script/cli.py +73 -0
- package/restore_script/download.py +73 -0
- package/restore_script/main.py +19 -0
- package/restore_script/poetry.lock +162 -0
- package/restore_script/pyproject.toml +15 -0
- package/restore_script/transfer.py +41 -0
- package/restore_script/upload.py +66 -0
- package/restore_script/utils.py +42 -0
- package/tests/transform.spec.ts +6 -6
- package/nodes/lime-crm/commons/limetype.ts +0 -11
- package/nodes/lime-crm/methods/getLimeTypeProperties.ts +0 -27
- package/nodes/lime-crm/methods/getLimeTypes.ts +0 -23
- package/nodes/lime-crm/resources/limeObject/index.ts +0 -64
- package/nodes/lime-crm/resources/limeObject/operations/fetchMany.operation.ts +0 -112
- package/nodes/lime-crm/resources/limeObject/operations/get.operation.ts +0 -54
- package/nodes/lime-crm/resources/limeType/index.ts +0 -58
- package/nodes/lime-crm/resources/limeType/operations/getProperties.operation.ts +0 -42
- package/nodes/lime-crm/resources/limeType/operations/getType.operation.ts +0 -36
- package/nodes/lime-crm/resources/limeType/operations/listTypes.operation.ts +0 -18
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IExecuteFunctions,
|
|
3
|
+
INodeProperties,
|
|
4
|
+
INodeExecutionData,
|
|
5
|
+
NodeOperationError,
|
|
6
|
+
} from 'n8n-workflow';
|
|
7
|
+
import {
|
|
8
|
+
getFileMetadata,
|
|
9
|
+
getFileMetadataByLimeobject,
|
|
10
|
+
} from '../../../transport';
|
|
11
|
+
import { METADATA_RESOURCE } from '../../../commons';
|
|
12
|
+
|
|
13
|
+
export const description = {
|
|
14
|
+
name: 'Get Single File Metadata',
|
|
15
|
+
value: 'getSingleFileMetadata',
|
|
16
|
+
description: 'Get the metadata for a single file',
|
|
17
|
+
action: 'Get single file metadata',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const properties: INodeProperties[] = [
|
|
21
|
+
{
|
|
22
|
+
displayName: 'Get by',
|
|
23
|
+
name: 'source',
|
|
24
|
+
type: 'options',
|
|
25
|
+
required: true,
|
|
26
|
+
placeholder: 'Add Source',
|
|
27
|
+
displayOptions: {
|
|
28
|
+
show: {
|
|
29
|
+
resource: [METADATA_RESOURCE],
|
|
30
|
+
operation: ['getSingleFileMetadata'],
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
options: [
|
|
34
|
+
{
|
|
35
|
+
name: 'File ID',
|
|
36
|
+
value: 'byFile',
|
|
37
|
+
description: 'Get file by its ID',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'Limeobject ID',
|
|
41
|
+
value: 'byLimeobject',
|
|
42
|
+
description: "Get file by it's associated Limeobject ID",
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
default: 'byFile',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
displayName: 'Limetype',
|
|
49
|
+
name: 'limetype',
|
|
50
|
+
type: 'options',
|
|
51
|
+
typeOptions: {
|
|
52
|
+
loadOptionsMethod: 'getLimetypes',
|
|
53
|
+
},
|
|
54
|
+
required: true,
|
|
55
|
+
default: '',
|
|
56
|
+
description: 'The type of entity associated with the file',
|
|
57
|
+
displayOptions: {
|
|
58
|
+
show: {
|
|
59
|
+
resource: [METADATA_RESOURCE],
|
|
60
|
+
operation: ['getSingleFileMetadata'],
|
|
61
|
+
source: ['byLimeobject'],
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
displayName: 'Identifier',
|
|
67
|
+
name: 'identifier',
|
|
68
|
+
type: 'string',
|
|
69
|
+
required: true,
|
|
70
|
+
default: '',
|
|
71
|
+
description: 'The ID of the file or Limeobject to retrieve',
|
|
72
|
+
displayOptions: {
|
|
73
|
+
show: {
|
|
74
|
+
resource: [METADATA_RESOURCE],
|
|
75
|
+
operation: ['getSingleFileMetadata'],
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
placeholder: 'e.g., 12345',
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
displayName: 'File type property',
|
|
82
|
+
name: 'property',
|
|
83
|
+
type: 'options',
|
|
84
|
+
typeOptions: {
|
|
85
|
+
loadOptionsMethod: 'getFileProperties',
|
|
86
|
+
loadOptionsDependsOn: ['limetype'],
|
|
87
|
+
},
|
|
88
|
+
required: true,
|
|
89
|
+
default: '',
|
|
90
|
+
description: 'The type of entity associated with the file',
|
|
91
|
+
displayOptions: {
|
|
92
|
+
show: {
|
|
93
|
+
resource: [METADATA_RESOURCE],
|
|
94
|
+
operation: ['getSingleFileMetadata'],
|
|
95
|
+
source: ['byLimeobject'],
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
];
|
|
100
|
+
|
|
101
|
+
export async function execute(
|
|
102
|
+
this: IExecuteFunctions,
|
|
103
|
+
i: number
|
|
104
|
+
): Promise<INodeExecutionData> {
|
|
105
|
+
const source = this.getNodeParameter('source', i) as string;
|
|
106
|
+
const id = this.getNodeParameter('identifier', i) as string;
|
|
107
|
+
|
|
108
|
+
if (source == 'byFile') {
|
|
109
|
+
return {
|
|
110
|
+
json: await getFileMetadata(this, id),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
if (source == 'byLimeobject') {
|
|
114
|
+
const limetype = this.getNodeParameter('limetype', i) as string;
|
|
115
|
+
const property = this.getNodeParameter('property', i) as string;
|
|
116
|
+
return {
|
|
117
|
+
json: await getFileMetadataByLimeobject(
|
|
118
|
+
this,
|
|
119
|
+
limetype,
|
|
120
|
+
id,
|
|
121
|
+
property
|
|
122
|
+
),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
throw new NodeOperationError(
|
|
127
|
+
this.getNode(),
|
|
128
|
+
`The source "${source}" is not supported!`
|
|
129
|
+
);
|
|
130
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { IExecuteFunctions, INodeProperties } from 'n8n-workflow';
|
|
2
|
+
import { getLimetype } from '../../../transport/limetypes';
|
|
3
|
+
import { METADATA_RESOURCE } from '../../../commons';
|
|
4
|
+
|
|
5
|
+
export const description = {
|
|
6
|
+
name: 'Get Single Limetype',
|
|
7
|
+
value: 'getSingleLimetype',
|
|
8
|
+
description: 'Get details about a specific Limetype',
|
|
9
|
+
action: 'Get single Limetype',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const properties: INodeProperties[] = [
|
|
13
|
+
{
|
|
14
|
+
displayName: 'Limetype',
|
|
15
|
+
name: 'limetype',
|
|
16
|
+
type: 'options',
|
|
17
|
+
typeOptions: {
|
|
18
|
+
loadOptionsMethod: 'getLimetypes',
|
|
19
|
+
},
|
|
20
|
+
required: true,
|
|
21
|
+
default: '',
|
|
22
|
+
description: 'The name of the entity type to get details for',
|
|
23
|
+
displayOptions: {
|
|
24
|
+
show: {
|
|
25
|
+
resource: [METADATA_RESOURCE],
|
|
26
|
+
operation: ['getSingleLimetype'],
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
export async function execute(this: IExecuteFunctions, i: number) {
|
|
33
|
+
const limetype = this.getNodeParameter('limetype', i) as string;
|
|
34
|
+
|
|
35
|
+
return getLimetype(this, limetype);
|
|
36
|
+
}
|
|
@@ -4,6 +4,17 @@ import { NodeResponse } from '../../nodeResponse';
|
|
|
4
4
|
|
|
5
5
|
type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
6
6
|
|
|
7
|
+
export function removeKeys<T extends object, K extends keyof T>(
|
|
8
|
+
data: T,
|
|
9
|
+
keys: K[]
|
|
10
|
+
): Omit<T, K> {
|
|
11
|
+
const { ...obj } = data;
|
|
12
|
+
for (const key of keys) {
|
|
13
|
+
delete obj[key];
|
|
14
|
+
}
|
|
15
|
+
return obj;
|
|
16
|
+
}
|
|
17
|
+
|
|
7
18
|
async function getLimeUrl(context: IAllExecuteFunctions): Promise<string> {
|
|
8
19
|
const credentials = await context.getCredentials(
|
|
9
20
|
LIME_CRM_API_CREDENTIAL_KEY
|
|
@@ -15,7 +26,8 @@ export async function callLimeApi<T>(
|
|
|
15
26
|
nodeContext: IAllExecuteFunctions,
|
|
16
27
|
method: HTTPMethod,
|
|
17
28
|
url: string,
|
|
18
|
-
options?: Record<string, unknown
|
|
29
|
+
options?: Record<string, unknown>,
|
|
30
|
+
json = true
|
|
19
31
|
): Promise<NodeResponse<T>> {
|
|
20
32
|
try {
|
|
21
33
|
const response: T =
|
|
@@ -25,7 +37,7 @@ export async function callLimeApi<T>(
|
|
|
25
37
|
{
|
|
26
38
|
method: method,
|
|
27
39
|
url: url,
|
|
28
|
-
json:
|
|
40
|
+
json: json,
|
|
29
41
|
baseURL: await getLimeUrl(nodeContext),
|
|
30
42
|
...options,
|
|
31
43
|
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { callLimeApi, getLimeobject } from '.';
|
|
2
|
+
import { IExecuteFunctions, IBinaryData, BINARY_ENCODING } from 'n8n-workflow';
|
|
3
|
+
import { NodeResponse } from '../../nodeResponse';
|
|
4
|
+
import { removeKeys } from './commons';
|
|
5
|
+
import { getFilenameFromHeader, setFilename } from '../commons';
|
|
6
|
+
|
|
7
|
+
const LIME_FILE_URL = '/api/v1/file/';
|
|
8
|
+
|
|
9
|
+
interface FileApiResponse {
|
|
10
|
+
headers: Record<string, string | string[] | undefined>;
|
|
11
|
+
body: Buffer;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface FileMetadata {
|
|
15
|
+
filename: string;
|
|
16
|
+
id: number;
|
|
17
|
+
size: number;
|
|
18
|
+
content_type: string;
|
|
19
|
+
extension: string;
|
|
20
|
+
created_by: number;
|
|
21
|
+
locked_by: number;
|
|
22
|
+
last_modified: string;
|
|
23
|
+
_links?: { [key: string]: { href: string } };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function getFileMetadata(
|
|
27
|
+
nodeContext: IExecuteFunctions,
|
|
28
|
+
id: string | number
|
|
29
|
+
): Promise<NodeResponse<FileMetadata>> {
|
|
30
|
+
const url = `${LIME_FILE_URL}${id}/`;
|
|
31
|
+
const response = await callLimeApi<FileMetadata>(nodeContext, 'GET', url);
|
|
32
|
+
if (!response.success) {
|
|
33
|
+
return response;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
success: true,
|
|
38
|
+
data: removeKeys(response.data, ['_links']),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function getFileMetadataByLimeobject(
|
|
43
|
+
nodeContext: IExecuteFunctions,
|
|
44
|
+
limetype: string,
|
|
45
|
+
id: string,
|
|
46
|
+
fileTypeProperty: string
|
|
47
|
+
): Promise<NodeResponse<FileMetadata>> {
|
|
48
|
+
const objectResponse = await getLimeobject(nodeContext, limetype, id);
|
|
49
|
+
if (!objectResponse.success) {
|
|
50
|
+
return objectResponse;
|
|
51
|
+
}
|
|
52
|
+
const fileId = objectResponse.data[fileTypeProperty] as string | undefined;
|
|
53
|
+
|
|
54
|
+
if (!fileId) {
|
|
55
|
+
return {
|
|
56
|
+
success: false,
|
|
57
|
+
error: 'The specified Limeobject does not have an associated file.',
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const metadataResponse = await getFileMetadata(nodeContext, fileId);
|
|
62
|
+
if (!metadataResponse.success) {
|
|
63
|
+
return metadataResponse;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
success: true,
|
|
68
|
+
data: removeKeys(metadataResponse.data, ['_links']),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export async function getFileContent(
|
|
73
|
+
nodeContext: IExecuteFunctions,
|
|
74
|
+
id: string | number
|
|
75
|
+
): Promise<NodeResponse<IBinaryData>> {
|
|
76
|
+
const url = `${LIME_FILE_URL}${id}/contents/`;
|
|
77
|
+
|
|
78
|
+
const response = await callLimeApi<FileApiResponse>(
|
|
79
|
+
nodeContext,
|
|
80
|
+
'GET',
|
|
81
|
+
url,
|
|
82
|
+
{
|
|
83
|
+
encoding: null,
|
|
84
|
+
responseType: 'stream',
|
|
85
|
+
resolveWithFullResponse: true,
|
|
86
|
+
},
|
|
87
|
+
false
|
|
88
|
+
);
|
|
89
|
+
if (!response.success) {
|
|
90
|
+
return response;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const fileName =
|
|
94
|
+
getFilenameFromHeader(response.data.headers) || `file_${id}`;
|
|
95
|
+
const binaryData = await nodeContext.helpers.prepareBinaryData(
|
|
96
|
+
response.data.body
|
|
97
|
+
);
|
|
98
|
+
binaryData.fileName = setFilename(binaryData, fileName);
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
success: true,
|
|
102
|
+
data: binaryData,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export async function getFileContentByLimetype(
|
|
107
|
+
nodeContext: IExecuteFunctions,
|
|
108
|
+
limetype: string,
|
|
109
|
+
id: string,
|
|
110
|
+
fileTypeProperty: string
|
|
111
|
+
): Promise<NodeResponse<IBinaryData>> {
|
|
112
|
+
const objectResponse = await getLimeobject(nodeContext, limetype, id);
|
|
113
|
+
if (!objectResponse.success) {
|
|
114
|
+
return objectResponse;
|
|
115
|
+
}
|
|
116
|
+
const fileId = objectResponse.data[fileTypeProperty] as string | undefined;
|
|
117
|
+
|
|
118
|
+
if (!fileId) {
|
|
119
|
+
return {
|
|
120
|
+
success: false,
|
|
121
|
+
error: 'The specified Limeobject does not have an associated file.',
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return await getFileContent(nodeContext, fileId);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export async function createFile(
|
|
129
|
+
nodeContext: IExecuteFunctions,
|
|
130
|
+
binary: IBinaryData,
|
|
131
|
+
fallbackFileName: string
|
|
132
|
+
): Promise<NodeResponse<FileMetadata>> {
|
|
133
|
+
const response = await callLimeApi<FileMetadata>(
|
|
134
|
+
nodeContext,
|
|
135
|
+
'POST',
|
|
136
|
+
LIME_FILE_URL,
|
|
137
|
+
{
|
|
138
|
+
body: Buffer.from(binary.data, BINARY_ENCODING),
|
|
139
|
+
headers: {
|
|
140
|
+
'Content-Disposition': `;filename*="UTF-8''${encodeURIComponent(binary.fileName || fallbackFileName)}"`,
|
|
141
|
+
'Content-Type': binary.mimeType,
|
|
142
|
+
},
|
|
143
|
+
}
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
// Remove metadata from the response to reduce its overall size
|
|
147
|
+
if (!response.success) {
|
|
148
|
+
return { success: false, error: response.error };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
success: true,
|
|
153
|
+
data: removeKeys(response.data, ['_links']),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
@@ -4,14 +4,22 @@ export {
|
|
|
4
4
|
createSubscription,
|
|
5
5
|
listSubscriptionsWithExistingData,
|
|
6
6
|
} from './webhooks';
|
|
7
|
-
export {
|
|
7
|
+
export { getLimetypesFromApi, getProperties } from './limetypes';
|
|
8
8
|
|
|
9
9
|
export {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
createLimeobject,
|
|
11
|
+
deleteLimeobject,
|
|
12
|
+
updateLimeobject,
|
|
13
|
+
getLimeobject,
|
|
14
|
+
fetchManyLimeobjects,
|
|
15
15
|
} from './limeobjects';
|
|
16
16
|
export { startCreateOrUpdateObjectsTask } from './erpConnector';
|
|
17
|
+
export { queryLimeobjects } from './limeQuery';
|
|
18
|
+
export {
|
|
19
|
+
createFile,
|
|
20
|
+
getFileContent,
|
|
21
|
+
getFileContentByLimetype,
|
|
22
|
+
getFileMetadata,
|
|
23
|
+
getFileMetadataByLimeobject,
|
|
24
|
+
} from './files';
|
|
17
25
|
export { callLimeApi } from './commons';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IAllExecuteFunctions } from 'n8n-workflow';
|
|
2
|
+
import { NodeResponse } from '../../nodeResponse';
|
|
3
|
+
import { callLimeApi } from './commons';
|
|
4
|
+
|
|
5
|
+
const LIME_QUERY_URL = '/api/v1/query/';
|
|
6
|
+
|
|
7
|
+
interface IncludedProperties {
|
|
8
|
+
[key: string]: IncludedProperties | string | number | boolean | null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface QueryResponse {
|
|
12
|
+
objects: IncludedProperties[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function queryLimeobjects(
|
|
16
|
+
nodeContext: IAllExecuteFunctions,
|
|
17
|
+
q: string
|
|
18
|
+
): Promise<NodeResponse<QueryResponse>> {
|
|
19
|
+
const queryParameters = {
|
|
20
|
+
q: q,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
return await callLimeApi(nodeContext, 'GET', LIME_QUERY_URL, {
|
|
24
|
+
qs: queryParameters,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -1,41 +1,56 @@
|
|
|
1
|
-
import { callLimeApi } from './commons';
|
|
1
|
+
import { callLimeApi, removeKeys } from './commons';
|
|
2
2
|
import { IAllExecuteFunctions, IDataObject } from 'n8n-workflow';
|
|
3
3
|
import { NodeResponse } from '../../nodeResponse';
|
|
4
|
+
import { Limeobject } from '../model';
|
|
4
5
|
|
|
5
6
|
const LIMEOBJECT_URL = '/api/v1/limeobject/';
|
|
6
7
|
|
|
7
|
-
interface
|
|
8
|
+
interface LimeobjectCrmApiResponse {
|
|
9
|
+
id_: number;
|
|
10
|
+
_links: object;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface FetchManyLimeobjectsApiResponse {
|
|
8
14
|
_embedded: {
|
|
9
|
-
limeobjects:
|
|
15
|
+
limeobjects: LimeobjectCrmApiResponse[];
|
|
10
16
|
};
|
|
11
17
|
}
|
|
12
18
|
|
|
13
|
-
export async function
|
|
19
|
+
export async function createLimeobject(
|
|
14
20
|
nodeContext: IAllExecuteFunctions,
|
|
15
|
-
|
|
21
|
+
limetype: string,
|
|
16
22
|
data: object
|
|
17
|
-
): Promise<NodeResponse<
|
|
18
|
-
const url = `${LIMEOBJECT_URL}${
|
|
19
|
-
const response = await callLimeApi(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
): Promise<NodeResponse<Limeobject>> {
|
|
24
|
+
const url = `${LIMEOBJECT_URL}${limetype}/`;
|
|
25
|
+
const response = await callLimeApi<LimeobjectCrmApiResponse>(
|
|
26
|
+
nodeContext,
|
|
27
|
+
'POST',
|
|
28
|
+
url,
|
|
29
|
+
{
|
|
30
|
+
body: data,
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
if (response.success)
|
|
34
|
+
return {
|
|
35
|
+
success: true,
|
|
36
|
+
data: removeKeys(response.data, ['_links']),
|
|
37
|
+
};
|
|
23
38
|
|
|
24
39
|
return {
|
|
25
40
|
...response,
|
|
26
41
|
metadata: {
|
|
27
42
|
...response.metadata,
|
|
28
|
-
|
|
43
|
+
limetype: limetype,
|
|
29
44
|
},
|
|
30
45
|
};
|
|
31
46
|
}
|
|
32
47
|
|
|
33
|
-
export async function
|
|
48
|
+
export async function deleteLimeobject(
|
|
34
49
|
nodeContext: IAllExecuteFunctions,
|
|
35
|
-
|
|
50
|
+
limetype: string,
|
|
36
51
|
id: string
|
|
37
52
|
): Promise<NodeResponse<void>> {
|
|
38
|
-
const url = `${LIMEOBJECT_URL}${
|
|
53
|
+
const url = `${LIMEOBJECT_URL}${limetype}/${id}/`;
|
|
39
54
|
const response: NodeResponse<void> = await callLimeApi(
|
|
40
55
|
nodeContext,
|
|
41
56
|
'DELETE',
|
|
@@ -48,63 +63,80 @@ export async function deleteLimeObject(
|
|
|
48
63
|
...response,
|
|
49
64
|
metadata: {
|
|
50
65
|
...response.metadata,
|
|
51
|
-
|
|
66
|
+
limetype: limetype,
|
|
52
67
|
id: id,
|
|
53
68
|
},
|
|
54
69
|
};
|
|
55
70
|
}
|
|
56
71
|
|
|
57
|
-
export async function
|
|
72
|
+
export async function getLimeobject(
|
|
58
73
|
nodeContext: IAllExecuteFunctions,
|
|
59
|
-
|
|
74
|
+
limetype: string,
|
|
60
75
|
id: string
|
|
61
|
-
): Promise<NodeResponse<
|
|
62
|
-
const url = `${LIMEOBJECT_URL}${
|
|
63
|
-
const response = await callLimeApi(
|
|
76
|
+
): Promise<NodeResponse<Limeobject>> {
|
|
77
|
+
const url = `${LIMEOBJECT_URL}${limetype}/${id}/`;
|
|
78
|
+
const response = await callLimeApi<LimeobjectCrmApiResponse>(
|
|
79
|
+
nodeContext,
|
|
80
|
+
'GET',
|
|
81
|
+
url
|
|
82
|
+
);
|
|
64
83
|
|
|
65
|
-
if (response.success)
|
|
84
|
+
if (response.success)
|
|
85
|
+
return {
|
|
86
|
+
success: true,
|
|
87
|
+
data: removeKeys(response.data, ['_links']),
|
|
88
|
+
};
|
|
66
89
|
|
|
67
90
|
return {
|
|
68
91
|
...response,
|
|
69
92
|
metadata: {
|
|
70
93
|
...response.metadata,
|
|
71
|
-
|
|
94
|
+
limetype: limetype,
|
|
72
95
|
id: id,
|
|
73
96
|
},
|
|
74
97
|
};
|
|
75
98
|
}
|
|
76
99
|
|
|
77
|
-
export async function
|
|
100
|
+
export async function updateLimeobject(
|
|
78
101
|
nodeContext: IAllExecuteFunctions,
|
|
79
|
-
|
|
102
|
+
limetype: string,
|
|
80
103
|
id: string,
|
|
81
104
|
data: object
|
|
82
|
-
): Promise<NodeResponse<
|
|
83
|
-
const url = `${LIMEOBJECT_URL}${
|
|
84
|
-
const response = await callLimeApi(
|
|
85
|
-
|
|
86
|
-
|
|
105
|
+
): Promise<NodeResponse<Limeobject>> {
|
|
106
|
+
const url = `${LIMEOBJECT_URL}${limetype}/${id}/`;
|
|
107
|
+
const response = await callLimeApi<LimeobjectCrmApiResponse>(
|
|
108
|
+
nodeContext,
|
|
109
|
+
'PUT',
|
|
110
|
+
url,
|
|
111
|
+
{
|
|
112
|
+
body: data,
|
|
113
|
+
}
|
|
114
|
+
);
|
|
87
115
|
|
|
88
|
-
if (response.success)
|
|
116
|
+
if (response.success)
|
|
117
|
+
return {
|
|
118
|
+
success: true,
|
|
119
|
+
data: removeKeys(response.data, ['_links']),
|
|
120
|
+
};
|
|
89
121
|
|
|
90
122
|
return {
|
|
91
123
|
...response,
|
|
92
124
|
metadata: {
|
|
93
125
|
...response.metadata,
|
|
94
|
-
|
|
126
|
+
limetype: limetype,
|
|
95
127
|
id: id,
|
|
96
128
|
},
|
|
97
129
|
};
|
|
98
130
|
}
|
|
99
131
|
|
|
100
|
-
async function
|
|
132
|
+
async function _searchLimeobjectWithLimit(
|
|
101
133
|
nodeContext: IAllExecuteFunctions,
|
|
102
134
|
url: string,
|
|
103
135
|
limit: number,
|
|
104
136
|
offset: number,
|
|
105
137
|
qs: IDataObject
|
|
106
|
-
): Promise<NodeResponse<
|
|
107
|
-
const returnData = [];
|
|
138
|
+
): Promise<NodeResponse<FetchManyLimeobjectsApiResponse>> {
|
|
139
|
+
const returnData: LimeobjectCrmApiResponse[] = [];
|
|
108
140
|
let hasMoreData = true;
|
|
109
141
|
let currentOffset = Math.max(0, offset);
|
|
110
142
|
const pageLimit = 50;
|
|
@@ -113,7 +145,7 @@ async function _searchLimeObjectWithLimit(
|
|
|
113
145
|
qs._limit = Math.min(limit, pageLimit);
|
|
114
146
|
qs._offset = currentOffset;
|
|
115
147
|
|
|
116
|
-
const response = await callLimeApi<
|
|
148
|
+
const response = await callLimeApi<FetchManyLimeobjectsApiResponse>(
|
|
117
149
|
nodeContext,
|
|
118
150
|
'GET',
|
|
119
151
|
url,
|
|
@@ -143,16 +175,16 @@ async function _searchLimeObjectWithLimit(
|
|
|
143
175
|
};
|
|
144
176
|
}
|
|
145
177
|
|
|
146
|
-
export async function
|
|
178
|
+
export async function fetchManyLimeobjects(
|
|
147
179
|
nodeContext: IAllExecuteFunctions,
|
|
148
|
-
|
|
180
|
+
limetype: string,
|
|
149
181
|
searchField: string,
|
|
150
182
|
searchTerm: string,
|
|
151
183
|
limit: number,
|
|
152
184
|
offset: number,
|
|
153
185
|
sortField: string | null
|
|
154
|
-
): Promise<NodeResponse<
|
|
155
|
-
const url = `${LIMEOBJECT_URL}${
|
|
186
|
+
): Promise<NodeResponse<Limeobject[]>> {
|
|
187
|
+
const url = `${LIMEOBJECT_URL}${limetype}/`;
|
|
156
188
|
const qs: IDataObject = {
|
|
157
189
|
...(searchField && searchTerm && { [searchField]: searchTerm }),
|
|
158
190
|
...(offset != null && offset > 0 && { _offset: offset }),
|
|
@@ -161,7 +193,7 @@ export async function fetchManyLimeObjects(
|
|
|
161
193
|
|
|
162
194
|
let response;
|
|
163
195
|
if (limit) {
|
|
164
|
-
response = await
|
|
196
|
+
response = await _searchLimeobjectWithLimit(
|
|
165
197
|
nodeContext,
|
|
166
198
|
url,
|
|
167
199
|
limit,
|
|
@@ -169,7 +201,7 @@ export async function fetchManyLimeObjects(
|
|
|
169
201
|
qs
|
|
170
202
|
);
|
|
171
203
|
} else {
|
|
172
|
-
response = await callLimeApi<
|
|
204
|
+
response = await callLimeApi<FetchManyLimeobjectsApiResponse>(
|
|
173
205
|
nodeContext,
|
|
174
206
|
'GET',
|
|
175
207
|
url,
|
|
@@ -182,7 +214,10 @@ export async function fetchManyLimeObjects(
|
|
|
182
214
|
if (response.success) {
|
|
183
215
|
return {
|
|
184
216
|
success: true,
|
|
185
|
-
data:
|
|
217
|
+
data:
|
|
218
|
+
response.data?._embedded.limeobjects.map((limeobject) =>
|
|
219
|
+
removeKeys(limeobject, ['_links'])
|
|
220
|
+
) ?? [],
|
|
186
221
|
};
|
|
187
222
|
}
|
|
188
223
|
return {
|
|
@@ -191,7 +226,7 @@ export async function fetchManyLimeObjects(
|
|
|
191
226
|
status: response.status,
|
|
192
227
|
metadata: {
|
|
193
228
|
...response.metadata,
|
|
194
|
-
|
|
229
|
+
limetype: limetype,
|
|
195
230
|
},
|
|
196
231
|
};
|
|
197
232
|
}
|