@elmohq/sdk 0.0.0-claim → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +325 -2
  3. package/dist/calls/index.d.mts +288 -0
  4. package/dist/calls/index.d.mts.map +1 -0
  5. package/dist/calls/index.mjs +390 -0
  6. package/dist/calls/index.mjs.map +1 -0
  7. package/dist/index.d.mts +2 -0
  8. package/dist/index.mjs +1029 -0
  9. package/dist/index.mjs.map +1 -0
  10. package/dist/request-options-DWYI_Ldj.d.mts +1550 -0
  11. package/dist/request-options-DWYI_Ldj.d.mts.map +1 -0
  12. package/dist/tools-7Hs5J2xb.d.mts +1945 -0
  13. package/dist/tools-7Hs5J2xb.d.mts.map +1 -0
  14. package/dist/tools-SwP0sK8H.mjs +2458 -0
  15. package/dist/tools-SwP0sK8H.mjs.map +1 -0
  16. package/dist/types/index.d.mts +2 -0
  17. package/dist/types/index.mjs +1 -0
  18. package/package.json +59 -2
  19. package/src/calls/brands-analytics-get.ts +33 -0
  20. package/src/calls/brands-citations-domains-list.ts +36 -0
  21. package/src/calls/brands-citations-urls-list.ts +32 -0
  22. package/src/calls/brands-create.ts +19 -0
  23. package/src/calls/brands-get.ts +19 -0
  24. package/src/calls/brands-list.ts +18 -0
  25. package/src/calls/brands-opportunities-get.ts +42 -0
  26. package/src/calls/brands-prompt-performance-list.ts +39 -0
  27. package/src/calls/brands-query-fanout-get.ts +30 -0
  28. package/src/calls/brands-tags-list.ts +28 -0
  29. package/src/calls/brands-update.ts +20 -0
  30. package/src/calls/competitors-create.ts +23 -0
  31. package/src/calls/competitors-delete.ts +19 -0
  32. package/src/calls/competitors-get.ts +19 -0
  33. package/src/calls/competitors-list.ts +23 -0
  34. package/src/calls/competitors-update.ts +24 -0
  35. package/src/calls/index.ts +33 -0
  36. package/src/calls/me-get.ts +18 -0
  37. package/src/calls/models-list.ts +20 -0
  38. package/src/calls/organizations-billing-get.ts +37 -0
  39. package/src/calls/organizations-get.ts +24 -0
  40. package/src/calls/organizations-list.ts +27 -0
  41. package/src/calls/prompts-create.ts +27 -0
  42. package/src/calls/prompts-delete.ts +28 -0
  43. package/src/calls/prompts-get.ts +23 -0
  44. package/src/calls/prompts-list.ts +28 -0
  45. package/src/calls/prompts-runs-get.ts +27 -0
  46. package/src/calls/prompts-runs-list.ts +30 -0
  47. package/src/calls/prompts-snapshot-get.ts +28 -0
  48. package/src/calls/prompts-update.ts +29 -0
  49. package/src/calls/reports-create.ts +31 -0
  50. package/src/calls/reports-get.ts +27 -0
  51. package/src/calls/reports-list.ts +28 -0
  52. package/src/calls/tools-analyze.ts +26 -0
  53. package/src/client.ts +662 -0
  54. package/src/index.ts +21 -0
  55. package/src/internal/binding/rest/binding.ts +127 -0
  56. package/src/internal/binding/rest/errors.ts +107 -0
  57. package/src/internal/binding/rest/path.ts +9 -0
  58. package/src/internal/binding/rest/url.ts +97 -0
  59. package/src/internal/codec/json.ts +66 -0
  60. package/src/internal/codec/registry.ts +55 -0
  61. package/src/internal/core/backoff.ts +170 -0
  62. package/src/internal/core/body.ts +54 -0
  63. package/src/internal/core/browser.ts +11 -0
  64. package/src/internal/core/call-promise.ts +145 -0
  65. package/src/internal/core/callable.ts +11 -0
  66. package/src/internal/core/client.ts +89 -0
  67. package/src/internal/core/config.ts +84 -0
  68. package/src/internal/core/credentials.ts +40 -0
  69. package/src/internal/core/dispatch.ts +227 -0
  70. package/src/internal/core/env.ts +68 -0
  71. package/src/internal/core/errors.ts +431 -0
  72. package/src/internal/core/features.ts +60 -0
  73. package/src/internal/core/lazy-promise.ts +39 -0
  74. package/src/internal/core/metadata.ts +79 -0
  75. package/src/internal/core/params.ts +98 -0
  76. package/src/internal/core/protocol.ts +17 -0
  77. package/src/internal/core/read-reply.ts +7 -0
  78. package/src/internal/core/text.ts +7 -0
  79. package/src/internal/core/types.ts +556 -0
  80. package/src/internal/feature/auth.ts +201 -0
  81. package/src/internal/feature/interceptors.ts +36 -0
  82. package/src/internal/feature/logger.ts +222 -0
  83. package/src/internal/feature/retry.ts +165 -0
  84. package/src/internal/feature/rules.ts +54 -0
  85. package/src/internal/feature/timeout.ts +146 -0
  86. package/src/internal/feature/validate.ts +74 -0
  87. package/src/internal/page/page.ts +402 -0
  88. package/src/internal/transport/fetch.ts +82 -0
  89. package/src/resources/analytics.ts +363 -0
  90. package/src/resources/brands.ts +285 -0
  91. package/src/resources/competitors.ts +212 -0
  92. package/src/resources/identity.ts +48 -0
  93. package/src/resources/models.ts +32 -0
  94. package/src/resources/opportunities.ts +79 -0
  95. package/src/resources/organizations.ts +181 -0
  96. package/src/resources/prompts.ts +292 -0
  97. package/src/resources/reports.ts +211 -0
  98. package/src/resources/runs.ts +123 -0
  99. package/src/resources/shared/auth.ts +13 -0
  100. package/src/resources/shared/request-options.ts +26 -0
  101. package/src/resources/shared/resource.ts +23 -0
  102. package/src/resources/shared/rule.ts +25 -0
  103. package/src/resources/snapshots.ts +54 -0
  104. package/src/resources/tags.ts +46 -0
  105. package/src/resources/tools.ts +68 -0
  106. package/src/types/analytics.ts +497 -0
  107. package/src/types/brands.ts +228 -0
  108. package/src/types/competitors.ts +196 -0
  109. package/src/types/identity.ts +55 -0
  110. package/src/types/index.ts +163 -0
  111. package/src/types/models.ts +40 -0
  112. package/src/types/opportunities.ts +84 -0
  113. package/src/types/organizations.ts +157 -0
  114. package/src/types/prompts.ts +231 -0
  115. package/src/types/reports.ts +266 -0
  116. package/src/types/runs.ts +131 -0
  117. package/src/types/shared/brand-id-path.ts +2 -0
  118. package/src/types/shared/conflict-error.ts +7 -0
  119. package/src/types/shared/error.ts +29 -0
  120. package/src/types/shared/limit.ts +8 -0
  121. package/src/types/shared/mention-entry.ts +21 -0
  122. package/src/types/shared/model-filter.ts +15 -0
  123. package/src/types/shared/not-found-error.ts +4 -0
  124. package/src/types/shared/page.ts +7 -0
  125. package/src/types/shared/pagination.ts +7 -0
  126. package/src/types/shared/validation-error.ts +4 -0
  127. package/src/types/snapshots.ts +88 -0
  128. package/src/types/tags.ts +47 -0
  129. package/src/types/tools.ts +78 -0
