facebook / facebook-nodejs-business-sdk

Node.js SDK for Meta Marketing APIs
https://developers.facebook.com/docs/business-sdk
Other
500 stars 227 forks source link

Need TypeScript definitions #130

Closed kevinclarkadstech closed 1 year ago

kevinclarkadstech commented 5 years ago

Which SDK version are you using?

"^5.0.1"

What's the issue?

Need TypeScript definitions.

Steps/Sample code to reproduce the issue

1) Create a .ts file 2) Type import fbSdk from 'facebook-nodejs-business-sdk';

Observed Results:

IDE throws an error: Could not find a declaration file for module 'facebook-nodejs-business-sdk'. '/Dev/facebook-nodejs-business-sdk-test/node_modules/facebook-nodejs-business-sdk/dist/cjs.js' implicitly has an 'any' type.
  Try `npm install @types/facebook-nodejs-business-sdk` if it exists or add a new declaration (.d.ts) file containing `declare module 'facebook-nodejs-business-sdk';`ts(7016)

Expected Results:

brent-weatherall commented 2 years ago

Another bump for the party. How is this still not supported? :(

KloudCoder commented 2 years ago

I'm shocked. No comment for Facebook. NoTypings for such a big project

gustavogr commented 2 years ago

Bump. Just stumbled with this when a client asked to be integrated with Facebook Business.

kigorw commented 2 years ago

bump to keep it active

lluchkaa commented 2 years ago

another bump

Vict0rd commented 2 years ago

BUUUMP

dtpietrzak commented 2 years ago

BUUMMPPPP

kevinclarkadstech commented 2 years ago

Stop thumb downing bumps @Desnoo . Facebook deserves the thumbs down.

Desnoo commented 2 years ago

@kevinclarkadstech we also do need this. But if you wait for a response you only get notifications about the bump messages and this is really annoying. Every week is ok but not every day.

Vict0rd commented 2 years ago

PR https://github.com/DefinitelyTyped/DefinitelyTyped/pull/62989

Vict0rd commented 2 years ago

The PR is merged.

kevinclarkadstech commented 1 year ago

I guess I'm closing this so I don't have to see it anymore. Annoying how the community has to write definitions for a product that Facebook profits from.

phillipmohr commented 8 months ago

Could someone please explain how to use the type definitions from DefinitelyTyped?

Example:

const leadgenForms: LeadgenForm[] = await (new Page(pageId)).getLeadGenForms([
    LeadgenForm.Fields.questions,
])

Getting Type 'Cursor' is not assignable to type 'LeadgenForm[]'., which makes sense since getLeadGenForms returns Promise<Cursor>. I also tried

const leadgenForms: Cursor<LeadgenForm[]> = await (new Page(pageId)).getLeadGenForms([
    LeadgenForm.Fields.questions,
]);

Not sure how it's supposed to work... Any help is appreciated

Vict0rd commented 8 months ago

@phillipmohr I use this method

  public async *fetchInsightPages({
    fields,
    params,
  }: {
    fields: string[];
    params: Record<string, string>;
  }): AsyncGenerator<Insight[]> {
    const cursor = await this.fbAdAccount.getInsights(fields, params);

    while (true) {
      yield cursor.map((item): Insight => {
        return {
          adId: item.ad_id,
          adName: item.ad_name,
          ...
          startDate: item.date_start,
          endDate: item.date_stop,
        };
      });

      if (cursor.hasNext()) {
        await cursor.next();
      } else {
        break;
      }
    }
  }

Maybe next method will work too

  public async fetchInsights({
    fields,
    params,
  }: {
    fields: string[];
    params: Record<string, string>;
  }): Promise<Insight[]> {
    const result: Insight[] = []
    const cursor = await this.fbAdAccount.getInsights(fields, params);

    while (true) {
      for (const item of cursor) {
        result.push({
          adId: item.ad_id,
          adName: item.ad_name,
          adSetId: item.adset_id,
          // ...
          startDate: item.date_start,
          endDate: item.date_stop,
        });
      }

      if (cursor.hasNext()) {
        await cursor.next();
      } else {
        break;
      }
    }

    return result;
  }