@cfxlabsinc/b2b-services
    Preparing search index...

    Unless need to directly act on an organization specifically, you should be using EntityService instead.

    The shared search cache is rooted at OrganizationCache, so this writer inherits it and self-busts via invalidateCache — one call that reaches both the customer and admin surfaces, since they share a namespace and a tag vocabulary.

    Hierarchy (View Summary)

    Index
    • Parameters

      • args: {
            aiPriseClient: AiPriseClient;
            customerQueryService: CustomerQueryService;
            db: B2bDatabase;
            defaultAiPriseTemplateId: string;
            eventPublisher: CustomerEventPublisher;
            relatedPersonService: RelatedPersonService;
            valkeyClient: ValkeyClient | null;
        }
        • aiPriseClient: AiPriseClient
        • customerQueryService: CustomerQueryService
        • db: B2bDatabase
        • defaultAiPriseTemplateId: string
        • eventPublisher: CustomerEventPublisher
        • relatedPersonService: RelatedPersonService

          Required — org-api forces at least one CONTROL person for RouteFusion-enabled customers (Phase 1), so create() can be called with relatedPeople from any construction site. Required (not optional-and-asserted-at-use) specifically so the compiler enumerates every construction site when this dependency is added, rather than a caller finding out at runtime — after the org row + AiPrise verify() have already committed — that nobody wired it in. Every consumer package constructs a small OrganizationQueryService to hand to its own RelatedPersonService instance (avoids a circular construction against this class) — see organization-api/src/main.ts for the canonical shape.

        • valkeyClient: ValkeyClient | null

      Returns OrganizationService

    cache: ServiceCache<CachedSearchPage<CachedOrgWithCustomer>>
    db: B2bDatabase
    • Parameters

      • __namedParameters: Omit<
            {
                achName: string;
                address?: {
                    city: string;
                    countryCode: string;
                    line1: string;
                    line2?: string;
                    postalCode?: string;
                    regionCode?: string;
                };
                capabilities: (
                    | "TRANSACT"
                    | "MANAGE_PAYMENT_INSTRUMENT"
                    | "MANAGE_LEDGER_ACCOUNT"
                    | "MANAGE_DEPOSIT_MEMO"
                )[];
                countryCode: string;
                countryOfIncorporation: string;
                createdAt: Date;
                deletedAt?: Date;
                description?: string;
                email?: string;
                fullName: string;
                id: string;
                incorporationDate?: string;
                legalEntityType: string;
                name: string;
                phone?: E164Phone;
                referenceId?: string;
                routeFusionEntity?: {
                    documentsUploadedAt?: string;
                    entityId: string;
                    lastFinalizeError?: { at: string; message: string }
                    | null;
                    programId?: string;
                    requiredDocuments?: string[][];
                    status: "PENDING" | "REJECTED" | "VERIFIED";
                };
                status: "ACTIVE"
                | "DELETED"
                | "DISABLED"
                | "PENDING_VERIFICATION";
                taxId: string;
                type: "ORGANIZATION";
                updatedAt: Date;
                uuid: string;
                verificationData?: {
                    status: "REVIEW" | "PENDING" | "APPROVED" | "DECLINED";
                    verificationSessionId?: string;
                    verificationTemplateId: string;
                };
                verificationProfileId?: string;
                websiteUrl?: string;
                wireName: string;
            },
            | "achName"
            | "wireName"
            | "id"
            | "status"
            | "type"
            | "createdAt"
            | "updatedAt"
            | "uuid"
            | "fullName"
            | "verificationProfileId"
            | "countryCode"
            | "capabilities"
            | "address",
        > & {
            address: {
                city: string;
                countryCode: string;
                line1: string;
                line2?: string;
                postalCode?: string;
                regionCode?: string;
            };
            customerId: string;
            isMainOrg?: boolean;
            relatedPeople?: Omit<
                RelatedPersonInput & {
                    countryOfResidence: string;
                    customerId: string;
                    organizationId: string;
                    type: "BENEFICIAL_OWNER"
                    | "CONTROL";
                },
                "customerId"
                | "organizationId",
            >[];
            verificationProfileId?: string;
        }
        • address: {
              city: string;
              countryCode: string;
              line1: string;
              line2?: string;
              postalCode?: string;
              regionCode?: string;
          }
        • customerId: string
        • OptionalisMainOrg?: boolean

          Mark this as the customer's PRIMARY organization (organization.is_main_org) — the one every customer-scoped read resolves to, and the replacement for the old customer.organization_id pointer. Exactly one per customer, enforced by the partial unique index organization_main_org_per_customer_idx; a second one surfaces as DUPLICATE through the existing unique-violation catch. Set only by the customer-onboarding flow (@cfxlabsinc/onboarding-services).

        • OptionalrelatedPeople?: Omit<
              RelatedPersonInput & {
                  countryOfResidence: string;
                  customerId: string;
                  organizationId: string;
                  type: "BENEFICIAL_OWNER"
                  | "CONTROL";
              },
              "customerId"
              | "organizationId",
          >[]

          Control persons / beneficial owners to create against this org right after it's inserted (organization-api forces at least one CONTROL person when the customer is RouteFusion-enabled — see OrganizationController). Each is forwarded to relatedPersonService the same way the standalone related-person endpoint does.

        • OptionalverificationProfileId?: string

          An existing AiPrise business profile to attach to this org. When supplied the profile is FETCHED here and its current result/session are attached to the org INSTEAD of kicking off a fresh async verify(). The customer-onboarding flow pastes a profile the operator already validated, and no AiPrise webhook will ever fire for it — so without this the org would sit PENDING_VERIFICATION forever.

          Only the id is accepted: the verification outcome is always read from AiPrise (the source of truth), never trusted from the caller.

      Returns Promise<
          | {
              ok: true;
              value: {
                  achName: string;
                  address?: {
                      city: string;
                      countryCode: string;
                      line1: string;
                      line2?: string;
                      postalCode?: string;
                      regionCode?: string;
                  };
                  capabilities: (
                      | "TRANSACT"
                      | "MANAGE_PAYMENT_INSTRUMENT"
                      | "MANAGE_LEDGER_ACCOUNT"
                      | "MANAGE_DEPOSIT_MEMO"
                  )[];
                  countryCode: string;
                  countryOfIncorporation: string;
                  createdAt: Date;
                  deletedAt?: Date;
                  description?: string;
                  email?: string;
                  fullName: string;
                  id: string;
                  incorporationDate?: string;
                  legalEntityType: string;
                  name: string;
                  phone?: E164Phone;
                  referenceId?: string;
                  routeFusionEntity?: {
                      documentsUploadedAt?: string;
                      entityId: string;
                      lastFinalizeError?: { at: string; message: string }
                      | null;
                      programId?: string;
                      requiredDocuments?: string[][];
                      status: "PENDING" | "REJECTED" | "VERIFIED";
                  };
                  status: "ACTIVE"
                  | "DELETED"
                  | "DISABLED"
                  | "PENDING_VERIFICATION";
                  taxId: string;
                  type: "ORGANIZATION";
                  updatedAt: Date;
                  uuid: string;
                  verificationData?: {
                      status: "REVIEW" | "PENDING" | "APPROVED" | "DECLINED";
                      verificationSessionId?: string;
                      verificationTemplateId: string;
                  };
                  verificationProfileId?: string;
                  websiteUrl?: string;
                  wireName: string;
              };
          }
          | {
              error: | ServiceError<"INVALID_EMAIL" | "INVALID_WEBSITE_URL">
              | ServiceError<"DUPLICATE" | "RELATED_PERSON_CREATE_FAILED">;
              ok: false;
          },
      >

    • Parameters

      • __namedParameters: { customerId: string; id: string }

      Returns Promise<
          | {
              ok: true;
              value: {
                  achName: string;
                  address?: {
                      city: string;
                      countryCode: string;
                      line1: string;
                      line2?: string;
                      postalCode?: string;
                      regionCode?: string;
                  };
                  capabilities: (
                      | "TRANSACT"
                      | "MANAGE_PAYMENT_INSTRUMENT"
                      | "MANAGE_LEDGER_ACCOUNT"
                      | "MANAGE_DEPOSIT_MEMO"
                  )[];
                  countryCode: string;
                  countryOfIncorporation: string;
                  createdAt: Date;
                  deletedAt?: Date;
                  description?: string;
                  email?: string;
                  fullName: string;
                  id: string;
                  incorporationDate?: string;
                  legalEntityType: string;
                  name: string;
                  phone?: E164Phone;
                  referenceId?: string;
                  routeFusionEntity?: {
                      documentsUploadedAt?: string;
                      entityId: string;
                      lastFinalizeError?: { at: string; message: string }
                      | null;
                      programId?: string;
                      requiredDocuments?: string[][];
                      status: "PENDING" | "REJECTED" | "VERIFIED";
                  };
                  status: "ACTIVE"
                  | "DELETED"
                  | "DISABLED"
                  | "PENDING_VERIFICATION";
                  taxId: string;
                  type: "ORGANIZATION";
                  updatedAt: Date;
                  uuid: string;
                  verificationData?: {
                      status: "REVIEW" | "PENDING" | "APPROVED" | "DECLINED";
                      verificationSessionId?: string;
                      verificationTemplateId: string;
                  };
                  verificationProfileId?: string;
                  websiteUrl?: string;
                  wireName: string;
              };
          }
          | { error: ServiceError; ok: false },
      >

    • Resolve the organization's incorporation (formation) date from its AiPrise business profile, for prefilling the RouteFusion virtual-account creation form (RouteFusion's createBusinessEntity requires incorporation_date).

      The date is not stored on the org record — it is read from AiPrise's registration_info.formation_date (falling back to the profile's top-level formation_date). Absence of a verification profile or a formation date is not an error: the admin can enter the value manually, so this returns { incorporationDate: null } in those cases.

      Parameters

      • __namedParameters: { customerId: string; id: string }
        • customerId: string
        • id: string

          Organization external id

      Returns Promise<
          | { ok: true; value: { incorporationDate: string
          | null } }
          | { error: ServiceError; ok: false },
      >

    • Parameters

      • __namedParameters: { customerId: string; id: string; redirectUrl: string }
        • customerId: string
        • id: string
        • redirectUrl: string

          The URL to redirect to, after verification is completed

      Returns Promise<
          | { error: ServiceError; ok: false }
          | { ok: true; value: { url: string } },
      >

      URL to start an identity document verification session

    • Bust every cached page — consumer or admin — that a write touching customerIds could have affected.

      The collection tag is always cleared alongside, because an unscoped admin page carries only that tag and no customer id can reach it.

      keys deletes exact entries in addition to the tag surgery, passing the key arguments — this cache hashes and prefixes them. It exists because invalidateTag resolves keys through the FT index, which does not exist in memory mode (valkeyClient: null); there the tag bust is a total no-op, and an exact-key delete is the only thing that keeps read-after-write honest. Services that folded get onto search pass that get's arguments.

      These deletes only reach this instance's own key space, because the key space is partitioned per surface. That is sufficient, and a writer must not try to name the other surface's key:

      • With Valkey, the other surface's get entry is itself tagged (by customer id, or by the collection tag when unscoped), so the tag bust above already evicts it from the shared L2 and publishes the peer eviction.
      • Without Valkey, the two surfaces are separate instances with separate L1 maps, so deleting a key from this instance could never have affected the other one anyway.

      Parameters

      • __namedParameters: { customerIds: readonly string[]; keys?: readonly CacheKey[] }

      Returns Promise<void>

    • Parameters

      • __namedParameters: {
            countriesOfIncorporation?: string[];
            createdAt?: DbTimestampCriteria;
            customerId: string;
            descriptionLike?: string;
            ids?: string[];
            includeDeleted?: boolean;
            legalEntityTypeLike?: string;
            legalEntityTypes?: (
                | "LIMITED_LIABILITY_COMPANY"
                | "C_CORPORATION"
                | "S_CORPORATION"
                | "B_CORPORATION"
                | "CLOSE_CORPORATION"
                | "COOPERATIVE"
                | "GENERAL_PARTNERSHIP"
                | "LIMITED_PARTNERSHIP"
                | "NONPROFIT_CORPORATION"
                | "SOLE_PROPRIETORSHIP"
            )[];
            nameLike?: string;
            orderBy?: DbOrderByCriterion<
                Omit<
                    PgTableWithColumns<
                        {
                            columns: {
                                achName: PgBuildColumn<
                                    "organization",
                                    SetNotNull<PgTextBuilder<(...)>>,
                                    {
                                        data: string;
                                        dataType: "string";
                                        driverParam: string;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "organization";
                                    },
                                >;
                                countryOfIncorporation: PgBuildColumn<
                                    "organization",
                                    SetNotNull<PgTextBuilder<(...)>>,
                                    {
                                        data: string;
                                        dataType: "string";
                                        driverParam: string;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "organization";
                                    },
                                >;
                                createdAt: PgBuildColumn<
                                    "organization",
                                    SetHasDefault<SetNotNull<(...)>>,
                                    {
                                        data: Date;
                                        dataType: "object date";
                                        driverParam: string;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: true;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "organization";
                                    },
                                >;
                                customerId: PgBuildColumn<
                                    "organization",
                                    SetNotNull<PgIntegerBuilder>,
                                    {
                                        data: number;
                                        dataType: "number int32";
                                        driverParam: (...) | (...);
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "organization";
                                    },
                                >;
                                data: PgBuildColumn<
                                    "organization",
                                    Set$Type<
                                        PgJsonbBuilder,
                                        {
                                            address?: ...;
                                            email?: ...;
                                            incorporationDate?: ...;
                                            phone?: ...;
                                            routeFusionEntity?: ...;
                                            verificationData?: ...;
                                            verificationProfileId?: ...;
                                            websiteUrl?: ...;
                                        },
                                    >,
                                    {
                                        data: {
                                            address?: ...;
                                            email?: ...;
                                            incorporationDate?: ...;
                                            phone?: ...;
                                            routeFusionEntity?: ...;
                                            verificationData?: ...;
                                            verificationProfileId?: ...;
                                            websiteUrl?: ...;
                                        };
                                        dataType: "object json";
                                        driverParam: unknown;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: false;
                                        tableName: "organization";
                                    },
                                >;
                                deletedAt: PgBuildColumn<
                                    "organization",
                                    PgTimestampBuilder,
                                    {
                                        data: Date;
                                        dataType: "object date";
                                        driverParam: string;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: false;
                                        tableName: "organization";
                                    },
                                >;
                                description: PgBuildColumn<
                                    "organization",
                                    PgTextBuilder<[(...), ...(...)[]]>,
                                    {
                                        data: string;
                                        dataType: "string";
                                        driverParam: string;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: false;
                                        tableName: "organization";
                                    },
                                >;
                                entityType: PgBuildColumn<
                                    "organization",
                                    SetNotNull<PgTextBuilder<(...)>>,
                                    {
                                        data: string;
                                        dataType: "string";
                                        driverParam: string;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "organization";
                                    },
                                >;
                                externalId: PgBuildColumn<
                                    "organization",
                                    SetHasRuntimeDefault<SetNotNull<(...)>>,
                                    {
                                        data: string;
                                        dataType: "string";
                                        driverParam: string;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: true;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "organization";
                                    },
                                >;
                                id: PgBuildColumn<
                                    "organization",
                                    HasIdentity<SetIsPrimaryKey<(...)>, "byDefault">,
                                    {
                                        data: number;
                                        dataType: "number int32";
                                        driverParam: (...) | (...);
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: true;
                                        hasRuntimeDefault: false;
                                        identity: "byDefault";
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "organization";
                                    },
                                >;
                                isMainOrg: PgBuildColumn<
                                    "organization",
                                    SetHasDefault<SetNotNull<(...)>>,
                                    {
                                        data: boolean;
                                        dataType: "boolean";
                                        driverParam: boolean;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: true;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "organization";
                                    },
                                >;
                                name: PgBuildColumn<
                                    "organization",
                                    SetNotNull<PgTextBuilder<(...)>>,
                                    {
                                        data: string;
                                        dataType: "string";
                                        driverParam: string;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "organization";
                                    },
                                >;
                                referenceId: PgBuildColumn<
                                    "organization",
                                    PgTextBuilder<[(...), ...(...)[]]>,
                                    {
                                        data: string;
                                        dataType: "string";
                                        driverParam: string;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: false;
                                        tableName: "organization";
                                    },
                                >;
                                status: PgBuildColumn<
                                    "organization",
                                    Set$Type<SetNotNull<(...)>, (...) | (...) | (...) | (...)>,
                                    {
                                        data: (...) | (...) | (...) | (...);
                                        dataType: "string";
                                        driverParam: string;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "organization";
                                    },
                                >;
                                taxId: PgBuildColumn<
                                    "organization",
                                    SetNotNull<PgTextBuilder<(...)>>,
                                    {
                                        data: string;
                                        dataType: "string";
                                        driverParam: string;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "organization";
                                    },
                                >;
                                updatedAt: PgBuildColumn<
                                    "organization",
                                    SetHasDefault<SetHasDefault<(...)>>,
                                    {
                                        data: Date;
                                        dataType: "object date";
                                        driverParam: string;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: true;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "organization";
                                    },
                                >;
                                uuid: PgBuildColumn<
                                    "organization",
                                    SetHasDefault<SetNotNull<(...)>>,
                                    {
                                        data: string;
                                        dataType: "string uuid";
                                        driverParam: string;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: true;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "organization";
                                    },
                                >;
                                wireName: PgBuildColumn<
                                    "organization",
                                    SetNotNull<PgTextBuilder<(...)>>,
                                    {
                                        data: string;
                                        dataType: "string";
                                        driverParam: string;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "organization";
                                    },
                                >;
                            };
                            dialect: "pg";
                            name: "organization";
                            schema: "b2b";
                        },
                    >,
                    "enableRLS",
                >,
                "createdAt"
                | "updatedAt",
            >[];
            page?: number;
            pageSize?: number;
            referenceIdLike?: string;
            referenceIds?: string[];
            routeFusionEntityIds?: string[];
            statuses?: ("ACTIVE" | "DELETED" | "DISABLED" | "PENDING_VERIFICATION")[];
            updatedAt?: DbTimestampCriteria;
        }
        • OptionalcountriesOfIncorporation?: string[]
        • OptionalcreatedAt?: DbTimestampCriteria
        • customerId: string
        • OptionaldescriptionLike?: string

          Partial match on description

        • Optionalids?: string[]
        • OptionalincludeDeleted?: boolean
        • OptionallegalEntityTypeLike?: string

          Partial match on legal entity type

        • OptionallegalEntityTypes?: (
              | "LIMITED_LIABILITY_COMPANY"
              | "C_CORPORATION"
              | "S_CORPORATION"
              | "B_CORPORATION"
              | "CLOSE_CORPORATION"
              | "COOPERATIVE"
              | "GENERAL_PARTNERSHIP"
              | "LIMITED_PARTNERSHIP"
              | "NONPROFIT_CORPORATION"
              | "SOLE_PROPRIETORSHIP"
          )[]

          Exact match to these canonical legal-entity-type codes (US structures).

        • OptionalnameLike?: string

          Partial match on legal entity name

        • OptionalorderBy?: DbOrderByCriterion<
              Omit<
                  PgTableWithColumns<
                      {
                          columns: {
                              achName: PgBuildColumn<
                                  "organization",
                                  SetNotNull<PgTextBuilder<(...)>>,
                                  {
                                      data: string;
                                      dataType: "string";
                                      driverParam: string;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "organization";
                                  },
                              >;
                              countryOfIncorporation: PgBuildColumn<
                                  "organization",
                                  SetNotNull<PgTextBuilder<(...)>>,
                                  {
                                      data: string;
                                      dataType: "string";
                                      driverParam: string;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "organization";
                                  },
                              >;
                              createdAt: PgBuildColumn<
                                  "organization",
                                  SetHasDefault<SetNotNull<(...)>>,
                                  {
                                      data: Date;
                                      dataType: "object date";
                                      driverParam: string;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: true;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "organization";
                                  },
                              >;
                              customerId: PgBuildColumn<
                                  "organization",
                                  SetNotNull<PgIntegerBuilder>,
                                  {
                                      data: number;
                                      dataType: "number int32";
                                      driverParam: (...) | (...);
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "organization";
                                  },
                              >;
                              data: PgBuildColumn<
                                  "organization",
                                  Set$Type<
                                      PgJsonbBuilder,
                                      {
                                          address?: ...;
                                          email?: ...;
                                          incorporationDate?: ...;
                                          phone?: ...;
                                          routeFusionEntity?: ...;
                                          verificationData?: ...;
                                          verificationProfileId?: ...;
                                          websiteUrl?: ...;
                                      },
                                  >,
                                  {
                                      data: {
                                          address?: ...;
                                          email?: ...;
                                          incorporationDate?: ...;
                                          phone?: ...;
                                          routeFusionEntity?: ...;
                                          verificationData?: ...;
                                          verificationProfileId?: ...;
                                          websiteUrl?: ...;
                                      };
                                      dataType: "object json";
                                      driverParam: unknown;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: false;
                                      tableName: "organization";
                                  },
                              >;
                              deletedAt: PgBuildColumn<
                                  "organization",
                                  PgTimestampBuilder,
                                  {
                                      data: Date;
                                      dataType: "object date";
                                      driverParam: string;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: false;
                                      tableName: "organization";
                                  },
                              >;
                              description: PgBuildColumn<
                                  "organization",
                                  PgTextBuilder<[(...), ...(...)[]]>,
                                  {
                                      data: string;
                                      dataType: "string";
                                      driverParam: string;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: false;
                                      tableName: "organization";
                                  },
                              >;
                              entityType: PgBuildColumn<
                                  "organization",
                                  SetNotNull<PgTextBuilder<(...)>>,
                                  {
                                      data: string;
                                      dataType: "string";
                                      driverParam: string;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "organization";
                                  },
                              >;
                              externalId: PgBuildColumn<
                                  "organization",
                                  SetHasRuntimeDefault<SetNotNull<(...)>>,
                                  {
                                      data: string;
                                      dataType: "string";
                                      driverParam: string;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: true;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "organization";
                                  },
                              >;
                              id: PgBuildColumn<
                                  "organization",
                                  HasIdentity<SetIsPrimaryKey<(...)>, "byDefault">,
                                  {
                                      data: number;
                                      dataType: "number int32";
                                      driverParam: (...) | (...);
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: true;
                                      hasRuntimeDefault: false;
                                      identity: "byDefault";
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "organization";
                                  },
                              >;
                              isMainOrg: PgBuildColumn<
                                  "organization",
                                  SetHasDefault<SetNotNull<(...)>>,
                                  {
                                      data: boolean;
                                      dataType: "boolean";
                                      driverParam: boolean;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: true;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "organization";
                                  },
                              >;
                              name: PgBuildColumn<
                                  "organization",
                                  SetNotNull<PgTextBuilder<(...)>>,
                                  {
                                      data: string;
                                      dataType: "string";
                                      driverParam: string;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "organization";
                                  },
                              >;
                              referenceId: PgBuildColumn<
                                  "organization",
                                  PgTextBuilder<[(...), ...(...)[]]>,
                                  {
                                      data: string;
                                      dataType: "string";
                                      driverParam: string;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: false;
                                      tableName: "organization";
                                  },
                              >;
                              status: PgBuildColumn<
                                  "organization",
                                  Set$Type<SetNotNull<(...)>, (...) | (...) | (...) | (...)>,
                                  {
                                      data: (...) | (...) | (...) | (...);
                                      dataType: "string";
                                      driverParam: string;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "organization";
                                  },
                              >;
                              taxId: PgBuildColumn<
                                  "organization",
                                  SetNotNull<PgTextBuilder<(...)>>,
                                  {
                                      data: string;
                                      dataType: "string";
                                      driverParam: string;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "organization";
                                  },
                              >;
                              updatedAt: PgBuildColumn<
                                  "organization",
                                  SetHasDefault<SetHasDefault<(...)>>,
                                  {
                                      data: Date;
                                      dataType: "object date";
                                      driverParam: string;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: true;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "organization";
                                  },
                              >;
                              uuid: PgBuildColumn<
                                  "organization",
                                  SetHasDefault<SetNotNull<(...)>>,
                                  {
                                      data: string;
                                      dataType: "string uuid";
                                      driverParam: string;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: true;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "organization";
                                  },
                              >;
                              wireName: PgBuildColumn<
                                  "organization",
                                  SetNotNull<PgTextBuilder<(...)>>,
                                  {
                                      data: string;
                                      dataType: "string";
                                      driverParam: string;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "organization";
                                  },
                              >;
                          };
                          dialect: "pg";
                          name: "organization";
                          schema: "b2b";
                      },
                  >,
                  "enableRLS",
              >,
              "createdAt"
              | "updatedAt",
          >[]
        • Optionalpage?: number

          Defaults to 1

        • OptionalpageSize?: number

          Defaults to 50

        • OptionalreferenceIdLike?: string

          Partial match on reference ID

        • OptionalreferenceIds?: string[]
        • OptionalrouteFusionEntityIds?: string[]

          Matches the pinned RouteFusion business-entity id on data->'routeFusionEntity'->>'entityId'. Mirrors the admin-side filter so Service/AdminService search signatures stay aligned.

        • Optionalstatuses?: ("ACTIVE" | "DELETED" | "DISABLED" | "PENDING_VERIFICATION")[]
        • OptionalupdatedAt?: DbTimestampCriteria

      Returns Promise<
          {
              ok: true;
              value: { hasNext: boolean; items: OrgWithCustomer[]; total: number };
          },
      >

    • Tags to write on a page, derived from the scope the query searched — never from the customers present in the result.

      That distinction is load-bearing. An entry tagged with the customer ids in the page carries no tags when the page is empty, so nothing can ever bust it and a later create leaves it stale for the full L2 TTL. Tagging by scope means an empty page still carries the tag for what it searched.

      An unscoped read falls back to the collection tag, since no customer-id tag can reach a row whose owner did not exist when the entry was written.

      Parameters

      • __namedParameters: { customerIds: readonly string[] | undefined }

      Returns string[]

    • Parameters

      • __namedParameters: {
            customerId: string;
            data: Partial<
                Omit<
                    Organization,
                    | "id"
                    | "type"
                    | "fullName"
                    | "countryCode"
                    | "name"
                    | "capabilities"
                    | "status"
                    | "createdAt"
                    | "updatedAt"
                    | "verificationProfileId",
                >,
            >;
            id: string;
        }

      Returns Promise<
          | {
              ok: true;
              value: {
                  achName: string;
                  address?: {
                      city: string;
                      countryCode: string;
                      line1: string;
                      line2?: string;
                      postalCode?: string;
                      regionCode?: string;
                  };
                  capabilities: (
                      | "TRANSACT"
                      | "MANAGE_PAYMENT_INSTRUMENT"
                      | "MANAGE_LEDGER_ACCOUNT"
                      | "MANAGE_DEPOSIT_MEMO"
                  )[];
                  countryCode: string;
                  countryOfIncorporation: string;
                  createdAt: Date;
                  deletedAt?: Date;
                  description?: string;
                  email?: string;
                  fullName: string;
                  id: string;
                  incorporationDate?: string;
                  legalEntityType: string;
                  name: string;
                  phone?: E164Phone;
                  referenceId?: string;
                  routeFusionEntity?: {
                      documentsUploadedAt?: string;
                      entityId: string;
                      lastFinalizeError?: { at: string; message: string }
                      | null;
                      programId?: string;
                      requiredDocuments?: string[][];
                      status: "PENDING" | "REJECTED" | "VERIFIED";
                  };
                  status: "ACTIVE"
                  | "DELETED"
                  | "DISABLED"
                  | "PENDING_VERIFICATION";
                  taxId: string;
                  type: "ORGANIZATION";
                  updatedAt: Date;
                  uuid: string;
                  verificationData?: {
                      status: "REVIEW" | "PENDING" | "APPROVED" | "DECLINED";
                      verificationSessionId?: string;
                      verificationTemplateId: string;
                  };
                  verificationProfileId?: string;
                  websiteUrl?: string;
                  wireName: string;
              };
          }
          | {
              error: | ServiceError<"INVALID_EMAIL" | "INVALID_WEBSITE_URL">
              | ServiceError<"NOT_FOUND" | "DUPLICATE">;
              ok: false;
          },
      >

    • The exact key OrganizationAdminQueryService.get reads through, for its includeDeleted: false callers.

      The includeDeleted: true variant hashes differently and is reached only by the collection tag, which every Valkey-backed environment has. That gap is deliberate and pre-existing: it only matters in memory mode, where no admin get runs with includeDeleted: true.

      Parameters

      • __namedParameters: { id: string }

      Returns Record<string, unknown>

    • The exact key OrganizationQueryService.get reads through.

      get folds onto search, so these args must stay identical to the ones it passes ({ customerId, ids: [id], pageSize: 1 }) plus the defaults search bakes into its own key — includeDeleted: false and page: 1. Every other filter is undefined there, and serviceCacheKey canonicalizes with JCS, which drops undefined properties. organizationCache.test.ts pins the equivalence.

      Parameters

      • __namedParameters: { customerId: string; id: string }

      Returns Record<string, unknown>