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

    Constructors

    Methods

    Constructors

    • eventPublisher is optional because most consumers only use get / search / update and never need to publish. create() does publish organization.organization.created on the verified path and asserts the publisher is wired — wire it in main.ts for any service that calls create() (today: internal-dashboard's createCustomer flow).

      Parameters

      Returns CustomerService

    Methods

    • Create a customer together with its primary organization in one transaction.

      The Customer↔Organization mutual FK (customer.organization_id ⇄ organization.customer_id) means neither row can be inserted standalone with both ends populated. This method inserts the customer (with organizationId NULL), inserts the organization with the new customer's id, then updates the customer to point at the organization — all inside a single transaction. Under READ COMMITTED (the Postgres default) no other session can observe the intermediate state: the in-flight tx doesn't publish its writes until commit, and get()/search() inner-join organization so a customer with NULL organizationId would be filtered out anyway.

      When organization.verificationProfileId is set, the org is created ACTIVE and an organization.organization.created event is published after commit — matching the deleted OrganizationAdminService.createVerified path. When omitted, the org is PENDING_VERIFICATION and no event is published; callers must drive verification through OrganizationService.

      Parameters

      • __namedParameters: Omit<
            Customer,
            | "id"
            | "status"
            | "createdAt"
            | "updatedAt"
            | "organizationId"
            | "legalEntityName",
        > & {
            id?: string;
            organization: {
                address: {
                    city: string;
                    countryCode: string;
                    line1: string;
                    line2?: string;
                    postalCode: string;
                    regionCode?: string;
                };
                countryOfIncorporation: string;
                description?: string;
                email?: string;
                legalEntityType: string;
                name: string;
                phone?: E164Phone;
                referenceId?: string;
                taxId: string;
                verificationProfileId?: string;
                websiteUrl?: string;
            };
        }
        • Optionalid?: string

          Optional pre-generated external id (cust_…). When provided it's inserted as externalId, overriding the nanoId("cust") column default — lets a caller (e.g. createCustomerWorkflow) mint the id up front and reuse it as the Temporal workflowId. Omit to auto-generate.

        • organization: {
              address: {
                  city: string;
                  countryCode: string;
                  line1: string;
                  line2?: string;
                  postalCode: string;
                  regionCode?: string;
              };
              countryOfIncorporation: string;
              description?: string;
              email?: string;
              legalEntityType: string;
              name: string;
              phone?: E164Phone;
              referenceId?: string;
              taxId: string;
              verificationProfileId?: string;
              websiteUrl?: string;
          }
          • address: {
                city: string;
                countryCode: string;
                line1: string;
                line2?: string;
                postalCode: string;
                regionCode?: string;
            }
            • city: string
            • countryCode: string
            • line1: string
            • Optionalline2?: string
            • postalCode: string
            • OptionalregionCode?: string

              e.g. US state

          • countryOfIncorporation: string
          • Optionaldescription?: string
          • Optionalemail?: string
          • legalEntityType: string
          • name: string
          • Optionalphone?: E164Phone
          • OptionalreferenceId?: string
          • taxId: string
          • OptionalverificationProfileId?: string

            When set, the organization is created as ACTIVE with this id stored in data.verificationProfileId (mirroring OrganizationAdminService.createVerified). When omitted, the organization is created PENDING_VERIFICATION and the caller is expected to drive verification through OrganizationService.verify.

          • OptionalwebsiteUrl?: string

      Returns Promise<{ ok: true; value: Customer }>

    • Parameters

      • __namedParameters: {
            ids?: string[];
            name?: string;
            nameLike?: string;
            orderBy?: DbOrderByCriterion<
                Omit<
                    PgTableWithColumns<
                        {
                            columns: {
                                attioId: PgBuildColumn<
                                    "customer",
                                    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: "customer";
                                    },
                                >;
                                createdAt: PgBuildColumn<
                                    "customer",
                                    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: "customer";
                                    },
                                >;
                                data: PgBuildColumn<
                                    "customer",
                                    Set$Type<
                                        SetHasDefault<(...)>,
                                        { bankPartners?: ...; verificationByo?: ... },
                                    >,
                                    {
                                        data: { bankPartners?: ...; verificationByo?: ... };
                                        dataType: "object json";
                                        driverParam: unknown;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: true;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "customer";
                                    },
                                >;
                                description: PgBuildColumn<
                                    "customer",
                                    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: "customer";
                                    },
                                >;
                                externalId: PgBuildColumn<
                                    "customer",
                                    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: "customer";
                                    },
                                >;
                                id: PgBuildColumn<
                                    "customer",
                                    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: "customer";
                                    },
                                >;
                                name: PgBuildColumn<
                                    "customer",
                                    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: "customer";
                                    },
                                >;
                                notifications: PgBuildColumn<
                                    "customer",
                                    Set$Type<PgJsonbBuilder, { email?: ...; slack?: ... }>,
                                    {
                                        data: { email?: ...; slack?: ... };
                                        dataType: "object json";
                                        driverParam: unknown;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: false;
                                        tableName: "customer";
                                    },
                                >;
                                organizationId: PgBuildColumn<
                                    "customer",
                                    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: "customer";
                                    },
                                >;
                                propelauthWorkspaceId: PgBuildColumn<
                                    "customer",
                                    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: "customer";
                                    },
                                >;
                                shortName: PgBuildColumn<
                                    "customer",
                                    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: "customer";
                                    },
                                >;
                                status: PgBuildColumn<
                                    "customer",
                                    SetHasDefault<Set$Type<(...), (...)>>,
                                    {
                                        data: (...) | (...) | (...);
                                        dataType: "string";
                                        driverParam: string;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: true;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "customer";
                                    },
                                >;
                                terms: PgBuildColumn<
                                    "customer",
                                    Set$Type<PgJsonbBuilder, Partial<(...)>>,
                                    {
                                        data: TData;
                                        dataType: "object json";
                                        driverParam: unknown;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: false;
                                        tableName: "customer";
                                    },
                                >;
                                updatedAt: PgBuildColumn<
                                    "customer",
                                    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: "customer";
                                    },
                                >;
                            };
                            dialect: "pg";
                            name: "customer";
                            schema: "b2b";
                        },
                    >,
                    "enableRLS",
                >,
                "createdAt"
                | "updatedAt",
            >[];
            page?: number;
            pageSize?: number;
            propelauthWorkspaceIds?: string[];
            q?: string;
        }
        • Optionalids?: string[]
        • Optionalname?: string
        • OptionalnameLike?: string
        • OptionalorderBy?: DbOrderByCriterion<
              Omit<
                  PgTableWithColumns<
                      {
                          columns: {
                              attioId: PgBuildColumn<
                                  "customer",
                                  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: "customer";
                                  },
                              >;
                              createdAt: PgBuildColumn<
                                  "customer",
                                  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: "customer";
                                  },
                              >;
                              data: PgBuildColumn<
                                  "customer",
                                  Set$Type<
                                      SetHasDefault<(...)>,
                                      { bankPartners?: ...; verificationByo?: ... },
                                  >,
                                  {
                                      data: { bankPartners?: ...; verificationByo?: ... };
                                      dataType: "object json";
                                      driverParam: unknown;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: true;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "customer";
                                  },
                              >;
                              description: PgBuildColumn<
                                  "customer",
                                  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: "customer";
                                  },
                              >;
                              externalId: PgBuildColumn<
                                  "customer",
                                  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: "customer";
                                  },
                              >;
                              id: PgBuildColumn<
                                  "customer",
                                  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: "customer";
                                  },
                              >;
                              name: PgBuildColumn<
                                  "customer",
                                  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: "customer";
                                  },
                              >;
                              notifications: PgBuildColumn<
                                  "customer",
                                  Set$Type<PgJsonbBuilder, { email?: ...; slack?: ... }>,
                                  {
                                      data: { email?: ...; slack?: ... };
                                      dataType: "object json";
                                      driverParam: unknown;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: false;
                                      tableName: "customer";
                                  },
                              >;
                              organizationId: PgBuildColumn<
                                  "customer",
                                  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: "customer";
                                  },
                              >;
                              propelauthWorkspaceId: PgBuildColumn<
                                  "customer",
                                  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: "customer";
                                  },
                              >;
                              shortName: PgBuildColumn<
                                  "customer",
                                  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: "customer";
                                  },
                              >;
                              status: PgBuildColumn<
                                  "customer",
                                  SetHasDefault<Set$Type<(...), (...)>>,
                                  {
                                      data: (...) | (...) | (...);
                                      dataType: "string";
                                      driverParam: string;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: true;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "customer";
                                  },
                              >;
                              terms: PgBuildColumn<
                                  "customer",
                                  Set$Type<PgJsonbBuilder, Partial<(...)>>,
                                  {
                                      data: TData;
                                      dataType: "object json";
                                      driverParam: unknown;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: false;
                                      tableName: "customer";
                                  },
                              >;
                              updatedAt: PgBuildColumn<
                                  "customer",
                                  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: "customer";
                                  },
                              >;
                          };
                          dialect: "pg";
                          name: "customer";
                          schema: "b2b";
                      },
                  >,
                  "enableRLS",
              >,
              "createdAt"
              | "updatedAt",
          >[]
        • Optionalpage?: number

          Defaults to 1

        • OptionalpageSize?: number

          Defaults to 50

        • OptionalpropelauthWorkspaceIds?: string[]
        • Optionalq?: string

          Unified free-text search. Case-insensitive substring match against the customer name, the customer external id (cust_…), or the legal entity (organization) name. Whitespace-only values are a no-op.

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

    • Parameters

      • __namedParameters: Partial<
            Pick<Customer, "name" | "status" | "description"> & {
                aipriseIdentityPersonProfileAmlTemplateId: string;
                aipriseIdentityPersonProfileIdentityDocumentTemplateId: string;
                aipriseOrganizationBusinessProfileTemplateId: string;
                aiprisePaymentInstrumentBusinessProfileTemplateId: string;
                aiprisePaymentInstrumentPersonProfileTemplateId: string;
            },
        > & ({ id: string } | { propelauthWorkspaceId: string })

      Returns Promise<{ ok: true; value: Customer } | { error: ServiceError; ok: false }>