"use strict"; // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. Object.defineProperty(exports, "__esModule", { value: true }); exports.Locations = exports.Permission = void 0; exports.isAppBinding = isAppBinding; const products_1 = require("./products"); const utilities_1 = require("./utilities"); var Permission; (function (Permission) { Permission["UserJoinedChannelNotification"] = "user_joined_channel_notification"; Permission["ActAsBot"] = "act_as_bot"; Permission["ActAsUser"] = "act_as_user"; Permission["PermissionActAsAdmin"] = "act_as_admin"; Permission["RemoteOAuth2"] = "remote_oauth2"; Permission["RemoteWebhooks"] = "remote_webhooks"; })(Permission || (exports.Permission = Permission = {})); var Locations; (function (Locations) { Locations["PostMenu"] = "/post_menu"; Locations["ChannelHeader"] = "/channel_header"; Locations["Command"] = "/command"; Locations["InPost"] = "/in_post"; })(Locations || (exports.Locations = Locations = {})); function isAppBinding(obj) { if (typeof obj !== 'object' || obj === null) { return false; } const binding = obj; if (typeof binding.app_id !== 'string' || typeof binding.label !== 'string') { return false; } if (binding.location !== undefined && typeof binding.location !== 'string') { return false; } if (binding.supported_product_ids !== undefined && !(0, products_1.isProductScope)(binding.supported_product_ids)) { return false; } if (binding.icon !== undefined && typeof binding.icon !== 'string') { return false; } if (binding.hint !== undefined && typeof binding.hint !== 'string') { return false; } if (binding.description !== undefined && typeof binding.description !== 'string') { return false; } if (binding.role_id !== undefined && typeof binding.role_id !== 'string') { return false; } if (binding.depends_on_team !== undefined && typeof binding.depends_on_team !== 'boolean') { return false; } if (binding.depends_on_channel !== undefined && typeof binding.depends_on_channel !== 'boolean') { return false; } if (binding.depends_on_user !== undefined && typeof binding.depends_on_user !== 'boolean') { return false; } if (binding.depends_on_post !== undefined && typeof binding.depends_on_post !== 'boolean') { return false; } if (binding.bindings !== undefined && !(0, utilities_1.isArrayOf)(binding.bindings, isAppBinding)) { return false; } if (binding.form !== undefined && !isAppForm(binding.form)) { return false; } if (binding.submit !== undefined && !isAppCall(binding.submit)) { return false; } return true; } function isAppCall(obj) { if (typeof obj !== 'object' || obj === null) { return false; } const call = obj; if (typeof call.path !== 'string') { return false; } if (call.expand !== undefined && !isAppExpand(call.expand)) { return false; } // Here we're assuming that 'state' can be of any type, so no type check for 'state' return true; } function isAppExpand(v) { if (typeof v !== 'object' || v === null) { return false; } const expand = v; if (expand.app !== undefined && typeof expand.app !== 'string') { return false; } if (expand.acting_user !== undefined && typeof expand.acting_user !== 'string') { return false; } if (expand.acting_user_access_token !== undefined && typeof expand.acting_user_access_token !== 'string') { return false; } if (expand.channel !== undefined && typeof expand.channel !== 'string') { return false; } if (expand.config !== undefined && typeof expand.config !== 'string') { return false; } if (expand.mentioned !== undefined && typeof expand.mentioned !== 'string') { return false; } if (expand.parent_post !== undefined && typeof expand.parent_post !== 'string') { return false; } if (expand.post !== undefined && typeof expand.post !== 'string') { return false; } if (expand.root_post !== undefined && typeof expand.root_post !== 'string') { return false; } if (expand.team !== undefined && typeof expand.team !== 'string') { return false; } if (expand.user !== undefined && typeof expand.user !== 'string') { return false; } if (expand.locale !== undefined && typeof expand.locale !== 'string') { return false; } return true; } function isAppForm(v) { if (typeof v !== 'object' || v === null) { return false; } const form = v; if (form.title !== undefined && typeof form.title !== 'string') { return false; } if (form.header !== undefined && typeof form.header !== 'string') { return false; } if (form.footer !== undefined && typeof form.footer !== 'string') { return false; } if (form.icon !== undefined && typeof form.icon !== 'string') { return false; } if (form.submit_buttons !== undefined && typeof form.submit_buttons !== 'string') { return false; } if (form.cancel_button !== undefined && typeof form.cancel_button !== 'boolean') { return false; } if (form.submit_on_cancel !== undefined && typeof form.submit_on_cancel !== 'boolean') { return false; } if (form.fields !== undefined && !(0, utilities_1.isArrayOf)(form.fields, isAppField)) { return false; } if (form.source !== undefined && !isAppCall(form.source)) { return false; } if (form.submit !== undefined && !isAppCall(form.submit)) { return false; } if (form.depends_on !== undefined && !(0, utilities_1.isStringArray)(form.depends_on)) { return false; } return true; } function isAppFormValue(v) { if (typeof v === 'string') { return true; } if (typeof v === 'boolean') { return true; } if (v === null) { return true; } return isAppSelectOption(v); } function isAppSelectOption(v) { if (typeof v !== 'object' || v === null) { return false; } const option = v; if (typeof option.label !== 'string' || typeof option.value !== 'string') { return false; } if (option.icon_data !== undefined && typeof option.icon_data !== 'string') { return false; } return true; } function isAppField(v) { if (typeof v !== 'object' || v === null) { return false; } const field = v; if (typeof field.name !== 'string' || typeof field.type !== 'string') { return false; } if (field.is_required !== undefined && typeof field.is_required !== 'boolean') { return false; } if (field.readonly !== undefined && typeof field.readonly !== 'boolean') { return false; } if (field.value !== undefined && !isAppFormValue(field.value)) { return false; } if (field.description !== undefined && typeof field.description !== 'string') { return false; } if (field.label !== undefined && typeof field.label !== 'string') { return false; } if (field.hint !== undefined && typeof field.hint !== 'string') { return false; } if (field.position !== undefined && typeof field.position !== 'number') { return false; } if (field.modal_label !== undefined && typeof field.modal_label !== 'string') { return false; } if (field.refresh !== undefined && typeof field.refresh !== 'boolean') { return false; } if (field.options !== undefined && !(0, utilities_1.isArrayOf)(field.options, isAppSelectOption)) { return false; } if (field.multiselect !== undefined && typeof field.multiselect !== 'boolean') { return false; } if (field.lookup !== undefined && !isAppCall(field.lookup)) { return false; } if (field.subtype !== undefined && typeof field.subtype !== 'string') { return false; } if (field.min_length !== undefined && typeof field.min_length !== 'number') { return false; } if (field.max_length !== undefined && typeof field.max_length !== 'number') { return false; } return true; }