@openmeter/sdk 1.0.0-beta.21 → 1.0.0-beta.210

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 (138) hide show
  1. package/README.md +38 -150
  2. package/dist/cjs/index.cjs +18 -0
  3. package/dist/cjs/index.d.cts +1 -0
  4. package/dist/cjs/index.js.map +1 -0
  5. package/dist/cjs/src/client/apps.cjs +174 -0
  6. package/dist/cjs/src/client/apps.d.cts +285 -0
  7. package/dist/cjs/src/client/apps.js.map +1 -0
  8. package/dist/cjs/src/client/billing.cjs +309 -0
  9. package/dist/cjs/src/client/billing.d.cts +502 -0
  10. package/dist/cjs/src/client/billing.js.map +1 -0
  11. package/dist/cjs/src/client/common.cjs +47 -0
  12. package/dist/cjs/src/client/common.d.cts +30 -0
  13. package/dist/cjs/src/client/common.js.map +1 -0
  14. package/dist/cjs/src/client/customers.cjs +199 -0
  15. package/dist/cjs/src/client/customers.d.cts +176 -0
  16. package/dist/cjs/src/client/customers.js.map +1 -0
  17. package/dist/cjs/src/client/entitlements.cjs +244 -0
  18. package/dist/cjs/src/client/entitlements.d.cts +472 -0
  19. package/dist/cjs/src/client/entitlements.js.map +1 -0
  20. package/dist/cjs/src/client/events.cjs +66 -0
  21. package/dist/cjs/src/client/events.d.cts +31 -0
  22. package/dist/cjs/src/client/events.js.map +1 -0
  23. package/dist/cjs/src/client/features.cjs +78 -0
  24. package/dist/cjs/src/client/features.d.cts +78 -0
  25. package/dist/cjs/src/client/features.js.map +1 -0
  26. package/dist/cjs/src/client/index.cjs +108 -0
  27. package/dist/cjs/src/client/index.d.cts +45 -0
  28. package/dist/cjs/src/client/index.js.map +1 -0
  29. package/dist/cjs/src/client/meters.cjs +96 -0
  30. package/dist/cjs/src/client/meters.d.cts +99 -0
  31. package/dist/cjs/src/client/meters.js.map +1 -0
  32. package/dist/cjs/src/client/notifications.cjs +249 -0
  33. package/dist/cjs/src/client/notifications.d.cts +219 -0
  34. package/dist/cjs/src/client/notifications.js.map +1 -0
  35. package/dist/cjs/src/client/plans.cjs +127 -0
  36. package/dist/cjs/src/client/plans.d.cts +142 -0
  37. package/dist/cjs/src/client/plans.js.map +1 -0
  38. package/dist/cjs/src/client/portal.cjs +55 -0
  39. package/dist/cjs/src/client/portal.d.cts +48 -0
  40. package/dist/cjs/src/client/portal.js.map +1 -0
  41. package/dist/cjs/src/client/schemas.cjs +3 -0
  42. package/dist/cjs/src/client/schemas.d.cts +22268 -0
  43. package/dist/cjs/src/client/schemas.js.map +1 -0
  44. package/dist/cjs/src/client/subjects.cjs +76 -0
  45. package/dist/cjs/src/client/subjects.d.cts +70 -0
  46. package/dist/cjs/src/client/subjects.js.map +1 -0
  47. package/dist/cjs/src/client/subscriptions.cjs +116 -0
  48. package/dist/cjs/src/client/subscriptions.d.cts +147 -0
  49. package/dist/cjs/src/client/subscriptions.js.map +1 -0
  50. package/dist/cjs/src/client/utils.cjs +69 -0
  51. package/dist/cjs/src/client/utils.d.cts +12 -0
  52. package/dist/cjs/src/client/utils.js.map +1 -0
  53. package/dist/cjs/src/portal/index.cjs +60 -0
  54. package/dist/cjs/src/portal/index.d.cts +43 -0
  55. package/dist/cjs/src/portal/index.js.map +1 -0
  56. package/dist/cjs/src/react/context.cjs +35 -0
  57. package/dist/cjs/src/react/context.d.cts +9 -0
  58. package/dist/cjs/src/react/context.js.map +1 -0
  59. package/dist/cjs/tsconfig.1232d5e5.tsbuildinfo +1 -0
  60. package/dist/cjs/tsconfig.90ca0b5f.tsbuildinfo +1 -0
  61. package/dist/index.d.ts +1 -14
  62. package/dist/index.js +2 -15
  63. package/dist/index.js.map +1 -0
  64. package/dist/src/client/apps.d.ts +285 -0
  65. package/dist/src/client/apps.js +168 -0
  66. package/dist/src/client/apps.js.map +1 -0
  67. package/dist/src/client/billing.d.ts +502 -0
  68. package/dist/src/client/billing.js +302 -0
  69. package/dist/src/client/billing.js.map +1 -0
  70. package/dist/src/client/common.d.ts +30 -0
  71. package/dist/src/client/common.js +42 -0
  72. package/dist/src/client/common.js.map +1 -0
  73. package/dist/src/client/customers.d.ts +176 -0
  74. package/dist/src/client/customers.js +193 -0
  75. package/dist/src/client/customers.js.map +1 -0
  76. package/dist/src/client/entitlements.d.ts +472 -0
  77. package/dist/src/client/entitlements.js +239 -0
  78. package/dist/src/client/entitlements.js.map +1 -0
  79. package/dist/src/client/events.d.ts +31 -0
  80. package/dist/src/client/events.js +58 -0
  81. package/dist/src/client/events.js.map +1 -0
  82. package/dist/src/client/features.d.ts +78 -0
  83. package/dist/src/client/features.js +74 -0
  84. package/dist/src/client/features.js.map +1 -0
  85. package/dist/src/client/index.d.ts +45 -0
  86. package/dist/src/client/index.js +68 -0
  87. package/dist/src/client/index.js.map +1 -0
  88. package/dist/src/client/meters.d.ts +99 -0
  89. package/dist/src/client/meters.js +92 -0
  90. package/dist/src/client/meters.js.map +1 -0
  91. package/dist/src/client/notifications.d.ts +219 -0
  92. package/dist/src/client/notifications.js +242 -0
  93. package/dist/src/client/notifications.js.map +1 -0
  94. package/dist/src/client/plans.d.ts +142 -0
  95. package/dist/src/client/plans.js +123 -0
  96. package/dist/src/client/plans.js.map +1 -0
  97. package/dist/src/client/portal.d.ts +48 -0
  98. package/dist/src/client/portal.js +51 -0
  99. package/dist/src/client/portal.js.map +1 -0
  100. package/dist/src/client/schemas.d.ts +22268 -0
  101. package/dist/src/client/schemas.js +2 -0
  102. package/dist/src/client/schemas.js.map +1 -0
  103. package/dist/src/client/subjects.d.ts +70 -0
  104. package/dist/src/client/subjects.js +72 -0
  105. package/dist/src/client/subjects.js.map +1 -0
  106. package/dist/src/client/subscriptions.d.ts +147 -0
  107. package/dist/src/client/subscriptions.js +112 -0
  108. package/dist/src/client/subscriptions.js.map +1 -0
  109. package/dist/src/client/utils.d.ts +12 -0
  110. package/dist/src/client/utils.js +63 -0
  111. package/dist/src/client/utils.js.map +1 -0
  112. package/dist/src/portal/index.d.ts +43 -0
  113. package/dist/src/portal/index.js +53 -0
  114. package/dist/src/portal/index.js.map +1 -0
  115. package/dist/src/react/context.d.ts +9 -0
  116. package/dist/src/react/context.js +16 -0
  117. package/dist/src/react/context.js.map +1 -0
  118. package/dist/tsconfig.tsbuildinfo +1 -1
  119. package/package.json +75 -35
  120. package/patches/openapi-typescript.patch +73 -0
  121. package/dist/clients/client.d.ts +0 -40
  122. package/dist/clients/client.js +0 -104
  123. package/dist/clients/event.d.ts +0 -79
  124. package/dist/clients/event.js +0 -53
  125. package/dist/clients/meter.d.ts +0 -96
  126. package/dist/clients/meter.js +0 -64
  127. package/dist/clients/portal.d.ts +0 -23
  128. package/dist/clients/portal.js +0 -37
  129. package/dist/next.d.ts +0 -15
  130. package/dist/next.js +0 -46
  131. package/dist/schemas/openapi.d.ts +0 -460
  132. package/dist/schemas/openapi.js +0 -5
  133. package/dist/test/agent.d.ts +0 -2
  134. package/dist/test/agent.js +0 -178
  135. package/dist/test/mocks.d.ts +0 -12
  136. package/dist/test/mocks.js +0 -32
  137. package/index.ts +0 -22
  138. package/next.ts +0 -76
