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

    A self-serve application: the basics, then a pointer to the applicant's AiPrise business profile and hosted session. Session URLs are never stored.

    Hierarchy (View Summary)

    Index
    • Parameters

      • args: {
            aiPriseClient: Pick<
                AiPriseClient,
                | "createBusinessProfile"
                | "createVerificationSessionUrlForBusinessProfile"
                | "renewBusinessVerificationUrl"
                | "verifyOrigin",
            >;
            db: B2bDatabase;
            internalEventPublisher: Pick<InternalEventPublisher, "publish">;
            logger?: Pick<Console, "warn" | "error">;
            verificationTemplateService: Pick<VerificationTemplateService, "search">;
            workspaceAdminService: Pick<
                CustomerDashboardWorkspaceAdminService,
                "createForApplicant",
            >;
        }
        • aiPriseClient: Pick<
              AiPriseClient,
              | "createBusinessProfile"
              | "createVerificationSessionUrlForBusinessProfile"
              | "renewBusinessVerificationUrl"
              | "verifyOrigin",
          >
        • db: B2bDatabase
        • internalEventPublisher: Pick<InternalEventPublisher, "publish">

          Tells the applicant's workspace, by email, as the application moves.

        • Optionallogger?: Pick<Console, "warn" | "error">
        • verificationTemplateService: Pick<VerificationTemplateService, "search">
        • workspaceAdminService: Pick<CustomerDashboardWorkspaceAdminService, "createForApplicant">

      Returns CustomerApplicationService

    db: B2bDatabase
    logger: Pick<Console, "warn" | "error">
    instance: (...args: []) => CustomerApplicationService = ...

    The process service: the shared database, AiPrise and the internal bus.

    • Whether userId may start an application: not while one of theirs (screened out included) is where they belong, nor once they are an ACTIVE member of a customer. Membership of another ACTIVE customer outranks their own application: an applicant invited into one belongs in its dashboard.

      Parameters

      • __namedParameters: { userId: string }

      Returns Promise<
          | { eligible: true }
          | {
              application: CustomerApplication;
              eligible: false;
              reason: "HAS_APPLICATION";
          }
          | { eligible: false; reason: "CUSTOMER_MEMBER" },
      >

    • The provisioning workflow calls this when it fails before the customer row exists: PROVISIONING becomes FAILED. Idempotent; marked is false when nothing changed.

      Parameters

      • __namedParameters: { customerId: string }

      Returns Promise<{ ok: true; value: { marked: boolean } }>

    • The provisioning workflow's last step: PROVISIONING becomes PROVISIONED. Idempotent; marked is false when nothing changed.

      Parameters

      • __namedParameters: { customerId: string }

      Returns Promise<{ ok: true; value: { marked: boolean } }>

    • The customer provisioning made from an application went ACTIVE: tell the workspace its account is ready. Call only from the write that activated it, so it is sent once. notified is false for an operator-path customer.

      Parameters

      • __namedParameters: { customerId: string }

      Returns Promise<{ ok: true; value: { notified: boolean } }>

    • The framed form's URL for an ACTIVE member of the application's workspace. Rebuilds the stored session's URL, renewing it when under a day is left; only a DRAFT asks AiPrise for a session, getting its profile too.

      Parameters

      • __namedParameters: Applicant & ReturnOrigin & { id: string }

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

    • A refresh of the application's AiPrise profile has been written: when it moved the application into review, an information request or a decline, tell the workspace. previous is the shadow the refresh's own write replaced, so a duplicate delivery, which replaces an identical row, finds no change. notified is false when nothing was published.

      Parameters

      • __namedParameters: {
            previous:
                | {
                    lifecycleStatus: | "PROFILE_NOT_SUBMITTED"
                    | "ONBOARDING_SESSIONS_PENDING"
                    | "READY_FOR_REVIEW"
                    | "ADDITIONAL_INFO_REQUESTED"
                    | "MONITORING_UPDATES"
                    | "SESSIONS_EXPIRED"
                    | null;
                    result: | "DECLINED"
                    | "APPROVED"
                    | "REVIEW"
                    | "UNKNOWN"
                    | "DEACTIVATED"
                    | null;
                }
                | null;
            verificationProfileId: string;
        }

      Returns Promise<{ ok: true; value: { notified: boolean } }>

    • Basics and screener in one submit: screened out, or a workspace the applicant owns, an AiPrise profile and a session. An AiPrise failure throws and leaves the row DRAFT, which openSession resumes.

      Parameters

      Returns Promise<
          | { ok: true; value: CustomerApplication }
          | {
              error:
                  | ServiceError<"INVALID_BASICS", { field: keyof ApplicationBasics }>
                  | ServiceError<
                      "SHORT_NAME_TAKEN"
                      | "ALREADY_APPLYING"
                      | "ALREADY_CUSTOMER_MEMBER",
                  >;
              ok: false;
          },
      >

    • The one write to an existing application. only and unless make it a compare-and-set: the row changes only while its status is only's, and while that column is still null, its status is not yet the one named, or no customer holds its workspace. True when a row changed.

      Parameters

      • __namedParameters: {
            id: number;
            only?: { statuses: CustomerApplicationStatus[] };
            set: Partial<
                Pick<
                    SelectCustomerApplication,
                    | "status"
                    | "verificationProfileId"
                    | "verificationSessionId"
                    | "verificationSessionExpiresAt"
                    | "attioId",
                >,
            >;
            unless?: | { set: "verificationProfileId"
            | "verificationSessionId" }
            | { status: CustomerApplicationStatus }
            | { customer: "exists" };
        }
      • db: Executor = ...

      Returns Promise<boolean>