diff --git a/docs/pages/changelog.mdx b/docs/pages/changelog.mdx index fc59c3d..09fd72a 100644 --- a/docs/pages/changelog.mdx +++ b/docs/pages/changelog.mdx @@ -15,3 +15,8 @@ - Packages do not export input types anymore. - Drop properties are not exported anymore. + +## 0.6.0 + +- `createMoment` does not upload media beforehand anymore. Use `createMomentAndUploadMedia` instead. +- For compass requests, the fetch signal is not a parameter of the `PoapCompass.request` method anymore, it must be given through the new `options` parameter: `compass.request(url, { variables }, { signal })`. diff --git a/packages/drops/package.json b/packages/drops/package.json index dbf33f4..6181de4 100644 --- a/packages/drops/package.json +++ b/packages/drops/package.json @@ -29,7 +29,7 @@ "node": ">=18" }, "dependencies": { - "@poap-xyz/providers": "0.5.5", + "@poap-xyz/providers": "0.6.0", "@poap-xyz/utils": "0.5.5" } } diff --git a/packages/providers/package.json b/packages/providers/package.json index 2a1af24..7809b70 100644 --- a/packages/providers/package.json +++ b/packages/providers/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/providers", - "version": "0.5.5", + "version": "0.6.0", "description": "Providers module for the poap.js library", "main": "dist/cjs/index.cjs", "module": "dist/esm/index.mjs", diff --git a/packages/providers/src/core/PoapCompass/PoapCompass.ts b/packages/providers/src/core/PoapCompass/PoapCompass.ts index b8e8404..b38b197 100644 --- a/packages/providers/src/core/PoapCompass/PoapCompass.ts +++ b/packages/providers/src/core/PoapCompass/PoapCompass.ts @@ -42,29 +42,32 @@ export class PoapCompass implements CompassProvider { * @name PoapCompass#fetchGraphQL * @param {string} query - The GraphQL query to fetch. * @param {{ readonly [variable: string]: unknown }} variables - The variables to include with the query. - * @param {AbortSignal} signal - When given, the request can be aborted with its controller. + * @param {RequestInit} options - Additional options to pass to the fetch call. * @returns {Promise} A Promise that resolves with the result of the query. * @template R - The type of the result. */ private async fetchGraphQL( query: string, variables: { readonly [variable: string]: unknown }, - signal?: AbortSignal, + options?: RequestInit, ): Promise { let response: Response; + const headers: HeadersInit = { + ...options?.headers, + 'Content-Type': 'application/json', + 'x-api-key': this.apiKey, + }; + try { response = await fetch(this.baseUrl, { - signal, method: 'POST', body: JSON.stringify({ query, variables, }), - headers: { - 'Content-Type': 'application/json', - 'x-api-key': this.apiKey, - }, + ...options, + headers, }); } catch (error: unknown) { throw new Error(`Network error, received error ${error}`); @@ -174,22 +177,26 @@ export class PoapCompass implements CompassProvider { async request( query: string, variables?: null | undefined | V, - signal?: AbortSignal, + options?: RequestInit, ): Promise<{ data: D }> { - return await this.fetchGraphQL<{ data: D }>(query, variables ?? {}, signal); + return await this.fetchGraphQL<{ data: D }>( + query, + variables ?? {}, + options, + ); } async batch( query: string, variables: V[], - signal?: AbortSignal, + options?: RequestInit, ): Promise<{ data: D }[]> { const results: { data: D }[] = []; const chunks: V[][] = chunk(variables, this.batchSize); for (const chunk of chunks) { const responses = await Promise.all( - chunk.map((variables) => this.request(query, variables, signal)), + chunk.map((variables) => this.request(query, variables, options)), ); results.push(...responses); } diff --git a/packages/providers/src/ports/CompassProvider/CompassProvider.ts b/packages/providers/src/ports/CompassProvider/CompassProvider.ts index 5f67cd5..9e09f4d 100644 --- a/packages/providers/src/ports/CompassProvider/CompassProvider.ts +++ b/packages/providers/src/ports/CompassProvider/CompassProvider.ts @@ -11,7 +11,7 @@ export interface CompassProvider { * @name CompassProvider#request * @param {string} query - The query string to execute. * @param {null | undefined | { readonly [variable: string]: unknown }} [variables] - The variables to pass with the query. - * @param {AbortSignal} signal - When given, the request can be aborted with its controller. + * @param {RequestInit} [options] - Options to pass to the fetch call. * @returns {Promise<{ data: D }>} A Promise that resolves with the result of the query. * @template D - The type of the result's data. * @template V - The type of the query's variables. @@ -19,7 +19,7 @@ export interface CompassProvider { request( query: string, variables?: null | undefined | V, - signal?: AbortSignal, + options?: RequestInit, ): Promise<{ data: D }>; /** @@ -31,7 +31,7 @@ export interface CompassProvider { * @name CompassProvider#batch * @param {string} query - The query string to execute. * @param {{ readonly [variable: string]: unknown }[]} variables - The variables to pass with the each query. - * @param {AbortSignal} [signal] - When given, the requests can be aborted with its controller. + * @param {RequestInit} [options] - Options to pass to the fetch call. * @returns {Promise<{ data: D }[]>} A Promise that resolves with the results of the queries. * @template D - The type of the result's data. * @template V - The type of the query's variables. @@ -39,6 +39,6 @@ export interface CompassProvider { batch( query: string, variables: V[], - signal?: AbortSignal, + options?: RequestInit, ): Promise<{ data: D }[]>; } diff --git a/yarn.lock b/yarn.lock index 262a1e8..73814d5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -884,7 +884,7 @@ __metadata: version: 0.0.0-use.local resolution: "@poap-xyz/drops@workspace:packages/drops" dependencies: - "@poap-xyz/providers": 0.5.5 + "@poap-xyz/providers": 0.6.0 "@poap-xyz/utils": 0.5.5 languageName: unknown linkType: soft @@ -917,7 +917,7 @@ __metadata: languageName: unknown linkType: soft -"@poap-xyz/providers@0.5.5, @poap-xyz/providers@workspace:packages/providers": +"@poap-xyz/providers@0.6.0, @poap-xyz/providers@workspace:packages/providers": version: 0.0.0-use.local resolution: "@poap-xyz/providers@workspace:packages/providers" dependencies: @@ -929,6 +929,17 @@ __metadata: languageName: unknown linkType: soft +"@poap-xyz/providers@npm:0.5.5": + version: 0.5.5 + resolution: "@poap-xyz/providers@npm:0.5.5" + dependencies: + "@poap-xyz/utils": 0.5.5 + axios: ^1.6.8 + lodash.chunk: ^4.2.0 + checksum: 7648e7cbcd68610591a9a5a2123271a80791224ba9fb5d1c4fc86318514c863e9888450183cfc35aa2a45f6fc09a9f9e87299771f78fda807e9e0062a1bb4fd1 + languageName: node + linkType: hard + "@poap-xyz/utils@0.5.5, @poap-xyz/utils@workspace:packages/utils": version: 0.0.0-use.local resolution: "@poap-xyz/utils@workspace:packages/utils"