Skip to content

Commit b2be996

Browse files
committed
Release 0.0.1-alpha0
0 parents  commit b2be996

File tree

2,793 files changed

+200706
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,793 files changed

+200706
-0
lines changed

.fernignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Specify files that shouldn't be modified by Fern

.github/workflows/ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: ci
2+
3+
on: [push]
4+
5+
jobs:
6+
compile:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout repo
11+
uses: actions/checkout@v3
12+
13+
- name: Set up node
14+
uses: actions/setup-node@v3
15+
16+
- name: Compile
17+
run: yarn && yarn build
18+
19+
test:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout repo
24+
uses: actions/checkout@v3
25+
26+
- name: Set up node
27+
uses: actions/setup-node@v3
28+
29+
- name: Compile
30+
run: yarn && yarn test

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.DS_Store
3+
/dist

.npmignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
node_modules
2+
src
3+
tests
4+
.gitignore
5+
.github
6+
.fernignore
7+
.prettierrc.yml
8+
tsconfig.json
9+
yarn.lock

.prettierrc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tabWidth: 4
2+
printWidth: 120

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Stripe.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# Stripe TypeScript Library
2+
3+
[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Fstripe-demo%2Fstripe-node)
4+
[![npm shield](https://img.shields.io/npm/v/stripe)](https://www.npmjs.com/package/stripe)
5+
6+
The Stripe TypeScript library provides convenient access to the Stripe API from TypeScript.
7+
8+
## Installation
9+
10+
```sh
11+
npm i -s stripe
12+
```
13+
14+
## Reference
15+
16+
A full reference for this library is available [here](./reference.md).
17+
18+
## Usage
19+
20+
Instantiate and use the client with the following:
21+
22+
```typescript
23+
import { StripeClient } from "stripe";
24+
25+
const client = new StripeClient({ username: "YOUR_USERNAME", password: "YOUR_PASSWORD" });
26+
await client.postCustomersCustomerSourcesId("customer", "id");
27+
```
28+
29+
## Request And Response Types
30+
31+
The SDK exports all request and response types as TypeScript interfaces. Simply import them with the
32+
following namespace:
33+
34+
```typescript
35+
import { Stripe } from "stripe";
36+
37+
const request: Stripe.AccountRetrieveRequest = {
38+
...
39+
};
40+
```
41+
42+
## Exception Handling
43+
44+
When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
45+
will be thrown.
46+
47+
```typescript
48+
import { StripeError } from "stripe";
49+
50+
try {
51+
await client.postCustomersCustomerSourcesId(...);
52+
} catch (err) {
53+
if (err instanceof StripeError) {
54+
console.log(err.statusCode);
55+
console.log(err.message);
56+
console.log(err.body);
57+
}
58+
}
59+
```
60+
61+
## Advanced
62+
63+
### Additional Headers
64+
65+
If you would like to send additional headers as part of the request, use the `headers` request option.
66+
67+
```typescript
68+
const response = await client.postCustomersCustomerSourcesId(..., {
69+
headers: {
70+
'X-Custom-Header': 'custom value'
71+
}
72+
});
73+
```
74+
75+
### Retries
76+
77+
The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
78+
as the request is deemed retriable and the number of retry attempts has not grown larger than the configured
79+
retry limit (default: 2).
80+
81+
A request is deemed retriable when any of the following HTTP status codes is returned:
82+
83+
- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
84+
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
85+
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
86+
87+
Use the `maxRetries` request option to configure this behavior.
88+
89+
```typescript
90+
const response = await client.postCustomersCustomerSourcesId(..., {
91+
maxRetries: 0 // override maxRetries at the request level
92+
});
93+
```
94+
95+
### Timeouts
96+
97+
The SDK defaults to a 60 second timeout. Use the `timeoutInSeconds` option to configure this behavior.
98+
99+
```typescript
100+
const response = await client.postCustomersCustomerSourcesId(..., {
101+
timeoutInSeconds: 30 // override timeout to 30s
102+
});
103+
```
104+
105+
### Aborting Requests
106+
107+
The SDK allows users to abort requests at any point by passing in an abort signal.
108+
109+
```typescript
110+
const controller = new AbortController();
111+
const response = await client.postCustomersCustomerSourcesId(..., {
112+
abortSignal: controller.signal
113+
});
114+
controller.abort(); // aborts the request
115+
```
116+
117+
### Runtime Compatibility
118+
119+
The SDK defaults to `node-fetch` but will use the global fetch client if present. The SDK works in the following
120+
runtimes:
121+
122+
- Node.js 18+
123+
- Vercel
124+
- Cloudflare Workers
125+
- Deno v1.25+
126+
- Bun 1.0+
127+
- React Native
128+
129+
### Customizing Fetch Client
130+
131+
The SDK provides a way for your to customize the underlying HTTP client / Fetch function. If you're running in an
132+
unsupported environment, this provides a way for you to break glass and ensure the SDK works.
133+
134+
```typescript
135+
import { StripeClient } from "stripe";
136+
137+
const client = new StripeClient({
138+
...
139+
fetcher: // provide your implementation here
140+
});
141+
```
142+
143+
## Contributing
144+
145+
While we value open-source contributions to this SDK, this library is generated programmatically.
146+
Additions made directly to this library would have to be moved over to our generation code,
147+
otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
148+
a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
149+
an issue first to discuss with us!
150+
151+
On the other hand, contributions to the README are always very welcome!

jest.config.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** @type {import('jest').Config} */
2+
export default {
3+
preset: "ts-jest",
4+
testEnvironment: "node",
5+
moduleNameMapper: {
6+
"(.+)\.js$": "$1",
7+
},
8+
};

package.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "stripe",
3+
"version": "0.0.1-alpha0",
4+
"private": false,
5+
"repository": "https://github.com/stripe-demo/stripe-node",
6+
"license": "MIT",
7+
"main": "./index.js",
8+
"types": "./index.d.ts",
9+
"scripts": {
10+
"format": "prettier . --write --ignore-unknown",
11+
"build": "tsc",
12+
"prepack": "cp -rv dist/. .",
13+
"test": "jest"
14+
},
15+
"dependencies": {
16+
"url-join": "4.0.1",
17+
"form-data": "^4.0.0",
18+
"formdata-node": "^6.0.3",
19+
"node-fetch": "^2.7.0",
20+
"qs": "^6.13.1",
21+
"readable-stream": "^4.5.2",
22+
"js-base64": "3.7.7"
23+
},
24+
"devDependencies": {
25+
"@types/url-join": "4.0.1",
26+
"@types/qs": "^6.9.17",
27+
"@types/node-fetch": "^2.6.12",
28+
"@types/readable-stream": "^4.0.18",
29+
"webpack": "^5.97.1",
30+
"ts-loader": "^9.5.1",
31+
"jest": "^29.7.0",
32+
"@types/jest": "^29.5.14",
33+
"ts-jest": "^29.1.1",
34+
"jest-environment-jsdom": "^29.7.0",
35+
"@types/node": "^18.19.70",
36+
"prettier": "^3.4.2",
37+
"typescript": "~5.7.2"
38+
},
39+
"browser": {
40+
"fs": false,
41+
"os": false,
42+
"path": false
43+
}
44+
}

0 commit comments

Comments
 (0)