cloudflare
Version:
The official TypeScript library for the Cloudflare API
92 lines • 3.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Tests = exports.BaseTests = void 0;
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
const resource_1 = require("../../../core/resource.js");
const pagination_1 = require("../../../core/pagination.js");
const path_1 = require("../../../internal/utils/path.js");
var BaseTests = /* @__PURE__ */ (() => {
class BaseTests extends resource_1.APIResource {
/**
* Starts a test for a specific webpage, in a specific region.
*
* @example
* ```ts
* const test = await client.speed.pages.tests.create(
* 'example.com',
* { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
create(url, params, options) {
const { zone_id, ...body } = params;
return this._client.post((0, path_1.path) `/zones/${zone_id}/speed_api/pages/${url}/tests`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Test history (list of tests) for a specific webpage.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const test of client.speed.pages.tests.list(
* 'example.com',
* { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* )) {
* // ...
* }
* ```
*/
list(url, params, options) {
const { zone_id, ...query } = params;
return this._client.getAPIList((0, path_1.path) `/zones/${zone_id}/speed_api/pages/${url}/tests`, (pagination_1.V4PagePaginationArray), { query, ...options });
}
/**
* Deletes all tests for a specific webpage from a specific region. Deleted tests
* are still counted as part of the quota.
*
* @example
* ```ts
* const test = await client.speed.pages.tests.delete(
* 'example.com',
* { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
delete(url, params, options) {
const { zone_id, region } = params;
return this._client.delete((0, path_1.path) `/zones/${zone_id}/speed_api/pages/${url}/tests`, {
query: { region },
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Retrieves the result of a specific test.
*
* @example
* ```ts
* const test = await client.speed.pages.tests.get('test_id', {
* zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
* url: 'example.com',
* });
* ```
*/
get(testID, params, options) {
const { zone_id, url } = params;
return this._client.get((0, path_1.path) `/zones/${zone_id}/speed_api/pages/${url}/tests/${testID}`, options)._thenUnwrap((obj) => obj.result);
}
}
BaseTests._key = Object.freeze([
'speed',
'pages',
'tests',
]);
return BaseTests;
})();
exports.BaseTests = BaseTests;
class Tests extends BaseTests {
}
exports.Tests = Tests;
//# sourceMappingURL=tests.js.map