# EC React Schemas



Schemas for the Socotra Insurance Suite [#schemas-for-the-socotra-insurance-suite]

This package provides a comprehensive collection of `zod` schemas that
define the core data structures for Socotra’s Enterprise Components.
These schemas are fundamental to ensuring type safety, data integrity,
and validation across the platform, from backend services to frontend
components.

Core Philosophy [#core-philosophy]

Zod Schemas are powerful tools for data validation and type inference.
They are used to define the structure of the data that is passed into
and out of the library. They are also used to define the structure of
the data that is stored in the database.

By leveraging the power of Zod, we can ensure that the data that is
passed into and out of the library is always valid and of the correct
type. This is especially important for complex data structures that are
used in the library, such as policies, accounts, and transactions.

Key Features [#key-features]

* **Domain Schemas:** Business-specific data models (e.g., Policies,
  Invoices, Accounts).
* **Config Schemas:** Structures for configuration objects (e.g.,
  Product and UI configurations).
* **Service Schemas:** Data contracts for API requests and responses.
* **Shared Schemas:** Common, reusable data structures used across
  multiple domains.

***

Installation [#installation]

This package has a peer dependency on `zod`. Install both packages in
your project:

```sh
npm i @socotra/ec-react-schemas zod
```

***

Usage [#usage]

Import schemas directly from the package to use them for data
validation, type inference, or in conjunction with libraries like
`react-hook-form`.

```ts
import { policyResponseSchema } from '@socotra/ec-react-schemas';
import { z } from 'zod';

type Policy = z.infer<typeof policyResponseSchema>;

function validatePolicy(data: unknown): Policy {
	return policyResponseSchema.parse(data);
}
```

Documentation [#documentation]

The documentation for this package is generated from a script that must
be run after the package is built.

To contribute to the documentation, clone the repo and run the following
command after adding, updating, or removing schemas:

```sh
git clone https://github.com/socotra/ec-react.git
cd ec-react/packages/schemas
pnpm run docs:generate
```

This will update the `README.md` file with the documentation for the
schemas. Copy and paste this file into
`ec-react/packages/docs/src/schemas/index.md`

Finally, run `pnpm run sync` to update the documentation in the
`README.md` files of this and other packages.

Follow instructions in the `packages/docs/README.md` file to build the
documentation and update the `Socotra Documentation` repo.

***

Available Schemas [#available-schemas]

Accounts [#accounts]

**account-request.ts**

| Zod Schema               | Type                   |
| ------------------------ | ---------------------- |
| `accountStateEnumSchema` | `AccountStateEnum`     |
| `accountCreateSchema`    | `AccountCreateRequest` |
| `accountUpdateSchema`    | `AccountUpdateRequest` |

Billings [#billings]

**credit-distribution-request-schema.ts**

| Zod Schema                        | Type                        |
| --------------------------------- | --------------------------- |
| `creditDistributionRequestSchema` | `CreditDistributionRequest` |

**credit-distribution-response-schema.ts**

| Zod Schema                         | Type                         |
| ---------------------------------- | ---------------------------- |
| `creditDistributionResponseSchema` | `CreditDistributionResponse` |

**credit-distribution-reverse-request.ts**

| Zod Schema                               | Type                               |
| ---------------------------------------- | ---------------------------------- |
| `creditDistributionReverseRequestSchema` | `CreditDistributionReverseRequest` |

**credit-distribution-schemas.ts**

| Zod Schema                          | Type                          |
| ----------------------------------- | ----------------------------- |
| `creditDistributionStateEnumSchema` | `CreditDistributionStateEnum` |

**delinquency-schemas.ts**

| Zod Schema                           | Type                       |
| ------------------------------------ | -------------------------- |
| `advanceLapseToEnumSchema`           |                            |
| `delinquencyLevelEnumSchema`         |                            |
| `delinquencyStateEnumSchema`         |                            |
| `delinquencyReferenceTypeEnumSchema` |                            |
| `delinquencySettingsSchema`          | `DelinquencySettings`      |
| `delinquencyReferenceSchema`         | `DelinquencyReferenceType` |
| `delinquencyResponseSchema`          | `DelinquencyResponse`      |
| \\                                   | `AdvanceLapseTo`           |
| \\                                   | `DelinquencyLevel`         |
| \\                                   | `DelinquencyState`         |
| \\                                   | `DelinquencyReference`     |

**invoice-response-schema.ts**

| Zod Schema                  | Type                  |
| --------------------------- | --------------------- |
| `invoiceItemResponseSchema` | `InvoiceItemResponse` |
| `invoiceResponseSchema`     | `InvoiceResponse`     |

**invoice-schemas.ts**

| Zod Schema               | Type           |
| ------------------------ | -------------- |
| `invoiceStateEnumSchema` |                |
| \\                       | `InvoiceState` |

**ledger-account-response-schema.ts**

| Zod Schema                    | Type                    |
| ----------------------------- | ----------------------- |
| `ledgerAccountResponseSchema` | `LedgerAccountResponse` |

**ledger-account-schemas.ts**

| Zod Schema                              | Type                              |
| --------------------------------------- | --------------------------------- |
| `ledgerAccountReferenceTypeEnumSchema`  | `LedgerAccountReferenceTypeEnum`  |
| `ledgerAccountAccountingTypeEnumSchema` | `LedgerAccountAccountingTypeEnum` |
| `ledgerAccountLineItemSchema`           | `LedgerAccountLineItem`           |

**payment-request-schema.ts**

| Zod Schema             | Type             |
| ---------------------- | ---------------- |
| `PaymentRequestSchema` | `PaymentRequest` |

**payment-schemas.ts**

| Zod Schema                          | Type                          |
| ----------------------------------- | ----------------------------- |
| `creditItemContainerTypeEnumSchema` | `CreditItemContainerTypeEnum` |
| `creditItemSchema`                  | `CreditItem`                  |
| `transactionMethodEnumSchema`       | `TransactionMethodEnum`       |
| `paymentStateEnumSchema`            |                               |
| \\                                  | `paymentStateEnum`            |

Charges [#charges]

**charge-enums.ts**

| Zod Schema                 | Type             |
| -------------------------- | ---------------- |
| `chargeCategoryEnumSchema` |                  |
| `chargeCategorySchema`     | `ChargeCategory` |

**charge-response-schema.ts**

| Zod Schema             | Type             |
| ---------------------- | ---------------- |
| `chargeResponseSchema` | `ChargeResponse` |

Config [#config]

**account-evaluate-constraints-request.ts**

| Zod Schema                                | Type                                |
| ----------------------------------------- | ----------------------------------- |
| `accountEvaluateConstraintsRequestSchema` | `AccountEvaluateConstraintsRequest` |

**account-schema.ts**

| Zod Schema                  | Type                  |
| --------------------------- | --------------------- |
| `accountConfigSchema`       | `AccountConfigRecord` |
| `accountConfigRecordSchema` |                       |
| \\                          | `AccountConfig`       |

**auto-renewal-plan-schema.ts**

| Zod Schema                     | Type              |
| ------------------------------ | ----------------- |
| `autoRenewalPlanSchema`        | `AutoRenewalPlan` |
| `autoRenewalPlanRecordsSchema` |                   |

**bootstrap.ts**

| Zod Schema                     | Type                        |
| ------------------------------ | --------------------------- |
| `bootstrapResourceGroupSchema` | `BootstrapResourceGroup`    |
| `bootstrapResourceInstance`    | `BootstrapResourceInstance` |
| `bootstrapResourcesSchema`     | `BootstrapResources`        |
| `bootstrapSchema`              | `Bootstrap`                 |

**constraint-schema.ts**

| Zod Schema               | Type               |
| ------------------------ | ------------------ |
| `constraintConfigSchema` | `ConstraintConfig` |

**constraint-tables-schema.ts**

| Zod Schema               | Type               |
| ------------------------ | ------------------ |
| `constraintTablesSchema` | `ConstraintTables` |

**coverage-terms-schema.ts**

| Zod Schema                  | Type                        |
| --------------------------- | --------------------------- |
| `CoverageTermValueSchema`   | `CoverageTermValue`         |
| `coverageTermOptionSchema`  | `CoverageTermOption`        |
| `coverageTermSchema`        | `CoverageTermsConfigRecord` |
| `coverageTermsRecordSchema` |                             |
| \\                          | `CoverageTermsConfig`       |

**data-model-schema.ts**

| Zod Schema        | Type        |
| ----------------- | ----------- |
| `dataModelSchema` | `DataModel` |

**data-type-schema.ts**

| Zod Schema              | Type                   |
| ----------------------- | ---------------------- |
| `dataTypeConfigSchema`  | `DataTypeConfigRecord` |
| `dataTypesRecordSchema` |                        |
| \\                      | `DataTypeConfig`       |

**delinquency-plan-schema.ts**

| Zod Schema                     | Type              |
| ------------------------------ | ----------------- |
| `delinquencyLevelSchema`       |                   |
| `advanceLapseToSchema`         |                   |
| `delinquencyPlanSchema`        | `DelinquencyPlan` |
| `delinquencyPlanRecordsSchema` |                   |

**element-schema.ts**

| Zod Schema                  | Type                  |
| --------------------------- | --------------------- |
| `elementConfigSchema`       | `ElementConfigRecord` |
| `elementConfigRecordSchema` |                       |
| \\                          | `ElementConfig`       |

**dependency-map-response.ts**

| Zod Schema                    | Type                    |
| ----------------------------- | ----------------------- |
| `dependencyMapResponseSchema` | `DependencyMapResponse` |

**evaluate-constraint-request.ts**

| Zod Schema                         | Type                         |
| ---------------------------------- | ---------------------------- |
| `evaluateConstraintsRequestSchema` | `EvaluateConstraintsRequest` |

**evaluate-constraint-response.ts**

| Zod Schema                          | Type                          |
| ----------------------------------- | ----------------------------- |
| `evaluateConstraintsResponseSchema` | `EvaluateConstraintsResponse` |

**field-schema.ts**

| Zod Schema                | Type                |
| ------------------------- | ------------------- |
| `fieldConfigSchema`       | `FieldConfigRecord` |
| `fieldConfigRecordSchema` |                     |
| \\                        | `FieldConfig`       |

**payment-schema.ts**

| Zod Schema                  | Type                  |
| --------------------------- | --------------------- |
| `paymentConfigSchema`       | `PaymentConfig`       |
| `paymentConfigRecordSchema` | `PaymentConfigRecord` |

**product-schema.ts**

| Zod Schema                  | Type                  |
| --------------------------- | --------------------- |
| `productConfigSchema`       | `ProductConfigRecord` |
| `productConfigRecordSchema` |                       |
| \\                          | `ProductConfig`       |

**quantifiers.ts**

| Zod Schema                  | Type                  |
| --------------------------- | --------------------- |
| `quantifiersSchema`         | `Quantifiers`         |
| `optionalQuantifiersSchema` | `OptionalQuantifiers` |

**reversal-type-schema.ts**

| Zod Schema                     | Type                       |
| ------------------------------ | -------------------------- |
| `reversalCreditTypeEnumSchema` | `ReversalCreditTypeEnum`   |
| `reversalTypeSchema`           | `ReversalType`             |
| `reversalTypesRecordsSchema`   |                            |
| \\                             | `ReversalTypeConfigRecord` |

**tenant-schema.ts**

| Zod Schema               | Type               |
| ------------------------ | ------------------ |
| `tenantBaseConfigSchema` | `TenantBaseConfig` |

**transaction-types-schema.ts**

| Zod Schema                      | Type                          |
| ------------------------------- | ----------------------------- |
| `transactionTypeCategorySchema` | `TransactionTypeCategory`     |
| `transactionTypeSchema`         | `TransactionType`             |
| `transactionTypesRecordsSchema` |                               |
| \\                              | `TransactionTypeConfigRecord` |

Documents [#documents]

**document-response.ts**

| Zod Schema                       | Type                       |
| -------------------------------- | -------------------------- |
| `documentInstanceResponseSchema` | `DocumentInstanceResponse` |

Policies [#policies]

**policy-schemas.ts**

| Zod Schema                       | Type                   |
| -------------------------------- | ---------------------- |
| `policyBillingLevelEnumSchema`   |                        |
| `policyBillingTriggerEnumSchema` |                        |
| \\                               | `PolicyBillingLevel`   |
| \\                               | `PolicyBillingTrigger` |

**policy-snapshot-response.ts**

| Zod Schema                     | Type                     |
| ------------------------------ | ------------------------ |
| `policySnapshotResponseSchema` | `PolicySnapshotResponse` |

**policy-term-response.ts**

| Zod Schema                  | Type                        |
| --------------------------- | --------------------------- |
| `policyTermResponseSchema`  | `PolicyTermResponse`        |
| `policyTermSummaryResponse` | `PolicyTermSummaryResponse` |

**policy-term-schemas.ts**

| Zod Schema                | Type                |
| ------------------------- | ------------------- |
| `documentSummarySchema`   | `DocumentSummary`   |
| `elementSummarySchema`    | `ElementSummary`    |
| `subsegmentSummarySchema` | `SubsegmentSummary` |

**term-schemas.ts**

| Zod Schema                | Type                |
| ------------------------- | ------------------- |
| `documentSummarySchema`   | `DocumentSummary`   |
| `elementSummarySchema`    | `ElementSummary`    |
| `subsegmentSummarySchema` | `SubsegmentSummary` |
| \\                        | `DocumentState`     |
| \\                        | `DocumentReference` |

**term-summary.ts**

| Zod Schema          | Type          |
| ------------------- | ------------- |
| `termSummarySchema` | `TermSummary` |

**transaction-snapshot-response.ts**

| Zod Schema                          | Type                          |
| ----------------------------------- | ----------------------------- |
| `segmentResponseSchema`             | `SegmentResponse`             |
| `transactionSnapshotResponseSchema` | `TransactionSnapshotResponse` |

**transaction-underwriting-response.ts**

| Zod Schema                             | Type                                   |
| -------------------------------------- | -------------------------------------- |
| `transactionUnderwritingFlagsResponse` | `TransactionUnderwritingFlagsResponse` |

Quotes [#quotes]

**quote-price-response.ts**

| Zod Schema                       | Type                       |
| -------------------------------- | -------------------------- |
| `quotePriceChargeCategoryEnum`   |                            |
| `quotePriceChargeResponseSchema` | `QuotePriceChargeResponse` |
| `quotePriceResponseSchema`       | `QuotePriceResponse`       |
| \\                               | `QuotePriceChargeCategory` |

**quote-request.ts**

| Zod Schema           | Type           |
| -------------------- | -------------- |
| `quoteRequestSchema` | `QuoteRequest` |

**quote-schemas.ts**

| Zod Schema                      | Type                  |
| ------------------------------- | --------------------- |
| `quoteStateSchema`              | `QuoteState`          |
| `quoteBillingTriggerEnumSchema` |                       |
| `quoteBillingLevelEnumSchema`   |                       |
| \\                              | `QuoteBillingTrigger` |
| \\                              | `QuoteBillingLevel`   |

**quote-underwriting-response.ts**

| Zod Schema                       | Type                             |
| -------------------------------- | -------------------------------- |
| `quoteUnderwritingFlagsResponse` | `QuoteUnderwritingFlagsResponse` |

**reset-quote-request.ts**

| Zod Schema                        | Type                    |
| --------------------------------- | ----------------------- |
| `resetQuoteFlagsActionEnumSchema` |                         |
| `resetQuoteRequestSchema`         | `ResetQuoteRequest`     |
| \\                                | `ResetQuoteFlagsAction` |

Shared [#shared]

**anchor-mode.ts**

| Zod Schema             | Type         |
| ---------------------- | ------------ |
| `anchorModeEnumSchema` |              |
| \\                     | `AnchorMode` |

**anchor-type.ts**

| Zod Schema             | Type         |
| ---------------------- | ------------ |
| `anchorTypeEnumSchema` |              |
| \\                     | `AnchorType` |

**billing-level.ts**

| Zod Schema               | Type           |
| ------------------------ | -------------- |
| `billingLevelEnumSchema` |                |
| \\                       | `BillingLevel` |

**cadence.ts**

| Zod Schema          | Type      |
| ------------------- | --------- |
| `cadenceEnumSchema` |           |
| \\                  | `Cadence` |

**currencies.ts**

| Zod Schema           | Type           |
| -------------------- | -------------- |
| `currencyEnumSchema` |                |
| \\                   | `CurrencyType` |

**days.ts**

| Zod Schema              | Type          |
| ----------------------- | ------------- |
| `dayOfWeekEnumSchema`   |               |
| `weekOfMonthEnumSchema` |               |
| \\                      | `DayOfWeek`   |
| \\                      | `WeekOfMonth` |

**document-reference-type.ts**

| Zod Schema                        | Type                |
| --------------------------------- | ------------------- |
| `documentReferenceTypeEnumSchema` |                     |
| \\                                | `DocumentReference` |

**document-state.ts**

| Zod Schema                | Type            |
| ------------------------- | --------------- |
| `documentStateEnumSchema` |                 |
| \\                        | `DocumentState` |

**element-request.ts**

| Zod Schema                   | Type                   |
| ---------------------------- | ---------------------- |
| `elementCreateRequestSchema` | `ElementCreateRequest` |
| `elementRequestSchema`       | `ElementRequest`       |

**element-response.ts**

| Zod Schema              | Type              |
| ----------------------- | ----------------- |
| `elementResponseSchema` | `ElementResponse` |

**field-values.ts**

| Zod Schema | Type             |
| ---------- | ---------------- |
| \\         | `PrimitiveValue` |
| \\         | `DataFieldValue` |

**preferences-response.ts**

| Zod Schema                  | Type                  |
| --------------------------- | --------------------- |
| `preferencesResponseSchema` | `PreferencesResponse` |

**timezones.ts**

| Zod Schema           | Type           |
| -------------------- | -------------- |
| `timezoneEnumSchema` |                |
| \\                   | `TimezoneType` |

**underwriting-flag-response.ts**

| Zod Schema                       | Type                       |
| -------------------------------- | -------------------------- |
| `underwritingFlagEnumSchema`     | `UnderwritingFlagEnum`     |
| `underwritingFlagResponseSchema` | `UnderwritingFlagResponse` |

**underwriting-flags-request.ts**

| Zod Schema                             | Type                             |
| -------------------------------------- | -------------------------------- |
| `underwritingFlagCreateRequestSchema`  | `UnderwritingFlagCreateRequest`  |
| `underwritingFlagsUpdateRequestSchema` | `UnderwritingFlagsUpdateRequest` |

**validation-result.ts**

| Zod Schema               | Type               |
| ------------------------ | ------------------ |
| `ulidSchema`             |                    |
| `validationItemSchema`   | `ValidationItem`   |
| `validationResultSchema` | `ValidationResult` |

Transactions [#transactions]

**add-change-instruction-create-request.ts**

| Zod Schema                                | Type                                |
| ----------------------------------------- | ----------------------------------- |
| `addChangeInstructionCreateRequestSchema` | `AddChangeInstructionCreateRequest` |

**add-change-instruction-response.ts**

| Zod Schema                           | Type                           |
| ------------------------------------ | ------------------------------ |
| `addChangeInstructionResponseSchema` | `AddChangeInstructionResponse` |

**delete-change-instruction-create-request.ts**

| Zod Schema                                   | Type                                   |
| -------------------------------------------- | -------------------------------------- |
| `deleteChangeInstructionCreateRequestSchema` | `DeleteChangeInstructionCreateRequest` |

**delete-change-instruction-response.ts**

| Zod Schema                              | Type                              |
| --------------------------------------- | --------------------------------- |
| `deleteChangeInstructionResponseSchema` | `DeleteChangeInstructionResponse` |

**modify-change-instruction-create-request.ts**

| Zod Schema                                   | Type                                   |
| -------------------------------------------- | -------------------------------------- |
| `modifyChangeInstructionCreateRequestSchema` | `ModifyChangeInstructionCreateRequest` |

**modify-change-instruction-response.ts**

| Zod Schema                              | Type                              |
| --------------------------------------- | --------------------------------- |
| `modifyChangeInstructionResponseSchema` | `ModifyChangeInstructionResponse` |

**params-change-instruction-create-request.ts**

| Zod Schema                                   | Type                                   |
| -------------------------------------------- | -------------------------------------- |
| `paramsChangeInstructionCreateRequestSchema` | `ParamsChangeInstructionCreateRequest` |

**params-change-instruction-response.ts**

| Zod Schema                              | Type                              |
| --------------------------------------- | --------------------------------- |
| `paramsChangeInstructionResponseSchema` | `ParamsChangeInstructionResponse` |

**policy-transaction-response.ts**

| Zod Schema                        | Type                        |
| --------------------------------- | --------------------------- |
| `policyTransactionResponseSchema` | `PolicyTransactionResponse` |

**reset-transaction-options-request.ts**

| Zod Schema                             | Type                             |
| -------------------------------------- | -------------------------------- |
| `resetTransactionOptionsRequestSchema` | `ResetTransactionOptionsRequest` |

**transaction-enums.ts**

| Zod Schema                      | Type                  |
| ------------------------------- | --------------------- |
| `transactionStateEnumSchema`    |                       |
| `transactionCategoryEnumSchema` |                       |
| \\                              | `TransactionCategory` |
| \\                              | `TransactionState`    |

**transaction-price-response.ts**

| Zod Schema                       | Type                       |
| -------------------------------- | -------------------------- |
| `transactionPriceResponseSchema` | `TransactionPriceResponse` |

**transaction-underwriting-response.ts**

| Zod Schema                              | Type                              |
| --------------------------------------- | --------------------------------- |
| `transactionUnderwritingResponseSchema` | `TransactionUnderwritingResponse` |
