Remove api keys from old world (#2548)

* Use apiKeyV2 for getApiKeys

* Use apiKeyV2 for createApiKey

* Use apiKeyV2 for getApiKey

* Use apiKeyV2 to deleteapikey

* Filter null revokedAt -> not working

* Use apiKeyV2 to regenerate

* Fix default values injected

* Remove useless stuff

* Fix type
This commit is contained in:
martmull
2023-11-16 18:14:04 +01:00
committed by GitHub
parent 31adb24ffd
commit e8a1d0d6d5
9 changed files with 179 additions and 76 deletions

View File

@ -1,4 +1,5 @@
import { useMutation } from '@apollo/client';
import { v4 } from 'uuid';
import { useOptimisticEffect } from '@/apollo/optimistic-effect/hooks/useOptimisticEffect';
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
@ -41,16 +42,7 @@ export const useCreateOneObjectRecord = ({
? async (input: Record<string, any>) => {
const createdObject = await mutate({
variables: {
input: {
...foundObjectMetadataItem.fields.reduce(
(result, field) => ({
...result,
[field.name]: defaultFieldValues[field.type],
}),
{},
),
...input,
},
input: { ...input, id: v4() },
},
});
@ -60,6 +52,7 @@ export const useCreateOneObjectRecord = ({
`create${capitalize(foundObjectMetadataItem.nameSingular)}`
],
);
return createdObject.data;
}
: undefined;

View File

@ -0,0 +1,9 @@
import { gql } from '@apollo/client';
export const GENERATE_ONE_API_KEY_TOKEN = gql`
mutation GenerateOneApiKeyToken($data: ApiKeyCreateInput!) {
generateApiKeyV2Token(data: $data) {
token
}
}
`;

View File

@ -1,5 +1,5 @@
import { ApiFieldItem } from '@/settings/developers/types/ApiFieldItem';
import { GetApiKeysQuery } from '~/generated/graphql';
import { ApiKey } from '~/generated/graphql';
import { beautifyDateDiff } from '~/utils/date-utils';
export const formatExpiration = (
@ -18,9 +18,9 @@ export const formatExpiration = (
};
export const formatExpirations = (
apiKeysQuery: GetApiKeysQuery,
apiKeys: Array<Pick<ApiKey, 'id' | 'name' | 'expiresAt'>>,
): ApiFieldItem[] => {
return apiKeysQuery.findManyApiKey.map(({ id, name, expiresAt }) => {
return apiKeys.map(({ id, name, expiresAt }) => {
return {
id,
name,