@mcma/client
Advanced tools
Comparing version 0.7.9 to 0.8.0
import { AxiosPromise, AxiosRequestConfig } from "axios"; | ||
import { ContextVariableProvider, JobBase, Resource, ResourceEndpoint, ResourceType, Service } from "@mcma/core"; | ||
import { ContextVariableProvider, JobBase, Resource, ResourceEndpoint, ResourceType, Service, McmaTracker } from "@mcma/core"; | ||
export type HttpRequestConfig = AxiosRequestConfig; | ||
export type HttpResponsePromise = AxiosPromise; | ||
export interface HttpRequestConfig extends AxiosRequestConfig { | ||
tracker?: McmaTracker; | ||
} | ||
export interface Authenticator { | ||
@@ -22,11 +25,6 @@ sign(config: HttpRequestConfig): void; | ||
request(config: HttpRequestConfig): HttpResponsePromise; | ||
get(url: string, config?: HttpRequestConfig): HttpResponsePromise; | ||
post(url: string, data?: any, config?: HttpRequestConfig): HttpResponsePromise; | ||
put(url: string, data?: any, config?: HttpRequestConfig): HttpResponsePromise; | ||
patch(url: string, data?: any, config?: HttpRequestConfig): HttpResponsePromise; | ||
delete(url: string, config?: HttpRequestConfig): HttpResponsePromise; | ||
@@ -79,4 +77,6 @@ } | ||
init(): Promise<void>; | ||
get<T extends Resource>(resourceType: ResourceType<T>, filter?: any): Promise<T[] | null>; | ||
query<T extends Resource>(resourceType: ResourceType<T>, filter?: any): Promise<T[] | null>; | ||
create<T extends Resource>(resource: T): Promise<T>; | ||
get<T extends Resource>(resource: T | string): Promise<T | undefined>; | ||
update<T extends Resource>(resource: T): Promise<T>; | ||
@@ -86,3 +86,2 @@ delete<T extends Resource>(resource: T | string): Promise<void>; | ||
getResourceEndpoint(url: string): Promise<ResourceEndpointClient | undefined>; | ||
resolve<T extends Resource>(resource: T | string): Promise<T | undefined>; | ||
sendNotification(resource: JobBase): Promise<void>; | ||
@@ -102,1 +101,6 @@ } | ||
} | ||
export namespace McmaHeaders { | ||
export const prefix: string; | ||
export const tracker: string; | ||
} |
@@ -6,2 +6,3 @@ const { HttpClient } = require("./lib/http-client"); | ||
const { AuthProvider } = require("./lib/auth-provider"); | ||
const { McmaHeaders } = require("./lib/headers"); | ||
require("./lib/context-variable-provider-ext"); | ||
@@ -15,3 +16,4 @@ | ||
ResourceManagerProvider, | ||
AuthProvider | ||
AuthProvider, | ||
McmaHeaders | ||
}; |
//"use strict"; | ||
const { Exception } = require("@mcma/core"); | ||
const { Exception, Utils } = require("@mcma/core"); | ||
const { McmaHeaders } = require("./headers"); | ||
@@ -38,2 +39,8 @@ const axios = require("axios"); | ||
// add tracker header, if a tracker is present | ||
if (config.tracker) { | ||
config.headers[McmaHeaders.tracker] = Utils.toBase64(JSON.stringify(config.tracker)); | ||
delete config.tracker; | ||
} | ||
// send request using axios | ||
@@ -40,0 +47,0 @@ try { |
@@ -52,3 +52,3 @@ const { Exception, Service, ResourceEndpoint, Notification } = require("@mcma/core"); | ||
this.get = async (resourceType, filter) => { | ||
this.query = async (resourceType, filter) => { | ||
if (typeof resourceType === "function" && resourceType.name) { | ||
@@ -107,2 +107,32 @@ resourceType = resourceType.name; | ||
this.get = async (resource) => { | ||
let resolvedResource; | ||
if (typeof resource === "string") { | ||
let http = await this.getResourceEndpointClient(resource); | ||
if (http === undefined) { | ||
http = httpClient; | ||
} | ||
try { | ||
let response = await http.get(resource); | ||
resolvedResource = response.data; | ||
} catch (error) { | ||
throw new Exception("ResourceManager: Failed to get resource from URL '" + resource + "'", error); | ||
} | ||
} else { | ||
resolvedResource = resource; | ||
} | ||
let resolvedType = typeof resolvedResource; | ||
if (resolvedType === "object") { | ||
if (Array.isArray(resolvedResource)) { | ||
throw new Exception("ResourceManager: Resource at '" + resource + "' has illegal type 'Array'"); | ||
} | ||
} else { | ||
throw new Exception("ResourceManager: Resource has illegal type '" + resolvedType + "'"); | ||
} | ||
return resolvedResource; | ||
}; | ||
this.update = async (resource) => { | ||
@@ -169,36 +199,6 @@ if (serviceClients.length === 0) { | ||
this.resolve = async (resource) => { | ||
let resolvedResource; | ||
if (typeof resource === "string") { | ||
let http = await this.getResourceEndpointClient(resource); | ||
if (http === undefined) { | ||
http = httpClient; | ||
} | ||
try { | ||
let response = await http.get(resource); | ||
resolvedResource = response.data; | ||
} catch (error) { | ||
throw new Exception("ResourceManager: Failed to resolve resource from URL '" + resource + "'", error); | ||
} | ||
} else { | ||
resolvedResource = resource; | ||
} | ||
let resolvedType = typeof resolvedResource; | ||
if (resolvedType === "object") { | ||
if (Array.isArray(resolvedResource)) { | ||
throw new Exception("ResourceManager: Resolved resource on URL '" + resource + "' has illegal type 'Array'"); | ||
} | ||
} else { | ||
throw new Exception("ResourceManager: Resolved resource has illegal type '" + resolvedType + "'"); | ||
} | ||
return resolvedResource; | ||
}; | ||
this.sendNotification = async (resource) => { | ||
if (resource.notificationEndpoint) { | ||
try { | ||
let notificationEndpoint = await this.resolve(resource.notificationEndpoint); | ||
let notificationEndpoint = await this.get(resource.notificationEndpoint); | ||
@@ -205,0 +205,0 @@ let http = await this.getResourceEndpointClient(notificationEndpoint.httpEndpoint); |
{ | ||
"name": "@mcma/client", | ||
"version": "0.7.9", | ||
"version": "0.8.0", | ||
"description": "Node module with classes and functions used to access services in an MCMA environment", | ||
@@ -30,8 +30,8 @@ "engines": { | ||
"peerDependencies": { | ||
"@mcma/core": "0.7.9" | ||
"@mcma/core": "0.8.0" | ||
}, | ||
"devDependencies": { | ||
"@mcma/core": "0.7.9", | ||
"@mcma/core": "0.8.0", | ||
"jasmine": "^3.3.1" | ||
} | ||
} |
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
25252
10
552