@worknice/js-sdk 0.0.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.
Files changed (112) hide show
  1. package/LICENSE +16 -0
  2. package/README.md +5 -0
  3. package/dist/_types-DsB4q143.d.ts +127 -0
  4. package/dist/api/ApiError.d.ts +12 -0
  5. package/dist/api/ApiError.js +27 -0
  6. package/dist/api/ApiError.js.map +1 -0
  7. package/dist/api/_generated.d.ts +5040 -0
  8. package/dist/api/_generated.js +386 -0
  9. package/dist/api/_generated.js.map +1 -0
  10. package/dist/api/_types.d.ts +2 -0
  11. package/dist/api/_types.js +1 -0
  12. package/dist/api/_types.js.map +1 -0
  13. package/dist/api/assertNotNull.d.ts +5 -0
  14. package/dist/api/assertNotNull.js +14 -0
  15. package/dist/api/assertNotNull.js.map +1 -0
  16. package/dist/api/createApiOperation.d.ts +11 -0
  17. package/dist/api/createApiOperation.js +6 -0
  18. package/dist/api/createApiOperation.js.map +1 -0
  19. package/dist/api/createWorkniceClient.d.ts +2 -0
  20. package/dist/api/createWorkniceClient.js +101 -0
  21. package/dist/api/createWorkniceClient.js.map +1 -0
  22. package/dist/api/operations/activateIntegration.d.ts +22 -0
  23. package/dist/api/operations/activateIntegration.js +29 -0
  24. package/dist/api/operations/activateIntegration.js.map +1 -0
  25. package/dist/api/operations/createApiToken.d.ts +14 -0
  26. package/dist/api/operations/createApiToken.js +31 -0
  27. package/dist/api/operations/createApiToken.js.map +1 -0
  28. package/dist/api/operations/deleteApiToken.d.ts +10 -0
  29. package/dist/api/operations/deleteApiToken.js +21 -0
  30. package/dist/api/operations/deleteApiToken.js.map +1 -0
  31. package/dist/api/operations/getApiTokens.d.ts +14 -0
  32. package/dist/api/operations/getApiTokens.js +33 -0
  33. package/dist/api/operations/getApiTokens.js.map +1 -0
  34. package/dist/api/operations/initializeIntegration.d.ts +20 -0
  35. package/dist/api/operations/initializeIntegration.js +23 -0
  36. package/dist/api/operations/initializeIntegration.js.map +1 -0
  37. package/dist/employee-records/EQUALITY_CHECKS.d.ts +9 -0
  38. package/dist/employee-records/EQUALITY_CHECKS.js +100 -0
  39. package/dist/employee-records/EQUALITY_CHECKS.js.map +1 -0
  40. package/dist/employee-records/_types.d.ts +171 -0
  41. package/dist/employee-records/_types.js +1 -0
  42. package/dist/employee-records/_types.js.map +1 -0
  43. package/dist/employee-records/comparePersonDataTransferLines.d.ts +5 -0
  44. package/dist/employee-records/comparePersonDataTransferLines.js +338 -0
  45. package/dist/employee-records/comparePersonDataTransferLines.js.map +1 -0
  46. package/dist/employee-records/index.d.ts +16 -0
  47. package/dist/employee-records/index.js +25 -0
  48. package/dist/employee-records/index.js.map +1 -0
  49. package/dist/employee-records/mergePersonDataTransferLines.d.ts +5 -0
  50. package/dist/employee-records/mergePersonDataTransferLines.js +27 -0
  51. package/dist/employee-records/mergePersonDataTransferLines.js.map +1 -0
  52. package/dist/employee-records/validatePersonDataTransferLine.d.ts +5 -0
  53. package/dist/employee-records/validatePersonDataTransferLine.js +23 -0
  54. package/dist/employee-records/validatePersonDataTransferLine.js.map +1 -0
  55. package/dist/employee-records/validatePersonDataTransferLineBankAccounts.d.ts +5 -0
  56. package/dist/employee-records/validatePersonDataTransferLineBankAccounts.js +240 -0
  57. package/dist/employee-records/validatePersonDataTransferLineBankAccounts.js.map +1 -0
  58. package/dist/employee-records/validatePersonDataTransferLineEmergencyContacts.d.ts +5 -0
  59. package/dist/employee-records/validatePersonDataTransferLineEmergencyContacts.js +6 -0
  60. package/dist/employee-records/validatePersonDataTransferLineEmergencyContacts.js.map +1 -0
  61. package/dist/employee-records/validatePersonDataTransferLinePersonalDetails.d.ts +5 -0
  62. package/dist/employee-records/validatePersonDataTransferLinePersonalDetails.js +40 -0
  63. package/dist/employee-records/validatePersonDataTransferLinePersonalDetails.js.map +1 -0
  64. package/dist/employee-records/validatePersonDataTransferLinePostalAddress.d.ts +5 -0
  65. package/dist/employee-records/validatePersonDataTransferLinePostalAddress.js +39 -0
  66. package/dist/employee-records/validatePersonDataTransferLinePostalAddress.js.map +1 -0
  67. package/dist/employee-records/validatePersonDataTransferLineResidentialAddress.d.ts +5 -0
  68. package/dist/employee-records/validatePersonDataTransferLineResidentialAddress.js +39 -0
  69. package/dist/employee-records/validatePersonDataTransferLineResidentialAddress.js.map +1 -0
  70. package/dist/employee-records/validatePersonDataTransferLineSuperFunds.d.ts +5 -0
  71. package/dist/employee-records/validatePersonDataTransferLineSuperFunds.js +46 -0
  72. package/dist/employee-records/validatePersonDataTransferLineSuperFunds.js.map +1 -0
  73. package/dist/employee-records/validatePersonDataTransferLineTaxDetails.d.ts +5 -0
  74. package/dist/employee-records/validatePersonDataTransferLineTaxDetails.js +46 -0
  75. package/dist/employee-records/validatePersonDataTransferLineTaxDetails.js.map +1 -0
  76. package/dist/employee-records/validatePersonDataTransferLineTenure.d.ts +5 -0
  77. package/dist/employee-records/validatePersonDataTransferLineTenure.js +20 -0
  78. package/dist/employee-records/validatePersonDataTransferLineTenure.js.map +1 -0
  79. package/dist/helpers/_types.d.ts +17 -0
  80. package/dist/helpers/_types.js +1 -0
  81. package/dist/helpers/_types.js.map +1 -0
  82. package/dist/helpers/handleCreateIntegrationWebhook.d.ts +11 -0
  83. package/dist/helpers/handleCreateIntegrationWebhook.js +20 -0
  84. package/dist/helpers/handleCreateIntegrationWebhook.js.map +1 -0
  85. package/dist/helpers/handleGetAuthorizationUrlWebhook.d.ts +11 -0
  86. package/dist/helpers/handleGetAuthorizationUrlWebhook.js +19 -0
  87. package/dist/helpers/handleGetAuthorizationUrlWebhook.js.map +1 -0
  88. package/dist/helpers/handleRequestWithWorknice.d.ts +19 -0
  89. package/dist/helpers/handleRequestWithWorknice.js +46 -0
  90. package/dist/helpers/handleRequestWithWorknice.js.map +1 -0
  91. package/dist/helpers/index.d.ts +5 -0
  92. package/dist/helpers/index.js +5 -0
  93. package/dist/helpers/index.js.map +1 -0
  94. package/dist/index.d.ts +16 -0
  95. package/dist/index.js +12 -0
  96. package/dist/index.js.map +1 -0
  97. package/dist/utils/errorToString.d.ts +22 -0
  98. package/dist/utils/errorToString.js +28 -0
  99. package/dist/utils/errorToString.js.map +1 -0
  100. package/dist/utils/isAfter.d.ts +4 -0
  101. package/dist/utils/isAfter.js +5 -0
  102. package/dist/utils/isAfter.js.map +1 -0
  103. package/dist/utils/isSamePlainDate.d.ts +1 -0
  104. package/dist/utils/isSamePlainDate.js +5 -0
  105. package/dist/utils/isSamePlainDate.js.map +1 -0
  106. package/dist/utils/isValidPlainDate.d.ts +1 -0
  107. package/dist/utils/isValidPlainDate.js +5 -0
  108. package/dist/utils/isValidPlainDate.js.map +1 -0
  109. package/dist/utils/parsePlainDate.d.ts +1 -0
  110. package/dist/utils/parsePlainDate.js +5 -0
  111. package/dist/utils/parsePlainDate.js.map +1 -0
  112. package/package.json +71 -0
