File size: 3,507 Bytes
1477a90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Code generated by @openmeter/typespec-typescript. DO NOT EDIT.

import { type Client } from '../core.js'
import { unwrap, type RequestOptions } from '../lib/types.js'
import { paginatePages } from '../lib/paginate.js'
import {
  listBillingProfiles,
  createBillingProfile,
  getBillingProfile,
  updateBillingProfile,
  deleteBillingProfile,
} from '../funcs/billing.js'
import type {
  ListBillingProfilesRequest,
  ListBillingProfilesResponse,
  CreateBillingProfileRequest,
  CreateBillingProfileResponse,
  GetBillingProfileRequest,
  GetBillingProfileResponse,
  UpdateBillingProfileRequest,
  UpdateBillingProfileResponse,
  DeleteBillingProfileRequest,
  DeleteBillingProfileResponse,
} from '../models/operations/billing.js'
import type { Profile } from '../models/types.js'

export class Billing {
  constructor(private readonly _client: Client) {}

  /**
   * List billing profiles
   *
   * List billing profiles.
   *
   * GET /openmeter/profiles
   */
  async listProfiles(
    request?: ListBillingProfilesRequest,
    options?: RequestOptions,
  ): Promise<ListBillingProfilesResponse> {
    return unwrap(await listBillingProfiles(this._client, request, options))
  }

  /**
   * List billing profiles
   *
   * List billing profiles.
   *
   * Iterates every item across all pages, fetching more as the returned iterable is consumed.
   *
   * GET /openmeter/profiles
   */
  listProfilesAll(
    request?: ListBillingProfilesRequest,
    options?: RequestOptions,
  ): AsyncIterable<Profile> {
    return paginatePages(
      (req, opts) => listBillingProfiles(this._client, req, opts),
      request ?? {},
      options,
    )
  }

  /**
   * Create a new billing profile
   *
   * Create a new billing profile.
   *
   * Billing profiles contain the settings for billing and controls invoice
   * generation. An organization can have multiple billing profiles defined. A
   * billing profile is linked to a specific app. This association is established
   * during the billing profile's creation and remains immutable.
   *
   * POST /openmeter/profiles
   */
  async createProfile(
    request: CreateBillingProfileRequest,
    options?: RequestOptions,
  ): Promise<CreateBillingProfileResponse> {
    return unwrap(await createBillingProfile(this._client, request, options))
  }

  /**
   * Get a billing profile
   *
   * Get a billing profile.
   *
   * GET /openmeter/profiles/{id}
   */
  async getProfile(
    request: GetBillingProfileRequest,
    options?: RequestOptions,
  ): Promise<GetBillingProfileResponse> {
    return unwrap(await getBillingProfile(this._client, request, options))
  }

  /**
   * Update a billing profile
   *
   * Update a billing profile.
   *
   * PUT /openmeter/profiles/{id}
   */
  async updateProfile(
    request: UpdateBillingProfileRequest,
    options?: RequestOptions,
  ): Promise<UpdateBillingProfileResponse> {
    return unwrap(await updateBillingProfile(this._client, request, options))
  }

  /**
   * Delete a billing profile
   *
   * Delete a billing profile.
   *
   * Only such billing profiles can be deleted that are:
   *
   * - not the default profile
   * - not pinned to any customer using customer overrides
   * - only have finalized invoices
   *
   * DELETE /openmeter/profiles/{id}
   */
  async deleteProfile(
    request: DeleteBillingProfileRequest,
    options?: RequestOptions,
  ): Promise<DeleteBillingProfileResponse> {
    return unwrap(await deleteBillingProfile(this._client, request, options))
  }
}