From 002ac3ae0193d2df8e36ca62f5fb1ca0746cdcbf Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Mon, 17 Nov 2025 23:22:00 +0000 Subject: [PATCH] fix(cloudflare.plugins): Switch to smartrequest namespace export and improve request typing and JSON parsing --- changelog.md | 9 +++++++++ ts/00_commitinfo_data.ts | 2 +- ts/cloudflare.classes.account.ts | 6 +++--- ts/cloudflare.plugins.ts | 4 ++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/changelog.md b/changelog.md index ac660d1..86cf29c 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,14 @@ # Changelog +## 2025-11-17 - 6.4.3 - fix(cloudflare.plugins) +Switch to smartrequest namespace export and improve request typing and JSON parsing + +- Export smartrequest as a namespace from cloudflare.plugins (replaced named SmartRequest/CoreResponse exports) +- Use plugins.smartrequest.SmartRequest.create() when building HTTP requests +- Type response as InstanceType to match the new smartrequest export shape +- Safer JSON parsing: cast result of response.json() to the expected generic instead of relying on a generic json() call and provide a text fallback when parsing fails +- Adjust imports/usages to align with @push.rocks/smartrequest namespace usage + ## 2025-11-17 - 6.4.2 - fix(core) Switch to SmartRequest fluent API and improve Cloudflare API request handling diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 67caa0b..c2fbb47 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@apiclient.xyz/cloudflare', - version: '6.4.2', + version: '6.4.3', description: 'A TypeScript client for managing Cloudflare accounts, zones, DNS records, and workers with ease.' } diff --git a/ts/cloudflare.classes.account.ts b/ts/cloudflare.classes.account.ts index ac156bf..875d3a4 100644 --- a/ts/cloudflare.classes.account.ts +++ b/ts/cloudflare.classes.account.ts @@ -45,7 +45,7 @@ export class CloudflareAccount implements plugins.tsclass.network.IConvenientDns logger.log('debug', `Making ${method} request to ${endpoint}`); // Build the request using fluent API - let requestBuilder = plugins.SmartRequest.create() + let requestBuilder = plugins.smartrequest.SmartRequest.create() .url(`https://api.cloudflare.com/client/v4${endpoint}`) .header('Authorization', `Bearer ${this.authToken}`); @@ -71,7 +71,7 @@ export class CloudflareAccount implements plugins.tsclass.network.IConvenientDns } // Execute the request with the appropriate method - let response: plugins.CoreResponse; + let response: InstanceType; switch (method) { case 'GET': response = await requestBuilder.get(); @@ -101,7 +101,7 @@ export class CloudflareAccount implements plugins.tsclass.network.IConvenientDns // Parse the response body try { - return await response.json(); + return (await response.json()) as T; } catch (parseError) { logger.log('warn', `Failed to parse response as JSON: ${parseError.message}`); diff --git a/ts/cloudflare.plugins.ts b/ts/cloudflare.plugins.ts index 10a7ee7..acbac90 100644 --- a/ts/cloudflare.plugins.ts +++ b/ts/cloudflare.plugins.ts @@ -1,11 +1,11 @@ import * as smartlog from '@push.rocks/smartlog'; import * as smartpromise from '@push.rocks/smartpromise'; import * as smartdelay from '@push.rocks/smartdelay'; -import { SmartRequest, CoreResponse } from '@push.rocks/smartrequest'; +import * as smartrequest from '@push.rocks/smartrequest'; import * as smartstring from '@push.rocks/smartstring'; import * as tsclass from '@tsclass/tsclass'; -export { smartlog, smartpromise, smartdelay, SmartRequest, CoreResponse, smartstring, tsclass }; +export { smartlog, smartpromise, smartdelay, smartrequest, smartstring, tsclass }; // third party import * as cloudflare from 'cloudflare';