From de5e42288baa2ab6fef055414beade81eb5a9e07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noe=CC=81=20Malzieu?= Date: Thu, 28 Mar 2024 10:03:41 +0100 Subject: [PATCH 1/2] Add the maxMetaTagSize parameter to the proxy client --- packages/client/src/actions.ts | 28 +++++++++++++++++++--------- packages/client/src/client.ts | 8 +++++--- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/packages/client/src/actions.ts b/packages/client/src/actions.ts index 63a0e51..cdc4b7d 100644 --- a/packages/client/src/actions.ts +++ b/packages/client/src/actions.ts @@ -3,8 +3,10 @@ import type { GetMetadataResponse, PostRedirectResponse } from '@open-frames/pro import { ApiError } from './errors.js'; import { JSONSerializable } from './types.js'; -export async function readMetadata(url: string, proxyUrl: string): Promise { - const response = await fetch(`${proxyUrl}?url=${encodeURIComponent(url)}`); +export async function readMetadata(url: string, proxyUrl: string, maxMetaTagSize?: number | undefined): Promise { + const response = await fetch( + `${proxyUrl}?url=${encodeURIComponent(url)}${maxMetaTagSize ? `&max-meta-tag-bytes=${maxMetaTagSize}` : ''}`, + ); if (!response.ok) { throw new ApiError(`Failed to read metadata for ${url}`, response.status); @@ -13,14 +15,22 @@ export async function readMetadata(url: string, proxyUrl: string): Promise { - const response = await fetch(`${proxyUrl}?url=${encodeURIComponent(url)}`, { - method: 'POST', - body: JSON.stringify(payload), - headers: { - 'Content-Type': 'application/json', +export async function post( + url: string, + payload: JSONSerializable, + proxyUrl: string, + maxMetaTagSize?: number | undefined, +): Promise { + const response = await fetch( + `${proxyUrl}?url=${encodeURIComponent(url)}${maxMetaTagSize ? `&max-meta-tag-bytes=${maxMetaTagSize}` : ''}`, + { + method: 'POST', + body: JSON.stringify(payload), + headers: { + 'Content-Type': 'application/json', + }, }, - }); + ); if (!response.ok) { throw new Error(`Failed to post to frame: ${response.status} ${response.statusText}`); diff --git a/packages/client/src/client.ts b/packages/client/src/client.ts index e311ae4..fa6177c 100644 --- a/packages/client/src/client.ts +++ b/packages/client/src/client.ts @@ -5,17 +5,19 @@ import { JSONSerializable } from './types.js'; export class OpenFramesProxy { baseUrl: string; + maxMetaTagSize: number | undefined; - constructor(baseUrl: string) { + constructor(baseUrl: string, maxMetaTagSize?: number | undefined) { this.baseUrl = baseUrl; + this.maxMetaTagSize = maxMetaTagSize; } async readMetadata(url: string): Promise { - return readMetadata(url, this.baseUrl); + return readMetadata(url, this.baseUrl, this.maxMetaTagSize); } async post(url: string, payload: JSONSerializable): Promise { - return post(url, payload, this.baseUrl); + return post(url, payload, this.baseUrl, this.maxMetaTagSize); } async postRedirect(url: string, payload: JSONSerializable): Promise { From b38ef0446a1b78435a57933e7958c9e709671c70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noe=CC=81=20Malzieu?= Date: Fri, 29 Mar 2024 00:33:13 +0100 Subject: [PATCH 2/2] docs(changeset): Adding the max meta tag size parameter --- .changeset/smart-lobsters-listen.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/smart-lobsters-listen.md diff --git a/.changeset/smart-lobsters-listen.md b/.changeset/smart-lobsters-listen.md new file mode 100644 index 0000000..c35915b --- /dev/null +++ b/.changeset/smart-lobsters-listen.md @@ -0,0 +1,6 @@ +--- +"@open-frames/proxy-client": patch +"@open-frames/proxy": patch +--- + +Adding the max meta tag size parameter