@superfaceai/one-sdk
Advanced tools
Comparing version 1.5.1 to 1.5.2-rc.0
@@ -9,6 +9,6 @@ # Changelog | ||
## [Unreleased] | ||
## [1.5.1] - 2022-06-14 | ||
### Fixed | ||
- Do not recache ProviderConfiguration on security values change | ||
- Do not call `Config.instance()` in the global scope to defer reading of env variables | ||
- Refactor security values passing in `perform` | ||
@@ -326,4 +326,3 @@ ## [1.5.0] - 2022-06-09 | ||
[Unreleased]: https://github.com/superfaceai/one-sdk-js/compare/v1.5.1...HEAD | ||
[1.5.1]: https://github.com/superfaceai/one-sdk-js/compare/v1.5.0...v1.5.1 | ||
[Unreleased]: https://github.com/superfaceai/one-sdk-js/compare/v1.5.0...HEAD | ||
[1.5.0]: https://github.com/superfaceai/one-sdk-js/compare/v1.4.1...v1.5.0 | ||
@@ -330,0 +329,0 @@ [1.4.1]: https://github.com/superfaceai/one-sdk-js/compare/v1.4.0...v1.4.1 |
@@ -132,5 +132,3 @@ "use strict"; | ||
profileProvider = new profile_provider_1.ProfileProvider(this.superJson, profileConfig, providerConfig, this); | ||
return [4 /*yield*/, profileProvider.bind({ | ||
security: providerConfig.security, | ||
})]; | ||
return [4 /*yield*/, profileProvider.bind()]; | ||
case 1: | ||
@@ -156,3 +154,3 @@ boundProfileProvider = _a.sent(); | ||
} | ||
return [2 /*return*/, new provider_1.Provider(this, new provider_1.ProviderConfiguration(providerName, providerSettings.security))]; | ||
return [2 /*return*/, new provider_1.Provider(this, new provider_1.ProviderConfiguration(providerName))]; | ||
}); | ||
@@ -159,0 +157,0 @@ }); |
@@ -14,3 +14,3 @@ import { MapDocumentNode, NormalizedProfileProviderSettings, ProfileDocumentNode, ProviderJson, SecurityValues } from '@superfaceai/ast'; | ||
private readonly mapAst; | ||
private readonly providerName; | ||
private readonly provider; | ||
readonly configuration: { | ||
@@ -24,3 +24,3 @@ services: IServiceSelector; | ||
private fetchInstance; | ||
constructor(profileAst: ProfileDocumentNode, mapAst: MapDocumentNode, providerName: string, configuration: { | ||
constructor(profileAst: ProfileDocumentNode, mapAst: MapDocumentNode, provider: ProviderJson, configuration: { | ||
services: IServiceSelector; | ||
@@ -38,3 +38,3 @@ profileProviderSettings?: NormalizedProfileProviderSettings; | ||
*/ | ||
perform<TInput extends NonPrimitive | undefined = undefined, TResult = any>(usecase: string, input?: TInput, parameters?: Record<string, string>): Promise<Result<TResult, ProfileParameterError | MapInterpreterError>>; | ||
perform<TInput extends NonPrimitive | undefined = undefined, TResult = any>(usecase: string, input?: TInput, parameters?: Record<string, string>, securityValues?: SecurityValues[]): Promise<Result<TResult, ProfileParameterError | MapInterpreterError>>; | ||
private mergeParameters; | ||
@@ -59,2 +59,3 @@ } | ||
private providerJson?; | ||
private readonly cachePath; | ||
constructor( | ||
@@ -94,5 +95,5 @@ /** Preloaded superJson instance */ | ||
* | ||
* The base variables either come from super.json or from `this.provider` if it is an instance of `ProviderConfiguration` | ||
* The base variables come from super.json | ||
*/ | ||
private resolveSecurityValues; | ||
} |
@@ -107,8 +107,7 @@ "use strict"; | ||
var boundProfileProviderDebug = debug_1.default('superface:bound-profile-provider'); | ||
var cachePath = path_1.join(config_1.Config.instance().cachePath, 'providers'); | ||
var BoundProfileProvider = /** @class */ (function () { | ||
function BoundProfileProvider(profileAst, mapAst, providerName, configuration, events) { | ||
function BoundProfileProvider(profileAst, mapAst, provider, configuration, events) { | ||
this.profileAst = profileAst; | ||
this.mapAst = mapAst; | ||
this.providerName = providerName; | ||
this.provider = provider; | ||
this.configuration = configuration; | ||
@@ -119,3 +118,3 @@ this.profileValidator = new interpreter_1.ProfileParameterValidator(this.profileAst); | ||
profile: profileAstId(profileAst), | ||
provider: providerName, | ||
provider: provider.name, | ||
}; | ||
@@ -140,7 +139,8 @@ this.fetchInstance.events = events; | ||
*/ | ||
BoundProfileProvider.prototype.perform = function (usecase, input, parameters) { | ||
BoundProfileProvider.prototype.perform = function (usecase, input, parameters, securityValues) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var composedInput, inputValidation, interpreter, result, resultValidation; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
var composedInput, inputValidation, security, interpreter, result, resultValidation; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
@@ -150,3 +150,3 @@ this.fetchInstance.metadata = { | ||
usecase: usecase, | ||
provider: this.providerName, | ||
provider: this.provider.name, | ||
}; | ||
@@ -159,2 +159,5 @@ composedInput = this.composeInput(usecase, input); | ||
forceCast(composedInput); | ||
security = securityValues | ||
? security_1.resolveSecurityConfiguration((_a = this.provider.securitySchemes) !== null && _a !== void 0 ? _a : [], securityValues, this.provider.name) | ||
: this.configuration.security; | ||
interpreter = new interpreter_1.MapInterpreter({ | ||
@@ -164,3 +167,3 @@ input: composedInput, | ||
services: this.configuration.services, | ||
security: this.configuration.security, | ||
security: security, | ||
parameters: this.mergeParameters(parameters, this.configuration.parameters), | ||
@@ -173,3 +176,3 @@ }, { | ||
case 1: | ||
result = _a.sent(); | ||
result = _b.sent(); | ||
if (result.isErr()) { | ||
@@ -234,2 +237,3 @@ return [2 /*return*/, lib_1.err(result.error)]; | ||
} | ||
this.cachePath = path_1.join(config_1.Config.instance().cachePath, 'providers'); | ||
} | ||
@@ -320,3 +324,3 @@ /** | ||
securityConfiguration = security_1.resolveSecurityConfiguration((_a = providerInfo.securitySchemes) !== null && _a !== void 0 ? _a : [], securityValues, providerName); | ||
return [2 /*return*/, new BoundProfileProvider(profileAst, mapAst, providerInfo.name, { | ||
return [2 /*return*/, new BoundProfileProvider(profileAst, mapAst, providerInfo, { | ||
services: new services_1.ServiceSelector(providerInfo.services, providerInfo.defaultService), | ||
@@ -397,3 +401,3 @@ profileProviderSettings: (_b = this.superJson.normalized.profiles[profileId]) === null || _b === void 0 ? void 0 : _b.providers[providerInfo.name], | ||
if (!(this.providerJson === undefined)) return [3 /*break*/, 9]; | ||
providerCachePath = path_1.join(cachePath, providerName); | ||
providerCachePath = path_1.join(this.cachePath, providerName); | ||
_b.label = 1; | ||
@@ -445,7 +449,7 @@ case 1: | ||
case 0: | ||
providerCachePath = path_1.join(cachePath, providerJson.name + ".json"); | ||
providerCachePath = path_1.join(this.cachePath, providerJson.name + ".json"); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 4, , 5]); | ||
return [4 /*yield*/, fs_1.promises.mkdir(cachePath, { recursive: true })]; | ||
return [4 /*yield*/, fs_1.promises.mkdir(this.cachePath, { recursive: true })]; | ||
case 2: | ||
@@ -680,18 +684,11 @@ _a.sent(); | ||
* | ||
* The base variables either come from super.json or from `this.provider` if it is an instance of `ProviderConfiguration` | ||
* The base variables come from super.json | ||
*/ | ||
ProfileProvider.prototype.resolveSecurityValues = function (providerName, overlay) { | ||
var _a; | ||
var base; | ||
if (this.provider instanceof provider_1.ProviderConfiguration) { | ||
base = this.provider.security; | ||
} | ||
else { | ||
base = (_a = this.superJson.normalized.providers[providerName]) === null || _a === void 0 ? void 0 : _a.security; | ||
} | ||
var resolved = base; | ||
var _a, _b; | ||
var base = (_b = (_a = this.superJson.normalized.providers[providerName]) === null || _a === void 0 ? void 0 : _a.security) !== null && _b !== void 0 ? _b : []; | ||
if (overlay !== undefined) { | ||
resolved = mutate_1.mergeSecurity(base, overlay); | ||
return mutate_1.mergeSecurity(base, overlay); | ||
} | ||
return resolved; | ||
return base; | ||
}; | ||
@@ -698,0 +695,0 @@ return ProfileProvider; |
@@ -1,7 +0,5 @@ | ||
import { SecurityValues } from '@superfaceai/ast'; | ||
import { SuperfaceClientBase } from './client'; | ||
export declare class ProviderConfiguration { | ||
readonly name: string; | ||
readonly security: SecurityValues[]; | ||
constructor(name: string, security: SecurityValues[]); | ||
constructor(name: string); | ||
get cacheKey(): string; | ||
@@ -13,5 +11,3 @@ } | ||
constructor(client: SuperfaceClientBase, configuration: ProviderConfiguration); | ||
configure(configuration: { | ||
security?: SecurityValues[]; | ||
}): Promise<Provider>; | ||
configure(): Promise<Provider>; | ||
} |
@@ -40,7 +40,5 @@ "use strict"; | ||
exports.Provider = exports.ProviderConfiguration = void 0; | ||
var mutate_1 = require("../internal/superjson/mutate"); | ||
var ProviderConfiguration = /** @class */ (function () { | ||
function ProviderConfiguration(name, security) { | ||
function ProviderConfiguration(name) { | ||
this.name = name; | ||
this.security = security; | ||
} | ||
@@ -63,8 +61,7 @@ Object.defineProperty(ProviderConfiguration.prototype, "cacheKey", { | ||
} | ||
Provider.prototype.configure = function (configuration) { | ||
var _a; | ||
Provider.prototype.configure = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var newConfiguration; | ||
return __generator(this, function (_b) { | ||
newConfiguration = new ProviderConfiguration(this.configuration.name, mutate_1.mergeSecurity(this.configuration.security, (_a = configuration.security) !== null && _a !== void 0 ? _a : [])); | ||
return __generator(this, function (_a) { | ||
newConfiguration = new ProviderConfiguration(this.configuration.name); | ||
return [2 /*return*/, new Provider(this.client, newConfiguration)]; | ||
@@ -71,0 +68,0 @@ }); |
@@ -73,3 +73,2 @@ "use strict"; | ||
var policies_1 = require("./failure/policies"); | ||
var provider_1 = require("./provider"); | ||
var debug = debug_1.default('superface:usecase'); | ||
@@ -114,14 +113,4 @@ var UseCaseBase = /** @class */ (function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var providerConfig; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: return [4 /*yield*/, this.getProviderConfiguration((_a = options === null || options === void 0 ? void 0 : options.provider) !== null && _a !== void 0 ? _a : currentProvider)]; | ||
case 1: | ||
providerConfig = _b.sent(); | ||
//If we have security values pass them directly to perform | ||
if (options === null || options === void 0 ? void 0 : options.security) { | ||
return [2 /*return*/, new provider_1.ProviderConfiguration(providerConfig.name, options.security)]; | ||
} | ||
return [2 /*return*/, providerConfig]; | ||
} | ||
return [2 /*return*/, this.getProviderConfiguration((_a = options === null || options === void 0 ? void 0 : options.provider) !== null && _a !== void 0 ? _a : currentProvider)]; | ||
}); | ||
@@ -152,3 +141,3 @@ }); | ||
}; | ||
UseCaseBase.prototype.performBoundUsecase = function (input, parameters) { | ||
UseCaseBase.prototype.performBoundUsecase = function (input, parameters, security) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -160,3 +149,3 @@ return __generator(this, function (_a) { | ||
// TODO: rewrap the errors for public consumption? | ||
return [2 /*return*/, this.boundProfileProvider.perform(this.name, input, parameters)]; | ||
return [2 /*return*/, this.boundProfileProvider.perform(this.name, input, parameters, security)]; | ||
}); | ||
@@ -173,3 +162,3 @@ }); | ||
debug('bound provider', this.boundProfileProvider); | ||
return [2 /*return*/, this.performBoundUsecase(input, options === null || options === void 0 ? void 0 : options.parameters)]; | ||
return [2 /*return*/, this.performBoundUsecase(input, options === null || options === void 0 ? void 0 : options.parameters, options === null || options === void 0 ? void 0 : options.security)]; | ||
} | ||
@@ -255,3 +244,3 @@ }); | ||
__metadata("design:type", Function), | ||
__metadata("design:paramtypes", [typeof (_a = typeof TInput !== "undefined" && TInput) === "function" ? _a : Object, Object]), | ||
__metadata("design:paramtypes", [typeof (_a = typeof TInput !== "undefined" && TInput) === "function" ? _a : Object, Object, Array]), | ||
__metadata("design:returntype", Promise) | ||
@@ -258,0 +247,0 @@ ], UseCaseBase.prototype, "performBoundUsecase", null); |
{ | ||
"name": "@superfaceai/one-sdk", | ||
"version": "1.5.1", | ||
"description": "Level 5 autonomous, self-driving API client, https://superface.ai", | ||
"version": "1.5.2-rc.0", | ||
"description": "OneSDK is a universal API client which provides an unparalleled developer experience for every HTTP API", | ||
"author": "Superface Team <hello@superface.ai>", | ||
"repository": "https://github.com/superfaceai/one-sdk-js.git", | ||
"homepage": "https://superface.ai", | ||
"bugs": { | ||
"url": "https://github.com/superfaceai/one-sdk-js/issues", | ||
"email": "support@superface.ai" | ||
}, | ||
"keywords": [ | ||
"api", | ||
"client", | ||
"http", | ||
"sdk", | ||
"integration", | ||
"superface" | ||
], | ||
"main": "dist/index.js", | ||
@@ -11,4 +26,2 @@ "source": "src/index.ts", | ||
"types": "dist/index.d.ts", | ||
"repository": "https://github.com/superfaceai/one-sdk-js.git", | ||
"author": "Superface Team", | ||
"private": false, | ||
@@ -21,15 +34,16 @@ "files": [ | ||
"build": "tsc -p tsconfig.release.json --outDir dist", | ||
"watch": "yarn build --watch", | ||
"check_dependencies": "node scripts/check_dependencies.js", | ||
"clean": "rimraf dist/", | ||
"format:fix": "prettier --write ./src", | ||
"format": "prettier -c ./src", | ||
"lint:fix": "yarn lint --fix", | ||
"lint": "eslint src/", | ||
"prebuild": "yarn clean", | ||
"test": "yarn test:base && yarn test:long", | ||
"prepack": "yarn build", | ||
"prepush": "yarn build && yarn test:clean && yarn lint && yarn format", | ||
"test:base": "jest --testPathIgnorePatterns 'event-adapter.test.ts$'", | ||
"test:clean": "jest --clear-cache && yarn test", | ||
"test:long": "jest --testPathPattern 'event-adapter.test.ts$'", | ||
"test:clean": "jest --clear-cache && yarn test", | ||
"lint": "eslint src/", | ||
"lint:fix": "yarn lint --fix", | ||
"format": "prettier -c ./src", | ||
"format:fix": "prettier --write ./src", | ||
"prepush": "yarn build && yarn test:clean && yarn lint && yarn format", | ||
"check_dependencies": "node scripts/check_dependencies.js" | ||
"test": "yarn test:base && yarn test:long", | ||
"watch": "yarn build --watch" | ||
}, | ||
@@ -36,0 +50,0 @@ "devDependencies": { |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
0
803147
12200