From 6387a928bfb8f58c8ecd58e15025c8c0b03c4f24 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Wed, 24 Jul 2024 10:33:49 -0500 Subject: [PATCH] Fixes issue with process undefined (#516) --- .changeset/healthy-tools-accept.md | 5 +++++ .../src/object/convertWireToOsdkObjects.ts | 2 +- .../objectSet/ObjectSetListenerWebsocket.ts | 20 +++++++++---------- packages/legacy-client/src/client/addCause.ts | 2 +- 4 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 .changeset/healthy-tools-accept.md diff --git a/.changeset/healthy-tools-accept.md b/.changeset/healthy-tools-accept.md new file mode 100644 index 000000000..3beb34880 --- /dev/null +++ b/.changeset/healthy-tools-accept.md @@ -0,0 +1,5 @@ +--- +"@osdk/client": patch +--- + +Makes defining process.env.NODE_ENV optional diff --git a/packages/client/src/object/convertWireToOsdkObjects.ts b/packages/client/src/object/convertWireToOsdkObjects.ts index 01c266372..cece42e85 100644 --- a/packages/client/src/object/convertWireToOsdkObjects.ts +++ b/packages/client/src/object/convertWireToOsdkObjects.ts @@ -174,7 +174,7 @@ function isConforming( ) { for (const propName of propsToCheck) { if (def.properties[propName].nullable === false && obj[propName] == null) { - if (process.env.NODE_ENV !== "production") { + if (process?.env?.NODE_ENV !== "production") { client.logger?.debug( { obj: { diff --git a/packages/client/src/objectSet/ObjectSetListenerWebsocket.ts b/packages/client/src/objectSet/ObjectSetListenerWebsocket.ts index a268f81e0..364d77773 100644 --- a/packages/client/src/objectSet/ObjectSetListenerWebsocket.ts +++ b/packages/client/src/objectSet/ObjectSetListenerWebsocket.ts @@ -226,7 +226,7 @@ export class ObjectSetListenerWebsocket { * @returns */ async #initiateSubscribe(sub: Subscription) { - if (process.env.NODE_ENV !== "production") { + if (process?.env?.NODE_ENV !== "production") { this.#logger?.trace("#initiateSubscribe()"); } if (sub.expiry) { @@ -278,7 +278,7 @@ export class ObjectSetListenerWebsocket { } #sendSubscribeMessage() { - if (process.env.NODE_ENV !== "production") { + if (process?.env?.NODE_ENV !== "production") { this.#logger?.trace("#sendSubscribeMessage()"); } // If two calls to `.subscribe()` happen at once (or if the connection is reset), @@ -287,7 +287,7 @@ export class ObjectSetListenerWebsocket { const readySubs = [...this.#subscriptions.values()].filter(isReady); if (readySubs.length === 0) { - if (process.env.NODE_ENV !== "production") { + if (process?.env?.NODE_ENV !== "production") { this.#logger?.trace( "#sendSubscribeMessage(): aborting due to no ready subscriptions", ); @@ -316,7 +316,7 @@ export class ObjectSetListenerWebsocket { })), }; - if (process.env.NODE_ENV !== "production") { + if (process?.env?.NODE_ENV !== "production") { this.#logger?.trace( { payload: subscribe }, "sending subscribe message", @@ -327,7 +327,7 @@ export class ObjectSetListenerWebsocket { } #expire(sub: Subscription) { - if (process.env.NODE_ENV !== "production") { + if (process?.env?.NODE_ENV !== "production") { this.#logger?.trace({ subscription: sub }, "#expire()"); } // the temporary ObjectSet has expired, we should re-subscribe which will cause the @@ -403,7 +403,7 @@ export class ObjectSetListenerWebsocket { // we again may have lost the race after our minimum backoff time if (this.#ws == null) { - if (process.env.NODE_ENV !== "production") { + if (process?.env?.NODE_ENV !== "production") { this.#logger?.trace("Creating websocket"); } this.#ws = new WebSocket(url, [`Bearer-${token}`]); @@ -449,7 +449,7 @@ export class ObjectSetListenerWebsocket { | StreamMessage | Message; - if (process.env.NODE_ENV !== "production") { + if (process?.env?.NODE_ENV !== "production") { this.#logger?.trace({ payload: data }, "received message from ws"); } @@ -543,7 +543,7 @@ export class ObjectSetListenerWebsocket { const shouldFireOutOfDate = sub.status === "expired" || sub.status === "reconnecting"; - if (process.env.NODE_ENV !== "production") { + if (process?.env?.NODE_ENV !== "production") { this.#logger?.trace({ shouldFireOutOfDate }, "success"); } @@ -572,7 +572,7 @@ export class ObjectSetListenerWebsocket { } #onClose = (event: WebSocket.CloseEvent) => { - if (process.env.NODE_ENV !== "production") { + if (process?.env?.NODE_ENV !== "production") { this.#logger?.trace({ event }, "Received close event from ws", event); } // TODO we should probably throttle this so we don't abuse the backend @@ -621,7 +621,7 @@ export class ObjectSetListenerWebsocket { // if we have any listeners that are still depending on us, go ahead and reopen the websocket if (this.#subscriptions.size > 0) { - if (process.env.NODE_ENV !== "production") { + if (process?.env?.NODE_ENV !== "production") { for (const s of this.#subscriptions.values()) { invariant( s.status !== "done" && s.status !== "error", diff --git a/packages/legacy-client/src/client/addCause.ts b/packages/legacy-client/src/client/addCause.ts index 1d589a787..a8c3fe7f6 100644 --- a/packages/legacy-client/src/client/addCause.ts +++ b/packages/legacy-client/src/client/addCause.ts @@ -15,7 +15,7 @@ */ export function addCause(e: Error, cause: any) { - if (process.env.NODE_ENV !== "production") { + if (process?.env?.NODE_ENV !== "production") { // In case someone is debugging on an older browser or the `.cause` assignment trick // does not work in certain environments, we log the cause to the console to aid debugging. // eslint-disable-next-line no-console