apigee-x-module
Advanced tools
Comparing version 0.4.15 to 0.5.1
@@ -5,4 +5,3 @@ import { ApiProducts, ApiProduct, App, Developers, Developer, Apps, AppCredential } from "./apigee-types"; | ||
apigeeOrganization: string; | ||
jwtClient: any; | ||
constructor(email: string, key: string, org: string); | ||
constructor(org: string); | ||
getApiProducts(): Promise<ApiProducts>; | ||
@@ -25,3 +24,2 @@ createApiProduct(apiProduct: ApiProduct): Promise<ApiProduct>; | ||
deleteApp(email: string, appName: string): Promise<App>; | ||
getToken(): Promise<string>; | ||
} |
@@ -5,18 +5,17 @@ "use strict"; | ||
const axios = require('axios'); | ||
const { JWT } = require('google-auth-library'); | ||
const { GoogleAuth } = require('google-auth-library'); | ||
const auth = new GoogleAuth({ | ||
scopes: 'https://www.googleapis.com/auth/cloud-platform' | ||
}); | ||
class ApigeeService { | ||
constructor(email, key, org) { | ||
//client: any; | ||
constructor(org) { | ||
this.apigeeOrganization = org; | ||
this.jwtClient = new JWT(email, null, key.replace(/\\n/g, '\n'), ['https://www.googleapis.com/auth/cloud-platform']); | ||
} | ||
getApiProducts() { | ||
return new Promise((resolve, reject) => { | ||
this.getToken().then((token) => { | ||
axios({ | ||
"url": `https://apigee.googleapis.com/v1/organizations/${this.apigeeOrganization}/apiproducts?expand=true`, | ||
"method": "get", | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer " + token | ||
} | ||
auth.getClient().then((client) => { | ||
client.request({ | ||
url: `https://apigee.googleapis.com/v1/organizations/${this.apigeeOrganization}/apiproducts?expand=true`, | ||
method: 'GET' | ||
}).then((response) => { | ||
@@ -29,16 +28,17 @@ let apigeeProducts = response.data; | ||
let apiProduct = apigeeProduct; | ||
for (const attr of apigeeProduct.attributes) { | ||
if (attr.name === "image") | ||
apiProduct.imageUrl = attr.value; | ||
if (attr.name === "spec") | ||
apiProduct.specUrl = attr.value; | ||
if (attr.name === "access") | ||
apiProduct.access = attr.value; | ||
} | ||
if (apigeeProduct.attributes) | ||
for (const attr of apigeeProduct.attributes) { | ||
if (attr.name === "image") | ||
apiProduct.imageUrl = attr.value; | ||
if (attr.name === "spec") | ||
apiProduct.specUrl = attr.value; | ||
if (attr.name === "access") | ||
apiProduct.access = attr.value; | ||
} | ||
products.apiProducts.push(apiProduct); | ||
}); | ||
resolve(products); | ||
}).catch((error) => { | ||
reject(error); | ||
}); | ||
}).catch((error) => { | ||
reject(error); | ||
}); | ||
@@ -49,22 +49,22 @@ }); | ||
return new Promise((resolve, reject) => { | ||
this.getToken().then((token) => { | ||
axios({ | ||
"url": `https://apigee.googleapis.com/v1/organizations/${this.apigeeOrganization}/apiproducts`, | ||
"method": "post", | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer " + token | ||
auth.getClient().then((client) => { | ||
client.request({ | ||
url: `https://apigee.googleapis.com/v1/organizations/${this.apigeeOrganization}/apiproducts`, | ||
method: "post", | ||
headers: { | ||
"Content-Type": "application/json" | ||
}, | ||
"data": apiProduct | ||
data: apiProduct | ||
}).then((response) => { | ||
let apigeeApiProduct = response.data; | ||
let apiProduct = apigeeApiProduct; | ||
for (const attr of apigeeApiProduct.attributes) { | ||
if (attr.name === "image") | ||
apiProduct.imageUrl = attr.value; | ||
if (attr.name === "spec") | ||
apiProduct.specUrl = attr.value; | ||
if (attr.name === "access") | ||
apiProduct.access = attr.value; | ||
} | ||
if (apigeeApiProduct.attributes) | ||
for (const attr of apigeeApiProduct.attributes) { | ||
if (attr.name === "image") | ||
apiProduct.imageUrl = attr.value; | ||
if (attr.name === "spec") | ||
apiProduct.specUrl = attr.value; | ||
if (attr.name === "access") | ||
apiProduct.access = attr.value; | ||
} | ||
resolve(apiProduct); | ||
@@ -77,5 +77,2 @@ }).catch((error) => { | ||
}); | ||
}).catch((error) => { | ||
console.error(error); | ||
reject(error); | ||
}); | ||
@@ -86,9 +83,8 @@ }); | ||
return new Promise((resolve, reject) => { | ||
this.getToken().then((token) => { | ||
axios({ | ||
auth.getClient().then((client) => { | ||
client.request({ | ||
"url": `https://apigee.googleapis.com/v1/organizations/${this.apigeeOrganization}/apiproducts/${apiProductName}`, | ||
"method": "delete", | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer " + token | ||
"Content-Type": "application/json" | ||
} | ||
@@ -103,5 +99,2 @@ }).then((response) => { | ||
}); | ||
}).catch((error) => { | ||
console.error(error); | ||
reject(error); | ||
}); | ||
@@ -112,9 +105,8 @@ }); | ||
return new Promise((resolve, reject) => { | ||
this.getToken().then((token) => { | ||
axios({ | ||
auth.getClient().then((client) => { | ||
client.request({ | ||
"url": `https://apigee.googleapis.com/v1/organizations/${this.apigeeOrganization}/developers?expand=true`, | ||
"method": "get", | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer " + token | ||
"Content-Type": "application/json" | ||
} | ||
@@ -131,5 +123,2 @@ }).then((response) => { | ||
}); | ||
}).catch((error) => { | ||
console.error(error); | ||
reject(error); | ||
}); | ||
@@ -140,9 +129,8 @@ }); | ||
return new Promise((resolve, reject) => { | ||
this.getToken().then((token) => { | ||
axios({ | ||
auth.getClient().then((client) => { | ||
client.request({ | ||
"url": `https://apigee.googleapis.com/v1/organizations/${this.apigeeOrganization}/developers/${email}`, | ||
"method": "get", | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer " + token | ||
"Content-Type": "application/json" | ||
} | ||
@@ -160,5 +148,2 @@ }).then((response) => { | ||
}); | ||
}).catch((error) => { | ||
console.error(error); | ||
reject(error); | ||
}); | ||
@@ -169,9 +154,8 @@ }); | ||
return new Promise((resolve, reject) => { | ||
this.getToken().then((token) => { | ||
axios({ | ||
auth.getClient().then((client) => { | ||
client.request({ | ||
"url": `https://apigee.googleapis.com/v1/organizations/${this.apigeeOrganization}/developers`, | ||
"method": "post", | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer " + token | ||
"Content-Type": "application/json" | ||
}, | ||
@@ -190,5 +174,2 @@ "data": developerData | ||
}); | ||
}).catch((error) => { | ||
console.error(error); | ||
reject(error); | ||
}); | ||
@@ -199,9 +180,8 @@ }); | ||
return new Promise((resolve, reject) => { | ||
this.getToken().then((token) => { | ||
axios({ | ||
auth.getClient().then((client) => { | ||
client.request({ | ||
"url": `https://apigee.googleapis.com/v1/organizations/${this.apigeeOrganization}/developers/${developerData.email}`, | ||
"method": "put", | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer " + token | ||
"Content-Type": "application/json" | ||
}, | ||
@@ -217,5 +197,2 @@ "data": developerData | ||
}); | ||
}).catch((error) => { | ||
console.error(error); | ||
reject(error); | ||
}); | ||
@@ -226,9 +203,8 @@ }); | ||
return new Promise((resolve, reject) => { | ||
this.getToken().then((token) => { | ||
axios({ | ||
auth.getClient().then((client) => { | ||
client.request({ | ||
"url": `https://apigee.googleapis.com/v1/organizations/${this.apigeeOrganization}/developers/${email}`, | ||
"method": "delete", | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer " + token | ||
"Content-Type": "application/json" | ||
} | ||
@@ -243,5 +219,2 @@ }).then((response) => { | ||
}); | ||
}).catch((error) => { | ||
console.error(error); | ||
reject(error); | ||
}); | ||
@@ -252,9 +225,8 @@ }); | ||
return new Promise((resolve, reject) => { | ||
this.getToken().then((token) => { | ||
axios({ | ||
auth.getClient().then((client) => { | ||
client.request({ | ||
"url": `https://apigee.googleapis.com/v1/organizations/${this.apigeeOrganization}/developers/${email}/apps?expand=true`, | ||
"method": "get", | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer " + token | ||
"Content-Type": "application/json" | ||
} | ||
@@ -279,5 +251,2 @@ }).then((response) => { | ||
}); | ||
}).catch((error) => { | ||
console.error(error); | ||
reject(error); | ||
}); | ||
@@ -288,9 +257,8 @@ }); | ||
return new Promise((resolve, reject) => { | ||
this.getToken().then((token) => { | ||
axios({ | ||
auth.getClient().then((client) => { | ||
client.request({ | ||
"url": `https://apigee.googleapis.com/v1/organizations/${this.apigeeOrganization}/developers/${email}/apps`, | ||
"method": "post", | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer " + token | ||
"Content-Type": "application/json" | ||
}, | ||
@@ -311,5 +279,2 @@ "data": { | ||
}); | ||
}).catch((error) => { | ||
console.error(error); | ||
reject(error); | ||
}); | ||
@@ -320,9 +285,8 @@ }); | ||
return new Promise((resolve, reject) => { | ||
this.getToken().then((token) => { | ||
axios({ | ||
auth.getClient().then((client) => { | ||
client.request({ | ||
"url": `https://apigee.googleapis.com/v1/organizations/${this.apigeeOrganization}/developers/${email}/apps/${appName}`, | ||
"method": "get", | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer " + token | ||
"Content-Type": "application/json" | ||
} | ||
@@ -339,5 +303,2 @@ }).then((response) => { | ||
}); | ||
}).catch((error) => { | ||
console.error(error); | ||
reject(error); | ||
}); | ||
@@ -348,9 +309,8 @@ }); | ||
return new Promise((resolve, reject) => { | ||
this.getToken().then((token) => { | ||
axios({ | ||
auth.getClient().then((client) => { | ||
client.request({ | ||
"url": `https://apigee.googleapis.com/v1/organizations/${this.apigeeOrganization}/developers/${email}/apps/${appName}`, | ||
"method": "put", | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer " + token | ||
"Content-Type": "application/json" | ||
}, | ||
@@ -368,5 +328,2 @@ "data": app | ||
}); | ||
}).catch((error) => { | ||
console.error(error); | ||
reject(error); | ||
}); | ||
@@ -377,9 +334,8 @@ }); | ||
return new Promise((resolve, reject) => { | ||
this.getToken().then((token) => { | ||
axios({ | ||
auth.getClient().then((client) => { | ||
client.request({ | ||
"url": `https://apigee.googleapis.com/v1/organizations/${this.apigeeOrganization}/developers/${email}/apps/${appName}/keys/${keyName}`, | ||
"method": "get", | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer " + token | ||
"Content-Type": "application/json" | ||
} | ||
@@ -396,5 +352,2 @@ }).then((response) => { | ||
}); | ||
}).catch((error) => { | ||
console.error(error); | ||
reject(error); | ||
}); | ||
@@ -425,9 +378,8 @@ }); | ||
key.apiProducts = newProductsArray; | ||
this.getToken().then((token) => { | ||
axios({ | ||
auth.getClient().then((client) => { | ||
client.request({ | ||
"url": `https://apigee.googleapis.com/v1/organizations/${this.apigeeOrganization}/developers/${email}/apps/${appName}/keys/${key.consumerKey}`, | ||
"method": "put", | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer " + token | ||
"Content-Type": "application/json" | ||
}, | ||
@@ -445,6 +397,6 @@ "data": key | ||
}); | ||
}).catch((error) => { | ||
console.error(error); | ||
reject(error); | ||
}); | ||
}).catch((error) => { | ||
console.error(error); | ||
reject(error); | ||
}); | ||
@@ -456,9 +408,8 @@ }); | ||
return new Promise((resolve, reject) => { | ||
this.getToken().then((token) => { | ||
axios({ | ||
auth.getClient().then((client) => { | ||
client.request({ | ||
"url": `https://apigee.googleapis.com/v1/organizations/${this.apigeeOrganization}/developers/${email}/apps/${appName}/keys/${keyName}`, | ||
"method": "post", | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer " + token | ||
"Content-Type": "application/json" | ||
}, | ||
@@ -478,5 +429,2 @@ "data": { | ||
}); | ||
}).catch((error) => { | ||
console.error(error); | ||
reject(error); | ||
}); | ||
@@ -487,9 +435,8 @@ }); | ||
return new Promise((resolve, reject) => { | ||
this.getToken().then((token) => { | ||
axios({ | ||
auth.getClient().then((client) => { | ||
client.request({ | ||
"url": `https://apigee.googleapis.com/v1/organizations/${this.apigeeOrganization}/developers/${email}/apps/${appName}/keys/${keyName}/apiproducts/${apiProduct}`, | ||
"method": "delete", | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer " + token | ||
"Content-Type": "application/json" | ||
} | ||
@@ -506,5 +453,2 @@ }).then((response) => { | ||
}); | ||
}).catch((error) => { | ||
console.error(error); | ||
reject(error); | ||
}); | ||
@@ -515,9 +459,8 @@ }); | ||
return new Promise((resolve, reject) => { | ||
this.getToken().then((token) => { | ||
axios({ | ||
auth.getClient().then((client) => { | ||
client.request({ | ||
"url": `https://apigee.googleapis.com/v1/organizations/${this.apigeeOrganization}/developers/${email}/apps/${appName}`, | ||
"method": "delete", | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer " + token | ||
"Content-Type": "application/json" | ||
} | ||
@@ -534,26 +477,6 @@ }).then((response) => { | ||
}); | ||
}).catch((error) => { | ||
console.error(error); | ||
reject(error); | ||
}); | ||
}); | ||
} | ||
getToken() { | ||
return new Promise((resolve, reject) => { | ||
this.jwtClient.authorize(function (error, tokens) { | ||
if (error) { | ||
console.log("Error making request to generate access token:", error); | ||
reject("Error getting token: " + error); | ||
} | ||
else if (tokens.access_token === null) { | ||
console.log("Provided service account does not have permission to generate access tokens"); | ||
reject("Error getting token."); | ||
} | ||
else { | ||
resolve(tokens.access_token); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
exports.ApigeeService = ApigeeService; |
{ | ||
"name": "apigee-x-module", | ||
"version": "0.4.15", | ||
"version": "0.5.1", | ||
"description": "Module for integrating with the Apigee X platform for TS/JS developer portal integrations.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/tyayers/apigee-x-module", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40265
644