@owlnext/heimdall-js
Advanced tools
Comparing version 1.0.10 to 1.0.11
@@ -45,2 +45,3 @@ "use strict"; | ||
this.authenticate = (payload) => __awaiter(this, void 0, void 0, function* () { | ||
this._http_client.setServerEnvironment(payload.server_environment); | ||
let uri = this._router.generate(Routes.AUTHENTICATE); | ||
@@ -47,0 +48,0 @@ return yield this._http_client.doRequest({ |
@@ -10,7 +10,10 @@ import { AxiosResponse } from "axios"; | ||
export default class HttpClient { | ||
private readonly _entrypoint; | ||
private _config; | ||
private _fingerprintUtils; | ||
private _fingerprint; | ||
private _server_environment; | ||
constructor(); | ||
setServerEnvironment: (server_env: string) => void; | ||
doRequest: (props: RequestPayload) => Promise<AxiosResponse<any>>; | ||
private getAPIEntrypoint; | ||
private generateSecurityHeader; | ||
@@ -17,0 +20,0 @@ private makeHeimdallHeader; |
@@ -43,4 +43,7 @@ "use strict"; | ||
constructor() { | ||
this.setServerEnvironment = (server_env) => { | ||
this._server_environment = server_env; | ||
}; | ||
this.doRequest = (props) => __awaiter(this, void 0, void 0, function* () { | ||
let uri = this._entrypoint + props.uri; | ||
let uri = this.getAPIEntrypoint() + props.uri; | ||
const payload = { | ||
@@ -74,2 +77,9 @@ method: props.method, | ||
}); | ||
this.getAPIEntrypoint = () => { | ||
let entrypoint = this._config.config.PRODUCTION_API_ENTRYPOINT; | ||
if (this._server_environment === 'integration') { | ||
entrypoint = this._config.config.INTEGRATION_API_ENTRYPOINT; | ||
} | ||
return entrypoint; | ||
}; | ||
this.generateSecurityHeader = () => __awaiter(this, void 0, void 0, function* () { | ||
@@ -87,6 +97,6 @@ return this._fingerprintUtils.getFingerprint().then(fingerprint => { | ||
}; | ||
const config = new config_loader_1.default(); | ||
this._entrypoint = config.config.API_ENTRYPOINT; | ||
this._config = new config_loader_1.default(); | ||
this._fingerprintUtils = new fingerprint_utils_1.default(); | ||
this._fingerprint = ''; | ||
this._server_environment = 'production'; | ||
} | ||
@@ -93,0 +103,0 @@ } |
interface ConfigPackage { | ||
API_ENTRYPOINT: string; | ||
PRODUCTION_API_ENTRYPOINT: string; | ||
INTEGRATION_API_ENTRYPOINT: string; | ||
} | ||
@@ -4,0 +5,0 @@ export default class ConfigLoader { |
@@ -6,3 +6,4 @@ "use strict"; | ||
this._config = { | ||
API_ENTRYPOINT: process.env.API_ENTRYPOINT || 'https://heimdall-api.tools.owlnext.fr' | ||
PRODUCTION_API_ENTRYPOINT: process.env.API_ENTRYPOINT || 'https://heimdall-api.tools.owlnext.fr', | ||
INTEGRATION_API_ENTRYPOINT: process.env.API_ENTRYPOINT || 'https://heimdall-api.integration.tools.owlnext.fr' | ||
}; | ||
@@ -9,0 +10,0 @@ } |
@@ -8,2 +8,4 @@ import HeimdallApi from "./api/heimdall-api"; | ||
private readonly _cipher; | ||
static readonly SERVER_ENVIRONMENT_PRODUCTION: string; | ||
static readonly SERVER_ENVIRONMENT_INTEGRATION: string; | ||
/** | ||
@@ -90,2 +92,3 @@ * Heimdall constructor. | ||
get api(): HeimdallApi; | ||
private validateServerEnvironment; | ||
} |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -23,10 +32,18 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
this.authenticate = (props) => { | ||
this.disconnect(); | ||
return this.api.authenticate({ | ||
login: props.login, | ||
password: props.password, | ||
application_uuid: props.application_uuid | ||
}).then((result) => { | ||
return Promise.resolve(result); | ||
}); | ||
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () { | ||
const server_env = props.server_environment || Heimdall.SERVER_ENVIRONMENT_PRODUCTION; | ||
const is_server_env_valid = this.validateServerEnvironment(server_env); | ||
if (!is_server_env_valid) { | ||
reject('You must use Heimdall.SERVER_ENVIRONMENT_* as a server_environment property.'); | ||
} | ||
this.disconnect(); | ||
return this.api.authenticate({ | ||
login: props.login, | ||
password: props.password, | ||
application_uuid: props.application_uuid, | ||
server_environment: server_env | ||
}).then((result) => { | ||
resolve(result); | ||
}); | ||
})); | ||
}; | ||
@@ -148,2 +165,6 @@ /** | ||
}; | ||
this.validateServerEnvironment = (server_env) => { | ||
return server_env === Heimdall.SERVER_ENVIRONMENT_PRODUCTION || | ||
server_env === Heimdall.SERVER_ENVIRONMENT_INTEGRATION; | ||
}; | ||
this._api = new heimdall_api_1.default(); | ||
@@ -161,2 +182,4 @@ this._cipher = new cipher_1.default(); | ||
exports.default = Heimdall; | ||
Heimdall.SERVER_ENVIRONMENT_PRODUCTION = 'production'; | ||
Heimdall.SERVER_ENVIRONMENT_INTEGRATION = 'integration'; | ||
//# sourceMappingURL=heimdall.js.map |
{ | ||
"name": "@owlnext/heimdall-js", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"description": "Heimdall API client & utils for javascript technologies", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -52,2 +52,23 @@ # heimdallJS | ||
> **Note:** You also have access to the full API implementation with the `api` getter from the `Heimdall` object. | ||
> **Note:** You also have access to the full API implementation with the `api` getter from the `Heimdall` object. | ||
## Integration environment | ||
To use integration environment, simply add the `server_environment` as a property to your authentication. | ||
```typescript | ||
import Heimdall from '@owlnext/heimdall-js' | ||
// first, authenticate your Heimdall client | ||
const heimdall: Heimdall = new Heimdall(); | ||
heimdall.authenticate({ | ||
login: '<your login>', | ||
password: '<your password>', | ||
application_uuid: '<your application UUID>', | ||
server_environment: Heimdall.SERVER_ENVIRONMENT_INTEGRATION | ||
}); | ||
``` | ||
> If left untouched, the default behaviour points the API to the production environment. |
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
81601
1109
73