Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@dmgt/google-ad-manager-api
Advanced tools
A fully typed library to access Google's Ad Manager.
npm install google-auth-library @dmgt/google-ad-manager-api
import {
GoogleAdManager,
In,
Not,
Like,
getByStatement,
} from '@dmgt/google-ad-manager-api'
import { JWT } from 'google-auth-lbrary'
const jwt = new JWT({
key: 'MY_JWT_KEY',
email: 'MY_JWT_EMAIL',
scopes: ['https://www.googleapis.com/auth/dfp'],
})
const api = new GoogleAdManager({
applicationName: 'MY_APPLICATION_NAME',
networkCode: 123456789,
authorize: () => jwt.authorize(),
})
const client = await api.createLineItemServiceClient()
const [response] = await getByStatement(client, 'lineItems', {
limit: 10,
where: {
orderId: In(1, 2, 3),
id: Not(11222),
name: Like('foo %'),
orderName: 'Foo',
},
})
expect(response.rval?.results).toHaveLength(10)
The following will produce the same result albeit more verbose:
import {
LineItemService,
In,
Not,
Like,
pql,
} from '@dmgt/google-ad-manager-api'
const [response] = await client.getLineItemsByStatementAsync({
filterStatement: {
query: pql<LineItemService.LineItems>({
limit: 10,
where: {
orderId: In(1, 2, 3),
id: Not(11222),
name: Like('foo %'),
orderName: 'Foo',
},
}),
},
})
You can also type the pql
function with JSDocs:
/**
* @typedef {import('@dmgt/google-ad-manager-api').PQL<
* import('@dmgt/google-ad-manager-api').LineItemService.LineItems
* >} LineItemsPQL
*/
const [response] = await client.getLineItemsByStatementAsync({
filterStatement: {
query: /** @type {LineItemsPQL} */ (pql)({
limit: 10,
where: {
orderId: In(1, 2, 3),
id: Not(11222),
name: Like('foo %'),
orderName: 'Foo',
},
}),
},
})
When quering large amounts of data, you'd generally want to use GAM's pagination feature. Use the iterate
function to help iterate through all individual items in paginated queries.
import {
GoogleAdManager,
iterate,
getByStatement,
} from '@dmgt/google-ad-manager-api'
import { JWT } from 'google-auth-lbrary'
const jwt = new JWT({
key: 'MY_JWT_KEY',
email: 'MY_JWT_EMAIL',
scopes: ['https://www.googleapis.com/auth/dfp'],
})
const api = new GoogleAdManager({
applicationName: 'MY_APPLICATION_NAME',
networkCode: 123456789,
authorize: () => jwt.authorize(),
})
const client = await api.createLineItemServiceClient()
for await (const result of iterate({
executeQuery: (limit, offset) =>
getByStatement(client, 'lineItems', {
limit,
offset,
}),
})) {
console.info(result)
}
FAQs
Typed Google Ad Manager API
We found that @dmgt/google-ad-manager-api demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.