audible-api-ts 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Thibaut
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.
package/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # audible-api-ts
2
+
3
+ [![CI](https://github.com/moifort/audible-api-ts/actions/workflows/ci.yml/badge.svg)](https://github.com/moifort/audible-api-ts/actions/workflows/ci.yml)
4
+ [![npm](https://img.shields.io/npm/v/audible-api-ts)](https://www.npmjs.com/package/audible-api-ts)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)
7
+
8
+ **A fully typed TypeScript client for the Audible API.**
9
+
10
+ Authentication, library, wishlist — all with complete type safety. The first maintained TypeScript alternative to [mkb79/Audible](https://github.com/mkb79/Audible) (Python).
11
+
12
+ **[Documentation](https://moifort.github.io/audible-api-ts)**
13
+
14
+ ## Features
15
+
16
+ - **Complete PKCE authentication** — Same OAuth flow as the official Audible iOS app
17
+ - **Signed API requests** — RSA SHA256 request signing with device private key
18
+ - **Library & wishlist** — Fetch all audiobooks with automatic pagination
19
+ - **10 locales** — US, UK, France, Germany, Italy, Spain, Canada, Australia, India, Japan
20
+ - **Fully typed** — Every function, response, and credential has TypeScript types
21
+ - **Minimal dependencies** — Only `zod` for response validation
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ bun add audible-api-ts
27
+ # or
28
+ npm install audible-api-ts
29
+ ```
30
+
31
+ Requires Node.js 18+ (for native `fetch` and `crypto`).
32
+
33
+ ## Quick Start
34
+
35
+ ```typescript
36
+ import {
37
+ generateLoginUrl,
38
+ registerDevice,
39
+ fetchLibrary,
40
+ } from 'audible-api-ts'
41
+
42
+ // 1. Generate login URL
43
+ const { loginUrl, session, cookies } = await generateLoginUrl('com')
44
+ // → Redirect user to loginUrl (set cookies first)
45
+
46
+ // 2. After login, register the device
47
+ const credentials = await registerDevice(authorizationCode, session)
48
+
49
+ // 3. Fetch the library
50
+ const { items } = await fetchLibrary(credentials)
51
+
52
+ items.map((book) => console.log(`${book.title} by ${book.authors.join(', ')}`))
53
+ // → "Dune by Frank Herbert"
54
+ ```
55
+
56
+ ## API
57
+
58
+ | Function | Description |
59
+ |----------|-------------|
60
+ | `generateLoginUrl(locale)` | Generate PKCE login URL + session + cookies |
61
+ | `registerDevice(code, session)` | Exchange auth code for credentials |
62
+ | `refreshAccessToken(credentials)` | Refresh an expired access token |
63
+ | `fetchLibrary(credentials)` | Fetch all library audiobooks |
64
+ | `fetchWishlist(credentials)` | Fetch all wishlist audiobooks |
65
+ | `verifyConnection(credentials)` | Check if credentials are valid |
66
+
67
+ See the **[full documentation](https://moifort.github.io/audible-api-ts)** for guides and API reference.
68
+
69
+ ## License
70
+
71
+ MIT
@@ -0,0 +1,43 @@
1
+ import type { AudibleCookie, AudibleCredentials, AudibleLocale, AuthSession } from './types.js';
2
+ /**
3
+ * Generate a login URL for the Audible PKCE OAuth flow.
4
+ *
5
+ * Returns the URL to redirect the user to, the session to pass back to `registerDevice`,
6
+ * and the cookies to set in the browser before redirecting.
7
+ */
8
+ export declare const generateLoginUrl: (locale: AudibleLocale) => Promise<{
9
+ readonly loginUrl: string;
10
+ readonly session: AuthSession;
11
+ readonly cookies: AudibleCookie[];
12
+ }>;
13
+ /**
14
+ * Complete device registration using the authorization code from the OAuth callback.
15
+ *
16
+ * @param authorizationCode - The code received from the OAuth callback URL
17
+ * @param session - The auth session returned by `generateLoginUrl`
18
+ * @returns The credentials to use for all subsequent API calls
19
+ */
20
+ export declare const registerDevice: (authorizationCode: string, session: AuthSession) => Promise<{
21
+ accessToken: string;
22
+ refreshToken: string;
23
+ adpToken: string;
24
+ devicePrivateKey: string;
25
+ serial: string;
26
+ locale: AudibleLocale;
27
+ expiresAt: Date;
28
+ }>;
29
+ /**
30
+ * Refresh an expired access token using the refresh token.
31
+ *
32
+ * @returns Updated credentials with the new access token and expiration
33
+ */
34
+ export declare const refreshAccessToken: (credentials: AudibleCredentials) => Promise<{
35
+ accessToken: string;
36
+ expiresAt: Date;
37
+ refreshToken: string;
38
+ adpToken: string;
39
+ devicePrivateKey: string;
40
+ serial: string;
41
+ locale: AudibleLocale;
42
+ }>;
43
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAO/F;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAU,QAAQ,aAAa;;;;EAkE3D,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,GAAU,mBAAmB,MAAM,EAAE,SAAS,WAAW;;;;;;;;EA8DnF,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAU,aAAa,kBAAkB;;;;;;;;EA0BvE,CAAA"}
@@ -0,0 +1,5 @@
1
+ export { generateLoginUrl, refreshAccessToken, registerDevice } from './client.js';
2
+ export { fetchLibrary, fetchWishlist, verifyConnection } from './library.js';
3
+ export { AUDIBLE_LOCALES } from './locales.js';
4
+ export type { AudibleCookie, AudibleCredentials, AudibleItem, AudibleLocale, AuthSession, LocaleConfig, } from './types.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAGlF,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAG5E,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAG9C,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,WAAW,EACX,aAAa,EACb,WAAW,EACX,YAAY,GACb,MAAM,YAAY,CAAA"}