Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ovh-api/common

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ovh-api/common - npm Package Compare versions

Comparing version 1.3.0 to 2.0.0

72

index.d.ts

@@ -8,49 +8,51 @@ /**

/**
* contains `requestPromised`
* params ton configure cache
*/
export interface OvhRequestable {
export interface ICacheOptions {
/**
* Execute a request on the API with promise
*
* @param httpMethod: The HTTP method GET POST PUT DELETE
* @param path: The request path with {pathParams}
* @param params: The request parameters (passed as query string or body params)
*/
requestPromised(httpMethod: string, path: string, params?: OvhParamType): Promise<any>;
}
/**
* Build Ovh API 2.0 Proxy
*
* @param ovhEngine
* @param path
*/
export declare function buildOvhProxy(ovhEngine: OvhRequestable, path: string): any;
/**
* Parent class of all Ovh Api helper
* for retro-compatibility with API OVH 1.x
*/
export declare class OvhWrapper {
* Time to live in second
*/
ttl?: number;
/**
* The Ovh Raw engine
* can be the official ovh api or the new Typescript engine
* ovh must implements `requestPromised`
* max memmory used to store your cache
*/
private ovh;
constructor(ovh: OvhRequestable);
size?: number;
/**
* Used to merged All Get Calls
* max number of entry in your cache
*/
protected get(path: string, params?: OvhParamType): Promise<any>;
count?: number;
}
/**
* common interface used to call ovh engine
*/
export interface OvhRequestable {
/**
* Used to merged All Put Calls
* Execute a request on the API with promise
*
* @param httpMethod: The HTTP method GET POST PUT DELETE
* @param path: The request final path
* @param pathTemplate: The request path with {pathParams}
* @param params: The request parameters (passed as query string or body params)
*/
protected put(path: string, params?: OvhParamType): Promise<any>;
doRequest(httpMethod: string, path: string, pathTemplate: string, params?: any): Promise<any>;
/**
* Used to merged All Post Calls
* Execute a request on the API with promise
*
* @param httpMethod: The HTTP method GET POST PUT DELETE
* @param path: The request path with {pathParams}
* @param params: The request parameters (passed as query string or body params)
* @deprecated
*/
protected post(path: string, params?: OvhParamType): Promise<any>;
request(httpMethod: string, path: string, params?: OvhParamType): Promise<any>;
/**
* Used to merged All Delete Calls
* cache controle
*/
protected delete(path: string, params?: OvhParamType): Promise<any>;
cache(template: string, param: ICacheOptions): Promise<any>;
}
/**
* Build Ovh API 2.0 Proxy
*
* @param ovhEngine
* @param path
*/
export declare function buildOvhProxy(ovhEngine: OvhRequestable, path: string): any;

@@ -6,3 +6,3 @@ "use strict";

* - $()
* - $getv/$put()/$post()/$delete()
* - $getv/$put()/$post()/$delete()/$cache()
* - path navigation

@@ -12,11 +12,19 @@ */

if (key.startsWith('$')) {
// give parameter in path
if (key == '$') {
return (id) => {
let child = new OvhProxyApi(target._ovhEngine, target._path + '/' + String(id));
const child = new OvhProxyApi(target._ovhEngine, `${target._path}/${id}`, `${target._path}/*`);
return new Proxy(child, handlerChild);
};
}
let fnc = (params) => {
let mtd = key.substring(1);
return target._ovhEngine.requestPromised(mtd, target._path, params);
// $get $post $delete $put
const fnc = (params) => {
const mtd = key.substring(1);
if (mtd === 'cache') {
return target._ovhEngine.cache(target._model, params);
}
else {
// get post put delete
return target._ovhEngine.doRequest(mtd, target._path, target._model, params);
}
};

@@ -27,3 +35,3 @@ return fnc.bind(target._ovhEngine);

key = key.substring(1);
let child = new OvhProxyApi(target._ovhEngine, target._path + '/' + key);
const child = new OvhProxyApi(target._ovhEngine, `${target._path}/${key}`);
return new Proxy(child, handlerChild);

@@ -41,4 +49,2 @@ };

construct(target, argArray, newTarget) {
console.log(argArray);
console.log(newTarget);
return target;

@@ -49,6 +55,7 @@ },

return target[p];
let key = p.toString();
const key = p.toString();
switch (key) {
case 'toString':
case 'valueOf':
case 'toLocaleString':
return target[p];

@@ -80,5 +87,12 @@ }

switch (key) {
// object
case 'toString':
case 'valueOf':
case 'toLocaleString':
// hasOwnProperty
// isPrototypeOf
// propertyIsEnumerable
// constructor
return target[p];
// EventEmitter
case 'addListener':

@@ -100,2 +114,4 @@ case 'on':

return target[p];
// legacy method only in root level
// @deprecated
case 'get':

@@ -105,3 +121,3 @@ case 'put':

case 'delete':
return (path) => (params) => target._ovhEngine.requestPromised(key, path, params);
return (path) => (params) => target._ovhEngine.request(key, path, params);
}

@@ -117,6 +133,8 @@ return commonGet(key, target);

class OvhProxyApi {
constructor(ovhEngine, path) {
constructor(ovhEngine, path, model) {
this._path = '';
this._model = '';
this._ovhEngine = ovhEngine;
this._path = path;
this._model = model || path;
}

@@ -137,35 +155,1 @@ toString() {

exports.buildOvhProxy = buildOvhProxy;
/**
* Parent class of all Ovh Api helper
* for retro-compatibility with API OVH 1.x
*/
class OvhWrapper {
constructor(ovh) {
this.ovh = ovh;
}
/**
* Used to merged All Get Calls
*/
get(path, params) {
return this.ovh.requestPromised('GET', path, params);
}
/**
* Used to merged All Put Calls
*/
put(path, params) {
return this.ovh.requestPromised('PUT', path, params);
}
/**
* Used to merged All Post Calls
*/
post(path, params) {
return this.ovh.requestPromised('POST', path, params);
}
/**
* Used to merged All Delete Calls
*/
delete(path, params) {
return this.ovh.requestPromised('DELETE', path, params);
}
}
exports.OvhWrapper = OvhWrapper;

@@ -7,18 +7,53 @@ /**

/**
* contains `requestPromised`
* params ton configure cache
*/
export interface ICacheOptions {
/**
* Time to live in second
*/
ttl?: number;
/**
* max memmory used to store your cache
*/
size?:number;
/**
* max number of entry in your cache
*/
count?: number
}
/**
* common interface used to call ovh engine
*/
export interface OvhRequestable {
/**
* Execute a request on the API with promise
*
* @param httpMethod: The HTTP method GET POST PUT DELETE
* @param path: The request path with {pathParams}
* @param params: The request parameters (passed as query string or body params)
*/
requestPromised(httpMethod: string, path: string, params?: OvhParamType): Promise<any>;
* Execute a request on the API with promise
*
* @param httpMethod: The HTTP method GET POST PUT DELETE
* @param path: The request final path
* @param pathTemplate: The request path with {pathParams}
* @param params: The request parameters (passed as query string or body params)
*/
doRequest(httpMethod: string, path: string, pathTemplate: string, params?: any): Promise<any>;
/**
* Execute a request on the API with promise
*
* @param httpMethod: The HTTP method GET POST PUT DELETE
* @param path: The request path with {pathParams}
* @param params: The request parameters (passed as query string or body params)
* @deprecated
*/
request(httpMethod: string, path: string, params?: OvhParamType): Promise<any>;
/**
* cache controle
*/
cache(template: string, param: ICacheOptions): Promise<any>;
}
/**
* common Getter part fot handlers
* - $()
* - $getv/$put()/$post()/$delete()
* - $getv/$put()/$post()/$delete()/$cache()
* - path navigation

@@ -28,11 +63,18 @@ */

if (key.startsWith('$')) {
// give parameter in path
if (key == '$') {
return (id: any) => {
let child = new OvhProxyApi(target._ovhEngine, target._path + '/' + String(id));
const child = new OvhProxyApi(target._ovhEngine, `${target._path}/${id}`, `${target._path}/*`);
return new Proxy(child, handlerChild);
}
}
let fnc = (params: any) => {
let mtd = key.substring(1);
return target._ovhEngine.requestPromised(mtd, target._path, params);
// $get $post $delete $put
const fnc = (params: any) => {
const mtd = key.substring(1);
if (mtd === 'cache') {
return target._ovhEngine.cache(target._model, params);
} else {
// get post put delete
return target._ovhEngine.doRequest(mtd, target._path, target._model, params);
}
}

@@ -43,3 +85,3 @@ return fnc.bind(target._ovhEngine);

key = key.substring(1);
let child = new OvhProxyApi(target._ovhEngine, target._path + '/' + key);
const child = new OvhProxyApi(target._ovhEngine, `${target._path}/${key}`);
return new Proxy(child, handlerChild);

@@ -58,4 +100,2 @@ }

construct(target: OvhProxyApi, argArray: any, newTarget?: any) {
console.log(argArray);
console.log(newTarget);
return target;

@@ -66,6 +106,7 @@ },

return (<any>target)[p];
let key = p.toString();
const key = p.toString();
switch (key) {
case 'toString':
case 'valueOf':
case 'toLocaleString':
return (<any>target)[p];

@@ -97,5 +138,12 @@ }

switch (key) {
// object
case 'toString':
case 'valueOf':
return (<any>target)[p];
case 'toLocaleString':
// hasOwnProperty
// isPrototypeOf
// propertyIsEnumerable
// constructor
return (target as any)[p];
// EventEmitter
case 'addListener':

@@ -116,3 +164,5 @@ case 'on':

case 'listenerCount':
return (<any>target)[p];
return (target as any)[p];
// legacy method only in root level
// @deprecated
case 'get':

@@ -122,3 +172,3 @@ case 'put':

case 'delete':
return (path: string) => (params: OvhParamType) => target._ovhEngine.requestPromised(key, path, params)
return (path: string) => (params: OvhParamType) => target._ovhEngine.request(key, path, params)
}

@@ -137,5 +187,7 @@ return commonGet(key, target);

public _path: string = '';
constructor(ovhEngine: OvhRequestable, path: string) {
public _model: string = '';
constructor(ovhEngine: OvhRequestable, path: string, model?: string) {
this._ovhEngine = ovhEngine;
this._path = path;
this._model = model || path;
}

@@ -153,46 +205,3 @@ toString(): string {

export function buildOvhProxy(ovhEngine: OvhRequestable, path: string): any {
return <any>new Proxy(new OvhProxyApi(ovhEngine, path), handlerRoot);
return new Proxy(new OvhProxyApi(ovhEngine, path), handlerRoot) as any;
}
/**
* Parent class of all Ovh Api helper
* for retro-compatibility with API OVH 1.x
*/
export class OvhWrapper {
/**
* The Ovh Raw engine
* can be the official ovh api or the new Typescript engine
* ovh must implements `requestPromised`
*/
private ovh: OvhRequestable;
constructor(ovh: OvhRequestable) {
this.ovh = ovh;
}
/**
* Used to merged All Get Calls
*/
protected get(path: string, params?: OvhParamType): Promise<any> {
return this.ovh.requestPromised('GET', path, params)
}
/**
* Used to merged All Put Calls
*/
protected put(path: string, params?: OvhParamType): Promise<any> {
return this.ovh.requestPromised('PUT', path, params)
}
/**
* Used to merged All Post Calls
*/
protected post(path: string, params?: OvhParamType): Promise<any> {
return this.ovh.requestPromised('POST', path, params)
}
/**
* Used to merged All Delete Calls
*/
protected delete(path: string, params?: OvhParamType): Promise<any> {
return this.ovh.requestPromised('DELETE', path, params)
}
}
{
"name": "@ovh-api/common",
"description": "common class used to enable Ovh Api new calls Syntax",
"version": "1.3.0",
"version": "2.0.0",
"main": "index.js",

@@ -21,5 +21,10 @@ "typings": "index.d.ts",

"build": "tsc -p .",
"prepublish": "yarn run build",
"prepare": "npm run build",
"build:watch": "tsc -p . --watch"
}
},
"files": [
"index.js",
"index.d.ts",
"index.ts"
]
}

@@ -6,2 +6,3 @@ # @ovh-api/common

Use a package like
* @ovh-api/domain

@@ -11,2 +12,2 @@ * @ovh-api/vps

* @ovh-api/order
* ...
* ...
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc