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

    Hierarchy (View Summary)

    Index
    db: B2bDatabase
    searchCache: ServiceCache<CachedBankTransactionSearch>
    timeseriesCache: ServiceCache<CachedBankBalanceTimeseries>
    • Self-bust the read caches after a write on the writer subclass. Drops the folded-get entry for this row by exact key (all-mode correct — works in memory mode, where tag invalidation no-ops), then the collection bust for every other cached search (a create/update can reshape any list). The folded-get key must match what search computes for get({ id }): all other filters undefined (dropped by serviceCacheKey), page 1, pageSize 1.

      Then the implied-balance timeseries for the row's correlation key. Takes the written ROW rather than its id because the timeseries cache has no per-key handle to drop — its keys carry the window bounds and timezone, which a write path cannot know — so the correlation tag is the only way in, and building it needs the row's routing / account / ffcMemo.

      A reconciliation-only update (a BANK_INTERNAL_TRANSFER stamp) does not move the gross implied balance, so this bust is sometimes redundant. Busting on every write anyway is correct and cheap; discriminating would be a way to be wrong.

      Parameters

      Returns Promise<void>

    • Parameters

      • __namedParameters: {
            accountNumber?: string;
            amount?: string;
            bankIds?: string[];
            bankTransactionIds?: string[];
            createdAt?: DbTimestampCriteria;
            id?: string[];
            methods?: (
                "BOOK_TRANSFER"
                | "ACH"
                | "ACH_DEBIT"
                | "RTP"
                | "SWIFT"
                | "FEDWIRE"
            )[];
            orderBy?: DbOrderByCriterion<
                Omit<
                    PgTableWithColumns<
                        {
                            columns: {
                                accountNumber: PgBuildColumn<
                                    "bank_transaction",
                                    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: "bank_transaction";
                                    },
                                >;
                                amount: PgBuildColumn<
                                    "bank_transaction",
                                    SetNotNull<PgNumericBuilder>,
                                    {
                                        data: string;
                                        dataType: "string numeric";
                                        driverParam: string;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "bank_transaction";
                                    },
                                >;
                                bankId: PgBuildColumn<
                                    "bank_transaction",
                                    Set$Type<SetNotNull<(...)>, string>,
                                    {
                                        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: "bank_transaction";
                                    },
                                >;
                                bankStatus: PgBuildColumn<
                                    "bank_transaction",
                                    Set$Type<SetNotNull<(...)>, "POSTED">,
                                    {
                                        data: "POSTED";
                                        dataType: "string";
                                        driverParam: string;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "bank_transaction";
                                    },
                                >;
                                bankTransactionId: PgBuildColumn<
                                    "bank_transaction",
                                    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: "bank_transaction";
                                    },
                                >;
                                createdAt: PgBuildColumn<
                                    "bank_transaction",
                                    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: "bank_transaction";
                                    },
                                >;
                                data: PgBuildColumn<
                                    "bank_transaction",
                                    Set$Type<
                                        SetHasDefault<(...)>,
                                        { isManual?: ...; methodData: ...; reconciliation: ... },
                                    >,
                                    {
                                        data: { isManual?: ...; methodData: ...; reconciliation: ... };
                                        dataType: "object json";
                                        driverParam: unknown;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: true;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "bank_transaction";
                                    },
                                >;
                                description: PgBuildColumn<
                                    "bank_transaction",
                                    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: "bank_transaction";
                                    },
                                >;
                                externalId: PgBuildColumn<
                                    "bank_transaction",
                                    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: "bank_transaction";
                                    },
                                >;
                                id: PgBuildColumn<
                                    "bank_transaction",
                                    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: "bank_transaction";
                                    },
                                >;
                                postedAt: PgBuildColumn<
                                    "bank_transaction",
                                    SetNotNull<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: true;
                                        tableName: "bank_transaction";
                                    },
                                >;
                                raw: PgBuildColumn<
                                    "bank_transaction",
                                    Set$Type<PgJsonbBuilder, BankTransactionRaw>,
                                    {
                                        data: BankTransactionRaw;
                                        dataType: "object json";
                                        driverParam: unknown;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: false;
                                        tableName: "bank_transaction";
                                    },
                                >;
                                routingNumber: PgBuildColumn<
                                    "bank_transaction",
                                    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: "bank_transaction";
                                    },
                                >;
                                statementDescription: PgBuildColumn<
                                    "bank_transaction",
                                    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: "bank_transaction";
                                    },
                                >;
                                type: PgBuildColumn<
                                    "bank_transaction",
                                    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: "bank_transaction";
                                    },
                                >;
                                updatedAt: PgBuildColumn<
                                    "bank_transaction",
                                    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: "bank_transaction";
                                    },
                                >;
                            };
                            dialect: "pg";
                            name: "bank_transaction";
                            schema: "b2b";
                        },
                    >,
                    "enableRLS",
                >,
                "amount"
                | "postedAt"
                | "createdAt"
                | "updatedAt",
            >[];
            page?: number;
            pageSize?: number;
            postedAt?: DbTimestampCriteria;
            q?: string;
            routingNumber?: string;
            status?: "POSTED" | "RECONCILED";
            tx?: PgAsyncTransaction<NodePgQueryResultHKT, EmptyRelations>;
            types?: ("CREDIT" | "DEBIT")[];
            updatedAt?: DbTimestampCriteria;
        }
        • OptionalaccountNumber?: string
        • Optionalamount?: string
        • OptionalbankIds?: string[]
        • OptionalbankTransactionIds?: string[]
        • OptionalcreatedAt?: DbTimestampCriteria
        • Optionalid?: string[]
        • Optionalmethods?: ("BOOK_TRANSFER" | "ACH" | "ACH_DEBIT" | "RTP" | "SWIFT" | "FEDWIRE")[]

          Filter on methodData.method — e.g. only the ACH debit postings.

        • OptionalorderBy?: DbOrderByCriterion<
              Omit<
                  PgTableWithColumns<
                      {
                          columns: {
                              accountNumber: PgBuildColumn<
                                  "bank_transaction",
                                  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: "bank_transaction";
                                  },
                              >;
                              amount: PgBuildColumn<
                                  "bank_transaction",
                                  SetNotNull<PgNumericBuilder>,
                                  {
                                      data: string;
                                      dataType: "string numeric";
                                      driverParam: string;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "bank_transaction";
                                  },
                              >;
                              bankId: PgBuildColumn<
                                  "bank_transaction",
                                  Set$Type<SetNotNull<(...)>, string>,
                                  {
                                      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: "bank_transaction";
                                  },
                              >;
                              bankStatus: PgBuildColumn<
                                  "bank_transaction",
                                  Set$Type<SetNotNull<(...)>, "POSTED">,
                                  {
                                      data: "POSTED";
                                      dataType: "string";
                                      driverParam: string;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "bank_transaction";
                                  },
                              >;
                              bankTransactionId: PgBuildColumn<
                                  "bank_transaction",
                                  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: "bank_transaction";
                                  },
                              >;
                              createdAt: PgBuildColumn<
                                  "bank_transaction",
                                  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: "bank_transaction";
                                  },
                              >;
                              data: PgBuildColumn<
                                  "bank_transaction",
                                  Set$Type<
                                      SetHasDefault<(...)>,
                                      { isManual?: ...; methodData: ...; reconciliation: ... },
                                  >,
                                  {
                                      data: { isManual?: ...; methodData: ...; reconciliation: ... };
                                      dataType: "object json";
                                      driverParam: unknown;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: true;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "bank_transaction";
                                  },
                              >;
                              description: PgBuildColumn<
                                  "bank_transaction",
                                  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: "bank_transaction";
                                  },
                              >;
                              externalId: PgBuildColumn<
                                  "bank_transaction",
                                  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: "bank_transaction";
                                  },
                              >;
                              id: PgBuildColumn<
                                  "bank_transaction",
                                  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: "bank_transaction";
                                  },
                              >;
                              postedAt: PgBuildColumn<
                                  "bank_transaction",
                                  SetNotNull<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: true;
                                      tableName: "bank_transaction";
                                  },
                              >;
                              raw: PgBuildColumn<
                                  "bank_transaction",
                                  Set$Type<PgJsonbBuilder, BankTransactionRaw>,
                                  {
                                      data: BankTransactionRaw;
                                      dataType: "object json";
                                      driverParam: unknown;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: false;
                                      tableName: "bank_transaction";
                                  },
                              >;
                              routingNumber: PgBuildColumn<
                                  "bank_transaction",
                                  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: "bank_transaction";
                                  },
                              >;
                              statementDescription: PgBuildColumn<
                                  "bank_transaction",
                                  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: "bank_transaction";
                                  },
                              >;
                              type: PgBuildColumn<
                                  "bank_transaction",
                                  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: "bank_transaction";
                                  },
                              >;
                              updatedAt: PgBuildColumn<
                                  "bank_transaction",
                                  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: "bank_transaction";
                                  },
                              >;
                          };
                          dialect: "pg";
                          name: "bank_transaction";
                          schema: "b2b";
                      },
                  >,
                  "enableRLS",
              >,
              "amount"
              | "postedAt"
              | "createdAt"
              | "updatedAt",
          >[]
        • Optionalpage?: number

          Defaults to 1

        • OptionalpageSize?: number

          Defaults to 10

        • OptionalpostedAt?: DbTimestampCriteria

          When the BANK posted the transaction — the only one of the three timestamps that is the bank's fact rather than ours. Correlating an external record (a wire notification, a statement line) against this table has to window on it: createdAt is when CFX happened to write the row, which for a hand-keyed row can be days off the money movement.

        • Optionalq?: string

          Free-text filter: case-insensitive substring match on bankTransactionId, description, and statementDescription; when it parses as a positive decimal it also matches the exact amount.

        • OptionalroutingNumber?: string
        • Optionalstatus?: "POSTED" | "RECONCILED"
        • Optionaltx?: PgAsyncTransaction<NodePgQueryResultHKT, EmptyRelations>
        • Optionaltypes?: ("CREDIT" | "DEBIT")[]
        • OptionalupdatedAt?: DbTimestampCriteria

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

    • The account's IMPLIED balance (credits − debits over its whole bank_transaction history) sampled at the CLOSE of every day in the window — the series behind the balance-over-time chart on the admin bank-account detail panel.

      Correlated on the same key as the bank_account_view balance lateral (bankAccountBalanceLateralSql), so the last point equals the panel's "Implied balance" figure exactly. A drift between the two would mislead an operator reconciling the account, which is why the correlation predicate is shared verbatim rather than re-derived.

      Windows and buckets on posted_at — the bank's fact. created_at is when CFX happened to write the row, which for a hand-keyed transaction can be days off the money movement.

      items is empty (rather than a flat zero line) when the key has NO matching transactions at all: § 6 of the bank_account_view design distinguishes "cannot be measured / nothing observed" from "measured as zero", and the chart must carry that distinction too.

      Parameters

      • __namedParameters: {
            accountNumber: string;
            blockTime: Exclude<Required<DbTimestampCriteria>, undefined>;
            memo?: string;
            routingNumber: string;
            timeZone?: string;
        }
        • accountNumber: string
        • blockTime: Exclude<Required<DbTimestampCriteria>, undefined>
        • Optionalmemo?: string

          FFC memo of a shared-FBO (deposit-memo) account. Narrows the correlation key to that memo's flow through the shared account.

        • routingNumber: string
        • OptionaltimeZone?: string

          IANA timezone (e.g. "America/Chicago"). Aligns day boundaries and localDate output to this timezone. Defaults to "UTC".

      Returns Promise<
          {
              ok: true;
              value: { items: BankBalanceTimeseriesItem[]; opening: BigNumber };
          },
      >

    • Parameters

      • args: {
            accountNumber: string;
            includeManual?: boolean;
            routingNumber: string;
            tx?: PgAsyncTransaction<NodePgQueryResultHKT, EmptyRelations>;
        }

      Returns Promise<{ ok: true; value: { txCount: number } }>