From 74fea7be97ea3b795ed36ff680e66342ee793a2b Mon Sep 17 00:00:00 2001 From: bitbeckers Date: Sun, 2 Jun 2024 18:09:53 +0200 Subject: [PATCH] fix(type): simpler api store typings --- sdk/package.json | 2 +- sdk/src/constants.ts | 1 + sdk/src/storage.ts | 16 +++++----------- sdk/src/utils/apis.ts | 24 +++++++++++++----------- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/sdk/package.json b/sdk/package.json index d29c8b6c..f65b7f9f 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@hypercerts-org/sdk", - "version": "2.0.0-alpha.9", + "version": "2.0.0-alpha.10", "description": "SDK for hypercerts protocol", "repository": "git@github.com:hypercerts-org/hypercerts.git", "author": "Hypercerts team", diff --git a/sdk/src/constants.ts b/sdk/src/constants.ts index 7a35601b..19bcef90 100644 --- a/sdk/src/constants.ts +++ b/sdk/src/constants.ts @@ -13,6 +13,7 @@ export const DEFAULT_INDEXER_ENVIRONMENT: IndexerEnvironment = "all"; // TODO when rolled out to production, enable both testing and prod environments const ENDPOINTS: { [key: string]: string } = { metadata: "https://staging-api.hypercerts.org/v1/metadata", + // metadata: "https://hypercerts-api-staging.up.railway.app/v1/metadata", allowlist: "https://staging-api.hypercerts.org/v1/allowlists", }; diff --git a/sdk/src/storage.ts b/sdk/src/storage.ts index 198e012b..56ae2209 100644 --- a/sdk/src/storage.ts +++ b/sdk/src/storage.ts @@ -57,10 +57,6 @@ export class HypercertsStorage implements HypercertStorageInterface { config, ); - if (!resData) { - throw new StorageError("Failed to store metadata", { errors: {}, cid: undefined }); - } - if (!resData.data?.cid || (resData.errors && Object.keys(resData.errors).length > 0)) { throw new StorageError("Failed to store metadata", { errors: resData.errors, data }); } @@ -95,17 +91,15 @@ export class HypercertsStorage implements HypercertStorageInterface { const resData = await uploadMetadata(metadata, config); - if (!resData) { - throw new StorageError("Failed to store metadata", { errors: {}, cid: undefined }); - } - - if (!resData.data?.cid || (resData.errors && Object.keys(resData.errors).length > 0)) { + if (!resData?.cid || (resData.errors && Object.keys(resData.errors).length > 0)) { throw new StorageError("Failed to store metadata", { errors: resData.errors, data }); } - logger.debug(`Stored metadata at ${resData.data?.cid}`); + const { cid } = resData; - return resData.data?.cid; + logger.debug(`Stored metadata at ${cid}`); + + return cid; } /** diff --git a/sdk/src/utils/apis.ts b/sdk/src/utils/apis.ts index 55e1fbcd..27ac4cde 100644 --- a/sdk/src/utils/apis.ts +++ b/sdk/src/utils/apis.ts @@ -10,15 +10,15 @@ type AllowListPostRequest = { totalUnits: string; }; -/** - * Type for the response data from the API. - */ -type ResponseData = { - success: boolean; - message: string; - data?: T; - errors?: Record; -}; +// /** +// * Type for the response data from the API. +// */ +// type ResponseData = { +// success: boolean; +// message: string; +// data?: T; +// errors?: Record; +// }; /** * Axios instance configured with the base URL for the hypercert API. @@ -32,8 +32,9 @@ const api = axios.create({ headers: { "Content-Type": "application/json" } }); * @param {StorageConfigOverrides} [config] - An optional configuration object. * @returns The response data from the API. */ +//TODO fix response typing based on updated API spec const uploadMetadata = async (metadata: HypercertMetadata, config: StorageConfigOverrides = { timeout: 0 }) => { - const res = await api.post>(ENDPOINTS.metadata, metadata, config); + const res = await api.post(ENDPOINTS.metadata, metadata, config); if (!res) { throw new StorageError("Failed to store metadata", { errors: {}, cid: undefined }); @@ -50,8 +51,9 @@ const uploadMetadata = async (metadata: HypercertMetadata, config: StorageConfig * @returns The response data from the API. * */ +//TODO fix response typing based on updated API spec const uploadAllowlist = async (req: AllowListPostRequest, config: StorageConfigOverrides = { timeout: 0 }) => { - const res = await api.post>(ENDPOINTS.allowlist, req, config); + const res = await api.post(ENDPOINTS.allowlist, req, config); if (!res) { throw new StorageError("Failed to store allow list", { errors: {}, cid: undefined });