Vonage / vonage-node-sdk

Vonage API client for Node.js. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
Apache License 2.0
374 stars 178 forks source link

Use promise instead of callback #510

Closed soullivaneuh closed 1 year ago

soullivaneuh commented 3 years ago

Sumarry

This issue is a following of https://github.com/Vonage/vonage-node-sdk/issues/197.

Even if some workarounds is possible (e.g. https://github.com/Vonage/vonage-node-sdk/issues/197#issuecomment-409252927), es6 promise is the current way to go on recent JavaScript environment.

I suggest to release a new major of this SDK, converting all callback function to ES6 promise system.

I think #78 should be resolved first or at the same time.

Examples

Classic way (then/catch)

nexmo.verify
  .request({
    number: '+33601020304',
    brand: 'My Brand',
    code_length: 4,
  })
  .then((verifyData: RequestResponse) => {
    // Stuff.
  })
  .catch((error: VerifyError) => {
    // Error handling stuff.
  })
;

Async way (try/catch)

try {
  const verifyData = async nexmo.verify.request({
    number: '+33601020304',
    brand: 'My Brand',
    code_length: 4,
  });
  // Stuff
} catch (error: VerifyError) {
  // Error handling stuff.
}
kellyjandrews commented 3 years ago

Thanks for the feedback. I'm currently working on a version 3 that addresses all of these issues. I'm also open to pull requests for the v2.x branch line.

manchuck commented 1 year ago

@soullivaneuh With the release of version 3, the entire SDK is now using promises. The SDK was also broken out into multiple packages as well. Check the migration guide on how to update to the new code. If you have any questions, please feel free to reach out.

cowchimp commented 1 year ago

Check the migration guide on how to update to the new code.

@manchuck Can you link to the migration guide please?

manchuck commented 1 year ago

@cowchimp Here is what was committed: https://github.com/Vonage/vonage-node-sdk/blob/3.x/packages/verify/v2_TO_v3_MIGRATION_GUIDE.md

There was a typo that is addressed in #726

We are also working on updating the code snippets and the docs at documentation

If you have any other issues or questions, you can reach out to our community slack channel