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

    Read-only interactions with API credentials belonging to customers

    Hierarchy (View Summary)

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

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

    • Parameters

      • args: { apiKeyName: string; customerId: string }

      Returns Promise<
          {
              ok: true;
              value: Omit<
                  {
                      apiKey: string;
                      apiSecret: string;
                      createdAt: Date;
                      customerExternalId: string;
                      customerId: number;
                      externalId: string;
                      id: number;
                      name: string;
                      replacedByExternalId: string
                      | null;
                      replacedById: number | null;
                      retireAt: Date | null;
                      updatedAt: Date;
                  },
                  | "id"
                  | "externalId"
                  | "customerId"
                  | "customerExternalId"
                  | "apiSecret"
                  | "replacedById"
                  | "replacedByExternalId"
                  | "retireAt",
              > & {
                  id: string;
                  supersededBy: { apiKeyId: string; retireAt: Date }
                  | null;
              } & { apiSecret: string };
          },
      >

    • Issues a replacement for id and marks the old key as superseded rather than deleting it — so a running integration keeps authenticating on the old credentials while it is updated. Finishing the rotation is delete on the old key, which the operator does once the new secret is deployed.

      The new secret is returned once, exactly as create does.

      Parameters

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

      Returns Promise<
          | {
              ok: true;
              value: Omit<
                  {
                      apiKey: string;
                      apiSecret: string;
                      createdAt: Date;
                      customerExternalId: string;
                      customerId: number;
                      externalId: string;
                      id: number;
                      name: string;
                      replacedByExternalId: string
                      | null;
                      replacedById: number | null;
                      retireAt: Date | null;
                      updatedAt: Date;
                  },
                  | "id"
                  | "externalId"
                  | "customerId"
                  | "customerExternalId"
                  | "apiSecret"
                  | "replacedById"
                  | "replacedByExternalId"
                  | "retireAt",
              > & {
                  id: string;
                  supersededBy: { apiKeyId: string; retireAt: Date }
                  | null;
              } & { apiSecret: string };
          }
          | {
              error: | ServiceError<"API_KEY_NOT_FOUND">
              | ServiceError<"API_KEY_ALREADY_SUPERSEDED">;
              ok: false;
          },
      >

    • Parameters

      • __namedParameters: {
            createdAt?: DbTimestampCriteria;
            customerId: string;
            orderBy?: DbOrderByCriterion<
                Omit<
                    PgTableWithColumns<
                        {
                            columns: {
                                apiKey: PgBuildColumn<
                                    "customer_api_key",
                                    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_api_key";
                                    },
                                >;
                                apiSecret: PgBuildColumn<
                                    "customer_api_key",
                                    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_api_key";
                                    },
                                >;
                                createdAt: PgBuildColumn<
                                    "customer_api_key",
                                    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_api_key";
                                    },
                                >;
                                customerExternalId: PgBuildColumn<
                                    "customer_api_key",
                                    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_api_key";
                                    },
                                >;
                                customerId: PgBuildColumn<
                                    "customer_api_key",
                                    SetNotNull<PgIntegerBuilder>,
                                    {
                                        data: number;
                                        dataType: "number int32";
                                        driverParam: (...) | (...);
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "customer_api_key";
                                    },
                                >;
                                externalId: PgBuildColumn<
                                    "customer_api_key",
                                    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_api_key";
                                    },
                                >;
                                id: PgBuildColumn<
                                    "customer_api_key",
                                    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_api_key";
                                    },
                                >;
                                name: PgBuildColumn<
                                    "customer_api_key",
                                    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_api_key";
                                    },
                                >;
                                replacedByExternalId: PgBuildColumn<
                                    "customer_api_key",
                                    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_api_key";
                                    },
                                >;
                                replacedById: PgBuildColumn<
                                    "customer_api_key",
                                    PgIntegerBuilder,
                                    {
                                        data: number;
                                        dataType: "number int32";
                                        driverParam: (...)
                                        | (...);
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: false;
                                        tableName: "customer_api_key";
                                    },
                                >;
                                retireAt: PgBuildColumn<
                                    "customer_api_key",
                                    PgTimestampBuilder,
                                    {
                                        data: Date;
                                        dataType: "object date";
                                        driverParam: string;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: false;
                                        tableName: "customer_api_key";
                                    },
                                >;
                                updatedAt: PgBuildColumn<
                                    "customer_api_key",
                                    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: "customer_api_key";
                                    },
                                >;
                            };
                            dialect: "pg";
                            isAlias: false;
                            name: "customer_api_key";
                            schema: "b2b";
                        },
                    >,
                    "enableRLS",
                >,
                "createdAt"
                | "updatedAt",
            >[];
            page?: number;
            pageSize?: number;
            updatedAt?: DbTimestampCriteria;
        }
        • OptionalcreatedAt?: DbTimestampCriteria
        • customerId: string
        • OptionalorderBy?: DbOrderByCriterion<
              Omit<
                  PgTableWithColumns<
                      {
                          columns: {
                              apiKey: PgBuildColumn<
                                  "customer_api_key",
                                  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_api_key";
                                  },
                              >;
                              apiSecret: PgBuildColumn<
                                  "customer_api_key",
                                  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_api_key";
                                  },
                              >;
                              createdAt: PgBuildColumn<
                                  "customer_api_key",
                                  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_api_key";
                                  },
                              >;
                              customerExternalId: PgBuildColumn<
                                  "customer_api_key",
                                  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_api_key";
                                  },
                              >;
                              customerId: PgBuildColumn<
                                  "customer_api_key",
                                  SetNotNull<PgIntegerBuilder>,
                                  {
                                      data: number;
                                      dataType: "number int32";
                                      driverParam: (...) | (...);
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "customer_api_key";
                                  },
                              >;
                              externalId: PgBuildColumn<
                                  "customer_api_key",
                                  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_api_key";
                                  },
                              >;
                              id: PgBuildColumn<
                                  "customer_api_key",
                                  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_api_key";
                                  },
                              >;
                              name: PgBuildColumn<
                                  "customer_api_key",
                                  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_api_key";
                                  },
                              >;
                              replacedByExternalId: PgBuildColumn<
                                  "customer_api_key",
                                  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_api_key";
                                  },
                              >;
                              replacedById: PgBuildColumn<
                                  "customer_api_key",
                                  PgIntegerBuilder,
                                  {
                                      data: number;
                                      dataType: "number int32";
                                      driverParam: (...)
                                      | (...);
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: false;
                                      tableName: "customer_api_key";
                                  },
                              >;
                              retireAt: PgBuildColumn<
                                  "customer_api_key",
                                  PgTimestampBuilder,
                                  {
                                      data: Date;
                                      dataType: "object date";
                                      driverParam: string;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: false;
                                      tableName: "customer_api_key";
                                  },
                              >;
                              updatedAt: PgBuildColumn<
                                  "customer_api_key",
                                  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: "customer_api_key";
                                  },
                              >;
                          };
                          dialect: "pg";
                          isAlias: false;
                          name: "customer_api_key";
                          schema: "b2b";
                      },
                  >,
                  "enableRLS",
              >,
              "createdAt"
              | "updatedAt",
          >[]
        • Optionalpage?: number

          Defaults to 1

        • OptionalpageSize?: number

          Defaults to 50

        • OptionalupdatedAt?: DbTimestampCriteria

      Returns Promise<{ ok: true; value: { hasNext: boolean; items: CustomerApiKey[] } }>

      List of API keys with their associated customers

    • Renames the key; the same name again writes and publishes nothing.

      Parameters

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

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