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

    Approval requests: create from a confirmed quote, read, decide and cancel. Recording the transactionApproval.* activities is the caller's job, as for the rule service; each write returns the activity to record. The last approval returns startExecution for the caller to act on after commit.

    Index
    db: B2bDatabase
    instance: (...args: []) => TransactionApprovalService = ...

    The process default: built from each dependency's own instance().

    • PENDING to CANCELLED, by the requester or a holder of settings/approvals:w.

      Parameters

      • __namedParameters: { actorId: string; customerId: string; reason: string; requestId: string }

      Returns Promise<
          | {
              ok: true;
              value: {
                  activity: TransactionApprovalActivity;
                  request: TransactionApprovalRequest;
              };
          }
          | {
              error: | ServiceError<
                  "REASON_REQUIRED"
                  | "REQUEST_NOT_FOUND"
                  | "ACTOR_NOT_ALLOWED",
              >
              | ServiceError<
                  "REQUEST_NOT_PENDING",
                  {
                      status: | "PENDING"
                      | "PROCESSING"
                      | "COMPLETED"
                      | "DECLINED"
                      | "FAILED"
                      | "CANCELLED";
                  },
              >;
              ok: false;
          },
      >

    • Creates a PENDING request from the ACTIVE quote the user confirmed. The requirements are re-derived here, never taken from the client, and the quote is left to expire. Files are promoted before the insert, outside any transaction.

      Parameters

      • __namedParameters: {
            cached: CachedTransactionMetadata | null;
            customerId: string;
            previousRequestId?: string;
            quoteId: string;
            requesterId: string;
        }

      Returns Promise<
          | {
              ok: true;
              value: {
                  activity: TransactionApprovalActivity;
                  request: TransactionApprovalRequest;
              };
          }
          | {
              error: | ServiceError<
                  | "QUOTE_NOT_ACTIVE"
                  | "QUOTE_EXPIRED"
                  | "QUOTE_MISMATCH"
                  | "UNSUPPORTED_QUOTE_METHOD"
                  | "INVALID_QUOTE"
                  | "PRODUCT_NOT_FOUND"
                  | "QUOTE_NOT_FOUND"
                  | "NO_APPROVAL_REQUIRED"
                  | "REQUESTER_NOT_MEMBER"
                  | "PREVIOUS_REQUEST_NOT_FOUND"
                  | "STAGING_FILE_NOT_FOUND",
              >
              | ServiceError<
                  "WALLET_SOURCE_NOT_SUPPORTED",
                  { rules: { ruleId: string; ruleName: string }[] },
              >
              | ServiceError<
                  "APPROVAL_UNSATISFIABLE",
                  { steps: { ruleId: string; ruleName: string; stepIndex: number }[] },
              >;
              ok: false;
          },
      >

    • Records approverId's decision under the request's row lock. An approval that completes every step moves the request to PROCESSING and returns startExecution; a decline moves it to DECLINED. Eligibility is read now: membership, the rail's keys and an open step the approver fits.

      Parameters

      • __namedParameters: {
            approverId: string;
            customerId: string;
            reason?: string;
            requestId: string;
            status: "DECLINED" | "APPROVED";
        }

      Returns Promise<
          | {
              ok: true;
              value: {
                  activity: TransactionApprovalActivity;
                  request: TransactionApprovalRequest;
                  startExecution: { approvalRequestId: string }
                  | null;
              };
          }
          | {
              error: | {
                  benign?: boolean;
                  code: | "REASON_REQUIRED"
                  | "REQUEST_NOT_FOUND"
                  | "APPROVER_IS_REQUESTER"
                  | "APPROVER_NOT_MEMBER"
                  | "APPROVER_LACKS_PERMISSION"
                  | "APPROVER_NOT_IN_OPEN_STEP"
                  | "ALREADY_DECIDED";
                  message?: string;
                  retryable: boolean;
              } & object
              | ServiceError<
                  "REQUEST_NOT_PENDING",
                  {
                      status: | "PENDING"
                      | "PROCESSING"
                      | "COMPLETED"
                      | "DECLINED"
                      | "FAILED"
                      | "CANCELLED";
                  },
              >;
              ok: false;
          },
      >

    • The Tasks tabs. WAITING_ON_YOU: PENDING requests with a step userId can satisfy and has not decided, plus PROCESSING requests userId approved (until BE-12 can tell which need an execution retry). MINE: the user's own requests. ALL: the workspace's. The first tab pages in memory: its candidates are the customer's open requests.

      Parameters

      • __namedParameters: {
            customerId: string;
            ids?: string[];
            includeSatisfiable?: boolean;
            page?: number;
            pageSize?: number;
            productIds?: string[];
            statuses?: (
                | "PENDING"
                | "PROCESSING"
                | "COMPLETED"
                | "DECLINED"
                | "FAILED"
                | "CANCELLED"
            )[];
            tab?: TransactionApprovalTab;
            transactionIds?: string[];
            userId: string;
        }
        • customerId: string
        • Optionalids?: string[]
        • OptionalincludeSatisfiable?: boolean
        • Optionalpage?: number
        • OptionalpageSize?: number
        • OptionalproductIds?: string[]
        • Optionalstatuses?: ("PENDING" | "PROCESSING" | "COMPLETED" | "DECLINED" | "FAILED" | "CANCELLED")[]
        • Optionaltab?: TransactionApprovalTab
        • OptionaltransactionIds?: string[]

          The transactions the requests executed; a request without one never matches.

        • userId: string

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