@adastradev/serverless-discovery-sdk
Advanced tools
Comparing version 2.2.8-beta.1668533119402 to 2.2.8-beta.1668555334531
@@ -10,2 +10,11 @@ export declare class DiscoverySdk { | ||
lookupService(serviceName: string, stageName?: string, version?: string, externalID?: string, shouldInvalidateCache?: boolean): Promise<any>; | ||
checkIsCurrentVersion(service: string, configVersion: string, shouldInvalidateCache?: boolean): Promise<{ | ||
isLatest: boolean; | ||
currentVersion: string; | ||
URI?: undefined; | ||
} | { | ||
URI: string; | ||
isLatest: boolean; | ||
currentVersion: any; | ||
}>; | ||
} |
@@ -69,3 +69,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result, error, retriesLeft, e_1; | ||
var result; | ||
return __generator(this, function (_a) { | ||
@@ -92,28 +92,62 @@ switch (_a.label) { | ||
} | ||
retriesLeft = 3; | ||
_a.label = 1; | ||
return [4 /*yield*/, this.api.lookupService(serviceName, stageName, version, externalID, shouldInvalidateCache)]; | ||
case 1: | ||
if (!(!result && retriesLeft > 0)) return [3 /*break*/, 7]; | ||
_a.label = 2; | ||
result = _a.sent(); | ||
return [2 /*return*/, result.data.map(function (item) { return item.ServiceURL; })]; | ||
} | ||
}); | ||
}); | ||
}; | ||
DiscoverySdk.prototype.checkIsCurrentVersion = function (service, configVersion, shouldInvalidateCache) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var URI, thisVersion, err_1, versionSpec, latestVer, retVal, err_2; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, this.api.lookupService(service, undefined, configVersion, undefined, shouldInvalidateCache)]; | ||
case 1: | ||
thisVersion = _a.sent(); | ||
URI = thisVersion.data[0].ServiceURL; | ||
return [3 /*break*/, 3]; | ||
case 2: | ||
_a.trys.push([2, 4, , 6]); | ||
return [4 /*yield*/, this.api.lookupService(serviceName, stageName, version, externalID, shouldInvalidateCache)]; | ||
err_1 = _a.sent(); | ||
return [2 /*return*/, { | ||
isLatest: false, | ||
currentVersion: configVersion | ||
}]; | ||
case 3: | ||
result = _a.sent(); | ||
error = null; | ||
return [3 /*break*/, 6]; | ||
if (!!configVersion.includes('-')) return [3 /*break*/, 8]; | ||
versionSpec = configVersion.split('.')[0] + '.x'; | ||
latestVer = void 0; | ||
_a.label = 4; | ||
case 4: | ||
e_1 = _a.sent(); | ||
error = e_1; | ||
retriesLeft--; | ||
return [4 /*yield*/, delay(500)]; | ||
_a.trys.push([4, 6, , 7]); | ||
return [4 /*yield*/, this.api.lookupService(service, undefined, versionSpec, undefined, shouldInvalidateCache)]; | ||
case 5: | ||
_a.sent(); | ||
return [3 /*break*/, 6]; | ||
case 6: return [3 /*break*/, 1]; | ||
retVal = _a.sent(); | ||
if (retVal && Array.isArray(retVal.data) && retVal.data.length > 0) { | ||
latestVer = retVal.data[0].Version; | ||
URI = retVal.data[0].ServiceURL; | ||
} | ||
return [3 /*break*/, 7]; | ||
case 6: | ||
err_2 = _a.sent(); | ||
return [2 /*return*/, { | ||
isLatest: false, | ||
currentVersion: configVersion | ||
}]; | ||
case 7: | ||
if (error) { | ||
throw new Error(error.message); | ||
// check returned version against this configVersion. | ||
// if no results, allow to proceed. Is this the best way to handle? | ||
if (latestVer !== configVersion) { | ||
// no match or no latest version returned, throw/return error result | ||
return [2 /*return*/, { | ||
URI: URI, | ||
isLatest: false, | ||
currentVersion: latestVer | ||
}]; | ||
} | ||
return [2 /*return*/, result.data.map(function (item) { return item.ServiceURL; })]; | ||
_a.label = 8; | ||
case 8: return [2 /*return*/, { isLatest: true, currentVersion: configVersion, URI: URI }]; | ||
} | ||
@@ -120,0 +154,0 @@ }); |
@@ -16,20 +16,17 @@ "use strict"; | ||
var apigClientFactory = require('@adastradev/aws-api-gateway-client').default; // tslint:disable-line | ||
var retryOptions = { | ||
retries: 3, | ||
retryDelay: function () { return 500; }, | ||
retryCondition: function (error) { | ||
return (!error.response || (error.response.status === 429 || error.response.status === 502 || error.response.status === 503 || error.response.status === 504)); | ||
} | ||
}; | ||
var DiscoveryServiceApi = /** @class */ (function () { | ||
function DiscoveryServiceApi(serviceEndpointUri, region, credentials) { | ||
if (credentials.type === 'None') { | ||
this.apigClient = apigClientFactory.newClient({ | ||
accessKey: '', | ||
invokeUrl: serviceEndpointUri, | ||
region: region, | ||
secretKey: '' | ||
}); | ||
this.apigClient = apigClientFactory.newClient(__assign({ accessKey: '', invokeUrl: serviceEndpointUri, region: region, secretKey: '' }, retryOptions)); | ||
} | ||
else if (credentials.type === 'IAM') { | ||
var iamCreds = credentials; | ||
this.apigClient = apigClientFactory.newClient({ | ||
accessKey: iamCreds.accessKeyId, | ||
invokeUrl: serviceEndpointUri, | ||
region: region, | ||
secretKey: iamCreds.secretAccessKey | ||
}); | ||
this.apigClient = apigClientFactory.newClient(__assign({ accessKey: iamCreds.accessKeyId, invokeUrl: serviceEndpointUri, region: region, secretKey: iamCreds.secretAccessKey }, retryOptions)); | ||
} | ||
@@ -43,8 +40,3 @@ else if (credentials.type === 'BearerToken') { | ||
}; | ||
this.apigClient = apigClientFactory.newClient({ | ||
accessKey: '', | ||
invokeUrl: serviceEndpointUri, | ||
region: region, | ||
secretKey: '' | ||
}); | ||
this.apigClient = apigClientFactory.newClient(__assign({ accessKey: '', invokeUrl: serviceEndpointUri, region: region, secretKey: '' }, retryOptions)); | ||
} | ||
@@ -51,0 +43,0 @@ else { |
{ | ||
"name": "@adastradev/serverless-discovery-sdk", | ||
"version": "2.2.8-beta.1668533119402", | ||
"version": "2.2.8-beta.1668555334531", | ||
"description": "Serverless Service Discovery API", | ||
@@ -36,3 +36,4 @@ "main": "dist/index.js", | ||
"tslint-config-security": "^1.16.0", | ||
"typescript": "^4.1.3" | ||
"typescript": "^4.1.3", | ||
"nock": "^13.2.9" | ||
}, | ||
@@ -39,0 +40,0 @@ "dependencies": { |
23440
357
13