@adport/provider-google 0.15.0 → 0.16.1

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.
package/dist/index.js CHANGED
@@ -3820,6 +3820,7 @@ var targeting = {
3820
3820
  var nativeResult = z13.record(z13.string(), z13.unknown());
3821
3821
  var output = z13.object({
3822
3822
  results: z13.array(nativeResult),
3823
+ currency: z13.string().regex(/^[A-Z]{3}$/).optional(),
3823
3824
  aggregate_metric_results: nativeResult.optional(),
3824
3825
  next_page_token: z13.string().optional(),
3825
3826
  total_size: z13.string().regex(/^\d+$/).optional(),
@@ -3861,6 +3862,26 @@ function result(data) {
3861
3862
  return parsed.data;
3862
3863
  }
3863
3864
  function googlePlanningTools(provider) {
3865
+ const currencies = /* @__PURE__ */ new Map();
3866
+ async function readPlan(customer, method, body) {
3867
+ const account2 = normalizeCustomerId(customer);
3868
+ const page = result(await provider.keywordPlanning(account2, method, body));
3869
+ const hasPrices = page.results.some((row2) => {
3870
+ const metrics = row2.keywordIdeaMetrics ?? row2.keywordMetrics;
3871
+ return metrics && typeof metrics === "object" && ("lowTopOfPageBidMicros" in metrics || "highTopOfPageBidMicros" in metrics || "averageCpcMicros" in metrics);
3872
+ });
3873
+ if (!hasPrices) return page;
3874
+ let currency2 = currencies.get(account2);
3875
+ if (!currency2) {
3876
+ const [row2] = await provider.gaqlSearch({ customer_id: account2, resource: "customer", fields: ["customer.currency_code"], limit: 1 }).catch(() => []);
3877
+ const code = row2?.customer?.currencyCode;
3878
+ if (typeof code === "string" && /^[A-Z]{3}$/.test(code)) {
3879
+ currency2 = code;
3880
+ currencies.set(account2, code);
3881
+ }
3882
+ }
3883
+ return currency2 ? { ...page, currency: currency2 } : page;
3884
+ }
3864
3885
  return [
3865
3886
  defineTool11({
3866
3887
  name: "google_keyword_ideas",
@@ -3878,7 +3899,7 @@ function googlePlanningTools(provider) {
3878
3899
  ...input2.page_token ? { pageToken: input2.page_token } : {},
3879
3900
  ...seed.type === "keywords" ? { keywordSeed: { keywords: seed.keywords } } : seed.type === "url" ? { urlSeed: { url: seed.url } } : seed.type === "keywords_and_url" ? { keywordAndUrlSeed: { keywords: seed.keywords, url: seed.url } } : { siteSeed: { site: seed.url } }
3880
3901
  };
3881
- return result(await provider.keywordPlanning(normalizeCustomerId(input2.account_id), "generateKeywordIdeas", body));
3902
+ return readPlan(input2.account_id, "generateKeywordIdeas", body);
3882
3903
  }
3883
3904
  }),
3884
3905
  defineTool11({
@@ -3888,7 +3909,7 @@ function googlePlanningTools(provider) {
3888
3909
  input: historicalInput,
3889
3910
  output,
3890
3911
  annotations: { readOnly: true },
3891
- handler: async (input2) => result(await provider.keywordPlanning(normalizeCustomerId(input2.account_id), "generateKeywordHistoricalMetrics", { ...target4(input2), keywords: input2.keywords }))
3912
+ handler: (input2) => readPlan(input2.account_id, "generateKeywordHistoricalMetrics", { ...target4(input2), keywords: input2.keywords })
3892
3913
  })
3893
3914
  ];
3894
3915
  }