google-ads-api 24.1.0 → 25.1.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +9 -1
  2. package/build/{src → cjs}/client.d.ts +6 -4
  3. package/build/{src → cjs}/client.js +4 -4
  4. package/build/{src → cjs}/customer.d.ts +5 -5
  5. package/build/{src → cjs}/customer.js +24 -20
  6. package/build/{src → cjs}/hooks.d.ts +2 -2
  7. package/build/cjs/index.d.ts +9 -0
  8. package/build/{src → cjs}/index.js +22 -20
  9. package/build/{src → cjs}/parser.d.ts +2 -2
  10. package/build/{src → cjs}/parser.js +5 -5
  11. package/build/{src → cjs}/parserRest.js +7 -7
  12. package/build/{src → cjs}/protos/autogen/enums.d.ts +1679 -1180
  13. package/build/{src → cjs}/protos/autogen/enums.js +1696 -1177
  14. package/build/cjs/protos/autogen/fields.d.ts +1191 -0
  15. package/build/cjs/protos/autogen/fields.js +205 -0
  16. package/build/cjs/protos/autogen/resourceNames.d.ts +1668 -0
  17. package/build/cjs/protos/autogen/resourceNames.js +1669 -0
  18. package/build/{src → cjs}/protos/autogen/serviceFactory.d.ts +206 -215
  19. package/build/{src → cjs}/protos/autogen/serviceFactory.js +483 -554
  20. package/build/cjs/protos/index.d.ts +14 -0
  21. package/build/{src → cjs}/protos/index.js +12 -12
  22. package/build/{src → cjs}/query.d.ts +2 -2
  23. package/build/{src → cjs}/query.js +5 -5
  24. package/build/{src → cjs}/service.d.ts +5 -5
  25. package/build/{src → cjs}/service.js +64 -22
  26. package/build/{src → cjs}/types.d.ts +1 -1
  27. package/build/{src → cjs}/utils.d.ts +1 -1
  28. package/build/{src → cjs}/utils.js +2 -2
  29. package/build/cjs/version.d.ts +1 -0
  30. package/build/{src → cjs}/version.js +1 -1
  31. package/build/esm/client.d.ts +19 -0
  32. package/build/esm/client.js +40 -0
  33. package/build/esm/customer.d.ts +71 -0
  34. package/build/esm/customer.js +502 -0
  35. package/build/esm/hooks.d.ts +160 -0
  36. package/build/esm/hooks.js +1 -0
  37. package/build/esm/index.d.ts +9 -0
  38. package/build/esm/index.js +10 -0
  39. package/build/esm/package.json +1 -0
  40. package/build/esm/parser.d.ts +21 -0
  41. package/build/esm/parser.js +113 -0
  42. package/build/esm/parserRest.d.ts +1 -0
  43. package/build/esm/parserRest.js +112 -0
  44. package/build/esm/protos/autogen/enums.d.ts +6002 -0
  45. package/build/esm/protos/autogen/enums.js +6401 -0
  46. package/build/esm/protos/autogen/fields.d.ts +1191 -0
  47. package/build/esm/protos/autogen/fields.js +202 -0
  48. package/build/esm/protos/autogen/resourceNames.d.ts +1668 -0
  49. package/build/esm/protos/autogen/resourceNames.js +1475 -0
  50. package/build/esm/protos/autogen/serviceFactory.d.ts +1825 -0
  51. package/build/esm/protos/autogen/serviceFactory.js +18795 -0
  52. package/build/esm/protos/index.d.ts +14 -0
  53. package/build/esm/protos/index.js +19 -0
  54. package/build/esm/query.d.ts +62 -0
  55. package/build/esm/query.js +304 -0
  56. package/build/esm/service.d.ts +47 -0
  57. package/build/esm/service.js +222 -0
  58. package/build/esm/types.d.ts +75 -0
  59. package/build/esm/types.js +14 -0
  60. package/build/esm/utils.d.ts +49 -0
  61. package/build/esm/utils.js +108 -0
  62. package/build/esm/version.d.ts +1 -0
  63. package/build/esm/version.js +1 -0
  64. package/package.json +50 -11
  65. package/build/src/index.d.ts +0 -8
  66. package/build/src/protos/autogen/fields.d.ts +0 -1122
  67. package/build/src/protos/autogen/fields.js +0 -644
  68. package/build/src/protos/autogen/resourceNames.d.ts +0 -1609
  69. package/build/src/protos/autogen/resourceNames.js +0 -1982
  70. package/build/src/protos/index.d.ts +0 -14
  71. package/build/src/testUtils.d.ts +0 -107
  72. package/build/src/testUtils.js +0 -333
  73. package/build/src/version.d.ts +0 -1
  74. /package/build/{src → cjs}/hooks.js +0 -0
  75. /package/build/{src → cjs}/parserRest.d.ts +0 -0
  76. /package/build/{src → cjs}/types.js +0 -0
