mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 06:50:19 +00:00
Merge pull request #9903 from CasperSkydt/feature-apigee-access
Added apigee-access
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
/// <reference path="apigee-access.d.ts"/>
|
||||
import apigee from "apigee-access";
|
||||
|
||||
//Sample code from
|
||||
// https://www.npmjs.com/package/apigee-access
|
||||
|
||||
var request: any = null;
|
||||
|
||||
// Variables
|
||||
var val1 = apigee.getVariable(request, 'TestVariable');
|
||||
|
||||
apigee.setIntVariable(request, 'TestVariable', '123');
|
||||
apigee.setIntVariable(request, 'TestVariable2', 42);
|
||||
|
||||
apigee.deleteVariable(request, 'TestVariable');
|
||||
|
||||
// Mode
|
||||
console.log('The deployment mode is ' + apigee.getMode());
|
||||
|
||||
// Cache
|
||||
var cache = apigee.getCache('cache');
|
||||
var customCache = apigee.getCache('MyCustomCache',
|
||||
{ resource: 'MyCustomrResource' });
|
||||
cache.put('key2', 'Hello, World!', 120);
|
||||
cache.put('key4', 'Hello, World!', function (err: any) {
|
||||
});
|
||||
|
||||
cache.get('key', function (err: any, data: any) {
|
||||
});
|
||||
|
||||
cache.remove('key');
|
||||
|
||||
// Secure Vault
|
||||
var orgVault = apigee.getVault('vault1', 'organization');
|
||||
orgVault.get('key1', function (err: any, secretValue: any) {
|
||||
});
|
||||
|
||||
// Quota Service
|
||||
var quota = apigee.getQuota();
|
||||
quota.apply({ identifier: 'Foo', allow: 10, timeUnit: 'hour' },
|
||||
function (err: any, result: any) {
|
||||
console.log('Quota applied: %j', result);
|
||||
});
|
||||
|
||||
quota.apply({
|
||||
identifier: 'Foo',
|
||||
timeUnit: 'hour',
|
||||
allow: 100
|
||||
}, quotaResult);
|
||||
|
||||
quota.apply({
|
||||
identifier: 'Bar',
|
||||
timeUnit: 'minute',
|
||||
interval: 5,
|
||||
allow: 500
|
||||
}, quotaResult);
|
||||
|
||||
quota.apply({
|
||||
identifier: 'Foo',
|
||||
timeUnit: 'hour',
|
||||
allow: 100,
|
||||
weight: 10
|
||||
}, quotaResult);
|
||||
|
||||
function quotaResult(err: any, r: any) {
|
||||
if (err) { console.error('Quota failed'); }
|
||||
}
|
||||
Vendored
+58
@@ -0,0 +1,58 @@
|
||||
// Type definitions for apigee-access
|
||||
// Project: https://www.npmjs.com/package/apigee-access
|
||||
// Definitions by: Casper Skydt <https://github.com/CasperSkydt>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare module ApigeeAccess {
|
||||
|
||||
function getVariable(request: any, name: string): string | number | boolean;
|
||||
function setVariable(request: any, name: string, value: string | number | boolean ): void;
|
||||
function setIntVariable(request: any, name: string, value: string | number): void;
|
||||
function deleteVariable(request: any, name: string): void;
|
||||
function getCache(name: string, options?: CacheOptions): any;
|
||||
function getVault(name: string, scope?: "organization" | "environment"): SecureVault;
|
||||
function getQuota(options?: any): QuotaService;
|
||||
function getMode(): "apigee" | "standalone";
|
||||
|
||||
interface CacheOptions{
|
||||
resource?: string;
|
||||
scope?: "global" | "application" | "exclusive";
|
||||
defaultTtl?: number;
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
interface Cache{
|
||||
put(key: string, data: any, ttl?: number, callback?: (err: any) => void): void;
|
||||
get(key: string, callback: (err: any, data: any) => void): void;
|
||||
remove(key: string, callback?: (err: any) => void): void;
|
||||
}
|
||||
|
||||
interface SecureVault{
|
||||
getKeys(callback: (err: any, data: any) => void): void;
|
||||
get(key: string, callback: (err: any, data: any) => void): void;
|
||||
}
|
||||
|
||||
interface QuotaService{
|
||||
apply(options?: QuotaServiceApplyOptions, callback?: (err: any, data: QuotaServiceApplyCallbackData) => void): void;
|
||||
}
|
||||
|
||||
interface QuotaServiceApplyOptions{
|
||||
identifier: string;
|
||||
timeUnit: "minute" | "hour" | "day" | "week" | "month";
|
||||
allow: number;
|
||||
interval?: number;
|
||||
weight?: number;
|
||||
}
|
||||
|
||||
interface QuotaServiceApplyCallbackData{
|
||||
used: number;
|
||||
allowed: number;
|
||||
isAllowed: boolean;
|
||||
expiryTime: number;
|
||||
timestamp: number;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "apigee-access"{
|
||||
export default ApigeeAccess;
|
||||
}
|
||||
Reference in New Issue
Block a user