Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDE-4677 fix(core): RawHttpResponse method types #735

Merged
merged 1 commit into from
Jan 30, 2024

Conversation

eliangcs
Copy link
Member

@eliangcs eliangcs commented Jan 29, 2024

Fixes #734, where the response of z.request({ raw: true }) doesn't have correct method typings for TypeScript.

Example TypeScript Code

import { Bundle, ZObject } from 'zapier-platform-core';

const getJson = async (z: ZObject): Promise<object> => {
  const response = await z.request({
    url: 'https://httpbin.zapier-tooling.com/get',
    raw: true,
  });
  return response.json();
};

const getBuffer = async (z: ZObject): Promise<Buffer> => {
  const response = await z.request({
    url: 'https://httpbin.zapier-tooling.com/image/png',
    raw: true,
  });
  return response.buffer();
};

const getText = async (z: ZObject): Promise<string> => {
  const response = await z.request({
    url: 'https://httpbin.zapier-tooling.com/status/418',
    raw: true,
    skipThrowForStatus: true,
  });
  return response.text();
};

const getContent = async (z: ZObject): Promise<Buffer> => {
  const response = await z.request({
    url: 'https://httpbin.zapier-tooling.com/robots.txt',
    raw: true,
  });
  return response.content;
};

Current Behavior

When running the tsc transpiler, response.buffer(), response.json(), and response.text() report errors. response.content, on the other hand, should report an error, but passes instead.

Expected Behavior

@eliangcs eliangcs requested a review from rnegron as a code owner January 29, 2024 10:05
@eliangcs eliangcs requested a review from kreddlear January 29, 2024 10:07
@@ -115,9 +115,10 @@ export interface HttpResponse extends BaseHttpResponse {
}

export interface RawHttpResponse extends BaseHttpResponse {
content: Buffer;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RawHttpResponse.content isn't a valid property and shouldn't be here. When used, it would throw a runtime error.

@eliangcs eliangcs merged commit f693a12 into main Jan 30, 2024
13 checks passed
@eliangcs eliangcs deleted the PDE-4677-fix-RawHttpResponse-method-types branch January 30, 2024 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: z.request when raw is true does not include buffer method on response object
2 participants