@@ -0,0 +1,75 @@
1
+ import { services, fields } from "./protos/index.js";
2
+ export interface CustomerOptions {
3
+ customer_id: string;
4
+ refresh_token: string;
5
+ login_customer_id?: string;
6
+ linked_customer_id?: string;
7
+ }
8
+ export type CustomerCredentials = Pick<CustomerOptions, "customer_id" | "login_customer_id" | "linked_customer_id">;
9
+ export interface ReportOptions extends RequestOptions {
10
+ entity: fields.Resource;
11
+ attributes?: fields.Attributes;
12
+ metrics?: fields.Metrics;
13
+ segments?: fields.Segments;
14
+ constraints?: Constraints;
15
+ parameters?: string;
16
+ limit?: number;
17
+ order?: Order[];
18
+ /**
19
+ * @deprecated `order_by` will be removed in a future version. Migration to the `order` report option key is advised.
20
+ */
21
+ order_by?: ConstraintKey | ConstraintKey[];
22
+ /**
23
+ * @deprecated `sort_order` will be removed in a future version. Migration to the `order` report option key is advised.
24
+ */
25
+ sort_order?: SortOrder;
26
+ date_constant?: DateConstant;
27
+ from_date?: string;
28
+ to_date?: string;
29
+ }
30
+ /**
31
+ * Add back optional return_total_results_count as it is still a valid request option
32
+ */
33
+ type SearchSettingsWithOptionalTotalCount = {
34
+ search_settings?: Pick<services.ISearchSettings, "return_total_results_count" | "return_summary_row">;
35
+ };
36
+ /**
37
+ * Request Options with optional total count in search_settings
38
+ */
39
+ export type RequestOptionsWithTotalResults = Omit<RequestOptions, "search_settings"> & SearchSettingsWithOptionalTotalCount;
40
+ /**
41
+ * Report Options with optional total count in search_settings
42
+ */
43
+ export type ReportOptionsWithTotalResults = Omit<ReportOptions, "search_settings"> & SearchSettingsWithOptionalTotalCount;
44
+ export type DateConstant = "TODAY" | "YESTERDAY" | "LAST_7_DAYS" | "LAST_BUSINESS_WEEK" | "THIS_MONTH" | "LAST_MONTH" | "LAST_14_DAYS" | "LAST_30_DAYS" | "THIS_WEEK_SUN_TODAY" | "THIS_WEEK_MON_TODAY" | "LAST_WEEK_SUN_SAT" | "LAST_WEEK_MON_SUN";
45
+ export declare const dateConstants: DateConstant[];
46
+ export type SortOrder = "ASC" | "DESC";
47
+ export interface Order {
48
+ field: ConstraintKey;
49
+ sort_order?: SortOrder;
50
+ }
51
+ export type ConstraintKey = fields.Attribute | fields.Metric | fields.Segment;
52
+ export type ConstraintValue = number | string | boolean | (number | string)[];
53
+ export type ConstraintOperation = "=" | "!=" | ">" | ">=" | "<" | "<=" | "IN" | "NOT IN" | "LIKE" | "NOT LIKE" | "CONTAINS ANY" | "CONTAINS ALL" | "CONTAINS NONE" | "IS NULL" | "IS NOT NULL" | "DURING" | "BETWEEN" | "REGEXP_MATCH" | "NOT REGEXP_MATCH";
54
+ export type ConstraintType1 = {
55
+ key: ConstraintKey;
56
+ op: ConstraintOperation;
57
+ val: ConstraintValue;
58
+ };
59
+ export type ConstraintType2 = {
60
+ [C in ConstraintKey]?: ConstraintValue;
61
+ };
62
+ export type Constraint = string | ConstraintType1 | ConstraintType2;
63
+ export type Constraints = Constraint[] | ConstraintType2;
64
+ export type RequestOptions = Omit<services.ISearchGoogleAdsRequest, "customer_id" | "query" | "search_settings"> & {
65
+ search_settings?: Omit<services.ISearchSettings, "return_total_results_count">;
66
+ };
67
+ export type MutateOptions = Omit<services.IMutateGoogleAdsRequest, "customer_id" | "mutate_operations">;
68
+ export type MutateOperation<T> = {
69
+ resource: T;
70
+ entity: fields.Resource;
71
+ operation?: "create" | "update" | "remove";
72
+ exempt_policy_violation_keys?: services.AdGroupCriterionOperation["exempt_policy_violation_keys"];
73
+ } & Partial<Omit<T, "toJSON">>;
74
+ export type PageToken = services.ISearchGoogleAdsResponse["next_page_token"];
75
+ export {};
@@ -0,0 +1,14 @@
1
+ export const dateConstants = [
2
+ "TODAY",
3
+ "YESTERDAY",
4
+ "LAST_7_DAYS",
5
+ "LAST_BUSINESS_WEEK",
6
+ "THIS_MONTH",
7
+ "LAST_MONTH",
8
+ "LAST_14_DAYS",
9
+ "LAST_30_DAYS",
10
+ "THIS_WEEK_SUN_TODAY",
11
+ "THIS_WEEK_MON_TODAY",
12
+ "LAST_WEEK_SUN_SAT",
13
+ "LAST_WEEK_MON_SUN",
14
+ ];
@@ -0,0 +1,49 @@
1
+ import { protobuf } from "./protos/index.js";
2
+ /**
3
+ * @param micros Money value in micros format
4
+ * @description Converts a micro amount to a normalised value
5
+ * @example
6
+ * const cost = fromMicros(campaign.metrics.costMicros)
7
+ */
8
+ export declare function fromMicros(micros: number): number;
9
+ /**
10
+ * @param value Money value in decimal format
11
+ * @description Converts a number to micro format
12
+ * @example
13
+ * const costMicros = toMicros(12.5) // 12,500,000
14
+ */
15
+ export declare function toMicros(value: number): number;
16
+ /**
17
+ * @param query String gaql query
18
+ * @description Normalises a query by replacing multiple whitespace with single whitespace
19
+ * @example
20
+ * const gaqlQuery =
21
+ * `SELECT campaign.name
22
+ * FROM campaign
23
+ * LIMIT 10`
24
+ * const normalisedQuery = normaliseQuery(gaqlQuery) // "SELECT campaign.name FROM campaign LIMIT 10"
25
+ */
26
+ export declare function normaliseQuery(query: string): string;
27
+ /**
28
+ * @param str
29
+ * @description Capitalises the first letter of a string
30
+ * @example
31
+ * const capitalisedString = capitaliseFirstLetter("adGroupCriterionSimulation") // "AdGroupCriterionSimulation"
32
+ */
33
+ export declare function capitaliseFirstLetter<T extends string>(str: string): Capitalize<T>;
34
+ /**
35
+ * @param str
36
+ * @description Converts a string to a camel case string. Works on space case, snake case and title case strings.
37
+ * @example
38
+ * const camelCaseString = toCamelCase("ad_group_criterion_simulation") // "adGroupCriterionSimulation"
39
+ */
40
+ export declare function toCamelCase(str: string): string;
41
+ /**
42
+ * @param str
43
+ * @description Converts a string to a snake case string. Works on space case, camel case and title case strings.
44
+ * @example
45
+ * const snakeCaseString = toSnakeCase("adGroupCriterionSimulation") // "ad_group_criterion_simulation"
46
+ */
47
+ export declare function toSnakeCase(str: string): string;
48
+ export declare function recursiveFieldMaskSearch(data: Record<string, any>, ancestors?: Set<object>): string[];
49
+ export declare function getFieldMask(data: Record<string, any>): protobuf.FieldMask;
@@ -0,0 +1,108 @@
1
+ import long from "long";
2
+ import { protobuf } from "./protos/index.js";
3
+ /**
4
+ * @param micros Money value in micros format
5
+ * @description Converts a micro amount to a normalised value
6
+ * @example
7
+ * const cost = fromMicros(campaign.metrics.costMicros)
8
+ */
9
+ export function fromMicros(micros) {
10
+ return micros / 1000000;
11
+ }
12
+ /**
13
+ * @param value Money value in decimal format
14
+ * @description Converts a number to micro format
15
+ * @example
16
+ * const costMicros = toMicros(12.5) // 12,500,000
17
+ */
18
+ export function toMicros(value) {
19
+ return Math.round(value * 1000000);
20
+ }
21
+ /**
22
+ * @param query String gaql query
23
+ * @description Normalises a query by replacing multiple whitespace with single whitespace
24
+ * @example
25
+ * const gaqlQuery =
26
+ * `SELECT campaign.name
27
+ * FROM campaign
28
+ * LIMIT 10`
29
+ * const normalisedQuery = normaliseQuery(gaqlQuery) // "SELECT campaign.name FROM campaign LIMIT 10"
30
+ */
31
+ export function normaliseQuery(query) {
32
+ return `${query.replace(/\s{2,}/g, " ")}`;
33
+ }
34
+ /**
35
+ * @param str
36
+ * @description Capitalises the first letter of a string
37
+ * @example
38
+ * const capitalisedString = capitaliseFirstLetter("adGroupCriterionSimulation") // "AdGroupCriterionSimulation"
39
+ */
40
+ export function capitaliseFirstLetter(str) {
41
+ return (str.charAt(0).toUpperCase() + str.slice(1));
42
+ }
43
+ /**
44
+ * @param str
45
+ * @description Converts a string to a camel case string. Works on space case, snake case and title case strings.
46
+ * @example
47
+ * const camelCaseString = toCamelCase("ad_group_criterion_simulation") // "adGroupCriterionSimulation"
48
+ */
49
+ export function toCamelCase(str) {
50
+ return str
51
+ .replace(/\s+/g, "_") // convert spaces to underscores
52
+ .replace(/(_)([A-Za-z])/g, (pattern) => pattern[1].toUpperCase()) // replace "_x" patterns with "X"
53
+ .replace(/^([A-Z])/g, (pattern) => pattern.toLowerCase()); // capitalises the first letter of the string
54
+ }
55
+ /**
56
+ * @param str
57
+ * @description Converts a string to a snake case string. Works on space case, camel case and title case strings.
58
+ * @example
59
+ * const snakeCaseString = toSnakeCase("adGroupCriterionSimulation") // "ad_group_criterion_simulation"
60
+ */
61
+ export function toSnakeCase(str) {
62
+ return str
63
+ .replace(/\s+/g, "_") // convert spaces to underscores
64
+ .replace(/(?<!(^|_))([A-Z])/g, (pattern) => "_" + pattern) // places an underscore before any capital chars, unless there is already an underscore or it is the first char of the string
65
+ .toLowerCase();
66
+ }
67
+ export function recursiveFieldMaskSearch(data,
68
+ // eslint-disable-next-line @typescript-eslint/ban-types
69
+ ancestors = new Set()) {
70
+ if (ancestors.has(data)) {
71
+ throw new Error("Cannot build a field mask from an object containing a circular reference");
72
+ }
73
+ ancestors.add(data);
74
+ const paths = [];
75
+ for (const key of Object.keys(data)) {
76
+ if (key === "resourceName") {
77
+ continue;
78
+ }
79
+ const fieldKey = toSnakeCase(key);
80
+ const value = data[key];
81
+ if (typeof value === "object" &&
82
+ !Array.isArray(value) &&
83
+ !ArrayBuffer.isView(value) &&
84
+ !long.isLong(value) &&
85
+ value !== null) {
86
+ if (Object.keys(value).length === 0) {
87
+ paths.push(fieldKey);
88
+ }
89
+ else {
90
+ const children = recursiveFieldMaskSearch(value, ancestors);
91
+ for (const child of children) {
92
+ paths.push(`${fieldKey}.${child}`);
93
+ }
94
+ }
95
+ continue;
96
+ }
97
+ paths.push(fieldKey);
98
+ }
99
+ ancestors.delete(data);
100
+ return paths;
101
+ }
102
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
103
+ export function getFieldMask(data) {
104
+ const paths = recursiveFieldMaskSearch(data);
105
+ return new protobuf.FieldMask({
106
+ paths,
107
+ });
108
+ }
@@ -0,0 +1 @@
1
+ export declare const googleAdsVersion = "v25";
@@ -0,0 +1 @@
1
+ export const googleAdsVersion = "v25";
package/package.json CHANGED
@@ -1,16 +1,20 @@
1
1
  {
2
2
  "name": "google-ads-api",
3
- "version": "24.1.0",
3
+ "version": "25.1.0-beta.0",
4
4
  "description": "Google Ads API Client Library for Node.js",
5
- "repository": "https://github.com/Opteo/google-ads-api",
6
- "main": "build/src/index.js",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/Opteo/google-ads-api.git"
8
+ },
9
+ "main": "./build/cjs/index.js",
7
10
  "files": [
8
- "build/src"
11
+ "build/cjs",
12
+ "build/esm"
9
13
  ],
