create-request 1.2.0 → 1.2.1

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 +42 -1
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -128,6 +128,7 @@ import create, {
128
128
  RedirectMode,
129
129
  ReferrerPolicy,
130
130
  SameSitePolicy,
131
+ CacheMode,
131
132
  } from "create-request";
132
133
 
133
134
  // Configure request options
@@ -177,7 +178,9 @@ const request = create
177
178
  .withReferrer("https://example.com") // Sets request referrer
178
179
  .withReferrerPolicy.NO_REFERRER_WHEN_DOWNGRADE() // Controls referrer policy
179
180
  .withPriority.HIGH() // Sets request priority
180
- .withKeepAlive(true); // Keeps connection alive after the page is unloaded
181
+ .withKeepAlive(true) // Keeps connection alive after the page is unloaded
182
+ .withIntegrity("sha256-abcdef1234567890...") // Sets subresource integrity hash
183
+ .withCache("no-cache"); // Controls cache behavior (or use .withCache.NO_CACHE())
181
184
  ```
182
185
 
183
186
  Each configuration method returns the request object, allowing for a fluent interface where methods can be chained together. You can configure only what you need for a specific request:
@@ -308,6 +311,44 @@ const merged = create
308
311
  .withQueryParams({ new: "param" }); // Both existing and new params included
309
312
  ```
310
313
 
314
+ ### Subresource Integrity and Cache Control
315
+
316
+ The library supports subresource integrity verification and cache control options:
317
+
318
+ ```typescript
319
+ // Subresource Integrity - ensures the fetched resource hasn't been tampered with
320
+ const secureRequest = create
321
+ .get("https://cdn.example.com/script.js")
322
+ .withIntegrity("sha256-abcdef1234567890..."); // Browser will verify the hash
323
+
324
+ // Cache Control - supports all cache modes via fluent API or string values
325
+ const cachedRequest = create.get("https://api.example.com/data").withCache("no-cache"); // Direct string value
326
+
327
+ // Using fluent API for cache modes
328
+ const fluentCache = create.get("https://api.example.com/data").withCache.NO_CACHE(); // Fluent API method
329
+
330
+ // All available cache modes:
331
+ create
332
+ .get("https://api.example.com/data")
333
+ .withCache.DEFAULT() // Default cache behavior
334
+ .withCache.NO_STORE() // Don't store in cache
335
+ .withCache.RELOAD() // Reload from server
336
+ .withCache.NO_CACHE() // Validate with server before using cache
337
+ .withCache.FORCE_CACHE() // Use cache even if stale
338
+ .withCache.ONLY_IF_CACHED(); // Only use cache, don't fetch from server
339
+
340
+ // Using enum values (import from create-request)
341
+ import { CacheMode } from "create-request";
342
+
343
+ const enumCache = create.get("https://api.example.com/data").withCache(CacheMode.NO_CACHE);
344
+
345
+ // Combining integrity and cache
346
+ const secureCached = create
347
+ .get("https://cdn.example.com/resource.js")
348
+ .withIntegrity("sha256-abcdef1234567890...")
349
+ .withCache("no-store"); // Ensure no caching for sensitive resources
350
+ ```
351
+
311
352
  ### Executing Requests
312
353
 
313
354
  ```typescript
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-request",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "A modern, chainable wrapper for fetch with automatic retries, timeouts, comprehensive error handling, and first-class TypeScript support",
5
5
  "main": "dist/library/index.cjs",
6
6
  "module": "dist/library/index.esm.js",