@skriptfabrik/n8n-nodes-clockify-enhanced 0.4.3 → 0.4.5

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 (27) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/package.json +5 -7
  3. package/src/nodes/ClockifyEnhanced/ClockifyEnhanced.node.d.ts +15 -0
  4. package/src/nodes/ClockifyEnhanced/ClockifyEnhanced.node.js +232 -0
  5. package/src/nodes/ClockifyEnhanced/ClockifyEnhanced.node.js.map +1 -0
  6. package/src/nodes/ClockifyEnhanced/ClockifyEnhancedTrigger.node.d.ts +52 -0
  7. package/src/nodes/ClockifyEnhanced/ClockifyEnhancedTrigger.node.js +297 -0
  8. package/src/nodes/ClockifyEnhanced/ClockifyEnhancedTrigger.node.js.map +1 -0
  9. package/src/nodes/ClockifyEnhanced/descriptions/ProjectDescription.d.ts +3 -0
  10. package/src/nodes/ClockifyEnhanced/descriptions/ProjectDescription.js +117 -0
  11. package/src/nodes/ClockifyEnhanced/descriptions/ProjectDescription.js.map +1 -0
  12. package/src/nodes/ClockifyEnhanced/descriptions/ProjectMembershipsDescription.d.ts +3 -0
  13. package/src/nodes/ClockifyEnhanced/descriptions/ProjectMembershipsDescription.js +122 -0
  14. package/src/nodes/ClockifyEnhanced/descriptions/ProjectMembershipsDescription.js.map +1 -0
  15. package/.eslintrc.json +0 -30
  16. package/jest.config.ts +0 -11
  17. package/project.json +0 -38
  18. package/src/api.d.ts +0 -12413
  19. package/src/nodes/ClockifyEnhanced/ClockifyEnhanced.node.spec.ts +0 -920
  20. package/src/nodes/ClockifyEnhanced/ClockifyEnhanced.node.ts +0 -387
  21. package/src/nodes/ClockifyEnhanced/ClockifyEnhancedTrigger.node.spec.ts +0 -870
  22. package/src/nodes/ClockifyEnhanced/ClockifyEnhancedTrigger.node.ts +0 -356
  23. package/src/nodes/ClockifyEnhanced/descriptions/ProjectDescription.ts +0 -120
  24. package/src/nodes/ClockifyEnhanced/descriptions/ProjectMembershipsDescription.ts +0 -125
  25. package/tsconfig.json +0 -28
  26. package/tsconfig.lib.json +0 -10
  27. package/tsconfig.spec.json +0 -13