10
14
  "scripts": {
11
15
  "test": "jest",
12
16
  "lint": "eslint . --ext .ts",
13
- "build": "tsc",
17
+ "build": "tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json && printf '{\"type\":\"module\"}' > build/esm/package.json",
14
18
  "compile": "esbuild --bundle --platform=node ./scripts/index.ts --outfile=./build/scripts/index.js && node ./build/scripts/index.js",
15
19
  "prepare": "rm -rf build && npm run build",
16
20
  "node": "tsx"
@@ -21,9 +25,9 @@
21
25
  "@isaacs/ttlcache": "^1.4.0",
22
26
  "axios": "^1.6.7",
23
27
  "circ-json": "^1.0.4",
24
- "google-ads-node": "24.1.0",
25
- "google-auth-library": "^9.15.1",
26
- "google-gax": "^5.0.7",
28
+ "google-ads-node": "25.1.0-beta.0",
29
+ "google-auth-library": "^11.0.2",
30
+ "google-gax": "^6.3.0",
27
31
  "long": "^4.0.0",
28
32
  "stream-json": "^1.8.0"
29
33
  },
@@ -60,8 +64,43 @@
60
64
  "adwords javascript",
61
65
  "gads"
62
66
  ],
63
- "resolutions": {
64
- "google-auth-library": "^9.15.1"
67
+ "packageManager": "yarn@1.22.21+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72",
68
+ "type": "commonjs",
69
+ "engines": {
70
+ "node": ">=22"
65
71
  },
66
- "packageManager": "yarn@1.22.21+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72"
72
+ "types": "./build/cjs/index.d.ts",
73
+ "exports": {
74
+ ".": {
75
+ "import": {
76
+ "types": "./build/esm/index.d.ts",
77
+ "default": "./build/esm/index.js"
78
+ },
79
+ "require": {
80
+ "types": "./build/cjs/index.d.ts",
81
+ "default": "./build/cjs/index.js"
82
+ }
83
+ },
84
+ "./enums": {
85
+ "import": {
86
+ "types": "./build/esm/protos/autogen/enums.d.ts",
87
+ "default": "./build/esm/protos/autogen/enums.js"
88
+ },
89
+ "require": {
90
+ "types": "./build/cjs/protos/autogen/enums.d.ts",
91
+ "default": "./build/cjs/protos/autogen/enums.js"
92
+ }
93
+ },
94
+ "./fields": {
95
+ "import": {
96
+ "types": "./build/esm/protos/autogen/fields.d.ts",
97
+ "default": "./build/esm/protos/autogen/fields.js"
98
+ },
99
+ "require": {
100
+ "types": "./build/cjs/protos/autogen/fields.d.ts",
101
+ "default": "./build/cjs/protos/autogen/fields.js"
102
+ }
103
+ },
104
+ "./package.json": "./package.json"
105
+ }
67
106
  }
@@ -1,8 +0,0 @@
1
- export { Client as GoogleAdsApi, ClientOptions } from "./client";
2
- export { common, enums, fields, errors, resources, services, longrunning, protobuf, } from "./protos/index";
3
- export { fromMicros, toMicros } from "./utils";
4
- export { parse } from "./parser";
5
- export * as ResourceNames from "./protos/autogen/resourceNames";
6
- export { CustomerOptions, ReportOptions, MutateOperation, Constraint, Constraints, } from "./types";
7
- export { Hooks, OnQueryStart, OnQueryError, OnQueryEnd, OnStreamStart, OnStreamError, OnMutationStart, OnMutationError, OnMutationEnd, OnServiceStart, OnServiceError, OnServiceEnd, } from "./hooks";
8
- export { Customer } from "./customer";