1 | |
2 | type Brex = { |
3 | token: string; |
4 | }; |
5 | |
6 | * |
7 | Create Spend Limit |
8 |
|
9 | * |
10 | Creates a Spend Limit |
11 |
|
12 | */ |
13 | export async function main( |
14 | auth: Brex, |
15 | Idempotency_Key: string, |
16 | body: { |
17 | name: string; |
18 | description?: string; |
19 | parent_budget_id?: string; |
20 | period_recurrence_type: |
21 | | ("PER_WEEK" & {}) |
22 | | ("PER_MONTH" & {}) |
23 | | ("PER_QUARTER" & {}) |
24 | | ("PER_YEAR" & {}) |
25 | | ("ONE_TIME" & {}); |
26 | start_date?: string; |
27 | end_date?: string; |
28 | authorization_settings: { |
29 | base_limit: { amount: number; currency?: string } & {}; |
30 | limit_buffer_percentage?: number; |
31 | authorization_type: ("HARD" & {}) | ("SOFT" & {}); |
32 | rollover_refresh_rate: |
33 | | ("PER_MONTH" & {}) |
34 | | ("PER_QUARTER" & {}) |
35 | | ("PER_YEAR" & {}) |
36 | | ("OFF" & {}) |
37 | | ("NEVER" & {}); |
38 | } & {}; |
39 | expense_visibility: ("SHARED" & {}) | ("PRIVATE" & {}); |
40 | authorization_visibility: ("PRIVATE" & {}) | ("PUBLIC" & {}); |
41 | transaction_limit?: { amount: number; currency?: string } & {}; |
42 | limit_increase_setting: ("ENABLED" & {}) | ("DISABLED" & {}); |
43 | spend_type: |
44 | | ("BUDGET_PROVISIONED_CARDS_ONLY" & {}) |
45 | | ("NON_BUDGET_PROVISIONED_CARDS_ALLOWED" & {}); |
46 | auto_transfer_cards_setting: ("ENABLED" & {}) | ("DISABLED" & {}); |
47 | auto_create_limit_cards_setting: ("DISABLED" & {}) | ("ALL_MEMBERS" & {}); |
48 | owner_user_ids?: string[]; |
49 | member_user_ids?: string[]; |
50 | expense_policy_id: string; |
51 | limit_increase_request_policy_id?: string; |
52 | limit_approval_policy_id?: string; |
53 | legal_entity_id?: string; |
54 | department_id?: string; |
55 | }, |
56 | ) { |
57 | const url = new URL(`https://platform.brexapis.com/v2/spend_limits`); |
58 |
|
59 | const response = await fetch(url, { |
60 | method: "POST", |
61 | headers: { |
62 | "Idempotency-Key": Idempotency_Key, |
63 | "Content-Type": "application/json", |
64 | Authorization: "Bearer " + auth.token, |
65 | }, |
66 | body: JSON.stringify(body), |
67 | }); |
68 | if (!response.ok) { |
69 | const text = await response.text(); |
70 | throw new Error(`${response.status} ${text}`); |
71 | } |
72 | return await response.json(); |
73 | } |
74 |
|