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

Develop #58

Merged
merged 22 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0b6dff7
chore: bump version for @grpc/grpc-js and protobufjs
htdangkhoa Mar 27, 2024
eaa8f8b
chore: bump version for typescript and @types/node
htdangkhoa Mar 27, 2024
7b1777a
chore: bump version for ts-node
htdangkhoa Mar 27, 2024
0d10016
chore: bump version for googleapis
htdangkhoa Mar 27, 2024
e288e37
chore: bump version for ts-proto
htdangkhoa Mar 27, 2024
3234054
chore: remove dotenv
htdangkhoa Mar 27, 2024
7a0dcf9
chore: bump version for ts-jest & @types/jest
htdangkhoa Mar 27, 2024
833f2d5
chore: unsupport node v14
htdangkhoa Mar 27, 2024
f282de6
chore: update yarn.lock
htdangkhoa Mar 27, 2024
bbe4025
chore: update README.md
htdangkhoa Mar 27, 2024
f0dc9b8
feat: create LICENSE file
htdangkhoa Mar 27, 2024
947767c
chore: update README.md
htdangkhoa Mar 27, 2024
67f06bd
Merge branches 'main' and 'develop' of https://github.com/htdangkhoa/…
htdangkhoa Apr 17, 2024
8c9c7ad
feat: add decodePartialFailureError function (#29)
htdangkhoa Apr 21, 2024
525d8f6
feat: add test report to github actions by using dorny/test-reporter
htdangkhoa Apr 22, 2024
f651bb0
feat: esm build
htdangkhoa Jun 19, 2024
3368353
chore: bump version of the dependencies
htdangkhoa Jun 19, 2024
0aaa835
feat: support google ads v17
htdangkhoa Jun 19, 2024
e7341a0
chore: drop support node 16 and support node 22
htdangkhoa Jun 19, 2024
16002a1
chore: update version of action images
htdangkhoa Jun 19, 2024
0bc282e
Merge pull request #56 from htdangkhoa/feature/google-ads-v17
htdangkhoa Jun 19, 2024
189e6cd
Merge pull request #57 from htdangkhoa/feature/esm
htdangkhoa Jun 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
environment: production
permissions: write-all
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Download build artifact
uses: actions/download-artifact@v3
Expand All @@ -38,7 +38,7 @@ jobs:
path: build

- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ jobs:
name: Generate google ads api ${{ inputs.google-ads-api-version }} for Node ${{ inputs.node-version }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install protobuf-compiler
run: |
sudo apt-get update -y
sudo apt-get install protobuf-compiler -y

- name: Setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
cache: 'yarn'
Expand All @@ -50,6 +50,14 @@ jobs:
if: ${{ inputs.test }}
run: yarn test

- name: Test report with Node ${{ inputs.node-version }} and Google Ads API ${{ inputs.google-ads-api-version }}
uses: dorny/test-reporter@v1
if: ${{ inputs.test }} && always()
with:
name: Test report with Node ${{ inputs.node-version }} and Google Ads API ${{ inputs.google-ads-api-version }}
path: junit.xml
reporter: jest-junit

- name: Write COVERALLS_TOKEN to .coveralls.yml
if: ${{ inputs.test }}
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
needs: export-google-ads-api-version
strategy:
matrix:
node: [16, 18, 20]
node: [18, 20, 22]
uses: ./.github/workflows/template.yml
with:
node-version: ${{ matrix.node }}
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,6 @@ build

generated

googleapis
googleapis

junit.xml
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<h1 align="center">Google Ads API Nodejs Client Library</h1>

<p align="center">
<a href="https://developers.google.com/google-ads/api/docs/release-notes#v16">
<img src="https://img.shields.io/badge/google%20ads-v16-009688.svg?style=flat-square">
<a href="https://developers.google.com/google-ads/api/docs/release-notes#v17">
<img src="https://img.shields.io/badge/google%20ads-v17-009688.svg?style=flat-square">
</a>
<a href="https://www.npmjs.com/package/@htdangkhoa/google-ads">
<img src="https://img.shields.io/npm/v/@htdangkhoa/google-ads.svg?style=flat-square">
Expand Down Expand Up @@ -317,7 +317,7 @@ See more at [Node.js gRPC Library](https://grpc.github.io/grpc/node/module-src_c
yarn generate <GOOGLE_ADS_API_VERSION>

# example
yarn generate v16
yarn generate v17
```
3. Make sure the version number in the `src` folder is correct (it should match the version number you passed to the `generate` command)

Expand Down
4 changes: 2 additions & 2 deletions example/ad-group-ad.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { google } from 'googleapis';

import { GoogleAds } from '../src/lib';
import { AdTextAsset } from '../src/generated/google/ads/googleads/v16/common/ad_asset';
import { AdGroupAdStatusEnum_AdGroupAdStatus } from '../src/generated/google/ads/googleads/v16/enums/ad_group_ad_status';
import { AdTextAsset } from '../src/generated/google/ads/googleads/v17/common/ad_asset';
import { AdGroupAdStatusEnum_AdGroupAdStatus } from '../src/generated/google/ads/googleads/v17/enums/ad_group_ad_status';

const authClient = new google.auth.JWT({
keyFile: process.env.GOOGLE_APPLICATION_CREDENTIALS,
Expand Down
4 changes: 2 additions & 2 deletions example/ad-group.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { google } from 'googleapis';

import { GoogleAds } from '../src/lib';
import { AdGroupStatusEnum_AdGroupStatus } from '../src/generated/google/ads/googleads/v16/enums/ad_group_status';
import { AdGroupTypeEnum_AdGroupType } from '../src/generated/google/ads/googleads/v16/enums/ad_group_type';
import { AdGroupStatusEnum_AdGroupStatus } from '../src/generated/google/ads/googleads/v17/enums/ad_group_status';
import { AdGroupTypeEnum_AdGroupType } from '../src/generated/google/ads/googleads/v17/enums/ad_group_type';

const authClient = new google.auth.JWT({
keyFile: process.env.GOOGLE_APPLICATION_CREDENTIALS,
Expand Down
4 changes: 2 additions & 2 deletions example/asset.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { google } from 'googleapis';

import { GoogleAds } from '../src/lib';
import { Asset } from '../src/generated/google/ads/googleads/v16/resources/asset';
import { MutateOperation } from '../src/generated/google/ads/googleads/v16/services/google_ads_service';
import { Asset } from '../src/generated/google/ads/googleads/v17/resources/asset';
import { MutateOperation } from '../src/generated/google/ads/googleads/v17/services/google_ads_service';

const authClient = new google.auth.JWT({
keyFile: process.env.GOOGLE_APPLICATION_CREDENTIALS,
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ module.exports = {
],
testPathIgnorePatterns: ['/node_modules/', '/build/'],
testTimeout: 20000,
reporters: ['default', 'jest-junit'],
};
38 changes: 24 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,47 @@
"[email protected]"
],
"license": "MIT",
"main": "build/lib/index.js",
"main": "dist/cjs/lib/index.js",
"module": "dist/esm/lib/index.js",
"files": [
"build/lib",
"build/generated"
"dist"
],
"exports": {
"./package.json": "./package.json",
".": {
"import": "./dist/esm/lib/index.js",
"require": "./dist/cjs/lib/index.js"
}
},
"scripts": {
"test": "jest --runInBand --no-cache",
"test:cov": "npm run test && coveralls < coverage/lcov.info",
"prebuild": "rimraf build",
"prebuild": "rimraf dist",
"build": "tsc",
"postbuild": "esm2cjs --in dist/esm --out dist/cjs -l error",
"generate": "./scripts/generate.sh"
},
"dependencies": {
"@grpc/grpc-js": "^1.10.4",
"@grpc/grpc-js": "^1.10.9",
"deepmerge": "^4.3.1",
"log4js": "^6.9.1",
"protobufjs": "^7.2.6"
"protobufjs": "^7.3.2"
},
"devDependencies": {
"@alcalzone/esm2cjs": "^1.1.2",
"@types/glob": "^8.1.0",
"@types/jest": "^29.5.12",
"@types/node": "^20.11.30",
"coveralls-next": "^4.2.0",
"glob": "^10.3.10",
"googleapis": "^134.0.0",
"@types/node": "^20.14.5",
"coveralls-next": "^4.2.1",
"glob": "^10.4.2",
"googleapis": "^140.0.0",
"jest": "^29.7.0",
"rimraf": "^5.0.5",
"ts-jest": "^29.1.2",
"jest-junit": "^16.0.0",
"rimraf": "^5.0.7",
"ts-jest": "^29.1.5",
"ts-node": "^10.9.2",
"ts-proto": "^1.170.0",
"typescript": "5.4.3"
"ts-proto": "^1.180.0",
"typescript": "5.4.5"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Customer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CustomerServiceClient } from '../generated/google';
import {
ListAccessibleCustomersRequest,
ListAccessibleCustomersResponse,
} from '../generated/google/ads/googleads/v16/services/customer_service';
} from '../generated/google/ads/googleads/v17/services/customer_service';

export class Customer extends Service {
protected get callMetadata(): Metadata {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/GoogleAds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
SearchGoogleAdsStreamResponse,
MutateGoogleAdsRequest,
MutateGoogleAdsResponse,
} from '../generated/google/ads/googleads/v16/services/google_ads_service';
} from '../generated/google/ads/googleads/v17/services/google_ads_service';

export class GoogleAds extends Service {
private customerOptions: CustomerOptions;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const HOST = 'googleads.googleapis.com' as const;

export const VERSION = 'v16' as const;
export const VERSION = 'v17' as const;

export const FAILURE_KEY = `google.ads.googleads.${VERSION}.errors.googleadsfailure-bin`;
27 changes: 26 additions & 1 deletion src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { credentials, OAuth2Client, ServiceError } from '@grpc/grpc-js';
import { GoogleAdsFailure } from '../generated/google/ads/googleads/v16/errors/errors';
import { GoogleAdsFailure } from '../generated/google/ads/googleads/v17/errors/errors';
import { FAILURE_KEY } from './constants';
import { MutateGoogleAdsResponse } from '../generated/google/ads/googleads/v17/services/google_ads_service';

export const getCredentials = (authClient: OAuth2Client) => {
const ssl = credentials.createSsl();
Expand Down Expand Up @@ -34,3 +35,27 @@ export const getGoogleAdsError = (

return decodeGoogleAdsFailureBuffer(buffer);
};

export const decodePartialFailureError = (
response: MutateGoogleAdsResponse,
) => {
if (!response.partial_failure_error) return response;

const { details } = response.partial_failure_error;

if (!details) return response;

const { value } =
details.find((detail) =>
detail.type_url?.includes('errors.GoogleAdsFailure'),
) ?? {};

if (!value) return response;

const buffer = Buffer.from(value);

return {
...response,
partial_failure_error: decodeGoogleAdsFailureBuffer(buffer),
};
};
Loading
Loading