@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.
- package/README.md +281 -200
- package/package.json +29 -41
- package/LICENSE +0 -663
- package/dist/ApiClient.js +0 -653
- package/dist/api/AuthApi.js +0 -100
- package/dist/api/CustomersApi.js +0 -376
- package/dist/api/EntitlementsApi.js +0 -267
- package/dist/api/EnvironmentsApi.js +0 -184
- package/dist/api/EventsApi.js +0 -238
- package/dist/api/FeaturesApi.js +0 -263
- package/dist/api/IntegrationsApi.js +0 -169
- package/dist/api/InvoicesApi.js +0 -419
- package/dist/api/PaymentsApi.js +0 -272
- package/dist/api/PlansApi.js +0 -226
- package/dist/api/PricesApi.js +0 -228
- package/dist/api/SecretsApi.js +0 -137
- package/dist/api/SubscriptionsApi.js +0 -353
- package/dist/api/TasksApi.js +0 -232
- package/dist/api/TenantsApi.js +0 -162
- package/dist/api/UsersApi.js +0 -61
- package/dist/api/WalletsApi.js +0 -392
- package/dist/index.js +0 -1102
- package/dist/model/DtoAddress.js +0 -132
- package/dist/model/DtoAggregatedEntitlement.js +0 -106
- package/dist/model/DtoAggregatedFeature.js +0 -109
- package/dist/model/DtoAuthResponse.js +0 -96
- package/dist/model/DtoBillingPeriodInfo.js +0 -97
- package/dist/model/DtoBulkIngestEventRequest.js +0 -91
- package/dist/model/DtoCreateAPIKeyRequest.js +0 -117
- package/dist/model/DtoCreateAPIKeyResponse.js +0 -86
- package/dist/model/DtoCreateCustomerRequest.js +0 -188
- package/dist/model/DtoCreateEntitlementRequest.js +0 -150
- package/dist/model/DtoCreateEnvironmentRequest.js +0 -96
- package/dist/model/DtoCreateFeatureRequest.js +0 -177
- package/dist/model/DtoCreateIntegrationRequest.js +0 -105
- package/dist/model/DtoCreateInvoiceLineItemRequest.js +0 -206
- package/dist/model/DtoCreateInvoiceRequest.js +0 -289
- package/dist/model/DtoCreateMeterRequest.js +0 -144
- package/dist/model/DtoCreatePaymentRequest.js +0 -172
- package/dist/model/DtoCreatePlanEntitlementRequest.js +0 -150
- package/dist/model/DtoCreatePlanPriceRequest.js +0 -279
- package/dist/model/DtoCreatePlanRequest.js +0 -148
- package/dist/model/DtoCreatePriceRequest.js +0 -279
- package/dist/model/DtoCreatePriceTier.js +0 -102
- package/dist/model/DtoCreateSubscriptionRequest.js +0 -223
- package/dist/model/DtoCreateTaskRequest.js +0 -137
- package/dist/model/DtoCreateTenantRequest.js +0 -96
- package/dist/model/DtoCreateWalletRequest.js +0 -205
- package/dist/model/DtoCustomerEntitlementsResponse.js +0 -93
- package/dist/model/DtoCustomerInvoiceSummary.js +0 -148
- package/dist/model/DtoCustomerMultiCurrencyInvoiceSummary.js +0 -105
- package/dist/model/DtoCustomerResponse.js +0 -283
- package/dist/model/DtoCustomerUsageSummaryResponse.js +0 -121
- package/dist/model/DtoEntitlementResponse.js +0 -259
- package/dist/model/DtoEntitlementSource.js +0 -144
- package/dist/model/DtoEnvironmentResponse.js +0 -120
- package/dist/model/DtoEvent.js +0 -154
- package/dist/model/DtoFeatureResponse.js +0 -258
- package/dist/model/DtoFeatureUsageSummary.js +0 -135
- package/dist/model/DtoGetEventsRequest.js +0 -219
- package/dist/model/DtoGetEventsResponse.js +0 -129
- package/dist/model/DtoGetPreviewInvoiceRequest.js +0 -106
- package/dist/model/DtoGetUsageAnalyticsRequest.js +0 -152
- package/dist/model/DtoGetUsageAnalyticsResponse.js +0 -101
- package/dist/model/DtoGetUsageByMeterRequest.js +0 -149
- package/dist/model/DtoGetUsageBySubscriptionRequest.js +0 -114
- package/dist/model/DtoGetUsageBySubscriptionResponse.js +0 -137
- package/dist/model/DtoGetUsageRequest.js +0 -173
- package/dist/model/DtoGetUsageResponse.js +0 -110
- package/dist/model/DtoIngestEventRequest.js +0 -156
- package/dist/model/DtoInvoiceLineItemResponse.js +0 -326
- package/dist/model/DtoInvoiceResponse.js +0 -450
- package/dist/model/DtoLinkedIntegrationsResponse.js +0 -72
- package/dist/model/DtoListCustomersResponse.js +0 -95
- package/dist/model/DtoListEntitlementsResponse.js +0 -95
- package/dist/model/DtoListEnvironmentsResponse.js +0 -105
- package/dist/model/DtoListFeaturesResponse.js +0 -95
- package/dist/model/DtoListInvoicesResponse.js +0 -95
- package/dist/model/DtoListPaymentsResponse.js +0 -95
- package/dist/model/DtoListPlansResponse.js +0 -95
- package/dist/model/DtoListPricesResponse.js +0 -95
- package/dist/model/DtoListSecretsResponse.js +0 -95
- package/dist/model/DtoListSubscriptionPausesResponse.js +0 -89
- package/dist/model/DtoListSubscriptionsResponse.js +0 -95
- package/dist/model/DtoListTasksResponse.js +0 -95
- package/dist/model/DtoListWalletTransactionsResponse.js +0 -95
- package/dist/model/DtoLoginRequest.js +0 -108
- package/dist/model/DtoMeterResponse.js +0 -188
- package/dist/model/DtoPauseSubscriptionRequest.js +0 -141
- package/dist/model/DtoPaymentAttemptResponse.js +0 -174
- package/dist/model/DtoPaymentResponse.js +0 -314
- package/dist/model/DtoPlanResponse.js +0 -231
- package/dist/model/DtoPriceResponse.js +0 -373
- package/dist/model/DtoResumeSubscriptionRequest.js +0 -97
- package/dist/model/DtoSecretResponse.js +0 -183
- package/dist/model/DtoSignUpRequest.js +0 -118
- package/dist/model/DtoSubscriptionPauseResponse.js +0 -283
- package/dist/model/DtoSubscriptionResponse.js +0 -489
- package/dist/model/DtoSubscriptionUsageByMetersResponse.js +0 -148
- package/dist/model/DtoTaskResponse.js +0 -294
- package/dist/model/DtoTenantBillingDetails.js +0 -110
- package/dist/model/DtoTenantBillingUsage.js +0 -95
- package/dist/model/DtoTenantResponse.js +0 -134
- package/dist/model/DtoTopUpWalletRequest.js +0 -148
- package/dist/model/DtoUpdateCustomerRequest.js +0 -178
- package/dist/model/DtoUpdateEntitlementRequest.js +0 -105
- package/dist/model/DtoUpdateEnvironmentRequest.js +0 -84
- package/dist/model/DtoUpdateFeatureRequest.js +0 -139
- package/dist/model/DtoUpdatePaymentRequest.js +0 -82
- package/dist/model/DtoUpdatePaymentStatusRequest.js +0 -87
- package/dist/model/DtoUpdatePlanEntitlementRequest.js +0 -163
- package/dist/model/DtoUpdatePlanPriceRequest.js +0 -292
- package/dist/model/DtoUpdatePlanRequest.js +0 -138
- package/dist/model/DtoUpdatePriceRequest.js +0 -94
- package/dist/model/DtoUpdateTaskStatusRequest.js +0 -79
- package/dist/model/DtoUpdateTenantRequest.js +0 -86
- package/dist/model/DtoUpdateWalletRequest.js +0 -133
- package/dist/model/DtoUsageAnalyticItem.js +0 -190
- package/dist/model/DtoUsageAnalyticPoint.js +0 -88
- package/dist/model/DtoUsageResult.js +0 -80
- package/dist/model/DtoUserResponse.js +0 -98
- package/dist/model/DtoWalletBalanceResponse.js +0 -336
- package/dist/model/DtoWalletResponse.js +0 -235
- package/dist/model/DtoWalletTransactionResponse.js +0 -221
- package/dist/model/ErrorsErrorDetail.js +0 -94
- package/dist/model/ErrorsErrorResponse.js +0 -82
- package/dist/model/GithubComFlexpriceFlexpriceInternalTypesValue.js +0 -112
- package/dist/model/MeterAggregation.js +0 -82
- package/dist/model/MeterFilter.js +0 -86
- package/dist/model/PriceJSONBTransformQuantity.js +0 -82
- package/dist/model/PricePrice.js +0 -359
- package/dist/model/PricePriceTier.js +0 -87
- package/dist/model/PriceTransformQuantity.js +0 -82
- package/dist/model/SubscriptionSubscriptionLineItem.js +0 -338
- package/dist/model/SubscriptionSubscriptionPause.js +0 -283
- package/dist/model/TypesAggregationType.js +0 -53
- package/dist/model/TypesAutoTopupTrigger.js +0 -41
- package/dist/model/TypesBillingCadence.js +0 -41
- package/dist/model/TypesBillingCycle.js +0 -41
- package/dist/model/TypesBillingModel.js +0 -47
- package/dist/model/TypesBillingPeriod.js +0 -65
- package/dist/model/TypesBillingTier.js +0 -41
- package/dist/model/TypesCustomerFilter.js +0 -230
- package/dist/model/TypesDataType.js +0 -53
- package/dist/model/TypesEntityType.js +0 -47
- package/dist/model/TypesFeatureFilter.js +0 -243
- package/dist/model/TypesFeatureType.js +0 -47
- package/dist/model/TypesFileType.js +0 -41
- package/dist/model/TypesFilterCondition.js +0 -104
- package/dist/model/TypesFilterOperatorType.js +0 -77
- package/dist/model/TypesInvoiceBillingReason.js +0 -53
- package/dist/model/TypesInvoiceCadence.js +0 -41
- package/dist/model/TypesInvoiceStatus.js +0 -47
- package/dist/model/TypesInvoiceType.js +0 -47
- package/dist/model/TypesPaginationResponse.js +0 -84
- package/dist/model/TypesPauseMode.js +0 -47
- package/dist/model/TypesPauseStatus.js +0 -59
- package/dist/model/TypesPaymentDestinationType.js +0 -35
- package/dist/model/TypesPaymentMethodType.js +0 -53
- package/dist/model/TypesPaymentStatus.js +0 -65
- package/dist/model/TypesPriceType.js +0 -41
- package/dist/model/TypesResetUsage.js +0 -41
- package/dist/model/TypesResumeMode.js +0 -47
- package/dist/model/TypesSecretProvider.js +0 -47
- package/dist/model/TypesSecretType.js +0 -47
- package/dist/model/TypesSortCondition.js +0 -81
- package/dist/model/TypesSortDirection.js +0 -41
- package/dist/model/TypesStatus.js +0 -47
- package/dist/model/TypesSubscriptionStatus.js +0 -77
- package/dist/model/TypesTaskStatus.js +0 -53
- package/dist/model/TypesTaskType.js +0 -41
- package/dist/model/TypesTransactionReason.js +0 -77
- package/dist/model/TypesTransactionStatus.js +0 -47
- package/dist/model/TypesTransactionType.js +0 -41
- package/dist/model/TypesWalletConfig.js +0 -74
- package/dist/model/TypesWalletConfigPriceType.js +0 -47
- package/dist/model/TypesWalletStatus.js +0 -47
- package/dist/model/TypesWalletTxReferenceType.js +0 -47
- package/dist/model/TypesWalletType.js +0 -41
- 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
|
-
|
|
3
|
+
[](https://badge.fury.io/js/%40flexprice%2Fsdk)
|
|
4
|
+
[](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
|
-
###
|
|
20
|
+
### Published Package
|
|
8
21
|
|
|
9
22
|
```bash
|
|
10
23
|
npm install @flexprice/sdk --save
|
|
11
24
|
```
|
|
12
25
|
|
|
13
|
-
###
|
|
26
|
+
### Unpublished (Development)
|
|
14
27
|
|
|
15
|
-
```
|
|
16
|
-
|
|
28
|
+
```bash
|
|
29
|
+
npm install PATH_TO_GENERATED_PACKAGE --save
|
|
17
30
|
```
|
|
18
31
|
|
|
19
|
-
##
|
|
32
|
+
## Quick Start
|
|
33
|
+
|
|
34
|
+
### JavaScript (CommonJS)
|
|
20
35
|
|
|
21
36
|
```javascript
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
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
|
-
##
|
|
123
|
+
## Environment Support
|
|
141
124
|
|
|
142
|
-
|
|
125
|
+
### Node.js Environments
|
|
143
126
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
cd javascript-sdk/examples
|
|
148
|
-
```
|
|
127
|
+
- Node.js 16+
|
|
128
|
+
- Webpack
|
|
129
|
+
- Browserify
|
|
149
130
|
|
|
150
|
-
|
|
151
|
-
```bash
|
|
152
|
-
npm install
|
|
153
|
-
```
|
|
131
|
+
### Language Levels
|
|
154
132
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
# Edit .env with your API key
|
|
159
|
-
```
|
|
133
|
+
- ES5 (requires Promises/A+ library)
|
|
134
|
+
- ES6+
|
|
135
|
+
- TypeScript 4.5+
|
|
160
136
|
|
|
161
|
-
|
|
162
|
-
```bash
|
|
163
|
-
npm start
|
|
164
|
-
```
|
|
137
|
+
### Module Systems
|
|
165
138
|
|
|
166
|
-
|
|
139
|
+
- CommonJS
|
|
140
|
+
- ES6 Modules
|
|
141
|
+
- UMD (Universal Module Definition)
|
|
167
142
|
|
|
168
|
-
|
|
169
|
-
- CommonJS and ES Module support
|
|
170
|
-
- Browser compatibility
|
|
171
|
-
- Detailed documentation
|
|
172
|
-
- Error handling
|
|
173
|
-
- TypeScript definitions
|
|
143
|
+
## API Reference
|
|
174
144
|
|
|
175
|
-
|
|
145
|
+
### Authentication
|
|
176
146
|
|
|
177
|
-
|
|
147
|
+
All API requests require authentication using an API key:
|
|
178
148
|
|
|
179
|
-
|
|
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
|
-
###
|
|
156
|
+
### Available APIs
|
|
182
157
|
|
|
183
|
-
|
|
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
|
-
|
|
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
|
-
|
|
170
|
+
#### Creating Events
|
|
190
171
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
-
|
|
184
|
+
eventsApi.eventsPost({ event: eventRequest }, callback);
|
|
185
|
+
```
|
|
196
186
|
|
|
197
|
-
|
|
198
|
-
- ✅ `eventsApi.eventsPost(eventRequest, callback)`
|
|
199
|
-
- ❌ `eventsApi.eventsPost({ dtoIngestEventRequest: eventRequest }, callback)`
|
|
187
|
+
#### Creating Customers
|
|
200
188
|
|
|
201
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
231
|
+
### Publishing
|
|
210
232
|
|
|
211
|
-
|
|
233
|
+
First build the package then run:
|
|
212
234
|
|
|
213
|
-
|
|
235
|
+
```bash
|
|
236
|
+
npm publish
|
|
237
|
+
```
|
|
214
238
|
|
|
215
|
-
|
|
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
|
-
|
|
241
|
+
```bash
|
|
242
|
+
npm test
|
|
243
|
+
```
|
|
220
244
|
|
|
221
|
-
|
|
245
|
+
### Linting
|
|
222
246
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
247
|
+
```bash
|
|
248
|
+
npm run lint
|
|
249
|
+
npm run lint:fix
|
|
250
|
+
```
|
|
226
251
|
|
|
227
|
-
##
|
|
252
|
+
## Examples
|
|
228
253
|
|
|
229
|
-
|
|
254
|
+
### Running JavaScript Example
|
|
230
255
|
|
|
231
|
-
```
|
|
232
|
-
|
|
256
|
+
```bash
|
|
257
|
+
cd examples
|
|
258
|
+
npm install
|
|
259
|
+
npm start
|
|
260
|
+
```
|
|
233
261
|
|
|
234
|
-
|
|
235
|
-
const client = FlexPrice.ApiClient.instance;
|
|
236
|
-
// ... rest of the configuration
|
|
262
|
+
### Running TypeScript Example
|
|
237
263
|
|
|
238
|
-
|
|
239
|
-
|
|
264
|
+
```bash
|
|
265
|
+
cd examples
|
|
266
|
+
npm install
|
|
267
|
+
npm run start:ts
|
|
268
|
+
```
|
|
240
269
|
|
|
241
|
-
|
|
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
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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.
|
|
4
|
-
"description": "Official JavaScript SDK of Flexprice",
|
|
5
|
-
"
|
|
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
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"typings": "./dist/index.d.ts",
|
|
12
|
+
"module": "./dist/index.js",
|
|
13
|
+
"sideEffects": false,
|
|
15
14
|
"scripts": {
|
|
16
|
-
"build": "
|
|
15
|
+
"build": "tsc",
|
|
17
16
|
"prepare": "npm run build",
|
|
18
|
-
"test": "
|
|
17
|
+
"test": "jest",
|
|
18
|
+
"lint": "eslint src/**/*.ts",
|
|
19
|
+
"lint:fix": "eslint src/**/*.ts --fix"
|
|
19
20
|
},
|
|
20
|
-
"
|
|
21
|
-
"
|
|
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
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"superagent": "^5.3.0"
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
26
33
|
},
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
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
|
-
"
|
|
52
|
-
|
|
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
|
}
|