fix(cloudflare.plugins): Switch to smartrequest namespace export and improve request typing and JSON parsing
This commit is contained in:
@@ -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.'
|
||||
}
|
||||
|
||||
@@ -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<typeof plugins.smartrequest.CoreResponse>;
|
||||
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<T>();
|
||||
return (await response.json()) as T;
|
||||
} catch (parseError) {
|
||||
logger.log('warn', `Failed to parse response as JSON: ${parseError.message}`);
|
||||
|
||||
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user