@gusto/embedded-react-sdk 0.52.1 → 0.52.2
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 +16 -0
- package/dist/components/Base/Base.d.ts +2 -2
- package/dist/components/Base/Base.js.map +1 -1
- package/dist/components/Company/AssignSignatory/CreateSignatory/useCreateSignatory.js +3 -5
- package/dist/components/Company/AssignSignatory/CreateSignatory/useCreateSignatory.js.map +1 -1
- package/dist/components/Company/AssignSignatory/InviteSignatory/useInviteSignatory.js +3 -5
- package/dist/components/Company/AssignSignatory/InviteSignatory/useInviteSignatory.js.map +1 -1
- package/dist/components/Company/AssignSignatory/useAssignSignatory.js +5 -7
- package/dist/components/Company/AssignSignatory/useAssignSignatory.js.map +1 -1
- package/dist/components/Company/BankAccount/BankAccountForm/context.js +3 -5
- package/dist/components/Company/BankAccount/BankAccountForm/context.js.map +1 -1
- package/dist/components/Company/DocumentSigner/DocumentList/useDocumentList.js +3 -5
- package/dist/components/Company/DocumentSigner/DocumentList/useDocumentList.js.map +1 -1
- package/dist/components/Company/DocumentSigner/shared/useSignCompanyForm/fields.js +4 -4
- package/dist/components/Company/FederalTaxes/useFederalTaxes.js +8 -10
- package/dist/components/Company/FederalTaxes/useFederalTaxes.js.map +1 -1
- package/dist/components/Company/Industry/Context.js +6 -8
- package/dist/components/Company/Industry/Context.js.map +1 -1
- package/dist/components/Company/Locations/LocationForm/useLocationForm.js +3 -5
- package/dist/components/Company/Locations/LocationForm/useLocationForm.js.map +1 -1
- package/dist/components/Company/Locations/LocationsList/useLocationsList.js +3 -5
- package/dist/components/Company/Locations/LocationsList/useLocationsList.js.map +1 -1
- package/dist/components/Company/OnboardingOverview/context.js +3 -5
- package/dist/components/Company/OnboardingOverview/context.js.map +1 -1
- package/dist/components/Company/PaySchedule/shared/usePayScheduleForm/fields.js +5 -5
- package/dist/components/Company/StateTaxes/StateTaxesForm/context.js +3 -5
- package/dist/components/Company/StateTaxes/StateTaxesForm/context.js.map +1 -1
- package/dist/components/Company/StateTaxes/StateTaxesList/context.js +3 -5
- package/dist/components/Company/StateTaxes/StateTaxesList/context.js.map +1 -1
- package/dist/components/Company/StateTaxes/stateTaxesStateMachine.d.ts +0 -1
- package/dist/components/Company/StateTaxes/stateTaxesStateMachine.js +12 -14
- package/dist/components/Company/StateTaxes/stateTaxesStateMachine.js.map +1 -1
- package/dist/components/Contractor/Address/Address.js +83 -75
- package/dist/components/Contractor/Address/Address.js.map +1 -1
- package/dist/components/Contractor/ContractorList/index.js +52 -61
- package/dist/components/Contractor/ContractorList/index.js.map +1 -1
- package/dist/components/Contractor/Documents/SignatureForm/SignatureForm.js +170 -123
- package/dist/components/Contractor/Documents/SignatureForm/SignatureForm.js.map +1 -1
- package/dist/components/Contractor/Documents/SignatureForm/SignatureForm.module.scss.js +12 -0
- package/dist/components/Contractor/Documents/SignatureForm/SignatureForm.module.scss.js.map +1 -0
- package/dist/components/Contractor/Documents/SignatureForm/useContractorSignatureForm/fields.js +44 -43
- package/dist/components/Contractor/Documents/SignatureForm/useContractorSignatureForm/fields.js.map +1 -1
- package/dist/components/Contractor/Documents/SignatureForm/useContractorSignatureForm/useContractorSignatureForm.js +91 -88
- package/dist/components/Contractor/Documents/SignatureForm/useContractorSignatureForm/useContractorSignatureForm.js.map +1 -1
- package/dist/components/Contractor/Documents/SignatureForm/useContractorSignatureForm/w9Fields.d.ts +0 -33
- package/dist/components/Contractor/Documents/SignatureForm/useContractorSignatureForm/w9Fields.js +77 -86
- package/dist/components/Contractor/Documents/SignatureForm/useContractorSignatureForm/w9Fields.js.map +1 -1
- package/dist/components/Contractor/PaymentMethod/shared/useContractorBankAccountForm/fields.js +1 -1
- package/dist/components/Contractor/Profile/ContractorProfile.js +63 -57
- package/dist/components/Contractor/Profile/ContractorProfile.js.map +1 -1
- package/dist/components/Contractor/Profile/shared/useContractorDetailsForm/fields.js +16 -16
- package/dist/components/Contractor/Submit/Submit.js +118 -101
- package/dist/components/Contractor/Submit/Submit.js.map +1 -1
- package/dist/components/Contractor/shared/useContractorHasSignedW9.d.ts +8 -0
- package/dist/components/Contractor/shared/useContractorHasSignedW9.js +10 -0
- package/dist/components/Contractor/shared/useContractorHasSignedW9.js.map +1 -0
- package/dist/components/Employee/Compensation/shared/useCompensationForm/fields.js +4 -4
- package/dist/components/Employee/Compensation/shared/useJobForm/fields.js +6 -6
- package/dist/components/Employee/Deductions/shared/useChildSupportGarnishmentForm/fields.js +8 -8
- package/dist/components/Employee/Deductions/shared/useDeductionForm/fields.js +4 -4
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/useDocumentList.js +3 -5
- package/dist/components/Employee/Documents/onboarding/DocumentSigner/DocumentList/useDocumentList.js.map +1 -1
- package/dist/components/Employee/Documents/shared/useSignEmployeeForm/fields.js +1 -1
- package/dist/components/Employee/FederalTaxes/shared/useFederalTaxesForm/fields.js +4 -4
- package/dist/components/Employee/PaymentMethod/shared/useBankForm/fields.js +1 -1
- package/dist/components/Employee/PaymentMethod/shared/useSplitPaymentsForm/splitFieldFactory.js +4 -4
- package/dist/components/Employee/Profile/shared/useEmployeeDetailsForm/fields.js +8 -8
- package/dist/components/Employee/Profile/shared/useHomeAddressForm/fields.js +5 -5
- package/dist/components/Employee/Profile/shared/useHomeAddressForm/useCurrentHomeAddressForm.d.ts +1 -0
- package/dist/components/Employee/Profile/shared/useHomeAddressForm/useCurrentHomeAddressForm.js.map +1 -1
- package/dist/components/Employee/Profile/shared/useWorkAddressForm/fields.js +4 -4
- package/dist/components/Employee/Profile/shared/useWorkAddressForm/useCurrentWorkAddressForm.d.ts +1 -0
- package/dist/components/Employee/Profile/shared/useWorkAddressForm/useCurrentWorkAddressForm.js.map +1 -1
- package/dist/components/Employee/StateTaxes/shared/useEmployeeStateTaxesForm/fieldComponents.js +8 -8
- package/dist/components/Payroll/usePreparedPayrollData.js +8 -10
- package/dist/components/Payroll/usePreparedPayrollData.js.map +1 -1
- package/dist/components/index.d.ts +40 -0
- package/dist/i18n/en/Contractor.Address.json.js +22 -20
- package/dist/i18n/en/Contractor.Address.json.js.map +1 -1
- package/dist/i18n/en/Contractor.Profile.json.js +13 -11
- package/dist/i18n/en/Contractor.Profile.json.js.map +1 -1
- package/dist/i18n/en/Contractor.SignatureForm.json.js +5 -5
- package/dist/i18n/types.d.ts +22 -6
- package/dist/index.d.ts +6 -3
- package/dist/style.css +1 -1
- package/dist/types/Helpers.d.ts +1 -1
- package/docs/guides/endpoint-inventory.json +0 -27
- package/package.json +6 -6
package/dist/components/Contractor/Documents/SignatureForm/useContractorSignatureForm/w9Fields.d.ts
CHANGED
|
@@ -16,39 +16,6 @@ export declare const W9_DOCUMENT_NAME = "taxpayer_identification_form_w_9";
|
|
|
16
16
|
* @internal
|
|
17
17
|
*/
|
|
18
18
|
export declare const NOT_APPLICABLE_VALUE = "N/A";
|
|
19
|
-
/**
|
|
20
|
-
* EIN input transform that preserves the `N/A` sentinel (and the in-progress
|
|
21
|
-
* prefixes a user types toward it) while formatting numeric input as a standard
|
|
22
|
-
* EIN (`NN-NNNNNNN`).
|
|
23
|
-
*
|
|
24
|
-
* @remarks
|
|
25
|
-
* The W-9 accepts `N/A` for a taxpayer who supplies an SSN instead of an EIN,
|
|
26
|
-
* but the plain `normalizeEin` formatter strips every non-digit on each
|
|
27
|
-
* keystroke — making the sentinel impossible to type. This wrapper lets the
|
|
28
|
-
* sentinel through (normalized to uppercase) and defers to `normalizeEin` for
|
|
29
|
-
* everything else.
|
|
30
|
-
*
|
|
31
|
-
* @param value - Raw user input.
|
|
32
|
-
* @returns The `N/A` sentinel (or an in-progress prefix), otherwise the EIN-formatted value.
|
|
33
|
-
* @internal
|
|
34
|
-
*/
|
|
35
|
-
export declare function normalizeEinOrNotApplicable(value: string): string;
|
|
36
|
-
/**
|
|
37
|
-
* SSN input transform that preserves the `N/A` sentinel (and the in-progress
|
|
38
|
-
* prefixes `N` and `N/`) while otherwise deferring to {@link normalizeSSN}.
|
|
39
|
-
*
|
|
40
|
-
* @remarks
|
|
41
|
-
* The W-9 accepts `N/A` for a taxpayer who supplies an EIN instead of an SSN,
|
|
42
|
-
* but the plain `normalizeSSN` formatter strips every non-digit on each
|
|
43
|
-
* keystroke — making the sentinel impossible to type. This wrapper lets the
|
|
44
|
-
* sentinel through (normalized to uppercase) and defers to `normalizeSSN` for
|
|
45
|
-
* everything else.
|
|
46
|
-
*
|
|
47
|
-
* @param value - Raw user input.
|
|
48
|
-
* @returns The `N/A` sentinel (or an in-progress prefix), otherwise the SSN-formatted value.
|
|
49
|
-
* @internal
|
|
50
|
-
*/
|
|
51
|
-
export declare function normalizeSsnOrNotApplicable(value: string): string;
|
|
52
19
|
/**
|
|
53
20
|
* Form-field name for the synthesized federal tax classification radio group.
|
|
54
21
|
*
|
package/dist/components/Contractor/Documents/SignatureForm/useContractorSignatureForm/w9Fields.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { normalizeSSN as N } from "../../../../../helpers/ssn.js";
|
|
3
|
-
const R = "taxpayer_identification_form_w_9", _ = "N/A";
|
|
4
|
-
function D(e) {
|
|
5
|
-
const t = e.replace(/\s/g, "").toUpperCase();
|
|
6
|
-
return t === "NA" ? _ : t === "N" || t === "N/" || t === _ ? t : S(e);
|
|
7
|
-
}
|
|
8
|
-
function k(e) {
|
|
9
|
-
const t = e.replace(/\s/g, "").toUpperCase();
|
|
10
|
-
return t === "NA" ? _ : t === "N" || t === "N/" || t === _ ? t : N(e);
|
|
11
|
-
}
|
|
12
|
-
const x = "taxClassification", T = "llcClassificationCode", F = "otherText", C = [
|
|
1
|
+
const C = "taxpayer_identification_form_w_9", P = "N/A", S = "taxClassification", x = "llcClassificationCode", T = "otherText", A = [
|
|
13
2
|
"individual_proprietor",
|
|
14
3
|
"c_corporation",
|
|
15
4
|
"s_corporation",
|
|
@@ -17,7 +6,7 @@ const x = "taxClassification", T = "llcClassificationCode", F = "otherText", C =
|
|
|
17
6
|
"trust_estate",
|
|
18
7
|
"limited_liability_company",
|
|
19
8
|
"other"
|
|
20
|
-
], y = "limited_liability_company",
|
|
9
|
+
], y = "limited_liability_company", F = "other", b = ["c", "s", "p"], _ = {
|
|
21
10
|
name: "name",
|
|
22
11
|
businessName: "business_name",
|
|
23
12
|
otherText: "other_text",
|
|
@@ -34,64 +23,67 @@ const x = "taxClassification", T = "llcClassificationCode", F = "otherText", C =
|
|
|
34
23
|
ssn: "ssn",
|
|
35
24
|
ein: "ein",
|
|
36
25
|
signatureText: "signature_text"
|
|
37
|
-
},
|
|
38
|
-
function
|
|
39
|
-
return typeof
|
|
26
|
+
}, I = /* @__PURE__ */ new Set(["ssn", "ein"]);
|
|
27
|
+
function N(s) {
|
|
28
|
+
return typeof s == "string" && /[X•*]/.test(s);
|
|
29
|
+
}
|
|
30
|
+
function h(s) {
|
|
31
|
+
return s ? (I.has(s.key ?? "") || s.dataType === "ssn" || s.dataType === "ein") && N(s.value) : !1;
|
|
40
32
|
}
|
|
41
|
-
function
|
|
42
|
-
|
|
33
|
+
function u(s) {
|
|
34
|
+
const n = /* @__PURE__ */ new Map();
|
|
35
|
+
for (const t of s.fields ?? [])
|
|
36
|
+
t.key && n.set(t.key, t);
|
|
37
|
+
return n;
|
|
43
38
|
}
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
for (const n of e.fields ?? [])
|
|
47
|
-
n.key && t.set(n.key, n);
|
|
48
|
-
return t;
|
|
39
|
+
function p(s) {
|
|
40
|
+
return s === "1" || s === "true";
|
|
49
41
|
}
|
|
50
|
-
function
|
|
51
|
-
return
|
|
42
|
+
function O(s) {
|
|
43
|
+
return s.name === C;
|
|
52
44
|
}
|
|
53
|
-
function
|
|
54
|
-
const
|
|
45
|
+
function g(s) {
|
|
46
|
+
const n = u(s), t = n.get("ssn"), e = n.get("ein"), a = h(t), o = h(e);
|
|
55
47
|
return {
|
|
56
|
-
ssnRedacted:
|
|
57
|
-
einRedacted:
|
|
58
|
-
ssnPlaceholder:
|
|
59
|
-
einPlaceholder:
|
|
48
|
+
ssnRedacted: a,
|
|
49
|
+
einRedacted: o,
|
|
50
|
+
ssnPlaceholder: a ? t?.value ?? void 0 : void 0,
|
|
51
|
+
einPlaceholder: o ? e?.value ?? void 0 : void 0
|
|
60
52
|
};
|
|
61
53
|
}
|
|
62
|
-
function
|
|
63
|
-
const
|
|
64
|
-
for (const [
|
|
65
|
-
|
|
66
|
-
return
|
|
54
|
+
function E(s) {
|
|
55
|
+
const n = u(s), t = /* @__PURE__ */ new Set();
|
|
56
|
+
for (const [a, o] of Object.entries(_))
|
|
57
|
+
n.has(o) && t.add(a);
|
|
58
|
+
return A.some((a) => n.has(a)) && (t.add(S), t.add(x)), t;
|
|
67
59
|
}
|
|
68
|
-
function
|
|
69
|
-
const
|
|
60
|
+
function v(s) {
|
|
61
|
+
const n = u(s), t = g(s), e = (o) => n.get(o)?.value ?? "", a = A.find((o) => p(n.get(o)?.value)) ?? "";
|
|
70
62
|
return {
|
|
71
|
-
name:
|
|
72
|
-
businessName:
|
|
73
|
-
taxClassification:
|
|
63
|
+
name: e("name"),
|
|
64
|
+
businessName: e("business_name"),
|
|
65
|
+
taxClassification: a,
|
|
74
66
|
// The LLC code serializes into the `tax_classification` field, so seed it
|
|
75
67
|
// back from there when the LLC classification is the selected one.
|
|
76
|
-
llcClassificationCode:
|
|
77
|
-
otherText:
|
|
78
|
-
foreignPartners:
|
|
79
|
-
exemptPayeeCode:
|
|
80
|
-
exemptionFromFatca:
|
|
81
|
-
homeAddressStreet1:
|
|
82
|
-
homeAddressStreet2:
|
|
83
|
-
homeAddressCity:
|
|
84
|
-
homeAddressState:
|
|
85
|
-
homeAddressZip:
|
|
86
|
-
accountNumber:
|
|
87
|
-
companyName:
|
|
88
|
-
ssn:
|
|
89
|
-
ein:
|
|
90
|
-
signatureText:
|
|
68
|
+
llcClassificationCode: a === y ? e("tax_classification") : "",
|
|
69
|
+
otherText: e("other_text"),
|
|
70
|
+
foreignPartners: p(n.get("foreign_partners")?.value),
|
|
71
|
+
exemptPayeeCode: e("exempt_payee_code"),
|
|
72
|
+
exemptionFromFatca: e("exemption_from_FATCA"),
|
|
73
|
+
homeAddressStreet1: e("home_address_street_1"),
|
|
74
|
+
homeAddressStreet2: e("home_address_street_2"),
|
|
75
|
+
homeAddressCity: e("home_address_city"),
|
|
76
|
+
homeAddressState: e("home_address_state"),
|
|
77
|
+
homeAddressZip: e("home_address_zip"),
|
|
78
|
+
accountNumber: e("account_number"),
|
|
79
|
+
companyName: e("company_name"),
|
|
80
|
+
ssn: t.ssnRedacted ? "" : e("ssn"),
|
|
81
|
+
ein: t.einRedacted ? "" : e("ein"),
|
|
82
|
+
signatureText: e("signature_text"),
|
|
91
83
|
agree: !1
|
|
92
84
|
};
|
|
93
85
|
}
|
|
94
|
-
const
|
|
86
|
+
const D = {
|
|
95
87
|
name: "",
|
|
96
88
|
businessName: "",
|
|
97
89
|
taxClassification: "",
|
|
@@ -111,7 +103,7 @@ const V = {
|
|
|
111
103
|
ein: "",
|
|
112
104
|
signatureText: "",
|
|
113
105
|
agree: !1
|
|
114
|
-
},
|
|
106
|
+
}, L = [
|
|
115
107
|
"name",
|
|
116
108
|
"businessName",
|
|
117
109
|
"exemptPayeeCode",
|
|
@@ -125,39 +117,38 @@ const V = {
|
|
|
125
117
|
"companyName",
|
|
126
118
|
"signatureText"
|
|
127
119
|
];
|
|
128
|
-
function
|
|
129
|
-
const
|
|
130
|
-
const m =
|
|
120
|
+
function R(s, n, t) {
|
|
121
|
+
const e = E(s), a = [], o = n, r = (i) => {
|
|
122
|
+
const m = o[i];
|
|
131
123
|
return typeof m == "string" ? m : "";
|
|
132
|
-
},
|
|
133
|
-
|
|
124
|
+
}, d = r("taxClassification"), c = (i, m) => {
|
|
125
|
+
a.push({ key: _[i], value: m });
|
|
134
126
|
};
|
|
135
|
-
for (const i of
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
key:
|
|
139
|
-
value:
|
|
127
|
+
for (const i of L)
|
|
128
|
+
e.has(i) && c(i, r(i));
|
|
129
|
+
e.has(T) && d === F && c("otherText", r("otherText")), e.has("foreignPartners") && a.push({
|
|
130
|
+
key: _.foreignPartners,
|
|
131
|
+
value: n.foreignPartners ? "1" : "0"
|
|
140
132
|
});
|
|
141
|
-
const
|
|
142
|
-
return
|
|
133
|
+
const l = r("ssn"), f = r("ein");
|
|
134
|
+
return e.has("ssn") && !(t.ssnRedacted && l === "") && c("ssn", l), e.has("ein") && !(t.einRedacted && f === "") && c("ein", f), d && (a.push({ key: d, value: "1" }), d === y && a.push({ key: "tax_classification", value: r("llcClassificationCode") })), a;
|
|
143
135
|
}
|
|
144
136
|
export {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
137
|
+
D as EMPTY_W9_DEFAULTS,
|
|
138
|
+
b as LLC_CLASSIFICATION_CODES,
|
|
139
|
+
x as LLC_CLASSIFICATION_FIELD,
|
|
148
140
|
y as LLC_CLASSIFICATION_OPTION,
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
U as serializeW9Fields
|
|
141
|
+
P as NOT_APPLICABLE_VALUE,
|
|
142
|
+
F as OTHER_CLASSIFICATION_OPTION,
|
|
143
|
+
T as OTHER_TEXT_FIELD,
|
|
144
|
+
S as TAX_CLASSIFICATION_FIELD,
|
|
145
|
+
A as TAX_CLASSIFICATION_OPTION_KEYS,
|
|
146
|
+
C as W9_DOCUMENT_NAME,
|
|
147
|
+
_ as W9_FIELD_API_KEYS,
|
|
148
|
+
v as buildW9Defaults,
|
|
149
|
+
E as getPresentFieldNames,
|
|
150
|
+
g as getRedactionState,
|
|
151
|
+
O as isW9Document,
|
|
152
|
+
R as serializeW9Fields
|
|
162
153
|
};
|
|
163
154
|
//# sourceMappingURL=w9Fields.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"w9Fields.js","sources":["../../../../../../src/components/Contractor/Documents/SignatureForm/useContractorSignatureForm/w9Fields.ts"],"sourcesContent":["import type {\n Document,\n Fields as DocumentField,\n} from '@gusto/embedded-api/models/components/document'\nimport type { ContractorSignatureFormData } from './contractorSignatureFormSchema'\nimport { normalizeEin } from '@/helpers/federalEin'\nimport { normalizeSSN } from '@/helpers/ssn'\n\n/**\n * The `name` of the W-9 document — the only contractor document type that\n * supports signing today.\n *\n * @internal\n */\nexport const W9_DOCUMENT_NAME = 'taxpayer_identification_form_w_9'\n\n/**\n * Sentinel the API returns (and accepts) for a taxpayer-ID field that doesn't\n * apply to the signer — e.g. the EIN of an individual contractor, or the SSN of\n * a business contractor. The sign endpoint stamps this verbatim, so the form\n * both prefills it and treats it as a valid submission.\n *\n * @internal\n */\nexport const NOT_APPLICABLE_VALUE = 'N/A'\n\n/**\n * EIN input transform that preserves the `N/A` sentinel (and the in-progress\n * prefixes a user types toward it) while formatting numeric input as a standard\n * EIN (`NN-NNNNNNN`).\n *\n * @remarks\n * The W-9 accepts `N/A` for a taxpayer who supplies an SSN instead of an EIN,\n * but the plain `normalizeEin` formatter strips every non-digit on each\n * keystroke — making the sentinel impossible to type. This wrapper lets the\n * sentinel through (normalized to uppercase) and defers to `normalizeEin` for\n * everything else.\n *\n * @param value - Raw user input.\n * @returns The `N/A` sentinel (or an in-progress prefix), otherwise the EIN-formatted value.\n * @internal\n */\nexport function normalizeEinOrNotApplicable(value: string): string {\n const sentinel = value.replace(/\\s/g, '').toUpperCase()\n if (sentinel === 'NA') return NOT_APPLICABLE_VALUE\n if (sentinel === 'N' || sentinel === 'N/' || sentinel === NOT_APPLICABLE_VALUE) return sentinel\n return normalizeEin(value)\n}\n\n/**\n * SSN input transform that preserves the `N/A` sentinel (and the in-progress\n * prefixes `N` and `N/`) while otherwise deferring to {@link normalizeSSN}.\n *\n * @remarks\n * The W-9 accepts `N/A` for a taxpayer who supplies an EIN instead of an SSN,\n * but the plain `normalizeSSN` formatter strips every non-digit on each\n * keystroke — making the sentinel impossible to type. This wrapper lets the\n * sentinel through (normalized to uppercase) and defers to `normalizeSSN` for\n * everything else.\n *\n * @param value - Raw user input.\n * @returns The `N/A` sentinel (or an in-progress prefix), otherwise the SSN-formatted value.\n * @internal\n */\nexport function normalizeSsnOrNotApplicable(value: string): string {\n const sentinel = value.replace(/\\s/g, '').toUpperCase()\n if (sentinel === 'NA') return NOT_APPLICABLE_VALUE\n if (sentinel === 'N' || sentinel === 'N/' || sentinel === NOT_APPLICABLE_VALUE) return sentinel\n return normalizeSSN(value)\n}\n\n/**\n * Form-field name for the synthesized federal tax classification radio group.\n *\n * @internal\n */\nexport const TAX_CLASSIFICATION_FIELD = 'taxClassification'\n\n/**\n * Form-field name for the synthesized LLC tax classification code select.\n *\n * @internal\n */\nexport const LLC_CLASSIFICATION_FIELD = 'llcClassificationCode'\n\n/**\n * Form-field name for the \"Other\" free-text classification field.\n *\n * @internal\n */\nexport const OTHER_TEXT_FIELD = 'otherText'\n\n/**\n * Ordered classification option keys backing the {@link TAX_CLASSIFICATION_FIELD}\n * radio group. Each maps to a W-9 checkbox field on the underlying document.\n *\n * @internal\n */\nexport const TAX_CLASSIFICATION_OPTION_KEYS = [\n 'individual_proprietor',\n 'c_corporation',\n 's_corporation',\n 'partnership',\n 'trust_estate',\n 'limited_liability_company',\n 'other',\n] as const\n\n/**\n * A single federal tax classification option key.\n *\n * @internal\n */\nexport type TaxClassificationOptionKey = (typeof TAX_CLASSIFICATION_OPTION_KEYS)[number]\n\n/**\n * The classification option that reveals the LLC tax classification select.\n *\n * @internal\n */\nexport const LLC_CLASSIFICATION_OPTION: TaxClassificationOptionKey = 'limited_liability_company'\n\n/**\n * The classification option that reveals the \"Other\" free-text field.\n *\n * @internal\n */\nexport const OTHER_CLASSIFICATION_OPTION: TaxClassificationOptionKey = 'other'\n\n/**\n * Ordered LLC tax classification code options.\n *\n * @internal\n */\nexport const LLC_CLASSIFICATION_CODES = ['c', 's', 'p'] as const\n\n/**\n * Maps each pass-through {@link ContractorSignatureFormData} field to its W-9\n * API field key. Synthesized fields (`taxClassification`,\n * `llcClassificationCode`) and `agree` are intentionally absent.\n *\n * @internal\n */\nexport const W9_FIELD_API_KEYS = {\n name: 'name',\n businessName: 'business_name',\n otherText: 'other_text',\n foreignPartners: 'foreign_partners',\n exemptPayeeCode: 'exempt_payee_code',\n exemptionFromFatca: 'exemption_from_FATCA',\n homeAddressStreet1: 'home_address_street_1',\n homeAddressStreet2: 'home_address_street_2',\n homeAddressCity: 'home_address_city',\n homeAddressState: 'home_address_state',\n homeAddressZip: 'home_address_zip',\n accountNumber: 'account_number',\n companyName: 'company_name',\n ssn: 'ssn',\n ein: 'ein',\n signatureText: 'signature_text',\n} as const satisfies Record<string, string>\n\n/** A pass-through W-9 field name (one with a single backing API key). */\ntype PassThroughFieldName = keyof typeof W9_FIELD_API_KEYS\n\n/** API field keys whose values are sensitive and arrive masked when on file. */\nconst SENSITIVE_FIELD_KEYS = new Set(['ssn', 'ein'])\n\n/** Whether a value is a server-side mask (e.g. `XXX-XX-1111`) rather than real input. */\nfunction isMaskedValue(value: string | null | undefined): boolean {\n return typeof value === 'string' && /[X•*]/.test(value)\n}\n\n/** Whether a document field carries a redacted (masked) sensitive value. */\nfunction hasRedactedValue(field: DocumentField | undefined): boolean {\n if (!field) return false\n const isSensitive =\n SENSITIVE_FIELD_KEYS.has(field.key ?? '') ||\n field.dataType === 'ssn' ||\n field.dataType === 'ein'\n return isSensitive && isMaskedValue(field.value)\n}\n\nfunction indexFields(document: Document): Map<string, DocumentField> {\n const byKey = new Map<string, DocumentField>()\n for (const field of document.fields ?? []) {\n if (field.key) byKey.set(field.key, field)\n }\n return byKey\n}\n\n/** Coerces an API checkbox value (`'1'`, `'true'`) to a boolean. */\nfunction toBoolean(value: string | null | undefined): boolean {\n return value === '1' || value === 'true'\n}\n\n/**\n * Whether the document is a W-9 (the only signable contractor document type).\n *\n * @internal\n */\nexport function isW9Document(document: Document): boolean {\n return document.name === W9_DOCUMENT_NAME\n}\n\n/**\n * Redaction state for the sensitive W-9 fields, derived from the API response.\n *\n * @internal\n */\nexport interface W9RedactionState {\n /** Whether the API returned a masked SSN value. */\n ssnRedacted: boolean\n /** Whether the API returned a masked EIN value. */\n einRedacted: boolean\n /** The masked SSN to surface as a placeholder, when redacted. */\n ssnPlaceholder?: string\n /** The masked EIN to surface as a placeholder, when redacted. */\n einPlaceholder?: string\n}\n\n/**\n * Computes the redaction state of the SSN/EIN fields from the document.\n *\n * @param document - The W-9 document returned by the API.\n * @returns The redaction flags and masked placeholders.\n * @internal\n */\nexport function getRedactionState(document: Document): W9RedactionState {\n const byKey = indexFields(document)\n const ssnField = byKey.get('ssn')\n const einField = byKey.get('ein')\n const ssnRedacted = hasRedactedValue(ssnField)\n const einRedacted = hasRedactedValue(einField)\n return {\n ssnRedacted,\n einRedacted,\n ssnPlaceholder: ssnRedacted ? (ssnField?.value ?? undefined) : undefined,\n einPlaceholder: einRedacted ? (einField?.value ?? undefined) : undefined,\n }\n}\n\n/**\n * Computes which W-9 form fields the API actually returned — the safety check\n * that drives presence-gating in {@link useContractorSignatureForm}.\n *\n * @remarks\n * A pass-through field is present when its API key is in `document.fields`. The\n * synthesized classification fields (`taxClassification`,\n * `llcClassificationCode`) are present when the document carries any of the\n * federal tax classification checkbox fields.\n *\n * @param document - The W-9 document returned by the API.\n * @returns The set of present camelCase field names.\n * @internal\n */\nexport function getPresentFieldNames(document: Document): Set<string> {\n const byKey = indexFields(document)\n const presentFieldNames = new Set<string>()\n\n for (const [fieldName, apiKey] of Object.entries(W9_FIELD_API_KEYS)) {\n if (byKey.has(apiKey)) presentFieldNames.add(fieldName)\n }\n\n const hasClassification = TAX_CLASSIFICATION_OPTION_KEYS.some(key => byKey.has(key))\n if (hasClassification) {\n presentFieldNames.add(TAX_CLASSIFICATION_FIELD)\n presentFieldNames.add(LLC_CLASSIFICATION_FIELD)\n }\n\n return presentFieldNames\n}\n\n/**\n * Builds default form values from a document's fields.\n *\n * @remarks\n * Pass-through values are seeded from the API `value`. The classification radio\n * defaults to whichever classification checkbox is already set (`'1'`/`'true'`),\n * and when that is the LLC classification the LLC code select is seeded from the\n * `tax_classification` field it serializes into. A masked SSN/EIN seeds an empty\n * input (the mask is surfaced as a placeholder instead) so it is never echoed\n * back as the new value on submit.\n *\n * @param document - The W-9 document returned by the API.\n * @returns The default form values.\n * @internal\n */\nexport function buildW9Defaults(document: Document): ContractorSignatureFormData {\n const byKey = indexFields(document)\n const redaction = getRedactionState(document)\n const textValue = (apiKey: string): string => byKey.get(apiKey)?.value ?? ''\n const selectedClassification =\n TAX_CLASSIFICATION_OPTION_KEYS.find(key => toBoolean(byKey.get(key)?.value)) ?? ''\n\n return {\n name: textValue('name'),\n businessName: textValue('business_name'),\n taxClassification: selectedClassification,\n // The LLC code serializes into the `tax_classification` field, so seed it\n // back from there when the LLC classification is the selected one.\n llcClassificationCode:\n selectedClassification === LLC_CLASSIFICATION_OPTION ? textValue('tax_classification') : '',\n otherText: textValue('other_text'),\n foreignPartners: toBoolean(byKey.get('foreign_partners')?.value),\n exemptPayeeCode: textValue('exempt_payee_code'),\n exemptionFromFatca: textValue('exemption_from_FATCA'),\n homeAddressStreet1: textValue('home_address_street_1'),\n homeAddressStreet2: textValue('home_address_street_2'),\n homeAddressCity: textValue('home_address_city'),\n homeAddressState: textValue('home_address_state'),\n homeAddressZip: textValue('home_address_zip'),\n accountNumber: textValue('account_number'),\n companyName: textValue('company_name'),\n ssn: redaction.ssnRedacted ? '' : textValue('ssn'),\n ein: redaction.einRedacted ? '' : textValue('ein'),\n signatureText: textValue('signature_text'),\n agree: false,\n }\n}\n\n/**\n * The empty default form values, used while the document is still loading.\n *\n * @internal\n */\nexport const EMPTY_W9_DEFAULTS: ContractorSignatureFormData = {\n name: '',\n businessName: '',\n taxClassification: '',\n llcClassificationCode: '',\n otherText: '',\n foreignPartners: false,\n exemptPayeeCode: '',\n exemptionFromFatca: '',\n homeAddressStreet1: '',\n homeAddressStreet2: '',\n homeAddressCity: '',\n homeAddressState: '',\n homeAddressZip: '',\n accountNumber: '',\n companyName: '',\n ssn: '',\n ein: '',\n signatureText: '',\n agree: false,\n}\n\n/**\n * A single `{ key, value }` pair sent in the sign request.\n *\n * @internal\n */\nexport interface SignFieldValue {\n /** The API field key. */\n key: string\n /** The serialized field value. */\n value: string\n}\n\n/** Pass-through text fields serialized verbatim (everything except the checkbox and TIN fields). */\nconst TEXT_PASS_THROUGH_FIELDS: PassThroughFieldName[] = [\n 'name',\n 'businessName',\n 'exemptPayeeCode',\n 'exemptionFromFatca',\n 'homeAddressStreet1',\n 'homeAddressStreet2',\n 'homeAddressCity',\n 'homeAddressState',\n 'homeAddressZip',\n 'accountNumber',\n 'companyName',\n 'signatureText',\n]\n\n/**\n * Serializes W-9 form values into the `{ key, value }` field array expected by\n * the sign API.\n *\n * @remarks\n * Only fields the API returned (see {@link getPresentFieldNames}) are sent.\n * Applies the W-9 mapping: the chosen classification key is sent with value\n * `'1'`; when the LLC classification is chosen, the selected LLC code is sent\n * under the `tax_classification` key. `foreignPartners` serializes to\n * `'1'`/`'0'`. The `otherText` value is only included for the \"Other\"\n * classification. An untouched redacted SSN/EIN is omitted so the mask is never\n * sent back. The `date` field is intentionally omitted so the API auto-fills the\n * signing date in its own locale-correct format.\n *\n * @param document - The W-9 document being signed.\n * @param values - The validated form values.\n * @param redaction - The redaction state from {@link getRedactionState}.\n * @returns The ordered field array for the sign request body.\n * @internal\n */\nexport function serializeW9Fields(\n document: Document,\n values: ContractorSignatureFormData,\n redaction: W9RedactionState,\n): SignFieldValue[] {\n const presentFieldNames = getPresentFieldNames(document)\n const fields: SignFieldValue[] = []\n // The schema preprocesses empty inputs to `undefined`, so read through an\n // `unknown` view and coalesce missing values to an empty string.\n const raw = values as Record<string, unknown>\n const text = (name: string): string => {\n const value = raw[name]\n return typeof value === 'string' ? value : ''\n }\n const classification = text('taxClassification')\n\n const pushField = (fieldName: PassThroughFieldName, value: string) => {\n fields.push({ key: W9_FIELD_API_KEYS[fieldName], value })\n }\n\n for (const fieldName of TEXT_PASS_THROUGH_FIELDS) {\n if (!presentFieldNames.has(fieldName)) continue\n pushField(fieldName, text(fieldName))\n }\n\n if (presentFieldNames.has(OTHER_TEXT_FIELD) && classification === OTHER_CLASSIFICATION_OPTION) {\n pushField('otherText', text('otherText'))\n }\n\n if (presentFieldNames.has('foreignPartners')) {\n fields.push({\n key: W9_FIELD_API_KEYS.foreignPartners,\n value: values.foreignPartners ? '1' : '0',\n })\n }\n\n // A redacted field left untouched is omitted so the masked value isn't sent\n // back as a replacement; the server keeps the value already on file.\n const ssnValue = text('ssn')\n const einValue = text('ein')\n if (presentFieldNames.has('ssn') && !(redaction.ssnRedacted && ssnValue === '')) {\n pushField('ssn', ssnValue)\n }\n if (presentFieldNames.has('ein') && !(redaction.einRedacted && einValue === '')) {\n pushField('ein', einValue)\n }\n\n if (classification) {\n fields.push({ key: classification, value: '1' })\n if (classification === LLC_CLASSIFICATION_OPTION) {\n fields.push({ key: 'tax_classification', value: text('llcClassificationCode') })\n }\n }\n\n return fields\n}\n"],"names":["W9_DOCUMENT_NAME","NOT_APPLICABLE_VALUE","normalizeEinOrNotApplicable","value","sentinel","normalizeEin","normalizeSsnOrNotApplicable","normalizeSSN","TAX_CLASSIFICATION_FIELD","LLC_CLASSIFICATION_FIELD","OTHER_TEXT_FIELD","TAX_CLASSIFICATION_OPTION_KEYS","LLC_CLASSIFICATION_OPTION","OTHER_CLASSIFICATION_OPTION","LLC_CLASSIFICATION_CODES","W9_FIELD_API_KEYS","SENSITIVE_FIELD_KEYS","isMaskedValue","hasRedactedValue","field","indexFields","document","byKey","toBoolean","getRedactionState","ssnField","einField","ssnRedacted","einRedacted","getPresentFieldNames","presentFieldNames","fieldName","apiKey","key","buildW9Defaults","redaction","textValue","selectedClassification","EMPTY_W9_DEFAULTS","TEXT_PASS_THROUGH_FIELDS","serializeW9Fields","values","fields","raw","text","name","classification","p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ources":["../../../../../../src/components/Contractor/Documents/SignatureForm/useContractorSignatureForm/w9Fields.ts"],"sourcesContent":["import type {\n Document,\n Fields as DocumentField,\n} from '@gusto/embedded-api/models/components/document'\nimport type { ContractorSignatureFormData } from './contractorSignatureFormSchema'\n\n/**\n * The `name` of the W-9 document — the only contractor document type that\n * supports signing today.\n *\n * @internal\n */\nexport const W9_DOCUMENT_NAME = 'taxpayer_identification_form_w_9'\n\n/**\n * Sentinel the API returns (and accepts) for a taxpayer-ID field that doesn't\n * apply to the signer — e.g. the EIN of an individual contractor, or the SSN of\n * a business contractor. The sign endpoint stamps this verbatim, so the form\n * both prefills it and treats it as a valid submission.\n *\n * @internal\n */\nexport const NOT_APPLICABLE_VALUE = 'N/A'\n\n/**\n * Form-field name for the synthesized federal tax classification radio group.\n *\n * @internal\n */\nexport const TAX_CLASSIFICATION_FIELD = 'taxClassification'\n\n/**\n * Form-field name for the synthesized LLC tax classification code select.\n *\n * @internal\n */\nexport const LLC_CLASSIFICATION_FIELD = 'llcClassificationCode'\n\n/**\n * Form-field name for the \"Other\" free-text classification field.\n *\n * @internal\n */\nexport const OTHER_TEXT_FIELD = 'otherText'\n\n/**\n * Ordered classification option keys backing the {@link TAX_CLASSIFICATION_FIELD}\n * radio group. Each maps to a W-9 checkbox field on the underlying document.\n *\n * @internal\n */\nexport const TAX_CLASSIFICATION_OPTION_KEYS = [\n 'individual_proprietor',\n 'c_corporation',\n 's_corporation',\n 'partnership',\n 'trust_estate',\n 'limited_liability_company',\n 'other',\n] as const\n\n/**\n * A single federal tax classification option key.\n *\n * @internal\n */\nexport type TaxClassificationOptionKey = (typeof TAX_CLASSIFICATION_OPTION_KEYS)[number]\n\n/**\n * The classification option that reveals the LLC tax classification select.\n *\n * @internal\n */\nexport const LLC_CLASSIFICATION_OPTION: TaxClassificationOptionKey = 'limited_liability_company'\n\n/**\n * The classification option that reveals the \"Other\" free-text field.\n *\n * @internal\n */\nexport const OTHER_CLASSIFICATION_OPTION: TaxClassificationOptionKey = 'other'\n\n/**\n * Ordered LLC tax classification code options.\n *\n * @internal\n */\nexport const LLC_CLASSIFICATION_CODES = ['c', 's', 'p'] as const\n\n/**\n * Maps each pass-through {@link ContractorSignatureFormData} field to its W-9\n * API field key. Synthesized fields (`taxClassification`,\n * `llcClassificationCode`) and `agree` are intentionally absent.\n *\n * @internal\n */\nexport const W9_FIELD_API_KEYS = {\n name: 'name',\n businessName: 'business_name',\n otherText: 'other_text',\n foreignPartners: 'foreign_partners',\n exemptPayeeCode: 'exempt_payee_code',\n exemptionFromFatca: 'exemption_from_FATCA',\n homeAddressStreet1: 'home_address_street_1',\n homeAddressStreet2: 'home_address_street_2',\n homeAddressCity: 'home_address_city',\n homeAddressState: 'home_address_state',\n homeAddressZip: 'home_address_zip',\n accountNumber: 'account_number',\n companyName: 'company_name',\n ssn: 'ssn',\n ein: 'ein',\n signatureText: 'signature_text',\n} as const satisfies Record<string, string>\n\n/** A pass-through W-9 field name (one with a single backing API key). */\ntype PassThroughFieldName = keyof typeof W9_FIELD_API_KEYS\n\n/** API field keys whose values are sensitive and arrive masked when on file. */\nconst SENSITIVE_FIELD_KEYS = new Set(['ssn', 'ein'])\n\n/** Whether a value is a server-side mask (e.g. `XXX-XX-1111`) rather than real input. */\nfunction isMaskedValue(value: string | null | undefined): boolean {\n return typeof value === 'string' && /[X•*]/.test(value)\n}\n\n/** Whether a document field carries a redacted (masked) sensitive value. */\nfunction hasRedactedValue(field: DocumentField | undefined): boolean {\n if (!field) return false\n const isSensitive =\n SENSITIVE_FIELD_KEYS.has(field.key ?? '') ||\n field.dataType === 'ssn' ||\n field.dataType === 'ein'\n return isSensitive && isMaskedValue(field.value)\n}\n\nfunction indexFields(document: Document): Map<string, DocumentField> {\n const byKey = new Map<string, DocumentField>()\n for (const field of document.fields ?? []) {\n if (field.key) byKey.set(field.key, field)\n }\n return byKey\n}\n\n/** Coerces an API checkbox value (`'1'`, `'true'`) to a boolean. */\nfunction toBoolean(value: string | null | undefined): boolean {\n return value === '1' || value === 'true'\n}\n\n/**\n * Whether the document is a W-9 (the only signable contractor document type).\n *\n * @internal\n */\nexport function isW9Document(document: Document): boolean {\n return document.name === W9_DOCUMENT_NAME\n}\n\n/**\n * Redaction state for the sensitive W-9 fields, derived from the API response.\n *\n * @internal\n */\nexport interface W9RedactionState {\n /** Whether the API returned a masked SSN value. */\n ssnRedacted: boolean\n /** Whether the API returned a masked EIN value. */\n einRedacted: boolean\n /** The masked SSN to surface as a placeholder, when redacted. */\n ssnPlaceholder?: string\n /** The masked EIN to surface as a placeholder, when redacted. */\n einPlaceholder?: string\n}\n\n/**\n * Computes the redaction state of the SSN/EIN fields from the document.\n *\n * @param document - The W-9 document returned by the API.\n * @returns The redaction flags and masked placeholders.\n * @internal\n */\nexport function getRedactionState(document: Document): W9RedactionState {\n const byKey = indexFields(document)\n const ssnField = byKey.get('ssn')\n const einField = byKey.get('ein')\n const ssnRedacted = hasRedactedValue(ssnField)\n const einRedacted = hasRedactedValue(einField)\n return {\n ssnRedacted,\n einRedacted,\n ssnPlaceholder: ssnRedacted ? (ssnField?.value ?? undefined) : undefined,\n einPlaceholder: einRedacted ? (einField?.value ?? undefined) : undefined,\n }\n}\n\n/**\n * Computes which W-9 form fields the API actually returned — the safety check\n * that drives presence-gating in {@link useContractorSignatureForm}.\n *\n * @remarks\n * A pass-through field is present when its API key is in `document.fields`. The\n * synthesized classification fields (`taxClassification`,\n * `llcClassificationCode`) are present when the document carries any of the\n * federal tax classification checkbox fields.\n *\n * @param document - The W-9 document returned by the API.\n * @returns The set of present camelCase field names.\n * @internal\n */\nexport function getPresentFieldNames(document: Document): Set<string> {\n const byKey = indexFields(document)\n const presentFieldNames = new Set<string>()\n\n for (const [fieldName, apiKey] of Object.entries(W9_FIELD_API_KEYS)) {\n if (byKey.has(apiKey)) presentFieldNames.add(fieldName)\n }\n\n const hasClassification = TAX_CLASSIFICATION_OPTION_KEYS.some(key => byKey.has(key))\n if (hasClassification) {\n presentFieldNames.add(TAX_CLASSIFICATION_FIELD)\n presentFieldNames.add(LLC_CLASSIFICATION_FIELD)\n }\n\n return presentFieldNames\n}\n\n/**\n * Builds default form values from a document's fields.\n *\n * @remarks\n * Pass-through values are seeded from the API `value`. The classification radio\n * defaults to whichever classification checkbox is already set (`'1'`/`'true'`),\n * and when that is the LLC classification the LLC code select is seeded from the\n * `tax_classification` field it serializes into. A masked SSN/EIN seeds an empty\n * input (the mask is surfaced as a placeholder instead) so it is never echoed\n * back as the new value on submit.\n *\n * @param document - The W-9 document returned by the API.\n * @returns The default form values.\n * @internal\n */\nexport function buildW9Defaults(document: Document): ContractorSignatureFormData {\n const byKey = indexFields(document)\n const redaction = getRedactionState(document)\n const textValue = (apiKey: string): string => byKey.get(apiKey)?.value ?? ''\n const selectedClassification =\n TAX_CLASSIFICATION_OPTION_KEYS.find(key => toBoolean(byKey.get(key)?.value)) ?? ''\n\n return {\n name: textValue('name'),\n businessName: textValue('business_name'),\n taxClassification: selectedClassification,\n // The LLC code serializes into the `tax_classification` field, so seed it\n // back from there when the LLC classification is the selected one.\n llcClassificationCode:\n selectedClassification === LLC_CLASSIFICATION_OPTION ? textValue('tax_classification') : '',\n otherText: textValue('other_text'),\n foreignPartners: toBoolean(byKey.get('foreign_partners')?.value),\n exemptPayeeCode: textValue('exempt_payee_code'),\n exemptionFromFatca: textValue('exemption_from_FATCA'),\n homeAddressStreet1: textValue('home_address_street_1'),\n homeAddressStreet2: textValue('home_address_street_2'),\n homeAddressCity: textValue('home_address_city'),\n homeAddressState: textValue('home_address_state'),\n homeAddressZip: textValue('home_address_zip'),\n accountNumber: textValue('account_number'),\n companyName: textValue('company_name'),\n ssn: redaction.ssnRedacted ? '' : textValue('ssn'),\n ein: redaction.einRedacted ? '' : textValue('ein'),\n signatureText: textValue('signature_text'),\n agree: false,\n }\n}\n\n/**\n * The empty default form values, used while the document is still loading.\n *\n * @internal\n */\nexport const EMPTY_W9_DEFAULTS: ContractorSignatureFormData = {\n name: '',\n businessName: '',\n taxClassification: '',\n llcClassificationCode: '',\n otherText: '',\n foreignPartners: false,\n exemptPayeeCode: '',\n exemptionFromFatca: '',\n homeAddressStreet1: '',\n homeAddressStreet2: '',\n homeAddressCity: '',\n homeAddressState: '',\n homeAddressZip: '',\n accountNumber: '',\n companyName: '',\n ssn: '',\n ein: '',\n signatureText: '',\n agree: false,\n}\n\n/**\n * A single `{ key, value }` pair sent in the sign request.\n *\n * @internal\n */\nexport interface SignFieldValue {\n /** The API field key. */\n key: string\n /** The serialized field value. */\n value: string\n}\n\n/** Pass-through text fields serialized verbatim (everything except the checkbox and TIN fields). */\nconst TEXT_PASS_THROUGH_FIELDS: PassThroughFieldName[] = [\n 'name',\n 'businessName',\n 'exemptPayeeCode',\n 'exemptionFromFatca',\n 'homeAddressStreet1',\n 'homeAddressStreet2',\n 'homeAddressCity',\n 'homeAddressState',\n 'homeAddressZip',\n 'accountNumber',\n 'companyName',\n 'signatureText',\n]\n\n/**\n * Serializes W-9 form values into the `{ key, value }` field array expected by\n * the sign API.\n *\n * @remarks\n * Only fields the API returned (see {@link getPresentFieldNames}) are sent.\n * Applies the W-9 mapping: the chosen classification key is sent with value\n * `'1'`; when the LLC classification is chosen, the selected LLC code is sent\n * under the `tax_classification` key. `foreignPartners` serializes to\n * `'1'`/`'0'`. The `otherText` value is only included for the \"Other\"\n * classification. An untouched redacted SSN/EIN is omitted so the mask is never\n * sent back. The `date` field is intentionally omitted so the API auto-fills the\n * signing date in its own locale-correct format.\n *\n * @param document - The W-9 document being signed.\n * @param values - The validated form values.\n * @param redaction - The redaction state from {@link getRedactionState}.\n * @returns The ordered field array for the sign request body.\n * @internal\n */\nexport function serializeW9Fields(\n document: Document,\n values: ContractorSignatureFormData,\n redaction: W9RedactionState,\n): SignFieldValue[] {\n const presentFieldNames = getPresentFieldNames(document)\n const fields: SignFieldValue[] = []\n // The schema preprocesses empty inputs to `undefined`, so read through an\n // `unknown` view and coalesce missing values to an empty string.\n const raw = values as Record<string, unknown>\n const text = (name: string): string => {\n const value = raw[name]\n return typeof value === 'string' ? value : ''\n }\n const classification = text('taxClassification')\n\n const pushField = (fieldName: PassThroughFieldName, value: string) => {\n fields.push({ key: W9_FIELD_API_KEYS[fieldName], value })\n }\n\n for (const fieldName of TEXT_PASS_THROUGH_FIELDS) {\n if (!presentFieldNames.has(fieldName)) continue\n pushField(fieldName, text(fieldName))\n }\n\n if (presentFieldNames.has(OTHER_TEXT_FIELD) && classification === OTHER_CLASSIFICATION_OPTION) {\n pushField('otherText', text('otherText'))\n }\n\n if (presentFieldNames.has('foreignPartners')) {\n fields.push({\n key: W9_FIELD_API_KEYS.foreignPartners,\n value: values.foreignPartners ? '1' : '0',\n })\n }\n\n // A redacted field left untouched is omitted so the masked value isn't sent\n // back as a replacement; the server keeps the value already on file.\n const ssnValue = text('ssn')\n const einValue = text('ein')\n if (presentFieldNames.has('ssn') && !(redaction.ssnRedacted && ssnValue === '')) {\n pushField('ssn', ssnValue)\n }\n if (presentFieldNames.has('ein') && !(redaction.einRedacted && einValue === '')) {\n pushField('ein', einValue)\n }\n\n if (classification) {\n fields.push({ key: classification, value: '1' })\n if (classification === LLC_CLASSIFICATION_OPTION) {\n fields.push({ key: 'tax_classification', value: text('llcClassificationCode') })\n }\n }\n\n return fields\n}\n"],"names":["W9_DOCUMENT_NAME","NOT_APPLICABLE_VALUE","TAX_CLASSIFICATION_FIELD","LLC_CLASSIFICATION_FIELD","OTHER_TEXT_FIELD","TAX_CLASSIFICATION_OPTION_KEYS","LLC_CLASSIFICATION_OPTION","OTHER_CLASSIFICATION_OPTION","LLC_CLASSIFICATION_CODES","W9_FIELD_API_KEYS","SENSITIVE_FIELD_KEYS","isMaskedValue","value","hasRedactedValue","field","indexFields","document","byKey","toBoolean","isW9Document","getRedactionState","ssnField","einField","ssnRedacted","einRedacted","getPresentFieldNames","presentFieldNames","fieldName","apiKey","key","buildW9Defaults","redaction","textValue","selectedClassification","EMPTY_W9_DEFAULTS","TEXT_PASS_THROUGH_FIELDS","serializeW9Fields","values","fields","raw","text","name","classification","pushField","ssnValue","einValue"],"mappings":"AAYO,MAAMA,IAAmB,oCAUnBC,IAAuB,OAOvBC,IAA2B,qBAO3BC,IAA2B,yBAO3BC,IAAmB,aAQnBC,IAAiC;AAAA,EAC5C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAcaC,IAAwD,6BAOxDC,IAA0D,SAO1DC,IAA2B,CAAC,KAAK,KAAK,GAAG,GASzCC,IAAoB;AAAA,EAC/B,MAAM;AAAA,EACN,cAAc;AAAA,EACd,WAAW;AAAA,EACX,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,iBAAiB;AAAA,EACjB,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB,eAAe;AAAA,EACf,aAAa;AAAA,EACb,KAAK;AAAA,EACL,KAAK;AAAA,EACL,eAAe;AACjB,GAMMC,IAAuB,oBAAI,IAAI,CAAC,OAAO,KAAK,CAAC;AAGnD,SAASC,EAAcC,GAA2C;AAChE,SAAO,OAAOA,KAAU,YAAY,QAAQ,KAAKA,CAAK;AACxD;AAGA,SAASC,EAAiBC,GAA2C;AACnE,SAAKA,KAEHJ,EAAqB,IAAII,EAAM,OAAO,EAAE,KACxCA,EAAM,aAAa,SACnBA,EAAM,aAAa,UACCH,EAAcG,EAAM,KAAK,IAL5B;AAMrB;AAEA,SAASC,EAAYC,GAAgD;AACnE,QAAMC,wBAAY,IAAA;AAClB,aAAWH,KAASE,EAAS,UAAU,CAAA;AACrC,IAAIF,EAAM,OAAKG,EAAM,IAAIH,EAAM,KAAKA,CAAK;AAE3C,SAAOG;AACT;AAGA,SAASC,EAAUN,GAA2C;AAC5D,SAAOA,MAAU,OAAOA,MAAU;AACpC;AAOO,SAASO,EAAaH,GAA6B;AACxD,SAAOA,EAAS,SAAShB;AAC3B;AAyBO,SAASo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7C,GACM8B,IAAiBF,EAAK,mBAAmB,GAEzCG,IAAY,CAAChB,GAAiCf,MAAkB;AACpE,IAAA0B,EAAO,KAAK,EAAE,KAAK7B,EAAkBkB,CAAS,GAAG,OAAAf,GAAO;AAAA,EAC1D;AAEA,aAAWe,KAAaQ;AACtB,IAAKT,EAAkB,IAAIC,CAAS,KACpCgB,EAAUhB,GAAWa,EAAKb,CAAS,CAAC;AAGtC,EAAID,EAAkB,IAAItB,CAAgB,KAAKsC,MAAmBnC,KAChEoC,EAAU,aAAaH,EAAK,WAAW,CAAC,GAGtCd,EAAkB,IAAI,iBAAiB,KACzCY,EAAO,KAAK;AAAA,IACV,KAAK7B,EAAkB;AAAA,IACvB,OAAO4B,EAAO,kBAAkB,MAAM;AAAA,EAAA,CACvC;AAKH,QAAMO,IAAWJ,EAAK,KAAK,GACrBK,IAAWL,EAAK,KAAK;AAC3B,SAAId,EAAkB,IAAI,KAAK,KAAK,EAAEK,EAAU,eAAea,MAAa,OAC1ED,EAAU,OAAOC,CAAQ,GAEvBlB,EAAkB,IAAI,KAAK,KAAK,EAAEK,EAAU,eAAec,MAAa,OAC1EF,EAAU,OAAOE,CAAQ,GAGvBH,MACFJ,EAAO,KAAK,EAAE,KAAKI,GAAgB,OAAO,KAAK,GAC3CA,MAAmBpC,KACrBgC,EAAO,KAAK,EAAE,KAAK,sBAAsB,OAAOE,EAAK,uBAAuB,GAAG,IAI5EF;AACT;"}
|
package/dist/components/Contractor/PaymentMethod/shared/useContractorBankAccountForm/fields.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as n } from "react/jsx-runtime";
|
|
2
|
-
import { RadioGroupHookField as r } from "../../../../../partner-hook-utils/form/fields/RadioGroupHookField.js";
|
|
3
2
|
import { TextInputHookField as o } from "../../../../../partner-hook-utils/form/fields/TextInputHookField.js";
|
|
3
|
+
import { RadioGroupHookField as r } from "../../../../../partner-hook-utils/form/fields/RadioGroupHookField.js";
|
|
4
4
|
function m(e) {
|
|
5
5
|
return /* @__PURE__ */ n(o, { ...e, name: "name" });
|
|
6
6
|
}
|
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
import { jsx as t, jsxs as
|
|
2
|
-
import { useMemo as
|
|
3
|
-
import { useTranslation as
|
|
4
|
-
import { useWatch as
|
|
5
|
-
import
|
|
6
|
-
import { useContractorDetailsForm as
|
|
1
|
+
import { jsx as t, jsxs as d, Fragment as E } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo as N, useState as v, useEffect as O } from "react";
|
|
3
|
+
import { useTranslation as I } from "react-i18next";
|
|
4
|
+
import { useWatch as S } from "react-hook-form";
|
|
5
|
+
import y from "classnames";
|
|
6
|
+
import { useContractorDetailsForm as A } from "./shared/useContractorDetailsForm/useContractorDetailsForm.js";
|
|
7
7
|
import { ContractorType as F } from "./shared/useContractorDetailsForm/contractorDetailsSchema.js";
|
|
8
|
-
import { SelfOnboardingContractorProfile as
|
|
9
|
-
import
|
|
10
|
-
import { BaseBoundaries as
|
|
8
|
+
import { SelfOnboardingContractorProfile as T } from "./SelfOnboardingContractorProfile.js";
|
|
9
|
+
import M from "./ContractorProfile.module.scss.js";
|
|
10
|
+
import { BaseBoundaries as P, BaseLayout as h } from "../../Base/Base.js";
|
|
11
11
|
import "../../Base/useBase.js";
|
|
12
12
|
import { SDKFormProvider as L } from "../../../partner-hook-utils/form/SDKFormProvider.js";
|
|
13
|
-
import { Form as
|
|
13
|
+
import { Form as _ } from "../../Common/Form/Form.js";
|
|
14
14
|
import { Flex as c } from "../../Common/Flex/Flex.js";
|
|
15
15
|
import { Grid as R } from "../../Common/Grid/Grid.js";
|
|
16
|
-
import { useComponentContext as
|
|
16
|
+
import { useComponentContext as D } from "../../../contexts/ComponentAdapter/useComponentContext.js";
|
|
17
17
|
import { useComponentDictionary as x, useI18n as B } from "../../../i18n/I18n.js";
|
|
18
18
|
import { ContractorOnboardingStatus as b, componentEvents as g } from "../../../shared/constants.js";
|
|
19
|
-
|
|
19
|
+
import { useContractorHasSignedW9 as W } from "../shared/useContractorHasSignedW9.js";
|
|
20
|
+
function w(a) {
|
|
20
21
|
return a?.onboarded === !0 || a?.onboardingStatus === b.ONBOARDING_COMPLETED || a?.onboardingStatus === b.SELF_ONBOARDING_REVIEW || a?.onboardingStatus === b.ADMIN_ONBOARDING_REVIEW;
|
|
21
22
|
}
|
|
22
|
-
function
|
|
23
|
+
function U(a) {
|
|
23
24
|
const n = {
|
|
24
25
|
create: [],
|
|
25
26
|
update: ["firstName", "lastName", "businessName", "hourlyRate", "workState"]
|
|
@@ -29,50 +30,54 @@ function Q(a) {
|
|
|
29
30
|
update: [...n.update ?? [], "ssn", "ein"]
|
|
30
31
|
};
|
|
31
32
|
}
|
|
32
|
-
function
|
|
33
|
-
return x("Contractor.Profile", a.dictionary), /* @__PURE__ */ t(
|
|
34
|
-
|
|
33
|
+
function le(a) {
|
|
34
|
+
return x("Contractor.Profile", a.dictionary), /* @__PURE__ */ t(P, { componentName: "Contractor.Profile", FallbackComponent: a.FallbackComponent, children: a.isAdmin === !1 ? /* @__PURE__ */ t(
|
|
35
|
+
T,
|
|
35
36
|
{
|
|
36
37
|
contractorId: a.contractorId,
|
|
37
38
|
onEvent: a.onEvent,
|
|
38
39
|
className: a.className
|
|
39
40
|
}
|
|
40
|
-
) : /* @__PURE__ */ t(
|
|
41
|
+
) : /* @__PURE__ */ t(Q, { ...a }) });
|
|
42
|
+
}
|
|
43
|
+
function V({ contractorId: a }) {
|
|
44
|
+
const n = W(a), { t: r } = I("Contractor.Profile"), s = D();
|
|
45
|
+
return n ? /* @__PURE__ */ t(s.Alert, { status: "warning", disableScrollIntoView: !0, label: r("w9EditWarning.label"), children: /* @__PURE__ */ t(s.Text, { children: r("w9EditWarning.body") }) }) : null;
|
|
41
46
|
}
|
|
42
|
-
function
|
|
47
|
+
function Q({
|
|
43
48
|
companyId: a,
|
|
44
49
|
contractorId: n,
|
|
45
|
-
defaultValues:
|
|
46
|
-
className:
|
|
50
|
+
defaultValues: r,
|
|
51
|
+
className: s,
|
|
47
52
|
onEvent: e
|
|
48
53
|
}) {
|
|
49
54
|
B("Contractor.Profile");
|
|
50
|
-
const o =
|
|
51
|
-
() => ({ type: F.Business, ...
|
|
52
|
-
[
|
|
53
|
-
), [
|
|
55
|
+
const o = N(
|
|
56
|
+
() => ({ type: F.Business, ...r }),
|
|
57
|
+
[r]
|
|
58
|
+
), [l, i] = v(
|
|
54
59
|
!n && (o.selfOnboarding ?? !1)
|
|
55
|
-
),
|
|
56
|
-
() =>
|
|
57
|
-
[
|
|
58
|
-
),
|
|
60
|
+
), m = N(
|
|
61
|
+
() => U(l),
|
|
62
|
+
[l]
|
|
63
|
+
), u = A(
|
|
59
64
|
n ? {
|
|
60
65
|
companyId: a,
|
|
61
66
|
contractorId: n,
|
|
62
67
|
defaultValues: o,
|
|
63
|
-
optionalFieldsToRequire:
|
|
68
|
+
optionalFieldsToRequire: m
|
|
64
69
|
} : {
|
|
65
70
|
companyId: a,
|
|
66
71
|
defaultValues: o,
|
|
67
|
-
optionalFieldsToRequire:
|
|
72
|
+
optionalFieldsToRequire: m
|
|
68
73
|
}
|
|
69
74
|
);
|
|
70
|
-
return
|
|
75
|
+
return u.isLoading ? /* @__PURE__ */ t(h, { isLoading: !0, error: u.errorHandling.errors }) : /* @__PURE__ */ t(
|
|
71
76
|
H,
|
|
72
77
|
{
|
|
73
|
-
contractor:
|
|
78
|
+
contractor: u,
|
|
74
79
|
onEvent: e,
|
|
75
|
-
className:
|
|
80
|
+
className: s,
|
|
76
81
|
setSelfOnboardingActive: i
|
|
77
82
|
}
|
|
78
83
|
);
|
|
@@ -80,36 +85,37 @@ function V({
|
|
|
80
85
|
function H({
|
|
81
86
|
contractor: a,
|
|
82
87
|
onEvent: n,
|
|
83
|
-
className:
|
|
84
|
-
setSelfOnboardingActive:
|
|
88
|
+
className: r,
|
|
89
|
+
setSelfOnboardingActive: s
|
|
85
90
|
}) {
|
|
86
|
-
const { t: e } =
|
|
91
|
+
const { t: e } = I("Contractor.Profile"), o = D(), l = S({
|
|
87
92
|
control: a.form.hookFormInternals.formMethods.control,
|
|
88
93
|
name: "selfOnboarding"
|
|
89
94
|
});
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}, [
|
|
93
|
-
const { Fields: i } = a.form,
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
O(() => {
|
|
96
|
+
s(l);
|
|
97
|
+
}, [l, s]);
|
|
98
|
+
const { Fields: i } = a.form, m = a.status.mode, u = w(a.data.contractor), p = !l || u, C = async () => {
|
|
99
|
+
const f = await a.actions.onSubmit();
|
|
100
|
+
f && (n(
|
|
101
|
+
f.mode === "create" ? g.CONTRACTOR_CREATED : g.CONTRACTOR_UPDATED,
|
|
102
|
+
f.data
|
|
98
103
|
), n(g.CONTRACTOR_PROFILE_DONE, {
|
|
99
|
-
contractorId:
|
|
100
|
-
onboardingStatus:
|
|
101
|
-
selfOnboarding:
|
|
104
|
+
contractorId: f.data.uuid,
|
|
105
|
+
onboardingStatus: f.data.onboardingStatus,
|
|
106
|
+
selfOnboarding: l && !u
|
|
102
107
|
}));
|
|
103
108
|
};
|
|
104
|
-
return /* @__PURE__ */ t("section", { className:
|
|
105
|
-
|
|
109
|
+
return /* @__PURE__ */ t("section", { className: y(M.root, r), children: /* @__PURE__ */ t(h, { error: a.errorHandling.errors, children: /* @__PURE__ */ t(L, { formHookResult: a, children: /* @__PURE__ */ d(_, { onSubmit: () => {
|
|
110
|
+
C();
|
|
106
111
|
}, children: [
|
|
107
|
-
/* @__PURE__ */
|
|
108
|
-
|
|
112
|
+
/* @__PURE__ */ d(c, { flexDirection: "column", gap: 20, alignItems: "stretch", children: [
|
|
113
|
+
m === "update" && a.data.contractor?.uuid && /* @__PURE__ */ t(V, { contractorId: a.data.contractor.uuid }),
|
|
114
|
+
/* @__PURE__ */ t("header", { children: /* @__PURE__ */ d(c, { flexDirection: "column", gap: 4, children: [
|
|
109
115
|
/* @__PURE__ */ t(o.Heading, { as: "h2", children: e("title") }),
|
|
110
116
|
/* @__PURE__ */ t(o.Text, { variant: "supporting", children: e("subtitle") })
|
|
111
117
|
] }) }),
|
|
112
|
-
(i.SelfOnboarding || i.Email) && /* @__PURE__ */ t(o.Box, { children: /* @__PURE__ */
|
|
118
|
+
(i.SelfOnboarding || i.Email) && /* @__PURE__ */ t(o.Box, { children: /* @__PURE__ */ d(R, { gap: 16, children: [
|
|
113
119
|
i.SelfOnboarding && /* @__PURE__ */ t(
|
|
114
120
|
i.SelfOnboarding,
|
|
115
121
|
{
|
|
@@ -129,8 +135,8 @@ function H({
|
|
|
129
135
|
)
|
|
130
136
|
] }) }),
|
|
131
137
|
/* @__PURE__ */ t(i.Type, { label: e("fields.contractorType.label") }),
|
|
132
|
-
i.FirstName && i.LastName && /* @__PURE__ */
|
|
133
|
-
/* @__PURE__ */
|
|
138
|
+
i.FirstName && i.LastName && /* @__PURE__ */ d(E, { children: [
|
|
139
|
+
/* @__PURE__ */ d(R, { gridTemplateColumns: { base: "1fr", medium: "1fr 1fr" }, gap: 16, children: [
|
|
134
140
|
/* @__PURE__ */ t(
|
|
135
141
|
i.FirstName,
|
|
136
142
|
{
|
|
@@ -164,7 +170,7 @@ function H({
|
|
|
164
170
|
}
|
|
165
171
|
)
|
|
166
172
|
] }),
|
|
167
|
-
i.BusinessName && /* @__PURE__ */
|
|
173
|
+
i.BusinessName && /* @__PURE__ */ d(E, { children: [
|
|
168
174
|
/* @__PURE__ */ t(
|
|
169
175
|
i.BusinessName,
|
|
170
176
|
{
|
|
@@ -208,12 +214,12 @@ function H({
|
|
|
208
214
|
type: "submit",
|
|
209
215
|
variant: "primary",
|
|
210
216
|
isDisabled: a.status.isPending,
|
|
211
|
-
children: a.status.isPending ? e(
|
|
217
|
+
children: a.status.isPending ? e(m === "create" ? "buttons.creating" : "buttons.updating") : e(m === "create" ? "buttons.create" : "buttons.update")
|
|
212
218
|
}
|
|
213
219
|
) })
|
|
214
220
|
] }) }) }) });
|
|
215
221
|
}
|
|
216
222
|
export {
|
|
217
|
-
|
|
223
|
+
le as ContractorProfile
|
|
218
224
|
};
|
|
219
225
|
//# sourceMappingURL=ContractorProfile.js.map
|