react-native-fetch-client 0.1.0 โ†’ 0.1.2

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 (2) hide show
  1. package/README.md +107 -8
  2. package/package.json +6 -5
package/README.md CHANGED
@@ -14,14 +14,14 @@
14
14
 
15
15
  For in-depth explanations, execution pipeline flows, and implementation guides, explore the dedicated documentation suite:
16
16
 
17
- * ๐Ÿ›๏ธ **[Architecture & Execution Pipeline Flow](./docs/architecture-flow.md)** โ€” Step-by-step trace through the 16-stage request pipeline.
18
- * ๐Ÿ› ๏ธ **[Core Features & Usage Guide](./docs/core-features-guide.md)** โ€” Client setup, HTTP methods, path params, form encoding, safe requests, and unwrap.
19
- * โšก **[Caching & Stale-While-Revalidate](./docs/caching-and-swr.md)** โ€” In-memory LRU, persistent storage adapters (MMKV/AsyncStorage), ETag/304, and SWR.
20
- * ๐Ÿ›ก๏ธ **[Resilience, Retries & Offline Queue](./docs/resilience-and-offline.md)** โ€” Exponential backoff, jitter, circuit breakers, concurrency throttling, and offline replay.
21
- * ๐Ÿค– **[Streaming, AI & File Uploads](./docs/streaming-and-uploads.md)** โ€” SSE & AI LLM token streams, WHATWG streams, file uploads, and upload/download progress.
22
- * ๐Ÿ”‘ **[Authentication & Security](./docs/auth-and-security.md)** โ€” Bearer presets, single-flight 401 refresh mutex, token rotation, and header redaction.
23
- * ๐Ÿ”„ **[Auto-Pagination Helper](./docs/auto-pagination.md)** โ€” Traversal strategies (`page`, `offset`, `cursor`, `linkHeader`) and async generator streaming.
24
- * ๐Ÿงช **[Testing & Mock Adapter Guide](./docs/testing-and-mocking.md)** โ€” Declarative unit testing (`createMockAdapter`), route stubbing, and call assertions.
17
+ * ๐Ÿ›๏ธ **[Architecture & Execution Pipeline Flow](https://github.com/arunkumarArjun/react-native-fetch-client/blob/main/docs/architecture-flow.md)** โ€” Step-by-step trace through the 16-stage request pipeline.
18
+ * ๐Ÿ› ๏ธ **[Core Features & Usage Guide](https://github.com/arunkumarArjun/react-native-fetch-client/blob/main/docs/core-features-guide.md)** โ€” Client setup, HTTP methods, path params, form encoding, safe requests, and unwrap.
19
+ * โšก **[Caching & Stale-While-Revalidate](https://github.com/arunkumarArjun/react-native-fetch-client/blob/main/docs/caching-and-swr.md)** โ€” In-memory LRU, persistent storage adapters (MMKV/AsyncStorage), ETag/304, and SWR.
20
+ * ๐Ÿ›ก๏ธ **[Resilience, Retries & Offline Queue](https://github.com/arunkumarArjun/react-native-fetch-client/blob/main/docs/resilience-and-offline.md)** โ€” Exponential backoff, jitter, circuit breakers, concurrency throttling, and offline replay.
21
+ * ๐Ÿค– **[Streaming, AI & File Uploads](https://github.com/arunkumarArjun/react-native-fetch-client/blob/main/docs/streaming-and-uploads.md)** โ€” SSE & AI LLM token streams, WHATWG streams, file uploads, and upload/download progress.
22
+ * ๐Ÿ”‘ **[Authentication & Security](https://github.com/arunkumarArjun/react-native-fetch-client/blob/main/docs/auth-and-security.md)** โ€” Bearer presets, single-flight 401 refresh mutex, token rotation, and header redaction.
23
+ * ๐Ÿ”„ **[Auto-Pagination Helper](https://github.com/arunkumarArjun/react-native-fetch-client/blob/main/docs/auto-pagination.md)** โ€” Traversal strategies (`page`, `offset`, `cursor`, `linkHeader`) and async generator streaming.
24
+ * ๐Ÿงช **[Testing & Mock Adapter Guide](https://github.com/arunkumarArjun/react-native-fetch-client/blob/main/docs/testing-and-mocking.md)** โ€” Declarative unit testing (`createMockAdapter`), route stubbing, and call assertions.
25
25
 
26
26
  ---
27
27
 
@@ -463,6 +463,105 @@ const api = createClient({
463
463
 
464
464
  ---
465
465
 
466
+ ## Auto-Pagination Helper (`api.paginate`)
467
+
468
+ Traverse multi-page APIs seamlessly using async generators (`for await`) or collect all pages directly:
469
+
470
+ ```typescript
471
+ // 1. Stream items individually with for-await (Memory efficient!)
472
+ for await (const user of api.paginate<User>('/users', {
473
+ pagination: { type: 'page', pageParam: 'page', pageSize: 20 },
474
+ })) {
475
+ console.log(user.name);
476
+ }
477
+
478
+ // 2. Fetch all pages and flatten into an array in one call:
479
+ const allPosts = await api.paginate.all<Post>('/posts', {
480
+ pagination: { type: 'page', pageParam: '_page', limitParam: '_limit', limit: 10 },
481
+ });
482
+ console.log(`Fetched ${allPosts.length} posts across all pages!`);
483
+ ```
484
+
485
+ Supports 4 pagination strategies: `page`, `offset`, `cursor`, and RFC 5988/8288 standard `Link` headers.
486
+
487
+ ---
488
+
489
+ ## Persistent Storage Response Cache (`storage`)
490
+
491
+ Cache responses directly to mobile disk (MMKV, AsyncStorage, or localStorage) so data survives app restarts:
492
+
493
+ ```typescript
494
+ import { MMKV } from 'react-native-mmkv';
495
+
496
+ const mmkv = new MMKV({ id: 'http-cache' });
497
+
498
+ const api = createClient({
499
+ baseURL: 'https://api.example.com',
500
+ cache: {
501
+ enabled: true,
502
+ storage: {
503
+ getItem: (key) => mmkv.getString(key) ?? null,
504
+ setItem: (key, value) => mmkv.set(key, value),
505
+ removeItem: (key) => mmkv.delete(key),
506
+ },
507
+ defaultTtl: 300_000, // 5 minutes
508
+ },
509
+ });
510
+
511
+ // Automatically hydrates from MMKV on startup!
512
+ // Immediate cache hit on cold app boots (0ms latency):
513
+ const res = await api.get('/user/profile');
514
+ ```
515
+
516
+ ---
517
+
518
+ ## Stale-While-Revalidate (`strategy: 'stale-while-revalidate'`)
519
+
520
+ Return cached data instantly (**0ms latency**, `cached: true, stale: true`) to keep the UI buttery smooth, while quietly fetching the latest data from the network in the background:
521
+
522
+ ```typescript
523
+ const res = await api.get('/dashboard/stats', {
524
+ cache: {
525
+ strategy: 'stale-while-revalidate',
526
+ onRevalidated: (freshResponse) => {
527
+ console.log('Background sync complete! Updated data:', freshResponse.data);
528
+ updateUI(freshResponse.data);
529
+ },
530
+ },
531
+ });
532
+
533
+ console.log(res.stale); // true (Served immediately without network lag!)
534
+ ```
535
+
536
+ ---
537
+
538
+ ## Declarative Testing Mock Adapter (`createMockAdapter`)
539
+
540
+ Zero-dependency unit testing for your network calls. Stub routes, simulate network timeouts or offline errors, and assert call history:
541
+
542
+ ```typescript
543
+ import { createClient, createMockAdapter } from 'react-native-fetch-client';
544
+
545
+ const api = createClient({ baseURL: 'https://api.example.com' });
546
+ const mock = createMockAdapter(api);
547
+
548
+ // 1. Mock a route
549
+ mock.onGet('/users/active').reply(200, [{ id: 1, name: 'Alice' }]);
550
+
551
+ // 2. Simulate errors
552
+ mock.onPost('/billing/charge').replyWithTimeout();
553
+
554
+ // 3. Test & assert history
555
+ const res = await api.get('/users/active');
556
+ expect(res.data).toEqual([{ id: 1, name: 'Alice' }]);
557
+ expect(mock.history.get).toHaveLength(1);
558
+
559
+ // Clean up
560
+ mock.restore();
561
+ ```
562
+
563
+ ---
564
+
466
565
  ## Path Parameter Interpolation (`pathParams`)
467
566
 
468
567
  Interpolate Express-style (`:param`) and OpenAPI-style (`{param}`) route variables with automated URI encoding:
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "react-native-fetch-client",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "A lightweight, Fetch-native HTTP client for TypeScript, React Native, Expo, browsers, and Node.js",
5
- "author": "",
5
+ "author": "Arunkumar Arjunan",
6
6
  "license": "MIT",
7
+ "sideEffects": false,
7
8
  "keywords": [
8
9
  "fetch",
9
10
  "http",
@@ -16,11 +17,11 @@
16
17
  ],
17
18
  "repository": {
18
19
  "type": "git",
19
- "url": "https://github.com/OWNER/react-native-fetch-client.git"
20
+ "url": "git+https://github.com/arunkumarArjun/react-native-fetch-client.git"
20
21
  },
21
- "homepage": "https://github.com/OWNER/react-native-fetch-client#readme",
22
+ "homepage": "https://github.com/arunkumarArjun/react-native-fetch-client#readme",
22
23
  "bugs": {
23
- "url": "https://github.com/OWNER/react-native-fetch-client/issues"
24
+ "url": "https://github.com/arunkumarArjun/react-native-fetch-client/issues"
24
25
  },
25
26
 
26
27
  "engines": {