diff --git a/example/src/Onboarding.tsx b/example/src/Onboarding.tsx index 67b53e78..8c7b3e96 100644 --- a/example/src/Onboarding.tsx +++ b/example/src/Onboarding.tsx @@ -263,6 +263,13 @@ const OnboardingWithProps = ({ render={OnBoardingRender} employmentId={employmentId} externalId={externalId} + options={{ + jsonSchemaVersionByCountry: { + DEU: { + contract_details: 1, + }, + }, + }} /> ); diff --git a/src/client/sdk.gen.ts b/src/client/sdk.gen.ts index 2e72b5bc..39e7a6df 100644 --- a/src/client/sdk.gen.ts +++ b/src/client/sdk.gen.ts @@ -53,9 +53,15 @@ import type { GetGetBreakdownBillingDocumentData, GetGetBreakdownBillingDocumentErrors, GetGetBreakdownBillingDocumentResponses, + GetGetGroupScimData, + GetGetGroupScimErrors, + GetGetGroupScimResponses, GetGetIdentityVerificationDataIdentityVerificationData, GetGetIdentityVerificationDataIdentityVerificationErrors, GetGetIdentityVerificationDataIdentityVerificationResponses, + GetGetUserScimData, + GetGetUserScimErrors, + GetGetUserScimResponses, GetIndexBenefitOfferData, GetIndexBenefitOfferErrors, GetIndexBenefitOfferResponses, @@ -190,6 +196,12 @@ import type { GetIndexWorkAuthorizationRequestData, GetIndexWorkAuthorizationRequestErrors, GetIndexWorkAuthorizationRequestResponses, + GetListGroupsScimData, + GetListGroupsScimErrors, + GetListGroupsScimResponses, + GetListUsersScimData, + GetListUsersScimErrors, + GetListUsersScimResponses, GetPendingChangesEmploymentContractData, GetPendingChangesEmploymentContractErrors, GetPendingChangesEmploymentContractResponses, @@ -2960,6 +2972,24 @@ export const postDeclineCancellationRequest = < }, }); +/** + * Get group by ID via SCIM v2.0 + * + * Retrieves a single group (department) for the authenticated company by group ID + */ +export const getGetGroupScim = ( + options: Options, +) => + (options.client ?? client).get< + GetGetGroupScimResponses, + GetGetGroupScimErrors, + ThrowOnError + >({ + security: [{ scheme: 'bearer', type: 'http' }], + url: '/scim/v2/Groups/{id}', + ...options, + }); + /** * Get a employment benefit offers JSON schema */ @@ -3097,6 +3127,8 @@ export const getShowEmployment = ( * * To update a Global Payment employment your input data must comply with the global payroll json schemas. * + * **For `active` employments:** In addition to the above list, you can update personal_details. + * * ## Direct Employees * * To update an HRIS employment your input data must comply with the HRIS json schemas. @@ -3163,6 +3195,8 @@ export const patchUpdateEmployment2 = ( * * To update a Global Payment employment your input data must comply with the global payroll json schemas. * + * **For `active` employments:** In addition to the above list, you can update personal_details. + * * ## Direct Employees * * To update an HRIS employment your input data must comply with the HRIS json schemas. @@ -3618,6 +3652,24 @@ export const postConvertWithSpreadCurrencyConverter = < }, }); +/** + * List users via SCIM v2.0 + * + * Retrieves a list of users for the authenticated company following SCIM 2.0 standard + */ +export const getListUsersScim = ( + options?: Options, +) => + (options?.client ?? client).get< + GetListUsersScimResponses, + GetListUsersScimErrors, + ThrowOnError + >({ + security: [{ scheme: 'bearer', type: 'http' }], + url: '/scim/v2/Users', + ...options, + }); + /** * Show Time Off * @@ -4644,6 +4696,24 @@ export const postCreateEmployeeTimeoff = ( }, }); +/** + * List groups via SCIM v2.0 + * + * Retrieves a list of groups (departments) for the authenticated company following SCIM 2.0 standard + */ +export const getListGroupsScim = ( + options?: Options, +) => + (options?.client ?? client).get< + GetListGroupsScimResponses, + GetListGroupsScimErrors, + ThrowOnError + >({ + security: [{ scheme: 'bearer', type: 'http' }], + url: '/scim/v2/Groups', + ...options, + }); + /** * Show Probation Extension * @@ -5191,6 +5261,24 @@ export const postApproveCancellationRequest = < ...options, }); +/** + * Get user by ID via SCIM v2.0 + * + * Retrieves a single user for the authenticated company by user ID + */ +export const getGetUserScim = ( + options: Options, +) => + (options.client ?? client).get< + GetGetUserScimResponses, + GetGetUserScimErrors, + ThrowOnError + >({ + security: [{ scheme: 'bearer', type: 'http' }], + url: '/scim/v2/Users/{id}', + ...options, + }); + /** * Verify Employment Identity * diff --git a/src/client/types.gen.ts b/src/client/types.gen.ts index f6be2168..94da64f9 100644 --- a/src/client/types.gen.ts +++ b/src/client/types.gen.ts @@ -246,6 +246,55 @@ export type ResignationResponse = { data?: Resignation; }; +/** + * Integrations.Scim.Group + */ +export type IntegrationsScimGroup = { + /** + * Display name of the group + */ + displayName: string; + /** + * Unique identifier for the group + */ + id: string; + /** + * Array of group members (per RFC 7643) + */ + members: Array<{ + /** + * URI of the user resource + */ + $ref?: string; + /** + * Display name of the user + */ + display?: string; + /** + * User ID (slug) + */ + value: string; + }>; + meta?: { + /** + * Creation timestamp + */ + created?: string; + /** + * Last modification timestamp + */ + lastModified?: string; + /** + * Resource type + */ + resourceType?: string; + }; + /** + * SCIM schema identifiers + */ + schemas: Array; +}; + /** * ConvertCurrency * @@ -1492,6 +1541,32 @@ export type ListDataSyncEventsResponse = { }; }; +/** + * Integrations.Scim.GroupListResponse + */ +export type IntegrationsScimGroupListResponse = { + /** + * Array of group resources + */ + Resources: Array; + /** + * Number of results returned in the current set + */ + itemsPerPage: number; + /** + * SCIM schema identifiers + */ + schemas: Array; + /** + * 1-based index of the first result in the current set + */ + startIndex: number; + /** + * Total number of results matching the query + */ + totalResults: number; +}; + /** * Country * @@ -7059,6 +7134,95 @@ export type ParameterError = { */ export type Actions = Array; +/** + * Integrations.Scim.User + */ +export type IntegrationsScimUser = { + /** + * Whether the user is active + */ + active: boolean; + /** + * Identifies the name of a department (Enterprise User extension) + */ + department?: string; + emails: Array<{ + /** + * Whether this is the primary email + */ + primary?: boolean; + /** + * Type of email (e.g., 'work') + */ + type: string; + /** + * Email address + */ + value: string; + }>; + /** + * Numeric or alphanumeric identifier assigned to a person (Enterprise User extension) + */ + employeeNumber?: string; + /** + * Unique identifier for the user + */ + id: string; + /** + * The user's manager (Enterprise User extension) + */ + manager?: { + /** + * The URI of the SCIM resource representing the user's manager + */ + $ref?: string; + /** + * The displayName of the user's manager + */ + displayName?: string; + /** + * The id of the SCIM resource representing the user's manager + */ + value?: string; + }; + meta?: { + /** + * Creation timestamp + */ + created?: string; + /** + * Last modification timestamp + */ + lastModified?: string; + /** + * Resource type + */ + resourceType?: string; + }; + name: { + /** + * Last name + */ + familyName: string; + /** + * Full name + */ + formatted?: string; + /** + * First name + */ + givenName: string; + }; + /** + * SCIM schema identifiers + */ + schemas: Array; + /** + * Username for the user + */ + userName: string; +}; + /** * CreateSSOConfigurationResult */ @@ -7623,6 +7787,32 @@ export type Timeoff = { timezone: Timezone; }; +/** + * Integrations.Scim.UserListResponse + */ +export type IntegrationsScimUserListResponse = { + /** + * Array of user resources + */ + Resources: Array; + /** + * Number of results returned in the current set + */ + itemsPerPage: number; + /** + * SCIM schema identifiers + */ + schemas: Array; + /** + * 1-based index of the first result in the current set + */ + startIndex: number; + /** + * Total number of results matching the query + */ + totalResults: number; +}; + /** * ApproveTimeoffParams * @@ -8327,7 +8517,7 @@ export type GetShowContractAmendmentSchemaData = { /** * Version of the form schema */ - json_schema_version?: number; + json_schema_version?: number | 'latest'; }; url: '/v1/contract-amendments/schema'; }; @@ -8667,7 +8857,7 @@ export type GetShowContractorContractDetailsCountryData = { /** * Version of the form schema */ - json_schema_version?: number; + json_schema_version?: number | 'latest'; }; url: '/v1/countries/{country_code}/contractor-contract-details'; }; @@ -8813,7 +9003,7 @@ export type PostCreateEmployment2Data = { /** * Version of the form schema */ - json_schema_version?: number; + json_schema_version?: number | 'latest'; }; url: '/v1/employments'; }; @@ -9141,7 +9331,7 @@ export type GetShowCompanySchemaData = { /** * Version of the form schema */ - json_schema_version?: number; + json_schema_version?: number | 'latest'; }; url: '/v1/companies/schema'; }; @@ -9242,7 +9432,7 @@ export type PutUpdateBenefitOfferData = { /** * Version of the form schema */ - json_schema_version?: number; + json_schema_version?: number | 'latest'; }; url: '/v1/employments/{employment_id}/benefit-offers'; }; @@ -9486,7 +9676,7 @@ export type GetShowTestSchemaData = { /** * Version of the form schema */ - json_schema_version?: number; + json_schema_version?: number | 'latest'; }; url: '/v1/test-schema'; }; @@ -10449,7 +10639,7 @@ export type GetSchemaBenefitRenewalRequestData = { /** * Version of the form schema */ - json_schema_version?: number; + json_schema_version?: number | 'latest'; }; url: '/v1/benefit-renewal-requests/{benefit_renewal_request_id}/schema'; }; @@ -11305,11 +11495,11 @@ export type PatchUpdateCompany2Data = { /** * Version of the address_details form schema */ - address_details_json_schema_version?: number; + address_details_json_schema_version?: number | 'latest'; /** * Version of the bank_account_details form schema */ - bank_account_details_json_schema_version?: number; + bank_account_details_json_schema_version?: number | 'latest'; }; url: '/v1/companies/{company_id}'; }; @@ -11375,11 +11565,11 @@ export type PatchUpdateCompanyData = { /** * Version of the address_details form schema */ - address_details_json_schema_version?: number; + address_details_json_schema_version?: number | 'latest'; /** * Version of the bank_account_details form schema */ - bank_account_details_json_schema_version?: number; + bank_account_details_json_schema_version?: number | 'latest'; }; url: '/v1/companies/{company_id}'; }; @@ -11552,7 +11742,7 @@ export type PostCreateContractAmendmentData = { /** * Version of the form schema */ - json_schema_version?: number; + json_schema_version?: number | 'latest'; }; url: '/v1/contract-amendments'; }; @@ -12004,7 +12194,7 @@ export type GetShowFormCountryData = { /** * Version of the form schema */ - json_schema_version?: number; + json_schema_version?: number | 'latest'; }; url: '/v1/countries/{country_code}/{form}'; }; @@ -12912,6 +13102,46 @@ export type PostDeclineCancellationRequestResponses = { export type PostDeclineCancellationRequestResponse = PostDeclineCancellationRequestResponses[keyof PostDeclineCancellationRequestResponses]; +export type GetGetGroupScimData = { + body?: never; + path: { + /** + * Group ID (slug) + */ + id: string; + }; + query?: never; + url: '/scim/v2/Groups/{id}'; +}; + +export type GetGetGroupScimErrors = { + /** + * Unauthorized + */ + 401: UnauthorizedResponse; + /** + * Forbidden + */ + 403: ForbiddenResponse; + /** + * Not Found + */ + 404: NotFoundResponse; +}; + +export type GetGetGroupScimError = + GetGetGroupScimErrors[keyof GetGetGroupScimErrors]; + +export type GetGetGroupScimResponses = { + /** + * Success + */ + 200: IntegrationsScimGroup; +}; + +export type GetGetGroupScimResponse = + GetGetGroupScimResponses[keyof GetGetGroupScimResponses]; + export type GetShowSchemaData = { body?: never; path: { @@ -12924,7 +13154,7 @@ export type GetShowSchemaData = { /** * Version of the form schema */ - json_schema_version?: number; + json_schema_version?: number | 'latest'; }; url: '/v1/employments/{employment_id}/benefit-offers/schema'; }; @@ -12966,7 +13196,7 @@ export type PostCreateEligibilityQuestionnaireData = { /** * Version of the form schema */ - json_schema_version?: number; + json_schema_version?: number | 'latest'; }; url: '/v1/contractors/eligibility-questionnaire'; }; @@ -13076,7 +13306,12 @@ export type GetShowEmploymentData = { */ employment_id: string; }; - query?: never; + query?: { + /** + * Wether files should be excluded + */ + exclude_files?: boolean; + }; url: '/v1/employments/{employment_id}'; }; @@ -13140,39 +13375,39 @@ export type PatchUpdateEmployment2Data = { /** * Version of the address_details form schema */ - address_details_json_schema_version?: number; + address_details_json_schema_version?: number | 'latest'; /** * Version of the administrative_details form schema */ - administrative_details_json_schema_version?: number; + administrative_details_json_schema_version?: number | 'latest'; /** * Version of the bank_account_details form schema */ - bank_account_details_json_schema_version?: number; + bank_account_details_json_schema_version?: number | 'latest'; /** * Version of the employment_basic_information form schema */ - employment_basic_information_json_schema_version?: number; + employment_basic_information_json_schema_version?: number | 'latest'; /** * Version of the billing_address_details form schema */ - billing_address_details_json_schema_version?: number; + billing_address_details_json_schema_version?: number | 'latest'; /** * Version of the contract_details form schema */ - contract_details_json_schema_version?: number; + contract_details_json_schema_version?: number | 'latest'; /** * Version of the emergency_contact_details form schema */ - emergency_contact_details_json_schema_version?: number; + emergency_contact_details_json_schema_version?: number | 'latest'; /** * Version of the personal_details form schema */ - personal_details_json_schema_version?: number; + personal_details_json_schema_version?: number | 'latest'; /** * Version of the pricing_plan_details form schema */ - pricing_plan_details_json_schema_version?: number; + pricing_plan_details_json_schema_version?: number | 'latest'; /** * Skips the dynamic benefits part of the schema if set. To be used when benefits are set via its own API. */ @@ -13245,39 +13480,39 @@ export type PatchUpdateEmploymentData = { /** * Version of the address_details form schema */ - address_details_json_schema_version?: number; + address_details_json_schema_version?: number | 'latest'; /** * Version of the administrative_details form schema */ - administrative_details_json_schema_version?: number; + administrative_details_json_schema_version?: number | 'latest'; /** * Version of the bank_account_details form schema */ - bank_account_details_json_schema_version?: number; + bank_account_details_json_schema_version?: number | 'latest'; /** * Version of the employment_basic_information form schema */ - employment_basic_information_json_schema_version?: number; + employment_basic_information_json_schema_version?: number | 'latest'; /** * Version of the billing_address_details form schema */ - billing_address_details_json_schema_version?: number; + billing_address_details_json_schema_version?: number | 'latest'; /** * Version of the contract_details form schema */ - contract_details_json_schema_version?: number; + contract_details_json_schema_version?: number | 'latest'; /** * Version of the emergency_contact_details form schema */ - emergency_contact_details_json_schema_version?: number; + emergency_contact_details_json_schema_version?: number | 'latest'; /** * Version of the personal_details form schema */ - personal_details_json_schema_version?: number; + personal_details_json_schema_version?: number | 'latest'; /** * Version of the pricing_plan_details form schema */ - pricing_plan_details_json_schema_version?: number; + pricing_plan_details_json_schema_version?: number | 'latest'; /** * Skips the dynamic benefits part of the schema if set. To be used when benefits are set via its own API. */ @@ -14100,6 +14335,54 @@ export type PostConvertWithSpreadCurrencyConverterResponses = { export type PostConvertWithSpreadCurrencyConverterResponse = PostConvertWithSpreadCurrencyConverterResponses[keyof PostConvertWithSpreadCurrencyConverterResponses]; +export type GetListUsersScimData = { + body?: never; + path?: never; + query?: { + /** + * 1-based index of the first result + */ + startIndex?: number; + /** + * Maximum number of results per page + */ + count?: number; + /** + * Filter expression for user attributes + */ + filter?: string; + }; + url: '/scim/v2/Users'; +}; + +export type GetListUsersScimErrors = { + /** + * Unauthorized + */ + 401: UnauthorizedResponse; + /** + * Forbidden + */ + 403: ForbiddenResponse; + /** + * Not Found + */ + 404: NotFoundResponse; +}; + +export type GetListUsersScimError = + GetListUsersScimErrors[keyof GetListUsersScimErrors]; + +export type GetListUsersScimResponses = { + /** + * Success + */ + 200: IntegrationsScimUserListResponse; +}; + +export type GetListUsersScimResponse = + GetListUsersScimResponses[keyof GetListUsersScimResponses]; + export type GetShowTimeoffData = { body?: never; headers: { @@ -14347,7 +14630,7 @@ export type PostAutomatableContractAmendmentData = { /** * Version of the form schema */ - json_schema_version?: number; + json_schema_version?: number | 'latest'; }; url: '/v1/contract-amendments/automatable'; }; @@ -15165,7 +15448,7 @@ export type PostUpdateBenefitRenewalRequestData = { /** * Version of the form schema */ - json_schema_version?: number; + json_schema_version?: number | 'latest'; }; url: '/v1/benefit-renewal-requests/{benefit_renewal_request_id}'; }; @@ -15907,7 +16190,7 @@ export type GetShowEligibilityQuestionnaireData = { /** * Version of the form schema */ - json_schema_version?: number; + json_schema_version?: number | 'latest'; }; url: '/v1/contractors/schemas/eligibility-questionnaire'; }; @@ -16176,6 +16459,54 @@ export type PostCreateEmployeeTimeoffResponses = { export type PostCreateEmployeeTimeoffResponse = PostCreateEmployeeTimeoffResponses[keyof PostCreateEmployeeTimeoffResponses]; +export type GetListGroupsScimData = { + body?: never; + path?: never; + query?: { + /** + * 1-based index of the first result + */ + startIndex?: number; + /** + * Maximum number of results per page + */ + count?: number; + /** + * Filter expression for user attributes + */ + filter?: string; + }; + url: '/scim/v2/Groups'; +}; + +export type GetListGroupsScimErrors = { + /** + * Unauthorized + */ + 401: UnauthorizedResponse; + /** + * Forbidden + */ + 403: ForbiddenResponse; + /** + * Not Found + */ + 404: NotFoundResponse; +}; + +export type GetListGroupsScimError = + GetListGroupsScimErrors[keyof GetListGroupsScimErrors]; + +export type GetListGroupsScimResponses = { + /** + * Success + */ + 200: IntegrationsScimGroupListResponse; +}; + +export type GetListGroupsScimResponse = + GetListGroupsScimResponses[keyof GetListGroupsScimResponses]; + export type GetShowProbationExtensionData = { body?: never; path: { @@ -16776,11 +17107,11 @@ export type PostCreateCompanyData = { /** * Version of the address_details form schema */ - address_details_json_schema_version?: number; + address_details_json_schema_version?: number | 'latest'; /** * Version of the bank_account_details form schema */ - bank_account_details_json_schema_version?: number; + bank_account_details_json_schema_version?: number | 'latest'; /** * Complementary action(s) to perform when creating a company: * @@ -17388,6 +17719,46 @@ export type PostApproveCancellationRequestResponses = { export type PostApproveCancellationRequestResponse = PostApproveCancellationRequestResponses[keyof PostApproveCancellationRequestResponses]; +export type GetGetUserScimData = { + body?: never; + path: { + /** + * User ID (slug) + */ + id: string; + }; + query?: never; + url: '/scim/v2/Users/{id}'; +}; + +export type GetGetUserScimErrors = { + /** + * Unauthorized + */ + 401: UnauthorizedResponse; + /** + * Forbidden + */ + 403: ForbiddenResponse; + /** + * Not Found + */ + 404: NotFoundResponse; +}; + +export type GetGetUserScimError = + GetGetUserScimErrors[keyof GetGetUserScimErrors]; + +export type GetGetUserScimResponses = { + /** + * Success + */ + 200: IntegrationsScimUser; +}; + +export type GetGetUserScimResponse = + GetGetUserScimResponses[keyof GetGetUserScimResponses]; + export type PostVerifyIdentityVerificationData = { body?: never; path: { diff --git a/src/flows/Onboarding/api.ts b/src/flows/Onboarding/api.ts index f0e8198e..4287437a 100644 --- a/src/flows/Onboarding/api.ts +++ b/src/flows/Onboarding/api.ts @@ -183,7 +183,7 @@ export const useJSONSchemaForm = ({ fieldValues: FieldValues; options?: FlowOptions & { queryOptions?: { enabled?: boolean } }; query?: Record; - jsonSchemaVersion?: number; + jsonSchemaVersion?: number | 'latest'; }): UseQueryResult => { const { client } = useClient(); const jsonSchemaQueryParam = jsonSchemaVersion diff --git a/src/flows/Onboarding/hooks.tsx b/src/flows/Onboarding/hooks.tsx index 8d040c45..7f3a042e 100644 --- a/src/flows/Onboarding/hooks.tsx +++ b/src/flows/Onboarding/hooks.tsx @@ -260,7 +260,7 @@ export const useOnboarding = ({ queryOptions?: { enabled?: boolean }; }; query?: Record; - jsonSchemaVersion?: number; + jsonSchemaVersion?: number | 'latest'; }) => { const hasUserEnteredAnyValues = Object.keys(fieldValues).length > 0; // when you write on the fields, the values are stored in the fieldValues state diff --git a/src/flows/Onboarding/tests/useOnboardingJsonSchemaVersion.test.tsx b/src/flows/Onboarding/tests/useOnboardingJsonSchemaVersion.test.tsx index b21b6c88..f872eb77 100644 --- a/src/flows/Onboarding/tests/useOnboardingJsonSchemaVersion.test.tsx +++ b/src/flows/Onboarding/tests/useOnboardingJsonSchemaVersion.test.tsx @@ -156,7 +156,7 @@ describe('useOnboarding jsonSchemaVersion', () => { }); }); - it('should pass jsonSchemaVersionByCountry only allow `DEU` to pass contract details form', async () => { + it('should pass jsonSchemaVersionByCountry to contract details form', async () => { const options = { jsonSchemaVersionByCountry: { DEU: { @@ -204,55 +204,6 @@ describe('useOnboarding jsonSchemaVersion', () => { }); }); }); - - it('should pass jsonSchemaVersionByCountry but set default version for other countries', async () => { - const options = { - jsonSchemaVersionByCountry: { - PRT: { - contract_details: 2, - }, - }, - }; - - const { result } = renderHook( - () => - useOnboarding({ - companyId: 'test-company-id', - countryCode: 'PRT', - employmentId: 'test-employment-id', - skipSteps: ['select_country'], - options, - }), - { wrapper: TestProviders }, - ); - - await waitFor(() => { - expect(result.current.isLoading).toBe(false); - }); - - // Navigate to contract details step - result.current.goTo('contract_details'); - - const contractDetailsCall = mockGetShowFormCountry.mock.calls[1][0]; - - await waitFor(() => { - expect(contractDetailsCall).toEqual({ - client: expect.any(Object), - headers: { - Authorization: ``, - }, - path: { - country_code: 'PRT', - form: 'contract_details', - }, - query: { - skip_benefits: true, - employment_id: 'test-employment-id', - json_schema_version: 1, - }, - }); - }); - }); }); describe('useUpdateEmployment calls', () => { @@ -348,55 +299,5 @@ describe('useOnboarding jsonSchemaVersion', () => { contract_details_json_schema_version: 2, }); }); - - it('should call patchUpdateEmployment2 with default contract_details_json_schema_version when submitting contract_details when jsonSchemaVersionByCountry is bigger than the allowed versions', async () => { - const { result } = renderHook( - () => - useOnboarding({ - employmentId: 'existing-employment-id', - companyId: 'test-company-id', - countryCode: 'DEU', - skipSteps: ['select_country'], - options: { - jsonSchemaVersionByCountry: { - DEU: { - contract_details: 3, - }, - }, - }, - }), - { wrapper: TestProviders }, - ); - - await waitFor(() => { - expect(result.current.isLoading).toBe(false); - }); - - // Navigate to contract_details step - act(() => { - result.current.goTo('contract_details'); - }); - - // Submit contract_details form - await act(async () => { - await result.current.onSubmit({ - // minimal contract details data - job_title: 'Engineer', - start_date: '2024-01-01', - }); - }); - - await waitFor(() => { - expect(mockPatchUpdateEmployment2).toHaveBeenCalled(); - }); - - const call = mockPatchUpdateEmployment2.mock.calls[0][0]; - - expect(call.query).toEqual({ - skip_benefits: true, - employment_basic_information_json_schema_version: 1, - contract_details_json_schema_version: 1, - }); - }); }); }); diff --git a/src/flows/Onboarding/tests/utils.test.ts b/src/flows/Onboarding/tests/utils.test.ts index 808f5426..a6f66e9e 100644 --- a/src/flows/Onboarding/tests/utils.test.ts +++ b/src/flows/Onboarding/tests/utils.test.ts @@ -21,32 +21,4 @@ describe('getContractDetailsSchemaVersion', () => { expect(result).toEqual(2); }); - - it('should return default version if country-specific version is not valid', () => { - const options = { - jsonSchemaVersionByCountry: { - DEU: { - contract_details: 5, - }, - }, - }; - - const result = getContractDetailsSchemaVersion(options, 'DEU'); - - expect(result).toEqual(1); - }); - - it('should return default version if country-specific version is not provided', () => { - const options = { - jsonSchemaVersionByCountry: { - PRT: { - contract_details: 5, - }, - }, - }; - - const result = getContractDetailsSchemaVersion(options, 'PRT'); - - expect(result).toEqual(1); - }); }); diff --git a/src/flows/Onboarding/types.ts b/src/flows/Onboarding/types.ts index fd656ee4..ce6eb624 100644 --- a/src/flows/Onboarding/types.ts +++ b/src/flows/Onboarding/types.ts @@ -99,7 +99,7 @@ export type OnboardingFlowProps = { jsonSchemaVersionByCountry?: { [countryCode: string]: { employment_basic_information?: number; - contract_details?: number; + contract_details?: number | 'latest'; }; }; }; diff --git a/src/flows/Onboarding/utils.ts b/src/flows/Onboarding/utils.ts index bbead7f0..6f5c5a11 100644 --- a/src/flows/Onboarding/utils.ts +++ b/src/flows/Onboarding/utils.ts @@ -48,65 +48,15 @@ export const disabledInviteButtonEmploymentStatus: Employment['status'][] = [ export const DEFAULT_VERSION = 1; -/** - * Defines allowed JSON schema versions per country for contract_details - * Key: country code, Value: array of allowed versions (first is default/recommended) - */ -const COUNTRY_CONTRACT_DETAILS_VERSION_ALLOWLIST: Record = { - DEU: [1, 2], // Germany: allows v1 (default) and v2 -}; - /** * Gets the default (recommended) contract details schema version for a country */ -const getDefaultContractDetailsSchemaVersion = ( - countryCode: string | null, -): number => { - if (!countryCode) return DEFAULT_VERSION; - const allowedVersions = - COUNTRY_CONTRACT_DETAILS_VERSION_ALLOWLIST[countryCode]; - return allowedVersions?.[0] ?? DEFAULT_VERSION; // First version is the default -}; - -/** - * Validates if a version is allowed for a given country - * Returns the version if valid, otherwise returns the default - */ -const getValidatedContractDetailsSchemaVersion = ( - requestedVersion: number | undefined, - countryCode: string | null, -): number => { - const defaultVersion = getDefaultContractDetailsSchemaVersion(countryCode); - - // If there is no country code, no allowlist for country, or no requested version, return the default version - if ( - !countryCode || - !COUNTRY_CONTRACT_DETAILS_VERSION_ALLOWLIST[countryCode] || - !requestedVersion - ) { - return defaultVersion; - } - - const allowedVersions = - COUNTRY_CONTRACT_DETAILS_VERSION_ALLOWLIST[countryCode]; - - // Check if requested version is allowed - if (allowedVersions.includes(requestedVersion)) { - return requestedVersion; - } - - // Version not allowed, return default with console warning - console.warn( - `[RemoteFlows] JSON Schema version ${requestedVersion} is not allowed for country ${countryCode}. ` + - `Allowed versions: [${allowedVersions.join(', ')}]. Using default version ${defaultVersion}.`, - ); - - return defaultVersion; +const getDefaultContractDetailsSchemaVersion = (): number => { + return DEFAULT_VERSION; }; /** * Resolves the effective contract details schema version for a country - * Priority: country-specific > global > default by country * * @param options - The flow options containing version configurations * @param countryCode - The country code to resolve version for @@ -123,11 +73,7 @@ export const getContractDetailsSchemaVersion = ( const requestedVersion = countrySpecificVersion ? countrySpecificVersion - : getDefaultContractDetailsSchemaVersion(countryCode); - const effectiveVersion = getValidatedContractDetailsSchemaVersion( - requestedVersion, - countryCode, - ); + : getDefaultContractDetailsSchemaVersion(); - return effectiveVersion; + return requestedVersion; };