File size: 1,966 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
// Code generated by @openmeter/typespec-typescript. DO NOT EDIT.

import { type Client, http } from '../core.js'
import { type Result, type RequestOptions } from '../lib/types.js'
import { request } from '../lib/request.js'
import { toURLSearchParams } from '../lib/encodings.js'
import { toWire, fromWire, assertValid } from '../lib/wire.js'
import * as schemas from '../models/schemas.js'
import type {
  QueryGovernanceAccessRequest,
  QueryGovernanceAccessResponse,
} from '../models/operations/governance.js'

/**
 * Query governance access
 *
 * Query feature access for a list of customers.
 *
 * The endpoint resolves each provided identifier to a customer and returns the
 * access status for the requested features, plus optional credit balance
 * availability.
 *
 * _Designed to be called on a fixed refresh interval and the query response is
 * intended to be cached._
 *
 * POST /openmeter/governance/query
 */
export function queryGovernanceAccess(
  client: Client,
  req: QueryGovernanceAccessRequest,
  options?: RequestOptions,
): Promise<Result<QueryGovernanceAccessResponse>> {
  return request(() => {
    const body = toWire(req.body, schemas.queryGovernanceAccessBody)
    if (client._options.validate) {
      assertValid(schemas.queryGovernanceAccessBodyWire, body)
    }
    const query = toWire(
      {
        page: req.page,
      },
      schemas.queryGovernanceAccessQueryParams,
    )
    if (client._options.validate) {
      assertValid(schemas.queryGovernanceAccessQueryParamsWire, query)
    }
    const searchParams = toURLSearchParams(query)
    return http(client)
      .post('openmeter/governance/query', {
        ...options,
        searchParams,
        json: body,
      })
      .json()
      .then((data) => {
        if (client._options.validate) {
          assertValid(schemas.queryGovernanceAccessResponseWire, data)
        }
        return fromWire(data, schemas.queryGovernanceAccessResponse)
      })
  })
}