UNPKG

pubnub

Version:

Publish & Subscribe Real-time Messaging with PubNub

70 lines (69 loc) 2.63 kB
"use strict"; /** * Set Channel Metadata REST API module. * * @internal */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SetChannelMetadataRequest = void 0; const transport_request_1 = require("../../../types/transport-request"); const request_1 = require("../../../components/request"); const operations_1 = __importDefault(require("../../../constants/operations")); const utils_1 = require("../../../utils"); // -------------------------------------------------------- // ----------------------- Defaults ----------------------- // -------------------------------------------------------- // region Defaults /** * Whether `Channel` custom field should be included by default or not. */ const INCLUDE_CUSTOM_FIELDS = true; // endregion /** * Set Channel Metadata request. * * @internal */ class SetChannelMetadataRequest extends request_1.AbstractRequest { constructor(parameters) { var _a, _b; var _c; super({ method: transport_request_1.TransportMethod.PATCH }); this.parameters = parameters; // Apply default request parameters. (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); (_b = (_c = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_c.customFields = INCLUDE_CUSTOM_FIELDS); } operation() { return operations_1.default.PNSetChannelMetadataOperation; } validate() { if (!this.parameters.channel) return 'Channel cannot be empty'; if (!this.parameters.data) return 'Data cannot be empty'; } get headers() { var _a; let headers = (_a = super.headers) !== null && _a !== void 0 ? _a : {}; if (this.parameters.ifMatchesEtag) headers = Object.assign(Object.assign({}, headers), { 'If-Match': this.parameters.ifMatchesEtag }); return Object.assign(Object.assign({}, headers), { 'Content-Type': 'application/json' }); } get path() { const { keySet: { subscribeKey }, channel, } = this.parameters; return `/v2/objects/${subscribeKey}/channels/${(0, utils_1.encodeString)(channel)}`; } get queryParameters() { return { include: ['status', 'type', ...(this.parameters.include.customFields ? ['custom'] : [])].join(','), }; } get body() { return JSON.stringify(this.parameters.data); } } exports.SetChannelMetadataRequest = SetChannelMetadataRequest;