diff --git a/apigee-access/apigee-access-tests.ts b/apigee-access/apigee-access-tests.ts new file mode 100644 index 0000000000..99baec8021 --- /dev/null +++ b/apigee-access/apigee-access-tests.ts @@ -0,0 +1,67 @@ +/// +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'); } +} \ No newline at end of file diff --git a/apigee-access/apigee-access.d.ts b/apigee-access/apigee-access.d.ts new file mode 100644 index 0000000000..af34724023 --- /dev/null +++ b/apigee-access/apigee-access.d.ts @@ -0,0 +1,58 @@ +// Type definitions for apigee-access +// Project: https://www.npmjs.com/package/apigee-access +// Definitions by: Casper Skydt +// 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; +} \ No newline at end of file