cloudflare
Version:
The official TypeScript library for the Cloudflare API
141 lines • 5.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ResourceSharing = exports.BaseResourceSharing = 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 RecipientsAPI = tslib_1.__importStar(require("./recipients.js"));
const recipients_1 = require("./recipients.js");
const ResourcesAPI = tslib_1.__importStar(require("./resources.js"));
const resources_1 = require("./resources.js");
const pagination_1 = require("../../core/pagination.js");
const path_1 = require("../../internal/utils/path.js");
var BaseResourceSharing = /* @__PURE__ */ (() => {
class BaseResourceSharing extends resource_1.APIResource {
/**
* Creates a new resource share for sharing Cloudflare resources with other
* accounts or organizations.
*
* @example
* ```ts
* const resourceSharing = await client.resourceSharing.create(
* {
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* name: 'My Shared WAF Managed Rule',
* recipients: [{}],
* resources: [
* {
* meta: {},
* resource_account_id:
* '023e105f4ecef8ad9ca31a8372d0c353',
* resource_id: '023e105f4ecef8ad9ca31a8372d0c353',
* resource_type: 'custom-ruleset',
* },
* ],
* },
* );
* ```
*/
create(params, options) {
const { account_id, ...body } = params;
return this._client.post((0, path_1.path) `/accounts/${account_id}/shares`, { body, ...options })._thenUnwrap((obj) => obj.result);
}
/**
* Updates the share's display name and tags. This endpoint does **not** modify
* recipients or resources — those are managed via dedicated subresource endpoints:
*
* - **Recipients**: Use `POST /accounts/{account_id}/shares/{share_id}/recipients`
* to add a single recipient,
* `PUT /accounts/{account_id}/shares/{share_id}/recipients` to replace the full
* recipient list, or
* `DELETE /accounts/{account_id}/shares/{share_id}/recipients/{recipient_id}` to
* remove a recipient.
* - **Resources**: Use the share's resource subresource endpoints.
*
* Updating is not immediate; an updated share object with a new status will be
* returned.
*
* @example
* ```ts
* const resourceSharing = await client.resourceSharing.update(
* '3fd85f74b32742f1bff64a85009dda07',
* {
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* name: 'My Shared WAF Managed Rule',
* },
* );
* ```
*/
update(shareID, params, options) {
const { account_id, ...body } = params;
return this._client.put((0, path_1.path) `/accounts/${account_id}/shares/${shareID}`, { body, ...options })._thenUnwrap((obj) => obj.result);
}
/**
* Lists all account shares.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const resourceSharingListResponse of client.resourceSharing.list(
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* )) {
* // ...
* }
* ```
*/
list(params, options) {
const { account_id, ...query } = params;
return this._client.getAPIList((0, path_1.path) `/accounts/${account_id}/shares`, (pagination_1.V4PagePaginationArray), { query, ...options });
}
/**
* Deletion is not immediate, an updated share object with a new status will be
* returned.
*
* @example
* ```ts
* const resourceSharing = await client.resourceSharing.delete(
* '3fd85f74b32742f1bff64a85009dda07',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
delete(shareID, params, options) {
const { account_id } = params;
return this._client.delete((0, path_1.path) `/accounts/${account_id}/shares/${shareID}`, options)._thenUnwrap((obj) => obj.result);
}
/**
* Fetches share by ID.
*
* @example
* ```ts
* const resourceSharing = await client.resourceSharing.get(
* '3fd85f74b32742f1bff64a85009dda07',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
get(shareID, params, options) {
const { account_id, ...query } = params;
return this._client.get((0, path_1.path) `/accounts/${account_id}/shares/${shareID}`, { query, ...options })._thenUnwrap((obj) => obj.result);
}
}
BaseResourceSharing._key = Object.freeze(['resourceSharing']);
return BaseResourceSharing;
})();
exports.BaseResourceSharing = BaseResourceSharing;
var ResourceSharing = /* @__PURE__ */ (() => {
class ResourceSharing extends BaseResourceSharing {
constructor() {
super(...arguments);
this.recipients = new RecipientsAPI.Recipients(this._client);
this.resources = new ResourcesAPI.Resources(this._client);
}
}
ResourceSharing.Recipients = recipients_1.Recipients;
ResourceSharing.BaseRecipients = recipients_1.BaseRecipients;
ResourceSharing.Resources = resources_1.Resources;
ResourceSharing.BaseResources = resources_1.BaseResources;
return ResourceSharing;
})();
exports.ResourceSharing = ResourceSharing;
//# sourceMappingURL=resource-sharing.js.map