From 0b9ec039af17d10752680b2c984a57210830b8f8 Mon Sep 17 00:00:00 2001 From: Matt Straathof Date: Tue, 12 Oct 2021 10:24:48 -0700 Subject: [PATCH] feat: bump momento wire types typescript to 0.1.2 --- package-lock.json | 45 ++++++++++++++++++++++++++++++++ package.json | 6 +++-- src/Cache.ts | 7 ++--- src/Momento.ts | 7 ++--- src/errors/GrpcErrorMapper.ts | 4 +-- src/grpc/AuthInterceptor.ts | 7 +++-- src/grpc/CacheNameInterceptor.ts | 8 +++--- 7 files changed, 65 insertions(+), 19 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0279247ef..54ba5288d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,12 +10,18 @@ "license": "MIT", "dependencies": { "@grpc/grpc-js": "1.3.7", + "@momento/wire-types-typescript": "0.1.2", + "google-protobuf": "^3.18.1", "jwt-decode": "^3.1.2" }, "devDependencies": { + "@types/google-protobuf": "^3.15.5", "typescript": "^4.4.3" } }, + "@momento/wire-types-typescript": { + "extraneous": true + }, "node_modules/@grpc/grpc-js": { "version": "1.3.7", "resolved": "https://momento-prod-401011790710.d.codeartifact.us-west-2.amazonaws.com:443/npm/npm-upstream/@grpc/grpc-js/-/grpc-js-1.3.7.tgz", @@ -27,11 +33,31 @@ "node": "^8.13.0 || >=10.10.0" } }, + "node_modules/@momento/wire-types-typescript": { + "version": "0.1.2", + "resolved": "https://momento.jfrog.io/artifactory/api/npm/npm-local/@momento/wire-types-typescript/-/@momento/wire-types-typescript-0.1.2.tgz", + "integrity": "sha1-rSOrlfLsAhvltaXwgaGfbYH+VWM=", + "license": "MIT", + "dependencies": { + "@grpc/grpc-js": "1.3.7" + } + }, + "node_modules/@types/google-protobuf": { + "version": "3.15.5", + "resolved": "https://momento-prod-401011790710.d.codeartifact.us-west-2.amazonaws.com:443/npm/npm-upstream/@types/google-protobuf/-/google-protobuf-3.15.5.tgz", + "integrity": "sha512-6bgv24B+A2bo9AfzReeg5StdiijKzwwnRflA8RLd1V4Yv995LeTmo0z69/MPbBDFSiZWdZHQygLo/ccXhMEDgw==", + "dev": true + }, "node_modules/@types/node": { "version": "16.10.3", "resolved": "https://momento-prod-401011790710.d.codeartifact.us-west-2.amazonaws.com:443/npm/npm-upstream/@types/node/-/node-16.10.3.tgz", "integrity": "sha512-ho3Ruq+fFnBrZhUYI46n/bV2GjwzSkwuT4dTf0GkuNFmnb8nq4ny2z9JEVemFi6bdEJanHLlYfy9c6FN9B9McQ==" }, + "node_modules/google-protobuf": { + "version": "3.18.1", + "resolved": "https://momento-prod-401011790710.d.codeartifact.us-west-2.amazonaws.com:443/npm/npm-upstream/google-protobuf/-/google-protobuf-3.18.1.tgz", + "integrity": "sha512-cDqSamZ8rGs+pOzhIsBte7wpezUKg/sggeptDWN5odhnRY/eDLa5VWLeNeQvcfiqjS3yUwgM+6OePCJMB7aWZA==" + }, "node_modules/jwt-decode": { "version": "3.1.2", "resolved": "https://momento-prod-401011790710.d.codeartifact.us-west-2.amazonaws.com:443/npm/npm-upstream/jwt-decode/-/jwt-decode-3.1.2.tgz", @@ -60,11 +86,30 @@ "@types/node": ">=12.12.47" } }, + "@momento/wire-types-typescript": { + "version": "0.1.2", + "resolved": "https://momento.jfrog.io/artifactory/api/npm/npm-local/@momento/wire-types-typescript/-/@momento/wire-types-typescript-0.1.2.tgz", + "integrity": "sha1-rSOrlfLsAhvltaXwgaGfbYH+VWM=", + "requires": { + "@grpc/grpc-js": "1.3.7" + } + }, + "@types/google-protobuf": { + "version": "3.15.5", + "resolved": "https://momento-prod-401011790710.d.codeartifact.us-west-2.amazonaws.com:443/npm/npm-upstream/@types/google-protobuf/-/google-protobuf-3.15.5.tgz", + "integrity": "sha512-6bgv24B+A2bo9AfzReeg5StdiijKzwwnRflA8RLd1V4Yv995LeTmo0z69/MPbBDFSiZWdZHQygLo/ccXhMEDgw==", + "dev": true + }, "@types/node": { "version": "16.10.3", "resolved": "https://momento-prod-401011790710.d.codeartifact.us-west-2.amazonaws.com:443/npm/npm-upstream/@types/node/-/node-16.10.3.tgz", "integrity": "sha512-ho3Ruq+fFnBrZhUYI46n/bV2GjwzSkwuT4dTf0GkuNFmnb8nq4ny2z9JEVemFi6bdEJanHLlYfy9c6FN9B9McQ==" }, + "google-protobuf": { + "version": "3.18.1", + "resolved": "https://momento-prod-401011790710.d.codeartifact.us-west-2.amazonaws.com:443/npm/npm-upstream/google-protobuf/-/google-protobuf-3.18.1.tgz", + "integrity": "sha512-cDqSamZ8rGs+pOzhIsBte7wpezUKg/sggeptDWN5odhnRY/eDLa5VWLeNeQvcfiqjS3yUwgM+6OePCJMB7aWZA==" + }, "jwt-decode": { "version": "3.1.2", "resolved": "https://momento-prod-401011790710.d.codeartifact.us-west-2.amazonaws.com:443/npm/npm-upstream/jwt-decode/-/jwt-decode-3.1.2.tgz", diff --git a/package.json b/package.json index 3e7e4b4ed..bd1d721c5 100644 --- a/package.json +++ b/package.json @@ -13,11 +13,13 @@ "author": "", "license": "MIT", "devDependencies": { + "@types/google-protobuf": "^3.15.5", "typescript": "^4.4.3" }, "dependencies": { "@grpc/grpc-js": "1.3.7", - "jwt-decode": "^3.1.2", - "@momento/wire-types-typescript": "0.1.1" + "@momento/wire-types-typescript": "0.1.2", + "google-protobuf": "^3.18.1", + "jwt-decode": "^3.1.2" } } diff --git a/src/Cache.ts b/src/Cache.ts index 55764ad20..ae0d51333 100644 --- a/src/Cache.ts +++ b/src/Cache.ts @@ -1,10 +1,11 @@ -import {cache, grpc} from '@momento/wire-types-typescript'; +import {cache} from '@momento/wire-types-typescript'; import {authInterceptor} from "./grpc/AuthInterceptor"; import {cacheNameInterceptor} from "./grpc/CacheNameInterceptor"; import {MomentoCacheResult, momentoResultConverter} from "./messages/Result"; import {IllegalArgumentError} from "./errors/IllegalArgumentError"; import {ClientSdkError} from "./errors/ClientSdkError"; import {errorMapper} from "./errors/GrpcErrorMapper"; +import {ChannelCredentials, Interceptor} from "@grpc/grpc-js"; type GetResponse = { body: string; @@ -21,10 +22,10 @@ export class Cache { private readonly client: cache.cache_client.ScsClient; private readonly textEncoder: TextEncoder; private readonly textDecoder: TextDecoder; - private readonly interceptors: grpc.Interceptor[]; + private readonly interceptors: Interceptor[]; private readonly cacheName: string; constructor(authToken: string, cacheName: string, endpoint: string) { - this.client = new cache.cache_client.ScsClient(endpoint, grpc.ChannelCredentials.createSsl()) + this.client = new cache.cache_client.ScsClient(endpoint, ChannelCredentials.createSsl()); this.textEncoder = new TextEncoder(); this.textDecoder = new TextDecoder(); this.cacheName = cacheName; diff --git a/src/Momento.ts b/src/Momento.ts index ca7fca1c7..6a288d1ec 100644 --- a/src/Momento.ts +++ b/src/Momento.ts @@ -1,4 +1,4 @@ -import {control, grpc} from '@momento/wire-types-typescript'; +import {control} from '@momento/wire-types-typescript'; import jwtDecode from "jwt-decode"; import {Cache} from "./Cache"; import {authInterceptor} from "./grpc/AuthInterceptor"; @@ -7,6 +7,7 @@ import {ClientSdkError} from "./errors/ClientSdkError"; import {Status} from "@grpc/grpc-js/build/src/constants"; import {CacheAlreadyExistsError} from "./errors/CacheAlreadyExistsError"; import {errorMapper} from "./errors/GrpcErrorMapper"; +import {ChannelCredentials, Interceptor} from "@grpc/grpc-js"; type Claims = { cp: string, @@ -15,7 +16,7 @@ type Claims = { export class Momento { private readonly client: control.control_client.ScsControlClient; - private readonly interceptors: grpc.Interceptor[]; + private readonly interceptors: Interceptor[]; private readonly controlEndpoint: string; private readonly cacheEndpoint: string; private readonly authToken: string; @@ -25,7 +26,7 @@ export class Momento { this.interceptors = [authInterceptor(authToken)] this.controlEndpoint = endpointOverride ? `control.${endpointOverride}` : claims.cp; this.cacheEndpoint = endpointOverride ? `cache.${endpointOverride}` : claims.c; - this.client = new control.control_client.ScsControlClient(this.controlEndpoint, grpc.ChannelCredentials.createSsl()) + this.client = new control.control_client.ScsControlClient(this.controlEndpoint, ChannelCredentials.createSsl()) } private static decodeJwt(jwt?: string): Claims { diff --git a/src/errors/GrpcErrorMapper.ts b/src/errors/GrpcErrorMapper.ts index 17bb9fe70..f38f2d303 100644 --- a/src/errors/GrpcErrorMapper.ts +++ b/src/errors/GrpcErrorMapper.ts @@ -1,12 +1,12 @@ -import {grpc} from '@momento/wire-types-typescript'; import {ClientSdkError} from "./ClientSdkError"; import {Status} from "@grpc/grpc-js/build/src/constants"; import {PermissionDeniedError} from "./PermissionDeniedError"; import {CacheNotFoundError} from "./CacheNotFoundError"; import {IllegalArgumentError} from "./IllegalArgumentError"; import {InternalServerError} from "./InternalServerError"; +import {ServiceError} from "@grpc/grpc-js"; -export function errorMapper(err: grpc.ServiceError): ClientSdkError { +export function errorMapper(err: ServiceError): ClientSdkError { if (err.code === Status.PERMISSION_DENIED) { return new PermissionDeniedError(err.message) } diff --git a/src/grpc/AuthInterceptor.ts b/src/grpc/AuthInterceptor.ts index 068a0105c..4b05bac3d 100644 --- a/src/grpc/AuthInterceptor.ts +++ b/src/grpc/AuthInterceptor.ts @@ -1,10 +1,9 @@ -import {grpc} from "@momento/wire-types-typescript"; +import {InterceptingCall, Interceptor} from "@grpc/grpc-js"; -grpc.InterceptingCall -export const authInterceptor = (token: string): grpc.Interceptor => { +export const authInterceptor = (token: string): Interceptor => { return (options, nextCall) => { - return new grpc.InterceptingCall(nextCall(options), { + return new InterceptingCall(nextCall(options), { start: function (metadata, listener, next) { metadata.add("Authorization", token) next(metadata, {}) diff --git a/src/grpc/CacheNameInterceptor.ts b/src/grpc/CacheNameInterceptor.ts index c02ea99b1..43aad3503 100644 --- a/src/grpc/CacheNameInterceptor.ts +++ b/src/grpc/CacheNameInterceptor.ts @@ -1,10 +1,8 @@ -import {grpc} from "@momento/wire-types-typescript"; +import {InterceptingCall, Interceptor} from "@grpc/grpc-js"; -grpc.InterceptingCall - -export const cacheNameInterceptor = (cacheName: string): grpc.Interceptor => { +export const cacheNameInterceptor = (cacheName: string): Interceptor => { return (options, nextCall) => { - return new grpc.InterceptingCall(nextCall(options), { + return new InterceptingCall(nextCall(options), { start: function (metadata, listener, next) { metadata.add("cache", cacheName) next(metadata, {})