lob / lob-typescript-sdk

MIT License
11 stars 7 forks source link

verifyBulk errors when creating new Model.UsVerification after successful API call #244

Closed jbaum012 closed 1 year ago

jbaum012 commented 2 years ago

Summary

I'm getting an error from within the @lob/lob-typescript-sdk when I attempt to verify bulk address.

Expected Behavior

verifyBulk is able to construct new UsVerification objects after a successful response to the verifyBulk API

Current Behavior

verifyBulk throws an error after successful response from Live API

TypeError: Models.UsVerification is not a constructor
    at UsVerifications.set (/path-to-project/node_modules/@lob/models/us-verifications.ts:51:30)
    at new UsVerifications (/path-to-project/node_modules/@lob/models/us-verifications.ts:27:21)
    at /path-to-project/node_modules/@lob/api/us-verifications-api.ts:288:16
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
node_modules/@cspotcode/source-map-support/source-map-support.js:594
Process exited with code 1

Possible Solution

There seems to be some issue with how that code is being compiled. See UsVerifications inside the compiled index.cjs.js file which is most easily found inside the node_modules folder of any given project.

Steps to Reproduce

  1. Set up a project similar to: https://github.com/jbaum012/lob-verifyBulk-error
  2. execute/debug the verifyBulk method

Context

BennyKitchell commented 2 years ago

Hey @jbaum012,

Thanks for bringing this to our attention, I will be looking into it in the next week or so and will keep you updated.

BennyKitchell commented 2 years ago

@jbaum012 I have put out a new version of the sdk (v1.1.0) that can be found on npm or directly here. I will leave this issue open for a few days to give you a chance to verify everything works. Thanks!

jbaum012 commented 2 years ago

Thank you for the quick response @BennyKitchell! Unfortunately I still see the error when debugging and also in the compiled js script. I've updated my package.json in the example repo if you'd like to test/reproduce.

jbaum012 commented 2 years ago

@BennyKitchell I did a little more digging, and I do see that the UsVerifications reference in index.mjs looks correct; however, the common js version, index.cjs.js is still using new Models.UsVerification. Not sure if that helps, but it might be a good lead.

BennyKitchell commented 2 years ago

@jbaum012 I will continue digging and see what I can find. I wasn't able to replicate it using the data you had in the example repo. Are you using your lob live key or your test key when performing these calls? And just to confirm, you are making these calls using Javascript and not Typescript? I just want to make sure I have as close to a clone as possible for testing.

deloreyj commented 1 year ago

I'm running into the same issue as @jbaum012 on version 1.2.0 of the Typescript SDK. Adding to the hypothesis that the issue is in index.cjs.js, I manually changed this block of the sdk's package.json

  "main": "./dist/index.cjs.js",
  "module": "./dist/index.mjs",
  "types": "./dist/index.d.ts",
  "exports": {
    "node": {
      "import": "./dist/index.mjs",
      "require": "./dist/index.cjs.js"
    },

to this to force referencing the ecma module instead of the common js one

  "main": "./dist/index.mjs",
  "module": "./dist/index.mjs",
  "types": "./dist/index.d.ts",
  "exports": {
    "node": {
      "import": "./dist/index.mjs",
      "require": "./dist/index.mjs"
    },

The issue went away.

BennyKitchell commented 1 year ago

@jbaum012 @deloreyj I have instituted the change suggested above. I will be releasing 1.2.1 by EoD today. Please test it and let me know if this change fixes the issue. Thanks so much for the patience!

BennyKitchell commented 1 year ago

@deloreyj @jbaum012 New version can be found here Thanks!

jbaum012 commented 1 year ago

Hey @BennyKitchell I'm not sure if that did the trick or not. I'm getting a new error (in multiple projects):

Error: Cannot find module `[path to my project]/node_modules/@lob/lob-typescript-sdk/dist/index.cjs.js'

Downgrading seems to also have the same issue though...so I'm not sure if this is related in any way to new code you've deployed 🤔. When I install the package (both 1.1.0 and 1.2.1) and I look in node_modules there is indeed nothing in there for dist/index.cjs.js

EDIT: sorry, I just saw the message above from deloreyj, Looking into that now EDIT 2: Ok, turns out I didn't really downgrade and was using version 1.2.1. I'm pretty sure this is the issue:https://github.com/lob/lob-typescript-sdk/commit/b7c33f1ab376606c98bce0cbd72bf760b964ba98

BennyKitchell commented 1 year ago

@jbaum012 I see the issue, missed a commit. This is what I get for trying to rush a release directly after holidays. Will push out a new version soon and update here. Thanks for your patience!

BennyKitchell commented 1 year ago

@jbaum012 @deloreyj v1.2.2 has been released here, please let me know if there's any problems with this release. Thanks!

jbaum012 commented 1 year ago

@BennyKitchell Progress, but I'm getting a new error in 1.2.2.

Error [ERR_REQUIRE_ESM]: require() of ES Module [path to project]/node_modules/@lob/lob-typescript-sdk/dist/index.mjs not supported. Instead change the require of [path to project]/node_modules/@lob/lob-typescript-sdk/dist/index.mjs to a dynamic import() which is available in all CommonJS modules. at Object. ([path to project]/build/index.js:40:28) { code: 'ERR_REQUIRE_ESM' }

BennyKitchell commented 1 year ago

@jbaum012 With your permission, I am going to pull down your bulkverify repo and work on it locally on my own time until I can find where the problem is hiding.

BennyKitchell commented 1 year ago

@jbaum012 @deloreyj Third times is the charm right? I have personally worked on/ tested this release and also verified it works with your repo on version 1.2.3. I appreciate both of you guys patience and help with this one. The newest version can be found on npm.

Please let me know if you have any other trouble 👍

jbaum012 commented 1 year ago

Success! Looks like everything is working in 1.2.3