Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
@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
The npm package @dmgt/google-ad-manager-api receives a total of 427 weekly downloads. As such, @dmgt/google-ad-manager-api popularity was classified as not popular.
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
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.