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

Is there a release date for Typescript support? #1

Open
cdslxc opened this issue Jun 15, 2023 · 40 comments · May be fixed by #19
Open

Is there a release date for Typescript support? #1

cdslxc opened this issue Jun 15, 2023 · 40 comments · May be fixed by #19

Comments

@cdslxc
Copy link

cdslxc commented Jun 15, 2023

My current project used Typescript, I wasn't able to migrate from SIB to Brevo.

CleanShot 2023-06-15 at 16 13 51@2x
@shubhamUpadhyayInBlue
Copy link
Collaborator

Hi @cody-ta
We are still trying to find a way to provide TS support for the same. It is taking us some time to figure that out since our SDKs are auto-generated using swagger-codegen@2.
Thanks.

@NarHakobyan
Copy link

NarHakobyan commented Jun 21, 2023

Yeah, I think most of NodeJS developers will look for this issue. @shubhamUpadhyayInBlue have you tried https://github.com/acacode/swagger-typescript-api?

@reynolga
Copy link

Also looking for typescript support as I'm moving my website from js to typescript at the moment.

@shubhamUpadhyayInBlue
Copy link
Collaborator

Hello
I have raised the request and will update you as soon as I have any updates. Thanks.

@matthiasbruns
Copy link

matthiasbruns commented Jun 27, 2023

Until solved:

swagger-typescript-api -p https://api.brevo.com/v3/swagger_definition.yml -o ./lib/email/brevo

@NarHakobyan
Copy link

Until solved:

swagger-typescript-api -p https://api.brevo.com/v3/swagger_definition.yml -o ./lib/email/brevo

Better then lib 😄

@AlexZeitler
Copy link

@matthiasbruns How do you set the API key?

@NarHakobyan
Copy link

@matthiasbruns How do you set the API key?

new Brevo({
          baseApiParams: {
            headers: {
              'api-key': yourKeyhere,
            },
          },
        })

@AlexZeitler
Copy link

@NarHakobyan Thanks!

@shubhamUpadhyayInBlue
Copy link
Collaborator

The latest swagger file is here: https://api.brevo.com/v3/swagger_definition_v3.yml

So, @matthiasbruns @NarHakobyan you can try using this latest swagger file instead.

@garysb
Copy link

garysb commented Jul 5, 2023

Hi @shubhamUpadhyayInBlue, thanks for the new definition but there is an issue in the swagger file at line 17986. Please remove the double quote.

   try to get swagger by URL "https://api.brevo.com/v3/swagger_definition_v3.yml"
☄️    start generating your typescript api
SyntaxError: ';' expected. (6656:97)
  6654 |    * @example "request"
  6655 |    */
> 6656 |     event: "invalid_parameter" | "missing_parameter" | "hardBounce" | "softBounce" | "delivered"" | "spam" | "request" | "opened" | "click" | "invalid" | "deferred" | "blocked" | "unsubscribed" | "error" | "uniqueOpened" | "loadedByProxy" | "allEvents",
       |                                                                                                 ^
  6657 |   /**
  6658 |    * Webhook URL to receive CSV file link
  6659 |    * @example "https://brevo.com"

@shubhamUpadhyayInBlue
Copy link
Collaborator

Hi @garysb
I have fixed the swagger file. Please try and let me know if you face any issue.

@marentdev
Copy link

Take me sometimes to get it working (because din't know how swagger-typescript-api was working) but now everything is working and tested!

https://gist.github.com/marentdev/28d49bfee47704ac39fcd55cb4ac8b0e (Brevo Lib)

@higuitadiaz
Copy link

Hi @shubhamUpadhyayInBlue
Do you have defined an estimated time for an official documentation of the library under TS?

Developer:

If you do not know how to use the swagger-typescript-api library you can guide yourself with the following steps:

/** npx swagger-typescript-api -p https://api.brevo.com/v3/swagger_definition.yml -o [PATH-OUTPUT] -n [TS-FILENAME (Sample: Brevo.ts)]
**/

// SAMPLE
// console
npx swagger-typescript-api -p https://api.brevo.com/v3/swagger_definition.yml -o /src/utils/email -n Brevo.ts
...

// ts-file.ts
import { Brevo } from './utils/email/Brevo';

...

