d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (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 / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (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)
|
|
}
|