Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@honkandgo/googleads

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@honkandgo/googleads - npm Package Compare versions

Comparing version 1.0.1 to 2.0.0

src/api.js

2

dist/googleads.js

@@ -1,2 +0,2 @@

var e,r=(e=require("node-fetch"))&&"object"==typeof e&&"default"in e?e.default:e;exports.clientId=process.env.GOOGLE_CLIENT_ID,exports.clientSecret=process.env.GOOGLE_CLIENT_SECRET,exports.developerToken=process.env.GOOGLE_DEVELOPER_TOKEN,exports.defaultRefreshToken=process.env.GOOGLE_REFRESH_TOKEN;var t=function(e){void 0===e&&(e=3600);var r={},t=function(e){var t=r[e];if(t){var n=Date.now();if(t.inserted+1e3*t.maxAge>n)return t.value;delete r[e]}};return{get:t,set:function(t,n,o){r[t]={value:n,maxAge:o||e,inserted:Date.now()}},has:function(e){return void 0!==t(e)}}}(1800),n=function(e,n,o,s){void 0===s&&(s=exports.defaultRefreshToken);try{return Promise.resolve(function(e){void 0===e&&(e="");try{return t.has(e)||t.set(e,function(e){try{return Promise.resolve(r("https://www.googleapis.com/oauth2/v4/token",{method:"POST",body:JSON.stringify({client_id:exports.clientId,client_secret:exports.clientSecret,refresh_token:e,grant_type:"refresh_token"})}).then(function(e){return e.json()}).then(function(e){return e.access_token}))}catch(e){return Promise.reject(e)}}(e)),Promise.resolve(t.get(e))}catch(e){return Promise.reject(e)}}(s)).then(function(t){return Promise.resolve(r("https://googleads.googleapis.com/v6"+n,{method:e,headers:{"Content-Type":"application/json",Authorization:"Bearer "+t,"Developer-Token":exports.developerToken},body:o?JSON.stringify(o):null})).then(function(e){if(404===e.status)throw new Error("404 "+n);return Promise.resolve(e.json()).then(function(e){if(e.error)throw new Error(JSON.stringify(e.error));return e})})})}catch(e){return Promise.reject(e)}},o=function(e,r,t){return n("GET",e,r,t)},s=function(e,r,t){return n("POST",e,r,t)};function a(){return(a=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}exports.config=function(e){e.clientId&&(exports.clientId=e.clientId),e.clientSecret&&(exports.clientSecret=e.clientSecret),e.developerToken&&(exports.developerToken=e.developerToken),e.refreshToken&&(exports.defaultRefreshToken=e.refreshToken)},exports.createCampaign=function(e,r){try{return Promise.resolve(s("/customers/"+e+"/googleAds:mutate",{mutateOperations:[{campaignBudgetOperation:{create:{resourceName:"customers/"+e+"/campaignBudgets/-1",explicitlyShared:!1,period:"DAILY",status:"ENABLED",amountMicros:13e6}}},{campaignOperation:{create:{resourceName:"customers/"+e+"/campaigns/-2",name:"Test campaign MOFO",status:"PAUSED",campaignBudget:"customers/"+e+"/campaignBudgets/-1",manualCpc:{enhancedCpcEnabled:!1},advertisingChannelType:"SEARCH",networkSettings:{targetGoogleSearch:!0,targetSearchNetwork:!0,targetContentNetwork:!0,targetPartnerSearchNetwork:!1}}}},{adGroupOperation:{create:{name:"Ad group 1",campaign:"customers/"+e+"/campaigns/-2"}}}]},r)).then(function(e){console.log(e)})}catch(e){return Promise.reject(e)}},exports.deleteCampaigns=function(e,r,t){try{var n=r.map(function(r){return{remove:"customers/"+e+"/campaigns/"+r}});return Promise.resolve(s("/customers/"+e+"/campaigns:mutate",{operations:n},t)).then(function(e){console.log(JSON.stringify(e,null,2))})}catch(e){return Promise.reject(e)}},exports.listCampaigns=function(e,r){try{return Promise.resolve(s("/customers/"+e+"/googleAds:search",{query:"SELECT campaign.id, campaign.name, campaign.status FROM campaign"},r)).then(function(e){var r=e.results;return(void 0===r?[]:r).map(function(e){return{id:e.campaign.id,name:e.campaign.name}})})}catch(e){return Promise.reject(e)}},exports.listCustomers=function(e){try{return Promise.resolve(o("/customers:listAccessibleCustomers",null,e)).then(function(r){var t=r.resourceNames.map(function(e){return e.replace("customers/","")});return Promise.resolve(Promise.all(t.map(function(r){return o("/customers/"+r,null,e).then(function(e){return{id:r,name:e.descriptiveName,manager:e.manager,testAccount:e.testAccount}}).catch(function(e){return null})})).then(function(e){return e.filter(function(e){return null!==e})}))})}catch(e){return Promise.reject(e)}},exports.listKeywords=function(e,r,t){try{return Promise.resolve(s("/customers/"+e+"/googleAds:search",{query:"SELECT campaign.id, ad_group_criterion.keyword.text, ad_group_criterion.status FROM ad_group_criterion WHERE campaign.id = '"+r+"' AND ad_group_criterion.type = 'KEYWORD' AND ad_group_criterion.status = 'ENABLED'"},t)).then(function(e){var r=e.results;return(void 0===r?[]:r).map(function(e){return e.adGroupCriterion.keyword.text})})}catch(e){return Promise.reject(e)}},exports.updateCampaigns=function(e,r,t,n){try{var o=r.map(function(r){return{updateMask:Object.keys(t).join(","),update:a({resourceName:"customers/"+e+"/campaigns/"+r},t)}});return Promise.resolve(s("/customers/"+e+"/campaigns:mutate",{operations:o},n)).then(function(e){console.log(JSON.stringify(e,null,2))})}catch(e){return Promise.reject(e)}};
var e,r=(e=require("node-fetch"))&&"object"==typeof e&&"default"in e?e.default:e;function t(){return(t=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}var n=function(e){var r=e.post;return function(e,t){try{return Promise.resolve(r("/customers/"+e+"/googleAds:search",{query:"SELECT campaign.id, campaign.name, campaign.status FROM campaign"},t)).then(function(e){var r=e.results;return(void 0===r?[]:r).map(function(e){return{id:e.campaign.id,name:e.campaign.name}})})}catch(e){return Promise.reject(e)}}},o=function(e){var r=e.post;return function(e,t){try{return Promise.resolve(r("/customers/"+e+"/googleAds:mutate",{mutateOperations:[{campaignBudgetOperation:{create:{resourceName:"customers/"+e+"/campaignBudgets/-1",explicitlyShared:!1,period:"DAILY",status:"ENABLED",amountMicros:13e6}}},{campaignOperation:{create:{resourceName:"customers/"+e+"/campaigns/-2",name:"Test campaign MOFO",status:"PAUSED",campaignBudget:"customers/"+e+"/campaignBudgets/-1",manualCpc:{enhancedCpcEnabled:!1},advertisingChannelType:"SEARCH",networkSettings:{targetGoogleSearch:!0,targetSearchNetwork:!0,targetContentNetwork:!0,targetPartnerSearchNetwork:!1}}}},{adGroupOperation:{create:{name:"Ad group 1",campaign:"customers/"+e+"/campaigns/-2"}}}]},t)).then(function(e){console.log(e)})}catch(e){return Promise.reject(e)}}},a=function(e){var r=e.post;return function(e,n,o,a){try{var i=n.map(function(r){return{updateMask:Object.keys(o).join(","),update:t({resourceName:"customers/"+e+"/campaigns/"+r},o)}});return Promise.resolve(r("/customers/"+e+"/campaigns:mutate",{operations:i},a)).then(function(e){console.log(JSON.stringify(e,null,2))})}catch(e){return Promise.reject(e)}}},i=function(e){var r=e.post;return function(e,t,n){try{var o=t.map(function(r){return{remove:"customers/"+e+"/campaigns/"+r}});return Promise.resolve(r("/customers/"+e+"/campaigns:mutate",{operations:o},n)).then(function(e){console.log(JSON.stringify(e,null,2))})}catch(e){return Promise.reject(e)}}},u=function(e){var r=e.post;return function(e,t,n){try{return Promise.resolve(r("/customers/"+e+"/googleAds:search",{query:"SELECT campaign.id, ad_group_criterion.keyword.text, ad_group_criterion.status FROM ad_group_criterion WHERE campaign.id = '"+t+"' AND ad_group_criterion.type = 'KEYWORD' AND ad_group_criterion.status = 'ENABLED'"},n)).then(function(e){var r=e.results;return(void 0===r?[]:r).map(function(e){return e.adGroupCriterion.keyword.text})})}catch(e){return Promise.reject(e)}}};module.exports=function(e){var t,c,s=function(e){var t=e.clientId,n=e.clientSecret,o=e.developerToken,a=function(e,r){if(null==e)return{};var t,n,o={},a=Object.keys(e);for(n=0;n<a.length;n++)r.indexOf(t=a[n])>=0||(o[t]=e[t]);return o}(e,["clientId","clientSecret","developerToken"]),i=function(e){void 0===e&&(e=3600);var r={},t=function(e){var t=r[e];if(t){var n=Date.now();if(t.inserted+1e3*t.maxAge>n)return t.value;delete r[e]}};return{get:t,set:function(t,n,o){r[t]={value:n,maxAge:o||e,inserted:Date.now()}},has:function(e){return void 0!==t(e)}}}(1800),u=function(e,u,c,s){try{return void 0===s&&(s=a.refreshToken),Promise.resolve(function(e){try{return i.has(e)||i.set(e,function(e){try{return Promise.resolve(r("https://www.googleapis.com/oauth2/v4/token",{method:"POST",body:JSON.stringify({client_id:t,client_secret:n,refresh_token:e,grant_type:"refresh_token"})}).then(function(e){return e.json()}).then(function(e){return e.access_token}))}catch(e){return Promise.reject(e)}}(e)),Promise.resolve(i.get(e))}catch(e){return Promise.reject(e)}}(s)).then(function(t){return Promise.resolve(r("https://googleads.googleapis.com/v6"+u,{method:e,headers:{"Content-Type":"application/json",Authorization:"Bearer "+t,"Developer-Token":o},body:c?JSON.stringify(c):null})).then(function(e){if(404===e.status)throw new Error("404 "+u);return Promise.resolve(e.json()).then(function(e){if(e.error)throw new Error(JSON.stringify(e.error));return e})})})}catch(e){return Promise.reject(e)}};return{get:function(e,r,t){return u("GET",e,r,t)},post:function(e,r,t){return u("POST",e,r,t)}}}(e);return{listCustomers:(t=s,c=t.get,function(e){try{return Promise.resolve(c("/customers:listAccessibleCustomers",null,e)).then(function(r){var t=r.resourceNames.map(function(e){return e.replace("customers/","")});return Promise.resolve(Promise.all(t.map(function(r){return c("/customers/"+r,null,e).then(function(e){return{id:r,name:e.descriptiveName,manager:e.manager,testAccount:e.testAccount}}).catch(function(e){return null})})).then(function(e){return e.filter(function(e){return null!==e})}))})}catch(e){return Promise.reject(e)}}),listCampaigns:n(s),listKeywords:u(s),createCampaign:o(s),updateCampaigns:a(s),deleteCampaigns:i(s)}};
//# sourceMappingURL=googleads.js.map

@@ -1,2 +0,2 @@

import e from"node-fetch";let t=process.env.GOOGLE_CLIENT_ID,a=process.env.GOOGLE_CLIENT_SECRET,r=process.env.GOOGLE_DEVELOPER_TOKEN,n=process.env.GOOGLE_REFRESH_TOKEN;const s=e=>{e.clientId&&(t=e.clientId),e.clientSecret&&(a=e.clientSecret),e.developerToken&&(r=e.developerToken),e.refreshToken&&(n=e.refreshToken)},o=((e=3600)=>{const t={},a=e=>{const a=t[e];if(a){const r=Date.now();if(a.inserted+1e3*a.maxAge>r)return a.value;delete t[e]}};return{get:a,set:(a,r,n)=>{t[a]={value:r,maxAge:n||e,inserted:Date.now()}},has:e=>void 0!==a(e)}})(1800),c=async(s,c,i,p=n)=>{const u=await(async(r="")=>(o.has(r)||o.set(r,(async r=>e("https://www.googleapis.com/oauth2/v4/token",{method:"POST",body:JSON.stringify({client_id:t,client_secret:a,refresh_token:r,grant_type:"refresh_token"})}).then(e=>e.json()).then(e=>e.access_token))(r)),o.get(r)))(p),m=await e("https://googleads.googleapis.com/v6"+c,{method:s,headers:{"Content-Type":"application/json",Authorization:"Bearer "+u,"Developer-Token":r},body:i?JSON.stringify(i):null});if(404===m.status)throw new Error("404 "+c);const g=await m.json();if(g.error)throw new Error(JSON.stringify(g.error));return g},i=async(e,t,a)=>c("GET",e,t,a),p=async(e,t,a)=>c("POST",e,t,a),u=async e=>{const{resourceNames:t}=await i("/customers:listAccessibleCustomers",null,e),a=t.map(e=>e.replace("customers/",""));return await Promise.all(a.map(t=>i("/customers/"+t,null,e).then(e=>({id:t,name:e.descriptiveName,manager:e.manager,testAccount:e.testAccount})).catch(e=>null))).then(e=>e.filter(e=>null!==e))},m=async(e,t)=>{const{results:a=[]}=await p(`/customers/${e}/googleAds:search`,{query:"SELECT campaign.id, campaign.name, campaign.status FROM campaign"},t);return a.map(e=>({id:e.campaign.id,name:e.campaign.name}))},g=async(e,t,a)=>{const{results:r=[]}=await p(`/customers/${e}/googleAds:search`,{query:`SELECT campaign.id, ad_group_criterion.keyword.text, ad_group_criterion.status FROM ad_group_criterion WHERE campaign.id = '${t}' AND ad_group_criterion.type = 'KEYWORD' AND ad_group_criterion.status = 'ENABLED'`},a);return r.map(e=>e.adGroupCriterion.keyword.text)},l=async(e,t)=>{const a=[{campaignBudgetOperation:{create:{resourceName:`customers/${e}/campaignBudgets/-1`,explicitlyShared:!1,period:"DAILY",status:"ENABLED",amountMicros:13e6}}},{campaignOperation:{create:{resourceName:`customers/${e}/campaigns/-2`,name:"Test campaign MOFO",status:"PAUSED",campaignBudget:`customers/${e}/campaignBudgets/-1`,manualCpc:{enhancedCpcEnabled:!1},advertisingChannelType:"SEARCH",networkSettings:{targetGoogleSearch:!0,targetSearchNetwork:!0,targetContentNetwork:!0,targetPartnerSearchNetwork:!1}}}},{adGroupOperation:{create:{name:"Ad group 1",campaign:`customers/${e}/campaigns/-2`}}}],r=await p(`/customers/${e}/googleAds:mutate`,{mutateOperations:a},t);console.log(r)};function d(){return(d=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var r in a)Object.prototype.hasOwnProperty.call(a,r)&&(e[r]=a[r])}return e}).apply(this,arguments)}const h=async(e,t,a,r)=>{const n=t.map(t=>({updateMask:Object.keys(a).join(","),update:d({resourceName:`customers/${e}/campaigns/${t}`},a)})),s=await p(`/customers/${e}/campaigns:mutate`,{operations:n},r);console.log(JSON.stringify(s,null,2))},E=async(e,t,a)=>{const r=t.map(t=>({remove:`customers/${e}/campaigns/${t}`})),n=await p(`/customers/${e}/campaigns:mutate`,{operations:r},a);console.log(JSON.stringify(n,null,2))};export{t as clientId,a as clientSecret,s as config,l as createCampaign,n as defaultRefreshToken,E as deleteCampaigns,r as developerToken,m as listCampaigns,u as listCustomers,g as listKeywords,h as updateCampaigns};
import e from"node-fetch";function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var r in a)Object.prototype.hasOwnProperty.call(a,r)&&(e[r]=a[r])}return e}).apply(this,arguments)}const a=({get:e})=>async t=>{const{resourceNames:a}=await e("/customers:listAccessibleCustomers",null,t),r=a.map(e=>e.replace("customers/",""));return await Promise.all(r.map(a=>e("/customers/"+a,null,t).then(e=>({id:a,name:e.descriptiveName,manager:e.manager,testAccount:e.testAccount})).catch(e=>null))).then(e=>e.filter(e=>null!==e))},r=({post:e})=>async(t,a)=>{const{results:r=[]}=await e(`/customers/${t}/googleAds:search`,{query:"SELECT campaign.id, campaign.name, campaign.status FROM campaign"},a);return r.map(e=>({id:e.campaign.id,name:e.campaign.name}))},n=({post:e})=>async(t,a)=>{const r=[{campaignBudgetOperation:{create:{resourceName:`customers/${t}/campaignBudgets/-1`,explicitlyShared:!1,period:"DAILY",status:"ENABLED",amountMicros:13e6}}},{campaignOperation:{create:{resourceName:`customers/${t}/campaigns/-2`,name:"Test campaign MOFO",status:"PAUSED",campaignBudget:`customers/${t}/campaignBudgets/-1`,manualCpc:{enhancedCpcEnabled:!1},advertisingChannelType:"SEARCH",networkSettings:{targetGoogleSearch:!0,targetSearchNetwork:!0,targetContentNetwork:!0,targetPartnerSearchNetwork:!1}}}},{adGroupOperation:{create:{name:"Ad group 1",campaign:`customers/${t}/campaigns/-2`}}}],n=await e(`/customers/${t}/googleAds:mutate`,{mutateOperations:r},a);console.log(n)},s=({post:e})=>async(a,r,n,s)=>{const o=r.map(e=>({updateMask:Object.keys(n).join(","),update:t({resourceName:`customers/${a}/campaigns/${e}`},n)})),c=await e(`/customers/${a}/campaigns:mutate`,{operations:o},s);console.log(JSON.stringify(c,null,2))},o=({post:e})=>async(t,a,r)=>{const n=a.map(e=>({remove:`customers/${t}/campaigns/${e}`})),s=await e(`/customers/${t}/campaigns:mutate`,{operations:n},r);console.log(JSON.stringify(s,null,2))},c=({post:e})=>async(t,a,r)=>{const{results:n=[]}=await e(`/customers/${t}/googleAds:search`,{query:`SELECT campaign.id, ad_group_criterion.keyword.text, ad_group_criterion.status FROM ad_group_criterion WHERE campaign.id = '${a}' AND ad_group_criterion.type = 'KEYWORD' AND ad_group_criterion.status = 'ENABLED'`},r);return n.map(e=>e.adGroupCriterion.keyword.text)};export default function(t){const i=(t=>{let{clientId:a,clientSecret:r,developerToken:n}=t,s=function(e,t){if(null==e)return{};var a,r,n={},s=Object.keys(e);for(r=0;r<s.length;r++)t.indexOf(a=s[r])>=0||(n[a]=e[a]);return n}(t,["clientId","clientSecret","developerToken"]);const o=((e=3600)=>{const t={},a=e=>{const a=t[e];if(a){const r=Date.now();if(a.inserted+1e3*a.maxAge>r)return a.value;delete t[e]}};return{get:a,set:(a,r,n)=>{t[a]={value:r,maxAge:n||e,inserted:Date.now()}},has:e=>void 0!==a(e)}})(1800),c=async(t,c,i,u=s.refreshToken)=>{const p=await(async t=>(o.has(t)||o.set(t,(async t=>e("https://www.googleapis.com/oauth2/v4/token",{method:"POST",body:JSON.stringify({client_id:a,client_secret:r,refresh_token:t,grant_type:"refresh_token"})}).then(e=>e.json()).then(e=>e.access_token))(t)),o.get(t)))(u),m=await e("https://googleads.googleapis.com/v6"+c,{method:t,headers:{"Content-Type":"application/json",Authorization:"Bearer "+p,"Developer-Token":n},body:i?JSON.stringify(i):null});if(404===m.status)throw new Error("404 "+c);const g=await m.json();if(g.error)throw new Error(JSON.stringify(g.error));return g};return{get:async(e,t,a)=>c("GET",e,t,a),post:async(e,t,a)=>c("POST",e,t,a)}})(t);return{listCustomers:a(i),listCampaigns:r(i),listKeywords:c(i),createCampaign:n(i),updateCampaigns:s(i),deleteCampaigns:o(i)}}
//# sourceMappingURL=googleads.modern.js.map

