google-ads-api 19.0.1-rest-beta → 19.0.2

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.
@@ -5,7 +5,7 @@ const service_1 = require("../../service");
5
5
  const index_1 = require("../index");
6
6
  class ServiceFactory extends service_1.Service {
7
7
  constructor(clientOptions, customerOptions, hooks) {
8
- super(clientOptions, customerOptions, hooks ?? {});
8
+ super(clientOptions, customerOptions, hooks !== null && hooks !== void 0 ? hooks : {});
9
9
  }
10
10
  /**
11
11
  * @link https://developers.google.com/google-ads/api/reference/rpc/v19/AccountBudgetProposalService
@@ -6,7 +6,7 @@ export import resources = protos.google.ads.googleads.v19.resources;
6
6
  export import services = protos.google.ads.googleads.v19.services;
7
7
  export import internalEnums = protos.google.ads.googleads.v19.enums;
8
8
  export { enums } from "./autogen/enums";
9
- export { fields, fieldDataTypes } from "./autogen/fields";
9
+ export { fields } from "./autogen/fields";
10
10
  export { GoogleAdsServiceClient } from "google-ads-node";
11
11
  export type AllServices = Omit<typeof allProtos, typeof VERSION>;
12
12
  export type ServiceName = keyof Omit<typeof allProtos, typeof VERSION>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.longrunning = exports.protobuf = exports.GoogleAdsServiceClient = exports.fieldDataTypes = exports.fields = exports.enums = exports.internalEnums = exports.services = exports.resources = exports.errors = exports.common = exports.VERSION = void 0;
3
+ exports.longrunning = exports.protobuf = exports.GoogleAdsServiceClient = exports.fields = exports.enums = exports.internalEnums = exports.services = exports.resources = exports.errors = exports.common = exports.VERSION = void 0;
4
4
  const google_ads_node_1 = require("google-ads-node");
5
5
  const version_1 = require("../version");
6
6
  // "as vN" is required to avoid type issues later on
@@ -17,7 +17,6 @@ var enums_1 = require("./autogen/enums");
17
17
  Object.defineProperty(exports, "enums", { enumerable: true, get: function () { return enums_1.enums; } });
18
18
  var fields_1 = require("./autogen/fields");
19
19
  Object.defineProperty(exports, "fields", { enumerable: true, get: function () { return fields_1.fields; } });
20
- Object.defineProperty(exports, "fieldDataTypes", { enumerable: true, get: function () { return fields_1.fieldDataTypes; } });
21
20
  // Common service used for report/query methods
22
21
  var google_ads_node_2 = require("google-ads-node");
23
22
  Object.defineProperty(exports, "GoogleAdsServiceClient", { enumerable: true, get: function () { return google_ads_node_2.GoogleAdsServiceClient; } });
@@ -51,7 +51,7 @@ exports.QueryError = {
51
51
  UNDEFINED_ENTITY: "The entity of the query must be defined.",
52
52
  };
53
53
  function buildSelectClause(attributes, metrics, segments) {
54
- if (!attributes?.length && !metrics?.length && !segments?.length) {
54
+ if (!(attributes === null || attributes === void 0 ? void 0 : attributes.length) && !(metrics === null || metrics === void 0 ? void 0 : metrics.length) && !(segments === null || segments === void 0 ? void 0 : segments.length)) {
55
55
  throw new Error(exports.QueryError.MISSING_FIELDS);
56
56
  }
57
57
  const selections = [
@@ -16,7 +16,6 @@ export declare class Service {
16
16
  get credentials(): CustomerCredentials;
17
17
  protected get callHeaders(): CallHeaders;
18
18
  private getCredentials;
19
- getAccessToken(): Promise<string>;
20
19
  protected loadService<T = AllServices>(service: ServiceName): T;
21
20
  protected getGoogleAdsError(error: Error): errors.GoogleAdsFailure | Error;
22
21
  private decodeGoogleAdsFailureBuffer;
@@ -14,26 +14,18 @@ const ttlcache_1 = __importDefault(require("@isaacs/ttlcache"));
14
14
  exports.FAILURE_KEY = `google.ads.googleads.${version_1.googleAdsVersion}.errors.googleadsfailure-bin`;
15
15
  // A global service cache to avoid re-initialising services
16
16
  const serviceCache = new ttlcache_1.default({
17
- max: 1_000,
17
+ max: 1000,
18
18
  ttl: 10 * 60 * 1000, // 10 minutes
19
19
  dispose: async (service) => {
20
20
  // Close connections when services are removed from the cache
21
21
  await service.close();
22
22
  },
23
23
  });
24
- // A global access token cache used by REST calls. Issued tokens expire after 1 hour, so we cache them for 50 minutes.
25
- const accessTokenCache = new ttlcache_1.default({
26
- max: 100_000,
27
- ttl: 50 * 60 * 1000, // 50 minutes
28
- });
29
24
  class Service {
30
- clientOptions;
31
- customerOptions;
32
- hooks;
33
25
  constructor(clientOptions, customerOptions, hooks) {
34
26
  this.clientOptions = clientOptions;
35
27
  this.customerOptions = customerOptions;
36
- this.hooks = hooks ?? {};
28
+ this.hooks = hooks !== null && hooks !== void 0 ? hooks : {};
37
29
  // @ts-expect-error All fields don't need to be set here
38
30
  this.serviceCache = {};
39
31
  }
@@ -56,30 +48,12 @@ class Service {
56
48
  }
57
49
  return headers;
58
50
  }
59
- // Used only by gRPC calls
60
51
  getCredentials() {
61
52
  const sslCreds = google_gax_1.grpc.credentials.createSsl();
62
53
  const authClient = new google_auth_library_1.UserRefreshClient(this.clientOptions.client_id, this.clientOptions.client_secret, this.customerOptions.refresh_token);
63
54
  const credentials = google_gax_1.grpc.credentials.combineChannelCredentials(sslCreds, google_gax_1.grpc.credentials.createFromGoogleCredential(authClient));
64
55
  return credentials;
65
56
  }
66
- // Used only by REST calls
67
- async getAccessToken() {
68
- const cachedToken = accessTokenCache.get(this.customerOptions.refresh_token);
69
- if (cachedToken) {
70
- return cachedToken;
71
- }
72
- const oAuth2Client = new google_auth_library_1.OAuth2Client(this.clientOptions.client_id, this.clientOptions.client_secret);
73
- oAuth2Client.setCredentials({
74
- refresh_token: this.customerOptions.refresh_token,
75
- });
76
- const { token } = await oAuth2Client.getAccessToken();
77
- if (typeof token !== "string") {
78
- throw new Error("Failed to retrieve access token");
79
- }
80
- accessTokenCache.set(this.customerOptions.refresh_token, token);
81
- return token;
82
- }
83
57
  loadService(service) {
84
58
  const serviceCacheKey = `${service}_${this.customerOptions.refresh_token}`;
85
59
  if (serviceCache.has(serviceCacheKey)) {
@@ -98,8 +72,9 @@ class Service {
98
72
  return client;
99
73
  }
100
74
  getGoogleAdsError(error) {
75
+ var _a;
101
76
  // @ts-expect-error No type exists for GA query error
102
- if (typeof error?.metadata?.internalRepr.get(exports.FAILURE_KEY) === "undefined") {
77
+ if (typeof ((_a = error === null || error === void 0 ? void 0 : error.metadata) === null || _a === void 0 ? void 0 : _a.internalRepr.get(exports.FAILURE_KEY)) === "undefined") {
103
78
  return error;
104
79
  }
105
80
  // @ts-expect-error No type exists for GA query error
@@ -111,12 +86,13 @@ class Service {
111
86
  return googleAdsFailure;
112
87
  }
113
88
  decodePartialFailureError(response) {
114
- if (typeof response?.partial_failure_error === "undefined" ||
115
- !response?.partial_failure_error) {
89
+ var _a;
90
+ if (typeof (response === null || response === void 0 ? void 0 : response.partial_failure_error) === "undefined" ||
91
+ !(response === null || response === void 0 ? void 0 : response.partial_failure_error)) {
116
92
  return response;
117
93
  }
118
94
  const { details } = response.partial_failure_error;
119
- const buffer = details?.find((d) => d.type_url.includes("errors.GoogleAdsFailure"))?.value;
95
+ const buffer = (_a = details === null || details === void 0 ? void 0 : details.find((d) => d.type_url.includes("errors.GoogleAdsFailure"))) === null || _a === void 0 ? void 0 : _a.value;
120
96
  if (typeof buffer === "undefined") {
121
97
  return response;
122
98
  }
@@ -147,13 +123,15 @@ class Service {
147
123
  buildMutationRequestAndService(mutations, options) {
148
124
  const service = this.loadService("GoogleAdsServiceClient");
149
125
  const mutateOperations = mutations.map((mutation) => {
126
+ var _a, _b;
150
127
  const opKey = (0, utils_1.toSnakeCase)(`${mutation.entity}Operation`);
151
128
  const operation = {
152
- [mutation.operation ?? "create"]: mutation.resource,
129
+ [(_a = mutation.operation) !== null && _a !== void 0 ? _a : "create"]: mutation.resource,
153
130
  };
154
131
  if (mutation.operation === "create" &&
132
+ (
155
133
  //@ts-ignore
156
- mutation?.exempt_policy_violation_keys?.length) {
134
+ (_b = mutation === null || mutation === void 0 ? void 0 : mutation.exempt_policy_violation_keys) === null || _b === void 0 ? void 0 : _b.length)) {
157
135
  //@ts-ignore
158
136
  operation.exempt_policy_violation_keys =
159
137
  mutation.exempt_policy_violation_keys;
@@ -176,12 +154,13 @@ class Service {
176
154
  }
177
155
  buildOperations(type, entities, message) {
178
156
  const ops = entities.map((e) => {
157
+ var _a;
179
158
  const op = {
180
159
  [type]: e,
181
160
  operation: type,
182
161
  };
183
162
  //@ts-ignore
184
- if (type === "create" && e?.exempt_policy_violation_keys?.length) {
163
+ if (type === "create" && ((_a = e === null || e === void 0 ? void 0 : e.exempt_policy_violation_keys) === null || _a === void 0 ? void 0 : _a.length)) {
185
164
  // @ts-expect-error Field required for policy violation exemptions
186
165
  op.exempt_policy_violation_keys = e.exempt_policy_violation_keys;
187
166
  //@ts-ignore
@@ -1,4 +1,3 @@
1
- import { Readable } from "stream";
2
1
  import { Customer } from "./customer";
3
2
  import { Hooks } from "./hooks";
4
3
  import { errors, GoogleAdsServiceClient, services } from "./protos";
@@ -12,39 +11,7 @@ export declare const MOCK_LOGIN_CID = "MOCK LOGIN CID";
12
11
  export declare const mockGaqlQuery = "SELECT campaign.resource_name FROM campaign LIMIT 1";
13
12
  export declare const mockReportOptions: ReportOptions;
14
13
  export declare const mockMutations: MutateOperation<any>[];
15
- export declare const mockSearchRawResult: {
16
- totalResultsCount: number;
17
- results: {
18
- campaign: {
19
- resourceName: string;
20
- };
21
- }[];
22
- }[];
23
- export declare const mockSearchRawResultWithSummaryRow: ({
24
- totalResultsCount: number;
25
- results: {
26
- campaign: {
27
- resourceName: string;
28
- };
29
- }[];
30
- summaryRow?: undefined;
31
- } | {
32
- summaryRow: {
33
- metrics: {
34
- clicks: number;
35
- impressions: number;
36
- };
37
- };
38
- totalResultsCount?: undefined;
39
- results?: undefined;
40
- })[];
41
14
  export declare const mockQueryReturnValue: services.IGoogleAdsRow[];
42
- export declare const mockQueryReturnValueWithSummaryRow: services.IGoogleAdsRow[];
43
- export declare const mockQueryReturnValueUnparsed: {
44
- campaign: {
45
- resourceName: string;
46
- };
47
- }[];
48
15
  export declare const mockSummaryRow: services.IGoogleAdsRow;
49
16
  export declare const mockTotalResultsCount = 23;
50
17
  export declare const mockMutationReturnValue: services.MutateGoogleAdsResponse;
@@ -59,10 +26,6 @@ export declare const mockError: {
59
26
  export declare const mockErrorMessage = "mock error message";
60
27
  export declare const mockParseValue: services.IGoogleAdsRow;
61
28
  export declare const mockParsedValues: services.IGoogleAdsRow[];
62
- export declare const mockStream: (data?: any) => Readable;
63
- export declare function mockGetAccessToken(customer: Customer): jest.SpyInstance;
64
- export declare const mockStreamWithSummaryRow: () => Readable;
65
- export declare const mockStreamWithBadData: () => Readable;
66
29
  export declare function mockPaginatedSearch(customer: Customer, includeTotalResultsCount?: boolean): jest.SpyInstance;
67
30
  export declare function mockSearchOnce({ customer, response, nextPageToken, includeTotalResultsCount, }: {
68
31
  customer: Customer;
@@ -98,7 +61,6 @@ export declare function mockBuildMutateRequestAndService({ customer, shouldThrow
98
61
  export declare function mockGetGoogleAdsError(customer: Customer): jest.SpyInstance;
99
62
  export declare function mockQuery(customer: Customer): jest.SpyInstance;
100
63
  export declare function mockParse(mockParsedValues: services.IGoogleAdsRow[]): jest.SpyInstance;
101
- export declare function mockParseRest(mockParsedValues: services.IGoogleAdsRow[]): jest.SpyInstance;
102
64
  export declare function noopParser(rows: services.IGoogleAdsRow[]): services.IGoogleAdsRow[];
103
65
  export declare function mockMethod(): {
104
66
  method(): void;
@@ -22,12 +22,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
25
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.mockStreamWithBadData = exports.mockStreamWithSummaryRow = exports.mockStream = exports.mockParsedValues = exports.mockParseValue = exports.mockErrorMessage = exports.mockError = exports.mockMutationReturnValue = exports.mockTotalResultsCount = exports.mockSummaryRow = exports.mockQueryReturnValueUnparsed = exports.mockQueryReturnValueWithSummaryRow = exports.mockQueryReturnValue = exports.mockSearchRawResultWithSummaryRow = exports.mockSearchRawResult = exports.mockMutations = exports.mockReportOptions = exports.mockGaqlQuery = exports.MOCK_LOGIN_CID = exports.MOCK_CID = exports.MOCK_REFRESH_TOKEN = exports.MOCK_DEVELOPER_TOKEN = exports.MOCK_CLIENT_SECRET = exports.MOCK_CLIENT_ID = void 0;
30
- exports.mockGetAccessToken = mockGetAccessToken;
26
+ exports.mockParsedValues = exports.mockParseValue = exports.mockErrorMessage = exports.mockError = exports.mockMutationReturnValue = exports.mockTotalResultsCount = exports.mockSummaryRow = exports.mockQueryReturnValue = exports.mockMutations = exports.mockReportOptions = exports.mockGaqlQuery = exports.MOCK_LOGIN_CID = exports.MOCK_CID = exports.MOCK_REFRESH_TOKEN = exports.MOCK_DEVELOPER_TOKEN = exports.MOCK_CLIENT_SECRET = exports.MOCK_CLIENT_ID = void 0;
31
27
  exports.mockPaginatedSearch = mockPaginatedSearch;
32
28
  exports.mockSearchOnce = mockSearchOnce;
33
29
  exports.mockBuildSearchStreamRequestAndService = mockBuildSearchStreamRequestAndService;
@@ -36,7 +32,6 @@ exports.mockBuildMutateRequestAndService = mockBuildMutateRequestAndService;
36
32
  exports.mockGetGoogleAdsError = mockGetGoogleAdsError;
37
33
  exports.mockQuery = mockQuery;
38
34
  exports.mockParse = mockParse;
39
- exports.mockParseRest = mockParseRest;
40
35
  exports.noopParser = noopParser;
41
36
  exports.mockMethod = mockMethod;
42
37
  exports.failTestIfExecuted = failTestIfExecuted;
@@ -44,9 +39,7 @@ exports.newCustomer = newCustomer;
44
39
  const stream_1 = require("stream");
45
40
  const customer_1 = require("./customer");
46
41
  const parser = __importStar(require("./parser"));
47
- const parserRest = __importStar(require("./parserRest"));
48
42
  const protos_1 = require("./protos");
49
- const lodash_1 = __importDefault(require("lodash"));
50
43
  exports.MOCK_CLIENT_ID = "MOCK CLIENT ID";
51
44
  exports.MOCK_CLIENT_SECRET = "MOCK CLIENT SECRET";
52
45
  exports.MOCK_DEVELOPER_TOKEN = "MOCK DEVELOPER TOKEN";
@@ -62,45 +55,11 @@ exports.mockReportOptions = {
62
55
  exports.mockMutations = [
63
56
  { resource: "abc", entity: "campaign", operation: "create" },
64
57
  ];
65
- exports.mockSearchRawResult = [
66
- {
67
- totalResultsCount: 23,
68
- results: [
69
- { campaign: { resourceName: "customers/1/campaigns/11" } },
70
- { campaign: { resourceName: "customers/2/campaigns/22" } },
71
- { campaign: { resourceName: "customers/3/campaigns/33" } },
72
- ],
73
- },
74
- ];
75
- exports.mockSearchRawResultWithSummaryRow = [
76
- {
77
- totalResultsCount: 23,
78
- results: [
79
- { campaign: { resourceName: "customers/1/campaigns/11" } },
80
- { campaign: { resourceName: "customers/2/campaigns/22" } },
81
- { campaign: { resourceName: "customers/3/campaigns/33" } },
82
- ],
83
- },
84
- {
85
- summaryRow: { metrics: { clicks: 90, impressions: 153 } },
86
- },
87
- ];
88
58
  exports.mockQueryReturnValue = [
89
59
  { campaign: { resource_name: "customers/1/campaigns/11" } },
90
60
  { campaign: { resource_name: "customers/2/campaigns/22" } },
91
61
  { campaign: { resource_name: "customers/3/campaigns/33" } },
92
62
  ];
93
- exports.mockQueryReturnValueWithSummaryRow = [
94
- { campaign: { resource_name: "customers/1/campaigns/11" } },
95
- { campaign: { resource_name: "customers/2/campaigns/22" } },
96
- { campaign: { resource_name: "customers/3/campaigns/33" } },
97
- { metrics: { clicks: 90, impressions: 153 } },
98
- ];
99
- exports.mockQueryReturnValueUnparsed = [
100
- { campaign: { resourceName: "customers/1/campaigns/11" } },
101
- { campaign: { resourceName: "customers/2/campaigns/22" } },
102
- { campaign: { resourceName: "customers/3/campaigns/33" } },
103
- ];
104
63
  exports.mockSummaryRow = {
105
64
  metrics: { clicks: 90, impressions: 153 },
106
65
  };
@@ -128,42 +87,17 @@ exports.mockParsedValues = [
128
87
  exports.mockParseValue,
129
88
  exports.mockParseValue,
130
89
  ];
131
- // Returns a stream that emits the provided values
132
- const mockStream = function (data = exports.mockSearchRawResult) {
133
- const chunks = lodash_1.default.chunk(JSON.stringify(data), 10).map((c) => c.join("")); // random splits
134
- const stream = new stream_1.Readable({ objectMode: true });
135
- chunks.forEach((value) => stream.push(new Buffer(value)));
136
- stream.push(null);
137
- return stream;
138
- };
139
- exports.mockStream = mockStream;
140
- function mockGetAccessToken(customer) {
141
- return (jest
142
- .spyOn(customer, "getAccessToken")
143
- // ts-expect-error
144
- .mockImplementation(async () => {
145
- return "mockedAccessTokenHere";
146
- }));
147
- }
148
- const mockStreamWithSummaryRow = function () {
149
- return (0, exports.mockStream)(exports.mockSearchRawResultWithSummaryRow);
150
- };
151
- exports.mockStreamWithSummaryRow = mockStreamWithSummaryRow;
152
- const mockStreamWithBadData = function () {
153
- return (0, exports.mockStream)({ results: 66 });
154
- };
155
- exports.mockStreamWithBadData = mockStreamWithBadData;
156
90
  function mockPaginatedSearch(customer, includeTotalResultsCount = false) {
157
91
  return (jest
158
92
  // @ts-expect-error private method
159
93
  .spyOn(customer, "paginatedSearch")
160
94
  // @ts-expect-error
161
- .mockImplementation((gaqlQuery, requestOptions) => {
95
+ .mockImplementation((gaqlQuery, requestOptions, _parser) => {
162
96
  const totalResultsCount = includeTotalResultsCount
163
97
  ? exports.mockTotalResultsCount
164
98
  : undefined;
165
99
  return {
166
- response: exports.mockQueryReturnValue,
100
+ response: _parser(exports.mockQueryReturnValue),
167
101
  totalResultsCount,
168
102
  };
169
103
  }));
@@ -254,7 +188,7 @@ function mockBuildMutateRequestAndService({ customer, shouldThrow = false, reque
254
188
  if (shouldThrow) {
255
189
  throw new Error(exports.mockErrorMessage);
256
190
  }
257
- return [response ?? exports.mockMutationReturnValue];
191
+ return [response !== null && response !== void 0 ? response : exports.mockMutationReturnValue];
258
192
  },
259
193
  };
260
194
  const spyBuild = jest
@@ -264,7 +198,7 @@ function mockBuildMutateRequestAndService({ customer, shouldThrow = false, reque
264
198
  .mockImplementation(() => {
265
199
  return {
266
200
  service: mockService,
267
- request: request ?? {},
201
+ request: request !== null && request !== void 0 ? request : {},
268
202
  };
269
203
  });
270
204
  return { mockService, spyBuild };
@@ -291,11 +225,6 @@ function mockQuery(customer) {
291
225
  function mockParse(mockParsedValues) {
292
226
  return jest.spyOn(parser, "parse").mockImplementation(() => mockParsedValues);
293
227
  }
294
- function mockParseRest(mockParsedValues) {
295
- return jest
296
- .spyOn(parserRest, "decamelizeKeys")
297
- .mockImplementation(() => mockParsedValues);
298
- }
299
228
  function noopParser(rows) {
300
229
  return rows;
301
230
  }
@@ -47,3 +47,8 @@ export declare function toCamelCase(str: string): string;
47
47
  export declare function toSnakeCase(str: string): string;
48
48
  export declare function recursiveFieldMaskSearch(data: Record<string, any>): string[];
49
49
  export declare function getFieldMask(data: Record<string, any>): protobuf.FieldMask;
50
+ export declare function createNextChunkArrivedPromise(): {
51
+ newPromise: Promise<unknown>;
52
+ resolve: () => void;
53
+ reject: (error: Error) => void;
54
+ };
@@ -8,6 +8,7 @@ exports.toCamelCase = toCamelCase;
8
8
  exports.toSnakeCase = toSnakeCase;
9
9
  exports.recursiveFieldMaskSearch = recursiveFieldMaskSearch;
10
10
  exports.getFieldMask = getFieldMask;
11
+ exports.createNextChunkArrivedPromise = createNextChunkArrivedPromise;
11
12
  const protos_1 = require("./protos");
12
13
  /**
13
14
  * @param micros Money value in micros format
@@ -99,3 +100,17 @@ function getFieldMask(data) {
99
100
  paths,
100
101
  });
101
102
  }
103
+ function createNextChunkArrivedPromise() {
104
+ let resolvePromise = () => {
105
+ return;
106
+ };
107
+ let rejectPromise = (error) => {
108
+ throw error;
109
+ };
110
+ const newPromise = new Promise((resolve, reject) => {
111
+ // @ts-ignore
112
+ resolvePromise = resolve;
113
+ rejectPromise = reject;
114
+ });
115
+ return { newPromise, resolve: resolvePromise, reject: rejectPromise };
116
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "google-ads-api",
3
- "version": "19.0.1-rest-beta",
3
+ "version": "19.0.2",
4
4
  "description": "Google Ads API Client Library for Node.js",
5
5
  "repository": "https://github.com/Opteo/google-ads-api",
6
6
  "main": "build/src/index.js",
@@ -11,7 +11,7 @@
11
11
  "test": "jest",
12
12
  "lint": "eslint . --ext .ts",
13
13
  "build": "tsc",
14
- "compile": "esbuild --bundle --platform=node ./scripts/index.ts --outfile=./build/scripts/index.js && node ./build/scripts/index.js",
14
+ "compile": "tsc && node build/scripts/index.js",
15
15
  "prepare": "rm -rf build && npm run build",
16
16
  "node": "tsx"
17
17
  },
@@ -19,31 +19,21 @@
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
21
  "@isaacs/ttlcache": "^1.2.2",
22
- "axios": "^1.6.7",
23
- "circ-json": "^1.0.4",
24
22
  "google-ads-node": "15.0.0",
25
23
  "google-auth-library": "^7.1.0",
26
24
  "google-gax": "^4.4.1",
27
- "long": "^4.0.0",
28
- "map-obj": "^4.0.0",
29
- "stream-json": "^1.8.0"
25
+ "long": "^4.0.0"
30
26
  },
31
27
  "devDependencies": {
32
28
  "@types/jest": "^29.0.1",
33
- "@types/lodash": "^4.14.202",
34
29
  "@types/node": "^22.5.4",
35
30
  "@types/pluralize": "^0.0.29",
36
- "@types/stream-json": "^1.7.7",
37
31
  "@typescript-eslint/eslint-plugin": "^4.8.2",
38
32
  "@typescript-eslint/parser": "^4.8.2",
39
- "axios-mock-adapter": "^1.22.0",
40
- "esbuild": "^0.20.1",
41
33
  "eslint": "^7.14.0",
42
- "jest": "^29.7.0",
43
- "lodash": "^4.17.21",
34
+ "jest": "^29.0.3",
44
35
  "pluralize": "^8.0.0",
45
- "protobufjs": "^7.2.6",
46
- "ts-jest": "^29.1.2",
36
+ "ts-jest": "^29.0.0",
47
37
  "tsx": "^4.19.3",
48
38
  "typescript": "^5.5.4"
49
39
  },
@@ -1,4 +0,0 @@
1
- /**
2
- * JSON Rest parsing
3
- */
4
- export declare const decamelizeKeys: (input: any) => any;
@@ -1,88 +0,0 @@
1
- "use strict";
2
- /**
3
- * JSON Rest parsing
4
- */
5
- var __importDefault = (this && this.__importDefault) || function (mod) {
6
- return (mod && mod.__esModule) ? mod : { "default": mod };
7
- };
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.decamelizeKeys = void 0;
10
- const map_obj_1 = __importDefault(require("map-obj"));
11
- const circ_json_1 = require("circ-json");
12
- const utils_1 = require("./utils");
13
- const fields_1 = require("./protos/autogen/fields");
14
- const enums_1 = require("./protos/autogen/enums");
15
- const fieldDataTypes = (0, circ_json_1.parse)(fields_1.fieldDataTypes);
16
- const decamelizeCache = new Map();
17
- const fieldTypeCache = new Map();
18
- const isObject = (value) => typeof value === "object" && value !== null;
19
- const decamelizeKeys = (input) => {
20
- if (!isObject(input)) {
21
- return input;
22
- }
23
- const makeMapper = (parentPath) => (key, value) => {
24
- key = cachedDecamelize(key);
25
- if (isObject(value)) {
26
- const path = parentPath === undefined ? key : `${parentPath}.${key}`;
27
- // @ts-ignore
28
- value = (0, map_obj_1.default)(value, makeMapper(path));
29
- }
30
- else {
31
- value = cachedValueParser(key, parentPath, value);
32
- }
33
- return [key, value];
34
- };
35
- // @ts-ignore
36
- return (0, map_obj_1.default)(input, makeMapper());
37
- };
38
- exports.decamelizeKeys = decamelizeKeys;
39
- const cachedDecamelize = (key) => {
40
- const cachedResult = decamelizeCache.get(key);
41
- if (cachedResult) {
42
- return cachedResult;
43
- }
44
- const newKey = (0, utils_1.toSnakeCase)(key);
45
- decamelizeCache.set(key, newKey);
46
- return newKey;
47
- };
48
- const cachedValueParser = (key, parentPath, value) => {
49
- let newValue = value;
50
- const fullPath = parentPath ? `${parentPath}.${key}` : key;
51
- const megaDataType = getTypeFromPath(fullPath);
52
- if (megaDataType === undefined && !fullPath.startsWith("@")) {
53
- console.warn(`No data type found for ${fullPath}`);
54
- }
55
- else if (typeof megaDataType === "object") {
56
- newValue = megaDataType[value];
57
- }
58
- else if (megaDataType === "INT64") {
59
- newValue = Number(value);
60
- }
61
- else if (megaDataType === "ENUM") {
62
- // Some enums aren't embedded in megaDataType, so we need this fallback.
63
- // @ts-expect-error typescript doesn't like accessing items in a namespace with a string
64
- newValue = enums_1.enums[fields_1.fields.enumFields[fullPath]][value]; // e.g. enums['CampaignStatus'][ENABLED] = "2"
65
- }
66
- return newValue;
67
- };
68
- const getTypeFromPath = (path) => {
69
- const cachedResult = fieldTypeCache.get(path);
70
- if (cachedResult) {
71
- return cachedResult;
72
- }
73
- const t = get(fieldDataTypes, path);
74
- fieldTypeCache.set(path, t);
75
- return t;
76
- };
77
- // Copied from youmightnotneed.com
78
- const get = (obj, path) => {
79
- if (!path)
80
- return undefined;
81
- // Check if path is string or array. Regex : ensure that we do not have '.' and brackets.
82
- // Regex explained: https://regexr.com/58j0k
83
- const pathArray = path.match(/([^[.\]])+/g);
84
- if (!pathArray)
85
- return undefined;
86
- // Find value
87
- return pathArray.reduce((prevObj, key) => prevObj && prevObj[key], obj);
88
- };