@flexprice/sdk 1.0.17 → 1.0.28

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 (180) hide show
  1. package/README.md +281 -200
  2. package/package.json +29 -41
  3. package/LICENSE +0 -663
  4. package/dist/ApiClient.js +0 -653
  5. package/dist/api/AuthApi.js +0 -100
  6. package/dist/api/CustomersApi.js +0 -376
  7. package/dist/api/EntitlementsApi.js +0 -267
  8. package/dist/api/EnvironmentsApi.js +0 -184
  9. package/dist/api/EventsApi.js +0 -238
  10. package/dist/api/FeaturesApi.js +0 -263
  11. package/dist/api/IntegrationsApi.js +0 -169
  12. package/dist/api/InvoicesApi.js +0 -419
  13. package/dist/api/PaymentsApi.js +0 -272
  14. package/dist/api/PlansApi.js +0 -226
  15. package/dist/api/PricesApi.js +0 -228
  16. package/dist/api/SecretsApi.js +0 -137
  17. package/dist/api/SubscriptionsApi.js +0 -353
  18. package/dist/api/TasksApi.js +0 -232
  19. package/dist/api/TenantsApi.js +0 -162
  20. package/dist/api/UsersApi.js +0 -61
  21. package/dist/api/WalletsApi.js +0 -392
  22. package/dist/index.js +0 -1102
  23. package/dist/model/DtoAddress.js +0 -132
  24. package/dist/model/DtoAggregatedEntitlement.js +0 -106
  25. package/dist/model/DtoAggregatedFeature.js +0 -109
  26. package/dist/model/DtoAuthResponse.js +0 -96
  27. package/dist/model/DtoBillingPeriodInfo.js +0 -97
  28. package/dist/model/DtoBulkIngestEventRequest.js +0 -91
  29. package/dist/model/DtoCreateAPIKeyRequest.js +0 -117
  30. package/dist/model/DtoCreateAPIKeyResponse.js +0 -86
  31. package/dist/model/DtoCreateCustomerRequest.js +0 -188
  32. package/dist/model/DtoCreateEntitlementRequest.js +0 -150
  33. package/dist/model/DtoCreateEnvironmentRequest.js +0 -96
  34. package/dist/model/DtoCreateFeatureRequest.js +0 -177
  35. package/dist/model/DtoCreateIntegrationRequest.js +0 -105
  36. package/dist/model/DtoCreateInvoiceLineItemRequest.js +0 -206
  37. package/dist/model/DtoCreateInvoiceRequest.js +0 -289
  38. package/dist/model/DtoCreateMeterRequest.js +0 -144
  39. package/dist/model/DtoCreatePaymentRequest.js +0 -172
  40. package/dist/model/DtoCreatePlanEntitlementRequest.js +0 -150
  41. package/dist/model/DtoCreatePlanPriceRequest.js +0 -279
  42. package/dist/model/DtoCreatePlanRequest.js +0 -148
  43. package/dist/model/DtoCreatePriceRequest.js +0 -279
  44. package/dist/model/DtoCreatePriceTier.js +0 -102
  45. package/dist/model/DtoCreateSubscriptionRequest.js +0 -223
  46. package/dist/model/DtoCreateTaskRequest.js +0 -137
  47. package/dist/model/DtoCreateTenantRequest.js +0 -96
  48. package/dist/model/DtoCreateWalletRequest.js +0 -205
  49. package/dist/model/DtoCustomerEntitlementsResponse.js +0 -93
  50. package/dist/model/DtoCustomerInvoiceSummary.js +0 -148
  51. package/dist/model/DtoCustomerMultiCurrencyInvoiceSummary.js +0 -105
  52. package/dist/model/DtoCustomerResponse.js +0 -283
  53. package/dist/model/DtoCustomerUsageSummaryResponse.js +0 -121
  54. package/dist/model/DtoEntitlementResponse.js +0 -259
  55. package/dist/model/DtoEntitlementSource.js +0 -144
  56. package/dist/model/DtoEnvironmentResponse.js +0 -120
  57. package/dist/model/DtoEvent.js +0 -154
  58. package/dist/model/DtoFeatureResponse.js +0 -258
  59. package/dist/model/DtoFeatureUsageSummary.js +0 -135
  60. package/dist/model/DtoGetEventsRequest.js +0 -219
  61. package/dist/model/DtoGetEventsResponse.js +0 -129
  62. package/dist/model/DtoGetPreviewInvoiceRequest.js +0 -106
  63. package/dist/model/DtoGetUsageAnalyticsRequest.js +0 -152
  64. package/dist/model/DtoGetUsageAnalyticsResponse.js +0 -101
  65. package/dist/model/DtoGetUsageByMeterRequest.js +0 -149
  66. package/dist/model/DtoGetUsageBySubscriptionRequest.js +0 -114
  67. package/dist/model/DtoGetUsageBySubscriptionResponse.js +0 -137
  68. package/dist/model/DtoGetUsageRequest.js +0 -173
  69. package/dist/model/DtoGetUsageResponse.js +0 -110
  70. package/dist/model/DtoIngestEventRequest.js +0 -156
  71. package/dist/model/DtoInvoiceLineItemResponse.js +0 -326
  72. package/dist/model/DtoInvoiceResponse.js +0 -450
  73. package/dist/model/DtoLinkedIntegrationsResponse.js +0 -72
  74. package/dist/model/DtoListCustomersResponse.js +0 -95
  75. package/dist/model/DtoListEntitlementsResponse.js +0 -95
  76. package/dist/model/DtoListEnvironmentsResponse.js +0 -105
  77. package/dist/model/DtoListFeaturesResponse.js +0 -95
  78. package/dist/model/DtoListInvoicesResponse.js +0 -95
  79. package/dist/model/DtoListPaymentsResponse.js +0 -95
  80. package/dist/model/DtoListPlansResponse.js +0 -95
  81. package/dist/model/DtoListPricesResponse.js +0 -95
  82. package/dist/model/DtoListSecretsResponse.js +0 -95
  83. package/dist/model/DtoListSubscriptionPausesResponse.js +0 -89
  84. package/dist/model/DtoListSubscriptionsResponse.js +0 -95
  85. package/dist/model/DtoListTasksResponse.js +0 -95
  86. package/dist/model/DtoListWalletTransactionsResponse.js +0 -95
  87. package/dist/model/DtoLoginRequest.js +0 -108
  88. package/dist/model/DtoMeterResponse.js +0 -188
  89. package/dist/model/DtoPauseSubscriptionRequest.js +0 -141
  90. package/dist/model/DtoPaymentAttemptResponse.js +0 -174
  91. package/dist/model/DtoPaymentResponse.js +0 -314
  92. package/dist/model/DtoPlanResponse.js +0 -231
  93. package/dist/model/DtoPriceResponse.js +0 -373
  94. package/dist/model/DtoResumeSubscriptionRequest.js +0 -97
  95. package/dist/model/DtoSecretResponse.js +0 -183
  96. package/dist/model/DtoSignUpRequest.js +0 -118
  97. package/dist/model/DtoSubscriptionPauseResponse.js +0 -283
  98. package/dist/model/DtoSubscriptionResponse.js +0 -489
  99. package/dist/model/DtoSubscriptionUsageByMetersResponse.js +0 -148
  100. package/dist/model/DtoTaskResponse.js +0 -294
  101. package/dist/model/DtoTenantBillingDetails.js +0 -110
  102. package/dist/model/DtoTenantBillingUsage.js +0 -95
  103. package/dist/model/DtoTenantResponse.js +0 -134
  104. package/dist/model/DtoTopUpWalletRequest.js +0 -148
  105. package/dist/model/DtoUpdateCustomerRequest.js +0 -178
  106. package/dist/model/DtoUpdateEntitlementRequest.js +0 -105
  107. package/dist/model/DtoUpdateEnvironmentRequest.js +0 -84
  108. package/dist/model/DtoUpdateFeatureRequest.js +0 -139
  109. package/dist/model/DtoUpdatePaymentRequest.js +0 -82
  110. package/dist/model/DtoUpdatePaymentStatusRequest.js +0 -87
  111. package/dist/model/DtoUpdatePlanEntitlementRequest.js +0 -163
  112. package/dist/model/DtoUpdatePlanPriceRequest.js +0 -292
  113. package/dist/model/DtoUpdatePlanRequest.js +0 -138
  114. package/dist/model/DtoUpdatePriceRequest.js +0 -94
  115. package/dist/model/DtoUpdateTaskStatusRequest.js +0 -79
  116. package/dist/model/DtoUpdateTenantRequest.js +0 -86
  117. package/dist/model/DtoUpdateWalletRequest.js +0 -133
  118. package/dist/model/DtoUsageAnalyticItem.js +0 -190
  119. package/dist/model/DtoUsageAnalyticPoint.js +0 -88
  120. package/dist/model/DtoUsageResult.js +0 -80
  121. package/dist/model/DtoUserResponse.js +0 -98
  122. package/dist/model/DtoWalletBalanceResponse.js +0 -336
  123. package/dist/model/DtoWalletResponse.js +0 -235
  124. package/dist/model/DtoWalletTransactionResponse.js +0 -221
  125. package/dist/model/ErrorsErrorDetail.js +0 -94
  126. package/dist/model/ErrorsErrorResponse.js +0 -82
  127. package/dist/model/GithubComFlexpriceFlexpriceInternalTypesValue.js +0 -112
  128. package/dist/model/MeterAggregation.js +0 -82
  129. package/dist/model/MeterFilter.js +0 -86
  130. package/dist/model/PriceJSONBTransformQuantity.js +0 -82
  131. package/dist/model/PricePrice.js +0 -359
  132. package/dist/model/PricePriceTier.js +0 -87
  133. package/dist/model/PriceTransformQuantity.js +0 -82
  134. package/dist/model/SubscriptionSubscriptionLineItem.js +0 -338
  135. package/dist/model/SubscriptionSubscriptionPause.js +0 -283
  136. package/dist/model/TypesAggregationType.js +0 -53
  137. package/dist/model/TypesAutoTopupTrigger.js +0 -41
  138. package/dist/model/TypesBillingCadence.js +0 -41
  139. package/dist/model/TypesBillingCycle.js +0 -41
  140. package/dist/model/TypesBillingModel.js +0 -47
  141. package/dist/model/TypesBillingPeriod.js +0 -65
  142. package/dist/model/TypesBillingTier.js +0 -41
  143. package/dist/model/TypesCustomerFilter.js +0 -230
  144. package/dist/model/TypesDataType.js +0 -53
  145. package/dist/model/TypesEntityType.js +0 -47
  146. package/dist/model/TypesFeatureFilter.js +0 -243
  147. package/dist/model/TypesFeatureType.js +0 -47
  148. package/dist/model/TypesFileType.js +0 -41
  149. package/dist/model/TypesFilterCondition.js +0 -104
  150. package/dist/model/TypesFilterOperatorType.js +0 -77
  151. package/dist/model/TypesInvoiceBillingReason.js +0 -53
  152. package/dist/model/TypesInvoiceCadence.js +0 -41
  153. package/dist/model/TypesInvoiceStatus.js +0 -47
  154. package/dist/model/TypesInvoiceType.js +0 -47
  155. package/dist/model/TypesPaginationResponse.js +0 -84
  156. package/dist/model/TypesPauseMode.js +0 -47
  157. package/dist/model/TypesPauseStatus.js +0 -59
  158. package/dist/model/TypesPaymentDestinationType.js +0 -35
  159. package/dist/model/TypesPaymentMethodType.js +0 -53
  160. package/dist/model/TypesPaymentStatus.js +0 -65
  161. package/dist/model/TypesPriceType.js +0 -41
  162. package/dist/model/TypesResetUsage.js +0 -41
  163. package/dist/model/TypesResumeMode.js +0 -47
  164. package/dist/model/TypesSecretProvider.js +0 -47
  165. package/dist/model/TypesSecretType.js +0 -47
  166. package/dist/model/TypesSortCondition.js +0 -81
  167. package/dist/model/TypesSortDirection.js +0 -41
  168. package/dist/model/TypesStatus.js +0 -47
  169. package/dist/model/TypesSubscriptionStatus.js +0 -77
  170. package/dist/model/TypesTaskStatus.js +0 -53
  171. package/dist/model/TypesTaskType.js +0 -41
  172. package/dist/model/TypesTransactionReason.js +0 -77
  173. package/dist/model/TypesTransactionStatus.js +0 -47
  174. package/dist/model/TypesTransactionType.js +0 -41
  175. package/dist/model/TypesWalletConfig.js +0 -74
  176. package/dist/model/TypesWalletConfigPriceType.js +0 -47
  177. package/dist/model/TypesWalletStatus.js +0 -47
  178. package/dist/model/TypesWalletTxReferenceType.js +0 -47
  179. package/dist/model/TypesWalletType.js +0 -41
  180. package/dist/model/TypesWindowSize.js +0 -83