@@ -1,387 +0,0 @@
1
- import {
2
- type IDataObject,
3
- type IExecuteFunctions,
4
- type ILoadOptionsFunctions,
5
- type INodeExecutionData,
6
- type INodePropertyOptions,
7
- type INodeType,
8
- type INodeTypeDescription,
9
- type NodeApiError,
10
- } from 'n8n-workflow';
11
-
12
- import {
13
- clockifyApiRequest,
14
- clockifyApiRequestAllItems,
15
- } from 'n8n-nodes-base/dist/nodes/Clockify/GenericFunctions';
16
-
17
- import { components } from '../../api';
18
-
19
- type Client = components['schemas']['ClientDtoV1'] &
20
- Required<Pick<components['schemas']['ClientDtoV1'], 'id' | 'name'>>;
21
-
22
- type Project = components['schemas']['ProjectDtoV1'] &
23
- Required<Pick<components['schemas']['ProjectDtoV1'], 'id' | 'name'>>;
24
-
25
- type User = components['schemas']['UserDtoV1'] &
26
- Required<
27
- Pick<components['schemas']['UserDtoV1'], 'id' | 'name' | 'memberships'>
28
- >;
29
-
30
- type Workspace = components['schemas']['WorkspaceDtoV1'] &
31
- Required<Pick<components['schemas']['WorkspaceDtoV1'], 'id' | 'name'>>;
32
-
33
- import {
34
- projectFields,
35
- projectOperations,
36
- } from './descriptions/ProjectDescription';
37
-
38
- import {
39
- projectMembershipFields,
40
- projectMembershipOperations,
41
- } from './descriptions/ProjectMembershipsDescription';
42
-
43
- export class ClockifyEnhanced implements INodeType {
44
- description: INodeTypeDescription = {
45
- displayName: 'Clockify Enhanced',
46
-
47
- name: 'clockifyEnhanced',
48
-
49
- icon: 'file:icons/clockify-enhanced.svg',
50
-
51
- group: ['transform'],
52
-
53
- version: 1,
54
-
55
- subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
56
-
57
- description: 'Consume Clockify REST API',
58
-
59
- defaults: {
60
- name: 'Clockify Enhanced',
61
- },
62
-
63
- inputs: ['main'],
64
-
65
- outputs: ['main'],
66
-
67
- credentials: [
68
- {
69
- name: 'clockifyApi',
70
- required: true,
71
- },
72
- ],
73
-
74
- properties: [
75
- {
76
- displayName: 'Resource',
77
- name: 'resource',
78
- type: 'options',
79
- noDataExpression: true,
80
- options: [
81
- {
82
- name: 'Project',
83
- value: 'project',
84
- },
85
- {
86
- name: 'Project Membership',
87
- value: 'project membership',
88
- },
89
- ],
90
- default: 'project',
91
- },
92
- ...projectOperations,
93
- ...projectMembershipOperations,
94
- {
95
- displayName: 'Workspace Name or ID',
96
- name: 'workspaceId',
97
- type: 'options',
98
- typeOptions: {
99
- loadOptionsMethod: 'loadWorkspaces',
100
- },
101
- default: '',
102
- description:
103
- 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
104
- required: true,
105
- requiresDataPath: 'single',
106
- validateType: 'string',
107
- },
108
- ...projectFields,
109
- ...projectMembershipFields,
110
- ],
111
- };
112
-
113
- methods = {
114
- loadOptions: {
115
- async loadWorkspaces(
116
- this: ILoadOptionsFunctions,
117
- ): Promise<INodePropertyOptions[]> {
118
- const workspaces: Workspace[] = await clockifyApiRequest.call(
119
- this,
120
- 'GET',
121
- 'workspaces',
122
- );
123
-
124
- if (!workspaces) {
125
- return [];
126
- }
127
-
128
- return workspaces.map((value) => ({
129
- name: value.name,
130
- value: value.id,
131
- }));
132
- },
133
-
134
- async loadClients(
135
- this: ILoadOptionsFunctions,
136
- ): Promise<INodePropertyOptions[]> {
137
- const workspaceId = this.getCurrentNodeParameter('workspaceId');
138
- if (!workspaceId) {
139
- return [];
140
- }
141
-
142
- const clients: Client[] = await clockifyApiRequestAllItems.call(
143
- this,
144
- 'GET',
145
- `workspaces/${workspaceId}/clients`,
146
- );
147
-
148
- if (!clients) {
149
- return [];
150
- }
151
-
152
- return clients.map((client) => ({
153
- name: client.name,
154
- value: client.id,
155
- }));
156
- },
157
-
158
- async loadProjects(
159
- this: ILoadOptionsFunctions,
160
- ): Promise<INodePropertyOptions[]> {
161
- const workspaceId = this.getCurrentNodeParameter('workspaceId');
162
- if (!workspaceId) {
163
- return [];
164
- }
165
-
166
- const projects: Project[] = await clockifyApiRequestAllItems.call(
167
- this,
168
- 'GET',
169
- `workspaces/${workspaceId}/projects`,
170
- );
171
-
172
- if (!projects) {
173
- return [];
174
- }
175
-
176
- return projects.map((project) => ({
177
- name: project.name,
178
- value: project.id,
179
- }));
180
- },
181
-
182
- async loadUsers(
183
- this: ILoadOptionsFunctions,
184
- ): Promise<INodePropertyOptions[]> {
185
- const workspaceId = this.getCurrentNodeParameter('workspaceId');
186
- if (!workspaceId) {
187
- return [];
188
- }
189
-
190
- const users: User[] = await clockifyApiRequestAllItems.call(
191
- this,
192
- 'GET',
193
- `workspaces/${workspaceId}/users`,
194
- );
195
-
196
- if (!users) {
197
- return [];
198
- }
199
-
200
- return users.map((value) => ({
201
- name: value.name,
202
- value: value.id,
203
- }));
204
- },
205
-
206
- async loadNonProjectUsers(
207
- this: ILoadOptionsFunctions,
208
- ): Promise<INodePropertyOptions[]> {
209
- const workspaceId = this.getCurrentNodeParameter(
210
- 'workspaceId',
211
- ) as string;
212
-
213
- const projectId = this.getCurrentNodeParameter('projectId') as string;
214
-
215
- if (!workspaceId || !projectId) {
216
- return [];
217
- }
218
-
219
- const users: User[] = await clockifyApiRequestAllItems.call(
220
- this,
221
- 'GET',
222
- `workspaces/${workspaceId}/users`,
223
- undefined,
224
- {
225
- memberships: 'PROJECT',
226
- },
227
- );
228
-
229
- if (!users) {
230
- return [];
231
- }
232
-
233
- return users
234
- .filter((user) => {
235
- const memberships = user.memberships.filter(
236
- (membership) => membership.targetId === projectId,
237
- );
238
-
239
- return memberships.length <= 0;
240
- })
241
- .map((user) => ({
242
- name: user.name,
243
- value: user.id,
244
- }));
245
- },
246
-
247
- async loadProjectUsers(
248
- this: ILoadOptionsFunctions,
249
- ): Promise<INodePropertyOptions[]> {
250
- const workspaceId = this.getCurrentNodeParameter(
251
- 'workspaceId',
252
- ) as string;
253
-
254
- const projectId = this.getCurrentNodeParameter('projectId') as string;
255
-
256
- if (!workspaceId || !projectId) {
257
- return [];
258
- }
259
-
260
- const users: User[] = await clockifyApiRequestAllItems.call(
261
- this,
262
- 'GET',
263
- `workspaces/${workspaceId}/users`,
264
- undefined,
265
- {
266
- projectId,
267
- },
268
- );
269
-
270
- if (!users) {
271
- return [];
272
- }
273
-
274
- return users.map((user) => ({
275
- name: user.name,
276
- value: user.id,
277
- }));
278
- },
279
- },
280
- };
281
-
282
- async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
283
- const items = this.getInputData();
284
-
285
- const returnData: INodeExecutionData[] = [];
286
-
287
- let responseData: IDataObject | IDataObject[] = {};
288
-
289
- const resource = this.getNodeParameter('resource', 0);
290
-
291
- const operation = this.getNodeParameter('operation', 0);
292
-
293
- for (let item = 0; item < items.length; item++) {
294
- try {
295
- if (resource === 'project') {
296
- if (operation === 'update') {
297
- const workspaceId = this.getNodeParameter(
298
- 'workspaceId',
299
- item,
300
- ) as string;
301
-
302
- const projectId = this.getNodeParameter(
303
- 'projectId',
304
- item,
305
- ) as string;
306
-
307
- const updateFields = this.getNodeParameter('updateFields', item);
308
-
309
- responseData = await clockifyApiRequest.call(
310
- this,
311
- 'PUT',
312
- `/workspaces/${workspaceId}/projects/${projectId}`,
313
- updateFields,
314
- );
315
- }
316
- }
317
-
318
- if (resource === 'project membership') {
319
- const workspaceId = this.getNodeParameter(
320
- 'workspaceId',
321
- item,
322
- ) as string;
323
-
324
- const projectId = this.getNodeParameter('projectId', item) as string;
325
-
326
- if (operation === 'patch') {
327
- const memberships = (
328
- this.getNodeParameter('memberships', item) as string[]
329
- ).map((membership) => ({ userId: membership }));
330
-
331
- responseData = await clockifyApiRequest.call(
332
- this,
333
- 'PATCH',
334
- `/workspaces/${workspaceId}/projects/${projectId}/memberships`,
335
- {
336
- memberships,
337
- },
338
- );
339
- }
340
-
341
- if (operation === 'assign') {
342
- responseData = await clockifyApiRequest.call(
343
- this,
344
- 'POST',
345
- `/workspaces/${workspaceId}/projects/${projectId}/memberships`,
346
- {
347
- remove: false,
348
- userIds: this.getNodeParameter('userIdsToAssign', item),
349
- },
350
- );
351
- }
352
-
353
- if (operation === 'remove') {
354
- responseData = await clockifyApiRequest.call(
355
- this,
356
- 'POST',
357
- `/workspaces/${workspaceId}/projects/${projectId}/memberships`,
358
- {
359
- remove: true,
360
- userIds: this.getNodeParameter('userIdsToRemove', item),
361
- },
362
- );
363
- }
364
- }
365
-
366
- const executionData = this.helpers.constructExecutionMetaData(
367
- this.helpers.returnJsonArray(responseData as IDataObject[]),
368
- { itemData: { item } },
369
- );
370
-
371
- returnData.push(...executionData);
372
- } catch (error) {
373
- if (this.continueOnFail()) {
374
- returnData.push({
375
- json: { error: (error as NodeApiError).message },
376
- pairedItem: { item },
377
- });
378
- continue;
379
- }
380
-
381
- throw error;
382
- }
383
- }
384
-
385
- return [returnData];
386
- }
387
- }