cloudflare
Version:
The official TypeScript library for the Cloudflare API
253 lines • 10.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Applications = exports.BaseApplications = void 0;
const tslib_1 = require("../../../../internal/tslib.js");
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
const resource_1 = require("../../../../core/resource.js");
const CAsAPI = tslib_1.__importStar(require("./cas.js"));
const cas_1 = require("./cas.js");
const ApplicationsPoliciesAPI = tslib_1.__importStar(require("./policies.js"));
const policies_1 = require("./policies.js");
const SettingsAPI = tslib_1.__importStar(require("./settings.js"));
const settings_1 = require("./settings.js");
const UserPolicyChecksAPI = tslib_1.__importStar(require("./user-policy-checks.js"));
const user_policy_checks_1 = require("./user-policy-checks.js");
const PolicyTestsAPI = tslib_1.__importStar(require("./policy-tests/policy-tests.js"));
const policy_tests_1 = require("./policy-tests/policy-tests.js");
const error_1 = require("../../../../core/error.js");
const pagination_1 = require("../../../../core/pagination.js");
const path_1 = require("../../../../internal/utils/path.js");
var BaseApplications = /* @__PURE__ */ (() => {
class BaseApplications extends resource_1.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 error_1.CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new error_1.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((0, path_1.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 error_1.CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new error_1.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((0, path_1.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 error_1.CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new error_1.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((0, path_1.path) `/${accountOrZone}/${accountOrZoneId}/access/apps`, (pagination_1.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 error_1.CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new error_1.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((0, path_1.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 error_1.CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new error_1.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((0, path_1.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 error_1.CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new error_1.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((0, path_1.path) `/${accountOrZone}/${accountOrZoneId}/access/apps/${appID}/revoke_tokens`, options)._thenUnwrap((obj) => obj.result);
}
}
BaseApplications._key = Object.freeze([
'zeroTrust',
'access',
'applications',
]);
return BaseApplications;
})();
exports.BaseApplications = BaseApplications;
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_1.CAs;
Applications.BaseCAs = cas_1.BaseCAs;
Applications.UserPolicyChecks = user_policy_checks_1.UserPolicyChecks;
Applications.BaseUserPolicyChecks = user_policy_checks_1.BaseUserPolicyChecks;
Applications.Policies = policies_1.Policies;
Applications.BasePolicies = policies_1.BasePolicies;
Applications.PolicyTests = policy_tests_1.PolicyTests;
Applications.BasePolicyTests = policy_tests_1.BasePolicyTests;
Applications.Settings = settings_1.Settings;
Applications.BaseSettings = settings_1.BaseSettings;
return Applications;
})();
exports.Applications = Applications;
//# sourceMappingURL=applications.js.map