const brevo = new Brevo({ baseApiParams: { headers: { 'api-key': 'YOUR-KEY' } })

@kracas
Copy link

kracas commented Aug 17, 2023

Hi @shubhamUpadhyayInBlue Do you have defined an estimated time for an official documentation of the library under TS?

Developer:

If you do not know how to use the swagger-typescript-api library you can guide yourself with the following steps:

/** npx swagger-typescript-api -p https://api.brevo.com/v3/swagger_definition.yml -o [PATH-OUTPUT] -n [TS-FILENAME (Sample: Brevo.ts)]
**/

// SAMPLE
// console
npx swagger-typescript-api -p https://api.brevo.com/v3/swagger_definition.yml -o /src/utils/email -n Brevo.ts
...

// ts-file.ts
import { Brevo } from './utils/email/Brevo';

...

const brevo = new Brevo({ baseApiParams: { headers: { 'api-key': 'YOUR-KEY' } })

Hi @higuitadiaz,
Thanks for the explanation.
Just a few comments, the swagger definition in your guide is outdated. The link to the current swagger definition is https://api.brevo.com/v3/swagger_definition_v3.yml (notice the second v3 at the end).
Also swagger-typescript-api does not name the client "Brevo" by default. The name for the client is "Api", so you should either change the name to Brevo in the Brevo.ts file or use it like this:

// ts-file.ts
import { Api } from './utils/email/Brevo';

...

const brevo = new Api({ baseApiParams: { headers: { 'api-key': 'YOUR-KEY' } })

@SMKH-PRO
Copy link

Really need ts support before we can migrate to brevo

@shorthander
Copy link

I also need ts support before I can move to brevo...
@shubhamUpadhyayInBlue have you thought about moving to the openapi generator? In openapi generator, which should be compatible to your swagger definition file, you should be able to generate typescript code for several libs like fetch or axios.
https://openapi-generator.tech/docs/generators

@cwierzbicki00
Copy link

Any update here @shubhamUpadhyayInBlue ?

We do not want to continue building with deprecated lib, but the lack of Typescript support here is blocking us. It has been several months since you've raised this issue, so I would hope some progress has been made. Could you provide us with an estimate?

@shubhamUpadhyayInBlue
Copy link
Collaborator

Hi @cwierzbicki00
It is under discussion and we will be able to give feedback soon. I will make sure your message reaches the concerned team.
Thanks.

@iampapagray
Copy link

iampapagray commented Sep 21, 2023

Hi @shubhamUpadhyayInBlue Do you have defined an estimated time for an official documentation of the library under TS?
Developer:
If you do not know how to use the swagger-typescript-api library you can guide yourself with the following steps:

/** npx swagger-typescript-api -p https://api.brevo.com/v3/swagger_definition.yml -o [PATH-OUTPUT] -n [TS-FILENAME (Sample: Brevo.ts)]
**/

// SAMPLE
// console
npx swagger-typescript-api -p https://api.brevo.com/v3/swagger_definition.yml -o /src/utils/email -n Brevo.ts
...

// ts-file.ts
import { Brevo } from './utils/email/Brevo';

...

const brevo = new Brevo({ baseApiParams: { headers: { 'api-key': 'YOUR-KEY' } })

Hi @higuitadiaz, Thanks for the explanation. Just a few comments, the swagger definition in your guide is outdated. The link to the current swagger definition is https://api.brevo.com/v3/swagger_definition_v3.yml (notice the second v3 at the end). Also swagger-typescript-api does not name the client "Brevo" by default. The name for the client is "Api", so you should either change the name to Brevo in the Brevo.ts file or use it like this:

// ts-file.ts
import { Api } from './utils/email/Brevo';

...

const brevo = new Api({ baseApiParams: { headers: { 'api-key': 'YOUR-KEY' } })

Thanks for the Ts help.
Can anyone help with the the steps to send a simple transactional email with a template and a param?
I cant seem to follow the instructions with this ts file.


EDIT:

I figured it out.
For anyone who gets confused too:

import { Api } from './utils/email/Brevo' // import from whichever location you generated the ts file to

const brevo = new Api({ baseApiParams: { headers: { 'api-key': 'YOUR-KEY' } })

let emailData: SendSmtpEmail = {
  templateId: parseInt(templateId),
  sender: { name: siteConfig.name, email: env.SMTP_FROM },
  to: [{ email: identifier }],
  headers: { "X-Entity-Ref-ID": new Date().getTime() + "" },
  params: {
    action_url: url,
    product_name: siteConfig.name,
  },
};

const result = await await brevo.smtp.sendTransacEmail(emailData);

if (result.status != 201) {
  throw new Error(result.error.message);
}

Thanks

@theofrgs
Copy link

theofrgs commented Oct 6, 2023

Is there any update about the typescript release ?

@FredTreg
Copy link

$ npm remove @sendinblue/client
$ npm install @getbrevo/brevo
$ npm i --save-dev @types/getbrevo__brevo
npm ERR! code E404

=> Googling, finding this github issue, then 5 minutes later:

$ npm remove @getbrevo/brevo
$ npm install @sendinblue/client

:)

(I do hope they support TS soon though as the security audit of sendinblue/client is bad)

@vladislavbogomolov
Copy link

Sending transactional emails via axios/fetch is more comfortable

@dkrest1
Copy link

dkrest1 commented Oct 23, 2023

Until solved:

swagger-typescript-api -p https://api.brevo.com/v3/swagger_definition.yml -o ./lib/email/brevo

how do I make use of this

@dkrest1
Copy link

dkrest1 commented Oct 23, 2023

Is there any update about the typescript release ?

I am not sure because I have not seen one

@tiavina-mika
Copy link

Is there any news about TypeScript?

@akouyate
Copy link

Up !

@mwolf1989
Copy link

Is there something new on this? Send In blue is gone now for a while and still missleading docs on the page, still no TS support.

@FrancoisSoler
Copy link

Hi, my client bought a license for Brevo without telling me, now i'm stuck with this and can't deliver the app, client is waiting, do you guys could at least bother to respond to us ? I understood you guys don't care but we are client, and you can bet I won't recommend this to any of my clients in the futur

@cwierzbicki00
Copy link

cwierzbicki00 commented Nov 16, 2023

@shubhamUpadhyayInBlue

Hi @cwierzbicki00 It is under discussion and we will be able to give feedback soon. I will make sure your message reaches the concerned team. Thanks.

This seems to be a larger and larger issue for everyone. Especially knowing that the types can be generated, this is frustrating. "swagger-typescript-api -p https://api.brevo.com/v3/swagger_definition.yml -o ./lib/email/brevo" is not a valid long-term solution for a production level product like this. I am hoping for an update soon.

Please at least advise how we should proceed - we need Typescript support. I don't want to build with insecure and deprecated sendinblue. What are we to do to use Brevo?

Thanks

@ryan-james-smith
Copy link

Hi @cwierzbicki00 It is under discussion and we will be able to give feedback soon. I will make sure your message reaches the concerned team. Thanks.

If soon as in "we will be able to give feedback soon" is over two months, I guess I may need to look for a different company than brevo as Typescript support is non negotiable in our projects these days.
Would love an update with some good news very very soon in the hopes I don't have to rewrite what we are already using brevo for.

@shubhamUpadhyayInBlue
Copy link
Collaborator

Hello!
I have released a beta tag with typescript support. Here are the steps how you can try it out and share your valuable feedback.

To install it in your application:
npm i @getbrevo/[email protected] --save

Sample code to send the transactional email:

const SibApiV3Sdk = require('@getbrevo/brevo');
let apiInstance = new SibApiV3Sdk.TransactionalEmailsApi();
let apiKey = apiInstance.authentications['apiKey'];
apiKey.apiKey = 'YOUR API KEY';
let sendSmtpEmail = new SibApiV3Sdk.SendSmtpEmail(); 

sendSmtpEmail.subject = "My {{params.subject}}";
sendSmtpEmail.htmlContent = "<html><body><h1>This is my first transactional email {{params.parameter}}</h1></body></html>";
sendSmtpEmail.sender = {"name":"John Doe","email":"[email protected]"};
sendSmtpEmail.to = [{"email":"[email protected]","name":"Jane Doe"}];
sendSmtpEmail.cc = [{"email":"[email protected]","name":"Janice Doe"}];
sendSmtpEmail.bcc = [{"name":"John Doe","email":"[email protected]"}];
sendSmtpEmail.replyTo = {"email":"[email protected]","name":"John Doe"};
sendSmtpEmail.headers = {"Some-Custom-Name":"unique-id-1234"};
sendSmtpEmail.params = {"parameter":"My param value","subject":"New Subject"};

apiInstance.sendTransacEmail(sendSmtpEmail).then(function(data) {
  console.log('API called successfully. Returned data: ' + JSON.stringify(data));

}, function(error) {
  console.error(error);
});

Hope it helps.
Thanks.

@mwolf1989
Copy link

mwolf1989 commented Dec 5, 2023

Hello! I have released a beta tag with typescript support. Here are the steps how you can try it out and share your valuable feedback.

To install it in your application: npm i @getbrevo/[email protected] --save

Sample code to send the transactional email:

const SibApiV3Sdk = require('@getbrevo/brevo');
let apiInstance = new SibApiV3Sdk.TransactionalEmailsApi();
let apiKey = apiInstance.authentications['apiKey'];
apiKey.apiKey = 'YOUR API KEY';
let sendSmtpEmail = new SibApiV3Sdk.SendSmtpEmail(); 

sendSmtpEmail.subject = "My {{params.subject}}";
sendSmtpEmail.htmlContent = "<html><body><h1>This is my first transactional email {{params.parameter}}</h1></body></html>";
sendSmtpEmail.sender = {"name":"John Doe","email":"[email protected]"};
sendSmtpEmail.to = [{"email":"[email protected]","name":"Jane Doe"}];
sendSmtpEmail.cc = [{"email":"[email protected]","name":"Janice Doe"}];
sendSmtpEmail.bcc = [{"name":"John Doe","email":"[email protected]"}];
sendSmtpEmail.replyTo = {"email":"[email protected]","name":"John Doe"};
sendSmtpEmail.headers = {"Some-Custom-Name":"unique-id-1234"};
sendSmtpEmail.params = {"parameter":"My param value","subject":"New Subject"};

apiInstance.sendTransacEmail(sendSmtpEmail).then(function(data) {
  console.log('API called successfully. Returned data: ' + JSON.stringify(data));

}, function(error) {
  console.error(error);
});

Hope it helps. Thanks.

Many thanks!

I tried your example but run directly in different issues:

for the line:
let apiKey = apiInstance.authentications['apiKey'];

TS complains:
TS2445: Property  authentications  is protected and only accessible within class  TransactionalEmailsApi  and its subclasses.

also I want to use it in the next's context so I have to convert the import from require to the import syntax.

If I wrap it in a function::

  async getContactByEmail(email: string) {
       let apiInstance = new SibApiV3Sdk.ContactsApi()
       apiInstance.setApiKey(SibApiV3Sdk.ContactsApiApiKeys.apiKey, process.env.BREVO_API_KEY);
       const resp = await apiInstance.getContactInfo(email);
       console.log(resp);
       return resp;
   }
I get following issue:
   Error: Cannot read properties of undefined (reading 'ContactsApi')
> 42 |     let apiInstance = new SibApiV3Sdk.ContactsApi()
    |                          ^
 Any suggestions? 

@bmenant
Copy link

bmenant commented Dec 11, 2023

⚠️
Another important note is that the 2.0.0-beta.4 release with typescript support has deprecated dependencies, notably request (last update ~5 years ago) and to some extent bluebird (native promises are strongly recommended).

As of today, the 1.x branch is probably safer (and faster) to use... or to use some swagger-typescript-api trickery.

@mwolf1989
Copy link

Are there news vor the V2 release?

@zolzaya
Copy link

zolzaya commented Jan 6, 2024

Is there any news about TypeScript?

@peterbbeu
Copy link

peterbbeu commented Jan 15, 2024

Quite annoying that I have to choose between typescript support, or a version with (ancient!) unpatchable vulnerabilities.

Come on, it's not that hard!

┌───────────────┬──────────────────────────────────────────────────────────────┐
│ moderate      │ Server-Side Request Forgery in Request                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ request                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ No patch available                                           │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @getbrevo/brevo                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @getbrevo/brevo > request                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://www.npmjs.com/advisories/1092972                     │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ moderate      │ tough-cookie Prototype Pollution vulnerability               │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ tough-cookie                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=4.1.3                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @getbrevo/brevo                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @getbrevo/brevo > request > tough-cookie                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://www.npmjs.com/advisories/1095102                     │
└───────────────┴──────────────────────────────────────────────────────────────┘

@NarHakobyan
Copy link

I think it's already been released, but it's the worst version I've ever seen. you need to call setApiKey on every class AccountApi, CompaniesApi, etc.

@alexbrazier
Copy link

I've created a PR #19 that hopefully solves this issue. Hopefully it gets accepted and merged, but in the meantime you can use @groupcards/brevo which you can verify was published from this action.

Feel free to leave a comment on the PR if there are any issues with it or if it's working for you.

Usage

npm install @groupcards/brevo

const brevo = new BrevoApi({
  headers: {
    "api-key": "YOUR_API_KEY",
  },
});

const account = await brevo.account.getAccount()

@alexbrazier alexbrazier linked a pull request Apr 4, 2024 that will close this issue
@gandrin
Copy link

gandrin commented May 27, 2024

Hello, as everyone here I think, I would like to see the types for this SDK.

If you do not plan to do so, you could at least remove the Typescript from Brevo Typescript in the package. It's misleading for people trying to work with your SDK as we're expecting real typing support.

It makes the first encounter, as a developper, with the tool, disappointing. It might be a harsh point of view but I prefer a good accessible swagger and no SDK rather than a SDK failing at its job of making integration simpler.

If you cannot maintain it, drop it.

@alexbrazier thanks for the MR, I'll try it ;)

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 a pull request may close this issue.