"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;const query_1=require("@b/utils/query"),utils_1=require("./utils"),utils_2=require("@b/api/user/api-key/utils");exports.metadata={summary:"Stores a new API Key",operationId:"storeApiKey",tags:["Admin","API Keys"],logModule:"ADMIN_API",logTitle:"Create API",requestBody:{required:!0,content:{"application/json":{schema:utils_1.apiKeyUpdateSchema}}},responses:(0,query_1.storeRecordResponses)(utils_1.apiKeyStoreSchema,"API Key"),requiresAuth:!0,permission:"create.api.key"};exports.default=async e=>{const{body:t,ctx:s}=e,{userId:r,name:i,type:a,permissions:o,ipRestriction:u,ipWhitelist:n}=t;null==s||s.step("Validating API key data");const p=Array.isArray(o)?o:[],y=Array.isArray(n)?n:[];null==s||s.step("Generating API key");null==s||s.step("Creating API key record");const l=await(0,query_1.storeRecord)({model:"apiKey",data:{userId:r,name:i,key:(0,utils_2.generateApiKey)(),type:a,permissions:p,ipRestriction:u,ipWhitelist:y}});null==s||s.success();return l};