@51eat/sdk 0.0.4

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 +306 -0
  2. package/package.json +168 -0
  3. package/reference.md +2928 -0
package/README.md ADDED
@@ -0,0 +1,306 @@
1
+ # 51Eat 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%2FNexuForma%2F51eat-sdk-typescript)
4
+ [![npm shield](https://img.shields.io/npm/v/@51eat/sdk)](https://www.npmjs.com/package/@51eat/sdk)
5
+
6
+ The 51Eat TypeScript library provides convenient access to the 51Eat APIs from TypeScript.
7
+
8
+ ## Table of Contents
9
+
10
+ - [Installation](#installation)
11
+ - [Reference](#reference)
12
+ - [Usage](#usage)
13
+ - [Environments](#environments)
14
+ - [Request and Response Types](#request-and-response-types)
15
+ - [Exception Handling](#exception-handling)
16
+ - [Advanced](#advanced)
17
+ - [Subpackage Exports](#subpackage-exports)
18
+ - [Additional Headers](#additional-headers)
19
+ - [Additional Query String Parameters](#additional-query-string-parameters)
20
+ - [Retries](#retries)
21
+ - [Timeouts](#timeouts)
22
+ - [Aborting Requests](#aborting-requests)
23
+ - [Access Raw Response Data](#access-raw-response-data)
24
+ - [Logging](#logging)
25
+ - [Custom Fetch](#custom-fetch)
26
+ - [Runtime Compatibility](#runtime-compatibility)
27
+ - [Contributing](#contributing)
28
+
29
+ ## Installation
30
+
31
+ ```sh
32
+ npm i -s @51eat/sdk
33
+ ```
34
+
35
+ ## Reference
36
+
37
+ A full reference for this library is available [here](https://github.com/NexuForma/51eat-sdk-typescript/blob/HEAD/./reference.md).
38
+
39
+ ## Usage
40
+
41
+ Instantiate and use the client with the following:
42
+
43
+ ```typescript
44
+ import { FiveOneEatClient } from "@51eat/sdk";
45
+
46
+ const client = new FiveOneEatClient({ token: "YOUR_TOKEN" });
47
+ await client.authentication.registerCustomer({
48
+ name: "name",
49
+ email: "email",
50
+ password: "password",
51
+ device_name: "device_name",
52
+ password_confirmation: "password_confirmation"
53
+ });
54
+ ```
55
+
56
+ ## Environments
57
+
58
+ This SDK allows you to configure different environments for API requests.
59
+
60
+ ```typescript
61
+ import { FiveOneEatClient, FiveOneEatEnvironment } from "@51eat/sdk";
62
+
63
+ const client = new FiveOneEatClient({
64
+ environment: FiveOneEatEnvironment.Production,
65
+ });
66
+ ```
67
+
68
+ ## Request and Response Types
69
+
70
+ The SDK exports all request and response types as TypeScript interfaces. Simply import them with the
71
+ following namespace:
72
+
73
+ ```typescript
74
+ import { FiveOneEat } from "@51eat/sdk";
75
+
76
+ const request: FiveOneEat.RegisterCustomerRequest = {
77
+ ...
78
+ };
79
+ ```
80
+
81
+ ## Exception Handling
82
+
83
+ When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
84
+ will be thrown.
85
+
86
+ ```typescript
87
+ import { FiveOneEatError } from "@51eat/sdk";
88
+
89
+ try {
90
+ await client.authentication.registerCustomer(...);
91
+ } catch (err) {
92
+ if (err instanceof FiveOneEatError) {
93
+ console.log(err.statusCode);
94
+ console.log(err.message);
95
+ console.log(err.body);
96
+ console.log(err.rawResponse);
97
+ }
98
+ }
99
+ ```
100
+
101
+ ## Advanced
102
+
103
+ ### Subpackage Exports
104
+
105
+ This SDK supports direct imports of subpackage clients, which allows JavaScript bundlers to tree-shake and include only the imported subpackage code. This results in much smaller bundle sizes.
106
+
107
+ ```typescript
108
+ import { AuthenticationClient } from '@51eat/sdk/authentication';
109
+
110
+ const client = new AuthenticationClient({...});
111
+ ```
112
+
113
+ ### Additional Headers
114
+
115
+ If you would like to send additional headers as part of the request, use the `headers` request option.
116
+
117
+ ```typescript
118
+ import { FiveOneEatClient } from "@51eat/sdk";
119
+
120
+ const client = new FiveOneEatClient({
121
+ ...
122
+ headers: {
123
+ 'X-Custom-Header': 'custom value'
124
+ }
125
+ });
126
+
127
+ const response = await client.authentication.registerCustomer(..., {
128
+ headers: {
129
+ 'X-Custom-Header': 'custom value'
130
+ }
131
+ });
132
+ ```
133
+
134
+ ### Additional Query String Parameters
135
+
136
+ If you would like to send additional query string parameters as part of the request, use the `queryParams` request option.
137
+
138
+ ```typescript
139
+ const response = await client.authentication.registerCustomer(..., {
140
+ queryParams: {
141
+ 'customQueryParamKey': 'custom query param value'
142
+ }
143
+ });
144
+ ```
145
+
146
+ ### Retries
147
+
148
+ The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
149
+ as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
150
+ retry limit (default: 2).
151
+
152
+ A request is deemed retryable when any of the following HTTP status codes is returned:
153
+
154
+ - [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
155
+ - [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
156
+ - [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
157
+
158
+ Use the `maxRetries` request option to configure this behavior.
159
+
160
+ ```typescript
161
+ const response = await client.authentication.registerCustomer(..., {
162
+ maxRetries: 0 // override maxRetries at the request level
163
+ });
164
+ ```
165
+
166
+ ### Timeouts
167
+
168
+ The SDK defaults to a 60 second timeout. Use the `timeoutInSeconds` option to configure this behavior.
169
+
170
+ ```typescript
171
+ const response = await client.authentication.registerCustomer(..., {
172
+ timeoutInSeconds: 30 // override timeout to 30s
173
+ });
174
+ ```
175
+
176
+ ### Aborting Requests
177
+
178
+ The SDK allows users to abort requests at any point by passing in an abort signal.
179
+
180
+ ```typescript
181
+ const controller = new AbortController();
182
+ const response = await client.authentication.registerCustomer(..., {
183
+ abortSignal: controller.signal
184
+ });
185
+ controller.abort(); // aborts the request
186
+ ```
187
+
188
+ ### Access Raw Response Data
189
+
190
+ The SDK provides access to raw response data, including headers, through the `.withRawResponse()` method.
191
+ The `.withRawResponse()` method returns a promise that results to an object with a `data` and a `rawResponse` property.
192
+
193
+ ```typescript
194
+ const { data, rawResponse } = await client.authentication.registerCustomer(...).withRawResponse();
195
+
196
+ console.log(data);
197
+ console.log(rawResponse.headers['X-My-Header']);
198
+ ```
199
+
200
+ ### Logging
201
+
202
+ The SDK supports logging. You can configure the logger by passing in a `logging` object to the client options.
203
+
204
+ ```typescript
205
+ import { FiveOneEatClient, logging } from "@51eat/sdk";
206
+
207
+ const client = new FiveOneEatClient({
208
+ ...
209
+ logging: {
210
+ level: logging.LogLevel.Debug, // defaults to logging.LogLevel.Info
211
+ logger: new logging.ConsoleLogger(), // defaults to ConsoleLogger
212
+ silent: false, // defaults to true, set to false to enable logging
213
+ }
214
+ });
215
+ ```
216
+ The `logging` object can have the following properties:
217
+ - `level`: The log level to use. Defaults to `logging.LogLevel.Info`.
218
+ - `logger`: The logger to use. Defaults to a `logging.ConsoleLogger`.
219
+ - `silent`: Whether to silence the logger. Defaults to `true`.
220
+
221
+ The `level` property can be one of the following values:
222
+ - `logging.LogLevel.Debug`
223
+ - `logging.LogLevel.Info`
224
+ - `logging.LogLevel.Warn`
225
+ - `logging.LogLevel.Error`
226
+
227
+ To provide a custom logger, you can pass in an object that implements the `logging.ILogger` interface.
228
+
229
+ <details>
230
+ <summary>Custom logger examples</summary>
231
+
232
+ Here's an example using the popular `winston` logging library.
233
+ ```ts
234
+ import winston from 'winston';
235
+
236
+ const winstonLogger = winston.createLogger({...});
237
+
238
+ const logger: logging.ILogger = {
239
+ debug: (msg, ...args) => winstonLogger.debug(msg, ...args),
240
+ info: (msg, ...args) => winstonLogger.info(msg, ...args),
241
+ warn: (msg, ...args) => winstonLogger.warn(msg, ...args),
242
+ error: (msg, ...args) => winstonLogger.error(msg, ...args),
243
+ };
244
+ ```
245
+
246
+ Here's an example using the popular `pino` logging library.
247
+
248
+ ```ts
249
+ import pino from 'pino';
250
+
251
+ const pinoLogger = pino({...});
252
+
253
+ const logger: logging.ILogger = {
254
+ debug: (msg, ...args) => pinoLogger.debug(args, msg),
255
+ info: (msg, ...args) => pinoLogger.info(args, msg),
256
+ warn: (msg, ...args) => pinoLogger.warn(args, msg),
257
+ error: (msg, ...args) => pinoLogger.error(args, msg),
258
+ };
259
+ ```
260
+ </details>
261
+
262
+
263
+ ### Custom Fetch
264
+
265
+ The SDK provides a low-level `fetch` method for making custom HTTP requests while still
266
+ benefiting from SDK-level configuration like authentication, retries, timeouts, and logging.
267
+ This is useful for calling API endpoints not yet supported in the SDK.
268
+
269
+ ```typescript
270
+ const response = await client.fetch("/v1/custom/endpoint", {
271
+ method: "GET",
272
+ }, {
273
+ timeoutInSeconds: 30,
274
+ maxRetries: 3,
275
+ headers: {
276
+ "X-Custom-Header": "custom-value",
277
+ },
278
+ });
279
+
280
+ const data = await response.json();
281
+ ```
282
+
283
+ ### Runtime Compatibility
284
+
285
+
286
+ The SDK works in the following runtimes:
287
+
288
+
289
+
290
+ - Node.js 18+
291
+ - Vercel
292
+ - Cloudflare Workers
293
+ - Deno v1.25+
294
+ - Bun 1.0+
295
+ - React Native
296
+
297
+
298
+ ## Contributing
299
+
300
+ While we value open-source contributions to this SDK, this library is generated programmatically.
301
+ Additions made directly to this library would have to be moved over to our generation code,
302
+ otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
303
+ a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
304
+ an issue first to discuss with us!
305
+
306
+ On the other hand, contributions to the README are always very welcome!
package/package.json ADDED
@@ -0,0 +1,168 @@
1
+ {
2
+ "name": "@51eat/sdk",
3
+ "version": "0.0.4",
4
+ "private": false,
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/NexuForma/51eat-sdk-typescript.git"
8
+ },
9
+ "type": "commonjs",
10
+ "main": "./dist/cjs/index.js",
11
+ "module": "./dist/esm/index.mjs",
12
+ "types": "./dist/cjs/index.d.ts",
13
+ "exports": {
14
+ ".": {
15
+ "import": {
16
+ "types": "./dist/esm/index.d.mts",
17
+ "default": "./dist/esm/index.mjs"
18
+ },
19
+ "require": {
20
+ "types": "./dist/cjs/index.d.ts",
21
+ "default": "./dist/cjs/index.js"
22
+ },
23
+ "default": "./dist/cjs/index.js"
24
+ },
25
+ "./authentication": {
26
+ "import": {
27
+ "types": "./dist/esm/api/resources/authentication/exports.d.mts",
28
+ "default": "./dist/esm/api/resources/authentication/exports.mjs"
29
+ },
30
+ "require": {
31
+ "types": "./dist/cjs/api/resources/authentication/exports.d.ts",
32
+ "default": "./dist/cjs/api/resources/authentication/exports.js"
33
+ },
34
+ "default": "./dist/cjs/api/resources/authentication/exports.js"
35
+ },
36
+ "./broadcasting": {
37
+ "import": {
38
+ "types": "./dist/esm/api/resources/broadcasting/exports.d.mts",
39
+ "default": "./dist/esm/api/resources/broadcasting/exports.mjs"
40
+ },
41
+ "require": {
42
+ "types": "./dist/cjs/api/resources/broadcasting/exports.d.ts",
43
+ "default": "./dist/cjs/api/resources/broadcasting/exports.js"
44
+ },
45
+ "default": "./dist/cjs/api/resources/broadcasting/exports.js"
46
+ },
47
+ "./businessContent": {
48
+ "import": {
49
+ "types": "./dist/esm/api/resources/businessContent/exports.d.mts",
50
+ "default": "./dist/esm/api/resources/businessContent/exports.mjs"
51
+ },
52
+ "require": {
53
+ "types": "./dist/cjs/api/resources/businessContent/exports.d.ts",
54
+ "default": "./dist/cjs/api/resources/businessContent/exports.js"
55
+ },
56
+ "default": "./dist/cjs/api/resources/businessContent/exports.js"
57
+ },
58
+ "./businessProfiles": {
59
+ "import": {
60
+ "types": "./dist/esm/api/resources/businessProfiles/exports.d.mts",
61
+ "default": "./dist/esm/api/resources/businessProfiles/exports.mjs"
62
+ },
63
+ "require": {
64
+ "types": "./dist/cjs/api/resources/businessProfiles/exports.d.ts",
65
+ "default": "./dist/cjs/api/resources/businessProfiles/exports.js"
66
+ },
67
+ "default": "./dist/cjs/api/resources/businessProfiles/exports.js"
68
+ },
69
+ "./customerMessaging": {
70
+ "import": {
71
+ "types": "./dist/esm/api/resources/customerMessaging/exports.d.mts",
72
+ "default": "./dist/esm/api/resources/customerMessaging/exports.mjs"
73
+ },
74
+ "require": {
75
+ "types": "./dist/cjs/api/resources/customerMessaging/exports.d.ts",
76
+ "default": "./dist/cjs/api/resources/customerMessaging/exports.js"
77
+ },
78
+ "default": "./dist/cjs/api/resources/customerMessaging/exports.js"
79
+ },
80
+ "./discovery": {
81
+ "import": {
82
+ "types": "./dist/esm/api/resources/discovery/exports.d.mts",
83
+ "default": "./dist/esm/api/resources/discovery/exports.mjs"
84
+ },
85
+ "require": {
86
+ "types": "./dist/cjs/api/resources/discovery/exports.d.ts",
87
+ "default": "./dist/cjs/api/resources/discovery/exports.js"
88
+ },
89
+ "default": "./dist/cjs/api/resources/discovery/exports.js"
90
+ },
91
+ "./events": {
92
+ "import": {
93
+ "types": "./dist/esm/api/resources/events/exports.d.mts",
94
+ "default": "./dist/esm/api/resources/events/exports.mjs"
95
+ },
96
+ "require": {
97
+ "types": "./dist/cjs/api/resources/events/exports.d.ts",
98
+ "default": "./dist/cjs/api/resources/events/exports.js"
99
+ },
100
+ "default": "./dist/cjs/api/resources/events/exports.js"
101
+ },
102
+ "./myAccount": {
103
+ "import": {
104
+ "types": "./dist/esm/api/resources/myAccount/exports.d.mts",
105
+ "default": "./dist/esm/api/resources/myAccount/exports.mjs"
106
+ },
107
+ "require": {
108
+ "types": "./dist/cjs/api/resources/myAccount/exports.d.ts",
109
+ "default": "./dist/cjs/api/resources/myAccount/exports.js"
110
+ },
111
+ "default": "./dist/cjs/api/resources/myAccount/exports.js"
112
+ },
113
+ "./ticketing": {
114
+ "import": {
115
+ "types": "./dist/esm/api/resources/ticketing/exports.d.mts",
116
+ "default": "./dist/esm/api/resources/ticketing/exports.mjs"
117
+ },
118
+ "require": {
119
+ "types": "./dist/cjs/api/resources/ticketing/exports.d.ts",
120
+ "default": "./dist/cjs/api/resources/ticketing/exports.js"
121
+ },
122
+ "default": "./dist/cjs/api/resources/ticketing/exports.js"
123
+ },
124
+ "./package.json": "./package.json"
125
+ },
126
+ "files": [
127
+ "dist",
128
+ "reference.md",
129
+ "README.md",
130
+ "LICENSE"
131
+ ],
132
+ "scripts": {
133
+ "format": "biome format --write --skip-parse-errors --no-errors-on-unmatched --max-diagnostics=none",
134
+ "format:check": "biome format --skip-parse-errors --no-errors-on-unmatched --max-diagnostics=none",
135
+ "lint": "biome lint --skip-parse-errors --no-errors-on-unmatched --max-diagnostics=none",
136
+ "lint:fix": "biome lint --fix --unsafe --skip-parse-errors --no-errors-on-unmatched --max-diagnostics=none",
137
+ "check": "biome check --skip-parse-errors --no-errors-on-unmatched --max-diagnostics=none",
138
+ "check:fix": "biome check --fix --unsafe --skip-parse-errors --no-errors-on-unmatched --max-diagnostics=none",
139
+ "build": "pnpm build:cjs && pnpm build:esm",
140
+ "build:cjs": "tsc --project ./tsconfig.cjs.json",
141
+ "build:esm": "tsc --project ./tsconfig.esm.json && node scripts/rename-to-esm-files.js dist/esm",
142
+ "test": "vitest",
143
+ "test:unit": "vitest --project unit",
144
+ "test:wire": "vitest --project wire"
145
+ },
146
+ "dependencies": {},
147
+ "devDependencies": {
148
+ "webpack": "^5.105.4",
149
+ "ts-loader": "^9.5.4",
150
+ "vitest": "^4.1.1",
151
+ "msw": "2.11.2",
152
+ "@types/node": "^18.19.70",
153
+ "typescript": "~5.9.3",
154
+ "@biomejs/biome": "2.4.10"
155
+ },
156
+ "browser": {
157
+ "fs": false,
158
+ "os": false,
159
+ "path": false,
160
+ "stream": false,
161
+ "crypto": false
162
+ },
163
+ "packageManager": "pnpm@10.33.0",
164
+ "engines": {
165
+ "node": ">=18.0.0"
166
+ },
167
+ "sideEffects": false
168
+ }