cloudflare
Version:
The official TypeScript library for the Cloudflare API
135 lines • 5.52 kB
JavaScript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../core/resource.mjs";
import * as RecipientsAPI from "./recipients.mjs";
import { BaseRecipients, Recipients, } from "./recipients.mjs";
import * as ResourcesAPI from "./resources.mjs";
import { BaseResources, Resources, } from "./resources.mjs";
import { V4PagePaginationArray } from "../../core/pagination.mjs";
import { path } from "../../internal/utils/path.mjs";
export var BaseResourceSharing = /* @__PURE__ */ (() => {
class BaseResourceSharing extends 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(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(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(path `/accounts/${account_id}/shares`, (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(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(path `/accounts/${account_id}/shares/${shareID}`, { query, ...options })._thenUnwrap((obj) => obj.result);
}
}
BaseResourceSharing._key = Object.freeze(['resourceSharing']);
return BaseResourceSharing;
})();
export 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;
ResourceSharing.BaseRecipients = BaseRecipients;
ResourceSharing.Resources = Resources;
ResourceSharing.BaseResources = BaseResources;
return ResourceSharing;
})();
//# sourceMappingURL=resource-sharing.mjs.map