@replit/revenuecat-sdk 4.0.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.
package/docs/SDK.md ADDED
@@ -0,0 +1,275 @@
1
+ # `@replit/revenuecat-sdk` SDK Docs
2
+
3
+ This SDK lets you interact with RevenueCat's Developer API to take actions like creating paywalls, products, entitlements, and more
4
+ that wouldn't otherwise be possible with the client-side `react-native-purchases` SDK.
5
+
6
+ ## Usage
7
+
8
+ ### Creating a Client
9
+
10
+ ```ts
11
+ import { createClient } from '@replit/revenuecat-sdk/client';
12
+ import { listProjects, getCustomer } from '@replit/revenuecat-sdk';
13
+
14
+ const client = createClient({
15
+ baseUrl: "https://api.revenuecat.com/v2",
16
+ headers: {
17
+ Authorization: `Bearer ${process.env.REVENUECAT_API_KEY}`,
18
+ },
19
+ });
20
+ ```
21
+
22
+ ### Making Requests
23
+
24
+ Pass the client to each function:
25
+
26
+ ```ts
27
+ // List all projects
28
+ const { data, error } = await listProjects({ client });
29
+
30
+ // Get a specific customer
31
+ const { data: customer } = await getCustomer({
32
+ client,
33
+ path: {
34
+ project_id: 'proj_xxx',
35
+ customer_id: 'cust_xxx',
36
+ },
37
+ });
38
+ ```
39
+
40
+ ### Using Types
41
+
42
+ All request/response types are exported:
43
+
44
+ ```ts
45
+ import type { Customer, Project, GetCustomerData } from '@replit/revenuecat-sdk';
46
+ ```
47
+
48
+ ### Error Handling
49
+
50
+ Functions return `{ data, error, response }`:
51
+
52
+ ```ts
53
+ const { data, error } = await getCustomer({
54
+ client,
55
+ path: { project_id: 'proj_xxx', customer_id: 'cust_xxx' },
56
+ });
57
+
58
+ if (error) {
59
+ console.error('Request failed:', error);
60
+ return;
61
+ }
62
+ ```
63
+
64
+ Use `throwOnError: true` to throw on non-2xx responses:
65
+
66
+ ```ts
67
+ const { data } = await getCustomer({
68
+ client,
69
+ path: { project_id: 'proj_xxx', customer_id: 'cust_xxx' },
70
+ throwOnError: true,
71
+ });
72
+ ```
73
+
74
+ ---
75
+
76
+ ## Functions
77
+
78
+ ### Paywalls
79
+
80
+ - `listPaywalls(options)` → `ListPaywalls` - Get a list of paywalls
81
+ - `createPaywall(options)` → `CreatePaywall` - Create a paywall
82
+ - `deletePaywall(options)` → `DeletePaywall` - Delete a paywall
83
+ - `getPaywall(options)` → `GetPaywall` - Get a paywall
84
+
85
+ ### Apps
86
+
87
+ - `listAppPublicApiKeys(options)` → `ListAppPublicApiKeys` - Get a list of the public API keys of an app
88
+ - `listApps(options)` → `ListApps` - Get a list of apps
89
+ - `createApp(options)` → `CreateApp` - Create an app
90
+ - `deleteApp(options)` → `DeleteApp` - Delete an app
91
+ - `getApp(options)` → `GetApp` - Get an app
92
+ - `updateApp(options)` → `UpdateApp` - Update an app
93
+ - `getAppStorekitConfig(options)` → `GetAppStorekitConfig` - Get the StoreKit configuration for an app
94
+
95
+ ### Projects
96
+
97
+ - `listProjects(options)` → `ListProjects` - Get a list of projects
98
+ - `createProject(options)` → `CreateProject` - Creates a new project
99
+
100
+ ### Audit logs
101
+
102
+ - `listAuditLogs(options)` → `ListAuditLogs` - List audit logs
103
+
104
+ ### Collaborators
105
+
106
+ - `listCollaborators(options)` → `ListCollaborators` - Get a list of collaborators
107
+
108
+ ### Customers
109
+
110
+ - `listCustomers(options)` → `ListCustomers` - Get a list of customers
111
+ - `createCustomer(options)` → `CreateCustomer` - Create a customer
112
+ - `deleteCustomer(options)` → `DeleteCustomer` - Delete a customer
113
+ - `getCustomer(options)` → `GetCustomer` - Get a customer
114
+ - `transferCustomerData(options)` → `TransferCustomerData` - Transfer customer's subscriptions and one-time purchases to another customer
115
+ - `grantCustomerEntitlement(options)` → `GrantCustomerEntitlement` - Grant an entitlement to a customer
116
+ - `revokeCustomerGrantedEntitlement(options)` → `RevokeCustomerGrantedEntitlement` - Revoke a granted entitlement from a customer
117
+ - `assignCustomerOffering(options)` → `AssignCustomerOffering` - Assign or clear an offering override for a customer
118
+ - `listSubscriptions(options)` → `ListSubscriptions` - Get a list of subscriptions associated with a customer
119
+ - `listPurchases(options)` → `ListPurchases` - Get a list of purchases associated with a customer
120
+ - `listCustomerActiveEntitlements(options)` → `ListCustomerActiveEntitlements` - Get a list of customer's active entitlements
121
+ - `listCustomerAliases(options)` → `ListCustomerAliases` - Get a list of the customer's aliases
122
+ - `listVirtualCurrenciesBalances(options)` → `ListVirtualCurrenciesBalances` - Get a list of customer's virtual currencies balances
123
+ - `createVirtualCurrenciesTransaction(options)` → `CreateVirtualCurrenciesTransaction` - Create a virtual currencies transaction
124
+ - `updateVirtualCurrenciesBalance(options)` → `UpdateVirtualCurrenciesBalance` - Update a virtual currencies balance without creating a transaction
125
+ - `listCustomerAttributes(options)` → `ListCustomerAttributes` - Get a list of the customer's attributes
126
+ - `setCustomerAttributes(options)` → `SetCustomerAttributes` - Set a customer's attributes
127
+ - `listCustomerInvoices(options)` → `ListCustomerInvoices` - Get a list of the customer's invoices
128
+ - `getInvoice(options)` → `unknown` - Get an invoice
129
+
130
+ ### Integrations
131
+
132
+ - `listWebhookIntegrations(options)` → `ListWebhookIntegrations` - List webhook integrations
133
+ - `createWebhookIntegration(options)` → `CreateWebhookIntegration` - Create a webhook integration
134
+ - `deleteWebhookIntegration(options)` → `DeleteWebhookIntegration` - Delete a webhook integration
135
+ - `getWebhookIntegration(options)` → `GetWebhookIntegration` - Get a webhook integration
136
+ - `updateWebhookIntegration(options)` → `UpdateWebhookIntegration` - Update a webhook integration
137
+
138
+ ### Products
139
+
140
+ - `deleteProduct(options)` → `DeleteProduct` - Delete a product
141
+ - `getProduct(options)` → `GetProduct` - Get a product
142
+ - `updateProduct(options)` → `UpdateProduct` - Update a product
143
+ - `archiveProduct(options)` → `ArchiveProduct` - Archive a product
144
+ - `unarchiveProduct(options)` → `UnarchiveProduct` - Unarchive a product
145
+ - `createProductInStore(options)` → `CreateProductInStore` - Push a product to the store
146
+ - `listProducts(options)` → `ListProducts` - Get a list of products
147
+ - `createProduct(options)` → `CreateProduct` - Create a product
148
+ - `getProductStoreState(options)` → `GetProductStoreState` - Get a product store state
149
+ - `setProductStoreState(options)` → `SetProductStoreState` - Set a product store state
150
+ - `getProductStoreStateOperation(options)` → `GetProductStoreStateOperation` - Get a product store state operation
151
+ - `uploadProductStoreStateScreenshot(options)` → `UploadProductStoreStateScreenshot` - Reserve a product store state screenshot upload
152
+
153
+ ### Virtual currencies
154
+
155
+ - `listVirtualCurrencies(options)` → `ListVirtualCurrencies` - Get a list of virtual currencies
156
+ - `createVirtualCurrency(options)` → `CreateVirtualCurrency` - Create a virtual currency
157
+ - `deleteVirtualCurrency(options)` → `DeleteVirtualCurrency` - Delete a virtual currency
158
+ - `getVirtualCurrency(options)` → `GetVirtualCurrency` - Get a virtual currency
159
+ - `updateVirtualCurrency(options)` → `UpdateVirtualCurrency` - Update a virtual currency
160
+ - `archiveVirtualCurrency(options)` → `ArchiveVirtualCurrency` - Archive a virtual currency
161
+ - `unarchiveVirtualCurrency(options)` → `UnarchiveVirtualCurrency` - Unarchive a virtual currency
162
+
163
+ ### Entitlements
164
+
165
+ - `deleteEntitlement(options)` → `DeleteEntitlement` - Delete an entitlement
166
+ - `getEntitlement(options)` → `GetEntitlement` - Get an entitlement
167
+ - `updateEntitlement(options)` → `UpdateEntitlement` - Update an entitlement
168
+ - `listEntitlements(options)` → `ListEntitlements` - Get a list of entitlements
169
+ - `createEntitlement(options)` → `CreateEntitlement` - Create an entitlement
170
+ - `getProductsFromEntitlement(options)` → `GetProductsFromEntitlement` - Get a list of products attached to a given entitlement
171
+ - `archiveEntitlement(options)` → `ArchiveEntitlement` - Archive an entitlement
172
+ - `unarchiveEntitlement(options)` → `UnarchiveEntitlement` - Unarchive an entitlement
173
+ - `attachProductsToEntitlement(options)` → `AttachProductsToEntitlement` - Attach a set of products to an entitlement
174
+ - `detachProductsFromEntitlement(options)` → `DetachProductsFromEntitlement` - Detach a set of product from an entitlement
175
+
176
+ ### Offerings
177
+
178
+ - `deleteOffering(options)` → `DeleteOffering` - Delete an offering and its attached packages
179
+ - `getOffering(options)` → `GetOffering` - Get an offering
180
+ - `updateOffering(options)` → `UpdateOffering` - Update an offering
181
+ - `archiveOffering(options)` → `ArchiveOffering` - Archive an offering
182
+ - `unarchiveOffering(options)` → `UnarchiveOffering` - Unarchive an offering
183
+ - `listOfferings(options)` → `ListOfferings` - Get a list of offerings
184
+ - `createOffering(options)` → `CreateOffering` - Create an offering
185
+ - `listPackages(options)` → `ListPackages` - Get a list of packages in an offering
186
+ - `createPackages(options)` → `CreatePackages` - Create a package
187
+
188
+ ### Packages
189
+
190
+ - `deletePackageFromOffering(options)` → `DeletePackageFromOffering` - Delete a package
191
+ - `getPackage(options)` → `GetPackage` - Get a package
192
+ - `updatePackage(options)` → `UpdatePackage` - Update a package
193
+ - `getProductsFromPackage(options)` → `GetProductsFromPackage` - Get a list of products attached to a given package of an offering
194
+ - `attachProductsToPackage(options)` → `AttachProductsToPackage` - Attach a set of products to a package
195
+ - `detachProductsFromPackage(options)` → `DetachProductsFromPackage` - Detach a set of products from a package
196
+
197
+ ### Subscriptions
198
+
199
+ - `getSubscription(options)` → `GetSubscription` - Get a subscription
200
+ - `getPlayStoreOrAppStoreSubscriptionTransactions(options)` → `GetPlayStoreOrAppStoreSubscriptionTransactions` - Get a Play Store or App Store subscription's transactions
201
+ - `refundPlayStoreSubscriptionTransaction(options)` → `RefundPlayStoreSubscriptionTransaction` - Refund a Play Store subscription's transaction
202
+ - `listSubscriptionEntitlements(options)` → `ListSubscriptionEntitlements` - Get a list of entitlements associated with a subscription
203
+ - `cancelSubscription(options)` → `CancelSubscription` - Cancel an active Web Billing subscription
204
+ - `refundSubscription(options)` → `RefundSubscription` - Refund an active Web Billing subscription
205
+ - `getAuthorizedSubscriptionManagementUrl(options)` → `GetAuthorizedSubscriptionManagementUrl` - Get an authenticated Web Billing customer portal URL
206
+ - `searchSubscriptions(options)` → `SearchSubscriptions` - Search subscriptions by store subscription identifier
207
+
208
+ ### Purchases
209
+
210
+ - `getPurchase(options)` → `GetPurchase` - Get a purchase
211
+ - `listPurchaseEntitlements(options)` → `ListPurchaseEntitlements` - Get a list of entitlements associated with a purchase
212
+ - `refundPurchase(options)` → `RefundPurchase` - Refund a Web Billing purchase
213
+ - `searchPurchases(options)` → `SearchPurchases` - Search one-time purchases by store purchase identifier
214
+
215
+ ### Metrics
216
+
217
+ - `getOverviewMetrics(options)` → `GetOverviewMetrics` - Get overview metrics for a project
218
+
219
+ ### Charts
220
+
221
+ - `getChartData(options)` → `GetChartData` - Get chart data
222
+ - `getChartOptions(options)` → `GetChartOptions` - Get available options for a chart
223
+
224
+ ### Undocumented Endpoints
225
+
226
+ The RevenueCat API has endpoints that are not implemented in this SDK.
227
+ They can be accessed directly using the client's HTTP methods (`get`, `post`, etc.).
228
+
229
+ #### Add Price to Test Store Product
230
+
231
+ `POST /projects/{project_id}/products/{product_id}/test_store_prices`
232
+
233
+ Request Body:
234
+ ```json
235
+ {
236
+ "prices": [
237
+ { "amount_micros": 9990000, "currency": "USD" },
238
+ { "amount_micros": 8990000, "currency": "EUR" }
239
+ ]
240
+ }
241
+ ```
242
+
243
+ Usage:
244
+ ```ts
245
+ const { data } = await client.post({
246
+ url: '/projects/{project_id}/products/{product_id}/test_store_prices',
247
+ path: { project_id, product_id },
248
+ body: {
249
+ prices: [
250
+ { amount_micros: 9990000, currency: 'USD' },
251
+ { amount_micros: 8990000, currency: 'EUR' },
252
+ ],
253
+ },
254
+ });
255
+ ```
256
+
257
+ #### List Test Store Product Prices
258
+
259
+ `GET /projects/{project_id}/products/{product_id}/test_store_prices`
260
+
261
+ Usage:
262
+ ```ts
263
+ const { data } = await client.get({
264
+ url: '/projects/{project_id}/products/{product_id}/test_store_prices',
265
+ path: { project_id, product_id },
266
+ });
267
+ ```
268
+
269
+ Response:
270
+ ```json
271
+ [
272
+ { "amount": 599, "amount_micros": 5990000, "currency": "USD" },
273
+ { "amount": 549, "amount_micros": 5490000, "currency": "EUR" }
274
+ ]
275
+ ```
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@replit/revenuecat-sdk",
3
+ "version": "4.0.0",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/index.d.ts",
8
+ "import": "./dist/index.js",
9
+ "require": "./dist/index.cjs"
10
+ },
11
+ "./client": {
12
+ "types": "./dist/client/index.d.ts",
13
+ "import": "./dist/client/index.js",
14
+ "require": "./dist/client/index.cjs"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "docs"
20
+ ],
21
+ "scripts": {
22
+ "build": "bun merge-openapi && bun openapi-ts && bun run tsup && bun docs",
23
+ "merge-openapi": "bun scripts/merge-openapi.ts",
24
+ "openapi-ts": "openapi-ts",
25
+ "docs": "bun scripts/generate-docs.ts",
26
+ "tsup": "tsup",
27
+ "prepublishOnly": "bun run build"
28
+ },
29
+ "devDependencies": {
30
+ "@hey-api/openapi-ts": "0.90.9",
31
+ "@types/bun": "latest",
32
+ "@types/js-yaml": "^4.0.9",
33
+ "js-yaml": "^4.1.1",
34
+ "tsup": "^8.5.1"
35
+ },
36
+ "peerDependencies": {
37
+ "typescript": "^5"
38
+ }
39
+ }