@worknice/js-sdk 0.0.6 → 0.0.8-rc.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/package.json +7 -5
- package/dist/_types-kBsjg67t.d.ts +0 -697
- package/dist/api/ApiError.d.ts +0 -13
- package/dist/api/ApiError.js +0 -29
- package/dist/api/ApiError.js.map +0 -1
- package/dist/api/WorkniceIntegrationLogger.d.ts +0 -123
- package/dist/api/WorkniceIntegrationLogger.js +0 -203
- package/dist/api/WorkniceIntegrationLogger.js.map +0 -1
- package/dist/api/_generated.d.ts +0 -5490
- package/dist/api/_generated.js +0 -388
- package/dist/api/_generated.js.map +0 -1
- package/dist/api/_types.d.ts +0 -2
- package/dist/api/_types.js +0 -2
- package/dist/api/_types.js.map +0 -1
- package/dist/api/assertNotNull.d.ts +0 -5
- package/dist/api/assertNotNull.js +0 -14
- package/dist/api/assertNotNull.js.map +0 -1
- package/dist/api/createApiOperation.d.ts +0 -11
- package/dist/api/createApiOperation.js +0 -6
- package/dist/api/createApiOperation.js.map +0 -1
- package/dist/api/createWorkniceClient.d.ts +0 -2
- package/dist/api/createWorkniceClient.js +0 -123
- package/dist/api/createWorkniceClient.js.map +0 -1
- package/dist/api/operations/activateIntegration.d.ts +0 -22
- package/dist/api/operations/activateIntegration.js +0 -29
- package/dist/api/operations/activateIntegration.js.map +0 -1
- package/dist/api/operations/authorizeIntegration.d.ts +0 -20
- package/dist/api/operations/authorizeIntegration.js +0 -23
- package/dist/api/operations/authorizeIntegration.js.map +0 -1
- package/dist/api/operations/completeSync.d.ts +0 -20
- package/dist/api/operations/completeSync.js +0 -23
- package/dist/api/operations/completeSync.js.map +0 -1
- package/dist/api/operations/createApiToken.d.ts +0 -14
- package/dist/api/operations/createApiToken.js +0 -31
- package/dist/api/operations/createApiToken.js.map +0 -1
- package/dist/api/operations/createDataImport.d.ts +0 -12
- package/dist/api/operations/createDataImport.js +0 -25
- package/dist/api/operations/createDataImport.js.map +0 -1
- package/dist/api/operations/createPersonConnection.d.ts +0 -139
- package/dist/api/operations/createPersonConnection.js +0 -66
- package/dist/api/operations/createPersonConnection.js.map +0 -1
- package/dist/api/operations/createPersonDataImportLine.d.ts +0 -26
- package/dist/api/operations/createPersonDataImportLine.js +0 -57
- package/dist/api/operations/createPersonDataImportLine.js.map +0 -1
- package/dist/api/operations/deleteApiToken.d.ts +0 -10
- package/dist/api/operations/deleteApiToken.js +0 -21
- package/dist/api/operations/deleteApiToken.js.map +0 -1
- package/dist/api/operations/deletePersonConnection.d.ts +0 -10
- package/dist/api/operations/deletePersonConnection.js +0 -21
- package/dist/api/operations/deletePersonConnection.js.map +0 -1
- package/dist/api/operations/getApiTokens.d.ts +0 -14
- package/dist/api/operations/getApiTokens.js +0 -39
- package/dist/api/operations/getApiTokens.js.map +0 -1
- package/dist/api/operations/getIntegration.d.ts +0 -65
- package/dist/api/operations/getIntegration.js +0 -32
- package/dist/api/operations/getIntegration.js.map +0 -1
- package/dist/api/operations/getMyApps.d.ts +0 -37
- package/dist/api/operations/getMyApps.js +0 -62
- package/dist/api/operations/getMyApps.js.map +0 -1
- package/dist/api/operations/getPeople.d.ts +0 -65
- package/dist/api/operations/getPeople.js +0 -79
- package/dist/api/operations/getPeople.js.map +0 -1
- package/dist/api/operations/getPersonConnections.d.ts +0 -114
- package/dist/api/operations/getPersonConnections.js +0 -44
- package/dist/api/operations/getPersonConnections.js.map +0 -1
- package/dist/api/operations/initializeIntegration.d.ts +0 -20
- package/dist/api/operations/initializeIntegration.js +0 -23
- package/dist/api/operations/initializeIntegration.js.map +0 -1
- package/dist/api/operations/updatePersonConnection.d.ts +0 -139
- package/dist/api/operations/updatePersonConnection.js +0 -66
- package/dist/api/operations/updatePersonConnection.js.map +0 -1
- package/dist/employee-records/EQUALITY_CHECKS.d.ts +0 -10
- package/dist/employee-records/EQUALITY_CHECKS.js +0 -111
- package/dist/employee-records/EQUALITY_CHECKS.js.map +0 -1
- package/dist/employee-records/_types.d.ts +0 -192
- package/dist/employee-records/_types.js +0 -1
- package/dist/employee-records/_types.js.map +0 -1
- package/dist/employee-records/comparePersonDataTransferLines.d.ts +0 -6
- package/dist/employee-records/comparePersonDataTransferLines.js +0 -383
- package/dist/employee-records/comparePersonDataTransferLines.js.map +0 -1
- package/dist/employee-records/index.d.ts +0 -20
- package/dist/employee-records/index.js +0 -33
- package/dist/employee-records/index.js.map +0 -1
- package/dist/employee-records/mergePersonDataTransferLines.d.ts +0 -6
- package/dist/employee-records/mergePersonDataTransferLines.js +0 -22
- package/dist/employee-records/mergePersonDataTransferLines.js.map +0 -1
- package/dist/employee-records/validatePersonDataTransferLine.d.ts +0 -6
- package/dist/employee-records/validatePersonDataTransferLine.js +0 -31
- package/dist/employee-records/validatePersonDataTransferLine.js.map +0 -1
- package/dist/employee-records/validatePersonDataTransferLineBankAccounts.d.ts +0 -6
- package/dist/employee-records/validatePersonDataTransferLineBankAccounts.js +0 -241
- package/dist/employee-records/validatePersonDataTransferLineBankAccounts.js.map +0 -1
- package/dist/employee-records/validatePersonDataTransferLineDateOfBirth.d.ts +0 -6
- package/dist/employee-records/validatePersonDataTransferLineDateOfBirth.js +0 -17
- package/dist/employee-records/validatePersonDataTransferLineDateOfBirth.js.map +0 -1
- package/dist/employee-records/validatePersonDataTransferLineEmergencyContacts.d.ts +0 -6
- package/dist/employee-records/validatePersonDataTransferLineEmergencyContacts.js +0 -6
- package/dist/employee-records/validatePersonDataTransferLineEmergencyContacts.js.map +0 -1
- package/dist/employee-records/validatePersonDataTransferLineFullName.d.ts +0 -6
- package/dist/employee-records/validatePersonDataTransferLineFullName.js +0 -20
- package/dist/employee-records/validatePersonDataTransferLineFullName.js.map +0 -1
- package/dist/employee-records/validatePersonDataTransferLineGender.d.ts +0 -6
- package/dist/employee-records/validatePersonDataTransferLineGender.js +0 -13
- package/dist/employee-records/validatePersonDataTransferLineGender.js.map +0 -1
- package/dist/employee-records/validatePersonDataTransferLinePersonalEmail.d.ts +0 -6
- package/dist/employee-records/validatePersonDataTransferLinePersonalEmail.js +0 -15
- package/dist/employee-records/validatePersonDataTransferLinePersonalEmail.js.map +0 -1
- package/dist/employee-records/validatePersonDataTransferLinePersonalPhone.d.ts +0 -6
- package/dist/employee-records/validatePersonDataTransferLinePersonalPhone.js +0 -15
- package/dist/employee-records/validatePersonDataTransferLinePersonalPhone.js.map +0 -1
- package/dist/employee-records/validatePersonDataTransferLinePostalAddress.d.ts +0 -6
- package/dist/employee-records/validatePersonDataTransferLinePostalAddress.js +0 -39
- package/dist/employee-records/validatePersonDataTransferLinePostalAddress.js.map +0 -1
- package/dist/employee-records/validatePersonDataTransferLineResidentialAddress.d.ts +0 -6
- package/dist/employee-records/validatePersonDataTransferLineResidentialAddress.js +0 -39
- package/dist/employee-records/validatePersonDataTransferLineResidentialAddress.js.map +0 -1
- package/dist/employee-records/validatePersonDataTransferLineSuperFunds.d.ts +0 -6
- package/dist/employee-records/validatePersonDataTransferLineSuperFunds.js +0 -46
- package/dist/employee-records/validatePersonDataTransferLineSuperFunds.js.map +0 -1
- package/dist/employee-records/validatePersonDataTransferLineTaxDetails.d.ts +0 -6
- package/dist/employee-records/validatePersonDataTransferLineTaxDetails.js +0 -46
- package/dist/employee-records/validatePersonDataTransferLineTaxDetails.js.map +0 -1
- package/dist/employee-records/validatePersonDataTransferLineTenure.d.ts +0 -6
- package/dist/employee-records/validatePersonDataTransferLineTenure.js +0 -20
- package/dist/employee-records/validatePersonDataTransferLineTenure.js.map +0 -1
- package/dist/helpers/_types.d.ts +0 -22
- package/dist/helpers/_types.js +0 -1
- package/dist/helpers/_types.js.map +0 -1
- package/dist/helpers/handleApproveLeaveRequestWebhook.d.ts +0 -15
- package/dist/helpers/handleApproveLeaveRequestWebhook.js +0 -21
- package/dist/helpers/handleApproveLeaveRequestWebhook.js.map +0 -1
- package/dist/helpers/handleCancelLeaveRequestWebhook.d.ts +0 -15
- package/dist/helpers/handleCancelLeaveRequestWebhook.js +0 -21
- package/dist/helpers/handleCancelLeaveRequestWebhook.js.map +0 -1
- package/dist/helpers/handleCreateIntegrationWebhook.d.ts +0 -14
- package/dist/helpers/handleCreateIntegrationWebhook.js +0 -42
- package/dist/helpers/handleCreateIntegrationWebhook.js.map +0 -1
- package/dist/helpers/handleCreateLeaveRequestWebhook.d.ts +0 -15
- package/dist/helpers/handleCreateLeaveRequestWebhook.js +0 -21
- package/dist/helpers/handleCreateLeaveRequestWebhook.js.map +0 -1
- package/dist/helpers/handleDenyLeaveRequestWebhook.d.ts +0 -15
- package/dist/helpers/handleDenyLeaveRequestWebhook.js +0 -21
- package/dist/helpers/handleDenyLeaveRequestWebhook.js.map +0 -1
- package/dist/helpers/handleGetAuthorizationUrlWebhook.d.ts +0 -12
- package/dist/helpers/handleGetAuthorizationUrlWebhook.js +0 -27
- package/dist/helpers/handleGetAuthorizationUrlWebhook.js.map +0 -1
- package/dist/helpers/handleGetLeaveBalancesWebhook.d.ts +0 -13
- package/dist/helpers/handleGetLeaveBalancesWebhook.js +0 -27
- package/dist/helpers/handleGetLeaveBalancesWebhook.js.map +0 -1
- package/dist/helpers/handleGetLeaveCategoriesWebhook.d.ts +0 -15
- package/dist/helpers/handleGetLeaveCategoriesWebhook.js +0 -27
- package/dist/helpers/handleGetLeaveCategoriesWebhook.js.map +0 -1
- package/dist/helpers/handleGetLeaveRequestHoursWebhook.d.ts +0 -13
- package/dist/helpers/handleGetLeaveRequestHoursWebhook.js +0 -27
- package/dist/helpers/handleGetLeaveRequestHoursWebhook.js.map +0 -1
- package/dist/helpers/handleProcessLeaveRequestWebhook.d.ts +0 -15
- package/dist/helpers/handleProcessLeaveRequestWebhook.js +0 -21
- package/dist/helpers/handleProcessLeaveRequestWebhook.js.map +0 -1
- package/dist/helpers/handleRequest.d.ts +0 -12
- package/dist/helpers/handleRequest.js +0 -58
- package/dist/helpers/handleRequest.js.map +0 -1
- package/dist/helpers/handleRequestWithWorknice.d.ts +0 -23
- package/dist/helpers/handleRequestWithWorknice.js +0 -44
- package/dist/helpers/handleRequestWithWorknice.js.map +0 -1
- package/dist/helpers/handleTriggerIntegrationSyncWebhook.d.ts +0 -77
- package/dist/helpers/handleTriggerIntegrationSyncWebhook.js +0 -687
- package/dist/helpers/handleTriggerIntegrationSyncWebhook.js.map +0 -1
- package/dist/helpers/index.d.ts +0 -19
- package/dist/helpers/index.js +0 -29
- package/dist/helpers/index.js.map +0 -1
- package/dist/index.d.ts +0 -20
- package/dist/index.js +0 -10
- package/dist/index.js.map +0 -1
- package/dist/utils/disambiguatePersonConnections.d.ts +0 -25
- package/dist/utils/disambiguatePersonConnections.js +0 -18
- package/dist/utils/disambiguatePersonConnections.js.map +0 -1
- package/dist/utils/errorToString.d.ts +0 -22
- package/dist/utils/errorToString.js +0 -32
- package/dist/utils/errorToString.js.map +0 -1
- package/dist/utils/isNotNullable.d.ts +0 -10
- package/dist/utils/isNotNullable.js +0 -6
- package/dist/utils/isNotNullable.js.map +0 -1
- package/dist/utils/isSamePlainDate.d.ts +0 -3
- package/dist/utils/isSamePlainDate.js +0 -5
- package/dist/utils/isSamePlainDate.js.map +0 -1
- package/dist/utils/isValidPlainDate.d.ts +0 -1
- package/dist/utils/isValidPlainDate.js +0 -5
- package/dist/utils/isValidPlainDate.js.map +0 -1
- package/dist/utils/parsePlainDate.d.ts +0 -1
- package/dist/utils/parsePlainDate.js +0 -5
- package/dist/utils/parsePlainDate.js.map +0 -1
- package/dist/webhooks.d.ts +0 -112
- package/dist/webhooks.js +0 -1
- package/dist/webhooks.js.map +0 -1
|
@@ -1,687 +0,0 @@
|
|
|
1
|
-
import isInstantAfter from "@worknice/utils/temporal/isInstantAfter";
|
|
2
|
-
import isValidInstant from "@worknice/utils/temporal/isValidInstant";
|
|
3
|
-
import { Temporal } from "temporal-polyfill";
|
|
4
|
-
import { ConnectionStatus } from "../api/_types.js";
|
|
5
|
-
import comparePersonDataTransferLines from "../employee-records/comparePersonDataTransferLines.js";
|
|
6
|
-
import mergePersonDataTransferLines from "../employee-records/mergePersonDataTransferLines.js";
|
|
7
|
-
import validatePersonDataTransferLineBankAccounts from "../employee-records/validatePersonDataTransferLineBankAccounts.js";
|
|
8
|
-
import validatePersonDataTransferLineDateOfBirth from "../employee-records/validatePersonDataTransferLineDateOfBirth.js";
|
|
9
|
-
import validatePersonDataTransferLineFullName from "../employee-records/validatePersonDataTransferLineFullName.js";
|
|
10
|
-
import validatePersonDataTransferLineGender from "../employee-records/validatePersonDataTransferLineGender.js";
|
|
11
|
-
import validatePersonDataTransferLinePersonalEmail from "../employee-records/validatePersonDataTransferLinePersonalEmail.js";
|
|
12
|
-
import validatePersonDataTransferLinePersonalPhone from "../employee-records/validatePersonDataTransferLinePersonalPhone.js";
|
|
13
|
-
import validatePersonDataTransferLineResidentialAddress from "../employee-records/validatePersonDataTransferLineResidentialAddress.js";
|
|
14
|
-
import handleRequestWithWorknice from "./handleRequestWithWorknice.js";
|
|
15
|
-
const handleTriggerIntegrationSyncWebhook = async (request, {
|
|
16
|
-
createRemotePerson,
|
|
17
|
-
getApiToken,
|
|
18
|
-
getConfig,
|
|
19
|
-
getEnv,
|
|
20
|
-
getRemotePeople,
|
|
21
|
-
updateRemotePerson
|
|
22
|
-
}, options) => handleRequestWithWorknice(
|
|
23
|
-
request,
|
|
24
|
-
{
|
|
25
|
-
getApiToken,
|
|
26
|
-
handleRequest: async (context) => {
|
|
27
|
-
const { logger, payload, worknice } = context;
|
|
28
|
-
let cachedDataImport;
|
|
29
|
-
const getDataImport = async () => {
|
|
30
|
-
if (!cachedDataImport) {
|
|
31
|
-
cachedDataImport = await worknice.createDataImport({
|
|
32
|
-
integrationId: payload.integrationId
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
return cachedDataImport;
|
|
36
|
-
};
|
|
37
|
-
try {
|
|
38
|
-
logger.connect(worknice, payload.integrationId);
|
|
39
|
-
logger.indent("Retrieving Worknice data\u2026");
|
|
40
|
-
const integration = await worknice.getIntegration({
|
|
41
|
-
integrationId: payload.integrationId
|
|
42
|
-
});
|
|
43
|
-
if (integration.archived) {
|
|
44
|
-
logger.info("Integration is archived. Skipping sync.");
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
if (integration.status !== "SYNCING") {
|
|
48
|
-
logger.info("Integration does not have a syncing status. Skipping sync.");
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
logger.info("Retrieved integration from Worknice.");
|
|
52
|
-
const personConnections = await worknice.getPersonConnections({
|
|
53
|
-
integrationId: payload.integrationId
|
|
54
|
-
});
|
|
55
|
-
logger.info(`Retrieved ${personConnections.length} person connection(s) from Worknice.`);
|
|
56
|
-
const people = await worknice.getPeople({ orgId: integration.org.id });
|
|
57
|
-
logger.info(`Retrieved ${people.length} person(s) from Worknice.`);
|
|
58
|
-
logger.dedent("Completed retrieving Worknice data.");
|
|
59
|
-
const contextWithIntegration = {
|
|
60
|
-
...context,
|
|
61
|
-
integration
|
|
62
|
-
};
|
|
63
|
-
logger.indent("Loading configuration details\u2026");
|
|
64
|
-
const config = await getConfig(contextWithIntegration);
|
|
65
|
-
logger.info(
|
|
66
|
-
config.automaticMatching ? "Automatic matching enabled." : "Automatic matching disabled."
|
|
67
|
-
);
|
|
68
|
-
logger.info(`Using a "${config.mode}" sync mode.`);
|
|
69
|
-
logger.dedent("Finished loading configuration details.");
|
|
70
|
-
logger.indent(`Retrieving ${config.appName} data\u2026`);
|
|
71
|
-
const remotePeople = await getRemotePeople(contextWithIntegration);
|
|
72
|
-
logger.info(`Retrieved ${remotePeople.length} people from ${config.appName}.`);
|
|
73
|
-
logger.dedent(`Completed retrieving ${config.appName} data.`);
|
|
74
|
-
logger.indent("Updating person connections\u2026");
|
|
75
|
-
for (const remotePerson of remotePeople) {
|
|
76
|
-
const remotePersonName = personToName(remotePerson);
|
|
77
|
-
try {
|
|
78
|
-
const remotePersonConnection = personConnections.find(
|
|
79
|
-
(connection) => connection.remote?.id === remotePerson.metadata.sourceId
|
|
80
|
-
);
|
|
81
|
-
if (remotePerson.metadata.deleted) {
|
|
82
|
-
if (remotePersonConnection) {
|
|
83
|
-
await worknice.deletePersonConnection({
|
|
84
|
-
personConnectionId: remotePersonConnection.id
|
|
85
|
-
});
|
|
86
|
-
logger.info(
|
|
87
|
-
`Deleted connection for "${remotePersonName}" in ${config.appName} because they have been terminated.`
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
} else {
|
|
91
|
-
if (remotePersonConnection && (remotePersonConnection.status === ConnectionStatus.Connected || remotePersonConnection.status === ConnectionStatus.Merged)) {
|
|
92
|
-
if (remotePersonConnection.remote?.name !== remotePersonName) {
|
|
93
|
-
const connection = await worknice.updatePersonConnection({
|
|
94
|
-
personConnectionId: remotePersonConnection.id,
|
|
95
|
-
personId: remotePersonConnection.person.id,
|
|
96
|
-
remote: {
|
|
97
|
-
id: remotePerson.metadata.sourceId,
|
|
98
|
-
name: remotePersonName
|
|
99
|
-
},
|
|
100
|
-
status: remotePersonConnection.status
|
|
101
|
-
});
|
|
102
|
-
personConnections.splice(
|
|
103
|
-
personConnections.indexOf(remotePersonConnection),
|
|
104
|
-
1,
|
|
105
|
-
connection
|
|
106
|
-
);
|
|
107
|
-
logger.info(
|
|
108
|
-
`Updated person connection remote name from "${remotePersonConnection.remote?.name}" to "${remotePersonName}".`
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
} else {
|
|
112
|
-
if (remotePersonConnection && remotePersonConnection.remote?.name !== remotePersonName) {
|
|
113
|
-
const connection = await worknice.updatePersonConnection({
|
|
114
|
-
personConnectionId: remotePersonConnection.id,
|
|
115
|
-
remote: {
|
|
116
|
-
id: remotePerson.metadata.sourceId,
|
|
117
|
-
name: remotePersonName
|
|
118
|
-
},
|
|
119
|
-
status: remotePersonConnection.status
|
|
120
|
-
});
|
|
121
|
-
personConnections.splice(
|
|
122
|
-
personConnections.indexOf(remotePersonConnection),
|
|
123
|
-
1,
|
|
124
|
-
connection
|
|
125
|
-
);
|
|
126
|
-
logger.info(
|
|
127
|
-
`Updated person connection remote name from "${remotePersonConnection.remote?.name}" to "${remotePersonName}".`
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
const matchingWorknicePerson = people.find(
|
|
131
|
-
(person) => person.id === remotePerson.metadata.targetId || person.employeeCode !== null && person.employeeCode === remotePerson.metadata.employeeCode || person.personalEmail !== null && person.personalEmail === remotePerson.personalEmail?.personalEmail || person.profileEmail !== null && person.profileEmail === remotePerson.profile?.profileEmail
|
|
132
|
-
) ?? null;
|
|
133
|
-
if (config.automaticMatching === true && matchingWorknicePerson) {
|
|
134
|
-
const personConnection = personConnections.find(
|
|
135
|
-
(connection) => connection.person?.id === matchingWorknicePerson.id
|
|
136
|
-
);
|
|
137
|
-
if (personConnection?.status === ConnectionStatus.Connected || personConnection?.status === ConnectionStatus.Merged) {
|
|
138
|
-
logger.info(
|
|
139
|
-
`Unable to automatically match person "${matchingWorknicePerson.displayName}" in Worknice to person "${remotePersonName}" in ${config.appName} because the Worknice person has already been matched to a different ${config.appName} person.`
|
|
140
|
-
);
|
|
141
|
-
} else {
|
|
142
|
-
if (personConnection) {
|
|
143
|
-
if (remotePersonConnection) {
|
|
144
|
-
await worknice.deletePersonConnection({
|
|
145
|
-
personConnectionId: personConnection.id
|
|
146
|
-
});
|
|
147
|
-
personConnections.splice(personConnections.indexOf(personConnection), 1);
|
|
148
|
-
const updatedConnection = await worknice.updatePersonConnection({
|
|
149
|
-
personConnectionId: remotePersonConnection.id,
|
|
150
|
-
personId: matchingWorknicePerson.id,
|
|
151
|
-
remote: {
|
|
152
|
-
id: remotePerson.metadata.sourceId,
|
|
153
|
-
name: remotePersonName
|
|
154
|
-
},
|
|
155
|
-
status: ConnectionStatus.Connected
|
|
156
|
-
});
|
|
157
|
-
personConnections.splice(
|
|
158
|
-
personConnections.indexOf(remotePersonConnection),
|
|
159
|
-
1,
|
|
160
|
-
updatedConnection
|
|
161
|
-
);
|
|
162
|
-
logger.info(
|
|
163
|
-
`Automatically matched and combined person connections for person "${matchingWorknicePerson.displayName}" in Worknice and person "${remotePersonName}" in ${config.appName}.`
|
|
164
|
-
);
|
|
165
|
-
} else {
|
|
166
|
-
const updatedConnection = await worknice.updatePersonConnection({
|
|
167
|
-
personConnectionId: personConnection.id,
|
|
168
|
-
personId: personConnection.person.id,
|
|
169
|
-
remote: {
|
|
170
|
-
id: remotePerson.metadata.sourceId,
|
|
171
|
-
name: remotePersonName
|
|
172
|
-
},
|
|
173
|
-
status: ConnectionStatus.Connected
|
|
174
|
-
});
|
|
175
|
-
personConnections.splice(
|
|
176
|
-
personConnections.indexOf(personConnection),
|
|
177
|
-
1,
|
|
178
|
-
updatedConnection
|
|
179
|
-
);
|
|
180
|
-
logger.info(
|
|
181
|
-
`Automatically matched existing person connection for person "${matchingWorknicePerson.displayName}" in Worknice to person "${remotePersonName}" in ${config.appName}.`
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
} else {
|
|
185
|
-
if (remotePersonConnection) {
|
|
186
|
-
const updatedConnection = await worknice.updatePersonConnection({
|
|
187
|
-
personConnectionId: remotePersonConnection.id,
|
|
188
|
-
personId: matchingWorknicePerson.id,
|
|
189
|
-
remote: {
|
|
190
|
-
...remotePersonConnection.remote,
|
|
191
|
-
name: remotePersonName
|
|
192
|
-
},
|
|
193
|
-
status: ConnectionStatus.Connected
|
|
194
|
-
});
|
|
195
|
-
personConnections.splice(
|
|
196
|
-
personConnections.indexOf(remotePersonConnection),
|
|
197
|
-
1,
|
|
198
|
-
updatedConnection
|
|
199
|
-
);
|
|
200
|
-
logger.info(
|
|
201
|
-
`Automatically matched existing person connection for person "${remotePersonName}" in ${config.appName} to person "${matchingWorknicePerson.displayName}" in Worknice.`
|
|
202
|
-
);
|
|
203
|
-
} else {
|
|
204
|
-
const newPersonConnection = await worknice.createPersonConnection({
|
|
205
|
-
integrationId: payload.integrationId,
|
|
206
|
-
personId: matchingWorknicePerson.id,
|
|
207
|
-
remote: {
|
|
208
|
-
id: remotePerson.metadata.sourceId,
|
|
209
|
-
name: remotePersonName
|
|
210
|
-
},
|
|
211
|
-
status: ConnectionStatus.Connected
|
|
212
|
-
});
|
|
213
|
-
personConnections.push(newPersonConnection);
|
|
214
|
-
logger.info(
|
|
215
|
-
`Created new person connection for person "${remotePersonName}" in ${config.appName} and automatically matched to person "${matchingWorknicePerson.displayName}" in Worknice.`
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
} else if (remotePersonConnection === void 0) {
|
|
221
|
-
const newPersonConnection = await worknice.createPersonConnection({
|
|
222
|
-
integrationId: payload.integrationId,
|
|
223
|
-
remote: {
|
|
224
|
-
id: remotePerson.metadata.sourceId,
|
|
225
|
-
name: remotePersonName
|
|
226
|
-
},
|
|
227
|
-
status: ConnectionStatus.RemoteOnly
|
|
228
|
-
});
|
|
229
|
-
personConnections.push(newPersonConnection);
|
|
230
|
-
logger.info(
|
|
231
|
-
`New person connection created for person "${remotePersonName}" in ${config.appName}.`
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
} catch (error) {
|
|
237
|
-
logger.info(
|
|
238
|
-
`Unable to update person connection for person "${remotePersonName}" in ${config.appName} because of the following error:`
|
|
239
|
-
);
|
|
240
|
-
logger.error(error);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
logger.dedent("Finished updating person connections.");
|
|
244
|
-
if (config.mode === "one-way" || config.mode === "two-way") {
|
|
245
|
-
logger.indent("Updating people with connections marked as merged\u2026");
|
|
246
|
-
const mergedConnections = personConnections.filter(
|
|
247
|
-
(personConnection) => personConnection.status === ConnectionStatus.Merged
|
|
248
|
-
);
|
|
249
|
-
for (const personConnection of mergedConnections) {
|
|
250
|
-
const worknicePerson = people.find(
|
|
251
|
-
(person) => person.id === personConnection.person.id
|
|
252
|
-
);
|
|
253
|
-
const remotePerson = remotePeople.find(
|
|
254
|
-
(person) => person.metadata.sourceId === personConnection.remote.id
|
|
255
|
-
);
|
|
256
|
-
if (!worknicePerson) {
|
|
257
|
-
throw Error(
|
|
258
|
-
`Unable to find person in Worknice with the ID "${personConnection.person.id}".`
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
if (!remotePerson) {
|
|
262
|
-
throw Error(
|
|
263
|
-
`Unable to find person in ${config.appName} with the ID "${personConnection.remote.id}".`
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
|
-
const remotePersonName = personToName(remotePerson);
|
|
267
|
-
const worknicePersonDataTransferLine = {
|
|
268
|
-
...worknicePersonToPersonDataTransferLine(worknicePerson),
|
|
269
|
-
metadata: {
|
|
270
|
-
deleted: false,
|
|
271
|
-
employeeCode: worknicePerson.employeeCode ?? null,
|
|
272
|
-
sourceId: worknicePerson.id,
|
|
273
|
-
targetId: remotePerson.metadata.sourceId,
|
|
274
|
-
updatedAt: worknicePerson.updatedAt
|
|
275
|
-
},
|
|
276
|
-
profile: {
|
|
277
|
-
displayName: worknicePerson.displayName,
|
|
278
|
-
profileEmail: worknicePerson.profileEmail ?? null
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
const remotePersonDataTransferLine = remotePerson;
|
|
282
|
-
const comparison = comparePersonDataTransferLines(
|
|
283
|
-
worknicePersonDataTransferLine,
|
|
284
|
-
remotePersonDataTransferLine
|
|
285
|
-
);
|
|
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)) {
|
|
287
|
-
const worknicePersonUpdatedAt = Temporal.Instant.from(worknicePerson.updatedAt);
|
|
288
|
-
if (!isValidInstant(remotePerson.metadata.updatedAt)) {
|
|
289
|
-
throw Error(
|
|
290
|
-
`Invalid updatedAt value for ${config.appName} person "${remotePersonName}". Must be in ISO 8601 format, including a date, a time, and a time zone offset.`,
|
|
291
|
-
{
|
|
292
|
-
cause: Error(`Unable to parse: ${remotePerson.metadata.updatedAt}`)
|
|
293
|
-
}
|
|
294
|
-
);
|
|
295
|
-
}
|
|
296
|
-
const remotePersonUpdatedAt = Temporal.Instant.from(
|
|
297
|
-
remotePerson.metadata.updatedAt
|
|
298
|
-
);
|
|
299
|
-
if (isInstantAfter(worknicePersonUpdatedAt, remotePersonUpdatedAt)) {
|
|
300
|
-
if (config.mode === "two-way") {
|
|
301
|
-
if (!updateRemotePerson) {
|
|
302
|
-
throw Error(
|
|
303
|
-
"No updateRemotePerson function supplied to handleTriggerIntegrationSyncWebhook."
|
|
304
|
-
);
|
|
305
|
-
}
|
|
306
|
-
try {
|
|
307
|
-
await updateRemotePerson(
|
|
308
|
-
worknicePersonDataTransferLine,
|
|
309
|
-
contextWithIntegration
|
|
310
|
-
);
|
|
311
|
-
logger.info(`Updated person "${remotePersonName}" in ${config.appName}.`);
|
|
312
|
-
} catch (error) {
|
|
313
|
-
logger.info(
|
|
314
|
-
`Unable to update person "${remotePersonName}" in ${config.appName} because of the following error:`
|
|
315
|
-
);
|
|
316
|
-
logger.error(error);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
} else {
|
|
320
|
-
try {
|
|
321
|
-
const bankAccounts = validatePersonDataTransferLineBankAccounts(
|
|
322
|
-
remotePersonDataTransferLine.bankAccounts
|
|
323
|
-
);
|
|
324
|
-
const dateOfBirth = validatePersonDataTransferLineDateOfBirth(
|
|
325
|
-
remotePersonDataTransferLine.dateOfBirth
|
|
326
|
-
);
|
|
327
|
-
const fullName = validatePersonDataTransferLineFullName(
|
|
328
|
-
remotePersonDataTransferLine.fullName
|
|
329
|
-
);
|
|
330
|
-
const gender = validatePersonDataTransferLineGender(
|
|
331
|
-
remotePersonDataTransferLine.gender
|
|
332
|
-
);
|
|
333
|
-
const personalEmail = validatePersonDataTransferLinePersonalEmail(
|
|
334
|
-
remotePersonDataTransferLine.personalEmail
|
|
335
|
-
);
|
|
336
|
-
const personalPhone = validatePersonDataTransferLinePersonalPhone(
|
|
337
|
-
remotePersonDataTransferLine.personalPhone
|
|
338
|
-
);
|
|
339
|
-
const residentialAddress = validatePersonDataTransferLineResidentialAddress(
|
|
340
|
-
remotePersonDataTransferLine.residentialAddress
|
|
341
|
-
);
|
|
342
|
-
const dataImport = await getDataImport();
|
|
343
|
-
await worknice.createPersonDataImportLine({
|
|
344
|
-
bankAccounts,
|
|
345
|
-
config: {
|
|
346
|
-
bankAccounts: config.syncFields?.bankAccounts ?? false,
|
|
347
|
-
dateOfBirth: config.syncFields?.dateOfBirth ?? false,
|
|
348
|
-
emergencyContacts: config.syncFields?.emergencyContacts ?? false,
|
|
349
|
-
fullName: config.syncFields?.fullName ?? false,
|
|
350
|
-
gender: config.syncFields?.gender ?? false,
|
|
351
|
-
personalEmail: config.syncFields?.personalEmail ?? false,
|
|
352
|
-
personalPhone: config.syncFields?.personalPhone ?? false,
|
|
353
|
-
postalAddress: config.syncFields?.postalAddress ?? false,
|
|
354
|
-
profile: config.syncFields?.profile ?? false,
|
|
355
|
-
remuneration: config.syncFields?.remuneration ?? false,
|
|
356
|
-
residentialAddress: config.syncFields?.residentialAddress ?? false,
|
|
357
|
-
superFunds: config.syncFields?.superFunds ?? false,
|
|
358
|
-
taxDetails: config.syncFields?.taxDetails ?? false,
|
|
359
|
-
tenure: config.syncFields?.tenure ?? false
|
|
360
|
-
},
|
|
361
|
-
dataImportId: dataImport.id,
|
|
362
|
-
dateOfBirth,
|
|
363
|
-
emergencyContacts: null,
|
|
364
|
-
fullName,
|
|
365
|
-
gender,
|
|
366
|
-
personalEmail,
|
|
367
|
-
personalPhone,
|
|
368
|
-
personId: worknicePerson.id,
|
|
369
|
-
postalAddress: null,
|
|
370
|
-
residentialAddress,
|
|
371
|
-
// TODO: Enable syncing super funds. See PROD-2216.
|
|
372
|
-
superFunds: null,
|
|
373
|
-
// TODO: Enable syncing tax details. See PROD-2375.
|
|
374
|
-
taxDetails: null,
|
|
375
|
-
// TODO: Enable syncing tenure. See PROD-1371.
|
|
376
|
-
tenure: null
|
|
377
|
-
});
|
|
378
|
-
logger.info(`Updated person "${worknicePerson.displayName}" in Worknice.`);
|
|
379
|
-
} catch (error) {
|
|
380
|
-
logger.info(
|
|
381
|
-
`Unable to update person "${worknicePerson.displayName}" in Worknice because of the following error:`
|
|
382
|
-
);
|
|
383
|
-
logger.error(error);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
logger.dedent("Finished updating people with connections marked as merged.");
|
|
389
|
-
}
|
|
390
|
-
logger.indent("Merging unmerged connections\u2026");
|
|
391
|
-
const connectedConnections = personConnections.filter(
|
|
392
|
-
(personConnection) => personConnection.status === ConnectionStatus.Connected
|
|
393
|
-
);
|
|
394
|
-
for (const personConnection of connectedConnections) {
|
|
395
|
-
const worknicePerson = people.find(
|
|
396
|
-
(person) => person.id === personConnection.person.id
|
|
397
|
-
);
|
|
398
|
-
const remotePerson = remotePeople.find(
|
|
399
|
-
(person) => person.metadata.sourceId === personConnection.remote.id
|
|
400
|
-
);
|
|
401
|
-
if (!worknicePerson) {
|
|
402
|
-
throw Error(
|
|
403
|
-
`Unable to find person in Worknice with the ID "${personConnection.person.id}".`
|
|
404
|
-
);
|
|
405
|
-
}
|
|
406
|
-
if (!remotePerson) {
|
|
407
|
-
throw Error(
|
|
408
|
-
`Unable to find person in ${config.appName} with the ID "${personConnection.remote.id}".`
|
|
409
|
-
);
|
|
410
|
-
}
|
|
411
|
-
const remotePersonName = personToName(remotePerson);
|
|
412
|
-
logger.indent(
|
|
413
|
-
`Merging Worknice person "${worknicePerson.displayName}" with ${config.appName} person "${remotePersonName}"\u2026`
|
|
414
|
-
);
|
|
415
|
-
try {
|
|
416
|
-
if (config.mode === "one-way" || config.mode === "two-way") {
|
|
417
|
-
const worknicePersonUpdatedAt = Temporal.Instant.from(worknicePerson.updatedAt);
|
|
418
|
-
if (!isValidInstant(remotePerson.metadata.updatedAt)) {
|
|
419
|
-
throw Error(
|
|
420
|
-
`Invalid updatedAt value for ${config.appName} person "${remotePersonName}". Must be in ISO 8601 format, including a date, a time, and a time zone offset.`,
|
|
421
|
-
{
|
|
422
|
-
cause: Error(`Unable to parse: ${remotePerson.metadata.updatedAt}`)
|
|
423
|
-
}
|
|
424
|
-
);
|
|
425
|
-
}
|
|
426
|
-
const remotePersonUpdatedAt = Temporal.Instant.from(
|
|
427
|
-
remotePerson.metadata.updatedAt
|
|
428
|
-
);
|
|
429
|
-
const [primaryDataTransferLine, secondaryDataTransferLine] = isInstantAfter(
|
|
430
|
-
worknicePersonUpdatedAt,
|
|
431
|
-
remotePersonUpdatedAt
|
|
432
|
-
) ? [worknicePersonToPersonDataTransferLine(worknicePerson), remotePerson] : [remotePerson, worknicePersonToPersonDataTransferLine(worknicePerson)];
|
|
433
|
-
const mergedDataTransferLine = mergePersonDataTransferLines(
|
|
434
|
-
primaryDataTransferLine,
|
|
435
|
-
secondaryDataTransferLine
|
|
436
|
-
);
|
|
437
|
-
const bankAccounts = validatePersonDataTransferLineBankAccounts(
|
|
438
|
-
mergedDataTransferLine.bankAccounts
|
|
439
|
-
);
|
|
440
|
-
const dateOfBirth = validatePersonDataTransferLineDateOfBirth(
|
|
441
|
-
mergedDataTransferLine.dateOfBirth
|
|
442
|
-
);
|
|
443
|
-
const fullName = validatePersonDataTransferLineFullName(
|
|
444
|
-
mergedDataTransferLine.fullName
|
|
445
|
-
);
|
|
446
|
-
const gender = validatePersonDataTransferLineGender(mergedDataTransferLine.gender);
|
|
447
|
-
const personalEmail = validatePersonDataTransferLinePersonalEmail(
|
|
448
|
-
mergedDataTransferLine.personalEmail
|
|
449
|
-
);
|
|
450
|
-
const personalPhone = validatePersonDataTransferLinePersonalPhone(
|
|
451
|
-
mergedDataTransferLine.personalPhone
|
|
452
|
-
);
|
|
453
|
-
const residentialAddress = validatePersonDataTransferLineResidentialAddress(
|
|
454
|
-
mergedDataTransferLine.residentialAddress
|
|
455
|
-
);
|
|
456
|
-
const dataImport = await getDataImport();
|
|
457
|
-
await worknice.createPersonDataImportLine({
|
|
458
|
-
bankAccounts,
|
|
459
|
-
config: {
|
|
460
|
-
bankAccounts: config.syncFields?.bankAccounts ?? false,
|
|
461
|
-
dateOfBirth: config.syncFields?.dateOfBirth ?? false,
|
|
462
|
-
emergencyContacts: config.syncFields?.emergencyContacts ?? false,
|
|
463
|
-
fullName: config.syncFields?.fullName ?? false,
|
|
464
|
-
gender: config.syncFields?.gender ?? false,
|
|
465
|
-
personalEmail: config.syncFields?.personalEmail ?? false,
|
|
466
|
-
personalPhone: config.syncFields?.personalPhone ?? false,
|
|
467
|
-
postalAddress: config.syncFields?.postalAddress ?? false,
|
|
468
|
-
profile: config.syncFields?.profile ?? false,
|
|
469
|
-
remuneration: config.syncFields?.remuneration ?? false,
|
|
470
|
-
residentialAddress: config.syncFields?.residentialAddress ?? false,
|
|
471
|
-
superFunds: config.syncFields?.superFunds ?? false,
|
|
472
|
-
taxDetails: config.syncFields?.taxDetails ?? false,
|
|
473
|
-
tenure: config.syncFields?.tenure ?? false
|
|
474
|
-
},
|
|
475
|
-
dataImportId: dataImport.id,
|
|
476
|
-
dateOfBirth,
|
|
477
|
-
emergencyContacts: null,
|
|
478
|
-
fullName,
|
|
479
|
-
gender,
|
|
480
|
-
personalEmail,
|
|
481
|
-
personalPhone,
|
|
482
|
-
personId: worknicePerson.id,
|
|
483
|
-
postalAddress: null,
|
|
484
|
-
residentialAddress,
|
|
485
|
-
// TODO: Enable syncing super funds. See PROD-2216.
|
|
486
|
-
superFunds: null,
|
|
487
|
-
// TODO: Enable syncing tax details. See PROD-2375.
|
|
488
|
-
taxDetails: null,
|
|
489
|
-
// TODO: Enable syncing tenure. See PROD-1371.
|
|
490
|
-
tenure: null
|
|
491
|
-
});
|
|
492
|
-
logger.info(`Updated person "${worknicePerson.displayName}" in Worknice.`);
|
|
493
|
-
if (config.mode === "two-way") {
|
|
494
|
-
if (!updateRemotePerson) {
|
|
495
|
-
throw Error(
|
|
496
|
-
"No updateRemotePerson function supplied to handleTriggerIntegrationSyncWebhook."
|
|
497
|
-
);
|
|
498
|
-
}
|
|
499
|
-
await updateRemotePerson(
|
|
500
|
-
{
|
|
501
|
-
...mergedDataTransferLine,
|
|
502
|
-
metadata: {
|
|
503
|
-
deleted: false,
|
|
504
|
-
employeeCode: worknicePerson.employeeCode ?? null,
|
|
505
|
-
sourceId: worknicePerson.id,
|
|
506
|
-
targetId: remotePerson.metadata.sourceId,
|
|
507
|
-
updatedAt: worknicePerson.updatedAt
|
|
508
|
-
},
|
|
509
|
-
profile: {
|
|
510
|
-
displayName: worknicePerson.displayName,
|
|
511
|
-
profileEmail: worknicePerson.profileEmail ?? null
|
|
512
|
-
}
|
|
513
|
-
},
|
|
514
|
-
contextWithIntegration
|
|
515
|
-
);
|
|
516
|
-
logger.info(`Updated person "${remotePersonName}" in ${config.appName}.`);
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
await worknice.updatePersonConnection({
|
|
520
|
-
personConnectionId: personConnection.id,
|
|
521
|
-
personId: personConnection.person.id,
|
|
522
|
-
remote: {
|
|
523
|
-
id: remotePerson.metadata.sourceId,
|
|
524
|
-
name: remotePersonName
|
|
525
|
-
},
|
|
526
|
-
status: ConnectionStatus.Merged
|
|
527
|
-
});
|
|
528
|
-
logger.dedent(`Finished merging.`);
|
|
529
|
-
} catch (error) {
|
|
530
|
-
logger.info(
|
|
531
|
-
`Unable to merge ${config.appName} person "${remotePersonName}" and Worknice person "${worknicePerson.displayName}" because of the following error:`
|
|
532
|
-
);
|
|
533
|
-
logger.error(error);
|
|
534
|
-
logger.dedent();
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
logger.dedent("Finished merging unmerged connections.");
|
|
538
|
-
if (config.mode === "two-way") {
|
|
539
|
-
logger.indent(`Adding new people to ${config.appName}\u2026`);
|
|
540
|
-
const localOnlyConnections = personConnections.filter(
|
|
541
|
-
(personConnection) => personConnection.status === ConnectionStatus.LocalOnly
|
|
542
|
-
);
|
|
543
|
-
for (const personConnection of localOnlyConnections) {
|
|
544
|
-
const worknicePerson = people.find(
|
|
545
|
-
(person) => person.id === personConnection.person.id
|
|
546
|
-
);
|
|
547
|
-
if (!worknicePerson) {
|
|
548
|
-
throw Error(
|
|
549
|
-
`Unable to find person in Worknice with the ID "${personConnection.person.id}".`
|
|
550
|
-
);
|
|
551
|
-
}
|
|
552
|
-
try {
|
|
553
|
-
if (!createRemotePerson) {
|
|
554
|
-
throw Error(
|
|
555
|
-
"No createRemotePerson function supplied to handleTriggerIntegrationSyncWebhook."
|
|
556
|
-
);
|
|
557
|
-
}
|
|
558
|
-
const remote = await createRemotePerson(
|
|
559
|
-
{
|
|
560
|
-
...worknicePersonToPersonDataTransferLine(worknicePerson),
|
|
561
|
-
metadata: {
|
|
562
|
-
deleted: false,
|
|
563
|
-
employeeCode: worknicePerson.employeeCode ?? null,
|
|
564
|
-
sourceId: worknicePerson.id,
|
|
565
|
-
targetId: null,
|
|
566
|
-
updatedAt: worknicePerson.updatedAt
|
|
567
|
-
},
|
|
568
|
-
profile: {
|
|
569
|
-
displayName: worknicePerson.displayName,
|
|
570
|
-
profileEmail: worknicePerson.profileEmail ?? null
|
|
571
|
-
}
|
|
572
|
-
},
|
|
573
|
-
contextWithIntegration
|
|
574
|
-
);
|
|
575
|
-
if (personConnections.some((connection) => connection.remote?.id === remote.id)) {
|
|
576
|
-
throw Error(
|
|
577
|
-
`A connection already exists for the ${config.appName} person "${remote.name}".`
|
|
578
|
-
);
|
|
579
|
-
}
|
|
580
|
-
await worknice.updatePersonConnection({
|
|
581
|
-
personConnectionId: personConnection.id,
|
|
582
|
-
personId: personConnection.person.id,
|
|
583
|
-
remote,
|
|
584
|
-
status: ConnectionStatus.Merged
|
|
585
|
-
});
|
|
586
|
-
logger.info(`Added new person "${remote.name}" to ${config.appName}.`);
|
|
587
|
-
} catch (error) {
|
|
588
|
-
logger.info(
|
|
589
|
-
`Unable to add person "${worknicePerson.displayName}" in Worknice to ${config.appName} because of the following error:`
|
|
590
|
-
);
|
|
591
|
-
logger.error(error);
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
logger.dedent(`Finished adding new people to ${config.appName}.`);
|
|
595
|
-
}
|
|
596
|
-
await worknice.completeSync({ integrationId: payload.integrationId });
|
|
597
|
-
logger.info("Sync completed.");
|
|
598
|
-
} catch (error) {
|
|
599
|
-
await worknice.completeSync({ integrationId: payload.integrationId });
|
|
600
|
-
throw error;
|
|
601
|
-
}
|
|
602
|
-
},
|
|
603
|
-
parseRequest: async (context) => {
|
|
604
|
-
const payload = await context.request.json();
|
|
605
|
-
return {
|
|
606
|
-
env: await getEnv({ ...context, payload }),
|
|
607
|
-
payload
|
|
608
|
-
};
|
|
609
|
-
}
|
|
610
|
-
},
|
|
611
|
-
options
|
|
612
|
-
);
|
|
613
|
-
const personToName = (person) => {
|
|
614
|
-
if ((person.fullName?.givenName ?? "").trim() !== "" && (person.fullName?.familyName ?? "").trim() !== "") {
|
|
615
|
-
return `${person.fullName?.givenName} ${person.fullName?.familyName}`;
|
|
616
|
-
}
|
|
617
|
-
if ((person.profile?.displayName ?? "").trim() !== "") {
|
|
618
|
-
return `${person.profile?.displayName}`;
|
|
619
|
-
}
|
|
620
|
-
return `(unnamed person ${person.metadata.sourceId})`;
|
|
621
|
-
};
|
|
622
|
-
const worknicePersonToPersonDataTransferLine = (worknicePerson) => ({
|
|
623
|
-
bankAccounts: worknicePerson.bankAccount1AllocationMethod ? {
|
|
624
|
-
bankAccount1Allocation: worknicePerson.bankAccount1Allocation ?? null,
|
|
625
|
-
bankAccount1AllocationMethod: worknicePerson.bankAccount1AllocationMethod,
|
|
626
|
-
bankAccount1Bsb: worknicePerson.bankAccount1Bsb ?? null,
|
|
627
|
-
bankAccount1Name: worknicePerson.bankAccount1Name ?? null,
|
|
628
|
-
bankAccount1Number: worknicePerson.bankAccount1Number ?? null,
|
|
629
|
-
bankAccount2Allocation: worknicePerson.bankAccount2Allocation ?? null,
|
|
630
|
-
bankAccount2AllocationMethod: worknicePerson.bankAccount2AllocationMethod ?? null,
|
|
631
|
-
bankAccount2Bsb: worknicePerson.bankAccount2Bsb ?? null,
|
|
632
|
-
bankAccount2Name: worknicePerson.bankAccount2Name ?? null,
|
|
633
|
-
bankAccount2Number: worknicePerson.bankAccount2Number ?? null,
|
|
634
|
-
bankAccount3Allocation: worknicePerson.bankAccount3Allocation ?? null,
|
|
635
|
-
bankAccount3AllocationMethod: worknicePerson.bankAccount3AllocationMethod ?? null,
|
|
636
|
-
bankAccount3Bsb: worknicePerson.bankAccount3Bsb ?? null,
|
|
637
|
-
bankAccount3Name: worknicePerson.bankAccount3Name ?? null,
|
|
638
|
-
bankAccount3Number: worknicePerson.bankAccount3Number ?? null,
|
|
639
|
-
bankAccount4Allocation: worknicePerson.bankAccount4Allocation ?? null,
|
|
640
|
-
bankAccount4AllocationMethod: worknicePerson.bankAccount4AllocationMethod ?? null,
|
|
641
|
-
bankAccount4Bsb: worknicePerson.bankAccount4Bsb ?? null,
|
|
642
|
-
bankAccount4Name: worknicePerson.bankAccount4Name ?? null,
|
|
643
|
-
bankAccount4Number: worknicePerson.bankAccount4Number ?? null,
|
|
644
|
-
bankAccount5Allocation: worknicePerson.bankAccount5Allocation ?? null,
|
|
645
|
-
bankAccount5AllocationMethod: worknicePerson.bankAccount5AllocationMethod ?? null,
|
|
646
|
-
bankAccount5Bsb: worknicePerson.bankAccount5Bsb ?? null,
|
|
647
|
-
bankAccount5Name: worknicePerson.bankAccount5Name ?? null,
|
|
648
|
-
bankAccount5Number: worknicePerson.bankAccount5Number ?? null
|
|
649
|
-
} : null,
|
|
650
|
-
dateOfBirth: worknicePerson.dateOfBirth ? { dateOfBirth: worknicePerson.dateOfBirth } : null,
|
|
651
|
-
emergencyContacts: null,
|
|
652
|
-
fullName: worknicePerson.givenName ? {
|
|
653
|
-
familyName: worknicePerson.familyName ?? null,
|
|
654
|
-
givenName: worknicePerson.givenName ?? null,
|
|
655
|
-
otherGivenNames: worknicePerson.otherGivenNames ?? null
|
|
656
|
-
} : null,
|
|
657
|
-
gender: worknicePerson.gender ? {
|
|
658
|
-
gender: worknicePerson.gender
|
|
659
|
-
} : null,
|
|
660
|
-
personalEmail: worknicePerson.personalEmail ? {
|
|
661
|
-
personalEmail: worknicePerson.personalEmail
|
|
662
|
-
} : null,
|
|
663
|
-
personalPhone: worknicePerson.personalPhone ? {
|
|
664
|
-
personalPhone: worknicePerson.personalPhone
|
|
665
|
-
} : null,
|
|
666
|
-
postalAddress: null,
|
|
667
|
-
residentialAddress: worknicePerson.residentialAddressLine1 ? {
|
|
668
|
-
residentialAddressCity: worknicePerson.residentialAddressCity ?? null,
|
|
669
|
-
// FIXME: This should not default to "Australia". See PROD-1085.
|
|
670
|
-
residentialAddressCountry: worknicePerson.residentialAddressCountry ?? "Australia",
|
|
671
|
-
residentialAddressLine1: worknicePerson.residentialAddressLine1 ?? null,
|
|
672
|
-
residentialAddressLine2: worknicePerson.residentialAddressLine2 ?? null,
|
|
673
|
-
residentialAddressPostcode: worknicePerson.residentialAddressPostcode ?? null,
|
|
674
|
-
residentialAddressState: worknicePerson.residentialAddressState ?? null
|
|
675
|
-
} : null,
|
|
676
|
-
// TODO: Enable syncing super funds. See PROD-2216.
|
|
677
|
-
superFunds: null,
|
|
678
|
-
// TODO: Enable syncing tax details. See PROD-2375.
|
|
679
|
-
taxDetails: null,
|
|
680
|
-
// TODO: Enable syncing tenure. See PROD-1371.
|
|
681
|
-
tenure: null
|
|
682
|
-
});
|
|
683
|
-
var handleTriggerIntegrationSyncWebhook_default = handleTriggerIntegrationSyncWebhook;
|
|
684
|
-
export {
|
|
685
|
-
handleTriggerIntegrationSyncWebhook_default as default
|
|
686
|
-
};
|
|
687
|
-
//# sourceMappingURL=handleTriggerIntegrationSyncWebhook.js.map
|