diff --git a/example/routes/use_aperture.ts b/example/routes/use_aperture.ts index 91f8da4..f278121 100644 --- a/example/routes/use_aperture.ts +++ b/example/routes/use_aperture.ts @@ -1,15 +1,19 @@ import express from "express"; -import { ApertureClient, Flow, FlowStatusEnum, LookupStatus } from "@fluxninja/aperture-js"; +import { + ApertureClient, + Flow, + FlowStatusEnum, + LookupStatus, +} from "@fluxninja/aperture-js"; import grpc from "@grpc/grpc-js"; - // Create aperture client export const apertureClient = new ApertureClient({ address: process.env.APERTURE_AGENT_ADDRESS !== undefined ? process.env.APERTURE_AGENT_ADDRESS : "localhost:8089", - agentAPIKey: process.env.APERTURE_AGENT_API_KEY || undefined, + apiKey: process.env.APERTURE_API_KEY || undefined, // if process.env.APERTURE_AGENT_INSECURE set channelCredentials to insecure channelCredentials: process.env.APERTURE_AGENT_INSECURE !== undefined @@ -43,14 +47,21 @@ apertureRoute.get("/", async (_: express.Request, res: express.Response) => { if (flow.CachedValue().GetLookupStatus() === LookupStatus.Hit) { console.log("Cache hit:", flow.CachedValue().GetValue()?.toString()); } else { - console.log("Cache miss:", flow.CachedValue().GetOperationStatus(), flow.CachedValue().GetError()?.message); + console.log( + "Cache miss:", + flow.CachedValue().GetOperationStatus(), + flow.CachedValue().GetError()?.message, + ); const resString = "awesomeString"; // create a new buffer const buffer = Buffer.from(resString); // set cache value - const setResult = await flow.SetCachedValue(buffer, { seconds: 30, nanos: 0 }) + const setResult = await flow.SetCachedValue(buffer, { + seconds: 30, + nanos: 0, + }); if (setResult?.error) { console.log(`Error setting cache value: ${setResult.error}`); } diff --git a/sdk/client.ts b/sdk/client.ts index 5156f96..d4cc375 100644 --- a/sdk/client.ts +++ b/sdk/client.ts @@ -35,26 +35,26 @@ export class ApertureClient { constructor({ address, - agentAPIKey, + apiKey, channelCredentials = grpc.credentials.createSsl(), channelOptions = {}, }: { address: string; channelCredentials?: ChannelCredentials; channelOptions?: ChannelOptions; - agentAPIKey?: string; + apiKey?: string; }) { if (!address) { throw new Error("address is required"); } - if (agentAPIKey) { + if (apiKey) { channelCredentials = grpc.credentials.combineChannelCredentials( channelCredentials, grpc.credentials.createFromMetadataGenerator( (_params: any, callback: any) => { const metadata = new grpc.Metadata(); - metadata.add("x-api-key", agentAPIKey); + metadata.add("x-api-key", apiKey); callback(null, metadata); }, ), @@ -104,7 +104,19 @@ export class ApertureClient { let startDate = Date.now(); const resolveFlow = (response: any, err: any) => { - resolve(new Flow(this.fcsClient, params.grpcCallOptions ?? {}, controlPoint, span, startDate, params.rampMode, params.cacheKey, response, err)); + resolve( + new Flow( + this.fcsClient, + params.grpcCallOptions ?? {}, + controlPoint, + span, + startDate, + params.rampMode, + params.cacheKey, + response, + err, + ), + ); }; try { @@ -126,7 +138,10 @@ export class ApertureClient { cacheKey: params.cacheKey, }; - const cb: grpc.requestCallback = (err: any, response: any) => { + const cb: grpc.requestCallback = ( + err: any, + response: any, + ) => { resolveFlow(err ? null : response, err); return; };