@gusto/embedded-react-sdk 0.55.8 → 0.56.0
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/CHANGELOG.md +40 -0
- package/dist/components/Common/UI/Menu/MenuTypes.js.map +1 -1
- package/dist/components/Common/UI/MultiSelectComboBox/MultiSelectComboBox.js +43 -42
- package/dist/components/Common/UI/MultiSelectComboBox/MultiSelectComboBox.js.map +1 -1
- package/dist/components/Company/AssignSignatory/CreateSignatory/useCreateSignatory.js +4 -3
- package/dist/components/Company/AssignSignatory/CreateSignatory/useCreateSignatory.js.map +1 -1
- package/dist/components/Company/AssignSignatory/InviteSignatory/useInviteSignatory.js +4 -3
- package/dist/components/Company/AssignSignatory/InviteSignatory/useInviteSignatory.js.map +1 -1
- package/dist/components/Company/AssignSignatory/useAssignSignatory.js +6 -5
- package/dist/components/Company/AssignSignatory/useAssignSignatory.js.map +1 -1
- package/dist/components/Company/BankAccount/BankAccountForm/context.js +4 -3
- package/dist/components/Company/BankAccount/BankAccountForm/context.js.map +1 -1
- package/dist/components/Company/DocumentSigner/DocumentList/useDocumentList.js +4 -3
- package/dist/components/Company/DocumentSigner/DocumentList/useDocumentList.js.map +1 -1
- package/dist/components/Company/FederalTaxes/useFederalTaxes.js +6 -5
- package/dist/components/Company/FederalTaxes/useFederalTaxes.js.map +1 -1
- package/dist/components/Company/Industry/Context.js +7 -6
- package/dist/components/Company/Industry/Context.js.map +1 -1
- package/dist/components/Company/Locations/LocationForm/useLocationForm.js +4 -3
- package/dist/components/Company/Locations/LocationForm/useLocationForm.js.map +1 -1
- package/dist/components/Company/Locations/LocationsList/useLocationsList.js +4 -3
- package/dist/components/Company/Locations/LocationsList/useLocationsList.js.map +1 -1
- package/dist/components/Company/OnboardingOverview/context.js +4 -3
- package/dist/components/Company/OnboardingOverview/context.js.map +1 -1
- package/dist/components/Company/StateTaxes/StateTaxesForm/context.js +4 -3
- package/dist/components/Company/StateTaxes/StateTaxesForm/context.js.map +1 -1
- package/dist/components/Company/StateTaxes/StateTaxesList/context.js +4 -3
- package/dist/components/Company/StateTaxes/StateTaxesList/context.js.map +1 -1
- package/dist/components/Company/StateTaxes/TaxRateManagement/context.js +4 -3
- package/dist/components/Company/StateTaxes/TaxRateManagement/context.js.map +1 -1
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/useDocumentList.js +4 -3
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/useDocumentList.js.map +1 -1
- package/dist/components/Employee/EmployeeList/management/ManagementEmployeeListView.js +70 -69
- package/dist/components/Employee/EmployeeList/management/ManagementEmployeeListView.js.map +1 -1
- package/dist/components/Employee/EmployeeList/onboarding/EmployeeListView.js +2 -2
- package/dist/components/Employee/EmployeeList/onboarding/EmployeeListView.js.map +1 -1
- package/dist/components/Employee/EmployeeList/shared/useEmployeeList.js +51 -42
- package/dist/components/Employee/EmployeeList/shared/useEmployeeList.js.map +1 -1
- package/dist/components/Employee/EmployeeListFlow/employeeListStateMachine.js +29 -26
- package/dist/components/Employee/EmployeeListFlow/employeeListStateMachine.js.map +1 -1
- package/dist/components/Employee/HomeAddress/management/HomeAddressView.js +2 -2
- package/dist/components/Employee/HomeAddress/management/HomeAddressView.js.map +1 -1
- package/dist/components/Employee/Terminations/TerminateEmployee/TerminateEmployeePresentation.js +11 -11
- package/dist/components/Employee/Terminations/TerminateEmployee/TerminateEmployeePresentation.js.map +1 -1
- package/dist/components/Employee/Terminations/TerminationSummary/TerminationSummaryPresentation.js +3 -3
- package/dist/components/Employee/Terminations/TerminationSummary/TerminationSummaryPresentation.js.map +1 -1
- package/dist/components/Employee/WorkAddress/management/WorkAddressView.js +76 -79
- package/dist/components/Employee/WorkAddress/management/WorkAddressView.js.map +1 -1
- package/dist/components/InformationRequests/InformationRequestList/InformationRequestList.js +2 -2
- package/dist/components/InformationRequests/InformationRequestList/InformationRequestList.js.map +1 -1
- package/dist/components/Payroll/ConfirmWireDetails/ConfirmWireDetailsBanner/ConfirmWireDetailsBanner.js +2 -2
- package/dist/components/Payroll/ConfirmWireDetails/ConfirmWireDetailsBanner/ConfirmWireDetailsBanner.js.map +1 -1
- package/dist/components/Payroll/Dismissal/DismissalPayPeriodSelection/DismissalPayPeriodSelectionPresentation.js +10 -10
- package/dist/components/Payroll/Dismissal/DismissalPayPeriodSelection/DismissalPayPeriodSelectionPresentation.js.map +1 -1
- package/dist/components/Payroll/GrossUpModal/GrossUpModal.js +49 -45
- package/dist/components/Payroll/GrossUpModal/GrossUpModal.js.map +1 -1
- package/dist/components/Payroll/OffCycleCreation/OffCycleCreation.js +83 -76
- package/dist/components/Payroll/OffCycleCreation/OffCycleCreation.js.map +1 -1
- package/dist/components/Payroll/OffCycleCreation/OffCycleCreationPresentation.js +63 -60
- package/dist/components/Payroll/OffCycleCreation/OffCycleCreationPresentation.js.map +1 -1
- package/dist/components/Payroll/PayrollConfiguration/PayrollConfiguration.js +184 -165
- package/dist/components/Payroll/PayrollConfiguration/PayrollConfiguration.js.map +1 -1
- package/dist/components/Payroll/PayrollConfiguration/useCalculationPoll.js +48 -34
- package/dist/components/Payroll/PayrollConfiguration/useCalculationPoll.js.map +1 -1
- package/dist/components/Payroll/PayrollOverview/PayrollOverview.js +185 -171
- package/dist/components/Payroll/PayrollOverview/PayrollOverview.js.map +1 -1
- package/dist/components/Payroll/PayrollOverview/useSubmissionPoll.js +45 -34
- package/dist/components/Payroll/PayrollOverview/useSubmissionPoll.js.map +1 -1
- package/dist/components/Payroll/PayrollReceipts/PayrollReceiptsPresentation.js +44 -44
- package/dist/components/Payroll/PayrollReceipts/PayrollReceiptsPresentation.js.map +1 -1
- package/dist/components/Payroll/PayrollReceipts/PayrollReceiptsPresentation.module.scss.js +14 -14
- package/dist/components/Payroll/PrintChecks/PrintChecksFailure/PrintChecksFailure.js +16 -16
- package/dist/components/Payroll/PrintChecks/PrintChecksFailure/PrintChecksFailure.js.map +1 -1
- package/dist/components/Payroll/PrintChecks/PrintChecksForm/useGenerationPoll.js +52 -37
- package/dist/components/Payroll/PrintChecks/PrintChecksForm/useGenerationPoll.js.map +1 -1
- package/dist/components/Payroll/usePreparedPayrollData.js +9 -8
- package/dist/components/Payroll/usePreparedPayrollData.js.map +1 -1
- package/dist/contexts/ApiProvider/ApiProvider.js +29 -28
- package/dist/contexts/ApiProvider/ApiProvider.js.map +1 -1
- package/dist/contexts/ApiProvider/apiVersionMismatchHook.js +15 -0
- package/dist/contexts/ApiProvider/apiVersionMismatchHook.js.map +1 -0
- package/dist/contexts/GustoProvider/GustoProviderCustomUIAdapter.js.map +1 -1
- package/dist/contexts/ThemeProvider/ThemeProvider.js +32 -26
- package/dist/contexts/ThemeProvider/ThemeProvider.js.map +1 -1
- package/dist/hooks/usePollingTask/usePollingTask.js +53 -41
- package/dist/hooks/usePollingTask/usePollingTask.js.map +1 -1
- package/dist/i18n/en/Employee.ManagementEmployeeList.json.js +28 -24
- package/dist/i18n/en/Employee.ManagementEmployeeList.json.js.map +1 -1
- package/dist/i18n/en/Payroll.GrossUpModal.json.js +12 -10
- package/dist/i18n/en/Payroll.GrossUpModal.json.js.map +1 -1
- package/dist/i18n/en/Payroll.PayrollConfiguration.json.js +8 -8
- package/dist/i18n/en/Payroll.PayrollOverview.json.js +15 -15
- package/dist/package.json.js +1 -1
- package/dist/src/components/Common/UI/ComboBox/ComboBoxTypes.d.ts +1 -1
- package/dist/src/components/Common/UI/DatePicker/DatePickerTypes.d.ts +2 -1
- package/dist/src/components/Common/UI/Menu/MenuTypes.d.ts +1 -1
- package/dist/src/components/Common/UI/MultiSelectComboBox/MultiSelectComboBox.d.ts +1 -1
- package/dist/src/components/Common/UI/MultiSelectComboBox/MultiSelectComboBoxTypes.d.ts +5 -0
- package/dist/src/components/Common/UI/Select/SelectTypes.d.ts +2 -1
- package/dist/src/components/Employee/EmployeeList/shared/useEmployeeList.d.ts +7 -2
- package/dist/src/components/Employee/EmployeeListFlow/employeeListStateMachine.test.d.ts +1 -0
- package/dist/src/components/Payroll/OffCycleCreation/OffCycleCreationPresentation.d.ts +1 -1
- package/dist/src/components/Payroll/OffCycleCreation/OffCycleCreationTypes.d.ts +6 -0
- package/dist/src/components/Payroll/PayrollConfiguration/useCalculationPoll.d.ts +6 -1
- package/dist/src/components/Payroll/PayrollOverview/useSubmissionPoll.d.ts +10 -1
- package/dist/src/contexts/ApiProvider/ApiProvider.d.ts +5 -3
- package/dist/src/contexts/ApiProvider/apiVersionMismatchHook.d.ts +3 -0
- package/dist/src/contexts/ApiProvider/apiVersionMismatchHook.test.d.ts +1 -0
- package/dist/src/contexts/GustoProvider/GustoProviderCustomUIAdapter.d.ts +9 -1
- package/dist/src/contexts/ThemeProvider/ThemeProvider.d.ts +8 -3
- package/dist/src/hooks/usePollingTask/usePollingTask.d.ts +55 -14
- package/dist/src/i18n/types.d.ts +14 -0
- package/dist/style.css +1 -1
- package/docs/guides/endpoint-inventory.json +5 -0
- package/package.json +6 -6
|
@@ -1,55 +1,70 @@
|
|
|
1
|
-
import { useRef as
|
|
2
|
-
import { buildGeneratedDocumentsGetQuery as
|
|
3
|
-
import { useGustoEmbeddedContext as
|
|
4
|
-
import { useQueryClient as
|
|
5
|
-
import { DocumentType as
|
|
6
|
-
import { GeneratedDocumentStatus as
|
|
7
|
-
import { usePollingTask as D } from "../../../../hooks/usePollingTask/usePollingTask.js";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { useRef as m, useCallback as f } from "react";
|
|
2
|
+
import { buildGeneratedDocumentsGetQuery as p } from "@gusto/embedded-api/react-query/generatedDocumentsGet";
|
|
3
|
+
import { useGustoEmbeddedContext as y } from "@gusto/embedded-api/react-query/_context";
|
|
4
|
+
import { useQueryClient as h } from "@tanstack/react-query";
|
|
5
|
+
import { DocumentType as P } from "@gusto/embedded-api/models/operations/getv1generateddocumentsdocumenttyperequestuuid";
|
|
6
|
+
import { GeneratedDocumentStatus as o } from "@gusto/embedded-api/models/components/generateddocument";
|
|
7
|
+
import { usePollingTask as D, isNonRetryablePollError as g } from "../../../../hooks/usePollingTask/usePollingTask.js";
|
|
8
|
+
import { useObservability as C } from "../../../../contexts/ObservabilityProvider/useObservability.js";
|
|
9
|
+
import { normalizeToSDKError as b } from "../../../../types/sdkError.js";
|
|
10
|
+
const k = "Payroll.PrintChecksForm", E = (e) => e?.generatedDocument?.status === o.Succeeded ? { type: "succeeded", url: e?.generatedDocument?.documentUrls?.[0] ?? null } : { type: "failed" }, v = (e) => {
|
|
11
|
+
if (!e.success)
|
|
12
|
+
return g(e.error) ? { status: "error", error: e.error } : { status: "polling" };
|
|
13
|
+
const r = e.data.generatedDocument?.status;
|
|
14
|
+
return r === o.Succeeded ? {
|
|
15
|
+
status: "done",
|
|
16
|
+
value: { type: "succeeded", url: e.data.generatedDocument?.documentUrls?.[0] ?? null }
|
|
17
|
+
} : r === o.Failed ? { status: "done", value: { type: "failed" } } : { status: "polling" };
|
|
18
|
+
};
|
|
19
|
+
function x({
|
|
20
|
+
onSucceeded: e,
|
|
17
21
|
onFailed: r
|
|
18
22
|
}) {
|
|
19
|
-
const l =
|
|
20
|
-
const
|
|
21
|
-
if (!
|
|
23
|
+
const l = y(), i = h(), s = m(null), { observability: c } = C(), d = (t) => {
|
|
24
|
+
const n = s.current;
|
|
25
|
+
if (!n)
|
|
22
26
|
throw new Error("usePollingTask started without a print-checks request in flight");
|
|
23
|
-
return
|
|
24
|
-
...
|
|
27
|
+
return i.fetchQuery({
|
|
28
|
+
...p(
|
|
25
29
|
l,
|
|
26
|
-
{ documentType:
|
|
27
|
-
{ signal:
|
|
30
|
+
{ documentType: P.PrintablePayrollChecks, requestUuid: n },
|
|
31
|
+
{ signal: t }
|
|
28
32
|
),
|
|
29
33
|
staleTime: 0
|
|
30
34
|
});
|
|
31
|
-
},
|
|
32
|
-
if (
|
|
35
|
+
}, u = (t) => {
|
|
36
|
+
if (t.type === "failed") {
|
|
33
37
|
r();
|
|
34
38
|
return;
|
|
35
39
|
}
|
|
36
|
-
t
|
|
37
|
-
}, { start:
|
|
38
|
-
fetch:
|
|
39
|
-
evaluate:
|
|
40
|
-
onDone:
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
e(t.url);
|
|
41
|
+
}, { start: a } = D({
|
|
42
|
+
fetch: d,
|
|
43
|
+
evaluate: v,
|
|
44
|
+
onDone: u,
|
|
45
|
+
// Unlike the payroll polls, print-checks generation has no equivalent to prepare/resubmit to
|
|
46
|
+
// guard against, so a non-retryable read error can safely reuse the same failure path as a
|
|
47
|
+
// real generation failure — same screen, same retry CTA.
|
|
48
|
+
onError: (t) => {
|
|
49
|
+
const n = b(t);
|
|
50
|
+
c?.onError?.({
|
|
51
|
+
...n,
|
|
52
|
+
timestamp: Date.now(),
|
|
53
|
+
componentName: k
|
|
54
|
+
}), r();
|
|
55
|
+
},
|
|
56
|
+
onDeadline: (t) => {
|
|
57
|
+
u(E(t));
|
|
43
58
|
}
|
|
44
59
|
});
|
|
45
|
-
return { start:
|
|
46
|
-
(
|
|
47
|
-
|
|
60
|
+
return { start: f(
|
|
61
|
+
(t) => {
|
|
62
|
+
s.current = t, a();
|
|
48
63
|
},
|
|
49
|
-
[
|
|
64
|
+
[a]
|
|
50
65
|
) };
|
|
51
66
|
}
|
|
52
67
|
export {
|
|
53
|
-
|
|
68
|
+
x as useGenerationPoll
|
|
54
69
|
};
|
|
55
70
|
//# sourceMappingURL=useGenerationPoll.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGenerationPoll.js","sources":["../../../../../src/components/Payroll/PrintChecks/PrintChecksForm/useGenerationPoll.ts"],"sourcesContent":["import { useCallback, useRef } from 'react'\nimport {\n buildGeneratedDocumentsGetQuery,\n type GeneratedDocumentsGetQueryData,\n} from '@gusto/embedded-api/react-query/generatedDocumentsGet'\nimport { useGustoEmbeddedContext } from '@gusto/embedded-api/react-query/_context'\nimport { useQueryClient } from '@tanstack/react-query'\nimport { DocumentType } from '@gusto/embedded-api/models/operations/getv1generateddocumentsdocumenttyperequestuuid'\nimport { GeneratedDocumentStatus } from '@gusto/embedded-api/models/components/generateddocument'\nimport {
|
|
1
|
+
{"version":3,"file":"useGenerationPoll.js","sources":["../../../../../src/components/Payroll/PrintChecks/PrintChecksForm/useGenerationPoll.ts"],"sourcesContent":["import { useCallback, useRef } from 'react'\nimport {\n buildGeneratedDocumentsGetQuery,\n type GeneratedDocumentsGetQueryData,\n} from '@gusto/embedded-api/react-query/generatedDocumentsGet'\nimport { useGustoEmbeddedContext } from '@gusto/embedded-api/react-query/_context'\nimport { useQueryClient } from '@tanstack/react-query'\nimport { DocumentType } from '@gusto/embedded-api/models/operations/getv1generateddocumentsdocumenttyperequestuuid'\nimport { GeneratedDocumentStatus } from '@gusto/embedded-api/models/components/generateddocument'\nimport {\n usePollingTask,\n isNonRetryablePollError,\n type PollReadOutcome,\n type PollTickResult,\n} from '@/hooks/usePollingTask/usePollingTask'\nimport { useObservability } from '@/contexts/ObservabilityProvider/useObservability'\nimport { normalizeToSDKError } from '@/types/sdkError'\n\nconst COMPONENT_NAME = 'Payroll.PrintChecksForm'\n\ntype PrintChecksOutcome = { type: 'succeeded'; url: string | null } | { type: 'failed' }\n\n// Verify against the last-known data before reporting failure: a document that already\n// finished generating must never be reported as a failure just because the deadline hit first.\nconst verifiedPrintChecksOutcome = (\n lastData: GeneratedDocumentsGetQueryData | null,\n): PrintChecksOutcome => {\n const status = lastData?.generatedDocument?.status\n if (status === GeneratedDocumentStatus.Succeeded) {\n return { type: 'succeeded', url: lastData?.generatedDocument?.documentUrls?.[0] ?? null }\n }\n return { type: 'failed' }\n}\n\nconst evaluatePrintChecksOutcome = (\n outcome: PollReadOutcome<GeneratedDocumentsGetQueryData>,\n): PollTickResult<PrintChecksOutcome> => {\n if (!outcome.success) {\n return isNonRetryablePollError(outcome.error)\n ? { status: 'error', error: outcome.error }\n : { status: 'polling' }\n }\n\n const status = outcome.data.generatedDocument?.status\n if (status === GeneratedDocumentStatus.Succeeded) {\n return {\n status: 'done',\n value: { type: 'succeeded', url: outcome.data.generatedDocument?.documentUrls?.[0] ?? null },\n }\n }\n if (status === GeneratedDocumentStatus.Failed) {\n return { status: 'done', value: { type: 'failed' } }\n }\n return { status: 'polling' }\n}\n\n/** @internal */\nexport interface UseGenerationPollOptions {\n onSucceeded: (url: string | null) => void\n onFailed: () => void\n}\n\n/** @internal */\nexport interface GenerationPoll {\n /** Starts polling the generated-document status for `requestUuid`. */\n start: (requestUuid: string) => void\n}\n\n/**\n * Polls a generated print-checks document until it reaches a terminal state, via\n * {@link usePollingTask}.\n *\n * @internal\n */\nexport function useGenerationPoll({\n onSucceeded,\n onFailed,\n}: UseGenerationPollOptions): GenerationPoll {\n const gustoClient = useGustoEmbeddedContext()\n const queryClient = useQueryClient()\n const requestUuidRef = useRef<string | null>(null)\n const { observability } = useObservability()\n\n // Unlike the payroll polls, there's no sibling `useGeneratedDocumentsGet` rendering this data —\n // the result is only ever downloaded, never displayed — so there's no other observer of this\n // queryKey for this fetchQuery call to race against, and no `refetch` to reuse instead.\n const fetchGeneratedDocument = (signal: AbortSignal) => {\n const requestUuid = requestUuidRef.current\n if (!requestUuid) {\n throw new Error('usePollingTask started without a print-checks request in flight')\n }\n return queryClient.fetchQuery({\n ...buildGeneratedDocumentsGetQuery(\n gustoClient,\n { documentType: DocumentType.PrintablePayrollChecks, requestUuid },\n { signal },\n ),\n staleTime: 0,\n })\n }\n\n const handleOutcome = (outcome: PrintChecksOutcome) => {\n if (outcome.type === 'failed') {\n onFailed()\n return\n }\n onSucceeded(outcome.url)\n }\n\n const { start: startPoll } = usePollingTask<GeneratedDocumentsGetQueryData, PrintChecksOutcome>({\n fetch: fetchGeneratedDocument,\n evaluate: evaluatePrintChecksOutcome,\n onDone: handleOutcome,\n // Unlike the payroll polls, print-checks generation has no equivalent to prepare/resubmit to\n // guard against, so a non-retryable read error can safely reuse the same failure path as a\n // real generation failure — same screen, same retry CTA.\n onError: error => {\n const sdkError = normalizeToSDKError(error)\n observability?.onError?.({\n ...sdkError,\n timestamp: Date.now(),\n componentName: COMPONENT_NAME,\n })\n onFailed()\n },\n onDeadline: lastData => {\n handleOutcome(verifiedPrintChecksOutcome(lastData))\n },\n })\n\n const start = useCallback(\n (requestUuid: string) => {\n requestUuidRef.current = requestUuid\n startPoll()\n },\n [startPoll],\n )\n\n return { start }\n}\n"],"names":["COMPONENT_NAME","verifiedPrintChecksOutcome","lastData","GeneratedDocumentStatus","evaluatePrintChecksOutcome","outcome","isNonRetryablePollError","status","useGenerationPoll","onSucceeded","onFailed","gustoClient","useGustoEmbeddedContext","queryClient","useQueryClient","requestUuidRef","useRef","observability","useObservability","fetchGeneratedDocument","signal","requestUuid","buildGeneratedDocumentsGetQuery","DocumentType","handleOutcome","startPoll","usePollingTask","error","sdkError","normalizeToSDKError","useCallback"],"mappings":";;;;;;;;;AAkBA,MAAMA,IAAiB,2BAMjBC,IAA6B,CACjCC,MAEeA,GAAU,mBAAmB,WAC7BC,EAAwB,YAC9B,EAAE,MAAM,aAAa,KAAKD,GAAU,mBAAmB,eAAe,CAAC,KAAK,KAAA,IAE9E,EAAE,MAAM,SAAA,GAGXE,IAA6B,CACjCC,MACuC;AACvC,MAAI,CAACA,EAAQ;AACX,WAAOC,EAAwBD,EAAQ,KAAK,IACxC,EAAE,QAAQ,SAAS,OAAOA,EAAQ,MAAA,IAClC,EAAE,QAAQ,UAAA;AAGhB,QAAME,IAASF,EAAQ,KAAK,mBAAmB;AAC/C,SAAIE,MAAWJ,EAAwB,YAC9B;AAAA,IACL,QAAQ;AAAA,IACR,OAAO,EAAE,MAAM,aAAa,KAAKE,EAAQ,KAAK,mBAAmB,eAAe,CAAC,KAAK,KAAA;AAAA,EAAK,IAG3FE,MAAWJ,EAAwB,SAC9B,EAAE,QAAQ,QAAQ,OAAO,EAAE,MAAM,WAAS,IAE5C,EAAE,QAAQ,UAAA;AACnB;AAoBO,SA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
|
|
15
15
|
import "../../contexts/LocaleProvider/useLocale.js";
|
|
16
16
|
import "../../shared/constants.js";
|
|
17
17
|
import "../../contexts/ComponentAdapter/useComponentContext.js";
|
|
18
|
+
import "../../contexts/LoadingIndicatorProvider/useLoadingIndicator.js";
|
|
18
19
|
import { retryAsync as x } from "../../helpers/retryAsync.js";
|
|
19
|
-
const q = 4, v = 1500, B = (e) => e instanceof T ? e.errors.some((r) => r.category === "invalid_operation") : !1,
|
|
20
|
+
const q = 4, v = 1500, B = (e) => e instanceof T ? e.errors.some((r) => r.category === "invalid_operation") : !1, $ = ({
|
|
20
21
|
companyId: e,
|
|
21
22
|
payrollId: r,
|
|
22
23
|
employeeUuids: a,
|
|
@@ -32,7 +33,7 @@ const q = 4, v = 1500, B = (e) => e instanceof T ? e.errors.some((r) => r.catego
|
|
|
32
33
|
enabled: !!o?.payPeriod?.payScheduleUuid
|
|
33
34
|
}
|
|
34
35
|
), P = y(async () => {
|
|
35
|
-
const
|
|
36
|
+
const s = await p({
|
|
36
37
|
request: {
|
|
37
38
|
companyId: e,
|
|
38
39
|
payrollId: r,
|
|
@@ -42,8 +43,8 @@ const q = 4, v = 1500, B = (e) => e instanceof T ? e.errors.some((r) => r.catego
|
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
});
|
|
45
|
-
f(
|
|
46
|
-
}, [e, r, p, h, n, l]),
|
|
46
|
+
f(s.payrollPrepared), s.payrollPrepared && (t.current = !0, l?.(s.payrollPrepared));
|
|
47
|
+
}, [e, r, p, h, n, l]), i = y(async () => {
|
|
47
48
|
await d(
|
|
48
49
|
null,
|
|
49
50
|
() => x(P, {
|
|
@@ -54,11 +55,11 @@ const q = 4, v = 1500, B = (e) => e instanceof T ? e.errors.some((r) => r.catego
|
|
|
54
55
|
);
|
|
55
56
|
}, [d, P]);
|
|
56
57
|
b(() => {
|
|
57
|
-
u.current || (u.current = !0,
|
|
58
|
-
}, [
|
|
58
|
+
u.current || (u.current = !0, i());
|
|
59
|
+
}, [i]);
|
|
59
60
|
const g = c && !t.current, R = c && t.current, A = g || E;
|
|
60
61
|
return {
|
|
61
|
-
handlePreparePayroll:
|
|
62
|
+
handlePreparePayroll: i,
|
|
62
63
|
preparedPayroll: o,
|
|
63
64
|
paySchedule: S?.payScheduleShow,
|
|
64
65
|
isLoading: A,
|
|
@@ -67,6 +68,6 @@ const q = 4, v = 1500, B = (e) => e instanceof T ? e.errors.some((r) => r.catego
|
|
|
67
68
|
};
|
|
68
69
|
};
|
|
69
70
|
export {
|
|
70
|
-
|
|
71
|
+
$ as usePreparedPayrollData
|
|
71
72
|
};
|
|
72
73
|
//# sourceMappingURL=usePreparedPayrollData.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePreparedPayrollData.js","sources":["../../../src/components/Payroll/usePreparedPayrollData.ts"],"sourcesContent":["import { useState, useEffect, useCallback, useRef, useMemo } from 'react'\nimport { usePayrollsPrepareMutation } from '@gusto/embedded-api/react-query/payrollsPrepare'\nimport { usePaySchedulesGet } from '@gusto/embedded-api/react-query/paySchedulesGet'\nimport type { PayrollPrepared } from '@gusto/embedded-api/models/components/payrollshow'\nimport type { PayScheduleShow } from '@gusto/embedded-api/models/components/payscheduleshow'\nimport { UnprocessableEntityError } from '@gusto/embedded-api/models/errors/unprocessableentityerror'\nimport { useBase } from '../Base'\nimport { retryAsync } from '@/helpers/retryAsync'\n\ninterface UsePreparedPayrollDataParams {\n companyId: string\n payrollId: string\n employeeUuids?: string[]\n sortBy?: string\n onDataReady?: (preparedPayroll: PayrollPrepared) => void\n}\n\ninterface UsePreparedPayrollDataReturn {\n handlePreparePayroll: () => Promise<void>\n preparedPayroll: PayrollPrepared | undefined\n paySchedule: PayScheduleShow | undefined\n isLoading: boolean\n isPaginating: boolean\n hasInitialData: boolean\n}\n\nconst PREPARE_MAX_ATTEMPTS = 4\nconst PREPARE_RETRY_DELAY_MS = 1500\n\nconst isPayrollBeingProcessedError = (error: unknown): boolean => {\n if (!(error instanceof UnprocessableEntityError)) return false\n return error.errors.some(e => e.category === 'invalid_operation')\n}\n\n/**\n * Wraps the prepare-payroll mutation and pay-schedule fetch, retrying while the payroll is still being processed.\n *\n * @remarks\n * Fires the prepare call once on mount, then exposes `handlePreparePayroll` for callers that need to re-prepare\n * (e.g. after sort or pagination changes). Distinguishes initial loading from subsequent pagination via\n * `isLoading` and `isPaginating`, and surfaces the pay schedule for the prepared payroll's pay period.\n *\n * @param params - The company and payroll identifiers, plus optional employee filter, sort, and ready callback.\n * @returns The prepared payroll, its pay schedule, loading flags, and a `handlePreparePayroll` callback to re-run.\n * @internal\n */\nexport const usePreparedPayrollData = ({\n companyId,\n payrollId,\n employeeUuids,\n sortBy,\n onDataReady,\n}: UsePreparedPayrollDataParams): UsePreparedPayrollDataReturn => {\n const { mutateAsync: preparePayroll, isPending: isPreparePayrollPending } =\n usePayrollsPrepareMutation()\n const [preparedPayroll, setPreparedPayroll] = useState<PayrollPrepared | undefined>()\n const hasInitialDataRef = useRef(false)\n const hasFiredRef = useRef(false)\n const { baseSubmitHandler } = useBase()\n\n const employeeUuidsKey = useMemo(() => employeeUuids?.join(',') ?? '', [employeeUuids])\n\n const { data: payScheduleData, isLoading: isPayScheduleLoading } = usePaySchedulesGet(\n {\n companyId,\n payScheduleId: preparedPayroll?.payPeriod?.payScheduleUuid || '',\n },\n {\n enabled: !!preparedPayroll?.payPeriod?.payScheduleUuid,\n },\n )\n\n const executePrepare = useCallback(async () => {\n const result = await preparePayroll({\n request: {\n companyId,\n payrollId,\n sortBy,\n requestBody: {\n employeeUuids,\n },\n },\n })\n setPreparedPayroll(result.payrollPrepared)\n if (result.payrollPrepared) {\n hasInitialDataRef.current = true\n onDataReady?.(result.payrollPrepared)\n }\n }, [companyId, payrollId, preparePayroll, employeeUuidsKey, sortBy, onDataReady])\n\n const handlePreparePayroll = useCallback(async () => {\n await baseSubmitHandler(null, () =>\n retryAsync(executePrepare, {\n maxAttempts: PREPARE_MAX_ATTEMPTS,\n delayMs: PREPARE_RETRY_DELAY_MS,\n shouldRetry: isPayrollBeingProcessedError,\n }),\n )\n }, [baseSubmitHandler, executePrepare])\n\n useEffect(() => {\n if (hasFiredRef.current) return\n hasFiredRef.current = true\n void handlePreparePayroll()\n }, [handlePreparePayroll])\n\n const isInitialLoading = isPreparePayrollPending && !hasInitialDataRef.current\n const isPaginating = isPreparePayrollPending && hasInitialDataRef.current\n const isLoading = isInitialLoading || isPayScheduleLoading\n\n return {\n handlePreparePayroll,\n preparedPayroll,\n paySchedule: payScheduleData?.payScheduleShow,\n isLoading,\n isPaginating,\n hasInitialData: hasInitialDataRef.current,\n }\n}\n"],"names":["PREPARE_MAX_ATTEMPTS","PREPARE_RETRY_DELAY_MS","isPayrollBeingProcessedError","error","UnprocessableEntityError","e","usePreparedPayrollData","companyId","payrollId","employeeUuids","sortBy","onDataReady","preparePayroll","isPreparePayrollPending","usePayrollsPrepareMutation","preparedPayroll","setPreparedPayroll","useState","hasInitialDataRef","useRef","hasFiredRef","baseSubmitHandler","useBase","employeeUuidsKey","useMemo","payScheduleData","isPayScheduleLoading","usePaySchedulesGet","executePrepare","useCallback","result","handlePreparePayroll","retryAsync","useEffect","isInitialLoading","isPaginating","isLoading"],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePreparedPayrollData.js","sources":["../../../src/components/Payroll/usePreparedPayrollData.ts"],"sourcesContent":["import { useState, useEffect, useCallback, useRef, useMemo } from 'react'\nimport { usePayrollsPrepareMutation } from '@gusto/embedded-api/react-query/payrollsPrepare'\nimport { usePaySchedulesGet } from '@gusto/embedded-api/react-query/paySchedulesGet'\nimport type { PayrollPrepared } from '@gusto/embedded-api/models/components/payrollshow'\nimport type { PayScheduleShow } from '@gusto/embedded-api/models/components/payscheduleshow'\nimport { UnprocessableEntityError } from '@gusto/embedded-api/models/errors/unprocessableentityerror'\nimport { useBase } from '../Base'\nimport { retryAsync } from '@/helpers/retryAsync'\n\ninterface UsePreparedPayrollDataParams {\n companyId: string\n payrollId: string\n employeeUuids?: string[]\n sortBy?: string\n onDataReady?: (preparedPayroll: PayrollPrepared) => void\n}\n\ninterface UsePreparedPayrollDataReturn {\n handlePreparePayroll: () => Promise<void>\n preparedPayroll: PayrollPrepared | undefined\n paySchedule: PayScheduleShow | undefined\n isLoading: boolean\n isPaginating: boolean\n hasInitialData: boolean\n}\n\nconst PREPARE_MAX_ATTEMPTS = 4\nconst PREPARE_RETRY_DELAY_MS = 1500\n\nconst isPayrollBeingProcessedError = (error: unknown): boolean => {\n if (!(error instanceof UnprocessableEntityError)) return false\n return error.errors.some(e => e.category === 'invalid_operation')\n}\n\n/**\n * Wraps the prepare-payroll mutation and pay-schedule fetch, retrying while the payroll is still being processed.\n *\n * @remarks\n * Fires the prepare call once on mount, then exposes `handlePreparePayroll` for callers that need to re-prepare\n * (e.g. after sort or pagination changes). Distinguishes initial loading from subsequent pagination via\n * `isLoading` and `isPaginating`, and surfaces the pay schedule for the prepared payroll's pay period.\n *\n * @param params - The company and payroll identifiers, plus optional employee filter, sort, and ready callback.\n * @returns The prepared payroll, its pay schedule, loading flags, and a `handlePreparePayroll` callback to re-run.\n * @internal\n */\nexport const usePreparedPayrollData = ({\n companyId,\n payrollId,\n employeeUuids,\n sortBy,\n onDataReady,\n}: UsePreparedPayrollDataParams): UsePreparedPayrollDataReturn => {\n const { mutateAsync: preparePayroll, isPending: isPreparePayrollPending } =\n usePayrollsPrepareMutation()\n const [preparedPayroll, setPreparedPayroll] = useState<PayrollPrepared | undefined>()\n const hasInitialDataRef = useRef(false)\n const hasFiredRef = useRef(false)\n const { baseSubmitHandler } = useBase()\n\n const employeeUuidsKey = useMemo(() => employeeUuids?.join(',') ?? '', [employeeUuids])\n\n const { data: payScheduleData, isLoading: isPayScheduleLoading } = usePaySchedulesGet(\n {\n companyId,\n payScheduleId: preparedPayroll?.payPeriod?.payScheduleUuid || '',\n },\n {\n enabled: !!preparedPayroll?.payPeriod?.payScheduleUuid,\n },\n )\n\n const executePrepare = useCallback(async () => {\n const result = await preparePayroll({\n request: {\n companyId,\n payrollId,\n sortBy,\n requestBody: {\n employeeUuids,\n },\n },\n })\n setPreparedPayroll(result.payrollPrepared)\n if (result.payrollPrepared) {\n hasInitialDataRef.current = true\n onDataReady?.(result.payrollPrepared)\n }\n }, [companyId, payrollId, preparePayroll, employeeUuidsKey, sortBy, onDataReady])\n\n const handlePreparePayroll = useCallback(async () => {\n await baseSubmitHandler(null, () =>\n retryAsync(executePrepare, {\n maxAttempts: PREPARE_MAX_ATTEMPTS,\n delayMs: PREPARE_RETRY_DELAY_MS,\n shouldRetry: isPayrollBeingProcessedError,\n }),\n )\n }, [baseSubmitHandler, executePrepare])\n\n useEffect(() => {\n if (hasFiredRef.current) return\n hasFiredRef.current = true\n void handlePreparePayroll()\n }, [handlePreparePayroll])\n\n const isInitialLoading = isPreparePayrollPending && !hasInitialDataRef.current\n const isPaginating = isPreparePayrollPending && hasInitialDataRef.current\n const isLoading = isInitialLoading || isPayScheduleLoading\n\n return {\n handlePreparePayroll,\n preparedPayroll,\n paySchedule: payScheduleData?.payScheduleShow,\n isLoading,\n isPaginating,\n hasInitialData: hasInitialDataRef.current,\n }\n}\n"],"names":["PREPARE_MAX_ATTEMPTS","PREPARE_RETRY_DELAY_MS","isPayrollBeingProcessedError","error","UnprocessableEntityError","e","usePreparedPayrollData","companyId","payrollId","employeeUuids","sortBy","onDataReady","preparePayroll","isPreparePayrollPending","usePayrollsPrepareMutation","preparedPayroll","setPreparedPayroll","useState","hasInitialDataRef","useRef","hasFiredRef","baseSubmitHandler","useBase","employeeUuidsKey","useMemo","payScheduleData","isPayScheduleLoading","usePaySchedulesGet","executePrepare","useCallback","result","handlePreparePayroll","retryAsync","useEffect","isInitialLoading","isPaginating","isLoading"],"mappings":";;;;;;;;;;;;;;;;;;;AA0BA,MAAMA,IAAuB,GACvBC,IAAyB,MAEzBC,IAA+B,CAACC,MAC9BA,aAAiBC,IAChBD,EAAM,OAAO,KAAK,CAAAE,MAAKA,EAAE,aAA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,EAAAK,EAAU,MAAM;AACd,IAAIb,EAAY,YAChBA,EAAY,UAAU,IACjBW,EAAA;AAAA,EACP,GAAG,CAACA,CAAoB,CAAC;AAEzB,QAAMG,IAAmBrB,KAA2B,CAACK,EAAkB,SACjEiB,IAAetB,KAA2BK,EAAkB,SAC5DkB,IAAYF,KAAoBR;AAEtC,SAAO;AAAA,IACL,sBAAAK;AAAA,IACA,iBAAAhB;AAAA,IACA,aAAaU,GAAiB;AAAA,IAC9B,WAAAW;AAAA,IACA,cAAAD;AAAA,IACA,gBAAgBjB,EAAkB;AAAA,EAAA;AAEtC;"}
|
|
@@ -1,43 +1,44 @@
|
|
|
1
1
|
import { jsx as u } from "react/jsx-runtime";
|
|
2
|
-
import { QueryClientProvider as
|
|
2
|
+
import { QueryClientProvider as k } from "@tanstack/react-query";
|
|
3
3
|
import { GustoEmbeddedProvider as R } from "@gusto/embedded-api/react-query/_context";
|
|
4
|
-
import { GustoEmbeddedCore as
|
|
5
|
-
import { SDKHooks as
|
|
6
|
-
import { useMemo as
|
|
7
|
-
import { apiVersionHook as
|
|
8
|
-
import {
|
|
9
|
-
|
|
4
|
+
import { GustoEmbeddedCore as g } from "@gusto/embedded-api/core";
|
|
5
|
+
import { SDKHooks as q } from "@gusto/embedded-api/hooks/hooks";
|
|
6
|
+
import { useMemo as m } from "react";
|
|
7
|
+
import { apiVersionHook as C } from "./apiVersionHook.js";
|
|
8
|
+
import { apiVersionMismatchHook as a } from "./apiVersionMismatchHook.js";
|
|
9
|
+
import { createSdkQueryClient as b } from "./createSdkQueryClient.js";
|
|
10
|
+
function I({
|
|
10
11
|
url: s,
|
|
11
12
|
headers: i,
|
|
12
13
|
hooks: e,
|
|
13
|
-
children:
|
|
14
|
+
children: d,
|
|
14
15
|
queryClient: f
|
|
15
16
|
}) {
|
|
16
|
-
const
|
|
17
|
-
const t = new
|
|
17
|
+
const p = m(() => {
|
|
18
|
+
const t = new g({
|
|
18
19
|
serverURL: s
|
|
19
|
-
}),
|
|
20
|
-
if (
|
|
21
|
-
const
|
|
22
|
-
beforeRequest: (
|
|
23
|
-
c && n.headers.set(
|
|
20
|
+
}), r = t._options.hooks || new q();
|
|
21
|
+
if (r.registerBeforeRequestHook(C), r.registerAfterSuccessHook(a), r.registerAfterErrorHook(a), i) {
|
|
22
|
+
const o = {
|
|
23
|
+
beforeRequest: (l, n) => (new Headers(i).forEach((c, E) => {
|
|
24
|
+
c && n.headers.set(E, c);
|
|
24
25
|
}), n)
|
|
25
26
|
};
|
|
26
|
-
|
|
27
|
+
r.registerBeforeRequestHook(o);
|
|
27
28
|
}
|
|
28
|
-
return e?.beforeCreateRequest && e.beforeCreateRequest.forEach((
|
|
29
|
-
|
|
30
|
-
}), e?.beforeRequest && e.beforeRequest.forEach((
|
|
31
|
-
|
|
32
|
-
}), e?.afterSuccess && e.afterSuccess.forEach((
|
|
33
|
-
|
|
34
|
-
}), e?.afterError && e.afterError.forEach((
|
|
35
|
-
|
|
36
|
-
}), t._options.hooks || (t._options.hooks =
|
|
37
|
-
}, [s, i, e]),
|
|
38
|
-
return /* @__PURE__ */ u(
|
|
29
|
+
return e?.beforeCreateRequest && e.beforeCreateRequest.forEach((o) => {
|
|
30
|
+
r.registerBeforeCreateRequestHook(o);
|
|
31
|
+
}), e?.beforeRequest && e.beforeRequest.forEach((o) => {
|
|
32
|
+
r.registerBeforeRequestHook(o);
|
|
33
|
+
}), e?.afterSuccess && e.afterSuccess.forEach((o) => {
|
|
34
|
+
r.registerAfterSuccessHook(o);
|
|
35
|
+
}), e?.afterError && e.afterError.forEach((o) => {
|
|
36
|
+
r.registerAfterErrorHook(o);
|
|
37
|
+
}), t._options.hooks || (t._options.hooks = r), t;
|
|
38
|
+
}, [s, i, e]), H = m(() => f ?? b(), [f]);
|
|
39
|
+
return /* @__PURE__ */ u(k, { client: H, children: /* @__PURE__ */ u(R, { client: p, children: d }) });
|
|
39
40
|
}
|
|
40
41
|
export {
|
|
41
|
-
|
|
42
|
+
I as ApiProvider
|
|
42
43
|
};
|
|
43
44
|
//# sourceMappingURL=ApiProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApiProvider.js","sources":["../../../src/contexts/ApiProvider/ApiProvider.tsx"],"sourcesContent":["import { QueryClientProvider, type QueryClient } from '@tanstack/react-query'\nimport { GustoEmbeddedProvider } from '@gusto/embedded-api/react-query/_context'\nimport { GustoEmbeddedCore } from '@gusto/embedded-api/core'\nimport { SDKHooks as NativeSDKHooks } from '@gusto/embedded-api/hooks/hooks'\nimport { useMemo } from 'react'\nimport { apiVersionHook } from './apiVersionHook'\nimport { createSdkQueryClient } from './createSdkQueryClient'\nimport type { SDKHooks, BeforeRequestHook } from '@/types/hooks'\n\n/**\n * Props for {@link ApiProvider}.\n *\n * @internal\n */\nexport interface ApiProviderProps {\n /** Base URL the SDK uses for all `@gusto/embedded-api-v-2026-06-15` requests. */\n url: string\n /** Default headers applied to every SDK request, in addition to the `X-Gusto-API-Version` header set automatically. */\n headers?: HeadersInit\n /** Lifecycle hooks for intercepting and modifying SDK requests and responses. */\n hooks?: SDKHooks\n /** Subtree that renders inside the API + React Query providers. */\n children: React.ReactNode\n /** Optional React Query client. When omitted, a client is created with the SDK's defaults (auto-invalidation on mutation success). */\n queryClient?: QueryClient\n}\n\n/**\n * Wires the `@gusto/embedded-api-v-2026-06-15` client and a React Query client into the React tree.\n *\n * @remarks\n * Registers the SDK's `X-Gusto-API-Version` header on every request, applies any default `headers
|
|
1
|
+
{"version":3,"file":"ApiProvider.js","sources":["../../../src/contexts/ApiProvider/ApiProvider.tsx"],"sourcesContent":["import { QueryClientProvider, type QueryClient } from '@tanstack/react-query'\nimport { GustoEmbeddedProvider } from '@gusto/embedded-api/react-query/_context'\nimport { GustoEmbeddedCore } from '@gusto/embedded-api/core'\nimport { SDKHooks as NativeSDKHooks } from '@gusto/embedded-api/hooks/hooks'\nimport { useMemo } from 'react'\nimport { apiVersionHook } from './apiVersionHook'\nimport { apiVersionMismatchHook } from './apiVersionMismatchHook'\nimport { createSdkQueryClient } from './createSdkQueryClient'\nimport type { SDKHooks, BeforeRequestHook } from '@/types/hooks'\n\n/**\n * Props for {@link ApiProvider}.\n *\n * @internal\n */\nexport interface ApiProviderProps {\n /** Base URL the SDK uses for all `@gusto/embedded-api-v-2026-06-15` requests. */\n url: string\n /** Default headers applied to every SDK request, in addition to the `X-Gusto-API-Version` header set automatically. */\n headers?: HeadersInit\n /** Lifecycle hooks for intercepting and modifying SDK requests and responses. */\n hooks?: SDKHooks\n /** Subtree that renders inside the API + React Query providers. */\n children: React.ReactNode\n /** Optional React Query client. When omitted, a client is created with the SDK's defaults (auto-invalidation on mutation success). */\n queryClient?: QueryClient\n}\n\n/**\n * Wires the `@gusto/embedded-api-v-2026-06-15` client and a React Query client into the React tree.\n *\n * @remarks\n * Registers the SDK's `X-Gusto-API-Version` header on every request, warns via `console.warn` if a\n * response reports a different `X-Gusto-API-Version` than was requested (e.g. a proxy rewriting the\n * header), applies any default `headers`, and registers user-supplied lifecycle hooks\n * (`beforeCreateRequest`, `beforeRequest`, `afterSuccess`, `afterError`). When no `queryClient` is\n * supplied, one is created with the SDK's defaults so\n * successful mutations under the `['@gusto/embedded-api-v-2026-06-15']` key invalidate every SDK\n * query automatically. Partners who supply their own `QueryClient` are responsible for matching that\n * contract.\n *\n * Typically wrapped by {@link GustoProvider}; use directly only when composing the provider stack\n * manually.\n *\n * @param props - See {@link ApiProviderProps}.\n * @returns A React subtree wrapped in `QueryClientProvider` and the embedded API context.\n * @internal\n */\nexport function ApiProvider({\n url,\n headers,\n hooks,\n children,\n queryClient: queryClientFromProps,\n}: ApiProviderProps) {\n const gustoClient = useMemo(() => {\n const client = new GustoEmbeddedCore({\n serverURL: url,\n })\n\n const sdkHooks = client._options.hooks || new NativeSDKHooks()\n\n sdkHooks.registerBeforeRequestHook(apiVersionHook)\n sdkHooks.registerAfterSuccessHook(apiVersionMismatchHook)\n sdkHooks.registerAfterErrorHook(apiVersionMismatchHook)\n\n if (headers) {\n const defaultHeaderHook: BeforeRequestHook = {\n beforeRequest: (context, request) => {\n const headersInstance = new Headers(headers)\n headersInstance.forEach((headerValue, headerName) => {\n if (headerValue) {\n request.headers.set(headerName, headerValue)\n }\n })\n return request\n },\n }\n sdkHooks.registerBeforeRequestHook(defaultHeaderHook)\n }\n\n if (hooks?.beforeCreateRequest) {\n hooks.beforeCreateRequest.forEach(hook => {\n sdkHooks.registerBeforeCreateRequestHook(hook)\n })\n }\n\n if (hooks?.beforeRequest) {\n hooks.beforeRequest.forEach(hook => {\n sdkHooks.registerBeforeRequestHook(hook)\n })\n }\n\n if (hooks?.afterSuccess) {\n hooks.afterSuccess.forEach(hook => {\n sdkHooks.registerAfterSuccessHook(hook)\n })\n }\n\n if (hooks?.afterError) {\n hooks.afterError.forEach(hook => {\n sdkHooks.registerAfterErrorHook(hook)\n })\n }\n\n if (!client._options.hooks) {\n client._options.hooks = sdkHooks\n }\n\n return client\n }, [url, headers, hooks])\n\n const queryClient = useMemo(() => {\n return queryClientFromProps ?? createSdkQueryClient()\n }, [queryClientFromProps])\n\n return (\n <QueryClientProvider client={queryClient}>\n <GustoEmbeddedProvider client={gustoClient}>{children}</GustoEmbeddedProvider>\n </QueryClientProvider>\n )\n}\n"],"names":["ApiProvider","url","headers","hooks","children","queryClientFromProps","gustoClient","useMemo","client","GustoEmbeddedCore","sdkHooks","NativeSDKHooks","apiVersionHook","apiVersionMismatchHook","defaultHeaderHook","context","request","headerValue","headerName","hook","queryClient","createSdkQueryClient","jsx","QueryClientProvider","GustoEmbeddedProvider"],"mappings":";;;;;;;;;AAgDO,SAASA,EAAY;AAAA,EAC1B,KAAAC;AAAA,EACA,SAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,aAAaC;AACf,GAAqB;AACnB,QAAMC,IAAcC,EAAQ,MAAM;AAChC,UAAMC,IAAS,IAAIC,EAAkB;AAAA,MACnC,WAAWR;AAAA,IAAA,CACZ,GAEKS,IAAWF,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const o = e?.headers.get("X-Gusto-API-Version");
|
|
4
|
+
o && o !== s && console.warn(
|
|
5
|
+
`[@gusto/embedded-react-sdk] Requested API version ${s} for "${r}", but the response reported version ${o}. This usually means something between the SDK and Gusto (e.g. a proxy) is rewriting the X-Gusto-API-Version header, which can cause the response to be parsed against the wrong schema.`
|
|
6
|
+
);
|
|
7
|
+
}
|
|
8
|
+
const a = {
|
|
9
|
+
afterSuccess: (r, e) => (t(r.operationID, e), e),
|
|
10
|
+
afterError: (r, e, o) => (t(r.operationID, e), { response: e, error: o })
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
a as apiVersionMismatchHook
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=apiVersionMismatchHook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiVersionMismatchHook.js","sources":["../../../src/contexts/ApiProvider/apiVersionMismatchHook.ts"],"sourcesContent":["import { API_VERSION } from './apiVersion'\nimport type { AfterErrorHook, AfterSuccessHook } from '@/types/hooks'\n\nfunction warnOnVersionMismatch(operationID: string, response: Response | null) {\n const responseVersion = response?.headers.get('X-Gusto-API-Version')\n if (responseVersion && responseVersion !== API_VERSION) {\n // eslint-disable-next-line no-console\n console.warn(\n `[@gusto/embedded-react-sdk] Requested API version ${API_VERSION} for \"${operationID}\", but the response reported version ${responseVersion}. This usually means something between the SDK and Gusto (e.g. a proxy) is rewriting the X-Gusto-API-Version header, which can cause the response to be parsed against the wrong schema.`,\n )\n }\n}\n\n/** @internal */\nexport const apiVersionMismatchHook: AfterSuccessHook & AfterErrorHook = {\n afterSuccess: (context, response) => {\n warnOnVersionMismatch(context.operationID, response)\n return response\n },\n afterError: (context, response, error) => {\n warnOnVersionMismatch(context.operationID, response)\n return { response, error }\n },\n}\n"],"names":["warnOnVersionMismatch","operationID","response","responseVersion","API_VERSION","apiVersionMismatchHook","context","error"],"mappings":";AAGA,SAASA,EAAsBC,GAAqBC,GAA2B;AAC7E,QAAMC,IAAkBD,GAAU,QAAQ,IAAI,qBAAqB;AACnE,EAAIC,KAAmBA,MAAoBC,KAEzC,QAAQ;AAAA,IACN,qDAAqDA,CAAW,SAASH,CAAW,wCAAwCE,CAAe;AAAA,EAAA;AAGjJ;AAGO,MAAME,IAA4D;AAAA,EACvE,cAAc,CAACC,GAASJ,OACtBF,EAAsBM,EAAQ,aAAaJ,CAAQ,GAC5CA;AAAA,EAET,YAAY,CAACI,GAASJ,GAAUK,OAC9BP,EAAsBM,EAAQ,aAAaJ,CAAQ,GAC5C,EAAE,UAAAA,GAAU,OAAAK,EAAA;AAEvB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GustoProviderCustomUIAdapter.js","sources":["../../../src/contexts/GustoProvider/GustoProviderCustomUIAdapter.tsx"],"sourcesContent":["import type React from 'react'\nimport type { ErrorInfo, JSX, ReactNode } from 'react'\nimport { ErrorBoundary } from 'react-error-boundary'\nimport { I18nextProvider } from 'react-i18next'\nimport type { QueryClient } from '@tanstack/react-query'\nimport { useEffect, useMemo } from 'react'\nimport { ComponentsProvider } from '../ComponentAdapter/ComponentsProvider'\nimport type { ComponentsContextType } from '../ComponentAdapter/useComponentContext'\nimport { ApiProvider } from '../ApiProvider/ApiProvider'\nimport { LoadingIndicatorProvider } from '../LoadingIndicatorProvider/LoadingIndicatorProvider'\nimport { ObservabilityProvider } from '../ObservabilityProvider'\nimport { sanitizeError } from '../ObservabilityProvider/sanitization'\nimport { UnstableFeaturesProvider } from '../UnstableFeaturesProvider/UnstableFeaturesProvider'\nimport type { UnstableFeatures } from '../UnstableFeaturesProvider/useUnstableFeature'\nimport { SDKI18next } from './SDKI18next'\nimport { InternalError } from '@/components/Common'\nimport { LocaleProvider } from '@/contexts/LocaleProvider'\nimport { NonceContext } from '@/contexts/NonceProvider'\nimport { ThemeProvider } from '@/contexts/ThemeProvider'\nimport type { GustoSDKTheme } from '@/contexts/ThemeProvider/theme'\nimport type { GlobalResourceDictionary, SupportedLanguages } from '@/types/Helpers'\nimport type { SDKHooks } from '@/types/hooks'\nimport type { ObservabilityHook } from '@/types/observability'\nimport { normalizeToSDKError } from '@/types/sdkError'\n\n/**\n * API client configuration passed to {@link GustoProvider} (and {@link GustoProviderCustomUIAdapter}).\n *\n * @public\n */\nexport interface APIConfig {\n /** URL of your backend proxy that forwards SDK requests to the Gusto Embedded API. SDK components never call Gusto directly. */\n baseUrl: string\n /** Extra headers applied to every API request. Combined with any headers your proxy adds. */\n headers?: HeadersInit\n /** Request interceptor hooks. Use these to inspect, modify, or react to requests and responses. See {@link SDKHooks}. */\n hooks?: SDKHooks\n /** Observability hook for surfacing errors and metrics from the SDK to your monitoring stack. See {@link ObservabilityHook}. */\n observability?: ObservabilityHook\n}\n\n/**\n * Shared configuration props accepted by {@link GustoProvider} and {@link GustoProviderCustomUIAdapter}.\n *\n * @public\n */\nexport interface GustoBaseProviderProps {\n /** API client configuration, including the proxy `baseUrl`, request hooks, and observability. See {@link APIConfig}. */\n config: APIConfig\n /** Translation overrides keyed by language and i18next namespace. Strings supplied here replace the SDK defaults for the matching keys. */\n dictionary?: GlobalResourceDictionary\n /** Active i18next language. Defaults to `'en'`. */\n lng?: string\n /** BCP 47 locale used for number, date, and currency formatting throughout the SDK. Defaults to `'en-US'`. */\n locale?: string\n /** ISO 4217 currency code used for monetary formatting. Defaults to `'USD'`. */\n currency?: string\n /** Theme overrides applied to SDK components. See {@link GustoSDKTheme}. */\n theme?: Partial<GustoSDKTheme>\n /**\n * CSP nonce to apply to runtime-injected `<style>` elements (theming, PDF download window).\n * Pass the same per-request nonce your app uses in its `style-src 'nonce-…'` directive.\n * Also exposed to custom UI components via `useNonce`.\n */\n nonce?: string\n /** Element to use as the portal container for SDK popovers and dropdowns. Useful when rendering inside a modal or shadow root. */\n portalContainer?: HTMLElement\n /** Optional TanStack Query `QueryClient`. When omitted, the SDK creates its own client configured for Gusto's API. */\n queryClient?: QueryClient\n /** Complete map of UI components the SDK renders. Required because this adapter ships no defaults. */\n components: ComponentsContextType\n /** Loading indicator rendered while SDK queries are pending. Overrides the SDK default spinner. */\n LoaderComponent?: ({ children }: { children?: ReactNode }) => JSX.Element\n /**\n * Opt-in flags for alpha SDK functionality. See {@link UnstableFeatures}.\n * @alpha\n */\n unstableFeatures?: UnstableFeatures\n}\n\n/**\n * Props for {@link GustoProviderCustomUIAdapter}.\n *\n * @public\n */\nexport interface GustoProviderCustomUIAdapterProps extends GustoBaseProviderProps {\n /** The application tree that should have access to the SDK. */\n children?: React.ReactNode\n}\n\n/**\n * Top-level provider that requires a complete component map and ships no UI defaults.\n *\n * @remarks\n * Use this adapter when you want full control over every UI primitive the SDK renders, or when\n * you want to avoid the React Aria dependency for tree-shaking. Unlike {@link GustoProvider}, the\n * `components` prop on {@link GustoProviderProps} is required and must supply every component the\n * SDK renders.\n *\n * @param props - See {@link GustoProviderCustomUIAdapterProps}.\n * @returns The configured provider tree wrapping `children`.\n * @public\n * @group Providers\n */\nexport function GustoProviderCustomUIAdapter(props: GustoProviderCustomUIAdapterProps) {\n const {\n children,\n config,\n dictionary,\n lng = 'en',\n locale = 'en-US',\n currency = 'USD',\n theme,\n nonce,\n portalContainer,\n components,\n LoaderComponent,\n queryClient,\n unstableFeatures,\n } = props\n\n if (dictionary) {\n for (const language in dictionary) {\n const lang = language as SupportedLanguages\n for (const ns in dictionary[lang]) {\n SDKI18next.addResourceBundle(\n lang,\n ns,\n (dictionary[lang] as Record<string, unknown>)[ns],\n true,\n true,\n )\n }\n }\n }\n\n useEffect(() => {\n void (async () => {\n await SDKI18next.changeLanguage(lng)\n })()\n }, [lng])\n\n const handleTopLevelError = useMemo(() => {\n if (!config.observability?.onError) return undefined\n\n return (error: unknown, errorInfo: ErrorInfo) => {\n if (!config.observability?.onError) return\n\n const sdkError = normalizeToSDKError(error)\n\n const observabilityError = {\n ...sdkError,\n timestamp: Date.now(),\n componentStack: errorInfo.componentStack ?? undefined,\n }\n\n const sanitizedError = sanitizeError(observabilityError, config.observability.sanitization)\n\n config.observability.onError(sanitizedError)\n }\n }, [config.observability])\n return (\n <NonceContext.Provider value={nonce}>\n <ComponentsProvider value={components}>\n <LoadingIndicatorProvider value={LoaderComponent}>\n <ObservabilityProvider observability={config.observability}>\n <ErrorBoundary FallbackComponent={InternalError} onError={handleTopLevelError}>\n <ThemeProvider theme={theme} portalContainer={portalContainer}>\n <LocaleProvider locale={locale} currency={currency}>\n <I18nextProvider i18n={SDKI18next} key={lng}>\n <ApiProvider\n url={config.baseUrl}\n headers={config.headers}\n hooks={config.hooks}\n queryClient={queryClient}\n >\n <UnstableFeaturesProvider value={unstableFeatures}>\n {children}\n </UnstableFeaturesProvider>\n </ApiProvider>\n </I18nextProvider>\n </LocaleProvider>\n </ThemeProvider>\n </ErrorBoundary>\n </ObservabilityProvider>\n </LoadingIndicatorProvider>\n </ComponentsProvider>\n </NonceContext.Provider>\n )\n}\n"],"names":["GustoProviderCustomUIAdapter","props","children","config","dictionary","lng","locale","currency","theme","nonce","portalContainer","components","LoaderComponent","queryClient","unstableFeatures","language","lang","ns","SDKI18next","useEffect","handleTopLevelError","useMemo","error","errorInfo","observabilityError","normalizeToSDKError","sanitizedError","sanitizeError","NonceContext","jsx","ComponentsProvider","LoadingIndicatorProvider","ObservabilityProvider","ErrorBoundary","InternalError","ThemeProvider","LocaleProvider","I18nextProvider","ApiProvider","UnstableFeaturesProvider"],"mappings":";;;;;;;;;;;;;;;;;AAwGO,SAASA,GAA6BC,GAA0C;AACrF,QAAM;AAAA,IACJ,UAAAC;AAAA,IACA,QAAAC;AAAA,IACA,YAAAC;AAAA,IACA,KAAAC,IAAM;AAAA,IACN,QAAAC,IAAS;AAAA,IACT,UAAAC,IAAW;AAAA,IACX,OAAAC;AAAA,IACA,OAAAC;AAAA,IACA,iBAAAC;AAAA,IACA,YAAAC;AAAA,IACA,iBAAAC;AAAA,IACA,aAAAC;AAAA,IACA,kBAAAC;AAAA,EAAA,IACEb;AAEJ,MAAIG;AACF,eAAWW,KAAYX,GAAY;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,aAAAU;AAAA,MAEA,UAAA,gBAAAgB,EAACU,GAAA,EAAyB,OAAOzB,GAC9B,UAAAZ,EAAA,CACH;AAAA,IAAA;AAAA,EAAA,KAToCG,CAWxC,EAAA,CACF,EAAA,CACF,GACF,GACF,EAAA,CACF,GACF,GACF;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"GustoProviderCustomUIAdapter.js","sources":["../../../src/contexts/GustoProvider/GustoProviderCustomUIAdapter.tsx"],"sourcesContent":["import type React from 'react'\nimport type { ErrorInfo, JSX, ReactNode } from 'react'\nimport { ErrorBoundary } from 'react-error-boundary'\nimport { I18nextProvider } from 'react-i18next'\nimport type { QueryClient } from '@tanstack/react-query'\nimport { useEffect, useMemo } from 'react'\nimport { ComponentsProvider } from '../ComponentAdapter/ComponentsProvider'\nimport type { ComponentsContextType } from '../ComponentAdapter/useComponentContext'\nimport { ApiProvider } from '../ApiProvider/ApiProvider'\nimport { LoadingIndicatorProvider } from '../LoadingIndicatorProvider/LoadingIndicatorProvider'\nimport { ObservabilityProvider } from '../ObservabilityProvider'\nimport { sanitizeError } from '../ObservabilityProvider/sanitization'\nimport { UnstableFeaturesProvider } from '../UnstableFeaturesProvider/UnstableFeaturesProvider'\nimport type { UnstableFeatures } from '../UnstableFeaturesProvider/useUnstableFeature'\nimport { SDKI18next } from './SDKI18next'\nimport { InternalError } from '@/components/Common'\nimport { LocaleProvider } from '@/contexts/LocaleProvider'\nimport { NonceContext } from '@/contexts/NonceProvider'\nimport { ThemeProvider } from '@/contexts/ThemeProvider'\nimport type { GustoSDKTheme } from '@/contexts/ThemeProvider/theme'\nimport type { GlobalResourceDictionary, SupportedLanguages } from '@/types/Helpers'\nimport type { SDKHooks } from '@/types/hooks'\nimport type { ObservabilityHook } from '@/types/observability'\nimport { normalizeToSDKError } from '@/types/sdkError'\n\n/**\n * API client configuration passed to {@link GustoProvider} (and {@link GustoProviderCustomUIAdapter}).\n *\n * @public\n */\nexport interface APIConfig {\n /** URL of your backend proxy that forwards SDK requests to the Gusto Embedded API. SDK components never call Gusto directly. */\n baseUrl: string\n /** Extra headers applied to every API request. Combined with any headers your proxy adds. */\n headers?: HeadersInit\n /** Request interceptor hooks. Use these to inspect, modify, or react to requests and responses. See {@link SDKHooks}. */\n hooks?: SDKHooks\n /** Observability hook for surfacing errors and metrics from the SDK to your monitoring stack. See {@link ObservabilityHook}. */\n observability?: ObservabilityHook\n}\n\n/**\n * Shared configuration props accepted by {@link GustoProvider} and {@link GustoProviderCustomUIAdapter}.\n *\n * @public\n */\nexport interface GustoBaseProviderProps {\n /** API client configuration, including the proxy `baseUrl`, request hooks, and observability. See {@link APIConfig}. */\n config: APIConfig\n /** Translation overrides keyed by language and i18next namespace. Strings supplied here replace the SDK defaults for the matching keys. */\n dictionary?: GlobalResourceDictionary\n /** Active i18next language. Defaults to `'en'`. */\n lng?: string\n /** BCP 47 locale used for number, date, and currency formatting throughout the SDK. Defaults to `'en-US'`. */\n locale?: string\n /** ISO 4217 currency code used for monetary formatting. Defaults to `'USD'`. */\n currency?: string\n /** Theme overrides applied to SDK components. See {@link GustoSDKTheme}. */\n theme?: Partial<GustoSDKTheme>\n /**\n * CSP nonce to apply to runtime-injected `<style>` elements (theming, PDF download window).\n * Pass the same per-request nonce your app uses in its `style-src 'nonce-…'` directive.\n * Also exposed to custom UI components via `useNonce`.\n */\n nonce?: string\n /**\n * Element to use as the portal container for SDK popovers and dropdowns.\n * Defaults to a themed root element the SDK appends to `document.body`.\n *\n * Pass an element here if rendering inside a modal, or **required** if\n * rendering inside a shadow root — `document.body` sits outside every\n * shadow boundary, so without an explicit container overlays would\n * otherwise escape your shadow root's style encapsulation.\n */\n portalContainer?: HTMLElement\n /** Optional TanStack Query `QueryClient`. When omitted, the SDK creates its own client configured for Gusto's API. */\n queryClient?: QueryClient\n /** Complete map of UI components the SDK renders. Required because this adapter ships no defaults. */\n components: ComponentsContextType\n /** Loading indicator rendered while SDK queries are pending. Overrides the SDK default spinner. */\n LoaderComponent?: ({ children }: { children?: ReactNode }) => JSX.Element\n /**\n * Opt-in flags for alpha SDK functionality. See {@link UnstableFeatures}.\n * @alpha\n */\n unstableFeatures?: UnstableFeatures\n}\n\n/**\n * Props for {@link GustoProviderCustomUIAdapter}.\n *\n * @public\n */\nexport interface GustoProviderCustomUIAdapterProps extends GustoBaseProviderProps {\n /** The application tree that should have access to the SDK. */\n children?: React.ReactNode\n}\n\n/**\n * Top-level provider that requires a complete component map and ships no UI defaults.\n *\n * @remarks\n * Use this adapter when you want full control over every UI primitive the SDK renders, or when\n * you want to avoid the React Aria dependency for tree-shaking. Unlike {@link GustoProvider}, the\n * `components` prop on {@link GustoProviderProps} is required and must supply every component the\n * SDK renders.\n *\n * @param props - See {@link GustoProviderCustomUIAdapterProps}.\n * @returns The configured provider tree wrapping `children`.\n * @public\n * @group Providers\n */\nexport function GustoProviderCustomUIAdapter(props: GustoProviderCustomUIAdapterProps) {\n const {\n children,\n config,\n dictionary,\n lng = 'en',\n locale = 'en-US',\n currency = 'USD',\n theme,\n nonce,\n portalContainer,\n components,\n LoaderComponent,\n queryClient,\n unstableFeatures,\n } = props\n\n if (dictionary) {\n for (const language in dictionary) {\n const lang = language as SupportedLanguages\n for (const ns in dictionary[lang]) {\n SDKI18next.addResourceBundle(\n lang,\n ns,\n (dictionary[lang] as Record<string, unknown>)[ns],\n true,\n true,\n )\n }\n }\n }\n\n useEffect(() => {\n void (async () => {\n await SDKI18next.changeLanguage(lng)\n })()\n }, [lng])\n\n const handleTopLevelError = useMemo(() => {\n if (!config.observability?.onError) return undefined\n\n return (error: unknown, errorInfo: ErrorInfo) => {\n if (!config.observability?.onError) return\n\n const sdkError = normalizeToSDKError(error)\n\n const observabilityError = {\n ...sdkError,\n timestamp: Date.now(),\n componentStack: errorInfo.componentStack ?? undefined,\n }\n\n const sanitizedError = sanitizeError(observabilityError, config.observability.sanitization)\n\n config.observability.onError(sanitizedError)\n }\n }, [config.observability])\n return (\n <NonceContext.Provider value={nonce}>\n <ComponentsProvider value={components}>\n <LoadingIndicatorProvider value={LoaderComponent}>\n <ObservabilityProvider observability={config.observability}>\n <ErrorBoundary FallbackComponent={InternalError} onError={handleTopLevelError}>\n <ThemeProvider theme={theme} portalContainer={portalContainer}>\n <LocaleProvider locale={locale} currency={currency}>\n <I18nextProvider i18n={SDKI18next} key={lng}>\n <ApiProvider\n url={config.baseUrl}\n headers={config.headers}\n hooks={config.hooks}\n queryClient={queryClient}\n >\n <UnstableFeaturesProvider value={unstableFeatures}>\n {children}\n </UnstableFeaturesProvider>\n </ApiProvider>\n </I18nextProvider>\n </LocaleProvider>\n </ThemeProvider>\n </ErrorBoundary>\n </ObservabilityProvider>\n </LoadingIndicatorProvider>\n </ComponentsProvider>\n </NonceContext.Provider>\n )\n}\n"],"names":["GustoProviderCustomUIAdapter","props","children","config","dictionary","lng","locale","currency","theme","nonce","portalContainer","components","LoaderComponent","queryClient","unstableFeatures","language","lang","ns","SDKI18next","useEffect","handleTopLevelError","useMemo","error","errorInfo","observabilityError","normalizeToSDKError","sanitizedError","sanitizeError","NonceContext","jsx","ComponentsProvider","LoadingIndicatorProvider","ObservabilityProvider","ErrorBoundary","InternalError","ThemeProvider","LocaleProvider","I18nextProvider","ApiProvider","UnstableFeaturesProvider"],"mappings":";;;;;;;;;;;;;;;;;AAgHO,SAASA,GAA6BC,GAA0C;AACrF,QAAM;AAAA,IACJ,UAAAC;AAAA,IACA,QAAAC;AAAA,IACA,YAAAC;AAAA,IACA,KAAAC,IAAM;AAAA,IACN,QAAAC,IAAS;AAAA,IACT,UAAAC,IAAW;AAAA,IACX,OAAAC;AAAA,IACA,OAAAC;AAAA,IACA,iBAAAC;AAAA,IACA,YAAAC;AAAA,IACA,iBAAAC;AAAA,IACA,aAAAC;AAAA,IACA,kBAAAC;AAAA,EAAA,IACEb;AAEJ,MAAIG;AACF,eAAWW,KAAYX,GAAY;AACjC,YAAMY,IAAOD;AACb,iBAAWE,KAAMb,EAAWY,CAAI;AAC9B,QAAAE,EAAW;AAAA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EAAA,CACH;AAAA,IAAA;AAAA,EAAA,KAToCG,CAWxC,EAAA,CACF,EAAA,CACF,GACF,GACF,EAAA,CACF,GACF,GACF;AAEJ;"}
|
|
@@ -1,39 +1,45 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useRef as
|
|
3
|
-
import { ThemeContext as
|
|
1
|
+
import { jsx as a } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as d, useLayoutEffect as f, useMemo as i, useEffect as p } from "react";
|
|
3
|
+
import { ThemeContext as h } from "./useTheme.js";
|
|
4
4
|
import { mergePartnerTheme as S } from "./theme.js";
|
|
5
5
|
/* empty css */
|
|
6
|
-
import { useNonce as
|
|
7
|
-
const
|
|
8
|
-
theme:
|
|
9
|
-
portalContainer:
|
|
10
|
-
children:
|
|
6
|
+
import { useNonce as G } from "../NonceProvider/useNonce.js";
|
|
7
|
+
const C = ({
|
|
8
|
+
theme: c = {},
|
|
9
|
+
portalContainer: t,
|
|
10
|
+
children: r
|
|
11
11
|
}) => {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
const o = G(), e = d(null), s = d(null);
|
|
13
|
+
f(() => {
|
|
14
|
+
if (t) {
|
|
15
|
+
s.current = t;
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const n = document.createElement("div");
|
|
19
|
+
return n.className = "GSDK GSDK-portal-root", n.setAttribute("data-testid", "GSDK-portal-root"), document.body.appendChild(n), s.current = n, () => {
|
|
20
|
+
n.remove();
|
|
21
|
+
};
|
|
22
|
+
}, [t]);
|
|
23
|
+
const u = i(
|
|
24
|
+
() => S(c),
|
|
25
|
+
[c]
|
|
20
26
|
), m = i(
|
|
21
27
|
() => `.GSDK{
|
|
22
|
-
${l(
|
|
28
|
+
${l(u).join(`
|
|
23
29
|
`)}
|
|
24
30
|
}`,
|
|
25
|
-
[
|
|
31
|
+
[u]
|
|
26
32
|
);
|
|
27
33
|
return p(() => {
|
|
28
|
-
e.current || (e.current = document.createElement("style"), e.current.setAttribute("data-testid", "GSDK"),
|
|
29
|
-
}, [m,
|
|
30
|
-
}, l = (
|
|
31
|
-
const
|
|
32
|
-
for (const [
|
|
33
|
-
typeof e == "object" ?
|
|
34
|
-
return
|
|
34
|
+
e.current || (e.current = document.createElement("style"), e.current.setAttribute("data-testid", "GSDK"), o && (e.current.nonce = o), document.head.appendChild(e.current)), e.current.textContent = m;
|
|
35
|
+
}, [m, o]), /* @__PURE__ */ a(h.Provider, { value: { container: s }, children: /* @__PURE__ */ a("article", { className: "GSDK", "data-testid": "GSDK", children: r }) });
|
|
36
|
+
}, l = (c, t) => {
|
|
37
|
+
const r = [];
|
|
38
|
+
for (const [o, e] of Object.entries(c))
|
|
39
|
+
typeof e == "object" ? r.push(...l(e, t ? t + "-" + o : o)) : r.push(`--g-${t ? t + "-" + o : o}: ${e};`);
|
|
40
|
+
return r;
|
|
35
41
|
};
|
|
36
42
|
export {
|
|
37
|
-
|
|
43
|
+
C as ThemeProvider
|
|
38
44
|
};
|
|
39
45
|
//# sourceMappingURL=ThemeProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeProvider.js","sources":["../../../src/contexts/ThemeProvider/ThemeProvider.tsx"],"sourcesContent":["import type React from 'react'\nimport {
|
|
1
|
+
{"version":3,"file":"ThemeProvider.js","sources":["../../../src/contexts/ThemeProvider/ThemeProvider.tsx"],"sourcesContent":["import type React from 'react'\nimport { useEffect, useLayoutEffect, useMemo, useRef } from 'react'\nimport { ThemeContext } from './useTheme'\nimport { mergePartnerTheme, type GustoSDKTheme } from './theme'\nimport { useNonce } from '@/contexts/NonceProvider'\nimport '@/styles/sdk.scss'\n\n/** @internal */\nexport interface ThemeProviderProps {\n /** Partial set of theme tokens that override the SDK defaults. */\n theme?: Partial<GustoSDKTheme>\n /**\n * Element to use as the portal container for all SDK overlays (Select, ComboBox,\n * DatePicker, Menu, etc.). Defaults to a themed root element the SDK appends\n * directly to `document.body`, so overlays are never affected by a host page's\n * `position`, `transform`, `filter`, or `contain` on an intervening ancestor.\n * That default root carries both the `GSDK` and `GSDK-portal-root` classes —\n * the latter lets a host page's own `.GSDK` overrides exclude it\n * (`.GSDK:not(.GSDK-portal-root)`) instead of reaching overlay content.\n *\n * Pass a specific element (e.g. when rendering inside a modal or shadow root)\n * to portal overlays there instead.\n */\n portalContainer?: HTMLElement\n /** Subtree rendered inside the SDK's themed root element. */\n children?: React.ReactNode\n}\n\n/** @internal */\nexport const ThemeProvider: React.FC<ThemeProviderProps> = ({\n theme: partnerThemeOverrides = {},\n portalContainer,\n children,\n}) => {\n const nonce = useNonce()\n const GThemeVariables = useRef<HTMLStyleElement | null>(null)\n const portalContainerRef = useRef<HTMLElement | null>(null)\n\n useLayoutEffect(() => {\n if (portalContainer) {\n portalContainerRef.current = portalContainer\n return\n }\n\n const defaultPortalRoot = document.createElement('div')\n defaultPortalRoot.className = 'GSDK GSDK-portal-root'\n defaultPortalRoot.setAttribute('data-testid', 'GSDK-portal-root')\n document.body.appendChild(defaultPortalRoot)\n portalContainerRef.current = defaultPortalRoot\n\n return () => {\n defaultPortalRoot.remove()\n }\n }, [portalContainer])\n\n const mergedTheme = useMemo(\n () => mergePartnerTheme(partnerThemeOverrides),\n [partnerThemeOverrides],\n )\n\n const cssContent = useMemo(\n () => `.GSDK{\\n${parseThemeToCSS(mergedTheme).join('\\n')}\\n}`,\n [mergedTheme],\n )\n\n useEffect(() => {\n if (!GThemeVariables.current) {\n GThemeVariables.current = document.createElement('style')\n GThemeVariables.current.setAttribute('data-testid', 'GSDK')\n if (nonce) GThemeVariables.current.nonce = nonce\n document.head.appendChild(GThemeVariables.current)\n }\n\n GThemeVariables.current.textContent = cssContent\n }, [cssContent, nonce])\n\n return (\n <ThemeContext.Provider value={{ container: portalContainerRef }}>\n <article className=\"GSDK\" data-testid=\"GSDK\">\n {children}\n </article>\n </ThemeContext.Provider>\n )\n}\n\n/**\n * Recursive flattening of the theme object into css variable format\n */\nconst parseThemeToCSS = (theme: Partial<GustoSDKTheme>, prefix?: string): string[] => {\n const cssProps: string[] = []\n for (const [key, value] of Object.entries(theme)) {\n if (typeof value === 'object') {\n cssProps.push(...parseThemeToCSS(value, prefix ? prefix + '-' + key : key))\n } else {\n cssProps.push(`--g-${prefix ? prefix + '-' + key : key}: ${value};`)\n }\n }\n return cssProps\n}\n"],"names":["ThemeProvider","partnerThemeOverrides","portalContainer","children","nonce","useNonce","GThemeVariables","useRef","portalContainerRef","useLayoutEffect","defaultPortalRoot","mergedTheme","useMemo","mergePartnerTheme","cssContent","parseThemeToCSS","useEffect","ThemeContext","jsx","theme","prefix","cssProps","key","value"],"mappings":";;;;;;AA6BO,MAAMA,IAA8C,CAAC;AAAA,EAC1D,OAAOC,IAAwB,CAAA;AAAA,EAC/B,iBAAAC;AAAA,EACA,UAAAC;AACF,MAAM;AACJ,QAAMC,IAAQC,EAAA,GACRC,IAAkBC,EAAgC,IAAI,GACtDC,IAAqBD,EAA2B,IAAI;AAE1D,EAAAE,EAAgB,MAAM;AACpB,QAAIP,GAAiB;AACnB,MAAAM,EAAmB,UAAUN;AAC7B;AAAA,IACF;AAEA,UAAMQ,IAAoB,SAAS,cAAc,KAAK;AACtD,WAAAA,EAAkB,YAAY,yBAC9BA,EAAkB,aAAa,eAAe,kBAAkB,GAChE,SAAS,KAAK,YAAYA,CAAiB,GAC3CF,EAAmB,UAAUE,GAEtB,MAAM;AACX,MAAAA,EAAkB,OAAA;AAAA,IACpB;AAAA,EACF,GAAG,CAACR,CAAe,CAAC;AAEpB,QAAMS,IAAcC;AAAA,IAClB,MAAMC,EAAkBZ,CAAqB;AAAA,IAC7C,CAACA,CAAqB;AAAA,EAAA,GAGlBa,IAAaF;AAAA,IACjB,MAAM;AAAA,EAAWG,EAAgBJ,CAAW,EAAE,KAAK;AAAA,CAAI,CAAC;AAAA;AAAA,IACxD,CAACA,CAAW;AAAA,E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