@@ -0,0 +1,199 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CustomerEntitlements = exports.CustomerApps = exports.Customers = void 0;
4
+ const utils_js_1 = require("./utils.cjs");
5
+ /**
6
+ * Customers
7
+ * Manage customer subscription lifecycles and plan assignments.
8
+ */
9
+ class Customers {
10
+ client;
11
+ apps;
12
+ entitlements;
13
+ constructor(client) {
14
+ this.client = client;
15
+ this.apps = new CustomerApps(client);
16
+ this.entitlements = new CustomerEntitlements(client);
17
+ }
18
+ /**
19
+ * Create a customer
20
+ * @param customer - The customer to create
21
+ * @param signal - An optional abort signal
22
+ * @returns The created customer
23
+ */
24
+ async create(customer, options) {
25
+ const resp = await this.client.POST('/api/v1/customers', {
26
+ body: customer,
27
+ ...options,
28
+ });
29
+ return (0, utils_js_1.transformResponse)(resp);
30
+ }
31
+ /**
32
+ * Get a customer by ID
33
+ * @param customerIdOrKey - The ID or Key of the customer
34
+ * @param signal - An optional abort signal
35
+ * @returns The customer
36
+ */
37
+ async get(customerIdOrKey, options) {
38
+ const resp = await this.client.GET('/api/v1/customers/{customerIdOrKey}', {
39
+ params: {
40
+ path: {
41
+ customerIdOrKey,
42
+ },
43
+ },
44
+ ...options,
45
+ });
46
+ return (0, utils_js_1.transformResponse)(resp);
47
+ }
48
+ /**
49
+ * Update a customer
50
+ * @param customerIdOrKey - The ID or Key of the customer
51
+ * @param customer - The customer to update
52
+ * @param signal - An optional abort signal
53
+ * @returns The updated customer
54
+ */
55
+ async update(customerIdOrKey, customer, options) {
56
+ const resp = await this.client.PUT('/api/v1/customers/{customerIdOrKey}', {
57
+ body: customer,
58
+ params: {
59
+ path: {
60
+ customerIdOrKey,
61
+ },
62
+ },
63
+ ...options,
64
+ });
65
+ return (0, utils_js_1.transformResponse)(resp);
66
+ }
67
+ /**
68
+ * Delete a customer
69
+ * @param customerIdOrKey - The ID or Key of the customer
70
+ * @param signal - An optional abort signal
71
+ * @returns The deleted customer
72
+ */
73
+ async delete(customerIdOrKey, options) {
74
+ const resp = await this.client.DELETE('/api/v1/customers/{customerIdOrKey}', {
75
+ params: {
76
+ path: {
77
+ customerIdOrKey,
78
+ },
79
+ },
80
+ ...options,
81
+ });
82
+ return (0, utils_js_1.transformResponse)(resp);
83
+ }
84
+ /**
85
+ * List customers
86
+ * @param signal - An optional abort signal
87
+ * @returns The list of customers
88
+ */
89
+ async list(query, options) {
90
+ const resp = await this.client.GET('/api/v1/customers', {
91
+ params: {
92
+ query,
93
+ },
94
+ ...options,
95
+ });
96
+ return (0, utils_js_1.transformResponse)(resp);
97
+ }
98
+ }
99
+ exports.Customers = Customers;
100
+ /**
101
+ * Customer Apps
102
+ * Manage customer apps.
103
+ */
104
+ class CustomerApps {
105
+ client;
106
+ constructor(client) {
107
+ this.client = client;
108
+ }
109
+ /**
110
+ * Upsert customer app data
111
+ * @param customerIdOrKey - The ID or Key of the customer
112
+ * @param appData - The app data to upsert
113
+ * @param signal - An optional abort signal
114
+ * @returns The upserted app data
115
+ */
116
+ async upsert(customerIdOrKey, appData, options) {
117
+ const resp = await this.client.PUT('/api/v1/customers/{customerIdOrKey}/apps', {
118
+ body: appData,
119
+ params: {
120
+ path: {
121
+ customerIdOrKey,
122
+ },
123
+ },
124
+ ...options,
125
+ });
126
+ return (0, utils_js_1.transformResponse)(resp);
127
+ }
128
+ /**
129
+ * List customer app data
130
+ * @param customerIdOrKey - The ID or key of the customer
131
+ * @param query - The query parameters
132
+ * @param signal - An optional abort signal
133
+ * @returns The list of customer app data
134
+ */
135
+ async list(customerIdOrKey, query, options) {
136
+ const resp = await this.client.GET('/api/v1/customers/{customerIdOrKey}/apps', {
137
+ params: {
138
+ path: { customerIdOrKey },
139
+ query,
140
+ },
141
+ ...options,
142
+ });
143
+ return (0, utils_js_1.transformResponse)(resp);
144
+ }
145
+ /**
146
+ * Delete customer app data
147
+ * @param customerIdOrKey - The ID or key of the customer
148
+ * @param appId - The ID of the app
149
+ * @param signal - An optional abort signal
150
+ * @returns The deleted customer app data
151
+ */
152
+ async delete(customerIdOrKey, appId, options) {
153
+ const resp = await this.client.DELETE('/api/v1/customers/{customerIdOrKey}/apps/{appId}', {
154
+ params: { path: { appId, customerIdOrKey } },
155
+ ...options,
156
+ });
157
+ return (0, utils_js_1.transformResponse)(resp);
158
+ }
159
+ /**
160
+ * List customer subscriptions
161
+ * @param customerIdOrKey - The ID or key of the customer
162
+ * @param query - The query parameters
163
+ * @param signal - An optional abort signal
164
+ * @returns The list of customer subscriptions
165
+ */
166
+ async listSubscriptions(customerIdOrKey, query, options) {
167
+ const resp = await this.client.GET('/api/v1/customers/{customerIdOrKey}/subscriptions', {
168
+ params: { path: { customerIdOrKey }, query },
169
+ ...options,
170
+ });
171
+ return (0, utils_js_1.transformResponse)(resp);
172
+ }
173
+ }
174
+ exports.CustomerApps = CustomerApps;
175
+ /**
176
+ * Customer Entitlements
177
+ */
178
+ class CustomerEntitlements {
179
+ client;
180
+ constructor(client) {
181
+ this.client = client;
182
+ }
183
+ /**
184
+ * Get the value of an entitlement for a customer
185
+ * @param customerIdOrKey - The ID or Key of the customer
186
+ * @param featureKey - The key of the feature
187
+ * @param signal - An optional abort signal
188
+ * @returns The value of the entitlement
189
+ */
190
+ async value(customerIdOrKey, featureKey, options) {
191
+ const resp = await this.client.GET('/api/v1/customers/{customerIdOrKey}/entitlements/{featureKey}/value', {
192
+ params: { path: { customerIdOrKey, featureKey } },
193
+ ...options,
194
+ });
195
+ return (0, utils_js_1.transformResponse)(resp);
196
+ }
197
+ }
198
+ exports.CustomerEntitlements = CustomerEntitlements;
199
+ //# sourceMappingURL=customers.js.map
@@ -0,0 +1,176 @@
1
+ import type { RequestOptions } from './common.cjs';
2
+ import type { CustomerAppData, CustomerCreate, CustomerReplaceUpdate, operations, paths } from './schemas.cjs';
3
+ import type { Client } from 'openapi-fetch';
4
+ /**
5
+ * Customers
6
+ * Manage customer subscription lifecycles and plan assignments.
7
+ */
8
+ export declare class Customers {
9
+ private client;
10
+ apps: CustomerApps;
11
+ entitlements: CustomerEntitlements;
12
+ constructor(client: Client<paths, `${string}/${string}`>);
13
+ /**
14
+ * Create a customer
15
+ * @param customer - The customer to create
16
+ * @param signal - An optional abort signal
17
+ * @returns The created customer
18
+ */
19
+ create(customer: CustomerCreate, options?: RequestOptions): Promise<{
20
+ readonly id: string;
21
+ name: string;
22
+ description?: string;
23
+ metadata?: import("./schemas.cjs").components["schemas"]["Metadata"] | null;
24
+ readonly createdAt: Date;
25
+ readonly updatedAt: Date;
26
+ readonly deletedAt?: Date;
27
+ key?: string;
28
+ usageAttribution: import("./schemas.cjs").components["schemas"]["CustomerUsageAttribution"];
29
+ primaryEmail?: string;
30
+ currency?: import("./schemas.cjs").components["schemas"]["CurrencyCode"];
31
+ billingAddress?: import("./schemas.cjs").components["schemas"]["Address"];
32
+ readonly currentSubscriptionId?: string;
33
+ }>;
34
+ /**
35
+ * Get a customer by ID
36
+ * @param customerIdOrKey - The ID or Key of the customer
37
+ * @param signal - An optional abort signal
38
+ * @returns The customer
39
+ */
40
+ get(customerIdOrKey: operations['getCustomer']['parameters']['path']['customerIdOrKey'], options?: RequestOptions): Promise<{
41
+ readonly id: string;
42
+ name: string;
43
+ description?: string;
44
+ metadata?: import("./schemas.cjs").components["schemas"]["Metadata"] | null;
45
+ readonly createdAt: Date;
46
+ readonly updatedAt: Date;
47
+ readonly deletedAt?: Date;
48
+ key?: string;
49
+ usageAttribution: import("./schemas.cjs").components["schemas"]["CustomerUsageAttribution"];
50
+ primaryEmail?: string;
51
+ currency?: import("./schemas.cjs").components["schemas"]["CurrencyCode"];
52
+ billingAddress?: import("./schemas.cjs").components["schemas"]["Address"];
53
+ readonly currentSubscriptionId?: string;
54
+ }>;
55
+ /**
56
+ * Update a customer
57
+ * @param customerIdOrKey - The ID or Key of the customer
58
+ * @param customer - The customer to update
59
+ * @param signal - An optional abort signal
60
+ * @returns The updated customer
61
+ */
62
+ update(customerIdOrKey: operations['updateCustomer']['parameters']['path']['customerIdOrKey'], customer: CustomerReplaceUpdate, options?: RequestOptions): Promise<{
63
+ readonly id: string;
64
+ name: string;
65
+ description?: string;
66
+ metadata?: import("./schemas.cjs").components["schemas"]["Metadata"] | null;
67
+ readonly createdAt: Date;
68
+ readonly updatedAt: Date;
69
+ readonly deletedAt?: Date;
70
+ key?: string;
71
+ usageAttribution: import("./schemas.cjs").components["schemas"]["CustomerUsageAttribution"];
72
+ primaryEmail?: string;
73
+ currency?: import("./schemas.cjs").components["schemas"]["CurrencyCode"];
74
+ billingAddress?: import("./schemas.cjs").components["schemas"]["Address"];
75
+ readonly currentSubscriptionId?: string;
76
+ }>;
77
+ /**
78
+ * Delete a customer
79
+ * @param customerIdOrKey - The ID or Key of the customer
80
+ * @param signal - An optional abort signal
81
+ * @returns The deleted customer
82
+ */
83
+ delete(customerIdOrKey: operations['deleteCustomer']['parameters']['path']['customerIdOrKey'], options?: RequestOptions): Promise<undefined>;
84
+ /**
85
+ * List customers
86
+ * @param signal - An optional abort signal
87
+ * @returns The list of customers
88
+ */
89
+ list(query?: operations['listCustomers']['parameters']['query'], options?: RequestOptions): Promise<{
90
+ totalCount: number;
91
+ page: number;
92
+ pageSize: number;
93
+ items: import("./schemas.cjs").components["schemas"]["Customer"][];
94
+ }>;
95
+ }
96
+ /**
97
+ * Customer Apps
98
+ * Manage customer apps.
99
+ */
100
+ export declare class CustomerApps {
101
+ private client;
102
+ constructor(client: Client<paths, `${string}/${string}`>);
103
+ /**
104
+ * Upsert customer app data
105
+ * @param customerIdOrKey - The ID or Key of the customer
106
+ * @param appData - The app data to upsert
107
+ * @param signal - An optional abort signal
108
+ * @returns The upserted app data
109
+ */
110
+ upsert(customerIdOrKey: operations['upsertCustomerAppData']['parameters']['path']['customerIdOrKey'], appData: CustomerAppData[], options?: RequestOptions): Promise<({
111
+ id?: string;
112
+ type: "stripe";
113
+ readonly app?: import("./schemas.cjs").components["schemas"]["StripeApp"];
114
+ stripeCustomerId: string;
115
+ stripeDefaultPaymentMethodId?: string;
116
+ } | {
117
+ readonly app?: import("./schemas.cjs").components["schemas"]["SandboxApp"];
118
+ id?: string;
119
+ type: "sandbox";
120
+ })[]>;
121
+ /**
122
+ * List customer app data
123
+ * @param customerIdOrKey - The ID or key of the customer
124
+ * @param query - The query parameters
125
+ * @param signal - An optional abort signal
126
+ * @returns The list of customer app data
127
+ */
128
+ list(customerIdOrKey: operations['listCustomerAppData']['parameters']['path']['customerIdOrKey'], query?: operations['listCustomerAppData']['parameters']['query'], options?: RequestOptions): Promise<{
129
+ totalCount: number;
130
+ page: number;
131
+ pageSize: number;
132
+ items: import("./schemas.cjs").components["schemas"]["CustomerAppData"][];
133
+ }>;
134
+ /**
135
+ * Delete customer app data
136
+ * @param customerIdOrKey - The ID or key of the customer
137
+ * @param appId - The ID of the app
138
+ * @param signal - An optional abort signal
139
+ * @returns The deleted customer app data
140
+ */
141
+ delete(customerIdOrKey: operations['deleteCustomerAppData']['parameters']['path']['customerIdOrKey'], appId: operations['deleteCustomerAppData']['parameters']['path']['appId'], options?: RequestOptions): Promise<undefined>;
142
+ /**
143
+ * List customer subscriptions
144
+ * @param customerIdOrKey - The ID or key of the customer
145
+ * @param query - The query parameters
146
+ * @param signal - An optional abort signal
147
+ * @returns The list of customer subscriptions
148
+ */
149
+ listSubscriptions(customerIdOrKey: operations['listCustomerSubscriptions']['parameters']['path']['customerIdOrKey'], query?: operations['listCustomerSubscriptions']['parameters']['query'], options?: RequestOptions): Promise<{
150
+ totalCount: number;
151
+ page: number;
152
+ pageSize: number;
153
+ items: import("./schemas.cjs").components["schemas"]["Subscription"][];
154
+ }>;
155
+ }
156
+ /**
157
+ * Customer Entitlements
158
+ */
159
+ export declare class CustomerEntitlements {
160
+ private client;
161
+ constructor(client: Client<paths, `${string}/${string}`>);
162
+ /**
163
+ * Get the value of an entitlement for a customer
164
+ * @param customerIdOrKey - The ID or Key of the customer
165
+ * @param featureKey - The key of the feature
166
+ * @param signal - An optional abort signal
167
+ * @returns The value of the entitlement
168
+ */
169
+ value(customerIdOrKey: operations['getCustomerEntitlementValue']['parameters']['path']['customerIdOrKey'], featureKey: operations['getCustomerEntitlementValue']['parameters']['path']['featureKey'], options?: RequestOptions): Promise<{
170
+ readonly hasAccess: boolean;
171
+ readonly balance?: number;
172
+ readonly usage?: number;
173
+ readonly overage?: number;
174
+ readonly config?: string;
175
+ }>;
176
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customers.js","sourceRoot":"","sources":["../../../../src/client/customers.ts"],"names":[],"mappings":";;;AAAA,yCAA8C;AAW9C;;;GAGG;AACH,MAAa,SAAS;IAIA;IAHb,IAAI,CAAc;IAClB,YAAY,CAAsB;IAEzC,YAAoB,MAA4C;QAA5C,WAAM,GAAN,MAAM,CAAsC;QAC9D,IAAI,CAAC,IAAI,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC,CAAA;QACpC,IAAI,CAAC,YAAY,GAAG,IAAI,oBAAoB,CAAC,MAAM,CAAC,C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,EAAE,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,eAAe,EAAE,EAAE;YAC5C,GAAG,OAAO;SACX,CACF,CAAA;QAED,OAAO,IAAA,4BAAiB,EAAC,IAAI,CAAC,CAAA;IAChC,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,iBAAiB,CAC5B,eAAiG,EACjG,KAAsE,EACtE,OAAwB;QAExB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAChC,mDAAmD,EACnD;YACE,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,eAAe,EAAE,EAAE,KAAK,EAAE;YAC5C,GAAG,OAAO;SACX,CACF,CAAA;QAED,OAAO,IAAA,4BAAiB,EAAC,IAAI,CAAC,CAAA;IAChC,CAAC;CACF;AAtGD,oCAsGC;AAED;;GAEG;AACH,MAAa,oBAAoB;IACX;IAApB,YAAoB,MAA4C;QAA5C,WAAM,GAAN,MAAM,CAAsC;IAAG,CAAC;IAEpE;;;;;;OAMG;IACI,KAAK,CAAC,KAAK,CAChB,eAAmG,EACnG,UAAyF,EACzF,OAAwB;QAExB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAChC,qEAAqE,EACrE;YACE,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,eAAe,EAAE,UAAU,EAAE,EAAE;YACjD,GAAG,OAAO;SACX,CACF,CAAA;QAED,OAAO,IAAA,4BAAiB,EAAC,IAAI,CAAC,CAAA;IAChC,CAAC;CACF;AAzBD,oDAyBC"}
@@ -0,0 +1,244 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Grants = exports.Entitlements = void 0;
4
+ const utils_js_1 = require("./utils.cjs");
5
+ /**
6
+ * Entitlements
7
+ * @description With Entitlements, you can define and enforce usage limits, implement quota-based pricing, and manage access to features in your application.
8
+ */
9
+ class Entitlements {
10
+ client;
11
+ grants;
12
+ constructor(client) {
13
+ this.client = client;
14
+ this.grants = new Grants(client);
15
+ }
16
+ /**
17
+ * Create an entitlement
18
+ *
19
+ * - Boolean entitlements define static feature access, e.g. "Can use SSO authentication".
20
+ * - Static entitlements let you pass along a configuration while granting access, e.g. "Using this feature with X Y settings" (passed in the config).
21
+ * - Metered entitlements have many use cases, from setting up usage-based access to implementing complex credit systems. Example: The customer can use 10000 AI tokens during the usage period of the entitlement.
22
+ *
23
+ * A given subject can only have one active (non-deleted) entitlement per featureKey. If you try to create a new entitlement for a featureKey that already has an active entitlement, the request will fail with a 409 error.
24
+ *
25
+ * Once an entitlement is created you cannot modify it, only delete it.
26
+ *
27
+ * @param subjectIdOrKey - The ID or key of the subject
28
+ * @param entitlement - The entitlement to create
29
+ * @param signal - An optional abort signal
30
+ * @returns The created entitlement
31
+ */
32
+ async create(subjectIdOrKey, entitlement, options) {
33
+ const resp = await this.client.POST('/api/v1/subjects/{subjectIdOrKey}/entitlements', {
34
+ body: entitlement,
35
+ params: {
36
+ path: {
37
+ subjectIdOrKey: subjectIdOrKey,
38
+ },
39
+ },
40
+ ...options,
41
+ });
42
+ return (0, utils_js_1.transformResponse)(resp);
43
+ }
44
+ /**
45
+ * Get an entitlement by ID
46
+ *
47
+ * @param id - The ID of the entitlement
48
+ * @param signal - An optional abort signal
49
+ * @returns The entitlement
50
+ */
51
+ async get(id, options) {
52
+ const resp = await this.client.GET('/api/v1/entitlements/{entitlementId}', {
53
+ params: {
54
+ path: {
55
+ entitlementId: id,
56
+ },
57
+ },
58
+ ...options,
59
+ });
60
+ return (0, utils_js_1.transformResponse)(resp);
61
+ }
62
+ /**
63
+ * List entitlements
64
+ *
65
+ * @param query - The query parameters
66
+ * @param signal - An optional abort signal
67
+ * @returns The entitlements
68
+ */
69
+ async list(query, options) {
70
+ const resp = await this.client.GET('/api/v1/entitlements', {
71
+ params: {
72
+ query,
73
+ },
74
+ ...options,
75
+ });
76
+ return (0, utils_js_1.transformResponse)(resp);
77
+ }
78
+ /**
79
+ * Delete an entitlement
80
+ *
81
+ * @param subjectIdOrKey - The ID or key of the subject
82
+ * @param entitlementId - The ID of the entitlement
83
+ * @param signal - An optional abort signal
84
+ * @returns The deleted entitlement
85
+ */
86
+ async delete(subjectIdOrKey, entitlementId, options) {
87
+ const resp = await this.client.DELETE('/api/v1/subjects/{subjectIdOrKey}/entitlements/{entitlementId}', {
88
+ params: {
89
+ path: {
90
+ entitlementId,
91
+ subjectIdOrKey,
92
+ },
93
+ },
94
+ ...options,
95
+ });
96
+ return (0, utils_js_1.transformResponse)(resp);
97
+ }
98
+ /**
99
+ * Get the value of an entitlement to check access
100
+ * All entitlement types share the hasAccess property in their value response, but multiple other properties are returned based on the entitlement type.
101
+ *
102
+ * @param subjectIdOrKey - The ID or key of the subject
103
+ * @param entitlementIdOrFeatureKey - The ID or feature key of the entitlement
104
+ * @param query - The query parameters
105
+ * @param signal - An optional abort signal
106
+ * @returns The entitlement value
107
+ */
108
+ async value(subjectIdOrKey, entitlementIdOrFeatureKey, query, options) {
109
+ const resp = await this.client.GET('/api/v1/subjects/{subjectIdOrKey}/entitlements/{entitlementIdOrFeatureKey}/value', {
110
+ params: {
111
+ path: {
112
+ entitlementIdOrFeatureKey,
113
+ subjectIdOrKey,
114
+ },
115
+ query,
116
+ },
117
+ ...options,
118
+ });
119
+ return (0, utils_js_1.transformResponse)(resp);
120
+ }
121
+ /**
122
+ * Get the history of an entitlement
123
+ * Returns historical balance and usage data for the entitlement. The queried history can span accross multiple reset events.
124
+ *
125
+ * @param subjectIdOrKey - The ID or key of the subject
126
+ * @param entitlementId - The ID of the entitlement
127
+ * @param query - The query parameters
128
+ * @param signal - An optional abort signal
129
+ * @returns The history of the entitlement
130
+ */
131
+ async history(subjectIdOrKey, entitlementId, query, options) {
132
+ const resp = await this.client.GET('/api/v1/subjects/{subjectIdOrKey}/entitlements/{entitlementId}/history', {
133
+ params: {
134
+ path: {
135
+ entitlementId,
136
+ subjectIdOrKey,
137
+ },
138
+ query,
139
+ },
140
+ ...options,
141
+ });
142
+ return (0, utils_js_1.transformResponse)(resp);
143
+ }
144
+ /**
145
+ * Override an entitlement
146
+ * This is useful for upgrades, downgrades, or other changes to entitlements that require a new entitlement to be created with zero downtime.
147
+ *
148
+ * @param subjectIdOrKey - The ID or key of the subject
149
+ * @param entitlementIdOrFeatureKey - The ID or feature key of the entitlement
150
+ * @param override - The override to create
151
+ * @param signal - An optional abort signal
152
+ * @returns The overridden entitlement
153
+ */
154
+ async override(subjectIdOrKey, entitlementIdOrFeatureKey, override, options) {
155
+ const resp = await this.client.PUT('/api/v1/subjects/{subjectIdOrKey}/entitlements/{entitlementIdOrFeatureKey}/override', {
156
+ body: override,
157
+ params: {
158
+ path: {
159
+ entitlementIdOrFeatureKey,
160
+ subjectIdOrKey,
161
+ },
162
+ },
163
+ ...options,
164
+ });
165
+ return (0, utils_js_1.transformResponse)(resp);
166
+ }
167
+ /**
168
+ * Reset entitlement usage
169
+ * - Reset marks the start of a new usage period for the entitlement and initiates grant rollover. At the start of a period usage is zerod out and grants are rolled over based on their rollover settings. It would typically be synced with the subjects billing period to enforce usage based on their subscription.
170
+ * - Usage is automatically reset for metered entitlements based on their usage period, but this endpoint allows to manually reset it at any time. When doing so the period anchor of the entitlement can be changed if needed.
171
+ *
172
+ * @param subjectIdOrKey - The ID or key of the subject
173
+ * @param entitlementId - The ID of the entitlement
174
+ * @param body - The body of the request
175
+ * @param signal - An optional abort signal
176
+ * @returns The reset entitlement
177
+ */
178
+ async reset(subjectIdOrKey, entitlementId, body, options) {
179
+ const resp = await this.client.POST('/api/v1/subjects/{subjectIdOrKey}/entitlements/{entitlementId}/reset', {
180
+ body,
181
+ params: {
182
+ path: {
183
+ entitlementId,
184
+ subjectIdOrKey,
185
+ },
186
+ },
187
+ ...options,
188
+ });
189
+ return (0, utils_js_1.transformResponse)(resp);
190
+ }
191
+ }
192
+ exports.Entitlements = Entitlements;
193
+ class Grants {
194
+ client;
195
+ constructor(client) {
196
+ this.client = client;
197
+ }
198
+ /**
199
+ /**
200
+ * Grant usage to a subject for an entitlement
201
+ *
202
+ * @param subjectIdOrKey - The ID or key of the subject
203
+ * @param entitlementIdOrFeatureKey - The ID or feature key of the entitlement
204
+ * @param grant - The grant to create
205
+ * @param signal - An optional abort signal
206
+ * @returns The created grant
207
+ */
208
+ async create(subjectIdOrKey, entitlementIdOrFeatureKey, grant, options) {
209
+ const resp = await this.client.POST('/api/v1/subjects/{subjectIdOrKey}/entitlements/{entitlementIdOrFeatureKey}/grants', {
210
+ body: grant,
211
+ params: {
212
+ path: {
213
+ entitlementIdOrFeatureKey,
214
+ subjectIdOrKey,
215
+ },
216
+ },
217
+ ...options,
218
+ });
219
+ return (0, utils_js_1.transformResponse)(resp);
220
+ }
221
+ /**
222
+ * List grants for an entitlement
223
+ *
224
+ * @param subjectIdOrKey - The ID or key of the subject
225
+ * @param entitlementIdOrFeatureKey - The ID or feature key of the entitlement
226
+ * @param signal - An optional abort signal
227
+ * @returns The grants
228
+ */
229
+ async list(subjectIdOrKey, entitlementIdOrFeatureKey, query, options) {
230
+ const resp = await this.client.GET('/api/v1/subjects/{subjectIdOrKey}/entitlements/{entitlementIdOrFeatureKey}/grants', {
231
+ params: {
232
+ path: {
233
+ entitlementIdOrFeatureKey,
234
+ subjectIdOrKey,
235
+ },
236
+ query,
237
+ },
238
+ ...options,
239
+ });
240
+ return (0, utils_js_1.transformResponse)(resp);
241
+ }
242
+ }
243
+ exports.Grants = Grants;
244
+ //# sourceMappingURL=entitlements.js.map