fix(cloudflare.plugins): Switch to smartrequest namespace export and improve request typing and JSON parsing

This commit is contained in:
2025-11-17 23:22:00 +00:00
parent 0184371635
commit 002ac3ae01
4 changed files with 15 additions and 6 deletions

View File

@@ -1,5 +1,14 @@
# Changelog # 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<typeof plugins.smartrequest.CoreResponse> 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<T>() 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) ## 2025-11-17 - 6.4.2 - fix(core)
Switch to SmartRequest fluent API and improve Cloudflare API request handling Switch to SmartRequest fluent API and improve Cloudflare API request handling

View File

@@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@apiclient.xyz/cloudflare', 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.' description: 'A TypeScript client for managing Cloudflare accounts, zones, DNS records, and workers with ease.'
} }

View File

@@ -45,7 +45,7 @@ export class CloudflareAccount implements plugins.tsclass.network.IConvenientDns
logger.log('debug', `Making ${method} request to ${endpoint}`); logger.log('debug', `Making ${method} request to ${endpoint}`);
// Build the request using fluent API // 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}`) .url(`https://api.cloudflare.com/client/v4${endpoint}`)
.header('Authorization', `Bearer ${this.authToken}`); .header('Authorization', `Bearer ${this.authToken}`);
@@ -71,7 +71,7 @@ export class CloudflareAccount implements plugins.tsclass.network.IConvenientDns
} }
// Execute the request with the appropriate method // Execute the request with the appropriate method
let response: plugins.CoreResponse; let response: InstanceType<typeof plugins.smartrequest.CoreResponse>;
switch (method) { switch (method) {
case 'GET': case 'GET':
response = await requestBuilder.get(); response = await requestBuilder.get();
@@ -101,7 +101,7 @@ export class CloudflareAccount implements plugins.tsclass.network.IConvenientDns
// Parse the response body // Parse the response body
try { try {
return await response.json<T>(); return (await response.json()) as T;
} catch (parseError) { } catch (parseError) {
logger.log('warn', `Failed to parse response as JSON: ${parseError.message}`); logger.log('warn', `Failed to parse response as JSON: ${parseError.message}`);

View File

@@ -1,11 +1,11 @@
import * as smartlog from '@push.rocks/smartlog'; import * as smartlog from '@push.rocks/smartlog';
import * as smartpromise from '@push.rocks/smartpromise'; import * as smartpromise from '@push.rocks/smartpromise';
import * as smartdelay from '@push.rocks/smartdelay'; 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 smartstring from '@push.rocks/smartstring';
import * as tsclass from '@tsclass/tsclass'; import * as tsclass from '@tsclass/tsclass';
export { smartlog, smartpromise, smartdelay, SmartRequest, CoreResponse, smartstring, tsclass }; export { smartlog, smartpromise, smartdelay, smartrequest, smartstring, tsclass };
// third party // third party
import * as cloudflare from 'cloudflare'; import * as cloudflare from 'cloudflare';