@@ -0,0 +1,212 @@
1
+ import { apiKeyRequirements } from './shared/auth';
2
+ import type { RequestOptions } from './shared/request-options';
3
+ import { ElmoResource } from './shared/resource';
4
+ import { nameRule } from './shared/rule';
5
+ import { callPromise, RestCallPromise } from '../internal/core/call-promise';
6
+ import { callable } from '../internal/core/callable';
7
+ import { groupParams, mergeParams, placeParams } from '../internal/core/params';
8
+ import { decoded, reviving } from '../internal/feature/validate';
9
+ import { PagePromise, pages } from '../internal/page/page';
10
+ import type {
11
+ Competitor,
12
+ CompetitorsList,
13
+ CreateCompetitorErrors,
14
+ CreateCompetitorParams,
15
+ CreateCompetitorResponses,
16
+ DeleteCompetitorErrors,
17
+ DeleteCompetitorResponses,
18
+ GetCompetitorErrors,
19
+ GetCompetitorResponses,
20
+ ListCompetitorsErrors,
21
+ ListCompetitorsParams,
22
+ ListCompetitorsResponses,
23
+ UpdateCompetitorErrors,
24
+ UpdateCompetitorParams,
25
+ UpdateCompetitorResponses,
26
+ } from '../types/competitors';
27
+
28
+ function reviveCompetitor(value: Competitor): void {
29
+ if (value.createdAt != null) {
30
+ value.createdAt = decoded('Competitor.createdAt', value.createdAt, (raw) => new Date(raw));
31
+ }
32
+ if (value.updatedAt != null) {
33
+ value.updatedAt = decoded('Competitor.updatedAt', value.updatedAt, (raw) => new Date(raw));
34
+ }
35
+ }
36
+
37
+ function reviveCompetitorsList(value: CompetitorsList): void {
38
+ if (value.data != null) {
39
+ value.data.forEach((item) => {
40
+ reviveCompetitor(item);
41
+ });
42
+ }
43
+ if (value.competitors != null) {
44
+ value.competitors.forEach((item) => {
45
+ reviveCompetitor(item);
46
+ });
47
+ }
48
+ }
49
+
50
+ export const listCompetitorsDescriptor = /* @__PURE__ */ callable({
51
+ address: '/competitors',
52
+ auth: apiKeyRequirements,
53
+ method: 'get',
54
+ pagination: {
55
+ items: 'data',
56
+ limitParam: 'limit',
57
+ pages: 'pagination.totalPages',
58
+ param: 'page',
59
+ size: 'pagination.limit',
60
+ style: 'page',
61
+ total: 'pagination.total',
62
+ },
63
+ returns: 'json',
64
+ validators: { response: /* @__PURE__ */ reviving(reviveCompetitorsList) },
65
+ } as const);
66
+
67
+ export const createCompetitorDescriptor = /* @__PURE__ */ callable({
68
+ address: '/competitors',
69
+ auth: apiKeyRequirements,
70
+ mediaType: 'application/json',
71
+ method: 'post',
72
+ returns: 'json',
73
+ rules: [
74
+ {
75
+ min: 1,
76
+ name: 'brandId',
77
+ of: 'characters',
78
+ },
79
+ nameRule,
80
+ ],
81
+ validators: { response: /* @__PURE__ */ reviving(reviveCompetitor) },
82
+ } as const);
83
+
84
+ export const deleteCompetitorFields = { path: ['competitorId'] };
85
+
86
+ export const deleteCompetitorDescriptor = /* @__PURE__ */ callable({
87
+ address: '/competitors/{competitorId}',
88
+ auth: apiKeyRequirements,
89
+ method: 'delete',
90
+ returns: 'json',
91
+ validators: { response: /* @__PURE__ */ reviving(reviveCompetitor) },
92
+ } as const);
93
+
94
+ export const getCompetitorFields = { path: ['competitorId'] };
95
+
96
+ export const getCompetitorDescriptor = /* @__PURE__ */ callable({
97
+ address: '/competitors/{competitorId}',
98
+ auth: apiKeyRequirements,
99
+ method: 'get',
100
+ returns: 'json',
101
+ validators: { response: /* @__PURE__ */ reviving(reviveCompetitor) },
102
+ } as const);
103
+
104
+ export const updateCompetitorFields = { path: ['competitorId'] };
105
+
106
+ export const updateCompetitorDescriptor = /* @__PURE__ */ callable({
107
+ address: '/competitors/{competitorId}',
108
+ auth: apiKeyRequirements,
109
+ mediaType: 'application/json',
110
+ method: 'patch',
111
+ returns: 'json',
112
+ rules: [nameRule],
113
+ validators: { response: /* @__PURE__ */ reviving(reviveCompetitor) },
114
+ } as const);
115
+
116
+ /** Manage brand competitors */
117
+ export class Competitors extends ElmoResource {
118
+ /** Add a competitor */
119
+ public create(
120
+ params: CreateCompetitorParams,
121
+ options?: RequestOptions,
122
+ ): RestCallPromise<CreateCompetitorResponses, CreateCompetitorErrors> {
123
+ return callPromise(
124
+ options?.client ?? this.client,
125
+ createCompetitorDescriptor,
126
+ mergeParams(groupParams(params, 'body'), options),
127
+ );
128
+ }
129
+
130
+ /**
131
+ * Delete a competitor
132
+ *
133
+ * @param competitorId Competitor identifier (UUID)
134
+ */
135
+ public delete(
136
+ competitorId: string,
137
+ options?: RequestOptions,
138
+ ): RestCallPromise<DeleteCompetitorResponses, DeleteCompetitorErrors> {
139
+ return callPromise(
140
+ options?.client ?? this.client,
141
+ deleteCompetitorDescriptor,
142
+ mergeParams(placeParams({ competitorId }, deleteCompetitorFields, 'query'), options),
143
+ );
144
+ }
145
+
146
+ /**
147
+ * Get a competitor
148
+ *
149
+ * @param competitorId Competitor identifier (UUID)
150
+ */
151
+ public get(
152
+ competitorId: string,
153
+ options?: RequestOptions,
154
+ ): RestCallPromise<GetCompetitorResponses, GetCompetitorErrors> {
155
+ return callPromise(
156
+ options?.client ?? this.client,
157
+ getCompetitorDescriptor,
158
+ mergeParams(placeParams({ competitorId }, getCompetitorFields, 'query'), options),
159
+ );
160
+ }
161
+
162
+ public list(
163
+ params?: ListCompetitorsParams,
164
+ options?: RequestOptions,
165
+ ): PagePromise<Competitor, CompetitorsList, ListCompetitorsErrors> {
166
+ return pages(
167
+ options?.client ?? this.client,
168
+ listCompetitorsDescriptor,
169
+ mergeParams(groupParams(params, 'query'), options),
170
+ );
171
+ }
172
+
173
+ /**
174
+ * Update a competitor
175
+ *
176
+ * @param competitorId Competitor identifier (UUID)
177
+ */
178
+ public update(
179
+ competitorId: string,
180
+ params: UpdateCompetitorParams,
181
+ options?: RequestOptions,
182
+ ): RestCallPromise<UpdateCompetitorResponses, UpdateCompetitorErrors> {
183
+ return callPromise(
184
+ options?.client ?? this.client,
185
+ updateCompetitorDescriptor,
186
+ mergeParams(
187
+ placeParams({ ...params, competitorId }, updateCompetitorFields, 'body'),
188
+ options,
189
+ ),
190
+ );
191
+ }
192
+ }
193
+
194
+ export declare namespace Competitors {
195
+ export type {
196
+ Competitor,
197
+ CompetitorsList,
198
+ CreateCompetitorErrors,
199
+ CreateCompetitorParams,
200
+ CreateCompetitorResponses,
201
+ DeleteCompetitorErrors,
202
+ DeleteCompetitorResponses,
203
+ GetCompetitorErrors,
204
+ GetCompetitorResponses,
205
+ ListCompetitorsErrors,
206
+ ListCompetitorsParams,
207
+ ListCompetitorsResponses,
208
+ UpdateCompetitorErrors,
209
+ UpdateCompetitorParams,
210
+ UpdateCompetitorResponses,
211
+ };
212
+ }
@@ -0,0 +1,48 @@
1
+ import { apiKeyRequirements } from './shared/auth';
2
+ import type { RequestOptions } from './shared/request-options';
3
+ import { ElmoResource } from './shared/resource';
4
+ import { callPromise, RestCallPromise } from '../internal/core/call-promise';
5
+ import { callable } from '../internal/core/callable';
6
+ import { decoded, reviving } from '../internal/feature/validate';
7
+ import type { APIKeyIdentity, GetMeErrors, GetMeResponses } from '../types/identity';
8
+
9
+ function reviveApiKeyIdentity(value: APIKeyIdentity): void {
10
+ if (value.createdAt != null) {
11
+ value.createdAt = decoded('ApiKeyIdentity.createdAt', value.createdAt, (raw) => new Date(raw));
12
+ }
13
+ if (value.expiresAt != null) {
14
+ value.expiresAt = decoded('ApiKeyIdentity.expiresAt', value.expiresAt, (raw) => new Date(raw));
15
+ }
16
+ if (value.lastUsedAt != null) {
17
+ value.lastUsedAt = decoded(
18
+ 'ApiKeyIdentity.lastUsedAt',
19
+ value.lastUsedAt,
20
+ (raw) => new Date(raw),
21
+ );
22
+ }
23
+ }
24
+
25
+ export const getMeDescriptor = /* @__PURE__ */ callable({
26
+ address: '/me',
27
+ auth: apiKeyRequirements,
28
+ method: 'get',
29
+ returns: 'json',
30
+ validators: { response: /* @__PURE__ */ reviving(reviveApiKeyIdentity) },
31
+ } as const);
32
+
33
+ /** What the calling key is and what it may reach */
34
+ export class Me extends ElmoResource {
35
+ /**
36
+ * Describe the calling key
37
+ *
38
+ * What this key is, which organization and brands it reaches, and which scopes it holds. Requires
39
+ * no scope, so it is always safe to call first when wiring up an integration.
40
+ */
41
+ public get(options?: RequestOptions): RestCallPromise<GetMeResponses, GetMeErrors> {
42
+ return callPromise(options?.client ?? this.client, getMeDescriptor, options);
43
+ }
44
+ }
45
+
46
+ export declare namespace Me {
47
+ export type { APIKeyIdentity, GetMeErrors, GetMeResponses };
48
+ }
@@ -0,0 +1,32 @@
1
+ import { apiKeyRequirements } from './shared/auth';
2
+ import type { RequestOptions } from './shared/request-options';
3
+ import { ElmoResource } from './shared/resource';
4
+ import { callPromise, RestCallPromise } from '../internal/core/call-promise';
5
+ import { callable } from '../internal/core/callable';
6
+ import type { ListModelsErrors, ListModelsResponses, Model, ModelList } from '../types/models';
7
+
8
+ export const listModelsDescriptor = /* @__PURE__ */ callable({
9
+ address: '/models',
10
+ auth: apiKeyRequirements,
11
+ method: 'get',
12
+ returns: 'json',
13
+ } as const);
14
+
15
+ /** The answer engines this deployment can track */
16
+ export class Models extends ElmoResource {
17
+ /**
18
+ * List trackable models
19
+ *
20
+ * The answer engines this deployment can track, so a client can build a model filter without
21
+ * hardcoding ids that differ between deployments.
22
+ *
23
+ * Requires no scope.
24
+ */
25
+ public list(options?: RequestOptions): RestCallPromise<ListModelsResponses, ListModelsErrors> {
26
+ return callPromise(options?.client ?? this.client, listModelsDescriptor, options);
27
+ }
28
+ }
29
+
30
+ export declare namespace Models {
31
+ export type { ListModelsErrors, ListModelsResponses, Model, ModelList };
32
+ }
@@ -0,0 +1,79 @@
1
+ import { apiKeyRequirements } from './shared/auth';
2
+ import type { RequestOptions } from './shared/request-options';
3
+ import { ElmoResource } from './shared/resource';
4
+ import { callPromise, RestCallPromise } from '../internal/core/call-promise';
5
+ import { callable } from '../internal/core/callable';
6
+ import { mergeParams, placeParams } from '../internal/core/params';
7
+ import { decoded, reviving } from '../internal/feature/validate';
8
+ import type {
9
+ BrandOpportunities,
10
+ CitedPage,
11
+ GetBrandOpportunitiesErrors,
12
+ GetBrandOpportunitiesResponses,
13
+ Opportunity,
14
+ OpportunityPrompt,
15
+ } from '../types/opportunities';
16
+ import type { BrandIdPath } from '../types/shared/brand-id-path';
17
+
18
+ export const getBrandOpportunitiesFields = { path: ['brandId'] };
19
+
20
+ function reviveBrandOpportunities(value: BrandOpportunities): void {
21
+ if (value.generatedAt != null) {
22
+ value.generatedAt = decoded(
23
+ 'BrandOpportunities.generatedAt',
24
+ value.generatedAt,
25
+ (raw) => new Date(raw),
26
+ );
27
+ }
28
+ }
29
+
30
+ export const getBrandOpportunitiesDescriptor = /* @__PURE__ */ callable({
31
+ address: '/brands/{brandId}/opportunities',
32
+ auth: apiKeyRequirements,
33
+ method: 'get',
34
+ returns: 'json',
35
+ validators: { response: /* @__PURE__ */ reviving(reviveBrandOpportunities) },
36
+ } as const);
37
+
38
+ /** Where a brand could win more citations, and why */
39
+ export class Opportunities extends ElmoResource {
40
+ /**
41
+ * Get the latest opportunities report
42
+ *
43
+ * **Experimental — the response shape may still change.**
44
+ *
45
+ * The brand's Opportunities report: a prioritized set of ways to get cited more often, with the
46
+ * tracked prompts and cited pages behind each one. The same analysis the dashboard shows, from
47
+ * the same code.
48
+ *
49
+ * Generation is inline and synchronous. A stored report is served while it is fresh and
50
+ * regenerated when it is not, so there is nothing to poll for and no way to be handed a stale one
51
+ * — but a request that triggers a generation waits for it. The freshness window bounds the cost:
52
+ * however many callers ask, one generation per brand per window. There is deliberately no `POST`,
53
+ * which would spend provider budget with nothing metering it per call.
54
+ *
55
+ * @experimental
56
+ * @param brandId Brand identifier.
57
+ */
58
+ public get(
59
+ brandId: BrandIdPath,
60
+ options?: RequestOptions,
61
+ ): RestCallPromise<GetBrandOpportunitiesResponses, GetBrandOpportunitiesErrors> {
62
+ return callPromise(
63
+ options?.client ?? this.client,
64
+ getBrandOpportunitiesDescriptor,
65
+ mergeParams(placeParams({ brandId }, getBrandOpportunitiesFields, 'query'), options),
66
+ );
67
+ }
68
+ }
69
+
70
+ export declare namespace Opportunities {
71
+ export type {
72
+ BrandOpportunities,
73
+ CitedPage,
74
+ GetBrandOpportunitiesErrors,
75
+ GetBrandOpportunitiesResponses,
76
+ Opportunity,
77
+ OpportunityPrompt,
78
+ };
79
+ }
@@ -0,0 +1,181 @@
1
+ import { apiKeyRequirements } from './shared/auth';
2
+ import type { RequestOptions } from './shared/request-options';
3
+ import { ElmoResource } from './shared/resource';
4
+ import { callPromise, RestCallPromise } from '../internal/core/call-promise';
5
+ import { callable } from '../internal/core/callable';
6
+ import { groupParams, mergeParams, placeParams } from '../internal/core/params';
7
+ import { decoded, reviving } from '../internal/feature/validate';
8
+ import { PagePromise, pages } from '../internal/page/page';
9
+ import type {
10
+ BillingPlan,
11
+ GetOrganizationBillingErrors,
12
+ GetOrganizationBillingResponses,
13
+ GetOrganizationErrors,
14
+ GetOrganizationResponses,
15
+ ListOrganizationsErrors,
16
+ ListOrganizationsParams,
17
+ ListOrganizationsResponses,
18
+ Organization,
19
+ OrganizationBilling,
20
+ OrganizationList,
21
+ PlanLimits,
22
+ } from '../types/organizations';
23
+
24
+ export const getOrganizationBillingFields = { path: ['organizationId'] };
25
+
26
+ function reviveBillingPlan(value: BillingPlan): void {
27
+ if (value.periodEnd != null) {
28
+ value.periodEnd = decoded('BillingPlan.periodEnd', value.periodEnd, (raw) => new Date(raw));
29
+ }
30
+ }
31
+
32
+ function reviveOrganizationBilling(value: OrganizationBilling): void {
33
+ if (value.plan != null) {
34
+ reviveBillingPlan(value.plan);
35
+ }
36
+ }
37
+
38
+ export const getOrganizationBillingDescriptor = /* @__PURE__ */ callable({
39
+ address: '/organizations/{organizationId}/billing',
40
+ auth: apiKeyRequirements,
41
+ method: 'get',
42
+ returns: 'json',
43
+ validators: { response: /* @__PURE__ */ reviving(reviveOrganizationBilling) },
44
+ } as const);
45
+
46
+ function reviveOrganization(value: Organization): void {
47
+ if (value.createdAt != null) {
48
+ value.createdAt = decoded('Organization.createdAt', value.createdAt, (raw) => new Date(raw));
49
+ }
50
+ }
51
+
52
+ function reviveOrganizationList(value: OrganizationList): void {
53
+ if (value.data != null) {
54
+ value.data.forEach((item) => {
55
+ reviveOrganization(item);
56
+ });
57
+ }
58
+ }
59
+
60
+ export const listOrganizationsDescriptor = /* @__PURE__ */ callable({
61
+ address: '/organizations',
62
+ auth: apiKeyRequirements,
63
+ method: 'get',
64
+ pagination: {
65
+ items: 'data',
66
+ limitParam: 'limit',
67
+ pages: 'pagination.totalPages',
68
+ param: 'page',
69
+ size: 'pagination.limit',
70
+ style: 'page',
71
+ total: 'pagination.total',
72
+ },
73
+ returns: 'json',
74
+ validators: { response: /* @__PURE__ */ reviving(reviveOrganizationList) },
75
+ } as const);
76
+
77
+ export const getOrganizationFields = { path: ['organizationId'] };
78
+
79
+ export const getOrganizationDescriptor = /* @__PURE__ */ callable({
80
+ address: '/organizations/{organizationId}',
81
+ auth: apiKeyRequirements,
82
+ method: 'get',
83
+ returns: 'json',
84
+ validators: { response: /* @__PURE__ */ reviving(reviveOrganization) },
85
+ } as const);
86
+
87
+ /** Organizations, their plan limits, and their usage */
88
+ export class Billing extends ElmoResource {
89
+ /**
90
+ * Get billing state
91
+ *
92
+ * The organization's plan, its limits, and how much of each limit is already spent — enough for
93
+ * an integration to know a write will be rejected before attempting it.
94
+ *
95
+ * This endpoint is read-only by construction. No API key of any kind can change a subscription,
96
+ * an add-on quantity, or a payment method; there is no billing write endpoint and no billing
97
+ * write scope. Stripe identifiers, invoices, and payment methods are never returned.
98
+ *
99
+ * Deployments without billing answer `200` with `billingEnabled: false`, a null plan, and null
100
+ * limits, so callers need no special case.
101
+ */
102
+ public get(
103
+ organizationId: string,
104
+ options?: RequestOptions,
105
+ ): RestCallPromise<GetOrganizationBillingResponses, GetOrganizationBillingErrors> {
106
+ return callPromise(
107
+ options?.client ?? this.client,
108
+ getOrganizationBillingDescriptor,
109
+ mergeParams(placeParams({ organizationId }, getOrganizationBillingFields, 'query'), options),
110
+ );
111
+ }
112
+ }
113
+
114
+ /** Organizations, their plan limits, and their usage */
115
+ export class Organizations extends ElmoResource {
116
+ /**
117
+ * Get an organization
118
+ *
119
+ * No scope required. An organization outside the key's reach answers `404`, identically to one
120
+ * that does not exist.
121
+ */
122
+ public get(
123
+ organizationId: string,
124
+ options?: RequestOptions,
125
+ ): RestCallPromise<GetOrganizationResponses, GetOrganizationErrors> {
126
+ return callPromise(
127
+ options?.client ?? this.client,
128
+ getOrganizationDescriptor,
129
+ mergeParams(placeParams({ organizationId }, getOrganizationFields, 'query'), options),
130
+ );
131
+ }
132
+
133
+ /**
134
+ * One entry for an organization key — the one it acts inside. Every organization for an instance
135
+ * admin key. No scope required: a key can only ever see the organization it is already bound to.
136
+ */
137
+ public list(
138
+ params?: ListOrganizationsParams,
139
+ options?: RequestOptions,
140
+ ): PagePromise<Organization, OrganizationList, ListOrganizationsErrors> {
141
+ return pages(
142
+ options?.client ?? this.client,
143
+ listOrganizationsDescriptor,
144
+ mergeParams(groupParams(params, 'query'), options),
145
+ );
146
+ }
147
+
148
+ private _billing?: Billing;
149
+ /** Organizations, their plan limits, and their usage */
150
+ get billing(): Billing {
151
+ return (this._billing ??= new Billing(this.client));
152
+ }
153
+ }
154
+
155
+ export declare namespace Billing {
156
+ export type {
157
+ BillingPlan,
158
+ GetOrganizationBillingErrors,
159
+ GetOrganizationBillingResponses,
160
+ OrganizationBilling,
161
+ PlanLimits,
162
+ };
163
+ }
164
+
165
+ export declare namespace Organizations {
166
+ export type {
167
+ Billing,
168
+ BillingPlan,
169
+ GetOrganizationBillingErrors,
170
+ GetOrganizationBillingResponses,
171
+ GetOrganizationErrors,
172
+ GetOrganizationResponses,
173
+ ListOrganizationsErrors,
174
+ ListOrganizationsParams,
175
+ ListOrganizationsResponses,
176
+ Organization,
177
+ OrganizationBilling,
178
+ OrganizationList,
179
+ PlanLimits,
180
+ };
181
+ }