kiota-typescript icon indicating copy to clipboard operation
kiota-typescript copied to clipboard

Polymorphism of buffer usage

Open baywet opened this issue 1 year ago • 4 comments

The libraries here make use of Buffer.from multiple places https://github.com/microsoft/kiota-typescript/blob/dfaf4045855f358a44f1fa91b5b85da901b5d24e/packages/authentication/azure/src/azureIdentityAccessTokenProvider.ts#L85 https://github.com/microsoft/kiota-typescript/blob/dfaf4045855f358a44f1fa91b5b85da901b5d24e/packages/serialization/json/src/jsonParseNode.ts#L59 https://github.com/microsoft/kiota-typescript/blob/dfaf4045855f358a44f1fa91b5b85da901b5d24e/packages/serialization/json/src/jsonSerializationWriter.ts#L19 https://github.com/microsoft/kiota-typescript/blob/dfaf4045855f358a44f1fa91b5b85da901b5d24e/packages/serialization/text/src/textParseNode.ts#L31 https://github.com/microsoft/kiota-typescript/blob/dfaf4045855f358a44f1fa91b5b85da901b5d24e/packages/serialization/text/src/textSerializationWriter.ts#L20

This API is NOT AVAILABLE on browsers, we're using it to perform base64 encoding/decoding.

We should instead:

  • define two base64 encode/decode methods in abstractions
  • in the implementations test whether Buffer.from is available, if so, use that.
  • in the implementations test whether atob/btoa are available, if so, use that.
  • if none of those APIs are available, throw
  • replace the calls to Buffer.from by the corresponding method.

baywet avatar Feb 15 '24 14:02 baywet

Adding this to fixes https://github.com/microsoft/kiota-typescript/blob/cd0b0ba50d70e92df22ee1ffe204d95306156073/packages/abstractions/test/common/requestInformation.ts#L9 as url is also a nodejs API in the test usage and fails browser tests.

musale avatar Mar 21 '24 16:03 musale

@musale are you still working on this and still have time? This is blocking for public preview and we might need to re-assign to make progress. Please let us know!

sebastienlevert avatar Mar 27 '24 15:03 sebastienlevert

Yep, confirmed with @musale today

petrhollayms avatar Apr 04 '24 19:04 petrhollayms

@sebastienlevert @petrhollayms almost done with this. Fixing the conflicts and final touches based on https://github.com/microsoft/kiota-typescript/blob/main/packages/http/fetch/docs/design/isomorphic.md as I move over to ESM. I'll have an update on Monday. Apologies for the late response.

musale avatar Apr 05 '24 13:04 musale