@@ -0,0 +1,46 @@
1
+ const validatePersonDataTransferLineTaxDetails = (value) => {
2
+ if (value === null) return null;
3
+ const {
4
+ hasLoanOrStudentDebt,
5
+ residencyStatus,
6
+ taxFreeThresholdClaimed,
7
+ taxFileNumber,
8
+ taxFileNumberExemption
9
+ } = value;
10
+ if (hasLoanOrStudentDebt === null) {
11
+ throw Error('Missing value for "has loan or student debt"');
12
+ }
13
+ if (residencyStatus === null) {
14
+ throw Error("Missing residency status");
15
+ }
16
+ if (taxFreeThresholdClaimed === null) {
17
+ throw Error('Missing value for "tax free threshold claimed"');
18
+ }
19
+ if (taxFileNumberExemption === null) {
20
+ throw Error("Missing tax file number exemption");
21
+ }
22
+ if (taxFileNumberExemption === "NONE") {
23
+ if (taxFileNumber === null) {
24
+ throw Error("Missing tax file number");
25
+ }
26
+ return {
27
+ hasLoanOrStudentDebt,
28
+ residencyStatus,
29
+ taxFreeThresholdClaimed,
30
+ taxFileNumber,
31
+ taxFileNumberExemption
32
+ };
33
+ }
34
+ return {
35
+ hasLoanOrStudentDebt,
36
+ residencyStatus,
37
+ taxFreeThresholdClaimed,
38
+ taxFileNumber: null,
39
+ taxFileNumberExemption
40
+ };
41
+ };
42
+ var validatePersonDataTransferLineTaxDetails_default = validatePersonDataTransferLineTaxDetails;
43
+ export {
44
+ validatePersonDataTransferLineTaxDetails_default as default
45
+ };
46
+ //# sourceMappingURL=validatePersonDataTransferLineTaxDetails.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/employee-records/validatePersonDataTransferLineTaxDetails.ts"],"sourcesContent":["import type { PartialPersonDataTransferLine, PersonDataTransferLine } from \"./_types.js\";\n\nconst validatePersonDataTransferLineTaxDetails = (\n value: PartialPersonDataTransferLine[\"taxDetails\"],\n): PersonDataTransferLine[\"taxDetails\"] => {\n if (value === null) return null;\n\n const {\n hasLoanOrStudentDebt,\n residencyStatus,\n taxFreeThresholdClaimed,\n taxFileNumber,\n taxFileNumberExemption,\n } = value;\n\n if (hasLoanOrStudentDebt === null) {\n throw Error('Missing value for \"has loan or student debt\"');\n }\n\n if (residencyStatus === null) {\n throw Error(\"Missing residency status\");\n }\n\n if (taxFreeThresholdClaimed === null) {\n throw Error('Missing value for \"tax free threshold claimed\"');\n }\n\n if (taxFileNumberExemption === null) {\n throw Error(\"Missing tax file number exemption\");\n }\n\n if (taxFileNumberExemption === \"NONE\") {\n if (taxFileNumber === null) {\n throw Error(\"Missing tax file number\");\n }\n\n // TODO: Check the TFN is a valid format. See PROD-2194.\n\n return {\n hasLoanOrStudentDebt,\n residencyStatus,\n taxFreeThresholdClaimed,\n taxFileNumber,\n taxFileNumberExemption,\n };\n }\n\n return {\n hasLoanOrStudentDebt,\n residencyStatus,\n taxFreeThresholdClaimed,\n taxFileNumber: null,\n taxFileNumberExemption,\n };\n};\n\nexport default validatePersonDataTransferLineTaxDetails;\n"],"mappings":"AAEA,MAAM,2CAA2C,CAC/C,UACyC;AACzC,MAAI,UAAU,KAAM,QAAO;AAE3B,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,MAAI,yBAAyB,MAAM;AACjC,UAAM,MAAM,8CAA8C;AAAA,EAC5D;AAEA,MAAI,oBAAoB,MAAM;AAC5B,UAAM,MAAM,0BAA0B;AAAA,EACxC;AAEA,MAAI,4BAA4B,MAAM;AACpC,UAAM,MAAM,gDAAgD;AAAA,EAC9D;AAEA,MAAI,2BAA2B,MAAM;AACnC,UAAM,MAAM,mCAAmC;AAAA,EACjD;AAEA,MAAI,2BAA2B,QAAQ;AACrC,QAAI,kBAAkB,MAAM;AAC1B,YAAM,MAAM,yBAAyB;AAAA,IACvC;AAIA,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe;AAAA,IACf;AAAA,EACF;AACF;AAEA,IAAO,mDAAQ;","names":[]}
@@ -0,0 +1,5 @@
1
+ import { PartialPersonDataTransferLine, PersonDataTransferLine } from './_types.js';
2
+
3
+ declare const validatePersonDataTransferLineTenure: (value: PartialPersonDataTransferLine["tenure"]) => PersonDataTransferLine["tenure"];
4
+
5
+ export { validatePersonDataTransferLineTenure as default };
@@ -0,0 +1,20 @@
1
+ import isValidPlainDate from "@worknice/shared/utils/isValidPlainDate";
2
+ const validatePersonDataTransferLineTenure = (value) => {
3
+ if (value === null) return null;
4
+ const { endDate, startDate } = value;
5
+ if (endDate !== null && !isValidPlainDate(endDate)) {
6
+ throw Error("Invalid end date");
7
+ }
8
+ if (!isValidPlainDate(startDate)) {
9
+ throw Error("Invalid start date");
10
+ }
11
+ return {
12
+ endDate,
13
+ startDate
14
+ };
15
+ };
16
+ var validatePersonDataTransferLineTenure_default = validatePersonDataTransferLineTenure;
17
+ export {
18
+ validatePersonDataTransferLineTenure_default as default
19
+ };
20
+ //# sourceMappingURL=validatePersonDataTransferLineTenure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/employee-records/validatePersonDataTransferLineTenure.ts"],"sourcesContent":["import isValidPlainDate from \"@worknice/shared/utils/isValidPlainDate\";\nimport type { PartialPersonDataTransferLine, PersonDataTransferLine } from \"./_types.js\";\n\nconst validatePersonDataTransferLineTenure = (\n value: PartialPersonDataTransferLine[\"tenure\"],\n): PersonDataTransferLine[\"tenure\"] => {\n if (value === null) return null;\n\n const { endDate, startDate } = value;\n\n if (endDate !== null && !isValidPlainDate(endDate)) {\n throw Error(\"Invalid end date\");\n }\n\n if (!isValidPlainDate(startDate)) {\n throw Error(\"Invalid start date\");\n }\n\n return {\n endDate,\n startDate,\n };\n};\n\nexport default validatePersonDataTransferLineTenure;\n"],"mappings":"AAAA,OAAO,sBAAsB;AAG7B,MAAM,uCAAuC,CAC3C,UACqC;AACrC,MAAI,UAAU,KAAM,QAAO;AAE3B,QAAM,EAAE,SAAS,UAAU,IAAI;AAE/B,MAAI,YAAY,QAAQ,CAAC,iBAAiB,OAAO,GAAG;AAClD,UAAM,MAAM,kBAAkB;AAAA,EAChC;AAEA,MAAI,CAAC,iBAAiB,SAAS,GAAG;AAChC,UAAM,MAAM,oBAAoB;AAAA,EAClC;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEA,IAAO,+CAAQ;","names":[]}
@@ -0,0 +1,17 @@
1
+ import { W as WorkniceClient } from '../_types-DsB4q143.js';
2
+ import '../api/_generated.js';
3
+
4
+ type HandlerOptions = {
5
+ apiUrl?: string;
6
+ debug?: boolean;
7
+ logger?: Logger;
8
+ };
9
+ type Logger = Pick<Console, "info" | "error">;
10
+ type TaskContext<T> = {
11
+ log: Logger;
12
+ payload: T;
13
+ request: Request;
14
+ worknice: WorkniceClient;
15
+ };
16
+
17
+ export type { HandlerOptions, Logger, TaskContext };
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=_types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,11 @@
1
+ import { CreateIntegrationRequestPayload } from '@worknice/shared/webhooks';
2
+ import { HandlerOptions, TaskContext } from './_types.js';
3
+ import '../_types-DsB4q143.js';
4
+ import '../api/_generated.js';
5
+
6
+ type Tasks = {
7
+ persistDetails: (context: TaskContext<CreateIntegrationRequestPayload>) => Promise<void>;
8
+ };
9
+ declare const handleCreateIntegrationWebhook: (request: Request, { persistDetails }: Tasks, options?: HandlerOptions) => Promise<Response>;
10
+
11
+ export { handleCreateIntegrationWebhook as default };
@@ -0,0 +1,20 @@
1
+ import handleRequestWithWorknice from "./handleRequestWithWorknice.js";
2
+ const handleCreateIntegrationWebhook = async (request, { persistDetails }, options) => handleRequestWithWorknice(
3
+ request,
4
+ {
5
+ getApiToken: async ({ payload }) => payload.apiToken,
6
+ handleRequest: async ({ log, payload, request: request2, worknice }) => {
7
+ log.info("Persisting details\u2026");
8
+ await persistDetails({ log, payload, request: request2, worknice });
9
+ log.info("Initializing integration\u2026");
10
+ await worknice.initializeIntegration({ id: payload.integrationId });
11
+ },
12
+ parsePayload: async ({ request: request2 }) => request2.json()
13
+ },
14
+ options
15
+ );
16
+ var handleCreateIntegrationWebhook_default = handleCreateIntegrationWebhook;
17
+ export {
18
+ handleCreateIntegrationWebhook_default as default
19
+ };
20
+ //# sourceMappingURL=handleCreateIntegrationWebhook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/helpers/handleCreateIntegrationWebhook.ts"],"sourcesContent":["import type { CreateIntegrationRequestPayload } from \"@worknice/shared/webhooks\";\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 ({ log, payload, request, worknice }) => {\n log.info(\"Persisting details…\");\n await persistDetails({ log, payload, request, worknice });\n log.info(\"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,eAAe,OAAO,EAAE,KAAK,SAAS,SAAAA,UAAS,SAAS,MAAM;AAC5D,UAAI,KAAK,0BAAqB;AAC9B,YAAM,eAAe,EAAE,KAAK,SAAS,SAAAA,UAAS,SAAS,CAAC;AACxD,UAAI,KAAK,gCAA2B;AACpC,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"]}
@@ -0,0 +1,11 @@
1
+ import { GetAuthorizationUrlRequestPayload } from '@worknice/shared/webhooks';
2
+ import { HandlerOptions, TaskContext } from './_types.js';
3
+ import '../_types-DsB4q143.js';
4
+ import '../api/_generated.js';
5
+
6
+ type Tasks = {
7
+ getAuthorisationUrl: (context: TaskContext<GetAuthorizationUrlRequestPayload>) => Promise<string>;
8
+ };
9
+ declare const handleGetAuthorizationUrlWebhook: (request: Request, { getAuthorisationUrl }: Tasks, options?: HandlerOptions) => Promise<Response>;
10
+
11
+ export { handleGetAuthorizationUrlWebhook as default };
@@ -0,0 +1,19 @@
1
+ import handleRequestWithWorknice from "./handleRequestWithWorknice.js";
2
+ const handleGetAuthorizationUrlWebhook = async (request, { getAuthorisationUrl }, options) => handleRequestWithWorknice(
3
+ request,
4
+ {
5
+ handleRequest: async (context) => {
6
+ context.log.info("Getting authorization url\u2026");
7
+ return {
8
+ authorizationUrl: await getAuthorisationUrl(context)
9
+ };
10
+ },
11
+ parsePayload: async ({ request: request2 }) => request2.json()
12
+ },
13
+ options
14
+ );
15
+ var handleGetAuthorizationUrlWebhook_default = handleGetAuthorizationUrlWebhook;
16
+ export {
17
+ handleGetAuthorizationUrlWebhook_default as default
18
+ };
19
+ //# sourceMappingURL=handleGetAuthorizationUrlWebhook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/helpers/handleGetAuthorizationUrlWebhook.ts"],"sourcesContent":["import type {\n GetAuthorizationUrlRequestPayload,\n GetAuthorizationUrlResponsePayload,\n} from \"@worknice/shared/webhooks\";\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.log.info(\"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,eAAe,OAAO,YAAY;AAChC,cAAQ,IAAI,KAAK,iCAA4B;AAC7C,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,19 @@
1
+ import { HandlerOptions, Logger, TaskContext } from './_types.js';
2
+ import '../_types-DsB4q143.js';
3
+ import '../api/_generated.js';
4
+
5
+ type Tasks<RequestPayload, ResponsePayload> = {
6
+ getApiToken?: (context: {
7
+ log: Logger;
8
+ payload: RequestPayload;
9
+ request: Request;
10
+ }) => Promise<string>;
11
+ handleRequest: (context: TaskContext<RequestPayload>) => Promise<ResponsePayload>;
12
+ parsePayload: (context: {
13
+ log: Logger;
14
+ request: Request;
15
+ }) => Promise<RequestPayload>;
16
+ };
17
+ declare const handleRequestWithWorknice: <RequestPayload, ResponsePayload extends object | undefined = undefined>(request: Request, tasks: Tasks<RequestPayload, ResponsePayload>, options?: HandlerOptions) => Promise<Response>;
18
+
19
+ export { handleRequestWithWorknice as default };
@@ -0,0 +1,46 @@
1
+ import createWorkniceClient from "../api/createWorkniceClient.js";
2
+ import errorToString from "../utils/errorToString.js";
3
+ const handleRequestWithWorknice = async (request, tasks, options) => {
4
+ const log = options?.logger ?? console;
5
+ try {
6
+ log.info("Parsing request payload\u2026");
7
+ const payload = await tasks.parsePayload({ log, request });
8
+ log.info("Getting Worknice API token\u2026");
9
+ const apiToken = tasks.getApiToken ? await tasks.getApiToken({ log, payload, request }) : void 0;
10
+ log.info("Creating Worknice client\u2026");
11
+ const worknice = createWorkniceClient({
12
+ accessToken: apiToken,
13
+ apiUrl: options?.apiUrl
14
+ });
15
+ log.info("Handling request\u2026");
16
+ const response = await tasks.handleRequest({
17
+ log,
18
+ payload,
19
+ request,
20
+ worknice
21
+ });
22
+ log.info("Serializing response\u2026");
23
+ const responseBody = typeof response === "object" ? JSON.stringify(response) : "ok";
24
+ log.info("Request complete.");
25
+ return new Response(responseBody, {
26
+ headers: {
27
+ "Content-Type": "application/json"
28
+ },
29
+ status: 200
30
+ });
31
+ } catch (error) {
32
+ const message = errorToString(error, {
33
+ format: options?.debug ? "chain" : "simple",
34
+ stack: options?.debug ?? false
35
+ });
36
+ log.error(message);
37
+ return new Response(message, {
38
+ status: 500
39
+ });
40
+ }
41
+ };
42
+ var handleRequestWithWorknice_default = handleRequestWithWorknice;
43
+ export {
44
+ handleRequestWithWorknice_default as default
45
+ };
46
+ //# sourceMappingURL=handleRequestWithWorknice.js.map
@@ -0,0 +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, Logger, TaskContext } from \"./_types.js\";\n\ntype Tasks<RequestPayload, ResponsePayload> = {\n getApiToken?: (context: {\n log: Logger;\n payload: RequestPayload;\n request: Request;\n }) => Promise<string>;\n handleRequest: (context: TaskContext<RequestPayload>) => Promise<ResponsePayload>;\n parsePayload: (context: { log: Logger; request: Request }) => Promise<RequestPayload>;\n};\n\nconst handleRequestWithWorknice = async <\n RequestPayload,\n ResponsePayload extends object | undefined = undefined,\n>(\n request: Request,\n tasks: Tasks<RequestPayload, ResponsePayload>,\n options?: HandlerOptions,\n) => {\n const log = options?.logger ?? console;\n\n try {\n log.info(\"Parsing request payload…\");\n\n const payload = await tasks.parsePayload({ log, request });\n\n log.info(\"Getting Worknice API token…\");\n\n const apiToken = tasks.getApiToken\n ? await tasks.getApiToken({ log, payload, request })\n : undefined;\n\n log.info(\"Creating Worknice client…\");\n\n const worknice = createWorkniceClient({\n accessToken: apiToken,\n apiUrl: options?.apiUrl,\n });\n\n log.info(\"Handling request…\");\n\n const response = await tasks.handleRequest({\n log,\n payload,\n request,\n worknice,\n });\n\n log.info(\"Serializing response…\");\n\n const responseBody = typeof response === \"object\" ? JSON.stringify(response) : \"ok\";\n\n log.info(\"Request complete.\");\n\n return new Response(responseBody, {\n headers: {\n \"Content-Type\": \"application/json\",\n },\n status: 200,\n });\n } catch (error) {\n const message = errorToString(error, {\n format: options?.debug ? \"chain\" : \"simple\",\n stack: options?.debug ?? false,\n });\n\n log.error(message);\n\n return new Response(message, {\n status: 500,\n });\n }\n};\n\nexport default handleRequestWithWorknice;\n"],"mappings":"AAAA,OAAO,0BAA0B;AACjC,OAAO,mBAAmB;AAa1B,MAAM,4BAA4B,OAIhC,SACA,OACA,YACG;AACH,QAAM,MAAM,SAAS,UAAU;AAE/B,MAAI;AACF,QAAI,KAAK,+BAA0B;AAEnC,UAAM,UAAU,MAAM,MAAM,aAAa,EAAE,KAAK,QAAQ,CAAC;AAEzD,QAAI,KAAK,kCAA6B;AAEtC,UAAM,WAAW,MAAM,cACnB,MAAM,MAAM,YAAY,EAAE,KAAK,SAAS,QAAQ,CAAC,IACjD;AAEJ,QAAI,KAAK,gCAA2B;AAEpC,UAAM,WAAW,qBAAqB;AAAA,MACpC,aAAa;AAAA,MACb,QAAQ,SAAS;AAAA,IACnB,CAAC;AAED,QAAI,KAAK,wBAAmB;AAE5B,UAAM,WAAW,MAAM,MAAM,cAAc;AAAA,MACzC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,QAAI,KAAK,4BAAuB;AAEhC,UAAM,eAAe,OAAO,aAAa,WAAW,KAAK,UAAU,QAAQ,IAAI;AAE/E,QAAI,KAAK,mBAAmB;AAE5B,WAAO,IAAI,SAAS,cAAc;AAAA,MAChC,SAAS;AAAA,QACP,gBAAgB;AAAA,MAClB;AAAA,MACA,QAAQ;AAAA,IACV,CAAC;AAAA,EACH,SAAS,OAAO;AACd,UAAM,UAAU,cAAc,OAAO;AAAA,MACnC,QAAQ,SAAS,QAAQ,UAAU;AAAA,MACnC,OAAO,SAAS,SAAS;AAAA,IAC3B,CAAC;AAED,QAAI,MAAM,OAAO;AAEjB,WAAO,IAAI,SAAS,SAAS;AAAA,MAC3B,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AACF;AAEA,IAAO,oCAAQ;","names":[]}
@@ -0,0 +1,5 @@
1
+ export { default as handleCreateIntegrationWebhook } from './handleCreateIntegrationWebhook.js';
2
+ import '@worknice/shared/webhooks';
3
+ import './_types.js';
4
+ import '../_types-DsB4q143.js';
5
+ import '../api/_generated.js';
@@ -0,0 +1,5 @@
1
+ import { default as default2 } from "./handleCreateIntegrationWebhook.js";
2
+ export {
3
+ default2 as handleCreateIntegrationWebhook
4
+ };
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/helpers/index.ts"],"sourcesContent":["export { default as handleCreateIntegrationWebhook } from \"./handleCreateIntegrationWebhook.js\";\n"],"mappings":"AAAA,SAAoB,WAAXA,gBAAiD;","names":["default"]}
@@ -0,0 +1,16 @@
1
+ export { default as comparePersonDataTransferLines } from './employee-records/comparePersonDataTransferLines.js';
2
+ export { default as mergePersonDataTransferLines } from './employee-records/mergePersonDataTransferLines.js';
3
+ export { default as validatePersonDataTransferLine } from './employee-records/validatePersonDataTransferLine.js';
4
+ export { default as validatePersonDataTransferLineBankAccounts } from './employee-records/validatePersonDataTransferLineBankAccounts.js';
5
+ export { default as validatePersonDataTransferLineEmergencyContacts } from './employee-records/validatePersonDataTransferLineEmergencyContacts.js';
6
+ export { default as validatePersonDataTransferLinePersonalDetails } from './employee-records/validatePersonDataTransferLinePersonalDetails.js';
7
+ export { default as validatePersonDataTransferLinePostalAddress } from './employee-records/validatePersonDataTransferLinePostalAddress.js';
8
+ export { default as validatePersonDataTransferLineResidentialAddress } from './employee-records/validatePersonDataTransferLineResidentialAddress.js';
9
+ export { default as validatePersonDataTransferLineSuperFunds } from './employee-records/validatePersonDataTransferLineSuperFunds.js';
10
+ export { default as validatePersonDataTransferLineTaxDetails } from './employee-records/validatePersonDataTransferLineTaxDetails.js';
11
+ export { default as validatePersonDataTransferLineTenure } from './employee-records/validatePersonDataTransferLineTenure.js';
12
+ export { PartialPersonDataTransferLine, PersonDataTransferLine, PersonDataTransferLineDiff } from './employee-records/_types.js';
13
+ export { default as isAfter } from '@worknice/shared/utils/isAfter';
14
+ export { default as isSamePlainDate } from '@worknice/shared/utils/isSamePlainDate';
15
+ export { default as isValidPlainDate } from '@worknice/shared/utils/isValidPlainDate';
16
+ export { default as parsePlainDate } from '@worknice/shared/utils/parsePlainDate';
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ export * from "./employee-records/index.js";
2
+ import { default as default2 } from "./utils/isAfter.js";
3
+ import { default as default3 } from "./utils/isSamePlainDate.js";
4
+ import { default as default4 } from "./utils/isValidPlainDate.js";
5
+ import { default as default5 } from "./utils/parsePlainDate.js";
6
+ export {
7
+ default2 as isAfter,
8
+ default3 as isSamePlainDate,
9
+ default4 as isValidPlainDate,
10
+ default5 as parsePlainDate
11
+ };
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from \"./employee-records/index.js\";\nexport type * from \"./employee-records/index.js\";\nexport { default as isAfter } from \"./utils/isAfter.js\";\nexport { default as isSamePlainDate } from \"./utils/isSamePlainDate.js\";\nexport { default as isValidPlainDate } from \"./utils/isValidPlainDate.js\";\nexport { default as parsePlainDate } from \"./utils/parsePlainDate.js\";\n"],"mappings":"AAAA,cAAc;AAEd,SAAoB,WAAXA,gBAA0B;AACnC,SAAoB,WAAXA,gBAAkC;AAC3C,SAAoB,WAAXA,gBAAmC;AAC5C,SAAoB,WAAXA,gBAAiC;","names":["default"]}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Converts an error to a string that can be logged. Displays a trace of errors
3
+ * causes, `errorCode` value from `ApiError` and a stack trace for the root
4
+ * error:
5
+ *
6
+ * ```txt
7
+ * [ApiError] (UNEXPECTED_RESPONSE) The API returned an unexpected response. This is likely a problem with the Worknice API or a mismatch between JS-SDK and the API. Make sure you are using the latest version of the JS-SDK.
8
+ * [RequestError] POST https://app.worknice.com/api/graphql 404 Not Found
9
+ *
10
+ * ApiError: The API returned an unexpected response. This is likely a problem with the Worknice API or a mismatch between JS-SDK and the API. Make sure you are using the latest version of the JS-SDK.
11
+ * at fetchFromApi (webpack-internal:///(api)/./src/api/createWorkniceClient.js:69:19)
12
+ * at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
13
+ * at async Object.eval [as initializeIntegration] (webpack-internal:///(api)/./src/api/operations/initializeIntegration.js:10:24)
14
+ * at async handleCreateIntegrationWebhook (webpack-internal:///(api)/./src/helpers/handleCreateIntegrationWebhook.js:21:9)
15
+ * ```
16
+ */
17
+ declare const errorToString: (error: unknown, options?: {
18
+ format: "chain" | "simple";
19
+ stack: boolean;
20
+ }) => string;
21
+
22
+ export { errorToString as default };
@@ -0,0 +1,28 @@
1
+ import ApiError from "../api/ApiError.js";
2
+ const errorToString = (error, options) => {
3
+ const message = options?.format === "simple" ? error instanceof Error ? error.message : `${error}` : errorToMessage(error);
4
+ const stack = options?.stack === false ? void 0 : errorToStack(error);
5
+ return stack ? `${message}
6
+
7
+ ${stack}
8
+ ` : `${message}
9
+ `;
10
+ };
11
+ const errorToMessage = (error, indent = 0) => {
12
+ if (error instanceof Error) {
13
+ return `[${error.name}] ${error instanceof ApiError ? `(${error.code}) ${error.message}` : error.message}${error.cause ? `
14
+ ${" ".repeat(indent + 1)}${errorToMessage(error.cause, indent + 1)}` : ""}`;
15
+ }
16
+ return JSON.stringify(error);
17
+ };
18
+ const errorToStack = (error) => {
19
+ if (error instanceof Error) {
20
+ return error.stack ?? (error.cause ? errorToStack(error.cause) : void 0);
21
+ }
22
+ return void 0;
23
+ };
24
+ var errorToString_default = errorToString;
25
+ export {
26
+ errorToString_default as default
27
+ };
28
+ //# sourceMappingURL=errorToString.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/errorToString.ts"],"sourcesContent":["import ApiError from \"../api/ApiError.js\";\n\n/**\n * Converts an error to a string that can be logged. Displays a trace of errors\n * causes, `errorCode` value from `ApiError` and a stack trace for the root\n * error:\n *\n * ```txt\n * [ApiError] (UNEXPECTED_RESPONSE) The API returned an unexpected response. This is likely a problem with the Worknice API or a mismatch between JS-SDK and the API. Make sure you are using the latest version of the JS-SDK.\n * [RequestError] POST https://app.worknice.com/api/graphql 404 Not Found\n *\n * ApiError: The API returned an unexpected response. This is likely a problem with the Worknice API or a mismatch between JS-SDK and the API. Make sure you are using the latest version of the JS-SDK.\n * at fetchFromApi (webpack-internal:///(api)/./src/api/createWorkniceClient.js:69:19)\n * at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n * at async Object.eval [as initializeIntegration] (webpack-internal:///(api)/./src/api/operations/initializeIntegration.js:10:24)\n * at async handleCreateIntegrationWebhook (webpack-internal:///(api)/./src/helpers/handleCreateIntegrationWebhook.js:21:9)\n * ```\n */\nconst errorToString = (\n error: unknown,\n options?: { format: \"chain\" | \"simple\"; stack: boolean },\n): string => {\n const message =\n options?.format === \"simple\"\n ? error instanceof Error\n ? error.message\n : `${error}`\n : errorToMessage(error);\n const stack = options?.stack === false ? undefined : errorToStack(error);\n return stack ? `${message}\\n\\n${stack}\\n` : `${message}\\n`;\n};\n\nconst errorToMessage = (error: unknown, indent: number = 0): string => {\n if (error instanceof Error) {\n return `[${error.name}] ${\n error instanceof ApiError ? `(${error.code}) ${error.message}` : error.message\n }${error.cause ? `\\n${\" \".repeat(indent + 1)}${errorToMessage(error.cause, indent + 1)}` : \"\"}`;\n }\n return JSON.stringify(error);\n};\n\nconst errorToStack = (error: unknown): string | undefined => {\n if (error instanceof Error) {\n return error.stack ?? (error.cause ? errorToStack(error.cause) : undefined);\n }\n return undefined;\n};\n\nexport default errorToString;\n"],"mappings":"AAAA,OAAO,cAAc;AAkBrB,MAAM,gBAAgB,CACpB,OACA,YACW;AACX,QAAM,UACJ,SAAS,WAAW,WAChB,iBAAiB,QACf,MAAM,UACN,GAAG,KAAK,KACV,eAAe,KAAK;AAC1B,QAAM,QAAQ,SAAS,UAAU,QAAQ,SAAY,aAAa,KAAK;AACvE,SAAO,QAAQ,GAAG,OAAO;AAAA;AAAA,EAAO,KAAK;AAAA,IAAO,GAAG,OAAO;AAAA;AACxD;AAEA,MAAM,iBAAiB,CAAC,OAAgB,SAAiB,MAAc;AACrE,MAAI,iBAAiB,OAAO;AAC1B,WAAO,IAAI,MAAM,IAAI,KACnB,iBAAiB,WAAW,IAAI,MAAM,IAAI,KAAK,MAAM,OAAO,KAAK,MAAM,OACzE,GAAG,MAAM,QAAQ;AAAA,EAAK,KAAK,OAAO,SAAS,CAAC,CAAC,GAAG,eAAe,MAAM,OAAO,SAAS,CAAC,CAAC,KAAK,EAAE;AAAA,EAChG;AACA,SAAO,KAAK,UAAU,KAAK;AAC7B;AAEA,MAAM,eAAe,CAAC,UAAuC;AAC3D,MAAI,iBAAiB,OAAO;AAC1B,WAAO,MAAM,UAAU,MAAM,QAAQ,aAAa,MAAM,KAAK,IAAI;AAAA,EACnE;AACA,SAAO;AACT;AAEA,IAAO,wBAAQ;","names":[]}
@@ -0,0 +1,4 @@
1
+ export { default } from '@worknice/shared/utils/isAfter';
2
+ import '@worknice/shared/utils/isSamePlainDate';
3
+ import '@worknice/shared/utils/isValidPlainDate';
4
+ import '@worknice/shared/utils/parsePlainDate';
@@ -0,0 +1,5 @@
1
+ import { default as default2 } from "@worknice/shared/utils/isAfter";
2
+ export {
3
+ default2 as default
4
+ };
5
+ //# sourceMappingURL=isAfter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/isAfter.ts"],"sourcesContent":["export { default } from \"@worknice/shared/utils/isAfter\";\n"],"mappings":"AAAA,SAAS,WAAAA,gBAAe;","names":["default"]}
@@ -0,0 +1 @@
1
+ export { default } from '@worknice/shared/utils/isSamePlainDate';
@@ -0,0 +1,5 @@
1
+ import { default as default2 } from "@worknice/shared/utils/isSamePlainDate";
2
+ export {
3
+ default2 as default
4
+ };
5
+ //# sourceMappingURL=isSamePlainDate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/isSamePlainDate.ts"],"sourcesContent":["export { default } from \"@worknice/shared/utils/isSamePlainDate\";\n"],"mappings":"AAAA,SAAS,WAAAA,gBAAe;","names":["default"]}
@@ -0,0 +1 @@
1
+ export { default } from '@worknice/shared/utils/isValidPlainDate';
@@ -0,0 +1,5 @@
1
+ import { default as default2 } from "@worknice/shared/utils/isValidPlainDate";
2
+ export {
3
+ default2 as default
4
+ };
5
+ //# sourceMappingURL=isValidPlainDate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/isValidPlainDate.ts"],"sourcesContent":["export { default } from \"@worknice/shared/utils/isValidPlainDate\";\n"],"mappings":"AAAA,SAAS,WAAAA,gBAAe;","names":["default"]}
@@ -0,0 +1 @@
1
+ export { default } from '@worknice/shared/utils/parsePlainDate';
@@ -0,0 +1,5 @@
1
+ import { default as default2 } from "@worknice/shared/utils/parsePlainDate";
2
+ export {
3
+ default2 as default
4
+ };
5
+ //# sourceMappingURL=parsePlainDate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/parsePlainDate.ts"],"sourcesContent":["export { default } from \"@worknice/shared/utils/parsePlainDate\";\n"],"mappings":"AAAA,SAAS,WAAAA,gBAAe;","names":["default"]}
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@worknice/js-sdk",
3
+ "description": "",
4
+ "version": "0.0.1",
5
+ "license": "MIT",
6
+ "private": false,
7
+ "files": [
8
+ "dist",
9
+ "LICENSE"
10
+ ],
11
+ "type": "module",
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js",
18
+ "require": "./dist/index.js"
19
+ },
20
+ "./employee-records": {
21
+ "types": "./dist/employee-records/index.d.ts",
22
+ "import": "./dist/employee-records/index.js",
23
+ "require": "./dist/employee-records/index.js"
24
+ },
25
+ "./helpers": {
26
+ "types": "./dist/helpers/index.d.ts",
27
+ "import": "./dist/helpers/index.js",
28
+ "require": "./dist/helpers/index.js"
29
+ },
30
+ "./*": {
31
+ "types": "./dist/*.d.ts",
32
+ "import": "./dist/*.js",
33
+ "require": "./dist/*.js"
34
+ }
35
+ },
36
+ "dependencies": {
37
+ "dedent": "^0.7.0",
38
+ "@worknice/shared": "^0.0.0"
39
+ },
40
+ "devDependencies": {
41
+ "@graphql-codegen/add": "^5.0.0",
42
+ "@graphql-codegen/cli": "^5.0.0",
43
+ "@graphql-codegen/typescript": "^4.0.1",
44
+ "@graphql-codegen/typescript-operations": "^4.0.1",
45
+ "@graphql-eslint/eslint-plugin": "^3.19.3",
46
+ "@total-typescript/tsconfig": "^1.0.4",
47
+ "@types/dedent": "^0.7.0",
48
+ "@types/node": "^20.16.10",
49
+ "@typescript-eslint/eslint-plugin": "^8.7.0",
50
+ "@typescript-eslint/parser": "^8.7.0",
51
+ "currency.js": "^2.0.4",
52
+ "eslint": "^8.57.1",
53
+ "tsup": "^8.2.4",
54
+ "typescript": "~5.5.0"
55
+ },
56
+ "peerDependencies": {
57
+ "currency.js": "^2.0.4"
58
+ },
59
+ "scripts": {
60
+ "build": "rm -rf ./dist && tsup",
61
+ "dev": "pnpm run --stream \"/^dev:.*/\"",
62
+ "dev:tsup": "rm -rf ./dist && tsup --watch",
63
+ "dev:codegen": "graphql-codegen -c graphql.config.json -w",
64
+ "gen:types": "graphql-codegen -c graphql.config.json",
65
+ "release": "pnpm dlx @jsdevtools/version-bump-prompt --commit \"chore(js-sdk): release v%s\" --tag \"js-sdk-v%s\"",
66
+ "test": "if [[ -z $TURBO_HASH ]]; then echo 'Use `pnpm turbo test` to run tests.\n' && exit 1; else exit 0; fi",
67
+ "test:lint": "eslint src --color",
68
+ "test:prettier": "prettier -c '**/*.{js,ts,tsx,css}'",
69
+ "test:types": "tsc --noEmit --pretty"
70
+ }
71
+ }