Skip to content

Commit

Permalink
Merge pull request #86 from htdangkhoa/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
htdangkhoa authored Oct 4, 2024
2 parents 0f2f8cb + ef524e7 commit 1705330
Show file tree
Hide file tree
Showing 44 changed files with 1,399 additions and 2,423 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
deployments: write
steps:
- name: Delete previous deployments
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
script: |
const { data: deployments } = await github.rest.repos.listDeployments({
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:

- name: Test
if: ${{ inputs.test }}
run: yarn test
run: yarn test --coverage

- name: Write COVERALLS_TOKEN to .coveralls.yml
if: ${{ inputs.test }}
Expand All @@ -62,10 +62,10 @@ jobs:
- name: Coveralls
if: ${{ inputs.test }}
uses: pmienk/coveralls-github-action@master
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: ${{matrix.os}}-node-${{ matrix.node }}
flag-name: node-${{ inputs.node-version }}
parallel: true

- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Coveralls finished
uses: pmienk/coveralls-github-action@master
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ dist

sa.json

build

.DS_Store

generated
Expand Down
27 changes: 25 additions & 2 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#v17">
<img src="https://img.shields.io/badge/google%20ads-v17-009688.svg?style=flat-square">
<a href="https://developers.google.com/google-ads/api/docs/release-notes#v1710_2024-08-07">
<img src="https://img.shields.io/badge/google%20ads-v17.1.0%202024--08--07-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 @@ -296,6 +296,29 @@ const service = new GoogleAds(

See more at [Node.js gRPC Library](https://grpc.github.io/grpc/node/module-src_client_interceptors.html) and some examples [here](https://github.com/grpc/proposal/blob/master/L5-node-client-interceptors.md).

## Bonus

### Type helper

If you are using the generated types from the protos, you may run into an issue where the types are referring to values instead of types or missing the following properties from types. You can use the following helper to fix this issue.

```ts
import { ads, MessageType, MessageFnsKeys } from '@htdangkhoa/google-ads';

const {
services: { GoogleAdsRow },
} = ads.googleads.v17;

const row: MessageType<typeof GoogleAdsRow> = {
// ... properties
};

// or
const row: Omit<typeof GoogleAdsRow, MessageFnsKeys> = {
// ... properties
};
```

## Development

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

import { GoogleAds } from '../src/lib';
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';
import { GoogleAds, ads, MessageType } from '../src';

const {
common: { AdTextAsset },
enums: { AdGroupAdStatusEnum_AdGroupAdStatus },
} = ads.googleads.v17;

const authClient = new google.auth.JWT({
keyFile: process.env.GOOGLE_APPLICATION_CREDENTIALS,
Expand All @@ -14,8 +17,8 @@ export async function createAdGroupAdApp(
customer_id: string,
login_customer_id: string,
ad_group_resource: string,
headlines: AdTextAsset[],
descriptions: AdTextAsset[],
headlines: MessageType<typeof AdTextAsset>[],
descriptions: MessageType<typeof AdTextAsset>[],
) {
const service = new GoogleAds(
{
Expand Down
8 changes: 5 additions & 3 deletions example/ad-group.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { google } from 'googleapis';

import { GoogleAds } from '../src/lib';
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';
import { GoogleAds, ads } from '../src';

const {
enums: { AdGroupStatusEnum_AdGroupStatus, AdGroupTypeEnum_AdGroupType },
} = ads.googleads.v17;

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

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

const {
resources: { Asset },
services: { MutateOperation },
} = ads.googleads.v17;

const authClient = new google.auth.JWT({
keyFile: process.env.GOOGLE_APPLICATION_CREDENTIALS,
Expand All @@ -13,7 +16,7 @@ const authClient = new google.auth.JWT({
export async function uploadAsset(
customer_id: string,
login_customer_id: string,
assets: Asset[],
assets: MessageType<typeof Asset>[],
) {
const service = new GoogleAds(
{
Expand All @@ -26,11 +29,13 @@ export async function uploadAsset(
},
);

const mutate_operations: MutateOperation[] = assets.map((asset) => ({
asset_operation: {
create: asset,
},
}));
const mutate_operations: MessageType<typeof MutateOperation>[] = assets.map(
(asset) => ({
asset_operation: {
create: asset,
},
}),
);

try {
const { mutate_operation_responses, partial_failure_error } =
Expand Down
2 changes: 1 addition & 1 deletion example/campaign.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { google } from 'googleapis';

import { GoogleAds } from '../src/lib';
import { GoogleAds } from '../src';

const authClient = new google.auth.JWT({
keyFile: process.env.GOOGLE_APPLICATION_CREDENTIALS,
Expand Down
2 changes: 1 addition & 1 deletion example/search.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { google } from 'googleapis';
import { Customer, GoogleAds, QueryBuilder } from '../src/lib';
import { Customer, GoogleAds, QueryBuilder } from '../src';

const authClient = new google.auth.JWT({
keyFile: process.env.GOOGLE_APPLICATION_CREDENTIALS,
Expand Down
16 changes: 0 additions & 16 deletions jest.config.js

This file was deleted.

69 changes: 44 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,65 @@
"contributors": [
"[email protected]"
],
"keywords": [
"google",
"ads",
"api",
"node",
"google ads api",
"google ads",
"google ads nodejs",
"google ads js",
"ads node",
"grpc",
"proto",
"sdk"
],
"license": "MIT",
"main": "build/lib/index.js",
"type": "module",
"exports": {
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js",
"default": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts"
}
},
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
"files": [
"build/lib",
"build/generated"
"dist"
],
"scripts": {
"test": "jest --runInBand --no-cache",
"test:cov": "npm run test && coveralls < coverage/lcov.info",
"prebuild": "rimraf build",
"build": "tsc",
"test": "vitest",
"test:cov": "vitest --coverage && coveralls < coverage/lcov.info",
"prebuild": "rm -rf dist",
"build": "npm run build:esm && npm run build:cjs && npm run build:types",
"build:esm": "node scripts/build/esm.mjs",
"build:cjs": "node scripts/build/cjs.mjs",
"build:types": "node scripts/build/types.mjs",
"generate": "./scripts/generate.sh"
},
"dependencies": {
"@grpc/grpc-js": "^1.10.9",
"@bufbuild/protobuf": "^2.1.0",
"@grpc/grpc-js": "^1.12.0",
"deepmerge": "^4.3.1",
"log4js": "^6.9.1",
"protobufjs": "^7.3.2"
"log4js": "^6.9.1"
},
"devDependencies": {
"@types/glob": "^8.1.0",
"@types/jest": "^29.5.12",
"@types/node": "^20.11.30",
"@types/node": "^22.7.4",
"@vitest/coverage-v8": "^2.1.2",
"coveralls-next": "^4.2.0",
"glob": "^10.3.10",
"googleapis": "^134.0.0",
"jest": "^29.7.0",
"jest-junit": "^16.0.0",
"rimraf": "^5.0.5",
"string-width": "^4.2.0",
"ts-jest": "^29.1.2",
"fast-glob": "^3.3.2",
"googleapis": "^144.0.0",
"ts-node": "^10.9.2",
"ts-proto": "^1.170.0",
"typescript": "5.4.3"
"ts-proto": "^2.2.2",
"typescript": "5.6.2",
"vitest": "^2.1.2"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
},
"resolutions": {
"string-width": "^4.2.0"
}
}
14 changes: 14 additions & 0 deletions scripts/build/cjs.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { execSync } from 'child_process';

async function build() {
try {
execSync('tsc --project tsconfig.cjs.json', { stdio: 'inherit' });
execSync(`echo '{"type": "commonjs"}' > dist/cjs/package.json`, {
stdio: 'inherit',
});
} catch (error) {
throw error;
}
}

build();
32 changes: 32 additions & 0 deletions scripts/build/esm.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as path from 'path';
import * as fs from 'fs';
import { execSync } from 'child_process';

async function build() {
// const indexFile = path.resolve(process.cwd(), 'src', 'lib', 'index.ts');

// const indexContent = fs.readFileSync(indexFile, 'utf-8');

// const requirePolyfill = `
// import { createRequire } from 'module';
// const require = createRequire(import.meta.url);
// global.require = require;
// `;

// const esmIndexContent = requirePolyfill + indexContent;

// fs.writeFileSync(indexFile, esmIndexContent);

try {
execSync('tsc --project tsconfig.esm.json', { stdio: 'inherit' });
execSync(`echo '{"type": "module"}' > dist/esm/package.json`, {
stdio: 'inherit',
});
} catch (error) {
throw error;
} finally {
// fs.writeFileSync(indexFile, indexContent);
}
}

build();
14 changes: 14 additions & 0 deletions scripts/build/types.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { execSync } from 'child_process';

async function build() {
try {
execSync('tsc --project tsconfig.types.json', { stdio: 'inherit' });
// execSync(`echo '{"type": "commonjs"}' > dist/cjs/package.json`, {
// stdio: 'inherit',
// });
} catch (error) {
throw error;
}
}

build();
25 changes: 0 additions & 25 deletions scripts/export-client.js

This file was deleted.

Loading

0 comments on commit 1705330

Please sign in to comment.