import * as Utils from '@datocms/rest-client-utils'; import BaseResource from '../../BaseResource.js'; import type * as ApiTypes from '../ApiTypes.js'; import type * as RawApiTypes from '../RawApiTypes.js'; export default class SiteSubscription extends BaseResource { static readonly TYPE = 'site_subscription' as const; /** * Create a new subscription * * @throws {ApiError} * @throws {TimeoutError} */ rawCreate( siteId: string, body: RawApiTypes.SiteSubscriptionCreateSchema, ): Promise { return this.client.request({ method: 'POST', url: `/sites/${siteId}/subscriptions`, body, }); } /** * Simulate * * @throws {ApiError} * @throws {TimeoutError} */ rawSimulate( siteId: string, body: RawApiTypes.SiteSubscriptionSimulateSchema, ): Promise { return this.client.request( { method: 'POST', url: `/sites/${siteId}/subscriptions/simulate`, body, }, ); } /** * Validate a new subscription * * @throws {ApiError} * @throws {TimeoutError} */ validate( siteId: string | ApiTypes.SiteData, body: ApiTypes.SiteSubscriptionValidateSchema, ) { return this.rawValidate( Utils.toId(siteId), Utils.serializeRequestBody( body, { type: 'site_subscription_validation', attributes: ['extra_packets', 'ignore_content', 'is_duplicate'], relationships: ['plan'], }, ), ).then((body) => Utils.deserializeResponseBody( body, ), ); } /** * Validate a new subscription * * @throws {ApiError} * @throws {TimeoutError} */ rawValidate( siteId: string, body: RawApiTypes.SiteSubscriptionValidateSchema, ): Promise { return this.client.request( { method: 'POST', url: `/sites/${siteId}/subscriptions/validate`, body, }, ); } }