@@ -1,2 +0,2 @@

import e from"node-fetch";var r=process.env.GOOGLE_CLIENT_ID,t=process.env.GOOGLE_CLIENT_SECRET,n=process.env.GOOGLE_DEVELOPER_TOKEN,o=process.env.GOOGLE_REFRESH_TOKEN,c=function(e){e.clientId&&(r=e.clientId),e.clientSecret&&(t=e.clientSecret),e.developerToken&&(n=e.developerToken),e.refreshToken&&(o=e.refreshToken)},a=function(e){void 0===e&&(e=3600);var r={},t=function(e){var t=r[e];if(t){var n=Date.now();if(t.inserted+1e3*t.maxAge>n)return t.value;delete r[e]}};return{get:t,set:function(t,n,o){r[t]={value:n,maxAge:o||e,inserted:Date.now()}},has:function(e){return void 0!==t(e)}}}(1800),i=function(c,i,s,u){void 0===u&&(u=o);try{return Promise.resolve(function(n){void 0===n&&(n="");try{return a.has(n)||a.set(n,function(n){try{return Promise.resolve(e("https://www.googleapis.com/oauth2/v4/token",{method:"POST",body:JSON.stringify({client_id:r,client_secret:t,refresh_token:n,grant_type:"refresh_token"})}).then(function(e){return e.json()}).then(function(e){return e.access_token}))}catch(e){return Promise.reject(e)}}(n)),Promise.resolve(a.get(n))}catch(e){return Promise.reject(e)}}(u)).then(function(r){return Promise.resolve(e("https://googleads.googleapis.com/v6"+i,{method:c,headers:{"Content-Type":"application/json",Authorization:"Bearer "+r,"Developer-Token":n},body:s?JSON.stringify(s):null})).then(function(e){if(404===e.status)throw new Error("404 "+i);return Promise.resolve(e.json()).then(function(e){if(e.error)throw new Error(JSON.stringify(e.error));return e})})})}catch(e){return Promise.reject(e)}},s=function(e,r,t){return i("GET",e,r,t)},u=function(e,r,t){return i("POST",e,r,t)},m=function(e){try{return Promise.resolve(s("/customers:listAccessibleCustomers",null,e)).then(function(r){var t=r.resourceNames.map(function(e){return e.replace("customers/","")});return Promise.resolve(Promise.all(t.map(function(r){return s("/customers/"+r,null,e).then(function(e){return{id:r,name:e.descriptiveName,manager:e.manager,testAccount:e.testAccount}}).catch(function(e){return null})})).then(function(e){return e.filter(function(e){return null!==e})}))})}catch(e){return Promise.reject(e)}},p=function(e,r){try{return Promise.resolve(u("/customers/"+e+"/googleAds:search",{query:"SELECT campaign.id, campaign.name, campaign.status FROM campaign"},r)).then(function(e){var r=e.results;return(void 0===r?[]:r).map(function(e){return{id:e.campaign.id,name:e.campaign.name}})})}catch(e){return Promise.reject(e)}},l=function(e,r,t){try{return Promise.resolve(u("/customers/"+e+"/googleAds:search",{query:"SELECT campaign.id, ad_group_criterion.keyword.text, ad_group_criterion.status FROM ad_group_criterion WHERE campaign.id = '"+r+"' AND ad_group_criterion.type = 'KEYWORD' AND ad_group_criterion.status = 'ENABLED'"},t)).then(function(e){var r=e.results;return(void 0===r?[]:r).map(function(e){return e.adGroupCriterion.keyword.text})})}catch(e){return Promise.reject(e)}},g=function(e,r){try{return Promise.resolve(u("/customers/"+e+"/googleAds:mutate",{mutateOperations:[{campaignBudgetOperation:{create:{resourceName:"customers/"+e+"/campaignBudgets/-1",explicitlyShared:!1,period:"DAILY",status:"ENABLED",amountMicros:13e6}}},{campaignOperation:{create:{resourceName:"customers/"+e+"/campaigns/-2",name:"Test campaign MOFO",status:"PAUSED",campaignBudget:"customers/"+e+"/campaignBudgets/-1",manualCpc:{enhancedCpcEnabled:!1},advertisingChannelType:"SEARCH",networkSettings:{targetGoogleSearch:!0,targetSearchNetwork:!0,targetContentNetwork:!0,targetPartnerSearchNetwork:!1}}}},{adGroupOperation:{create:{name:"Ad group 1",campaign:"customers/"+e+"/campaigns/-2"}}}]},r)).then(function(e){console.log(e)})}catch(e){return Promise.reject(e)}};function f(){return(f=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}var d=function(e,r,t,n){try{var o=r.map(function(r){return{updateMask:Object.keys(t).join(","),update:f({resourceName:"customers/"+e+"/campaigns/"+r},t)}});return Promise.resolve(u("/customers/"+e+"/campaigns:mutate",{operations:o},n)).then(function(e){console.log(JSON.stringify(e,null,2))})}catch(e){return Promise.reject(e)}},h=function(e,r,t){try{var n=r.map(function(r){return{remove:"customers/"+e+"/campaigns/"+r}});return Promise.resolve(u("/customers/"+e+"/campaigns:mutate",{operations:n},t)).then(function(e){console.log(JSON.stringify(e,null,2))})}catch(e){return Promise.reject(e)}};export{r as clientId,t as clientSecret,c as config,g as createCampaign,o as defaultRefreshToken,h as deleteCampaigns,n as developerToken,p as listCampaigns,m as listCustomers,l as listKeywords,d as updateCampaigns};
import e from"node-fetch";function r(){return(r=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}var t=function(e){var r=e.post;return function(e,t){try{return Promise.resolve(r("/customers/"+e+"/googleAds:search",{query:"SELECT campaign.id, campaign.name, campaign.status FROM campaign"},t)).then(function(e){var r=e.results;return(void 0===r?[]:r).map(function(e){return{id:e.campaign.id,name:e.campaign.name}})})}catch(e){return Promise.reject(e)}}},n=function(e){var r=e.post;return function(e,t){try{return Promise.resolve(r("/customers/"+e+"/googleAds:mutate",{mutateOperations:[{campaignBudgetOperation:{create:{resourceName:"customers/"+e+"/campaignBudgets/-1",explicitlyShared:!1,period:"DAILY",status:"ENABLED",amountMicros:13e6}}},{campaignOperation:{create:{resourceName:"customers/"+e+"/campaigns/-2",name:"Test campaign MOFO",status:"PAUSED",campaignBudget:"customers/"+e+"/campaignBudgets/-1",manualCpc:{enhancedCpcEnabled:!1},advertisingChannelType:"SEARCH",networkSettings:{targetGoogleSearch:!0,targetSearchNetwork:!0,targetContentNetwork:!0,targetPartnerSearchNetwork:!1}}}},{adGroupOperation:{create:{name:"Ad group 1",campaign:"customers/"+e+"/campaigns/-2"}}}]},t)).then(function(e){console.log(e)})}catch(e){return Promise.reject(e)}}},o=function(e){var t=e.post;return function(e,n,o,a){try{var i=n.map(function(t){return{updateMask:Object.keys(o).join(","),update:r({resourceName:"customers/"+e+"/campaigns/"+t},o)}});return Promise.resolve(t("/customers/"+e+"/campaigns:mutate",{operations:i},a)).then(function(e){console.log(JSON.stringify(e,null,2))})}catch(e){return Promise.reject(e)}}},a=function(e){var r=e.post;return function(e,t,n){try{var o=t.map(function(r){return{remove:"customers/"+e+"/campaigns/"+r}});return Promise.resolve(r("/customers/"+e+"/campaigns:mutate",{operations:o},n)).then(function(e){console.log(JSON.stringify(e,null,2))})}catch(e){return Promise.reject(e)}}},i=function(e){var r=e.post;return function(e,t,n){try{return Promise.resolve(r("/customers/"+e+"/googleAds:search",{query:"SELECT campaign.id, ad_group_criterion.keyword.text, ad_group_criterion.status FROM ad_group_criterion WHERE campaign.id = '"+t+"' AND ad_group_criterion.type = 'KEYWORD' AND ad_group_criterion.status = 'ENABLED'"},n)).then(function(e){var r=e.results;return(void 0===r?[]:r).map(function(e){return e.adGroupCriterion.keyword.text})})}catch(e){return Promise.reject(e)}}};export default function(r){var c,u,s=function(r){var t=r.clientId,n=r.clientSecret,o=r.developerToken,a=function(e,r){if(null==e)return{};var t,n,o={},a=Object.keys(e);for(n=0;n<a.length;n++)r.indexOf(t=a[n])>=0||(o[t]=e[t]);return o}(r,["clientId","clientSecret","developerToken"]),i=function(e){void 0===e&&(e=3600);var r={},t=function(e){var t=r[e];if(t){var n=Date.now();if(t.inserted+1e3*t.maxAge>n)return t.value;delete r[e]}};return{get:t,set:function(t,n,o){r[t]={value:n,maxAge:o||e,inserted:Date.now()}},has:function(e){return void 0!==t(e)}}}(1800),c=function(r,c,u,s){try{return void 0===s&&(s=a.refreshToken),Promise.resolve(function(r){try{return i.has(r)||i.set(r,function(r){try{return Promise.resolve(e("https://www.googleapis.com/oauth2/v4/token",{method:"POST",body:JSON.stringify({client_id:t,client_secret:n,refresh_token:r,grant_type:"refresh_token"})}).then(function(e){return e.json()}).then(function(e){return e.access_token}))}catch(e){return Promise.reject(e)}}(r)),Promise.resolve(i.get(r))}catch(e){return Promise.reject(e)}}(s)).then(function(t){return Promise.resolve(e("https://googleads.googleapis.com/v6"+c,{method:r,headers:{"Content-Type":"application/json",Authorization:"Bearer "+t,"Developer-Token":o},body:u?JSON.stringify(u):null})).then(function(e){if(404===e.status)throw new Error("404 "+c);return Promise.resolve(e.json()).then(function(e){if(e.error)throw new Error(JSON.stringify(e.error));return e})})})}catch(e){return Promise.reject(e)}};return{get:function(e,r,t){return c("GET",e,r,t)},post:function(e,r,t){return c("POST",e,r,t)}}}(r);return{listCustomers:(c=s,u=c.get,function(e){try{return Promise.resolve(u("/customers:listAccessibleCustomers",null,e)).then(function(r){var t=r.resourceNames.map(function(e){return e.replace("customers/","")});return Promise.resolve(Promise.all(t.map(function(r){return u("/customers/"+r,null,e).then(function(e){return{id:r,name:e.descriptiveName,manager:e.manager,testAccount:e.testAccount}}).catch(function(e){return null})})).then(function(e){return e.filter(function(e){return null!==e})}))})}catch(e){return Promise.reject(e)}}),listCampaigns:t(s),listKeywords:i(s),createCampaign:n(s),updateCampaigns:o(s),deleteCampaigns:a(s)}}
//# sourceMappingURL=googleads.module.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("node-fetch")):"function"==typeof define&&define.amd?define(["exports","node-fetch"],t):t((e=e||self).googleads={},e.nodeFetch)}(this,function(e,t){t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t,e.clientId=process.env.GOOGLE_CLIENT_ID,e.clientSecret=process.env.GOOGLE_CLIENT_SECRET,e.developerToken=process.env.GOOGLE_DEVELOPER_TOKEN,e.defaultRefreshToken=process.env.GOOGLE_REFRESH_TOKEN;var r=function(e){void 0===e&&(e=3600);var t={},r=function(e){var r=t[e];if(r){var n=Date.now();if(r.inserted+1e3*r.maxAge>n)return r.value;delete t[e]}};return{get:r,set:function(r,n,o){t[r]={value:n,maxAge:o||e,inserted:Date.now()}},has:function(e){return void 0!==r(e)}}}(1800),n=function(n,o,i,c){void 0===c&&(c=e.defaultRefreshToken);try{return Promise.resolve(function(n){void 0===n&&(n="");try{return r.has(n)||r.set(n,function(r){try{return Promise.resolve(t("https://www.googleapis.com/oauth2/v4/token",{method:"POST",body:JSON.stringify({client_id:e.clientId,client_secret:e.clientSecret,refresh_token:r,grant_type:"refresh_token"})}).then(function(e){return e.json()}).then(function(e){return e.access_token}))}catch(e){return Promise.reject(e)}}(n)),Promise.resolve(r.get(n))}catch(e){return Promise.reject(e)}}(c)).then(function(r){return Promise.resolve(t("https://googleads.googleapis.com/v6"+o,{method:n,headers:{"Content-Type":"application/json",Authorization:"Bearer "+r,"Developer-Token":e.developerToken},body:i?JSON.stringify(i):null})).then(function(e){if(404===e.status)throw new Error("404 "+o);return Promise.resolve(e.json()).then(function(e){if(e.error)throw new Error(JSON.stringify(e.error));return e})})})}catch(e){return Promise.reject(e)}},o=function(e,t,r){return n("GET",e,t,r)},i=function(e,t,r){return n("POST",e,t,r)};function c(){return(c=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}e.config=function(t){t.clientId&&(e.clientId=t.clientId),t.clientSecret&&(e.clientSecret=t.clientSecret),t.developerToken&&(e.developerToken=t.developerToken),t.refreshToken&&(e.defaultRefreshToken=t.refreshToken)},e.createCampaign=function(e,t){try{return Promise.resolve(i("/customers/"+e+"/googleAds:mutate",{mutateOperations:[{campaignBudgetOperation:{create:{resourceName:"customers/"+e+"/campaignBudgets/-1",explicitlyShared:!1,period:"DAILY",status:"ENABLED",amountMicros:13e6}}},{campaignOperation:{create:{resourceName:"customers/"+e+"/campaigns/-2",name:"Test campaign MOFO",status:"PAUSED",campaignBudget:"customers/"+e+"/campaignBudgets/-1",manualCpc:{enhancedCpcEnabled:!1},advertisingChannelType:"SEARCH",networkSettings:{targetGoogleSearch:!0,targetSearchNetwork:!0,targetContentNetwork:!0,targetPartnerSearchNetwork:!1}}}},{adGroupOperation:{create:{name:"Ad group 1",campaign:"customers/"+e+"/campaigns/-2"}}}]},t)).then(function(e){console.log(e)})}catch(e){return Promise.reject(e)}},e.deleteCampaigns=function(e,t,r){try{var n=t.map(function(t){return{remove:"customers/"+e+"/campaigns/"+t}});return Promise.resolve(i("/customers/"+e+"/campaigns:mutate",{operations:n},r)).then(function(e){console.log(JSON.stringify(e,null,2))})}catch(e){return Promise.reject(e)}},e.listCampaigns=function(e,t){try{return Promise.resolve(i("/customers/"+e+"/googleAds:search",{query:"SELECT campaign.id, campaign.name, campaign.status FROM campaign"},t)).then(function(e){var t=e.results;return(void 0===t?[]:t).map(function(e){return{id:e.campaign.id,name:e.campaign.name}})})}catch(e){return Promise.reject(e)}},e.listCustomers=function(e){try{return Promise.resolve(o("/customers:listAccessibleCustomers",null,e)).then(function(t){var r=t.resourceNames.map(function(e){return e.replace("customers/","")});return Promise.resolve(Promise.all(r.map(function(t){return o("/customers/"+t,null,e).then(function(e){return{id:t,name:e.descriptiveName,manager:e.manager,testAccount:e.testAccount}}).catch(function(e){return null})})).then(function(e){return e.filter(function(e){return null!==e})}))})}catch(e){return Promise.reject(e)}},e.listKeywords=function(e,t,r){try{return Promise.resolve(i("/customers/"+e+"/googleAds:search",{query:"SELECT campaign.id, ad_group_criterion.keyword.text, ad_group_criterion.status FROM ad_group_criterion WHERE campaign.id = '"+t+"' AND ad_group_criterion.type = 'KEYWORD' AND ad_group_criterion.status = 'ENABLED'"},r)).then(function(e){var t=e.results;return(void 0===t?[]:t).map(function(e){return e.adGroupCriterion.keyword.text})})}catch(e){return Promise.reject(e)}},e.updateCampaigns=function(e,t,r,n){try{var o=t.map(function(t){return{updateMask:Object.keys(r).join(","),update:c({resourceName:"customers/"+e+"/campaigns/"+t},r)}});return Promise.resolve(i("/customers/"+e+"/campaigns:mutate",{operations:o},n)).then(function(e){console.log(JSON.stringify(e,null,2))})}catch(e){return Promise.reject(e)}}});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("node-fetch")):"function"==typeof define&&define.amd?define(["node-fetch"],t):(e=e||self).googleads=t(e.nodeFetch)}(this,function(e){function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;var r=function(e){var t=e.post;return function(e,r){try{return Promise.resolve(t("/customers/"+e+"/googleAds:search",{query:"SELECT campaign.id, campaign.name, campaign.status FROM campaign"},r)).then(function(e){var t=e.results;return(void 0===t?[]:t).map(function(e){return{id:e.campaign.id,name:e.campaign.name}})})}catch(e){return Promise.reject(e)}}},n=function(e){var t=e.post;return function(e,r){try{return Promise.resolve(t("/customers/"+e+"/googleAds:mutate",{mutateOperations:[{campaignBudgetOperation:{create:{resourceName:"customers/"+e+"/campaignBudgets/-1",explicitlyShared:!1,period:"DAILY",status:"ENABLED",amountMicros:13e6}}},{campaignOperation:{create:{resourceName:"customers/"+e+"/campaigns/-2",name:"Test campaign MOFO",status:"PAUSED",campaignBudget:"customers/"+e+"/campaignBudgets/-1",manualCpc:{enhancedCpcEnabled:!1},advertisingChannelType:"SEARCH",networkSettings:{targetGoogleSearch:!0,targetSearchNetwork:!0,targetContentNetwork:!0,targetPartnerSearchNetwork:!1}}}},{adGroupOperation:{create:{name:"Ad group 1",campaign:"customers/"+e+"/campaigns/-2"}}}]},r)).then(function(e){console.log(e)})}catch(e){return Promise.reject(e)}}},o=function(e){var r=e.post;return function(e,n,o,a){try{var i=n.map(function(r){return{updateMask:Object.keys(o).join(","),update:t({resourceName:"customers/"+e+"/campaigns/"+r},o)}});return Promise.resolve(r("/customers/"+e+"/campaigns:mutate",{operations:i},a)).then(function(e){console.log(JSON.stringify(e,null,2))})}catch(e){return Promise.reject(e)}}},a=function(e){var t=e.post;return function(e,r,n){try{var o=r.map(function(t){return{remove:"customers/"+e+"/campaigns/"+t}});return Promise.resolve(t("/customers/"+e+"/campaigns:mutate",{operations:o},n)).then(function(e){console.log(JSON.stringify(e,null,2))})}catch(e){return Promise.reject(e)}}},i=function(e){var t=e.post;return function(e,r,n){try{return Promise.resolve(t("/customers/"+e+"/googleAds:search",{query:"SELECT campaign.id, ad_group_criterion.keyword.text, ad_group_criterion.status FROM ad_group_criterion WHERE campaign.id = '"+r+"' AND ad_group_criterion.type = 'KEYWORD' AND ad_group_criterion.status = 'ENABLED'"},n)).then(function(e){var t=e.results;return(void 0===t?[]:t).map(function(e){return e.adGroupCriterion.keyword.text})})}catch(e){return Promise.reject(e)}}};return function(t){var u,c,s=function(t){var r=t.clientId,n=t.clientSecret,o=t.developerToken,a=function(e,t){if(null==e)return{};var r,n,o={},a=Object.keys(e);for(n=0;n<a.length;n++)t.indexOf(r=a[n])>=0||(o[r]=e[r]);return o}(t,["clientId","clientSecret","developerToken"]),i=function(e){void 0===e&&(e=3600);var t={},r=function(e){var r=t[e];if(r){var n=Date.now();if(r.inserted+1e3*r.maxAge>n)return r.value;delete t[e]}};return{get:r,set:function(r,n,o){t[r]={value:n,maxAge:o||e,inserted:Date.now()}},has:function(e){return void 0!==r(e)}}}(1800),u=function(t,u,c,s){try{return void 0===s&&(s=a.refreshToken),Promise.resolve(function(t){try{return i.has(t)||i.set(t,function(t){try{return Promise.resolve(e("https://www.googleapis.com/oauth2/v4/token",{method:"POST",body:JSON.stringify({client_id:r,client_secret:n,refresh_token:t,grant_type:"refresh_token"})}).then(function(e){return e.json()}).then(function(e){return e.access_token}))}catch(e){return Promise.reject(e)}}(t)),Promise.resolve(i.get(t))}catch(e){return Promise.reject(e)}}(s)).then(function(r){return Promise.resolve(e("https://googleads.googleapis.com/v6"+u,{method:t,headers:{"Content-Type":"application/json",Authorization:"Bearer "+r,"Developer-Token":o},body:c?JSON.stringify(c):null})).then(function(e){if(404===e.status)throw new Error("404 "+u);return Promise.resolve(e.json()).then(function(e){if(e.error)throw new Error(JSON.stringify(e.error));return e})})})}catch(e){return Promise.reject(e)}};return{get:function(e,t,r){return u("GET",e,t,r)},post:function(e,t,r){return u("POST",e,t,r)}}}(t);return{listCustomers:(u=s,c=u.get,function(e){try{return Promise.resolve(c("/customers:listAccessibleCustomers",null,e)).then(function(t){var r=t.resourceNames.map(function(e){return e.replace("customers/","")});return Promise.resolve(Promise.all(r.map(function(t){return c("/customers/"+t,null,e).then(function(e){return{id:t,name:e.descriptiveName,manager:e.manager,testAccount:e.testAccount}}).catch(function(e){return null})})).then(function(e){return e.filter(function(e){return null!==e})}))})}catch(e){return Promise.reject(e)}}),listCampaigns:r(s),listKeywords:i(s),createCampaign:n(s),updateCampaigns:o(s),deleteCampaigns:a(s)}}});
//# sourceMappingURL=googleads.umd.js.map
{
"name": "@honkandgo/googleads",
"version": "1.0.1",
"version": "2.0.0",
"license": "MIT",

@@ -15,8 +15,11 @@ "publishConfig": {

"dev": "microbundle watch",
"test": "node -r esm test.js",
"prepublishOnly": "yarn build"
},
"dependencies": {
"esm": "^3.2.25",
"node-fetch": "^2.6.1"
},
"devDependencies": {
"esm": "^3.2.25"
}
}

@@ -1,4 +0,2 @@

import { post } from './fetch'
export const createCampaign = async (customerId, refreshToken) => {
export const createCampaign = ({ post }) => async (customerId, refreshToken) => {
const mutateOperations = [

@@ -5,0 +3,0 @@ {

@@ -1,4 +0,2 @@

import { post } from './fetch'
export const deleteCampaigns = async (customerId, campaignIds, refreshToken) => {
export const deleteCampaigns = ({ post }) => async (customerId, campaignIds, refreshToken) => {
const operations = campaignIds.map((campaignId) => ({

@@ -5,0 +3,0 @@ remove: `customers/${customerId}/campaigns/${campaignId}`

@@ -1,7 +0,20 @@

export * from './config'
export * from './list-customers'
export * from './list-campaigns'
export * from './list-keywords'
export * from './create-campaign'
export * from './update-campaigns'
export * from './delete-campaigns'
import { makeApi } from './api'
import { listCustomers } from './list-customers'
import { listCampaigns } from './list-campaigns'
import { createCampaign } from './create-campaign'
import { updateCampaigns } from './update-campaigns'
import { deleteCampaigns } from './delete-campaigns'
import { listKeywords } from './list-keywords'
export default function GoogleAdsClient(options) {
const api = makeApi(options)
return {
listCustomers: listCustomers(api),
listCampaigns: listCampaigns(api),
listKeywords: listKeywords(api),
createCampaign: createCampaign(api),
updateCampaigns: updateCampaigns(api),
deleteCampaigns: deleteCampaigns(api)
}
}

@@ -1,4 +0,2 @@

import { post } from './fetch'
export const listCampaigns = async (customerId, refreshToken) => {
export const listCampaigns = ({ post }) => async (customerId, refreshToken) => {
const { results = [] } = await post(

@@ -5,0 +3,0 @@ `/customers/${customerId}/googleAds:search`,

@@ -1,4 +0,2 @@

import { get } from './fetch'
export const listCustomers = async (refreshToken) => {
export const listCustomers = ({ get }) => async (refreshToken) => {
const { resourceNames } = await get('/customers:listAccessibleCustomers', null, refreshToken)

@@ -5,0 +3,0 @@ const customerIds = resourceNames.map((resource) => resource.replace('customers/', ''))

@@ -1,4 +0,2 @@

import { post } from './fetch'
export const listKeywords = async (customerId, campaignId, refreshToken) => {
export const listKeywords = ({ post }) => async (customerId, campaignId, refreshToken) => {
const { results = [] } = await post(

@@ -5,0 +3,0 @@ `/customers/${customerId}/googleAds:search`,

@@ -1,2 +0,2 @@

export const newPool = (defaultMaxAge = 3600) => {
export const makePool = (defaultMaxAge = 3600) => {
const objects = {}

@@ -3,0 +3,0 @@

@@ -1,4 +0,7 @@

import { post } from './fetch'
export const updateCampaigns = async (customerId, campaignIds, params, refreshToken) => {
export const updateCampaigns = ({ post }) => async (
customerId,
campaignIds,
params,
refreshToken
) => {
const operations = campaignIds.map((campaignId) => ({

@@ -5,0 +8,0 @@ updateMask: Object.keys(params).join(','),

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc