@worknice/js-sdk 0.0.5 → 0.0.7
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/{_types-kBsjg67t.d.ts → _types-Cobjq3B-.d.ts} +64 -0
- package/dist/api/ApiError.js +3 -3
- package/dist/api/ApiError.js.map +1 -1
- package/dist/api/WorkniceIntegrationLogger.d.ts +3 -1
- package/dist/api/WorkniceIntegrationLogger.js.map +1 -1
- package/dist/api/_generated.d.ts +261 -40
- package/dist/api/_generated.js +15 -12
- package/dist/api/_generated.js.map +1 -1
- package/dist/api/_types.d.ts +2 -2
- package/dist/api/createApiOperation.d.ts +1 -1
- package/dist/api/createWorkniceClient.d.ts +1 -1
- package/dist/api/createWorkniceClient.js +2 -0
- package/dist/api/createWorkniceClient.js.map +1 -1
- package/dist/api/operations/activateIntegration.d.ts +1 -1
- package/dist/api/operations/authorizeIntegration.d.ts +1 -1
- package/dist/api/operations/completeSync.d.ts +1 -1
- package/dist/api/operations/createApiToken.d.ts +1 -1
- package/dist/api/operations/createDataImport.d.ts +1 -1
- package/dist/api/operations/createPersonConnection.d.ts +1 -1
- package/dist/api/operations/createPersonDataImportLine.d.ts +1 -1
- package/dist/api/operations/deleteApiToken.d.ts +1 -1
- package/dist/api/operations/deletePersonConnection.d.ts +1 -1
- package/dist/api/operations/getApiTokens.d.ts +1 -1
- package/dist/api/operations/getIntegration.d.ts +1 -1
- package/dist/api/operations/getMyApps.d.ts +1 -1
- package/dist/api/operations/getPeople.d.ts +2 -1
- package/dist/api/operations/getPeople.js +1 -0
- package/dist/api/operations/getPeople.js.map +1 -1
- package/dist/api/operations/getPersonConnections.d.ts +1 -1
- package/dist/api/operations/initializeIntegration.d.ts +1 -1
- package/dist/api/operations/updatePerson.d.ts +70 -0
- package/dist/api/operations/updatePerson.js +90 -0
- package/dist/api/operations/updatePerson.js.map +1 -0
- package/dist/api/operations/updatePersonConnection.d.ts +1 -1
- package/dist/api/operations/updatePersonConnection.js.map +1 -1
- package/dist/employee-records/EQUALITY_CHECKS.js +5 -0
- package/dist/employee-records/EQUALITY_CHECKS.js.map +1 -1
- package/dist/employee-records/_types.d.ts +11 -5
- package/dist/employee-records/comparePersonDataTransferLines.js +14 -0
- package/dist/employee-records/comparePersonDataTransferLines.js.map +1 -1
- package/dist/employee-records/index.d.ts +1 -1
- package/dist/employee-records/mergePersonDataTransferLines.js +1 -0
- package/dist/employee-records/mergePersonDataTransferLines.js.map +1 -1
- package/dist/employee-records/validatePersonDataTransferLine.js +2 -0
- package/dist/employee-records/validatePersonDataTransferLine.js.map +1 -1
- package/dist/employee-records/validatePersonDataTransferLineProfile.d.ts +6 -0
- package/dist/employee-records/validatePersonDataTransferLineProfile.js +17 -0
- package/dist/employee-records/validatePersonDataTransferLineProfile.js.map +1 -0
- package/dist/helpers/_types.d.ts +1 -1
- package/dist/helpers/handleApproveLeaveRequestWebhook.d.ts +1 -1
- package/dist/helpers/handleCancelLeaveRequestWebhook.d.ts +1 -1
- package/dist/helpers/handleCreateIntegrationWebhook.d.ts +4 -2
- package/dist/helpers/handleCreateIntegrationWebhook.js +17 -2
- package/dist/helpers/handleCreateIntegrationWebhook.js.map +1 -1
- package/dist/helpers/handleCreateLeaveRequestWebhook.d.ts +1 -1
- package/dist/helpers/handleDenyLeaveRequestWebhook.d.ts +1 -1
- package/dist/helpers/handleGetAuthorizationUrlWebhook.d.ts +1 -1
- package/dist/helpers/handleGetLeaveBalancesWebhook.d.ts +1 -1
- package/dist/helpers/handleGetLeaveCategoriesWebhook.d.ts +1 -1
- package/dist/helpers/handleGetLeaveRequestHoursWebhook.d.ts +1 -1
- package/dist/helpers/handleProcessLeaveRequestWebhook.d.ts +1 -1
- package/dist/helpers/handleRequest.d.ts +1 -1
- package/dist/helpers/handleRequestWithWorknice.d.ts +1 -1
- package/dist/helpers/handleTriggerIntegrationSyncWebhook.d.ts +7 -8
- package/dist/helpers/handleTriggerIntegrationSyncWebhook.js +185 -117
- package/dist/helpers/handleTriggerIntegrationSyncWebhook.js.map +1 -1
- package/dist/helpers/index.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/utils/errorToString.js +6 -4
- package/dist/utils/errorToString.js.map +1 -1
- package/package.json +7 -4
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { W as WorkniceClient } from '../_types-
|
|
2
|
-
import {
|
|
1
|
+
import { W as WorkniceClient } from '../_types-Cobjq3B-.js';
|
|
2
|
+
import { PersonDataTransferLine } from '../employee-records/_types.js';
|
|
3
3
|
import { TriggerIntegrationSyncRequestPayload } from '../webhooks.js';
|
|
4
4
|
import { HandlerOptions, TaskContext } from './_types.js';
|
|
5
|
-
import '../api/_generated.js';
|
|
5
|
+
import { ConnectionStatus } from '../api/_generated.js';
|
|
6
6
|
import '../api/WorkniceIntegrationLogger.js';
|
|
7
7
|
|
|
8
8
|
type Context<Env, Req extends Request = Request> = TaskContext<TriggerIntegrationSyncRequestPayload, Env, Req> & {
|
|
9
9
|
integration: Awaited<ReturnType<WorkniceClient["getIntegration"]>>;
|
|
10
10
|
};
|
|
11
|
-
type Person =
|
|
11
|
+
type Person = Omit<PersonDataTransferLine, "profile"> & {
|
|
12
|
+
profile: NonNullable<PersonDataTransferLine["profile"]>;
|
|
13
|
+
} & {
|
|
12
14
|
metadata: {
|
|
13
15
|
deleted: boolean;
|
|
14
16
|
employeeCode: string | null;
|
|
@@ -16,15 +18,12 @@ type Person = PartialPersonDataTransferLine & {
|
|
|
16
18
|
targetId: string | null;
|
|
17
19
|
updatedAt: string;
|
|
18
20
|
};
|
|
19
|
-
profile: {
|
|
20
|
-
displayName: string;
|
|
21
|
-
profileEmail: string | null;
|
|
22
|
-
} | null;
|
|
23
21
|
};
|
|
24
22
|
type Tasks<Env, Req extends Request = Request> = {
|
|
25
23
|
createRemotePerson?: (person: Person, context: Context<Env, Req>) => Promise<{
|
|
26
24
|
id: string;
|
|
27
25
|
name: string;
|
|
26
|
+
status?: ConnectionStatus.Connected | ConnectionStatus.Merged;
|
|
28
27
|
}>;
|
|
29
28
|
getApiToken: (context: Pick<Context<Env, Req>, "env" | "logger" | "payload" | "request">) => Promise<string>;
|
|
30
29
|
getConfig: (context: Context<Env, Req>) => Promise<Config>;
|
|
@@ -4,14 +4,17 @@ import { Temporal } from "temporal-polyfill";
|
|
|
4
4
|
import { ConnectionStatus } from "../api/_types.js";
|
|
5
5
|
import comparePersonDataTransferLines from "../employee-records/comparePersonDataTransferLines.js";
|
|
6
6
|
import mergePersonDataTransferLines from "../employee-records/mergePersonDataTransferLines.js";
|
|
7
|
+
import validatePersonDataTransferLine from "../employee-records/validatePersonDataTransferLine.js";
|
|
7
8
|
import validatePersonDataTransferLineBankAccounts from "../employee-records/validatePersonDataTransferLineBankAccounts.js";
|
|
8
9
|
import validatePersonDataTransferLineDateOfBirth from "../employee-records/validatePersonDataTransferLineDateOfBirth.js";
|
|
9
10
|
import validatePersonDataTransferLineFullName from "../employee-records/validatePersonDataTransferLineFullName.js";
|
|
10
11
|
import validatePersonDataTransferLineGender from "../employee-records/validatePersonDataTransferLineGender.js";
|
|
11
12
|
import validatePersonDataTransferLinePersonalEmail from "../employee-records/validatePersonDataTransferLinePersonalEmail.js";
|
|
12
13
|
import validatePersonDataTransferLinePersonalPhone from "../employee-records/validatePersonDataTransferLinePersonalPhone.js";
|
|
14
|
+
import validatePersonDataTransferLineProfile from "../employee-records/validatePersonDataTransferLineProfile.js";
|
|
13
15
|
import validatePersonDataTransferLineResidentialAddress from "../employee-records/validatePersonDataTransferLineResidentialAddress.js";
|
|
14
16
|
import handleRequestWithWorknice from "./handleRequestWithWorknice.js";
|
|
17
|
+
import validatePersonDataTransferLineTaxDetails from "../employee-records/validatePersonDataTransferLineTaxDetails.js";
|
|
15
18
|
const handleTriggerIntegrationSyncWebhook = async (request, {
|
|
16
19
|
createRemotePerson,
|
|
17
20
|
getApiToken,
|
|
@@ -68,7 +71,13 @@ const handleTriggerIntegrationSyncWebhook = async (request, {
|
|
|
68
71
|
logger.info(`Using a "${config.mode}" sync mode.`);
|
|
69
72
|
logger.dedent("Finished loading configuration details.");
|
|
70
73
|
logger.indent(`Retrieving ${config.appName} data\u2026`);
|
|
71
|
-
|
|
74
|
+
let remotePeople;
|
|
75
|
+
try {
|
|
76
|
+
remotePeople = await getRemotePeople(contextWithIntegration);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
logger.info(`An error occurred while retrieving data from ${config.appName}.`);
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
72
81
|
logger.info(`Retrieved ${remotePeople.length} people from ${config.appName}.`);
|
|
73
82
|
logger.dedent(`Completed retrieving ${config.appName} data.`);
|
|
74
83
|
logger.indent("Updating person connections\u2026");
|
|
@@ -84,7 +93,7 @@ const handleTriggerIntegrationSyncWebhook = async (request, {
|
|
|
84
93
|
personConnectionId: remotePersonConnection.id
|
|
85
94
|
});
|
|
86
95
|
logger.info(
|
|
87
|
-
`Deleted connection for
|
|
96
|
+
`Deleted connection for ${config.appName} person "${remotePersonName}" because they have been terminated.`
|
|
88
97
|
);
|
|
89
98
|
}
|
|
90
99
|
} else {
|
|
@@ -136,7 +145,7 @@ const handleTriggerIntegrationSyncWebhook = async (request, {
|
|
|
136
145
|
);
|
|
137
146
|
if (personConnection?.status === ConnectionStatus.Connected || personConnection?.status === ConnectionStatus.Merged) {
|
|
138
147
|
logger.info(
|
|
139
|
-
`Unable to automatically match person "${matchingWorknicePerson.displayName}"
|
|
148
|
+
`Unable to automatically match Worknice person "${matchingWorknicePerson.displayName}" to ${config.appName} person "${remotePersonName}" because the Worknice person has already been matched to a different ${config.appName} person.`
|
|
140
149
|
);
|
|
141
150
|
} else {
|
|
142
151
|
if (personConnection) {
|
|
@@ -160,7 +169,7 @@ const handleTriggerIntegrationSyncWebhook = async (request, {
|
|
|
160
169
|
updatedConnection
|
|
161
170
|
);
|
|
162
171
|
logger.info(
|
|
163
|
-
`Automatically matched and combined person connections for person "${matchingWorknicePerson.displayName}"
|
|
172
|
+
`Automatically matched and combined person connections for Worknice person "${matchingWorknicePerson.displayName}" and ${config.appName} person "${remotePersonName}".`
|
|
164
173
|
);
|
|
165
174
|
} else {
|
|
166
175
|
const updatedConnection = await worknice.updatePersonConnection({
|
|
@@ -178,7 +187,7 @@ const handleTriggerIntegrationSyncWebhook = async (request, {
|
|
|
178
187
|
updatedConnection
|
|
179
188
|
);
|
|
180
189
|
logger.info(
|
|
181
|
-
`Automatically matched existing person connection for person "${matchingWorknicePerson.displayName}"
|
|
190
|
+
`Automatically matched existing person connection for Worknice person "${matchingWorknicePerson.displayName}" to ${config.appName} person "${remotePersonName}".`
|
|
182
191
|
);
|
|
183
192
|
}
|
|
184
193
|
} else {
|
|
@@ -198,7 +207,7 @@ const handleTriggerIntegrationSyncWebhook = async (request, {
|
|
|
198
207
|
updatedConnection
|
|
199
208
|
);
|
|
200
209
|
logger.info(
|
|
201
|
-
`Automatically matched existing person connection for person "${remotePersonName}"
|
|
210
|
+
`Automatically matched existing person connection for ${config.appName} person "${remotePersonName}" to Worknice person "${matchingWorknicePerson.displayName}".`
|
|
202
211
|
);
|
|
203
212
|
} else {
|
|
204
213
|
const newPersonConnection = await worknice.createPersonConnection({
|
|
@@ -212,7 +221,7 @@ const handleTriggerIntegrationSyncWebhook = async (request, {
|
|
|
212
221
|
});
|
|
213
222
|
personConnections.push(newPersonConnection);
|
|
214
223
|
logger.info(
|
|
215
|
-
`Created new person connection for person "${remotePersonName}"
|
|
224
|
+
`Created new person connection for ${config.appName} person "${remotePersonName}" and automatically matched to Worknice person "${matchingWorknicePerson.displayName}".`
|
|
216
225
|
);
|
|
217
226
|
}
|
|
218
227
|
}
|
|
@@ -228,16 +237,17 @@ const handleTriggerIntegrationSyncWebhook = async (request, {
|
|
|
228
237
|
});
|
|
229
238
|
personConnections.push(newPersonConnection);
|
|
230
239
|
logger.info(
|
|
231
|
-
`New person connection created for person "${remotePersonName}"
|
|
240
|
+
`New person connection created for ${config.appName} person "${remotePersonName}".`
|
|
232
241
|
);
|
|
233
242
|
}
|
|
234
243
|
}
|
|
235
244
|
}
|
|
236
245
|
} catch (error) {
|
|
237
|
-
logger.
|
|
238
|
-
`Unable to update person connection for person "${remotePersonName}"
|
|
246
|
+
logger.indent(
|
|
247
|
+
`Unable to update person connection for ${config.appName} person "${remotePersonName}" because of the following error:`
|
|
239
248
|
);
|
|
240
249
|
logger.error(error);
|
|
250
|
+
logger.dedent();
|
|
241
251
|
}
|
|
242
252
|
}
|
|
243
253
|
logger.dedent("Finished updating person connections.");
|
|
@@ -253,15 +263,24 @@ const handleTriggerIntegrationSyncWebhook = async (request, {
|
|
|
253
263
|
const remotePerson = remotePeople.find(
|
|
254
264
|
(person) => person.metadata.sourceId === personConnection.remote.id
|
|
255
265
|
);
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
266
|
+
try {
|
|
267
|
+
if (!worknicePerson) {
|
|
268
|
+
throw Error(
|
|
269
|
+
`Unable to find person in Worknice with the ID "${personConnection.person.id}".`
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
if (!remotePerson) {
|
|
273
|
+
throw Error(
|
|
274
|
+
`Unable to find person in ${config.appName} with the ID "${personConnection.remote.id}".`
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
} catch (error) {
|
|
278
|
+
logger.indent(
|
|
279
|
+
`Unable to update Worknice person "${personConnection.person.displayName}" and/or ${config.appName} person "${personConnection.remote.name}" because of the following error:`
|
|
264
280
|
);
|
|
281
|
+
logger.error(error);
|
|
282
|
+
logger.dedent();
|
|
283
|
+
continue;
|
|
265
284
|
}
|
|
266
285
|
const remotePersonName = personToName(remotePerson);
|
|
267
286
|
const worknicePersonDataTransferLine = {
|
|
@@ -272,10 +291,6 @@ const handleTriggerIntegrationSyncWebhook = async (request, {
|
|
|
272
291
|
sourceId: worknicePerson.id,
|
|
273
292
|
targetId: remotePerson.metadata.sourceId,
|
|
274
293
|
updatedAt: worknicePerson.updatedAt
|
|
275
|
-
},
|
|
276
|
-
profile: {
|
|
277
|
-
displayName: worknicePerson.displayName,
|
|
278
|
-
profileEmail: worknicePerson.profileEmail ?? null
|
|
279
294
|
}
|
|
280
295
|
};
|
|
281
296
|
const remotePersonDataTransferLine = remotePerson;
|
|
@@ -283,7 +298,7 @@ const handleTriggerIntegrationSyncWebhook = async (request, {
|
|
|
283
298
|
worknicePersonDataTransferLine,
|
|
284
299
|
remotePersonDataTransferLine
|
|
285
300
|
);
|
|
286
|
-
if (comparison.hasDifferences && (config.syncFields?.bankAccounts && comparison.sections.bankAccounts.hasDifferences || config.syncFields?.dateOfBirth && comparison.sections.dateOfBirth.hasDifferences || config.syncFields?.fullName && comparison.sections.fullName.hasDifferences || config.syncFields?.gender && comparison.sections.gender.hasDifferences || config.syncFields?.personalEmail && comparison.sections.personalEmail.hasDifferences || config.syncFields?.personalPhone && comparison.sections.personalPhone.hasDifferences || config.syncFields?.residentialAddress && comparison.sections.residentialAddress.hasDifferences)) {
|
|
301
|
+
if (comparison.hasDifferences && (config.syncFields?.bankAccounts && comparison.sections.bankAccounts.hasDifferences || config.syncFields?.dateOfBirth && comparison.sections.dateOfBirth.hasDifferences || config.syncFields?.fullName && comparison.sections.fullName.hasDifferences || config.syncFields?.gender && comparison.sections.gender.hasDifferences || config.syncFields?.personalEmail && comparison.sections.personalEmail.hasDifferences || config.syncFields?.personalPhone && comparison.sections.personalPhone.hasDifferences || config.syncFields?.residentialAddress && comparison.sections.residentialAddress.hasDifferences || config.syncFields?.taxDetails && comparison.sections.taxDetails.hasDifferences)) {
|
|
287
302
|
const worknicePersonUpdatedAt = Temporal.Instant.from(worknicePerson.updatedAt);
|
|
288
303
|
if (!isValidInstant(remotePerson.metadata.updatedAt)) {
|
|
289
304
|
throw Error(
|
|
@@ -308,12 +323,13 @@ const handleTriggerIntegrationSyncWebhook = async (request, {
|
|
|
308
323
|
worknicePersonDataTransferLine,
|
|
309
324
|
contextWithIntegration
|
|
310
325
|
);
|
|
311
|
-
logger.info(`Updated person "${remotePersonName}"
|
|
326
|
+
logger.info(`Updated ${config.appName} person "${remotePersonName}".`);
|
|
312
327
|
} catch (error) {
|
|
313
|
-
logger.
|
|
314
|
-
`Unable to update person "${remotePersonName}"
|
|
328
|
+
logger.indent(
|
|
329
|
+
`Unable to update ${config.appName} person "${remotePersonName}" because of the following error:`
|
|
315
330
|
);
|
|
316
331
|
logger.error(error);
|
|
332
|
+
logger.dedent();
|
|
317
333
|
}
|
|
318
334
|
}
|
|
319
335
|
} else {
|
|
@@ -339,6 +355,9 @@ const handleTriggerIntegrationSyncWebhook = async (request, {
|
|
|
339
355
|
const residentialAddress = validatePersonDataTransferLineResidentialAddress(
|
|
340
356
|
remotePersonDataTransferLine.residentialAddress
|
|
341
357
|
);
|
|
358
|
+
const taxDetails = validatePersonDataTransferLineTaxDetails(
|
|
359
|
+
remotePersonDataTransferLine.taxDetails
|
|
360
|
+
);
|
|
342
361
|
const dataImport = await getDataImport();
|
|
343
362
|
await worknice.createPersonDataImportLine({
|
|
344
363
|
bankAccounts,
|
|
@@ -370,17 +389,17 @@ const handleTriggerIntegrationSyncWebhook = async (request, {
|
|
|
370
389
|
residentialAddress,
|
|
371
390
|
// TODO: Enable syncing super funds. See PROD-2216.
|
|
372
391
|
superFunds: null,
|
|
373
|
-
|
|
374
|
-
taxDetails: null,
|
|
392
|
+
taxDetails,
|
|
375
393
|
// TODO: Enable syncing tenure. See PROD-1371.
|
|
376
394
|
tenure: null
|
|
377
395
|
});
|
|
378
|
-
logger.info(`Updated person "${worknicePerson.displayName}"
|
|
396
|
+
logger.info(`Updated Worknice person "${worknicePerson.displayName}".`);
|
|
379
397
|
} catch (error) {
|
|
380
|
-
logger.
|
|
381
|
-
`Unable to update person "${worknicePerson.displayName}"
|
|
398
|
+
logger.indent(
|
|
399
|
+
`Unable to update Worknice person "${worknicePerson.displayName}" because of the following error:`
|
|
382
400
|
);
|
|
383
401
|
logger.error(error);
|
|
402
|
+
logger.dedent();
|
|
384
403
|
}
|
|
385
404
|
}
|
|
386
405
|
}
|
|
@@ -392,21 +411,28 @@ const handleTriggerIntegrationSyncWebhook = async (request, {
|
|
|
392
411
|
(personConnection) => personConnection.status === ConnectionStatus.Connected
|
|
393
412
|
);
|
|
394
413
|
for (const personConnection of connectedConnections) {
|
|
395
|
-
|
|
396
|
-
(person) => person.id === personConnection.person.id
|
|
397
|
-
);
|
|
414
|
+
let worknicePerson = people.find((person) => person.id === personConnection.person.id);
|
|
398
415
|
const remotePerson = remotePeople.find(
|
|
399
416
|
(person) => person.metadata.sourceId === personConnection.remote.id
|
|
400
417
|
);
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
418
|
+
try {
|
|
419
|
+
if (!worknicePerson) {
|
|
420
|
+
throw Error(
|
|
421
|
+
`Unable to find person in Worknice with the ID "${personConnection.person.id}".`
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
if (!remotePerson) {
|
|
425
|
+
throw Error(
|
|
426
|
+
`Unable to find person in ${config.appName} with the ID "${personConnection.remote.id}".`
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
} catch (error) {
|
|
430
|
+
logger.indent(
|
|
431
|
+
`Unable to merge Worknice person "${personConnection.person.displayName}" with ${config.appName} person "${personConnection.remote.name}" because of the following error:`
|
|
409
432
|
);
|
|
433
|
+
logger.error(error);
|
|
434
|
+
logger.dedent();
|
|
435
|
+
continue;
|
|
410
436
|
}
|
|
411
437
|
const remotePersonName = personToName(remotePerson);
|
|
412
438
|
logger.indent(
|
|
@@ -450,9 +476,15 @@ const handleTriggerIntegrationSyncWebhook = async (request, {
|
|
|
450
476
|
const personalPhone = validatePersonDataTransferLinePersonalPhone(
|
|
451
477
|
mergedDataTransferLine.personalPhone
|
|
452
478
|
);
|
|
479
|
+
const profile = validatePersonDataTransferLineProfile(
|
|
480
|
+
mergedDataTransferLine.profile
|
|
481
|
+
);
|
|
453
482
|
const residentialAddress = validatePersonDataTransferLineResidentialAddress(
|
|
454
483
|
mergedDataTransferLine.residentialAddress
|
|
455
484
|
);
|
|
485
|
+
const taxDetails = validatePersonDataTransferLineTaxDetails(
|
|
486
|
+
mergedDataTransferLine.taxDetails
|
|
487
|
+
);
|
|
456
488
|
const dataImport = await getDataImport();
|
|
457
489
|
await worknice.createPersonDataImportLine({
|
|
458
490
|
bankAccounts,
|
|
@@ -484,12 +516,18 @@ const handleTriggerIntegrationSyncWebhook = async (request, {
|
|
|
484
516
|
residentialAddress,
|
|
485
517
|
// TODO: Enable syncing super funds. See PROD-2216.
|
|
486
518
|
superFunds: null,
|
|
487
|
-
|
|
488
|
-
taxDetails: null,
|
|
519
|
+
taxDetails,
|
|
489
520
|
// TODO: Enable syncing tenure. See PROD-1371.
|
|
490
521
|
tenure: null
|
|
491
522
|
});
|
|
492
|
-
|
|
523
|
+
worknicePerson = await worknice.updatePerson({
|
|
524
|
+
displayName: profile?.displayName,
|
|
525
|
+
employeeCode: remotePerson.metadata.employeeCode,
|
|
526
|
+
personId: worknicePerson.id,
|
|
527
|
+
profileEmail: profile?.profileEmail,
|
|
528
|
+
profilePhone: profile?.profilePhone
|
|
529
|
+
});
|
|
530
|
+
logger.info(`Updated Worknice person "${worknicePerson.displayName}".`);
|
|
493
531
|
if (config.mode === "two-way") {
|
|
494
532
|
if (!updateRemotePerson) {
|
|
495
533
|
throw Error(
|
|
@@ -498,7 +536,11 @@ const handleTriggerIntegrationSyncWebhook = async (request, {
|
|
|
498
536
|
}
|
|
499
537
|
await updateRemotePerson(
|
|
500
538
|
{
|
|
501
|
-
|
|
539
|
+
bankAccounts,
|
|
540
|
+
dateOfBirth,
|
|
541
|
+
emergencyContacts: null,
|
|
542
|
+
fullName,
|
|
543
|
+
gender,
|
|
502
544
|
metadata: {
|
|
503
545
|
deleted: false,
|
|
504
546
|
employeeCode: worknicePerson.employeeCode ?? null,
|
|
@@ -506,14 +548,24 @@ const handleTriggerIntegrationSyncWebhook = async (request, {
|
|
|
506
548
|
targetId: remotePerson.metadata.sourceId,
|
|
507
549
|
updatedAt: worknicePerson.updatedAt
|
|
508
550
|
},
|
|
551
|
+
personalEmail,
|
|
552
|
+
personalPhone,
|
|
553
|
+
postalAddress: null,
|
|
509
554
|
profile: {
|
|
510
555
|
displayName: worknicePerson.displayName,
|
|
511
|
-
profileEmail: worknicePerson.profileEmail ?? null
|
|
512
|
-
|
|
556
|
+
profileEmail: worknicePerson.profileEmail ?? null,
|
|
557
|
+
profilePhone: worknicePerson.profilePhone ?? null
|
|
558
|
+
},
|
|
559
|
+
residentialAddress,
|
|
560
|
+
// TODO: Enable syncing super funds. See PROD-2216.
|
|
561
|
+
superFunds: null,
|
|
562
|
+
taxDetails,
|
|
563
|
+
// TODO: Enable syncing tenure. See PROD-1371.
|
|
564
|
+
tenure: null
|
|
513
565
|
},
|
|
514
566
|
contextWithIntegration
|
|
515
567
|
);
|
|
516
|
-
logger.info(`Updated person "${remotePersonName}"
|
|
568
|
+
logger.info(`Updated ${config.appName} person "${remotePersonName}".`);
|
|
517
569
|
}
|
|
518
570
|
}
|
|
519
571
|
await worknice.updatePersonConnection({
|
|
@@ -527,11 +579,12 @@ const handleTriggerIntegrationSyncWebhook = async (request, {
|
|
|
527
579
|
});
|
|
528
580
|
logger.dedent(`Finished merging.`);
|
|
529
581
|
} catch (error) {
|
|
530
|
-
logger.
|
|
582
|
+
logger.indent(
|
|
531
583
|
`Unable to merge ${config.appName} person "${remotePersonName}" and Worknice person "${worknicePerson.displayName}" because of the following error:`
|
|
532
584
|
);
|
|
533
585
|
logger.error(error);
|
|
534
586
|
logger.dedent();
|
|
587
|
+
logger.dedent();
|
|
535
588
|
}
|
|
536
589
|
}
|
|
537
590
|
logger.dedent("Finished merging unmerged connections.");
|
|
@@ -555,7 +608,7 @@ const handleTriggerIntegrationSyncWebhook = async (request, {
|
|
|
555
608
|
"No createRemotePerson function supplied to handleTriggerIntegrationSyncWebhook."
|
|
556
609
|
);
|
|
557
610
|
}
|
|
558
|
-
const remote = await createRemotePerson(
|
|
611
|
+
const { status, ...remote } = await createRemotePerson(
|
|
559
612
|
{
|
|
560
613
|
...worknicePersonToPersonDataTransferLine(worknicePerson),
|
|
561
614
|
metadata: {
|
|
@@ -564,26 +617,28 @@ const handleTriggerIntegrationSyncWebhook = async (request, {
|
|
|
564
617
|
sourceId: worknicePerson.id,
|
|
565
618
|
targetId: null,
|
|
566
619
|
updatedAt: worknicePerson.updatedAt
|
|
567
|
-
},
|
|
568
|
-
profile: {
|
|
569
|
-
displayName: worknicePerson.displayName,
|
|
570
|
-
profileEmail: worknicePerson.profileEmail ?? null
|
|
571
620
|
}
|
|
572
621
|
},
|
|
573
622
|
contextWithIntegration
|
|
574
623
|
);
|
|
624
|
+
if (personConnections.some((connection) => connection.remote?.id === remote.id)) {
|
|
625
|
+
throw Error(
|
|
626
|
+
`A connection already exists for the ${config.appName} person "${remote.name}".`
|
|
627
|
+
);
|
|
628
|
+
}
|
|
575
629
|
await worknice.updatePersonConnection({
|
|
576
630
|
personConnectionId: personConnection.id,
|
|
577
631
|
personId: personConnection.person.id,
|
|
578
632
|
remote,
|
|
579
|
-
status: ConnectionStatus.Merged
|
|
633
|
+
status: status ?? ConnectionStatus.Merged
|
|
580
634
|
});
|
|
581
635
|
logger.info(`Added new person "${remote.name}" to ${config.appName}.`);
|
|
582
636
|
} catch (error) {
|
|
583
|
-
logger.
|
|
584
|
-
`Unable to add person "${worknicePerson.displayName}"
|
|
637
|
+
logger.indent(
|
|
638
|
+
`Unable to add Worknice person "${worknicePerson.displayName}" to ${config.appName} because of the following error:`
|
|
585
639
|
);
|
|
586
640
|
logger.error(error);
|
|
641
|
+
logger.dedent();
|
|
587
642
|
}
|
|
588
643
|
}
|
|
589
644
|
logger.dedent(`Finished adding new people to ${config.appName}.`);
|
|
@@ -615,65 +670,78 @@ const personToName = (person) => {
|
|
|
615
670
|
return `(unnamed person ${person.metadata.sourceId})`;
|
|
616
671
|
};
|
|
617
672
|
const worknicePersonToPersonDataTransferLine = (worknicePerson) => ({
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
gender: worknicePerson.gender
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
personalEmail: worknicePerson.personalEmail
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
personalPhone: worknicePerson.personalPhone
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
673
|
+
...validatePersonDataTransferLine({
|
|
674
|
+
bankAccounts: worknicePerson.bankAccount1AllocationMethod ? {
|
|
675
|
+
bankAccount1Allocation: worknicePerson.bankAccount1Allocation ?? null,
|
|
676
|
+
bankAccount1AllocationMethod: worknicePerson.bankAccount1AllocationMethod,
|
|
677
|
+
bankAccount1Bsb: worknicePerson.bankAccount1Bsb ?? null,
|
|
678
|
+
bankAccount1Name: worknicePerson.bankAccount1Name ?? null,
|
|
679
|
+
bankAccount1Number: worknicePerson.bankAccount1Number ?? null,
|
|
680
|
+
bankAccount2Allocation: worknicePerson.bankAccount2Allocation ?? null,
|
|
681
|
+
bankAccount2AllocationMethod: worknicePerson.bankAccount2AllocationMethod ?? null,
|
|
682
|
+
bankAccount2Bsb: worknicePerson.bankAccount2Bsb ?? null,
|
|
683
|
+
bankAccount2Name: worknicePerson.bankAccount2Name ?? null,
|
|
684
|
+
bankAccount2Number: worknicePerson.bankAccount2Number ?? null,
|
|
685
|
+
bankAccount3Allocation: worknicePerson.bankAccount3Allocation ?? null,
|
|
686
|
+
bankAccount3AllocationMethod: worknicePerson.bankAccount3AllocationMethod ?? null,
|
|
687
|
+
bankAccount3Bsb: worknicePerson.bankAccount3Bsb ?? null,
|
|
688
|
+
bankAccount3Name: worknicePerson.bankAccount3Name ?? null,
|
|
689
|
+
bankAccount3Number: worknicePerson.bankAccount3Number ?? null,
|
|
690
|
+
bankAccount4Allocation: worknicePerson.bankAccount4Allocation ?? null,
|
|
691
|
+
bankAccount4AllocationMethod: worknicePerson.bankAccount4AllocationMethod ?? null,
|
|
692
|
+
bankAccount4Bsb: worknicePerson.bankAccount4Bsb ?? null,
|
|
693
|
+
bankAccount4Name: worknicePerson.bankAccount4Name ?? null,
|
|
694
|
+
bankAccount4Number: worknicePerson.bankAccount4Number ?? null,
|
|
695
|
+
bankAccount5Allocation: worknicePerson.bankAccount5Allocation ?? null,
|
|
696
|
+
bankAccount5AllocationMethod: worknicePerson.bankAccount5AllocationMethod ?? null,
|
|
697
|
+
bankAccount5Bsb: worknicePerson.bankAccount5Bsb ?? null,
|
|
698
|
+
bankAccount5Name: worknicePerson.bankAccount5Name ?? null,
|
|
699
|
+
bankAccount5Number: worknicePerson.bankAccount5Number ?? null
|
|
700
|
+
} : null,
|
|
701
|
+
dateOfBirth: worknicePerson.dateOfBirth ? { dateOfBirth: worknicePerson.dateOfBirth } : null,
|
|
702
|
+
emergencyContacts: null,
|
|
703
|
+
fullName: worknicePerson.givenName ? {
|
|
704
|
+
familyName: worknicePerson.familyName ?? null,
|
|
705
|
+
givenName: worknicePerson.givenName,
|
|
706
|
+
otherGivenNames: worknicePerson.otherGivenNames ?? null
|
|
707
|
+
} : null,
|
|
708
|
+
gender: worknicePerson.gender ? {
|
|
709
|
+
gender: worknicePerson.gender
|
|
710
|
+
} : null,
|
|
711
|
+
personalEmail: worknicePerson.personalEmail ? {
|
|
712
|
+
personalEmail: worknicePerson.personalEmail
|
|
713
|
+
} : null,
|
|
714
|
+
personalPhone: worknicePerson.personalPhone ? {
|
|
715
|
+
personalPhone: worknicePerson.personalPhone
|
|
716
|
+
} : null,
|
|
717
|
+
postalAddress: null,
|
|
718
|
+
profile: null,
|
|
719
|
+
residentialAddress: worknicePerson.residentialAddressLine1 ? {
|
|
720
|
+
residentialAddressCity: worknicePerson.residentialAddressCity ?? null,
|
|
721
|
+
// FIXME: This should not default to "Australia". See PROD-1085.
|
|
722
|
+
residentialAddressCountry: worknicePerson.residentialAddressCountry ?? "Australia",
|
|
723
|
+
residentialAddressLine1: worknicePerson.residentialAddressLine1,
|
|
724
|
+
residentialAddressLine2: worknicePerson.residentialAddressLine2 ?? null,
|
|
725
|
+
residentialAddressPostcode: worknicePerson.residentialAddressPostcode ?? null,
|
|
726
|
+
residentialAddressState: worknicePerson.residentialAddressState ?? null
|
|
727
|
+
} : null,
|
|
728
|
+
// TODO: Enable syncing super funds. See PROD-2216.
|
|
729
|
+
superFunds: null,
|
|
730
|
+
taxDetails: worknicePerson.taxFileNumberExemption ? {
|
|
731
|
+
hasLoanOrStudentDebt: worknicePerson.hasLoanOrStudentDebt ?? null,
|
|
732
|
+
residencyStatus: worknicePerson.residencyStatus ?? null,
|
|
733
|
+
taxFileNumber: worknicePerson.taxFileNumber ?? null,
|
|
734
|
+
taxFileNumberExemption: worknicePerson.taxFileNumberExemption ?? null,
|
|
735
|
+
taxFreeThresholdClaimed: worknicePerson.taxFreeThresholdClaimed ?? null
|
|
736
|
+
} : null,
|
|
737
|
+
// TODO: Enable syncing tenure. See PROD-1371.
|
|
738
|
+
tenure: null
|
|
739
|
+
}),
|
|
740
|
+
profile: {
|
|
741
|
+
displayName: worknicePerson.displayName,
|
|
742
|
+
profileEmail: worknicePerson.profileEmail ?? null,
|
|
743
|
+
profilePhone: worknicePerson.profilePhone ?? null
|
|
744
|
+
}
|
|
677
745
|
});
|
|
678
746
|
var handleTriggerIntegrationSyncWebhook_default = handleTriggerIntegrationSyncWebhook;
|
|
679
747
|
export {
|