@worknice/js-sdk 0.0.2 → 0.0.4
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-BXw9D0Qi.d.ts +642 -0
- package/dist/api/WorkniceIntegrationLogger.d.ts +99 -0
- package/dist/api/WorkniceIntegrationLogger.js +173 -0
- package/dist/api/WorkniceIntegrationLogger.js.map +1 -0
- package/dist/api/_generated.d.ts +357 -22
- package/dist/api/_generated.js.map +1 -1
- package/dist/api/_types.d.ts +2 -2
- package/dist/api/_types.js +1 -0
- package/dist/api/_types.js.map +1 -1
- package/dist/api/createApiOperation.d.ts +1 -1
- package/dist/api/createWorkniceClient.d.ts +1 -1
- package/dist/api/createWorkniceClient.js +21 -1
- package/dist/api/createWorkniceClient.js.map +1 -1
- package/dist/api/operations/activateIntegration.d.ts +1 -1
- package/dist/api/operations/authorizeIntegration.d.ts +20 -0
- package/dist/api/operations/authorizeIntegration.js +23 -0
- package/dist/api/operations/authorizeIntegration.js.map +1 -0
- package/dist/api/operations/completeSync.d.ts +20 -0
- package/dist/api/operations/completeSync.js +23 -0
- package/dist/api/operations/completeSync.js.map +1 -0
- package/dist/api/operations/createApiToken.d.ts +1 -1
- package/dist/api/operations/createDataImport.d.ts +12 -0
- package/dist/api/operations/createDataImport.js +25 -0
- package/dist/api/operations/createDataImport.js.map +1 -0
- package/dist/api/operations/createPersonConnection.d.ts +132 -0
- package/dist/api/operations/createPersonConnection.js +65 -0
- package/dist/api/operations/createPersonConnection.js.map +1 -0
- package/dist/api/operations/createPersonDataImportLine.d.ts +22 -0
- package/dist/api/operations/createPersonDataImportLine.js +49 -0
- package/dist/api/operations/createPersonDataImportLine.js.map +1 -0
- package/dist/api/operations/deleteApiToken.d.ts +1 -1
- package/dist/api/operations/deletePersonConnection.d.ts +10 -0
- package/dist/api/operations/deletePersonConnection.js +21 -0
- package/dist/api/operations/deletePersonConnection.js.map +1 -0
- package/dist/api/operations/getApiTokens.d.ts +1 -1
- package/dist/api/operations/getIntegration.d.ts +65 -0
- package/dist/api/operations/getIntegration.js +32 -0
- package/dist/api/operations/getIntegration.js.map +1 -0
- package/dist/api/operations/getPeople.d.ts +65 -0
- package/dist/api/operations/getPeople.js +79 -0
- package/dist/api/operations/getPeople.js.map +1 -0
- package/dist/api/operations/getPersonConnections.d.ts +107 -0
- package/dist/api/operations/getPersonConnections.js +43 -0
- package/dist/api/operations/getPersonConnections.js.map +1 -0
- package/dist/api/operations/initializeIntegration.d.ts +1 -1
- package/dist/api/operations/updatePersonConnection.d.ts +132 -0
- package/dist/api/operations/updatePersonConnection.js +65 -0
- package/dist/api/operations/updatePersonConnection.js.map +1 -0
- package/dist/employee-records/EQUALITY_CHECKS.d.ts +1 -0
- package/dist/employee-records/EQUALITY_CHECKS.js +0 -1
- package/dist/employee-records/EQUALITY_CHECKS.js.map +1 -1
- package/dist/employee-records/_types.d.ts +13 -12
- package/dist/employee-records/comparePersonDataTransferLines.d.ts +1 -0
- package/dist/employee-records/comparePersonDataTransferLines.js +0 -3
- package/dist/employee-records/comparePersonDataTransferLines.js.map +1 -1
- package/dist/employee-records/index.d.ts +1 -0
- package/dist/employee-records/mergePersonDataTransferLines.d.ts +1 -0
- package/dist/employee-records/mergePersonDataTransferLines.js +0 -1
- package/dist/employee-records/mergePersonDataTransferLines.js.map +1 -1
- package/dist/employee-records/validatePersonDataTransferLine.d.ts +1 -0
- package/dist/employee-records/validatePersonDataTransferLineBankAccounts.d.ts +1 -0
- package/dist/employee-records/validatePersonDataTransferLineBankAccounts.js +10 -9
- package/dist/employee-records/validatePersonDataTransferLineBankAccounts.js.map +1 -1
- package/dist/employee-records/validatePersonDataTransferLineEmergencyContacts.d.ts +1 -0
- package/dist/employee-records/validatePersonDataTransferLinePersonalDetails.d.ts +1 -0
- package/dist/employee-records/validatePersonDataTransferLinePersonalDetails.js +0 -2
- package/dist/employee-records/validatePersonDataTransferLinePersonalDetails.js.map +1 -1
- package/dist/employee-records/validatePersonDataTransferLinePostalAddress.d.ts +1 -0
- package/dist/employee-records/validatePersonDataTransferLineResidentialAddress.d.ts +1 -0
- package/dist/employee-records/validatePersonDataTransferLineSuperFunds.d.ts +1 -0
- package/dist/employee-records/validatePersonDataTransferLineTaxDetails.d.ts +1 -0
- package/dist/employee-records/validatePersonDataTransferLineTenure.d.ts +1 -0
- package/dist/helpers/_types.d.ts +7 -6
- package/dist/helpers/handleCreateIntegrationWebhook.d.ts +2 -1
- package/dist/helpers/handleCreateIntegrationWebhook.js +6 -4
- package/dist/helpers/handleCreateIntegrationWebhook.js.map +1 -1
- package/dist/helpers/handleGetAuthorizationUrlWebhook.d.ts +2 -1
- package/dist/helpers/handleGetAuthorizationUrlWebhook.js +4 -1
- package/dist/helpers/handleGetAuthorizationUrlWebhook.js.map +1 -1
- package/dist/helpers/handleGetLeaveBalancesWebhook.d.ts +14 -0
- package/dist/helpers/handleGetLeaveBalancesWebhook.js +22 -0
- package/dist/helpers/handleGetLeaveBalancesWebhook.js.map +1 -0
- package/dist/helpers/handleRequestWithWorknice.d.ts +9 -14
- package/dist/helpers/handleRequestWithWorknice.js +40 -19
- package/dist/helpers/handleRequestWithWorknice.js.map +1 -1
- package/dist/helpers/handleTriggerIntegrationSyncWebhook.d.ts +73 -0
- package/dist/helpers/handleTriggerIntegrationSyncWebhook.js +612 -0
- package/dist/helpers/handleTriggerIntegrationSyncWebhook.js.map +1 -0
- package/dist/helpers/index.d.ts +7 -1
- package/dist/helpers/index.js +9 -1
- package/dist/helpers/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/utils/disambiguatePersonConnections.d.ts +25 -0
- package/dist/utils/disambiguatePersonConnections.js +18 -0
- package/dist/utils/disambiguatePersonConnections.js.map +1 -0
- package/dist/utils/isNotNullable.d.ts +10 -0
- package/dist/utils/isNotNullable.js +6 -0
- package/dist/utils/isNotNullable.js.map +1 -0
- package/dist/webhooks.d.ts +13 -1
- package/package.json +8 -4
- package/dist/_types-DsB4q143.d.ts +0 -127
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PartialPersonDataTransferLine, PersonDataTransferLine } from './_types.js';
|
|
2
|
+
import '../api/_generated.js';
|
|
2
3
|
|
|
3
4
|
declare const validatePersonDataTransferLinePostalAddress: (value: PartialPersonDataTransferLine["postalAddress"]) => PersonDataTransferLine["postalAddress"];
|
|
4
5
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PartialPersonDataTransferLine, PersonDataTransferLine } from './_types.js';
|
|
2
|
+
import '../api/_generated.js';
|
|
2
3
|
|
|
3
4
|
declare const validatePersonDataTransferLineResidentialAddress: (value: PartialPersonDataTransferLine["residentialAddress"]) => PersonDataTransferLine["residentialAddress"];
|
|
4
5
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PartialPersonDataTransferLine, PersonDataTransferLine } from './_types.js';
|
|
2
|
+
import '../api/_generated.js';
|
|
2
3
|
|
|
3
4
|
declare const validatePersonDataTransferLineSuperFunds: (value: PartialPersonDataTransferLine["superFunds"]) => PersonDataTransferLine["superFunds"];
|
|
4
5
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PartialPersonDataTransferLine, PersonDataTransferLine } from './_types.js';
|
|
2
|
+
import '../api/_generated.js';
|
|
2
3
|
|
|
3
4
|
declare const validatePersonDataTransferLineTaxDetails: (value: PartialPersonDataTransferLine["taxDetails"]) => PersonDataTransferLine["taxDetails"];
|
|
4
5
|
|
package/dist/helpers/_types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { W as WorkniceClient } from '../_types-
|
|
1
|
+
import { W as WorkniceClient } from '../_types-BXw9D0Qi.js';
|
|
2
|
+
import WorkniceIntegrationLogger, { Logger } from '../api/WorkniceIntegrationLogger.js';
|
|
2
3
|
import '../api/_generated.js';
|
|
3
4
|
|
|
4
5
|
type HandlerOptions = {
|
|
@@ -6,12 +7,12 @@ type HandlerOptions = {
|
|
|
6
7
|
debug?: boolean;
|
|
7
8
|
logger?: Logger;
|
|
8
9
|
};
|
|
9
|
-
type
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
payload:
|
|
10
|
+
type TaskContext<Payload, Env = null> = {
|
|
11
|
+
env: Env;
|
|
12
|
+
logger: WorkniceIntegrationLogger;
|
|
13
|
+
payload: Payload;
|
|
13
14
|
request: Request;
|
|
14
15
|
worknice: WorkniceClient;
|
|
15
16
|
};
|
|
16
17
|
|
|
17
|
-
export type { HandlerOptions,
|
|
18
|
+
export type { HandlerOptions, TaskContext };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { CreateIntegrationRequestPayload } from '../webhooks.js';
|
|
2
2
|
import { HandlerOptions, TaskContext } from './_types.js';
|
|
3
|
-
import '../_types-
|
|
3
|
+
import '../_types-BXw9D0Qi.js';
|
|
4
4
|
import '../api/_generated.js';
|
|
5
|
+
import '../api/WorkniceIntegrationLogger.js';
|
|
5
6
|
|
|
6
7
|
type Tasks = {
|
|
7
8
|
persistDetails: (context: TaskContext<CreateIntegrationRequestPayload>) => Promise<void>;
|
|
@@ -3,10 +3,12 @@ const handleCreateIntegrationWebhook = async (request, { persistDetails }, optio
|
|
|
3
3
|
request,
|
|
4
4
|
{
|
|
5
5
|
getApiToken: async ({ payload }) => payload.apiToken,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
getEnv: async () => null,
|
|
7
|
+
handleRequest: async (context) => {
|
|
8
|
+
const { logger, payload, worknice } = context;
|
|
9
|
+
logger.debug("Persisting details\u2026");
|
|
10
|
+
await persistDetails(context);
|
|
11
|
+
logger.debug("Initializing integration\u2026");
|
|
10
12
|
await worknice.initializeIntegration({ id: payload.integrationId });
|
|
11
13
|
},
|
|
12
14
|
parsePayload: async ({ request: request2 }) => request2.json()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/helpers/handleCreateIntegrationWebhook.ts"],"sourcesContent":["import type { CreateIntegrationRequestPayload } from \"../webhooks.js\";\nimport type { HandlerOptions, TaskContext } from \"./_types.js\";\nimport handleRequestWithWorknice from \"./handleRequestWithWorknice.js\";\n\ntype Tasks = {\n persistDetails: (context: TaskContext<CreateIntegrationRequestPayload>) => Promise<void>;\n};\n\nconst handleCreateIntegrationWebhook = async (\n request: Request,\n { persistDetails }: Tasks,\n options?: HandlerOptions,\n) =>\n handleRequestWithWorknice<CreateIntegrationRequestPayload>(\n request,\n {\n getApiToken: async ({ payload }) => payload.apiToken,\n handleRequest: async ({
|
|
1
|
+
{"version":3,"sources":["../../src/helpers/handleCreateIntegrationWebhook.ts"],"sourcesContent":["import type { CreateIntegrationRequestPayload } from \"../webhooks.js\";\nimport type { HandlerOptions, TaskContext } from \"./_types.js\";\nimport handleRequestWithWorknice from \"./handleRequestWithWorknice.js\";\n\ntype Tasks = {\n persistDetails: (context: TaskContext<CreateIntegrationRequestPayload>) => Promise<void>;\n};\n\nconst handleCreateIntegrationWebhook = async (\n request: Request,\n { persistDetails }: Tasks,\n options?: HandlerOptions,\n) =>\n handleRequestWithWorknice<CreateIntegrationRequestPayload>(\n request,\n {\n getApiToken: async ({ payload }) => payload.apiToken,\n getEnv: async () => null,\n handleRequest: async (context) => {\n const { logger, payload, worknice } = context;\n logger.debug(\"Persisting details…\");\n await persistDetails(context);\n logger.debug(\"Initializing integration…\");\n await worknice.initializeIntegration({ id: payload.integrationId });\n },\n parsePayload: async ({ request }) => request.json(),\n },\n options,\n );\n\nexport default handleCreateIntegrationWebhook;\n"],"mappings":"AAEA,OAAO,+BAA+B;AAMtC,MAAM,iCAAiC,OACrC,SACA,EAAE,eAAe,GACjB,YAEA;AAAA,EACE;AAAA,EACA;AAAA,IACE,aAAa,OAAO,EAAE,QAAQ,MAAM,QAAQ;AAAA,IAC5C,QAAQ,YAAY;AAAA,IACpB,eAAe,OAAO,YAAY;AAChC,YAAM,EAAE,QAAQ,SAAS,SAAS,IAAI;AACtC,aAAO,MAAM,0BAAqB;AAClC,YAAM,eAAe,OAAO;AAC5B,aAAO,MAAM,gCAA2B;AACxC,YAAM,SAAS,sBAAsB,EAAE,IAAI,QAAQ,cAAc,CAAC;AAAA,IACpE;AAAA,IACA,cAAc,OAAO,EAAE,SAAAA,SAAQ,MAAMA,SAAQ,KAAK;AAAA,EACpD;AAAA,EACA;AACF;AAEF,IAAO,yCAAQ;","names":["request"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { GetAuthorizationUrlRequestPayload } from '../webhooks.js';
|
|
2
2
|
import { HandlerOptions, TaskContext } from './_types.js';
|
|
3
|
-
import '../_types-
|
|
3
|
+
import '../_types-BXw9D0Qi.js';
|
|
4
4
|
import '../api/_generated.js';
|
|
5
|
+
import '../api/WorkniceIntegrationLogger.js';
|
|
5
6
|
|
|
6
7
|
type Tasks = {
|
|
7
8
|
getAuthorisationUrl: (context: TaskContext<GetAuthorizationUrlRequestPayload>) => Promise<string>;
|
|
@@ -2,8 +2,11 @@ import handleRequestWithWorknice from "./handleRequestWithWorknice.js";
|
|
|
2
2
|
const handleGetAuthorizationUrlWebhook = async (request, { getAuthorisationUrl }, options) => handleRequestWithWorknice(
|
|
3
3
|
request,
|
|
4
4
|
{
|
|
5
|
+
getApiToken: async () => void 0,
|
|
6
|
+
getEnv: async () => null,
|
|
5
7
|
handleRequest: async (context) => {
|
|
6
|
-
|
|
8
|
+
const { logger } = context;
|
|
9
|
+
logger.debug("Getting authorization url\u2026");
|
|
7
10
|
return {
|
|
8
11
|
authorizationUrl: await getAuthorisationUrl(context)
|
|
9
12
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/helpers/handleGetAuthorizationUrlWebhook.ts"],"sourcesContent":["import type {\n GetAuthorizationUrlRequestPayload,\n GetAuthorizationUrlResponsePayload,\n} from \"../webhooks.js\";\nimport type { HandlerOptions, TaskContext } from \"./_types.js\";\nimport handleRequestWithWorknice from \"./handleRequestWithWorknice.js\";\n\ntype Tasks = {\n getAuthorisationUrl: (context: TaskContext<GetAuthorizationUrlRequestPayload>) => Promise<string>;\n};\n\nconst handleGetAuthorizationUrlWebhook = async (\n request: Request,\n { getAuthorisationUrl }: Tasks,\n options?: HandlerOptions,\n) =>\n handleRequestWithWorknice<GetAuthorizationUrlRequestPayload, GetAuthorizationUrlResponsePayload>(\n request,\n {\n handleRequest: async (context) => {\n context.
|
|
1
|
+
{"version":3,"sources":["../../src/helpers/handleGetAuthorizationUrlWebhook.ts"],"sourcesContent":["import type {\n GetAuthorizationUrlRequestPayload,\n GetAuthorizationUrlResponsePayload,\n} from \"../webhooks.js\";\nimport type { HandlerOptions, TaskContext } from \"./_types.js\";\nimport handleRequestWithWorknice from \"./handleRequestWithWorknice.js\";\n\ntype Tasks = {\n getAuthorisationUrl: (context: TaskContext<GetAuthorizationUrlRequestPayload>) => Promise<string>;\n};\n\nconst handleGetAuthorizationUrlWebhook = async (\n request: Request,\n { getAuthorisationUrl }: Tasks,\n options?: HandlerOptions,\n) =>\n handleRequestWithWorknice<GetAuthorizationUrlRequestPayload, GetAuthorizationUrlResponsePayload>(\n request,\n {\n getApiToken: async () => undefined,\n getEnv: async () => null,\n handleRequest: async (context) => {\n const { logger } = context;\n logger.debug(\"Getting authorization url…\");\n return {\n authorizationUrl: await getAuthorisationUrl(context),\n };\n },\n parsePayload: async ({ request }) => request.json(),\n },\n options,\n );\n\nexport default handleGetAuthorizationUrlWebhook;\n"],"mappings":"AAKA,OAAO,+BAA+B;AAMtC,MAAM,mCAAmC,OACvC,SACA,EAAE,oBAAoB,GACtB,YAEA;AAAA,EACE;AAAA,EACA;AAAA,IACE,aAAa,YAAY;AAAA,IACzB,QAAQ,YAAY;AAAA,IACpB,eAAe,OAAO,YAAY;AAChC,YAAM,EAAE,OAAO,IAAI;AACnB,aAAO,MAAM,iCAA4B;AACzC,aAAO;AAAA,QACL,kBAAkB,MAAM,oBAAoB,OAAO;AAAA,MACrD;AAAA,IACF;AAAA,IACA,cAAc,OAAO,EAAE,SAAAA,SAAQ,MAAMA,SAAQ,KAAK;AAAA,EACpD;AAAA,EACA;AACF;AAEF,IAAO,2CAAQ;","names":["request"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { GetLeaveBalancesResponsePayload, GetLeaveBalancesRequestPayload } from '../webhooks.js';
|
|
2
|
+
import { HandlerOptions, TaskContext } from './_types.js';
|
|
3
|
+
import '../_types-BXw9D0Qi.js';
|
|
4
|
+
import '../api/_generated.js';
|
|
5
|
+
import '../api/WorkniceIntegrationLogger.js';
|
|
6
|
+
|
|
7
|
+
type Context<Env> = TaskContext<GetLeaveBalancesRequestPayload, Env>;
|
|
8
|
+
type Tasks<Env> = {
|
|
9
|
+
getEnv: (context: Pick<Context<Env>, "logger" | "payload" | "request">) => Promise<Env>;
|
|
10
|
+
getLeaveBalances: (context: Context<Env>) => Promise<GetLeaveBalancesResponsePayload>;
|
|
11
|
+
};
|
|
12
|
+
declare const handleGetLeaveBalancesWebhook: <Env>(request: Request, { getEnv, getLeaveBalances }: Tasks<Env>, options?: HandlerOptions) => Promise<Response>;
|
|
13
|
+
|
|
14
|
+
export { handleGetLeaveBalancesWebhook as default };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import handleRequestWithWorknice from "./handleRequestWithWorknice.js";
|
|
2
|
+
const handleGetLeaveBalancesWebhook = async (request, { getEnv, getLeaveBalances }, options) => handleRequestWithWorknice(
|
|
3
|
+
request,
|
|
4
|
+
{
|
|
5
|
+
getApiToken: async () => void 0,
|
|
6
|
+
getEnv,
|
|
7
|
+
handleRequest: async (context) => {
|
|
8
|
+
const { logger } = context;
|
|
9
|
+
logger.info("Retrieving leave balances\u2026");
|
|
10
|
+
const result = await getLeaveBalances(context);
|
|
11
|
+
logger.info(`Retrieved ${result.length} leave balances.`);
|
|
12
|
+
return result;
|
|
13
|
+
},
|
|
14
|
+
parsePayload: async ({ request: request2 }) => request2.json()
|
|
15
|
+
},
|
|
16
|
+
options
|
|
17
|
+
);
|
|
18
|
+
var handleGetLeaveBalancesWebhook_default = handleGetLeaveBalancesWebhook;
|
|
19
|
+
export {
|
|
20
|
+
handleGetLeaveBalancesWebhook_default as default
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=handleGetLeaveBalancesWebhook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/helpers/handleGetLeaveBalancesWebhook.ts"],"sourcesContent":["import type {\n GetLeaveBalancesRequestPayload,\n GetLeaveBalancesResponsePayload,\n} from \"../webhooks.js\";\nimport type { HandlerOptions, TaskContext } from \"./_types.js\";\nimport handleRequestWithWorknice from \"./handleRequestWithWorknice.js\";\n\ntype Context<Env> = TaskContext<GetLeaveBalancesRequestPayload, Env>;\n\ntype Tasks<Env> = {\n getEnv: (context: Pick<Context<Env>, \"logger\" | \"payload\" | \"request\">) => Promise<Env>;\n getLeaveBalances: (context: Context<Env>) => Promise<GetLeaveBalancesResponsePayload>;\n};\n\nconst handleGetLeaveBalancesWebhook = async <Env>(\n request: Request,\n { getEnv, getLeaveBalances }: Tasks<Env>,\n options?: HandlerOptions,\n) =>\n handleRequestWithWorknice<GetLeaveBalancesRequestPayload, GetLeaveBalancesResponsePayload, Env>(\n request,\n {\n getApiToken: async () => undefined,\n getEnv,\n handleRequest: async (context) => {\n const { logger } = context;\n logger.info(\"Retrieving leave balances…\");\n const result = await getLeaveBalances(context);\n logger.info(`Retrieved ${result.length} leave balances.`);\n return result;\n },\n parsePayload: async ({ request }) => request.json(),\n },\n options,\n );\n\nexport default handleGetLeaveBalancesWebhook;\n"],"mappings":"AAKA,OAAO,+BAA+B;AAStC,MAAM,gCAAgC,OACpC,SACA,EAAE,QAAQ,iBAAiB,GAC3B,YAEA;AAAA,EACE;AAAA,EACA;AAAA,IACE,aAAa,YAAY;AAAA,IACzB;AAAA,IACA,eAAe,OAAO,YAAY;AAChC,YAAM,EAAE,OAAO,IAAI;AACnB,aAAO,KAAK,iCAA4B;AACxC,YAAM,SAAS,MAAM,iBAAiB,OAAO;AAC7C,aAAO,KAAK,aAAa,OAAO,MAAM,kBAAkB;AACxD,aAAO;AAAA,IACT;AAAA,IACA,cAAc,OAAO,EAAE,SAAAA,SAAQ,MAAMA,SAAQ,KAAK;AAAA,EACpD;AAAA,EACA;AACF;AAEF,IAAO,wCAAQ;","names":["request"]}
|
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
import { HandlerOptions,
|
|
2
|
-
import '../_types-
|
|
1
|
+
import { HandlerOptions, TaskContext } from './_types.js';
|
|
2
|
+
import '../_types-BXw9D0Qi.js';
|
|
3
3
|
import '../api/_generated.js';
|
|
4
|
+
import '../api/WorkniceIntegrationLogger.js';
|
|
4
5
|
|
|
5
|
-
type Tasks<RequestPayload, ResponsePayload> = {
|
|
6
|
-
getApiToken
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}) => Promise<string>;
|
|
11
|
-
handleRequest: (context: TaskContext<RequestPayload>) => Promise<ResponsePayload>;
|
|
12
|
-
parsePayload: (context: {
|
|
13
|
-
log: Logger;
|
|
14
|
-
request: Request;
|
|
15
|
-
}) => Promise<RequestPayload>;
|
|
6
|
+
type Tasks<RequestPayload, ResponsePayload, Env = null> = {
|
|
7
|
+
getApiToken: (context: Pick<TaskContext<RequestPayload, Env>, "env" | "logger" | "payload" | "request">) => Promise<string | undefined>;
|
|
8
|
+
getEnv: (context: Pick<TaskContext<RequestPayload, Env>, "logger" | "payload" | "request">) => Promise<Env>;
|
|
9
|
+
handleRequest: (context: TaskContext<RequestPayload, Env>) => Promise<ResponsePayload>;
|
|
10
|
+
parsePayload: (context: Pick<TaskContext<RequestPayload, Env>, "logger" | "request">) => Promise<RequestPayload>;
|
|
16
11
|
};
|
|
17
|
-
declare const handleRequestWithWorknice: <RequestPayload, ResponsePayload extends object | undefined = undefined>(request: Request, tasks: Tasks<RequestPayload, ResponsePayload>, options?: HandlerOptions) => Promise<Response>;
|
|
12
|
+
declare const handleRequestWithWorknice: <RequestPayload, ResponsePayload extends Response | object | undefined = undefined, Env = null>(request: Request, tasks: Tasks<RequestPayload, ResponsePayload, Env>, options?: HandlerOptions) => Promise<Response>;
|
|
18
13
|
|
|
19
14
|
export { handleRequestWithWorknice as default };
|
|
@@ -1,39 +1,60 @@
|
|
|
1
1
|
import createWorkniceClient from "../api/createWorkniceClient.js";
|
|
2
|
+
import WorkniceIntegrationLogger from "../api/WorkniceIntegrationLogger.js";
|
|
2
3
|
import errorToString from "../utils/errorToString.js";
|
|
3
4
|
const handleRequestWithWorknice = async (request, tasks, options) => {
|
|
4
|
-
const
|
|
5
|
+
const logger = new WorkniceIntegrationLogger(options?.logger ?? console);
|
|
5
6
|
try {
|
|
6
|
-
|
|
7
|
-
const payload = await tasks.parsePayload({
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
7
|
+
logger.debug("Parsing request payload\u2026");
|
|
8
|
+
const payload = await tasks.parsePayload({ logger, request });
|
|
9
|
+
logger.indent("Initialising environment\u2026");
|
|
10
|
+
const env = await tasks.getEnv({ logger, payload, request });
|
|
11
|
+
logger.dedent("Finished initialising environment.");
|
|
12
|
+
logger.indent("Initialising Worknice client\u2026");
|
|
13
|
+
const apiToken = await tasks.getApiToken({ env, logger, payload, request });
|
|
14
|
+
logger.info("Retrieved Worknice API token.");
|
|
11
15
|
const worknice = createWorkniceClient({
|
|
12
16
|
accessToken: apiToken,
|
|
13
17
|
apiUrl: options?.apiUrl
|
|
14
18
|
});
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
logger.info("Created Worknice client.");
|
|
20
|
+
logger.dedent("Finished initialising Worknice client.");
|
|
21
|
+
logger.debug("Handling request\u2026");
|
|
22
|
+
const result = await tasks.handleRequest({
|
|
23
|
+
env,
|
|
24
|
+
logger,
|
|
18
25
|
payload,
|
|
19
26
|
request,
|
|
20
27
|
worknice
|
|
21
28
|
});
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
logger.debug("Generating response\u2026");
|
|
30
|
+
let response;
|
|
31
|
+
if (result instanceof Response) {
|
|
32
|
+
response = result;
|
|
33
|
+
} else if (typeof result === "object") {
|
|
34
|
+
response = new Response(JSON.stringify(result), {
|
|
35
|
+
headers: {
|
|
36
|
+
"Content-Type": "application/json"
|
|
37
|
+
},
|
|
38
|
+
status: 200
|
|
39
|
+
});
|
|
40
|
+
} else {
|
|
41
|
+
response = new Response("ok", {
|
|
42
|
+
headers: {
|
|
43
|
+
"Content-Type": "application/json"
|
|
44
|
+
},
|
|
45
|
+
status: 200
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
logger.debug("Request complete.");
|
|
49
|
+
await logger.flush();
|
|
50
|
+
return response;
|
|
31
51
|
} catch (error) {
|
|
32
52
|
const message = errorToString(error, {
|
|
33
53
|
format: options?.debug ? "chain" : "simple",
|
|
34
54
|
stack: options?.debug ?? false
|
|
35
55
|
});
|
|
36
|
-
|
|
56
|
+
logger.error(message);
|
|
57
|
+
await logger.flush();
|
|
37
58
|
return new Response(message, {
|
|
38
59
|
status: 500
|
|
39
60
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/helpers/handleRequestWithWorknice.ts"],"sourcesContent":["import createWorkniceClient from \"../api/createWorkniceClient.js\";\nimport errorToString from \"../utils/errorToString.js\";\nimport type { HandlerOptions,
|
|
1
|
+
{"version":3,"sources":["../../src/helpers/handleRequestWithWorknice.ts"],"sourcesContent":["import createWorkniceClient from \"../api/createWorkniceClient.js\";\nimport WorkniceIntegrationLogger from \"../api/WorkniceIntegrationLogger.js\";\nimport errorToString from \"../utils/errorToString.js\";\nimport type { HandlerOptions, TaskContext } from \"./_types.js\";\n\ntype Tasks<RequestPayload, ResponsePayload, Env = null> = {\n getApiToken: (\n context: Pick<TaskContext<RequestPayload, Env>, \"env\" | \"logger\" | \"payload\" | \"request\">,\n ) => Promise<string | undefined>;\n getEnv: (\n context: Pick<TaskContext<RequestPayload, Env>, \"logger\" | \"payload\" | \"request\">,\n ) => Promise<Env>;\n handleRequest: (context: TaskContext<RequestPayload, Env>) => Promise<ResponsePayload>;\n parsePayload: (\n context: Pick<TaskContext<RequestPayload, Env>, \"logger\" | \"request\">,\n ) => Promise<RequestPayload>;\n};\n\nconst handleRequestWithWorknice = async <\n RequestPayload,\n ResponsePayload extends Response | object | undefined = undefined,\n Env = null,\n>(\n request: Request,\n tasks: Tasks<RequestPayload, ResponsePayload, Env>,\n options?: HandlerOptions,\n) => {\n const logger = new WorkniceIntegrationLogger(options?.logger ?? console);\n\n try {\n logger.debug(\"Parsing request payload…\");\n\n const payload = await tasks.parsePayload({ logger, request });\n\n logger.indent(\"Initialising environment…\");\n\n const env = await tasks.getEnv({ logger, payload, request });\n\n logger.dedent(\"Finished initialising environment.\");\n\n logger.indent(\"Initialising Worknice client…\");\n\n const apiToken = await tasks.getApiToken({ env, logger, payload, request });\n\n logger.info(\"Retrieved Worknice API token.\");\n\n const worknice = createWorkniceClient({\n accessToken: apiToken,\n apiUrl: options?.apiUrl,\n });\n\n logger.info(\"Created Worknice client.\");\n\n logger.dedent(\"Finished initialising Worknice client.\");\n\n logger.debug(\"Handling request…\");\n\n const result = await tasks.handleRequest({\n env,\n logger,\n payload,\n request,\n worknice,\n });\n\n logger.debug(\"Generating response…\");\n\n let response: Response;\n\n if (result instanceof Response) {\n response = result;\n } else if (typeof result === \"object\") {\n response = new Response(JSON.stringify(result), {\n headers: {\n \"Content-Type\": \"application/json\",\n },\n status: 200,\n });\n } else {\n response = new Response(\"ok\", {\n headers: {\n \"Content-Type\": \"application/json\",\n },\n status: 200,\n });\n }\n\n logger.debug(\"Request complete.\");\n\n await logger.flush();\n\n return response;\n } catch (error) {\n const message = errorToString(error, {\n format: options?.debug ? \"chain\" : \"simple\",\n stack: options?.debug ?? false,\n });\n\n logger.error(message);\n\n await logger.flush();\n\n return new Response(message, {\n status: 500,\n });\n }\n};\n\nexport default handleRequestWithWorknice;\n"],"mappings":"AAAA,OAAO,0BAA0B;AACjC,OAAO,+BAA+B;AACtC,OAAO,mBAAmB;AAgB1B,MAAM,4BAA4B,OAKhC,SACA,OACA,YACG;AACH,QAAM,SAAS,IAAI,0BAA0B,SAAS,UAAU,OAAO;AAEvE,MAAI;AACF,WAAO,MAAM,+BAA0B;AAEvC,UAAM,UAAU,MAAM,MAAM,aAAa,EAAE,QAAQ,QAAQ,CAAC;AAE5D,WAAO,OAAO,gCAA2B;AAEzC,UAAM,MAAM,MAAM,MAAM,OAAO,EAAE,QAAQ,SAAS,QAAQ,CAAC;AAE3D,WAAO,OAAO,oCAAoC;AAElD,WAAO,OAAO,oCAA+B;AAE7C,UAAM,WAAW,MAAM,MAAM,YAAY,EAAE,KAAK,QAAQ,SAAS,QAAQ,CAAC;AAE1E,WAAO,KAAK,+BAA+B;AAE3C,UAAM,WAAW,qBAAqB;AAAA,MACpC,aAAa;AAAA,MACb,QAAQ,SAAS;AAAA,IACnB,CAAC;AAED,WAAO,KAAK,0BAA0B;AAEtC,WAAO,OAAO,wCAAwC;AAEtD,WAAO,MAAM,wBAAmB;AAEhC,UAAM,SAAS,MAAM,MAAM,cAAc;AAAA,MACvC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,WAAO,MAAM,2BAAsB;AAEnC,QAAI;AAEJ,QAAI,kBAAkB,UAAU;AAC9B,iBAAW;AAAA,IACb,WAAW,OAAO,WAAW,UAAU;AACrC,iBAAW,IAAI,SAAS,KAAK,UAAU,MAAM,GAAG;AAAA,QAC9C,SAAS;AAAA,UACP,gBAAgB;AAAA,QAClB;AAAA,QACA,QAAQ;AAAA,MACV,CAAC;AAAA,IACH,OAAO;AACL,iBAAW,IAAI,SAAS,MAAM;AAAA,QAC5B,SAAS;AAAA,UACP,gBAAgB;AAAA,QAClB;AAAA,QACA,QAAQ;AAAA,MACV,CAAC;AAAA,IACH;AAEA,WAAO,MAAM,mBAAmB;AAEhC,UAAM,OAAO,MAAM;AAEnB,WAAO;AAAA,EACT,SAAS,OAAO;AACd,UAAM,UAAU,cAAc,OAAO;AAAA,MACnC,QAAQ,SAAS,QAAQ,UAAU;AAAA,MACnC,OAAO,SAAS,SAAS;AAAA,IAC3B,CAAC;AAED,WAAO,MAAM,OAAO;AAEpB,UAAM,OAAO,MAAM;AAEnB,WAAO,IAAI,SAAS,SAAS;AAAA,MAC3B,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AACF;AAEA,IAAO,oCAAQ;","names":[]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { W as WorkniceClient } from '../_types-BXw9D0Qi.js';
|
|
2
|
+
import { PartialPersonDataTransferLine } from '../employee-records/_types.js';
|
|
3
|
+
import { TriggerIntegrationSyncRequestPayload } from '../webhooks.js';
|
|
4
|
+
import { HandlerOptions, TaskContext } from './_types.js';
|
|
5
|
+
import '../api/_generated.js';
|
|
6
|
+
import '../api/WorkniceIntegrationLogger.js';
|
|
7
|
+
|
|
8
|
+
type Context<Env> = TaskContext<TriggerIntegrationSyncRequestPayload, Env> & {
|
|
9
|
+
integration: Awaited<ReturnType<WorkniceClient["getIntegration"]>>;
|
|
10
|
+
};
|
|
11
|
+
type Person = PartialPersonDataTransferLine & {
|
|
12
|
+
metadata: {
|
|
13
|
+
deleted: boolean;
|
|
14
|
+
employeeCode: string | null;
|
|
15
|
+
sourceId: string;
|
|
16
|
+
targetId: string | null;
|
|
17
|
+
updatedAt: string;
|
|
18
|
+
};
|
|
19
|
+
profile: {
|
|
20
|
+
displayName: string;
|
|
21
|
+
profileEmail: string | null;
|
|
22
|
+
} | null;
|
|
23
|
+
};
|
|
24
|
+
type Tasks<Env> = {
|
|
25
|
+
createRemotePerson?: (person: Person, context: Context<Env>) => Promise<{
|
|
26
|
+
id: string;
|
|
27
|
+
name: string;
|
|
28
|
+
}>;
|
|
29
|
+
getApiToken: (context: Pick<Context<Env>, "env" | "logger" | "payload" | "request">) => Promise<string>;
|
|
30
|
+
getConfig: (context: Context<Env>) => Promise<Config>;
|
|
31
|
+
getEnv: (context: Pick<Context<Env>, "logger" | "payload" | "request">) => Promise<Env>;
|
|
32
|
+
getRemotePeople: (context: Context<Env>) => Promise<Array<Person>>;
|
|
33
|
+
updateRemotePerson?: (person: Person, context: Context<Env>) => Promise<unknown>;
|
|
34
|
+
};
|
|
35
|
+
type Config = {
|
|
36
|
+
appName: string;
|
|
37
|
+
automaticMatching?: boolean;
|
|
38
|
+
mode?: "connection-only" | "one-way" | "two-way";
|
|
39
|
+
syncFields?: {
|
|
40
|
+
bankAccounts?: boolean;
|
|
41
|
+
emergencyContacts?: boolean;
|
|
42
|
+
personalDetails?: boolean;
|
|
43
|
+
postalAddress?: boolean;
|
|
44
|
+
profile?: boolean;
|
|
45
|
+
remuneration?: boolean;
|
|
46
|
+
residentialAddress?: boolean;
|
|
47
|
+
superFunds?: boolean;
|
|
48
|
+
taxDetails?: boolean;
|
|
49
|
+
tenure?: boolean;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* The process for syncing has four steps:
|
|
54
|
+
*
|
|
55
|
+
* 1. Update person connections: Create new person connections for Worknice
|
|
56
|
+
* people or remote people that don't have existing connections. If needed,
|
|
57
|
+
* update names of existing person connections. If enabled, automatically
|
|
58
|
+
* match connections.
|
|
59
|
+
*
|
|
60
|
+
* 2. Update merged people: Copy details from the Worknice people to remote
|
|
61
|
+
* people or vice-versa (based on whichever one was updated most recently)
|
|
62
|
+
* for person connections that are already marked as merged.
|
|
63
|
+
*
|
|
64
|
+
* 3. Merge matched people: Update both Worknice people and remote people for
|
|
65
|
+
* person connections that are marked as matched using details from both
|
|
66
|
+
* people merged together. Mark the connections as merged.
|
|
67
|
+
*
|
|
68
|
+
* 4. Add new people to the remote app: Create new people in the remote app for
|
|
69
|
+
* connections are unmatched and local-only. Mark the connections as merged.
|
|
70
|
+
*/
|
|
71
|
+
declare const handleTriggerIntegrationSyncWebhook: <Env>(request: Request, { createRemotePerson, getApiToken, getConfig, getEnv, getRemotePeople, updateRemotePerson, }: Tasks<Env>, options?: HandlerOptions) => Promise<Response>;
|
|
72
|
+
|
|
73
|
+
export { handleTriggerIntegrationSyncWebhook as default };
|