afternoon-sdk 0.0.6

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 (3) hide show
  1. package/README.md +180 -0
  2. package/package.json +66 -0
  3. package/reference.md +1455 -0
package/README.md ADDED
@@ -0,0 +1,180 @@
1
+ # Afternoon 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%2Ffern-demo%2Fafternoon-ts-sdk)
4
+ [![npm shield](https://img.shields.io/npm/v/afternoon-sdk)](https://www.npmjs.com/package/afternoon-sdk)
5
+
6
+ The Afternoon TypeScript library provides convenient access to the Afternoon APIs from TypeScript.
7
+
8
+ ## Table of Contents
9
+
10
+ - [Installation](#installation)
11
+ - [Reference](#reference)
12
+ - [Usage](#usage)
13
+ - [Request and Response Types](#request-and-response-types)
14
+ - [Exception Handling](#exception-handling)
15
+ - [Advanced](#advanced)
16
+ - [Additional Headers](#additional-headers)
17
+ - [Retries](#retries)
18
+ - [Timeouts](#timeouts)
19
+ - [Aborting Requests](#aborting-requests)
20
+ - [Access Raw Response Data](#access-raw-response-data)
21
+ - [Runtime Compatibility](#runtime-compatibility)
22
+ - [Contributing](#contributing)
23
+
24
+ ## Installation
25
+
26
+ ```sh
27
+ npm i -s afternoon-sdk
28
+ ```
29
+
30
+ ## Reference
31
+
32
+ A full reference for this library is available [here](https://github.com/fern-demo/afternoon-ts-sdk/blob/HEAD/./reference.md).
33
+
34
+ ## Usage
35
+
36
+ Instantiate and use the client with the following:
37
+
38
+ ```typescript
39
+ import { AfternoonClient } from "afternoon-sdk";
40
+
41
+ const client = new AfternoonClient({ token: "YOUR_TOKEN" });
42
+ await client.customers.createACustomer();
43
+ ```
44
+
45
+ ## Request and Response Types
46
+
47
+ The SDK exports all request and response types as TypeScript interfaces. Simply import them with the
48
+ following namespace:
49
+
50
+ ```typescript
51
+ import { Afternoon } from "afternoon-sdk";
52
+
53
+ const request: Afternoon.GetV1CustomersRequest = {
54
+ ...
55
+ };
56
+ ```
57
+
58
+ ## Exception Handling
59
+
60
+ When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
61
+ will be thrown.
62
+
63
+ ```typescript
64
+ import { AfternoonError } from "afternoon-sdk";
65
+
66
+ try {
67
+ await client.customers.createACustomer(...);
68
+ } catch (err) {
69
+ if (err instanceof AfternoonError) {
70
+ console.log(err.statusCode);
71
+ console.log(err.message);
72
+ console.log(err.body);
73
+ console.log(err.rawResponse);
74
+ }
75
+ }
76
+ ```
77
+
78
+ ## Advanced
79
+
80
+ ### Additional Headers
81
+
82
+ If you would like to send additional headers as part of the request, use the `headers` request option.
83
+
84
+ ```typescript
85
+ const response = await client.customers.createACustomer(..., {
86
+ headers: {
87
+ 'X-Custom-Header': 'custom value'
88
+ }
89
+ });
90
+ ```
91
+
92
+ ### Retries
93
+
94
+ The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
95
+ as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
96
+ retry limit (default: 2).
97
+
98
+ A request is deemed retryable when any of the following HTTP status codes is returned:
99
+
100
+ - [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
101
+ - [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
102
+ - [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
103
+
104
+ Use the `maxRetries` request option to configure this behavior.
105
+
106
+ ```typescript
107
+ const response = await client.customers.createACustomer(..., {
108
+ maxRetries: 0 // override maxRetries at the request level
109
+ });
110
+ ```
111
+
112
+ ### Timeouts
113
+
114
+ The SDK defaults to a 60 second timeout. Use the `timeoutInSeconds` option to configure this behavior.
115
+
116
+ ```typescript
117
+ const response = await client.customers.createACustomer(..., {
118
+ timeoutInSeconds: 30 // override timeout to 30s
119
+ });
120
+ ```
121
+
122
+ ### Aborting Requests
123
+
124
+ The SDK allows users to abort requests at any point by passing in an abort signal.
125
+
126
+ ```typescript
127
+ const controller = new AbortController();
128
+ const response = await client.customers.createACustomer(..., {
129
+ abortSignal: controller.signal
130
+ });
131
+ controller.abort(); // aborts the request
132
+ ```
133
+
134
+ ### Access Raw Response Data
135
+
136
+ The SDK provides access to raw response data, including headers, through the `.withRawResponse()` method.
137
+ The `.withRawResponse()` method returns a promise that results to an object with a `data` and a `rawResponse` property.
138
+
139
+ ```typescript
140
+ const { data, rawResponse } = await client.customers.createACustomer(...).withRawResponse();
141
+
142
+ console.log(data);
143
+ console.log(rawResponse.headers['X-My-Header']);
144
+ ```
145
+
146
+ ### Runtime Compatibility
147
+
148
+ The SDK defaults to `node-fetch` but will use the global fetch client if present. The SDK works in the following
149
+ runtimes:
150
+
151
+ - Node.js 18+
152
+ - Vercel
153
+ - Cloudflare Workers
154
+ - Deno v1.25+
155
+ - Bun 1.0+
156
+ - React Native
157
+
158
+ ### Customizing Fetch Client
159
+
160
+ The SDK provides a way for you to customize the underlying HTTP client / Fetch function. If you're running in an
161
+ unsupported environment, this provides a way for you to break glass and ensure the SDK works.
162
+
163
+ ```typescript
164
+ import { AfternoonClient } from "afternoon-sdk";
165
+
166
+ const client = new AfternoonClient({
167
+ ...
168
+ fetcher: // provide your implementation here
169
+ });
170
+ ```
171
+
172
+ ## Contributing
173
+
174
+ While we value open-source contributions to this SDK, this library is generated programmatically.
175
+ Additions made directly to this library would have to be moved over to our generation code,
176
+ otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
177
+ a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
178
+ an issue first to discuss with us!
179
+
180
+ On the other hand, contributions to the README are always very welcome!
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "afternoon-sdk",
3
+ "version": "0.0.6",
4
+ "private": false,
5
+ "repository": "https://github.com/fern-demo/afternoon-ts-sdk",
6
+ "type": "commonjs",
7
+ "main": "./dist/cjs/index.js",
8
+ "module": "./dist/esm/index.mjs",
9
+ "types": "./dist/cjs/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/cjs/index.d.ts",
13
+ "import": {
14
+ "types": "./dist/esm/index.d.mts",
15
+ "default": "./dist/esm/index.mjs"
16
+ },
17
+ "require": {
18
+ "types": "./dist/cjs/index.d.ts",
19
+ "default": "./dist/cjs/index.js"
20
+ },
21
+ "default": "./dist/cjs/index.js"
22
+ },
23
+ "./package.json": "./package.json"
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "reference.md"
28
+ ],
29
+ "scripts": {
30
+ "format": "prettier . --write --ignore-unknown",
31
+ "build": "yarn build:cjs && yarn build:esm",
32
+ "build:cjs": "tsc --project ./tsconfig.cjs.json",
33
+ "build:esm": "tsc --project ./tsconfig.esm.json && node scripts/rename-to-esm-files.js dist/esm",
34
+ "test": "jest"
35
+ },
36
+ "dependencies": {
37
+ "url-join": "4.0.1",
38
+ "form-data": "^4.0.0",
39
+ "formdata-node": "^6.0.3",
40
+ "node-fetch": "^2.7.0",
41
+ "qs": "^6.13.1",
42
+ "readable-stream": "^4.5.2",
43
+ "js-base64": "3.7.7"
44
+ },
45
+ "devDependencies": {
46
+ "@types/url-join": "4.0.1",
47
+ "@types/qs": "^6.9.17",
48
+ "@types/node-fetch": "^2.6.12",
49
+ "@types/readable-stream": "^4.0.18",
50
+ "webpack": "^5.97.1",
51
+ "ts-loader": "^9.5.1",
52
+ "jest": "^29.7.0",
53
+ "@types/jest": "^29.5.14",
54
+ "ts-jest": "^29.1.1",
55
+ "jest-environment-jsdom": "^29.7.0",
56
+ "@types/node": "^18.19.70",
57
+ "prettier": "^3.4.2",
58
+ "typescript": "~5.7.2"
59
+ },
60
+ "browser": {
61
+ "fs": false,
62
+ "os": false,
63
+ "path": false
64
+ },
65
+ "packageManager": "yarn@1.22.22"
66
+ }