import { freezeSys , toPlainObject } from 'contentful-sdk-core' ; import copy from 'fast-copy' ; import { DefaultElements , MakeRequest , MetaLinkProps , MetaSysProps } from '../common-types' ; import { wrapCollection } from '../common-utils' ; import enhanceWithMethods from '../enhance-with-methods' ; export type ApiKeyProps = { sys : MetaSysProps ; name : string ; accessToken : string ; environments : { sys : MetaLinkProps ; } [ ] ; preview_api_key : { sys : MetaLinkProps ; } ; description ? : string ; policies ? : { effect : string ; action : string ; } [ ] ; } ; export type CreateApiKeyProps = Pick < ApiKeyProps , 'name' | 'environments' | 'description' > ; export interface ApiKey extends ApiKeyProps , DefaultElements < ApiKeyProps > { return example delete ( ) : Promise < void > ; return example update ( ) : Promise < ApiKey > ; } private function createApiKeyApi ( makeRequest ) { const getParams = ( data ) => ( { spaceId : data . sys . space ?. sys . id ?? '' , apiKeyId : data . sys . id , } ) ; return { update : function update ( ) { const self = this as ApiKeyProps ; return makeRequest ( { entityType : 'ApiKey' , action : 'update' , params : getParams ( self ) , payload : self , headers : { } , } ) . then ( ( data ) => wrapApiKey ( makeRequest , data ) ) ; } , delete : function del ( ) { const self = this as ApiKeyProps ; return makeRequest ( { entityType : 'ApiKey' , action : 'delete' , params : getParams ( self ) , } ) ; } , } ; } private param makeRequest param data export function wrapApiKey ( makeRequest , data ) { const apiKey = toPlainObject ( copy ( data ) ) ; const apiKeyWithMethods = enhanceWithMethods ( apiKey , createApiKeyApi ( makeRequest ) ) ; return freezeSys ( apiKeyWithMethods ) ; } private param makeRequest param data return export const wrapApiKeyCollection = wrapCollection ( wrapApiKey ) ;