import copy from 'fast-copy' ; import { freezeSys , toPlainObject } from 'contentful-sdk-core' ; import enhanceWithMethods from '../enhance-with-methods' ; import { wrapCollection } from '../common-utils' ; import { MetaSysProps , DefaultElements , MakeRequest } from '../common-types' ; export type PersonalAccessTokenProp = { sys : MetaSysProps ; name : string ; scopes : 'content_management_manage' [ ] ; revokedAt : null | string ; token ? : string ; } ; export type CreatePersonalAccessTokenProps = Pick < PersonalAccessToken , 'name' | 'scopes' > ; export interface PersonalAccessToken extends PersonalAccessTokenProp , DefaultElements < PersonalAccessTokenProp > { return example revoke ( ) : Promise < PersonalAccessToken > ; } private param makeRequest param data return export function wrapPersonalAccessToken ( makeRequest , data ) { const personalAccessToken = toPlainObject ( copy ( data ) ) ; const personalAccessTokenWithMethods = enhanceWithMethods ( personalAccessToken , { revoke : function ( ) { return makeRequest ( { entityType : 'PersonalAccessToken' , action : 'revoke' , params : { tokenId : data . sys . id } , } ) . then ( ( data ) => wrapPersonalAccessToken ( makeRequest , data ) ) ; } , } ) ; return freezeSys ( personalAccessTokenWithMethods ) ; } private param makeRequest param data return export const wrapPersonalAccessTokenCollection = wrapCollection ( wrapPersonalAccessToken ) ;