@profullstack/stripe-config 1.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/LICENSE +15 -0
- package/README.md +338 -0
- package/dist/cli/commands/prices.d.ts +5 -0
- package/dist/cli/commands/prices.d.ts.map +1 -0
- package/dist/cli/commands/prices.js +399 -0
- package/dist/cli/commands/prices.js.map +1 -0
- package/dist/cli/commands/products.d.ts +5 -0
- package/dist/cli/commands/products.d.ts.map +1 -0
- package/dist/cli/commands/products.js +307 -0
- package/dist/cli/commands/products.js.map +1 -0
- package/dist/cli/commands/setup.d.ts +5 -0
- package/dist/cli/commands/setup.d.ts.map +1 -0
- package/dist/cli/commands/setup.js +120 -0
- package/dist/cli/commands/setup.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +52 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/core/config-manager.d.ts +60 -0
- package/dist/core/config-manager.d.ts.map +1 -0
- package/dist/core/config-manager.js +185 -0
- package/dist/core/config-manager.js.map +1 -0
- package/dist/core/stripe-client.d.ts +64 -0
- package/dist/core/stripe-client.d.ts.map +1 -0
- package/dist/core/stripe-client.js +172 -0
- package/dist/core/stripe-client.js.map +1 -0
- package/dist/core/types.d.ts +203 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +37 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts +69 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +96 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024, ProFullStack
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
# @profullstack/stripe-config
|
|
2
|
+
|
|
3
|
+
A powerful CLI tool and ESM module for managing Stripe products and prices across multiple projects.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🔧 **CLI Tool** - Interactive command-line interface for managing Stripe resources
|
|
8
|
+
- 📦 **ESM Module** - Programmatic API for Node.js applications
|
|
9
|
+
- 🔐 **Secure Storage** - API keys stored in `~/.config/stripeconf` with proper permissions
|
|
10
|
+
- 🎯 **Multi-Project** - Manage multiple Stripe projects from a single configuration
|
|
11
|
+
- 💰 **Full CRUD** - Complete product and price lifecycle management
|
|
12
|
+
- 🔄 **Recurring Prices** - Support for subscriptions with flexible billing intervals
|
|
13
|
+
- 📊 **Advanced Features** - Metadata, images, tax codes, tiered pricing, and more
|
|
14
|
+
- 🎨 **TypeScript** - Full type definitions included
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pnpm add @profullstack/stripe-config
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Or install globally for CLI usage:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pnpm add -g @profullstack/stripe-config
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## CLI Usage
|
|
29
|
+
|
|
30
|
+
### Setup
|
|
31
|
+
|
|
32
|
+
Configure a new Stripe project:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
stripeconf setup
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
This will prompt you for:
|
|
39
|
+
- Project name
|
|
40
|
+
- Environment (test/live)
|
|
41
|
+
- API keys (publishable and secret)
|
|
42
|
+
- Webhook secret (optional)
|
|
43
|
+
- Default currency
|
|
44
|
+
|
|
45
|
+
### Manage Products
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
stripeconf products
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Operations available:
|
|
52
|
+
- List all products
|
|
53
|
+
- View product details
|
|
54
|
+
- Create new product
|
|
55
|
+
- Update existing product
|
|
56
|
+
- Delete product
|
|
57
|
+
|
|
58
|
+
### Manage Prices
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
stripeconf prices
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Operations available:
|
|
65
|
+
- List all prices
|
|
66
|
+
- View price details
|
|
67
|
+
- Create new price (one-time or recurring)
|
|
68
|
+
- Update price
|
|
69
|
+
- Archive price
|
|
70
|
+
|
|
71
|
+
## Programmatic Usage
|
|
72
|
+
|
|
73
|
+
### Basic Example
|
|
74
|
+
|
|
75
|
+
```javascript
|
|
76
|
+
import { ConfigManager, StripeClient } from '@profullstack/stripe-config';
|
|
77
|
+
|
|
78
|
+
// Load configuration
|
|
79
|
+
const config = new ConfigManager();
|
|
80
|
+
const project = await config.getDefaultProject();
|
|
81
|
+
|
|
82
|
+
// Initialize Stripe client
|
|
83
|
+
const stripe = new StripeClient(project);
|
|
84
|
+
|
|
85
|
+
// List products
|
|
86
|
+
const products = await stripe.listProducts({ limit: 10 });
|
|
87
|
+
console.log(`Found ${products.length} products`);
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Using High-Level Managers
|
|
91
|
+
|
|
92
|
+
```javascript
|
|
93
|
+
import { ConfigManager, ProductManager, PriceManager } from '@profullstack/stripe-config';
|
|
94
|
+
|
|
95
|
+
// Load configuration
|
|
96
|
+
const config = new ConfigManager();
|
|
97
|
+
const project = await config.getDefaultProject();
|
|
98
|
+
|
|
99
|
+
// Initialize managers
|
|
100
|
+
const products = new ProductManager(project);
|
|
101
|
+
const prices = new PriceManager(project);
|
|
102
|
+
|
|
103
|
+
// Create a product
|
|
104
|
+
const product = await products.create({
|
|
105
|
+
name: 'Premium Plan',
|
|
106
|
+
description: 'Full access to all features',
|
|
107
|
+
active: true,
|
|
108
|
+
metadata: { tier: 'premium' }
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// Create a recurring price
|
|
112
|
+
const price = await prices.create({
|
|
113
|
+
product: product.id,
|
|
114
|
+
currency: 'usd',
|
|
115
|
+
unit_amount: 2999, // $29.99
|
|
116
|
+
recurring: {
|
|
117
|
+
interval: 'month',
|
|
118
|
+
interval_count: 1
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Managing Configuration
|
|
124
|
+
|
|
125
|
+
```javascript
|
|
126
|
+
import { ConfigManager } from '@profullstack/stripe-config';
|
|
127
|
+
|
|
128
|
+
const config = new ConfigManager();
|
|
129
|
+
|
|
130
|
+
// Add a new project
|
|
131
|
+
await config.addProject({
|
|
132
|
+
name: 'my-project',
|
|
133
|
+
environment: 'test',
|
|
134
|
+
publishableKey: 'pk_test_...',
|
|
135
|
+
secretKey: 'sk_test_...',
|
|
136
|
+
defaultCurrency: 'usd'
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// List all projects
|
|
140
|
+
const projects = await config.listProjects();
|
|
141
|
+
|
|
142
|
+
// Get a specific project
|
|
143
|
+
const project = await config.getProject('my-project');
|
|
144
|
+
|
|
145
|
+
// Set default project
|
|
146
|
+
await config.setDefaultProject('my-project');
|
|
147
|
+
|
|
148
|
+
// Update project
|
|
149
|
+
await config.updateProject('my-project', {
|
|
150
|
+
defaultCurrency: 'eur'
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// Delete project
|
|
154
|
+
await config.deleteProject('my-project');
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## API Reference
|
|
158
|
+
|
|
159
|
+
### ConfigManager
|
|
160
|
+
|
|
161
|
+
Manages project configurations stored in `~/.config/stripeconf/config.json`.
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
class ConfigManager {
|
|
165
|
+
constructor(configPath?: string);
|
|
166
|
+
|
|
167
|
+
async addProject(project: Omit<ProjectConfig, 'id' | 'createdAt' | 'updatedAt'>): Promise<ProjectConfig>;
|
|
168
|
+
async getProject(name: string): Promise<ProjectConfig>;
|
|
169
|
+
async listProjects(): Promise<ProjectConfig[]>;
|
|
170
|
+
async updateProject(name: string, updates: Partial<ProjectConfig>): Promise<ProjectConfig>;
|
|
171
|
+
async deleteProject(name: string): Promise<void>;
|
|
172
|
+
async setDefaultProject(name: string): Promise<void>;
|
|
173
|
+
async getDefaultProject(): Promise<ProjectConfig>;
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### StripeClient
|
|
178
|
+
|
|
179
|
+
Low-level wrapper around the Stripe SDK.
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
class StripeClient {
|
|
183
|
+
constructor(project: ProjectConfig);
|
|
184
|
+
|
|
185
|
+
// Products
|
|
186
|
+
async createProduct(input: CreateProductInput): Promise<Stripe.Product>;
|
|
187
|
+
async getProduct(productId: string): Promise<Stripe.Product>;
|
|
188
|
+
async updateProduct(productId: string, updates: UpdateProductInput): Promise<Stripe.Product>;
|
|
189
|
+
async deleteProduct(productId: string): Promise<void>;
|
|
190
|
+
async listProducts(options?: ListOptions): Promise<Stripe.Product[]>;
|
|
191
|
+
|
|
192
|
+
// Prices
|
|
193
|
+
async createPrice(input: CreatePriceInput): Promise<Stripe.Price>;
|
|
194
|
+
async getPrice(priceId: string): Promise<Stripe.Price>;
|
|
195
|
+
async updatePrice(priceId: string, updates: UpdatePriceInput): Promise<Stripe.Price>;
|
|
196
|
+
async listPrices(options?: PriceListOptions): Promise<Stripe.Price[]>;
|
|
197
|
+
async archivePrice(priceId: string): Promise<Stripe.Price>;
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### ProductManager
|
|
202
|
+
|
|
203
|
+
High-level API for product operations.
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
class ProductManager {
|
|
207
|
+
constructor(project: ProjectConfig);
|
|
208
|
+
|
|
209
|
+
async create(input: CreateProductInput): Promise<Stripe.Product>;
|
|
210
|
+
async get(productId: string): Promise<Stripe.Product>;
|
|
211
|
+
async update(productId: string, updates: UpdateProductInput): Promise<Stripe.Product>;
|
|
212
|
+
async delete(productId: string): Promise<void>;
|
|
213
|
+
async list(options?: ListOptions): Promise<Stripe.Product[]>;
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### PriceManager
|
|
218
|
+
|
|
219
|
+
High-level API for price operations.
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
class PriceManager {
|
|
223
|
+
constructor(project: ProjectConfig);
|
|
224
|
+
|
|
225
|
+
async create(input: CreatePriceInput): Promise<Stripe.Price>;
|
|
226
|
+
async get(priceId: string): Promise<Stripe.Price>;
|
|
227
|
+
async update(priceId: string, updates: UpdatePriceInput): Promise<Stripe.Price>;
|
|
228
|
+
async archive(priceId: string): Promise<Stripe.Price>;
|
|
229
|
+
async list(options?: PriceListOptions): Promise<Stripe.Price[]>;
|
|
230
|
+
async listByProduct(productId: string): Promise<Stripe.Price[]>;
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Type Definitions
|
|
235
|
+
|
|
236
|
+
All TypeScript types are exported from the main module:
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
import type {
|
|
240
|
+
ProjectConfig,
|
|
241
|
+
Config,
|
|
242
|
+
CreateProductInput,
|
|
243
|
+
UpdateProductInput,
|
|
244
|
+
CreatePriceInput,
|
|
245
|
+
UpdatePriceInput,
|
|
246
|
+
RecurringConfig,
|
|
247
|
+
TierConfig,
|
|
248
|
+
ListOptions,
|
|
249
|
+
PriceListOptions,
|
|
250
|
+
} from '@profullstack/stripe-config';
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
## Configuration File
|
|
254
|
+
|
|
255
|
+
Configuration is stored in `~/.config/stripeconf/config.json`:
|
|
256
|
+
|
|
257
|
+
```json
|
|
258
|
+
{
|
|
259
|
+
"version": "1.0.0",
|
|
260
|
+
"projects": [
|
|
261
|
+
{
|
|
262
|
+
"id": "uuid",
|
|
263
|
+
"name": "my-project",
|
|
264
|
+
"environment": "test",
|
|
265
|
+
"publishableKey": "pk_test_...",
|
|
266
|
+
"secretKey": "sk_test_...",
|
|
267
|
+
"webhookSecret": "whsec_...",
|
|
268
|
+
"defaultCurrency": "usd",
|
|
269
|
+
"createdAt": "2024-01-01T00:00:00.000Z",
|
|
270
|
+
"updatedAt": "2024-01-01T00:00:00.000Z"
|
|
271
|
+
}
|
|
272
|
+
],
|
|
273
|
+
"defaultProject": "my-project"
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## Security
|
|
278
|
+
|
|
279
|
+
- Configuration files are stored with `0600` permissions (owner read/write only)
|
|
280
|
+
- Configuration directory has `0700` permissions (owner full access only)
|
|
281
|
+
- API keys are never logged or displayed in error messages
|
|
282
|
+
- All user inputs are validated before API calls
|
|
283
|
+
|
|
284
|
+
## Examples
|
|
285
|
+
|
|
286
|
+
See the [`examples/`](./examples) directory for more usage examples:
|
|
287
|
+
|
|
288
|
+
- [`basic-usage.js`](./examples/basic-usage.js) - Basic configuration and product listing
|
|
289
|
+
- [`create-product.js`](./examples/create-product.js) - Creating products with prices
|
|
290
|
+
|
|
291
|
+
## Development
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
# Install dependencies
|
|
295
|
+
pnpm install
|
|
296
|
+
|
|
297
|
+
# Run tests
|
|
298
|
+
pnpm test
|
|
299
|
+
|
|
300
|
+
# Run tests with coverage
|
|
301
|
+
pnpm test:coverage
|
|
302
|
+
|
|
303
|
+
# Build
|
|
304
|
+
pnpm build
|
|
305
|
+
|
|
306
|
+
# Lint
|
|
307
|
+
pnpm lint
|
|
308
|
+
|
|
309
|
+
# Format code
|
|
310
|
+
pnpm format
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
## Testing
|
|
314
|
+
|
|
315
|
+
The project uses Vitest for testing with comprehensive unit test coverage:
|
|
316
|
+
|
|
317
|
+
```bash
|
|
318
|
+
# Run all tests
|
|
319
|
+
pnpm test
|
|
320
|
+
|
|
321
|
+
# Run tests in watch mode
|
|
322
|
+
pnpm test:watch
|
|
323
|
+
|
|
324
|
+
# Generate coverage report
|
|
325
|
+
pnpm test:coverage
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
## License
|
|
329
|
+
|
|
330
|
+
ISC
|
|
331
|
+
|
|
332
|
+
## Contributing
|
|
333
|
+
|
|
334
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
335
|
+
|
|
336
|
+
## Support
|
|
337
|
+
|
|
338
|
+
For issues and questions, please open an issue on GitHub.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prices.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/prices.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAkEnD"}
|