cloudflare
Version:
The official TypeScript library for the Cloudflare API
247 lines • 9.98 kB
JavaScript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../../../core/resource.mjs";
import * as CAsAPI from "./cas.mjs";
import { BaseCAs, CAs, } from "./cas.mjs";
import * as ApplicationsPoliciesAPI from "./policies.mjs";
import { BasePolicies, Policies, } from "./policies.mjs";
import * as SettingsAPI from "./settings.mjs";
import { BaseSettings, Settings, } from "./settings.mjs";
import * as UserPolicyChecksAPI from "./user-policy-checks.mjs";
import { BaseUserPolicyChecks, UserPolicyChecks, } from "./user-policy-checks.mjs";
import * as PolicyTestsAPI from "./policy-tests/policy-tests.mjs";
import { BasePolicyTests, PolicyTests, } from "./policy-tests/policy-tests.mjs";
import { CloudflareError } from "../../../../core/error.mjs";
import { V4PagePaginationArray, } from "../../../../core/pagination.mjs";
import { path } from "../../../../internal/utils/path.mjs";
export var BaseApplications = /* @__PURE__ */ (() => {
class BaseApplications extends APIResource {
/**
* Adds a new application to Access.
*
* @example
* ```ts
* const application =
* await client.zeroTrust.access.applications.create({
* domain: 'test.example.com/admin',
* type: 'self_hosted',
* account_id: 'account_id',
* });
* ```
*/
create(params, options) {
const { account_id, zone_id, ...body } = params;
if (!account_id && !zone_id) {
throw new CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new CloudflareError('You cannot provide both account_id and zone_id.');
}
const { accountOrZone, accountOrZoneId } = account_id ?
{
accountOrZone: 'accounts',
accountOrZoneId: account_id,
}
: {
accountOrZone: 'zones',
accountOrZoneId: zone_id,
};
return this._client.post(path `/${accountOrZone}/${accountOrZoneId}/access/apps`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Updates an Access application.
*
* @example
* ```ts
* const application =
* await client.zeroTrust.access.applications.update(
* '023e105f4ecef8ad9ca31a8372d0c353',
* {
* domain: 'test.example.com/admin',
* type: 'self_hosted',
* account_id: 'account_id',
* },
* );
* ```
*/
update(appID, params, options) {
const { account_id, zone_id, ...body } = params;
if (!account_id && !zone_id) {
throw new CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new CloudflareError('You cannot provide both account_id and zone_id.');
}
const { accountOrZone, accountOrZoneId } = account_id ?
{
accountOrZone: 'accounts',
accountOrZoneId: account_id,
}
: {
accountOrZone: 'zones',
accountOrZoneId: zone_id,
};
return this._client.put(path `/${accountOrZone}/${accountOrZoneId}/access/apps/${appID}`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Lists all Access applications in an account or zone.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const applicationListResponse of client.zeroTrust.access.applications.list(
* { account_id: 'account_id' },
* )) {
* // ...
* }
* ```
*/
list(params = {}, options) {
const { account_id, zone_id, ...query } = params ?? {};
if (!account_id && !zone_id) {
throw new CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new CloudflareError('You cannot provide both account_id and zone_id.');
}
const { accountOrZone, accountOrZoneId } = account_id ?
{
accountOrZone: 'accounts',
accountOrZoneId: account_id,
}
: {
accountOrZone: 'zones',
accountOrZoneId: zone_id,
};
return this._client.getAPIList(path `/${accountOrZone}/${accountOrZoneId}/access/apps`, (V4PagePaginationArray), { query, ...options });
}
/**
* Deletes an application from Access.
*
* @example
* ```ts
* const application =
* await client.zeroTrust.access.applications.delete(
* '023e105f4ecef8ad9ca31a8372d0c353',
* { account_id: 'account_id' },
* );
* ```
*/
delete(appID, params = {}, options) {
const { account_id, zone_id } = params ?? {};
if (!account_id && !zone_id) {
throw new CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new CloudflareError('You cannot provide both account_id and zone_id.');
}
const { accountOrZone, accountOrZoneId } = account_id ?
{
accountOrZone: 'accounts',
accountOrZoneId: account_id,
}
: {
accountOrZone: 'zones',
accountOrZoneId: zone_id,
};
return this._client.delete(path `/${accountOrZone}/${accountOrZoneId}/access/apps/${appID}`, options)._thenUnwrap((obj) => obj.result);
}
/**
* Fetches information about an Access application.
*
* @example
* ```ts
* const application =
* await client.zeroTrust.access.applications.get(
* '023e105f4ecef8ad9ca31a8372d0c353',
* { account_id: 'account_id' },
* );
* ```
*/
get(appID, params = {}, options) {
const { account_id, zone_id } = params ?? {};
if (!account_id && !zone_id) {
throw new CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new CloudflareError('You cannot provide both account_id and zone_id.');
}
const { accountOrZone, accountOrZoneId } = account_id ?
{
accountOrZone: 'accounts',
accountOrZoneId: account_id,
}
: {
accountOrZone: 'zones',
accountOrZoneId: zone_id,
};
return this._client.get(path `/${accountOrZone}/${accountOrZoneId}/access/apps/${appID}`, options)._thenUnwrap((obj) => obj.result);
}
/**
* Revokes all tokens issued for an application.
*
* @example
* ```ts
* const response =
* await client.zeroTrust.access.applications.revokeTokens(
* '023e105f4ecef8ad9ca31a8372d0c353',
* { account_id: 'account_id' },
* );
* ```
*/
revokeTokens(appID, params = {}, options) {
const { account_id, zone_id } = params ?? {};
if (!account_id && !zone_id) {
throw new CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new CloudflareError('You cannot provide both account_id and zone_id.');
}
const { accountOrZone, accountOrZoneId } = account_id ?
{
accountOrZone: 'accounts',
accountOrZoneId: account_id,
}
: {
accountOrZone: 'zones',
accountOrZoneId: zone_id,
};
return this._client.post(path `/${accountOrZone}/${accountOrZoneId}/access/apps/${appID}/revoke_tokens`, options)._thenUnwrap((obj) => obj.result);
}
}
BaseApplications._key = Object.freeze([
'zeroTrust',
'access',
'applications',
]);
return BaseApplications;
})();
export var Applications = /* @__PURE__ */ (() => {
class Applications extends BaseApplications {
constructor() {
super(...arguments);
this.cas = new CAsAPI.CAs(this._client);
this.userPolicyChecks = new UserPolicyChecksAPI.UserPolicyChecks(this._client);
this.policies = new ApplicationsPoliciesAPI.Policies(this._client);
this.policyTests = new PolicyTestsAPI.PolicyTests(this._client);
this.settings = new SettingsAPI.Settings(this._client);
}
}
Applications.CAs = CAs;
Applications.BaseCAs = BaseCAs;
Applications.UserPolicyChecks = UserPolicyChecks;
Applications.BaseUserPolicyChecks = BaseUserPolicyChecks;
Applications.Policies = Policies;
Applications.BasePolicies = BasePolicies;
Applications.PolicyTests = PolicyTests;
Applications.BasePolicyTests = BasePolicyTests;
Applications.Settings = Settings;
Applications.BaseSettings = BaseSettings;
return Applications;
})();
//# sourceMappingURL=applications.mjs.map