package/README.md CHANGED
@@ -1,256 +1,337 @@
1
- # FlexPrice JavaScript SDK
1
+ # FlexPrice JavaScript/TypeScript SDK
2
2
 
3
- This is the JavaScript client library for the FlexPrice API.
3
+ [![npm version](https://badge.fury.io/js/%40flexprice%2Fsdk.svg)](https://badge.fury.io/js/%40flexprice%2Fsdk)
4
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
5
+
6
+ Official TypeScript/JavaScript SDK for the FlexPrice API with modern ES7 module support and comprehensive type safety.
7
+
8
+ ## Features
9
+
10
+ - ✅ **Full TypeScript Support** - Complete type definitions for all API endpoints
11
+ - ✅ **Modern ES7 Modules** - Native ES modules with CommonJS fallback
12
+ - ✅ **Fetch API** - Built on modern web standards
13
+ - ✅ **Browser Compatible** - Works in Node.js, Webpack, and Browserify
14
+ - ✅ **Promise & Callback Support** - Flexible async patterns
15
+ - ✅ **Comprehensive Documentation** - Auto-generated from OpenAPI specs
16
+ - ✅ **Error Handling** - Detailed error messages and status codes
4
17
 
5
18
  ## Installation
6
19
 
7
- ### Node.js
20
+ ### Published Package
8
21
 
9
22
  ```bash
10
23
  npm install @flexprice/sdk --save
11
24
  ```
12
25
 
13
- ### Browser via CDN
26
+ ### Unpublished (Development)
14
27
 
15
- ```html
16
- <script src="https://cdn.jsdelivr.net/npm/@flexprice/sdk/dist/flexprice-sdk.min.js"></script>
28
+ ```bash
29
+ npm install PATH_TO_GENERATED_PACKAGE --save
17
30
  ```
18
31
 
19
- ## Usage
32
+ ## Quick Start
33
+
34
+ ### JavaScript (CommonJS)
20
35
 
21
36
  ```javascript
22
- // Import the FlexPrice SDK
23
- const FlexPrice = require('@flexprice/sdk');
24
- // Or using ES modules:
25
- // import * as FlexPrice from '@flexprice/sdk';
26
-
27
- // Load environment variables (using dotenv package)
28
- require('dotenv').config();
29
-
30
- function main() {
31
- try {
32
- // Configure the API client with your API key
33
- // API keys should start with 'sk_' followed by a unique identifier
34
- const apiKey = process.env.FLEXPRICE_API_KEY;
35
- const apiHost = process.env.FLEXPRICE_API_HOST || 'api.cloud.flexprice.io';
36
-
37
- if (!apiKey) {
38
- console.error('ERROR: You must provide a valid FlexPrice API key');
39
- process.exit(1);
40
- }
37
+ const FlexPrice = require("@flexprice/sdk");
38
+ require("dotenv").config();
39
+
40
+ // Configure the API client
41
+ const defaultClient = FlexPrice.ApiClient.instance;
42
+ defaultClient.basePath = "https://api.cloud.flexprice.io/v1";
41
43
 
42
- // Initialize the API client with your API key
43
- const defaultClient = FlexPrice.ApiClient.instance;
44
-
45
- // Set the base path directly to the API endpoint including /v1
46
- defaultClient.basePath = `https://${apiHost}/v1`;
47
-
48
- // Configure API key authorization
49
- const apiKeyAuth = defaultClient.authentications['ApiKeyAuth'];
50
- apiKeyAuth.apiKey = apiKey;
51
- apiKeyAuth.in = 'header';
52
- apiKeyAuth.name = 'x-api-key';
53
-
54
- // Generate a unique customer ID for this example
55
- const customerId = `sample-customer-${Date.now()}`;
56
-
57
- // Create API instances for different endpoints
58
- const eventsApi = new FlexPrice.EventsApi();
59
- const customersApi = new FlexPrice.CustomersApi();
60
-
61
- // Step 1: Create a customer
62
- console.log(`Creating customer with ID: ${customerId}...`);
63
-
64
- const customerRequest = {
65
- externalId: customerId,
66
- email: `example-${customerId}@example.com`,
67
- name: 'Example Customer',
68
- metadata: {
69
- source: 'javascript-sdk-example',
70
- createdAt: new Date().toISOString()
71
- }
72
- };
73
-
74
- customersApi.customersPost({
75
- dtoCreateCustomerRequest: customerRequest
76
- }, function(error, data, response) {
77
- if (error) {
78
- console.error('Error creating customer:', error);
79
- return;
80
- }
81
-
82
- console.log('Customer created successfully!');
83
-
84
- // Step 2: Create an event
85
- console.log('Creating event...');
86
-
87
- // Important: Use snake_case for all property names to match the API
88
- const eventRequest = {
89
- event_name: 'Sample Event',
90
- external_customer_id: customerId,
91
- properties: {
92
- source: 'javascript_sample_app',
93
- environment: 'test',
94
- timestamp: new Date().toISOString()
95
- },
96
- source: 'javascript_sample_app',
97
- timestamp: new Date().toISOString()
98
- };
99
-
100
- // Important: Pass the event directly without wrapping it
101
- eventsApi.eventsPost(eventRequest, function(error, eventResult, response) {
102
- if (error) {
103
- console.error('Error creating event:', error);
104
- return;
105
- }
106
-
107
- console.log(`Event created successfully! ID: ${eventResult.event_id}`);
108
-
109
- // Step 3: Retrieve events for this customer
110
- console.log(`Retrieving events for customer ${customerId}...`);
111
-
112
- // Important: Use snake_case for parameter names
113
- eventsApi.eventsGet({
114
- external_customer_id: customerId
115
- }, function(error, events, response) {
116
- if (error) {
117
- console.error('Error retrieving events:', error);
118
- return;
119
- }
120
-
121
- console.log(`Found ${events.events.length} events:`);
122
-
123
- events.events.forEach((event, index) => {
124
- console.log(`Event ${index + 1}: ${event.id} - ${event.event_name}`);
125
- console.log(`Properties: ${JSON.stringify(event.properties)}`);
126
- });
127
-
128
- console.log('Example completed successfully!');
129
- });
130
- });
131
- });
132
- } catch (error) {
133
- console.error('Error:', error);
44
+ const apiKeyAuth = defaultClient.authentications["ApiKeyAuth"];
45
+ apiKeyAuth.apiKey = process.env.FLEXPRICE_API_KEY;
46
+ apiKeyAuth.in = "header";
47
+ apiKeyAuth.name = "x-api-key";
48
+
49
+ // Create an event
50
+ const eventsApi = new FlexPrice.EventsApi();
51
+ const eventRequest = {
52
+ event_name: "Sample Event",
53
+ external_customer_id: "customer-123",
54
+ properties: { source: "javascript_app" },
55
+ source: "javascript_app",
56
+ timestamp: new Date().toISOString(),
57
+ };
58
+
59
+ eventsApi.eventsPost(eventRequest, (error, data, response) => {
60
+ if (error) {
61
+ console.error("Error:", error);
62
+ } else {
63
+ console.log("Event created:", data);
134
64
  }
65
+ });
66
+ ```
67
+
68
+ ### TypeScript (ES Modules)
69
+
70
+ ```typescript
71
+ import * as FlexPrice from "@flexprice/sdk";
72
+ import * as dotenv from "dotenv";
73
+
74
+ dotenv.config();
75
+
76
+ // Configure the API client with type safety
77
+ const defaultClient = FlexPrice.ApiClient.instance;
78
+ defaultClient.basePath = "https://api.cloud.flexprice.io/v1";
79
+
80
+ const apiKeyAuth = defaultClient.authentications["ApiKeyAuth"];
81
+ apiKeyAuth.apiKey = process.env.FLEXPRICE_API_KEY!;
82
+ apiKeyAuth.in = "header";
83
+ apiKeyAuth.name = "x-api-key";
84
+
85
+ // Type-safe API calls
86
+ const eventsApi = new FlexPrice.EventsApi();
87
+ const eventRequest: FlexPrice.DtoIngestEventRequest = {
88
+ eventName: "Sample Event",
89
+ externalCustomerId: "customer-123",
90
+ properties: { source: "typescript_app" },
91
+ source: "typescript_app",
92
+ timestamp: new Date().toISOString(),
93
+ };
94
+
95
+ try {
96
+ const result = await eventsApi.eventsPost({ event: eventRequest });
97
+ console.log("Event created:", result);
98
+ } catch (error) {
99
+ console.error("Error:", error);
135
100
  }
101
+ ```
102
+
103
+ ### Browser Usage
136
104
 
137
- main();
105
+ ```html
106
+ <script src="https://cdn.jsdelivr.net/npm/@flexprice/sdk/dist/flexprice-sdk.min.js"></script>
107
+ <script>
108
+ // Configure the API client
109
+ const defaultClient = FlexPrice.ApiClient.instance;
110
+ defaultClient.basePath = "https://api.cloud.flexprice.io/v1";
111
+
112
+ const apiKeyAuth = defaultClient.authentications["ApiKeyAuth"];
113
+ apiKeyAuth.apiKey = "your-api-key-here";
114
+ apiKeyAuth.in = "header";
115
+ apiKeyAuth.name = "x-api-key";
116
+
117
+ // Use the SDK
118
+ const eventsApi = new FlexPrice.EventsApi();
119
+ // ... rest of your code
120
+ </script>
138
121
  ```
139
122
 
140
- ## Running the Example
123
+ ## Environment Support
141
124
 
142
- To run the provided example:
125
+ ### Node.js Environments
143
126
 
144
- 1. Clone the repository:
145
- ```bash
146
- git clone https://github.com/flexprice/javascript-sdk.git
147
- cd javascript-sdk/examples
148
- ```
127
+ - Node.js 16+
128
+ - Webpack
129
+ - Browserify
149
130
 
150
- 2. Install dependencies:
151
- ```bash
152
- npm install
153
- ```
131
+ ### Language Levels
154
132
 
155
- 3. Create a `.env` file with your API credentials:
156
- ```bash
157
- cp .env.sample .env
158
- # Edit .env with your API key
159
- ```
133
+ - ES5 (requires Promises/A+ library)
134
+ - ES6+
135
+ - TypeScript 4.5+
160
136
 
161
- 4. Run the example:
162
- ```bash
163
- npm start
164
- ```
137
+ ### Module Systems
165
138
 
166
- ## Features
139
+ - CommonJS
140
+ - ES6 Modules
141
+ - UMD (Universal Module Definition)
167
142
 
168
- - Complete API coverage
169
- - CommonJS and ES Module support
170
- - Browser compatibility
171
- - Detailed documentation
172
- - Error handling
173
- - TypeScript definitions
143
+ ## API Reference
174
144
 
175
- ## Documentation
145
+ ### Authentication
176
146
 
177
- For detailed API documentation, refer to the code comments and the official FlexPrice API documentation.
147
+ All API requests require authentication using an API key:
178
148
 
179
- ## Troubleshooting
149
+ ```javascript
150
+ const apiKeyAuth = defaultClient.authentications["ApiKeyAuth"];
151
+ apiKeyAuth.apiKey = "sk_your_api_key_here";
152
+ apiKeyAuth.in = "header";
153
+ apiKeyAuth.name = "x-api-key";
154
+ ```
180
155
 
181
- ### Authentication Issues
156
+ ### Available APIs
182
157
 
183
- If you see errors related to authentication:
158
+ - **EventsApi** - Event ingestion and retrieval
159
+ - **CustomersApi** - Customer management
160
+ - **SubscriptionsApi** - Subscription management
161
+ - **InvoicesApi** - Invoice operations
162
+ - **PaymentsApi** - Payment processing
163
+ - **PlansApi** - Plan management
164
+ - **AddonsApi** - Addon management
165
+ - **CouponsApi** - Coupon management
166
+ - **WebhooksApi** - Webhook management
184
167
 
185
- - Make sure your API key starts with `sk_` (for server-side usage)
186
- - Check that the key is active and has the necessary permissions
187
- - Use the `x-api-key` header for authentication (the SDK handles this for you)
168
+ ### Common Patterns
188
169
 
189
- ### Property Names
170
+ #### Creating Events
190
171
 
191
- Always use snake_case for property names in requests:
192
- - `event_name`, `external_customer_id`, `page_size`
193
- - ❌ `eventName`, `externalCustomerId`, `pageSize`
172
+ ```javascript
173
+ const eventRequest = {
174
+ eventName: "user_signup",
175
+ externalCustomerId: "customer-123",
176
+ properties: {
177
+ plan: "premium",
178
+ source: "website",
179
+ },
180
+ source: "web_app",
181
+ timestamp: new Date().toISOString(),
182
+ };
194
183
 
195
- ### Parameter Passing
184
+ eventsApi.eventsPost({ event: eventRequest }, callback);
185
+ ```
196
186
 
197
- Pass parameters directly to methods like eventsPost:
198
- - ✅ `eventsApi.eventsPost(eventRequest, callback)`
199
- - ❌ `eventsApi.eventsPost({ dtoIngestEventRequest: eventRequest }, callback)`
187
+ #### Creating Customers
200
188
 
201
- ### Callback vs Promise Error
189
+ ```javascript
190
+ const customerRequest = {
191
+ externalId: "customer-123",
192
+ email: "user@example.com",
193
+ name: "John Doe",
194
+ metadata: {
195
+ source: "signup_form",
196
+ },
197
+ };
198
+
199
+ customersApi.customersPost({ customer: customerRequest }, callback);
200
+ ```
202
201
 
203
- The SDK uses callback-style API calls instead of Promises. If you see an error like:
202
+ #### Error Handling
204
203
 
204
+ ```javascript
205
+ eventsApi.eventsPost(eventRequest, (error, data, response) => {
206
+ if (error) {
207
+ if (error.status === 401) {
208
+ console.error("Authentication failed");
209
+ } else if (error.status === 400) {
210
+ console.error("Bad request:", error.response.body);
211
+ } else {
212
+ console.error("API Error:", error.message);
213
+ }
214
+ } else {
215
+ console.log("Success:", data);
216
+ }
217
+ });
205
218
  ```
206
- Warning: superagent request was sent twice, because both .end() and .then() were called.
219
+
220
+ ## Development
221
+
222
+ ### Building
223
+
224
+ To build and compile the TypeScript sources to JavaScript:
225
+
226
+ ```bash
227
+ npm install
228
+ npm run build
207
229
  ```
208
230
 
209
- Make sure you're using the callback pattern shown in the examples, not trying to `await` the API calls.
231
+ ### Publishing
210
232
 
211
- ### Network or Connectivity Issues
233
+ First build the package then run:
212
234
 
213
- If you encounter network-related errors:
235
+ ```bash
236
+ npm publish
237
+ ```
214
238
 
215
- - Check your internet connection
216
- - Verify that the API host is accessible from your environment
217
- - Look for firewall or proxy settings that might block API requests
239
+ ### Testing
218
240
 
219
- ### Using the SDK in a Browser
241
+ ```bash
242
+ npm test
243
+ ```
220
244
 
221
- When using the SDK in a browser, remember:
245
+ ### Linting
222
246
 
223
- - CORS restrictions might apply - ensure your domain is whitelisted
224
- - Never expose API keys in client-side code - use a proxy or backend service
225
- - Some features might be limited in browser environments
247
+ ```bash
248
+ npm run lint
249
+ npm run lint:fix
250
+ ```
226
251
 
227
- ## TypeScript Usage
252
+ ## Examples
228
253
 
229
- The package includes TypeScript definitions:
254
+ ### Running JavaScript Example
230
255
 
231
- ```typescript
232
- import * as FlexPrice from '@flexprice/sdk';
256
+ ```bash
257
+ cd examples
258
+ npm install
259
+ npm start
260
+ ```
233
261
 
234
- // Configure the client
235
- const client = FlexPrice.ApiClient.instance;
236
- // ... rest of the configuration
262
+ ### Running TypeScript Example
237
263
 
238
- // Type-safe API calls with correct property names
239
- const api = new FlexPrice.EventsApi();
264
+ ```bash
265
+ cd examples
266
+ npm install
267
+ npm run start:ts
268
+ ```
240
269
 
241
- const eventRequest = {
242
- event_name: 'Sample Event',
243
- external_customer_id: 'customer-123',
244
- properties: { key: 'value' },
245
- source: 'typescript_example',
246
- timestamp: new Date().toISOString()
247
- };
270
+ ### Building TypeScript Example
248
271
 
249
- api.eventsPost(eventRequest, (error, data, response) => {
250
- if (error) {
251
- console.error(error);
252
- } else {
253
- console.log(data);
254
- }
255
- });
256
- ```
272
+ ```bash
273
+ cd examples
274
+ npm run build:ts
275
+ npm run start:built
276
+ ```
277
+
278
+ ## Troubleshooting
279
+
280
+ ### Authentication Issues
281
+
282
+ - Ensure your API key starts with `sk_`
283
+ - Verify the key is active and has required permissions
284
+ - Check that the `x-api-key` header is being sent correctly
285
+
286
+ ### Property Naming
287
+
288
+ Use the correct property names based on the TypeScript interfaces:
289
+
290
+ - ✅ TypeScript: `eventName`, `externalCustomerId`, `externalId`
291
+ - ✅ API JSON: `event_name`, `external_customer_id`, `external_id`
292
+ - ❌ Mixed: `event_name` in TypeScript or `eventName` in JSON
293
+
294
+ ### Parameter Passing
295
+
296
+ Pass parameters in the correct format for each API method:
297
+
298
+ - ✅ `eventsApi.eventsPost({ event: eventRequest }, callback)`
299
+ - ✅ `customersApi.customersPost({ customer: customerRequest }, callback)`
300
+ - ❌ `eventsApi.eventsPost(eventRequest, callback)` (missing wrapper object)
301
+
302
+ ### TypeScript Issues
303
+
304
+ - Ensure you have TypeScript 4.5+ installed
305
+ - Use proper type imports: `import * as FlexPrice from '@flexprice/sdk'`
306
+ - Check that your `tsconfig.json` includes the SDK types
307
+
308
+ ### Network Issues
309
+
310
+ - Verify your internet connection
311
+ - Check firewall/proxy settings
312
+ - Ensure the API host is accessible from your environment
313
+
314
+ ## Browser Considerations
315
+
316
+ When using in browsers:
317
+
318
+ - CORS restrictions may apply - ensure your domain is whitelisted
319
+ - Never expose API keys in client-side code
320
+ - Use a proxy or backend service for sensitive operations
321
+ - Some features may be limited in browser environments
322
+
323
+ ## TypeScript Definitions
324
+
325
+ The package includes comprehensive TypeScript definitions that are automatically resolved via `package.json`. All API endpoints, request/response types, and configuration options are fully typed.
326
+
327
+ ## License
328
+
329
+ This SDK is licensed under the MIT License. See the LICENSE file for details.
330
+
331
+ ## Support
332
+
333
+ For support and questions:
334
+
335
+ - Check the [API Documentation](https://docs.flexprice.io)
336
+ - Open an issue on [GitHub](https://github.com/flexprice/javascript-sdk)
337
+ - Contact support at [support@flexprice.io](mailto:support@flexprice.io)
package/package.json CHANGED
@@ -1,54 +1,42 @@
1
1
  {
2
2
  "name": "@flexprice/sdk",
3
- "version": "1.0.17",
4
- "description": "Official JavaScript SDK of Flexprice",
5
- "license": "Apache 2.0",
6
- "homepage": "https://flexprice.io",
3
+ "version": "1.0.28",
4
+ "description": "Official TypeScript/JavaScript SDK of Flexprice",
5
+ "author": "Flexprice",
7
6
  "repository": {
8
7
  "type": "git",
9
8
  "url": "https://github.com/flexprice/javascript-sdk.git"
10
9
  },
11
- "publishConfig": {
12
- "access": "public"
13
- },
14
- "main": "dist/index.js",
10
+ "main": "./dist/index.js",
11
+ "typings": "./dist/index.d.ts",
12
+ "module": "./dist/index.js",
13
+ "sideEffects": false,
15
14
  "scripts": {
16
- "build": "babel src -d dist",
15
+ "build": "tsc",
17
16
  "prepare": "npm run build",
18
- "test": "mocha --require @babel/register --recursive"
17
+ "test": "jest",
18
+ "lint": "eslint src/**/*.ts",
19
+ "lint:fix": "eslint src/**/*.ts --fix"
19
20
  },
20
- "browser": {
21
- "fs": false
21
+ "devDependencies": {
22
+ "@types/jest": "^29.5.14",
23
+ "@types/node": "^20.19.17",
24
+ "@typescript-eslint/eslint-plugin": "^6.21.0",
25
+ "@typescript-eslint/parser": "^6.21.0",
26
+ "eslint": "^8.57.1",
27
+ "jest": "^29.7.0",
28
+ "ts-jest": "^29.4.4",
29
+ "typescript": "^5.9.2"
22
30
  },
23
- "dependencies": {
24
- "@babel/cli": "^7.0.0",
25
- "superagent": "^5.3.0"
31
+ "publishConfig": {
32
+ "access": "public"
26
33
  },
27
- "devDependencies": {
28
- "@babel/core": "^7.0.0",
29
- "@babel/plugin-proposal-class-properties": "^7.0.0",
30
- "@babel/plugin-proposal-decorators": "^7.0.0",
31
- "@babel/plugin-proposal-do-expressions": "^7.0.0",
32
- "@babel/plugin-proposal-export-default-from": "^7.0.0",
33
- "@babel/plugin-proposal-export-namespace-from": "^7.0.0",
34
- "@babel/plugin-proposal-function-bind": "^7.0.0",
35
- "@babel/plugin-proposal-function-sent": "^7.0.0",
36
- "@babel/plugin-proposal-json-strings": "^7.0.0",
37
- "@babel/plugin-proposal-logical-assignment-operators": "^7.0.0",
38
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0",
39
- "@babel/plugin-proposal-numeric-separator": "^7.0.0",
40
- "@babel/plugin-proposal-optional-chaining": "^7.0.0",
41
- "@babel/plugin-proposal-pipeline-operator": "^7.0.0",
42
- "@babel/plugin-proposal-throw-expressions": "^7.0.0",
43
- "@babel/plugin-syntax-dynamic-import": "^7.0.0",
44
- "@babel/plugin-syntax-import-meta": "^7.0.0",
45
- "@babel/preset-env": "^7.0.0",
46
- "@babel/register": "^7.0.0",
47
- "expect.js": "^0.3.1",
48
- "mocha": "^8.0.1",
49
- "sinon": "^7.2.0"
34
+ "type": "module",
35
+ "types": "./dist/index.d.ts",
36
+ "engines": {
37
+ "node": ">=16.0.0"
50
38
  },
51
- "files": [
52
- "dist"
53
- ]
39
+ "keywords": "[\"flexprice\",\"sdk\",\"typescript\",\"javascript\",\"api\",\"billing\",\"pricing\",\"es7\",\"esmodules\",\"fetch\"]",
40
+ "files": "[\"dist\",\"src\",\"README.md\"]",
41
+ "exports": "{\".\": {\"import\": \"./dist/index.js\", \"require\": \"./dist/index.cjs\", \"types\": \"./dist/index.d.ts\"}, \"./package.json\": \"./package.json\"}"
54
42
  }