@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
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import { join, dirname } from 'path';
|
|
3
|
+
import { homedir } from 'os';
|
|
4
|
+
import { randomUUID } from 'crypto';
|
|
5
|
+
import { ConfigError } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Manages configuration file operations for Stripe projects
|
|
8
|
+
* Stores configuration in ~/.config/stripeconf/config.json
|
|
9
|
+
*/
|
|
10
|
+
export class ConfigManager {
|
|
11
|
+
configPath;
|
|
12
|
+
CONFIG_VERSION = '1.0.0';
|
|
13
|
+
/**
|
|
14
|
+
* Create a new ConfigManager instance
|
|
15
|
+
* @param configPath Optional custom path for config file
|
|
16
|
+
*/
|
|
17
|
+
constructor(configPath) {
|
|
18
|
+
this.configPath =
|
|
19
|
+
configPath || join(homedir(), '.config', 'stripeconf', 'config.json');
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get the current config file path
|
|
23
|
+
*/
|
|
24
|
+
getConfigPath() {
|
|
25
|
+
return this.configPath;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Ensure the config directory exists with proper permissions
|
|
29
|
+
*/
|
|
30
|
+
async ensureConfigDirectory() {
|
|
31
|
+
const configDir = dirname(this.configPath);
|
|
32
|
+
try {
|
|
33
|
+
await fs.access(configDir);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
// Directory doesn't exist, create it
|
|
37
|
+
await fs.mkdir(configDir, { recursive: true });
|
|
38
|
+
// Set directory permissions to 0700 (owner read/write/execute only)
|
|
39
|
+
await fs.chmod(configDir, 0o700);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Load configuration from file
|
|
44
|
+
* Returns empty config if file doesn't exist
|
|
45
|
+
*/
|
|
46
|
+
async loadConfig() {
|
|
47
|
+
try {
|
|
48
|
+
const data = await fs.readFile(this.configPath, 'utf-8');
|
|
49
|
+
const config = JSON.parse(data);
|
|
50
|
+
return config;
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
if (error.code === 'ENOENT') {
|
|
54
|
+
// File doesn't exist, return empty config
|
|
55
|
+
return {
|
|
56
|
+
version: this.CONFIG_VERSION,
|
|
57
|
+
projects: [],
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (error instanceof SyntaxError) {
|
|
61
|
+
throw new ConfigError(`Invalid JSON in config file: ${this.configPath}`);
|
|
62
|
+
}
|
|
63
|
+
throw new ConfigError(`Failed to load config: ${error.message}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Save configuration to file with proper permissions
|
|
68
|
+
*/
|
|
69
|
+
async saveConfig(config) {
|
|
70
|
+
try {
|
|
71
|
+
await this.ensureConfigDirectory();
|
|
72
|
+
const data = JSON.stringify(config, null, 2);
|
|
73
|
+
await fs.writeFile(this.configPath, data, 'utf-8');
|
|
74
|
+
// Set file permissions to 0600 (owner read/write only)
|
|
75
|
+
await fs.chmod(this.configPath, 0o600);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
throw new ConfigError(`Failed to save config: ${error.message}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Add a new project to the configuration
|
|
83
|
+
*/
|
|
84
|
+
async addProject(projectInput) {
|
|
85
|
+
const config = await this.loadConfig();
|
|
86
|
+
// Check if project with same name already exists
|
|
87
|
+
const existing = config.projects.find((p) => p.name === projectInput.name);
|
|
88
|
+
if (existing) {
|
|
89
|
+
throw new ConfigError(`Project with name "${projectInput.name}" already exists`);
|
|
90
|
+
}
|
|
91
|
+
// Create new project with generated ID and timestamps
|
|
92
|
+
const now = new Date().toISOString();
|
|
93
|
+
const project = {
|
|
94
|
+
...projectInput,
|
|
95
|
+
id: randomUUID(),
|
|
96
|
+
createdAt: now,
|
|
97
|
+
updatedAt: now,
|
|
98
|
+
};
|
|
99
|
+
config.projects.push(project);
|
|
100
|
+
// Set as default if it's the first project
|
|
101
|
+
if (config.projects.length === 1) {
|
|
102
|
+
config.defaultProject = project.name;
|
|
103
|
+
}
|
|
104
|
+
await this.saveConfig(config);
|
|
105
|
+
return project;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get a project by name
|
|
109
|
+
*/
|
|
110
|
+
async getProject(name) {
|
|
111
|
+
const config = await this.loadConfig();
|
|
112
|
+
const project = config.projects.find((p) => p.name === name);
|
|
113
|
+
if (!project) {
|
|
114
|
+
throw new ConfigError(`Project "${name}" not found`);
|
|
115
|
+
}
|
|
116
|
+
return project;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* List all projects
|
|
120
|
+
*/
|
|
121
|
+
async listProjects() {
|
|
122
|
+
const config = await this.loadConfig();
|
|
123
|
+
return config.projects;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Update an existing project
|
|
127
|
+
*/
|
|
128
|
+
async updateProject(name, updates) {
|
|
129
|
+
const config = await this.loadConfig();
|
|
130
|
+
const projectIndex = config.projects.findIndex((p) => p.name === name);
|
|
131
|
+
if (projectIndex === -1) {
|
|
132
|
+
throw new ConfigError(`Project "${name}" not found`);
|
|
133
|
+
}
|
|
134
|
+
// Update project with new values and updated timestamp
|
|
135
|
+
const updatedProject = {
|
|
136
|
+
...config.projects[projectIndex],
|
|
137
|
+
...updates,
|
|
138
|
+
updatedAt: new Date().toISOString(),
|
|
139
|
+
};
|
|
140
|
+
config.projects[projectIndex] = updatedProject;
|
|
141
|
+
await this.saveConfig(config);
|
|
142
|
+
return updatedProject;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Delete a project by name
|
|
146
|
+
*/
|
|
147
|
+
async deleteProject(name) {
|
|
148
|
+
const config = await this.loadConfig();
|
|
149
|
+
const projectIndex = config.projects.findIndex((p) => p.name === name);
|
|
150
|
+
if (projectIndex === -1) {
|
|
151
|
+
throw new ConfigError(`Project "${name}" not found`);
|
|
152
|
+
}
|
|
153
|
+
// Remove project from array
|
|
154
|
+
config.projects.splice(projectIndex, 1);
|
|
155
|
+
// Clear default project if it was the deleted one
|
|
156
|
+
if (config.defaultProject === name) {
|
|
157
|
+
delete config.defaultProject;
|
|
158
|
+
}
|
|
159
|
+
await this.saveConfig(config);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Set the default project
|
|
163
|
+
*/
|
|
164
|
+
async setDefaultProject(name) {
|
|
165
|
+
const config = await this.loadConfig();
|
|
166
|
+
// Verify project exists
|
|
167
|
+
const project = config.projects.find((p) => p.name === name);
|
|
168
|
+
if (!project) {
|
|
169
|
+
throw new ConfigError(`Project "${name}" not found`);
|
|
170
|
+
}
|
|
171
|
+
config.defaultProject = name;
|
|
172
|
+
await this.saveConfig(config);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Get the default project
|
|
176
|
+
*/
|
|
177
|
+
async getDefaultProject() {
|
|
178
|
+
const config = await this.loadConfig();
|
|
179
|
+
if (!config.defaultProject) {
|
|
180
|
+
throw new ConfigError('No default project set. Use setDefaultProject() to set one.');
|
|
181
|
+
}
|
|
182
|
+
return this.getProject(config.defaultProject);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=config-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-manager.js","sourceRoot":"","sources":["../../src/core/config-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC;;;GAGG;AACH,MAAM,OAAO,aAAa;IAChB,UAAU,CAAS;IACV,cAAc,GAAG,OAAO,CAAC;IAE1C;;;OAGG;IACH,YAAY,UAAmB;QAC7B,IAAI,CAAC,UAAU;YACb,UAAU,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC;IAC1E,CAAC;IAED;;OAEG;IACH,aAAa;QACX,OAAO,IAAI,CAAC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,KAAK,CAAC,iBAAiB;QACrB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QAEvC,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;YAC3B,MAAM,IAAI,WAAW,CACnB,6DAA6D,CAC9D,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAChD,CAAC;CACF"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import Stripe from 'stripe';
|
|
2
|
+
import type { ProjectConfig, CreateProductInput, UpdateProductInput, CreatePriceInput, UpdatePriceInput, ListOptions, PriceListOptions } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Wrapper around Stripe SDK for type-safe API operations
|
|
5
|
+
*/
|
|
6
|
+
export declare class StripeClient {
|
|
7
|
+
private stripe;
|
|
8
|
+
private project;
|
|
9
|
+
/**
|
|
10
|
+
* Create a new StripeClient instance
|
|
11
|
+
* @param project Project configuration containing API keys
|
|
12
|
+
*/
|
|
13
|
+
constructor(project: ProjectConfig);
|
|
14
|
+
/**
|
|
15
|
+
* Get the current project configuration
|
|
16
|
+
*/
|
|
17
|
+
getProject(): ProjectConfig;
|
|
18
|
+
/**
|
|
19
|
+
* Handle Stripe API errors and wrap them in StripeClientError
|
|
20
|
+
*/
|
|
21
|
+
private handleStripeError;
|
|
22
|
+
/**
|
|
23
|
+
* Create a new product
|
|
24
|
+
*/
|
|
25
|
+
createProduct(input: CreateProductInput): Promise<Stripe.Product>;
|
|
26
|
+
/**
|
|
27
|
+
* Retrieve a product by ID
|
|
28
|
+
*/
|
|
29
|
+
getProduct(productId: string): Promise<Stripe.Product>;
|
|
30
|
+
/**
|
|
31
|
+
* Update an existing product
|
|
32
|
+
*/
|
|
33
|
+
updateProduct(productId: string, updates: UpdateProductInput): Promise<Stripe.Product>;
|
|
34
|
+
/**
|
|
35
|
+
* Delete a product
|
|
36
|
+
*/
|
|
37
|
+
deleteProduct(productId: string): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* List products with optional filters
|
|
40
|
+
*/
|
|
41
|
+
listProducts(options?: ListOptions): Promise<Stripe.Product[]>;
|
|
42
|
+
/**
|
|
43
|
+
* Create a new price
|
|
44
|
+
*/
|
|
45
|
+
createPrice(input: CreatePriceInput): Promise<Stripe.Price>;
|
|
46
|
+
/**
|
|
47
|
+
* Retrieve a price by ID
|
|
48
|
+
*/
|
|
49
|
+
getPrice(priceId: string): Promise<Stripe.Price>;
|
|
50
|
+
/**
|
|
51
|
+
* Update an existing price
|
|
52
|
+
* Note: Most price fields are immutable after creation
|
|
53
|
+
*/
|
|
54
|
+
updatePrice(priceId: string, updates: UpdatePriceInput): Promise<Stripe.Price>;
|
|
55
|
+
/**
|
|
56
|
+
* List prices with optional filters
|
|
57
|
+
*/
|
|
58
|
+
listPrices(options?: PriceListOptions): Promise<Stripe.Price[]>;
|
|
59
|
+
/**
|
|
60
|
+
* Archive a price (prices cannot be deleted, only archived)
|
|
61
|
+
*/
|
|
62
|
+
archivePrice(priceId: string): Promise<Stripe.Price>;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=stripe-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe-client.d.ts","sourceRoot":"","sources":["../../src/core/stripe-client.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAGpB;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAgB;IAE/B;;;OAGG;gBACS,OAAO,EAAE,aAAa;IAOlC;;OAEG;IACH,UAAU,IAAI,aAAa;IAI3B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAUzB;;OAEG;IACG,aAAa,CACjB,KAAK,EAAE,kBAAkB,GACxB,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;IAS1B;;OAEG;IACG,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;IAS5D;;OAEG;IACG,aAAa,CACjB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;IAS1B;;OAEG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQrD;;OAEG;IACG,YAAY,CAChB,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IAoB5B;;OAEG;IACG,WAAW,CACf,KAAK,EAAE,gBAAgB,GACtB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;IASxB;;OAEG;IACG,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;IAStD;;;OAGG;IACG,WAAW,CACf,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;IASxB;;OAEG;IACG,UAAU,CACd,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAuB1B;;OAEG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;CAG3D"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import Stripe from 'stripe';
|
|
2
|
+
import { StripeClientError } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Wrapper around Stripe SDK for type-safe API operations
|
|
5
|
+
*/
|
|
6
|
+
export class StripeClient {
|
|
7
|
+
stripe;
|
|
8
|
+
project;
|
|
9
|
+
/**
|
|
10
|
+
* Create a new StripeClient instance
|
|
11
|
+
* @param project Project configuration containing API keys
|
|
12
|
+
*/
|
|
13
|
+
constructor(project) {
|
|
14
|
+
this.project = project;
|
|
15
|
+
this.stripe = new Stripe(project.secretKey, {
|
|
16
|
+
apiVersion: '2023-10-16',
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Get the current project configuration
|
|
21
|
+
*/
|
|
22
|
+
getProject() {
|
|
23
|
+
return this.project;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Handle Stripe API errors and wrap them in StripeClientError
|
|
27
|
+
*/
|
|
28
|
+
handleStripeError(error) {
|
|
29
|
+
const message = error.message || 'Unknown Stripe API error';
|
|
30
|
+
const statusCode = error.statusCode;
|
|
31
|
+
const code = error.code;
|
|
32
|
+
throw new StripeClientError(message, statusCode, code);
|
|
33
|
+
}
|
|
34
|
+
// ==================== Product Operations ====================
|
|
35
|
+
/**
|
|
36
|
+
* Create a new product
|
|
37
|
+
*/
|
|
38
|
+
async createProduct(input) {
|
|
39
|
+
try {
|
|
40
|
+
const product = await this.stripe.products.create(input);
|
|
41
|
+
return product;
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
this.handleStripeError(error);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Retrieve a product by ID
|
|
49
|
+
*/
|
|
50
|
+
async getProduct(productId) {
|
|
51
|
+
try {
|
|
52
|
+
const product = await this.stripe.products.retrieve(productId);
|
|
53
|
+
return product;
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
this.handleStripeError(error);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Update an existing product
|
|
61
|
+
*/
|
|
62
|
+
async updateProduct(productId, updates) {
|
|
63
|
+
try {
|
|
64
|
+
const product = await this.stripe.products.update(productId, updates);
|
|
65
|
+
return product;
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
this.handleStripeError(error);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Delete a product
|
|
73
|
+
*/
|
|
74
|
+
async deleteProduct(productId) {
|
|
75
|
+
try {
|
|
76
|
+
await this.stripe.products.del(productId);
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
this.handleStripeError(error);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* List products with optional filters
|
|
84
|
+
*/
|
|
85
|
+
async listProducts(options) {
|
|
86
|
+
try {
|
|
87
|
+
const params = {
|
|
88
|
+
limit: options?.limit || 100,
|
|
89
|
+
...(options?.starting_after && {
|
|
90
|
+
starting_after: options.starting_after,
|
|
91
|
+
}),
|
|
92
|
+
...(options?.ending_before && { ending_before: options.ending_before }),
|
|
93
|
+
...(options?.active !== undefined && { active: options.active }),
|
|
94
|
+
};
|
|
95
|
+
const response = await this.stripe.products.list(params);
|
|
96
|
+
return response.data;
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
this.handleStripeError(error);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// ==================== Price Operations ====================
|
|
103
|
+
/**
|
|
104
|
+
* Create a new price
|
|
105
|
+
*/
|
|
106
|
+
async createPrice(input) {
|
|
107
|
+
try {
|
|
108
|
+
const price = await this.stripe.prices.create(input);
|
|
109
|
+
return price;
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
this.handleStripeError(error);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Retrieve a price by ID
|
|
117
|
+
*/
|
|
118
|
+
async getPrice(priceId) {
|
|
119
|
+
try {
|
|
120
|
+
const price = await this.stripe.prices.retrieve(priceId);
|
|
121
|
+
return price;
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
this.handleStripeError(error);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Update an existing price
|
|
129
|
+
* Note: Most price fields are immutable after creation
|
|
130
|
+
*/
|
|
131
|
+
async updatePrice(priceId, updates) {
|
|
132
|
+
try {
|
|
133
|
+
const price = await this.stripe.prices.update(priceId, updates);
|
|
134
|
+
return price;
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
this.handleStripeError(error);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* List prices with optional filters
|
|
142
|
+
*/
|
|
143
|
+
async listPrices(options) {
|
|
144
|
+
try {
|
|
145
|
+
const params = {
|
|
146
|
+
limit: options?.limit || 100,
|
|
147
|
+
...(options?.starting_after && {
|
|
148
|
+
starting_after: options.starting_after,
|
|
149
|
+
}),
|
|
150
|
+
...(options?.ending_before && { ending_before: options.ending_before }),
|
|
151
|
+
...(options?.active !== undefined && { active: options.active }),
|
|
152
|
+
...(options?.product && { product: options.product }),
|
|
153
|
+
...(options?.type && { type: options.type }),
|
|
154
|
+
...(options?.recurring?.interval && {
|
|
155
|
+
recurring: { interval: options.recurring.interval },
|
|
156
|
+
}),
|
|
157
|
+
};
|
|
158
|
+
const response = await this.stripe.prices.list(params);
|
|
159
|
+
return response.data;
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
this.handleStripeError(error);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Archive a price (prices cannot be deleted, only archived)
|
|
167
|
+
*/
|
|
168
|
+
async archivePrice(priceId) {
|
|
169
|
+
return this.updatePrice(priceId, { active: false });
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=stripe-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe-client.js","sourceRoot":"","sources":["../../src/core/stripe-client.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAU5B,OAAO,EAAE,iB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AE,OAAO,CAAC,cAAc;iBACvC,CAAC;gBACF,GAAG,CAAC,OAAO,EAAE,aAAa,IAAI,EAAE,aAAa,EAAE,OAAO,CAAC,aAAa,EAAE,CAAC;gBACvE,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,SAAS,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;gBAChE,GAAG,CAAC,OAAO,EAAE,OAAO,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC;gBACrD,GAAG,CAAC,OAAO,EAAE,IAAI,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;gBAC5C,GAAG,CAAC,OAAO,EAAE,SAAS,EAAE,QAAQ,IAAI;oBAClC,SAAS,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,SAAS,CAAC,QAAQ,EAAE;iBACpD,CAAC;aACH,CAAC;YAEF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACvD,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,YAAY,CAAC,OAAe;QAChC,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IACtD,CAAC;CACF"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core type definitions for the Stripe configuration tool
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Project configuration stored in ~/.config/stripeconf/config.json
|
|
6
|
+
*/
|
|
7
|
+
export interface ProjectConfig {
|
|
8
|
+
/** Unique identifier for the project */
|
|
9
|
+
id: string;
|
|
10
|
+
/** Human-readable project name */
|
|
11
|
+
name: string;
|
|
12
|
+
/** Stripe environment (test or live) */
|
|
13
|
+
environment: 'test' | 'live';
|
|
14
|
+
/** Stripe publishable key */
|
|
15
|
+
publishableKey: string;
|
|
16
|
+
/** Stripe secret key */
|
|
17
|
+
secretKey: string;
|
|
18
|
+
/** Optional webhook secret for event verification */
|
|
19
|
+
webhookSecret?: string;
|
|
20
|
+
/** Default currency for the project (ISO 4217 code) */
|
|
21
|
+
defaultCurrency: string;
|
|
22
|
+
/** Timestamp when project was created */
|
|
23
|
+
createdAt: string;
|
|
24
|
+
/** Timestamp when project was last updated */
|
|
25
|
+
updatedAt: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Root configuration file structure
|
|
29
|
+
*/
|
|
30
|
+
export interface Config {
|
|
31
|
+
/** Configuration file version */
|
|
32
|
+
version: string;
|
|
33
|
+
/** List of configured projects */
|
|
34
|
+
projects: ProjectConfig[];
|
|
35
|
+
/** Name of the default project to use */
|
|
36
|
+
defaultProject?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Input for creating a new product
|
|
40
|
+
*/
|
|
41
|
+
export interface CreateProductInput {
|
|
42
|
+
/** Product name (required) */
|
|
43
|
+
name: string;
|
|
44
|
+
/** Product description */
|
|
45
|
+
description?: string;
|
|
46
|
+
/** Whether the product is active */
|
|
47
|
+
active?: boolean;
|
|
48
|
+
/** Custom metadata key-value pairs */
|
|
49
|
+
metadata?: Record<string, string>;
|
|
50
|
+
/** Array of image URLs */
|
|
51
|
+
images?: string[];
|
|
52
|
+
/** Stripe tax code */
|
|
53
|
+
tax_code?: string;
|
|
54
|
+
/** Unit label (e.g., "seat", "GB") */
|
|
55
|
+
unit_label?: string;
|
|
56
|
+
/** Statement descriptor for card statements */
|
|
57
|
+
statement_descriptor?: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Input for updating an existing product
|
|
61
|
+
*/
|
|
62
|
+
export interface UpdateProductInput {
|
|
63
|
+
/** Product name */
|
|
64
|
+
name?: string;
|
|
65
|
+
/** Product description */
|
|
66
|
+
description?: string;
|
|
67
|
+
/** Whether the product is active */
|
|
68
|
+
active?: boolean;
|
|
69
|
+
/** Custom metadata key-value pairs */
|
|
70
|
+
metadata?: Record<string, string>;
|
|
71
|
+
/** Array of image URLs */
|
|
72
|
+
images?: string[];
|
|
73
|
+
/** Stripe tax code */
|
|
74
|
+
tax_code?: string;
|
|
75
|
+
/** Unit label */
|
|
76
|
+
unit_label?: string;
|
|
77
|
+
/** Statement descriptor */
|
|
78
|
+
statement_descriptor?: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Recurring price configuration
|
|
82
|
+
*/
|
|
83
|
+
export interface RecurringConfig {
|
|
84
|
+
/** Billing interval */
|
|
85
|
+
interval: 'day' | 'week' | 'month' | 'year';
|
|
86
|
+
/** Number of intervals between billings */
|
|
87
|
+
interval_count?: number;
|
|
88
|
+
/** Usage type for metered billing */
|
|
89
|
+
usage_type?: 'licensed' | 'metered';
|
|
90
|
+
/** How to aggregate usage for metered billing */
|
|
91
|
+
aggregate_usage?: 'sum' | 'last_during_period' | 'max';
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Tiered pricing configuration
|
|
95
|
+
*/
|
|
96
|
+
export interface TierConfig {
|
|
97
|
+
/** Upper bound of this tier (use 'inf' for unlimited) */
|
|
98
|
+
up_to: number | 'inf';
|
|
99
|
+
/** Price per unit in this tier */
|
|
100
|
+
unit_amount?: number;
|
|
101
|
+
/** Flat fee for this tier */
|
|
102
|
+
flat_amount?: number;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Quantity transformation configuration
|
|
106
|
+
*/
|
|
107
|
+
export interface TransformQuantityConfig {
|
|
108
|
+
/** Divide quantity by this number */
|
|
109
|
+
divide_by: number;
|
|
110
|
+
/** Rounding strategy */
|
|
111
|
+
round: 'up' | 'down';
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Input for creating a new price
|
|
115
|
+
*/
|
|
116
|
+
export interface CreatePriceInput {
|
|
117
|
+
/** Product ID this price belongs to */
|
|
118
|
+
product: string;
|
|
119
|
+
/** Currency (ISO 4217 code) */
|
|
120
|
+
currency: string;
|
|
121
|
+
/** Price amount in cents (required for one-time, optional for metered) */
|
|
122
|
+
unit_amount?: number;
|
|
123
|
+
/** Whether the price is active */
|
|
124
|
+
active?: boolean;
|
|
125
|
+
/** Recurring billing configuration */
|
|
126
|
+
recurring?: RecurringConfig;
|
|
127
|
+
/** Billing scheme */
|
|
128
|
+
billing_scheme?: 'per_unit' | 'tiered';
|
|
129
|
+
/** Tiered pricing configuration */
|
|
130
|
+
tiers?: TierConfig[];
|
|
131
|
+
/** Tiers mode */
|
|
132
|
+
tiers_mode?: 'graduated' | 'volume';
|
|
133
|
+
/** Quantity transformation */
|
|
134
|
+
transform_quantity?: TransformQuantityConfig;
|
|
135
|
+
/** Custom metadata */
|
|
136
|
+
metadata?: Record<string, string>;
|
|
137
|
+
/** Internal nickname */
|
|
138
|
+
nickname?: string;
|
|
139
|
+
/** Lookup key for API references */
|
|
140
|
+
lookup_key?: string;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Input for updating an existing price
|
|
144
|
+
* Note: Most price fields are immutable after creation
|
|
145
|
+
*/
|
|
146
|
+
export interface UpdatePriceInput {
|
|
147
|
+
/** Whether the price is active */
|
|
148
|
+
active?: boolean;
|
|
149
|
+
/** Custom metadata */
|
|
150
|
+
metadata?: Record<string, string>;
|
|
151
|
+
/** Internal nickname */
|
|
152
|
+
nickname?: string;
|
|
153
|
+
/** Lookup key */
|
|
154
|
+
lookup_key?: string;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Options for listing resources
|
|
158
|
+
*/
|
|
159
|
+
export interface ListOptions {
|
|
160
|
+
/** Maximum number of items to return */
|
|
161
|
+
limit?: number;
|
|
162
|
+
/** Cursor for pagination (ID to start after) */
|
|
163
|
+
starting_after?: string;
|
|
164
|
+
/** Cursor for pagination (ID to end before) */
|
|
165
|
+
ending_before?: string;
|
|
166
|
+
/** Filter by active status */
|
|
167
|
+
active?: boolean;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Options for listing prices
|
|
171
|
+
*/
|
|
172
|
+
export interface PriceListOptions extends ListOptions {
|
|
173
|
+
/** Filter by product ID */
|
|
174
|
+
product?: string;
|
|
175
|
+
/** Filter by price type */
|
|
176
|
+
type?: 'one_time' | 'recurring';
|
|
177
|
+
/** Filter by recurring interval */
|
|
178
|
+
recurring?: {
|
|
179
|
+
interval?: 'day' | 'week' | 'month' | 'year';
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Custom error class for configuration errors
|
|
184
|
+
*/
|
|
185
|
+
export declare class ConfigError extends Error {
|
|
186
|
+
constructor(message: string);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Custom error class for Stripe API errors
|
|
190
|
+
*/
|
|
191
|
+
export declare class StripeClientError extends Error {
|
|
192
|
+
statusCode?: number | undefined;
|
|
193
|
+
code?: string | undefined;
|
|
194
|
+
constructor(message: string, statusCode?: number | undefined, code?: string | undefined);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Custom error class for validation errors
|
|
198
|
+
*/
|
|
199
|
+
export declare class ValidationError extends Error {
|
|
200
|
+
field?: string | undefined;
|
|
201
|
+
constructor(message: string, field?: string | undefined);
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,wCAAwC;IACxC,EAAE,EAAE,MAAM,CAAC;IACX,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,wCAAwC;IACxC,WAAW,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