Socket
Socket
Sign inDemoInstall

fb-graph

Package Overview
Dependencies
47
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.1 to 2.0.2

4

dist/constants.d.ts

@@ -6,3 +6,5 @@ export declare type GetArrayElementType<T extends readonly any[]> = T extends readonly (infer U)[] ? U : never;

export declare const BREAKDOWNS: readonly ["app_store_clicks", "newsfeed_avg_position", "newsfeed_clicks", "relevance_score", "newsfeed_impressions"];
export declare const FIELDS: readonly ["adset_id", "adset_name", "campaign_name", "campaign_id", "account_id", "account_name", "spend", "clicks", "imporessions", "reach", "unique_clicks", "actions", "action_values", "device_platform"];
export declare const DIMENSION_FIELDS: readonly ["account_id", "account_name", "campaign_name", "campaign_id", "adset_id", "adset_name", "ad_id", "ad_name", "attribution_setting", "buying_type", "canvas_avg_view_percent", "canvas_avg_view_time", "catalog_segment_value", "conversion_rate_ranking", "objective"];
export declare const NUMERIC_FIELDS: readonly ["outbound_clicks", "unique_actions", "full_view_impressions", "inline_post_engagement", "spend", "clicks", "impressions", "reach", "unique_clicks", "actions", "action_values", "device_platform"];
export declare const FIELDS: readonly ["account_id", "account_name", "campaign_name", "campaign_id", "adset_id", "adset_name", "ad_id", "ad_name", "attribution_setting", "buying_type", "canvas_avg_view_percent", "canvas_avg_view_time", "catalog_segment_value", "conversion_rate_ranking", "objective", "outbound_clicks", "unique_actions", "full_view_impressions", "inline_post_engagement", "spend", "clicks", "impressions", "reach", "unique_clicks", "actions", "action_values", "device_platform"];
export interface FbAPIAuth {

@@ -9,0 +11,0 @@ accessToken: string;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AttributionWindow = exports.Level = exports.FIELDS = exports.BREAKDOWNS = exports.GRAPH_VIDEO_DOMAIN = exports.GRAPH_DOMAIN = exports.GRAPH_VERSION = void 0;
exports.AttributionWindow = exports.Level = exports.FIELDS = exports.NUMERIC_FIELDS = exports.DIMENSION_FIELDS = exports.BREAKDOWNS = exports.GRAPH_VIDEO_DOMAIN = exports.GRAPH_DOMAIN = exports.GRAPH_VERSION = void 0;
exports.GRAPH_VERSION = 'v9.0';
exports.GRAPH_DOMAIN = 'https://graph.facebook.com';
exports.GRAPH_VIDEO_DOMAIN = 'https://graph-video.facebook.com';
// https://developers.facebook.com/docs/marketing-api/insights/parameters#fields
exports.BREAKDOWNS = [
'app_store_clicks', 'newsfeed_avg_position', 'newsfeed_clicks', 'relevance_score', 'newsfeed_impressions'
];
exports.FIELDS = [
'adset_id', 'adset_name', 'campaign_name', 'campaign_id', 'account_id', 'account_name',
'spend', 'clicks', 'imporessions',
exports.DIMENSION_FIELDS = [
'account_id', 'account_name',
'campaign_name', 'campaign_id',
'adset_id', 'adset_name',
'ad_id', 'ad_name',
'attribution_setting', 'buying_type',
'canvas_avg_view_percent', 'canvas_avg_view_time',
'catalog_segment_value', 'conversion_rate_ranking',
'objective',
];
exports.NUMERIC_FIELDS = [
'outbound_clicks', 'unique_actions',
'full_view_impressions', 'inline_post_engagement',
'spend', 'clicks', 'impressions',
'reach', 'unique_clicks', 'actions', 'action_values',
'device_platform'
];
exports.FIELDS = [
...exports.DIMENSION_FIELDS,
...exports.NUMERIC_FIELDS
];
var Level;

@@ -17,0 +33,0 @@ (function (Level) {

/// <reference types="node" />
import { Readable } from 'stream';
import Emitter from 'events';
import { AsyncStatus } from './core';
import { FbAPIAuth, CreateReportParams, ReportRow } from './constants';
export default class FbAdsInsights extends Emitter {
interface EventComplete {
event: 'COMPLETE' | 'LIMIT_REACHED';
totalRows: number;
}
declare type EventProgress = {
event: 'CREATED';
reportId: string;
} | (AsyncStatus & {
event: 'CHECKED';
});
export declare interface FbAdsInsights<RowT extends ReportRow = ReportRow> {
on(event: 'progress', listener: (event: EventProgress) => void): this;
on(event: 'data', listener: (row: RowT) => void): this;
on(event: 'complete', listener: (event: EventComplete) => void): this;
on(event: 'error', listener: (error: Error) => void): this;
on(event: string, listener: (event: any) => void): this;
}
export declare class FbAdsInsights<RowT extends ReportRow = ReportRow> extends Readable {
auth: FbAPIAuth;

@@ -13,8 +29,10 @@ params: CreateReportParams;

_limit: number;
_started: boolean;
constructor(auth: FbAPIAuth, params: CreateReportParams);
limit(i: number): this;
prepare(): Promise<string>;
stream<T extends ReportRow>(): Readable;
get<T extends ReportRow>(): Promise<T[]>;
generator<T extends ReportRow>(): AsyncGenerator<T, void, unknown>;
_read(): Promise<void>;
get<T extends RowT>(): Promise<T[]>;
generator<T extends RowT>(): AsyncGenerator<T, void, unknown>;
}
export {};

@@ -32,12 +32,10 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FbAdsInsights = void 0;
const stream_1 = require("stream");
const events_1 = __importDefault(require("events"));
const core_1 = require("./core");
class FbAdsInsights extends events_1.default {
class FbAdsInsights extends stream_1.Readable {
constructor(auth, params) {
super();
super({ objectMode: true });
this._started = false;
this.auth = auth;

@@ -81,34 +79,32 @@ this.params = params;

}
stream() {
const stream = new stream_1.Readable({
objectMode: true,
read: async () => {
(async () => {
var e_2, _a;
try {
for (var _b = __asyncValues(this.generator()), _c; _c = await _b.next(), !_c.done;) {
const row = _c.value;
if (!stream.push(row)) {
await new Promise((resolve) => stream.once("drain", resolve));
}
}
async _read() {
this._started = true;
(async () => {
var e_2, _a;
try {
for (var _b = __asyncValues(this.generator()), _c; _c = await _b.next(), !_c.done;) {
const row = _c.value;
if (!this.push(row)) {
await new Promise((resolve) => this.once("drain", resolve));
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) await _a.call(_b);
}
finally { if (e_2) throw e_2.error; }
}
stream.push(null);
})().catch(e => {
console.log(e, 'ERROR');
stream.emit('error', e);
});
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) await _a.call(_b);
}
finally { if (e_2) throw e_2.error; }
}
this.push(null);
})().catch(e => {
this.emit('error', e);
});
return stream;
}
async get() {
var e_3, _a;
if (this._started) {
throw new Error('Report already called');
}
this._started = true;
const rows = [];

@@ -133,2 +129,6 @@ try {

var e_4, _a;
if (this._started) {
throw new Error('Report already called');
}
this._started = true;
const { auth } = this;

@@ -167,2 +167,2 @@ const { pageSize } = this.params;

}
exports.default = FbAdsInsights;
exports.FbAdsInsights = FbAdsInsights;
import { FBAPICallParams } from './core';
import { CreateReportParams, ReportParams, FbAPIAuth, AttributionWindow, Level } from './constants';
import FbAdsInsights from './FbAdsInsights';
import { FbAdsInsights } from './FbAdsInsights';
import { flattenActions, parseUserInputsToParams } from './tools';

@@ -31,3 +31,3 @@ export { FBAPICallParams, FbAdsInsights, flattenActions, parseUserInputsToParams, CreateReportParams, ReportParams };

});
insights(params: CreateReportParams): FbAdsInsights;
insights(params: CreateReportParams): FbAdsInsights<import("./constants").ReportRow>;
callAPI<T>(params: FBAPICallParams): Promise<T>;

@@ -34,0 +34,0 @@ page<T>(url: string): Promise<T>;

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -9,4 +6,4 @@ exports.FacebookAds = exports.getExchangeToken = exports.enums = exports.parseUserInputsToParams = exports.flattenActions = exports.FbAdsInsights = void 0;

const constants_1 = require("./constants");
const FbAdsInsights_1 = __importDefault(require("./FbAdsInsights"));
exports.FbAdsInsights = FbAdsInsights_1.default;
const FbAdsInsights_1 = require("./FbAdsInsights");
Object.defineProperty(exports, "FbAdsInsights", { enumerable: true, get: function () { return FbAdsInsights_1.FbAdsInsights; } });
const tools_1 = require("./tools");

@@ -35,3 +32,3 @@ Object.defineProperty(exports, "flattenActions", { enumerable: true, get: function () { return tools_1.flattenActions; } });

insights(params) {
return new FbAdsInsights_1.default(this.auth, params);
return new FbAdsInsights_1.FbAdsInsights(this.auth, params);
}

@@ -38,0 +35,0 @@ callAPI(params) {

@@ -9,3 +9,2 @@ "use strict";

exports.wait = wait;
const VAL_REG = /(impressions|clicks|reach|value|spend)/i;
function flattenActions(data, customEventMap = {}, actionsList = [], attriList) {

@@ -36,3 +35,3 @@ const attributionWindowList = attriList || Object.values(constants_1.AttributionWindow);

const value = ob;
if (VAL_REG.test(el)) {
if (constants_1.NUMERIC_FIELDS.includes(el)) {
row[el] = parseFloat(value);

@@ -39,0 +38,0 @@ return;

{
"name": "fb-graph",
"version": "2.0.1",
"version": "2.0.2",
"description": "For Facebook graph API and Marketing Api, with normalised querying and responses",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -60,8 +60,8 @@ # fb-graph

const reportStream = fb.insights({
const report = fb.insights({
accountId:'act_12345677898765',
...params
}).stream()
})
reportStream.on('data',function(row){
report.on('data',function(row){
console.log(row)

@@ -68,0 +68,0 @@ }).on('complete',function(metaData){

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc