6bf8bebf51
CI / Test and Build (push) Failing after 1s
CI / Migrate Dev DB (push) Has been skipped
CI / Migrate DB (push) Has been skipped
CodeQL / Analyze actions (push) Has been cancelled
CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI / Detect Version (push) Has been cancelled
CI / Detect Desktop Changes (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/cron.Dockerfile, ubuntu-latest, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build AMD64 (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/cron.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/db.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/pii.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/realtime.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-8vcpu-ubuntu-2404-arm, ./docker/app.Dockerfile, linux-arm64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
Helm Chart / Lint, test, and validate chart (push) Has been cancelled
Helm Chart / Chart version bumped (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Build Dev ECR (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core) (push) Has been cancelled
CI / Promote Images (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Check Desktop Signing Secrets (push) Has been cancelled
CI / Desktop Release (push) Has been cancelled
CI / Create Desktop Prerelease (push) Has been cancelled
CI / Desktop Prerelease Build (push) Has been cancelled
CI / Publish Desktop Prerelease (push) Has been cancelled
CI / Prune Desktop Prereleases (push) Has been cancelled
Helm Chart / Install on kind and run helm test (push) Has been cancelled
79 lines
2.3 KiB
TypeScript
79 lines
2.3 KiB
TypeScript
export const BREX_API_BASE = 'https://api.brex.com'
|
|
|
|
/**
|
|
* Builds the standard headers for Brex API requests.
|
|
*/
|
|
export function buildBrexHeaders(apiKey: string): Record<string, string> {
|
|
return {
|
|
Authorization: `Bearer ${apiKey}`,
|
|
Accept: 'application/json',
|
|
'Content-Type': 'application/json',
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Parses a Brex API response body, throwing a descriptive error for non-2xx responses.
|
|
*/
|
|
export async function parseBrexJson(response: Response) {
|
|
if (!response.ok) {
|
|
const text = await response.text()
|
|
let message = text
|
|
try {
|
|
const parsed = JSON.parse(text)
|
|
message = parsed.message ?? text
|
|
} catch {
|
|
message = text
|
|
}
|
|
throw new Error(`Brex API error (${response.status}): ${message}`)
|
|
}
|
|
return response.json()
|
|
}
|
|
|
|
/**
|
|
* Appends a comma-separated value as repeated query parameters (Brex array syntax).
|
|
*/
|
|
export function appendBrexArrayParam(query: URLSearchParams, key: string, value?: string): void {
|
|
if (!value) return
|
|
for (const item of value.split(',')) {
|
|
const trimmed = item.trim()
|
|
if (trimmed) query.append(key, trimmed)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Appends standard cursor/limit pagination parameters to a query.
|
|
*/
|
|
export function appendBrexPagination(
|
|
query: URLSearchParams,
|
|
params: { cursor?: string; limit?: string }
|
|
): void {
|
|
if (params.cursor) query.append('cursor', params.cursor)
|
|
if (params.limit) query.append('limit', params.limit)
|
|
}
|
|
|
|
/**
|
|
* Splits a comma-separated string of IDs into a trimmed, non-empty array for
|
|
* use in a JSON request body (as opposed to repeated query parameters).
|
|
*/
|
|
export function splitBrexIdList(value?: string): string[] | undefined {
|
|
if (!value) return undefined
|
|
const ids = value
|
|
.split(',')
|
|
.map((id) => id.trim())
|
|
.filter(Boolean)
|
|
return ids.length > 0 ? ids : undefined
|
|
}
|
|
|
|
/**
|
|
* Converts a timestamp to the timezone-less date-time form the Brex Transactions
|
|
* API requires (e.g., 2026-01-01T00:00:00). Brex rejects timezone-suffixed
|
|
* timestamps on these endpoints, so offsets are converted to UTC and stripped.
|
|
*/
|
|
export function toBrexDateTime(value: string): string {
|
|
const trimmed = value.trim()
|
|
if (!/(?:z|[+-]\d{2}:?\d{2})$/i.test(trimmed)) return trimmed
|
|
const parsed = new Date(trimmed)
|
|
if (Number.isNaN(parsed.getTime())) return trimmed
|
|
return parsed.toISOString().slice(0, 19)
|
|
}
|