diff --git a/src/commands.ts b/src/commands.ts index 58a325ce..abfd1c3b 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -1,4 +1,3 @@ -import * as grpc from '@grpc/grpc-js'; import * as querystring from 'querystring'; import * as vscode from 'vscode'; import { @@ -352,10 +351,9 @@ export class Commands { openLogDetails = (data: any) => { this.telemetry.sendEvent('openLogDetails'); - const {id, provider} = data; + const {id} = data; const filename = id; const uri = vscode.Uri.parse(`stripeLog:${filename}`); - provider.refresh(uri); vscode.workspace .openTextDocument(uri) .then((doc) => vscode.languages.setTextDocumentLanguage(doc, 'json')) @@ -418,7 +416,9 @@ export class Commands { fixtureRequest.setEvent(eventName); daemonClient.fixture(fixtureRequest, (error, response) => { if (error) { - if (error.code === grpc.status.UNIMPLEMENTED) { + if (error.code === 12) { + // https://grpc.github.io/grpc/core/md_doc_statuscodes.html + // 12: UNIMPLEMENTED vscode.window.showErrorMessage( 'Please upgrade your Stripe CLI to the latest version to use this feature.', ); @@ -494,7 +494,9 @@ export class Commands { daemonClient.trigger(triggerRequest, (error, response) => { if (error) { - if (error.code === grpc.status.UNIMPLEMENTED) { + if (error.code === 12) { + // https://grpc.github.io/grpc/core/md_doc_statuscodes.html + // 12: UNIMPLEMENTED vscode.window.showErrorMessage( 'Please upgrade your Stripe CLI to the latest version to use this feature.', ); diff --git a/src/extension.ts b/src/extension.ts index 5f07c39b..d0bfd770 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -37,7 +37,7 @@ import {SurveyPrompt} from './surveyPrompt'; import {TelemetryPrompt} from './telemetryPrompt'; import path from 'path'; -export async function activate(this: any, context: ExtensionContext) { +export function activate(this: any, context: ExtensionContext) { initializeStripeWorkspaceState(context); new TelemetryPrompt(context).activate(); @@ -52,23 +52,6 @@ export async function activate(this: any, context: ExtensionContext) { const stripeClient = new StripeClient(telemetry, context); const stripeDaemon = new StripeDaemon(stripeClient); const stripeSamples = new StripeSamples(stripeClient, stripeDaemon); - const daemonClient = await stripeDaemon.setupClient(); - - workspace.registerTextDocumentContentProvider( - 'stripeEvent', - new StripeResourceDocumentContentProvider(context, EVENT_ID_REGEXP, retrieveEventDetails, undefined, undefined, false), - ); - - const logContentProvider = new StripeResourceDocumentContentProvider(context, LOG_ID_REGEXP, undefined, retrieveLogDetails, daemonClient, true); - workspace.registerTextDocumentContentProvider( - 'stripeLog', - logContentProvider, - ); - - languages.registerDocumentLinkProvider( - {scheme: 'stripeLog'}, - new StripeLogsDashboardLinkProvider(), - ); const stripeEventsViewProvider = new StripeEventsViewProvider( stripeClient, @@ -80,7 +63,7 @@ export async function activate(this: any, context: ExtensionContext) { showCollapseAll: true, }); - const stripeLogsViewProvider = new StripeLogsViewProvider(stripeClient, stripeDaemon, context, logContentProvider); + const stripeLogsViewProvider = new StripeLogsViewProvider(stripeClient, stripeDaemon, context); window.createTreeView('stripeLogsView', { treeDataProvider: stripeLogsViewProvider, showCollapseAll: true, @@ -111,6 +94,21 @@ export async function activate(this: any, context: ExtensionContext) { debug.registerDebugConfigurationProvider('stripe', new StripeDebugProvider(telemetry)); + workspace.registerTextDocumentContentProvider( + 'stripeEvent', + new StripeResourceDocumentContentProvider(context, EVENT_ID_REGEXP, retrieveEventDetails), + ); + + workspace.registerTextDocumentContentProvider( + 'stripeLog', + new StripeResourceDocumentContentProvider(context, LOG_ID_REGEXP, retrieveLogDetails), + ); + + languages.registerDocumentLinkProvider( + {scheme: 'stripeLog'}, + new StripeLogsDashboardLinkProvider(), + ); + const git = new Git(); new StripeLinter(telemetry, git).activate(); diff --git a/src/rpc/commands_grpc_pb.d.ts b/src/rpc/commands_grpc_pb.d.ts index 60b6e480..7f94a156 100644 --- a/src/rpc/commands_grpc_pb.d.ts +++ b/src/rpc/commands_grpc_pb.d.ts @@ -6,7 +6,6 @@ import * as commands_pb from "./commands_pb"; import * as events_resend_pb from "./events_resend_pb"; import * as fixtures_pb from "./fixtures_pb"; -import * as integration_insights_pb from "./integration_insights_pb"; import * as listen_pb from "./listen_pb"; import * as login_pb from "./login_pb"; import * as login_status_pb from "./login_status_pb"; @@ -23,7 +22,6 @@ import * as grpc from "@grpc/grpc-js"; interface IStripeCLIService extends grpc.ServiceDefinition { eventsResend: grpc.MethodDefinition; fixture: grpc.MethodDefinition; - integrationInsight: grpc.MethodDefinition; listen: grpc.MethodDefinition; login: grpc.MethodDefinition; loginStatus: grpc.MethodDefinition; @@ -42,7 +40,6 @@ export const StripeCLIService: IStripeCLIService; export interface IStripeCLIServer extends grpc.UntypedServiceImplementation { eventsResend: grpc.handleUnaryCall; fixture: grpc.handleUnaryCall; - integrationInsight: grpc.handleUnaryCall; listen: grpc.handleServerStreamingCall; login: grpc.handleUnaryCall; loginStatus: grpc.handleUnaryCall; @@ -64,9 +61,6 @@ export class StripeCLIClient extends grpc.Client { fixture(argument: fixtures_pb.FixtureRequest, callback: grpc.requestCallback): grpc.ClientUnaryCall; fixture(argument: fixtures_pb.FixtureRequest, metadataOrOptions: grpc.Metadata | grpc.CallOptions | null, callback: grpc.requestCallback): grpc.ClientUnaryCall; fixture(argument: fixtures_pb.FixtureRequest, metadata: grpc.Metadata | null, options: grpc.CallOptions | null, callback: grpc.requestCallback): grpc.ClientUnaryCall; - integrationInsight(argument: integration_insights_pb.IntegrationInsightRequest, callback: grpc.requestCallback): grpc.ClientUnaryCall; - integrationInsight(argument: integration_insights_pb.IntegrationInsightRequest, metadataOrOptions: grpc.Metadata | grpc.CallOptions | null, callback: grpc.requestCallback): grpc.ClientUnaryCall; - integrationInsight(argument: integration_insights_pb.IntegrationInsightRequest, metadata: grpc.Metadata | null, options: grpc.CallOptions | null, callback: grpc.requestCallback): grpc.ClientUnaryCall; listen(argument: listen_pb.ListenRequest, metadataOrOptions?: grpc.Metadata | grpc.CallOptions | null): grpc.ClientReadableStream; listen(argument: listen_pb.ListenRequest, metadata?: grpc.Metadata | null, options?: grpc.CallOptions | null): grpc.ClientReadableStream; login(argument: login_pb.LoginRequest, callback: grpc.requestCallback): grpc.ClientUnaryCall; diff --git a/src/rpc/commands_grpc_pb.js b/src/rpc/commands_grpc_pb.js index 1c5eea5c..2593151a 100644 --- a/src/rpc/commands_grpc_pb.js +++ b/src/rpc/commands_grpc_pb.js @@ -4,7 +4,6 @@ var grpc = require('@grpc/grpc-js'); var events_resend_pb = require('./events_resend_pb.js'); var fixtures_pb = require('./fixtures_pb.js'); -var integration_insights_pb = require('./integration_insights_pb.js'); var listen_pb = require('./listen_pb.js'); var login_pb = require('./login_pb.js'); var login_status_pb = require('./login_status_pb.js'); @@ -61,28 +60,6 @@ function deserialize_rpc_FixtureResponse(buffer_arg) { return fixtures_pb.FixtureResponse.deserializeBinary(new Uint8Array(buffer_arg)); } -function serialize_rpc_IntegrationInsightRequest(arg) { - if (!(arg instanceof integration_insights_pb.IntegrationInsightRequest)) { - throw new Error('Expected argument of type rpc.IntegrationInsightRequest'); - } - return Buffer.from(arg.serializeBinary()); -} - -function deserialize_rpc_IntegrationInsightRequest(buffer_arg) { - return integration_insights_pb.IntegrationInsightRequest.deserializeBinary(new Uint8Array(buffer_arg)); -} - -function serialize_rpc_IntegrationInsightResponse(arg) { - if (!(arg instanceof integration_insights_pb.IntegrationInsightResponse)) { - throw new Error('Expected argument of type rpc.IntegrationInsightResponse'); - } - return Buffer.from(arg.serializeBinary()); -} - -function deserialize_rpc_IntegrationInsightResponse(buffer_arg) { - return integration_insights_pb.IntegrationInsightResponse.deserializeBinary(new Uint8Array(buffer_arg)); -} - function serialize_rpc_ListenRequest(arg) { if (!(arg instanceof listen_pb.ListenRequest)) { throw new Error('Expected argument of type rpc.ListenRequest'); @@ -351,18 +328,6 @@ fixture: { responseSerialize: serialize_rpc_FixtureResponse, responseDeserialize: deserialize_rpc_FixtureResponse, }, - // Retrieve the integration insight of given log. -integrationInsight: { - path: '/rpc.StripeCLI/IntegrationInsight', - requestStream: false, - responseStream: false, - requestType: integration_insights_pb.IntegrationInsightRequest, - responseType: integration_insights_pb.IntegrationInsightResponse, - requestSerialize: serialize_rpc_IntegrationInsightRequest, - requestDeserialize: deserialize_rpc_IntegrationInsightRequest, - responseSerialize: serialize_rpc_IntegrationInsightResponse, - responseDeserialize: deserialize_rpc_IntegrationInsightResponse, - }, // Receive webhook events from the Stripe API to your local machine. Like `stripe listen`. listen: { path: '/rpc.StripeCLI/Listen', diff --git a/src/rpc/commands_pb.d.ts b/src/rpc/commands_pb.d.ts index bcf564d7..11e93d5b 100644 --- a/src/rpc/commands_pb.d.ts +++ b/src/rpc/commands_pb.d.ts @@ -4,7 +4,6 @@ import * as jspb from "google-protobuf"; import * as events_resend_pb from "./events_resend_pb"; import * as fixtures_pb from "./fixtures_pb"; -import * as integration_insights_pb from "./integration_insights_pb"; import * as listen_pb from "./listen_pb"; import * as login_pb from "./login_pb"; import * as login_status_pb from "./login_status_pb"; diff --git a/src/rpc/commands_pb.js b/src/rpc/commands_pb.js index a00e5dc0..9cb52b0e 100644 --- a/src/rpc/commands_pb.js +++ b/src/rpc/commands_pb.js @@ -19,8 +19,6 @@ var events_resend_pb = require('./events_resend_pb.js'); goog.object.extend(proto, events_resend_pb); var fixtures_pb = require('./fixtures_pb.js'); goog.object.extend(proto, fixtures_pb); -var integration_insights_pb = require('./integration_insights_pb.js'); -goog.object.extend(proto, integration_insights_pb); var listen_pb = require('./listen_pb.js'); goog.object.extend(proto, listen_pb); var login_pb = require('./login_pb.js'); diff --git a/src/rpc/integration_insights_grpc_pb.d.ts b/src/rpc/integration_insights_grpc_pb.d.ts deleted file mode 100644 index 51b4d695..00000000 --- a/src/rpc/integration_insights_grpc_pb.d.ts +++ /dev/null @@ -1 +0,0 @@ -// GENERATED CODE -- NO SERVICES IN PROTO diff --git a/src/rpc/integration_insights_grpc_pb.js b/src/rpc/integration_insights_grpc_pb.js deleted file mode 100644 index 97b3a246..00000000 --- a/src/rpc/integration_insights_grpc_pb.js +++ /dev/null @@ -1 +0,0 @@ -// GENERATED CODE -- NO SERVICES IN PROTO \ No newline at end of file diff --git a/src/rpc/integration_insights_pb.d.ts b/src/rpc/integration_insights_pb.d.ts deleted file mode 100644 index 08bba921..00000000 --- a/src/rpc/integration_insights_pb.d.ts +++ /dev/null @@ -1,45 +0,0 @@ -// package: rpc -// file: integration_insights.proto - -import * as jspb from "google-protobuf"; - -export class IntegrationInsightRequest extends jspb.Message { - getLog(): string; - setLog(value: string): void; - - serializeBinary(): Uint8Array; - toObject(includeInstance?: boolean): IntegrationInsightRequest.AsObject; - static toObject(includeInstance: boolean, msg: IntegrationInsightRequest): IntegrationInsightRequest.AsObject; - static extensions: {[key: number]: jspb.ExtensionFieldInfo}; - static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; - static serializeBinaryToWriter(message: IntegrationInsightRequest, writer: jspb.BinaryWriter): void; - static deserializeBinary(bytes: Uint8Array): IntegrationInsightRequest; - static deserializeBinaryFromReader(message: IntegrationInsightRequest, reader: jspb.BinaryReader): IntegrationInsightRequest; -} - -export namespace IntegrationInsightRequest { - export type AsObject = { - log: string, - } -} - -export class IntegrationInsightResponse extends jspb.Message { - getMessage(): string; - setMessage(value: string): void; - - serializeBinary(): Uint8Array; - toObject(includeInstance?: boolean): IntegrationInsightResponse.AsObject; - static toObject(includeInstance: boolean, msg: IntegrationInsightResponse): IntegrationInsightResponse.AsObject; - static extensions: {[key: number]: jspb.ExtensionFieldInfo}; - static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; - static serializeBinaryToWriter(message: IntegrationInsightResponse, writer: jspb.BinaryWriter): void; - static deserializeBinary(bytes: Uint8Array): IntegrationInsightResponse; - static deserializeBinaryFromReader(message: IntegrationInsightResponse, reader: jspb.BinaryReader): IntegrationInsightResponse; -} - -export namespace IntegrationInsightResponse { - export type AsObject = { - message: string, - } -} - diff --git a/src/rpc/integration_insights_pb.js b/src/rpc/integration_insights_pb.js deleted file mode 100644 index 38b1fdef..00000000 --- a/src/rpc/integration_insights_pb.js +++ /dev/null @@ -1,322 +0,0 @@ -// source: integration_insights.proto -/** - * @fileoverview - * @enhanceable - * @suppress {missingRequire} reports error on implicit type usages. - * @suppress {messageConventions} JS Compiler reports an error if a variable or - * field starts with 'MSG_' and isn't a translatable message. - * @public - */ -// GENERATED CODE -- DO NOT EDIT! -/* eslint-disable */ -// @ts-nocheck - -var jspb = require('google-protobuf'); -var goog = jspb; -var global = Function('return this')(); - -goog.exportSymbol('proto.rpc.IntegrationInsightRequest', null, global); -goog.exportSymbol('proto.rpc.IntegrationInsightResponse', null, global); -/** - * Generated by JsPbCodeGenerator. - * @param {Array=} opt_data Optional initial data array, typically from a - * server response, or constructed directly in Javascript. The array is used - * in place and becomes part of the constructed object. It is not cloned. - * If no data is provided, the constructed object will be empty, but still - * valid. - * @extends {jspb.Message} - * @constructor - */ -proto.rpc.IntegrationInsightRequest = function(opt_data) { - jspb.Message.initialize(this, opt_data, 0, -1, null, null); -}; -goog.inherits(proto.rpc.IntegrationInsightRequest, jspb.Message); -if (goog.DEBUG && !COMPILED) { - /** - * @public - * @override - */ - proto.rpc.IntegrationInsightRequest.displayName = 'proto.rpc.IntegrationInsightRequest'; -} -/** - * Generated by JsPbCodeGenerator. - * @param {Array=} opt_data Optional initial data array, typically from a - * server response, or constructed directly in Javascript. The array is used - * in place and becomes part of the constructed object. It is not cloned. - * If no data is provided, the constructed object will be empty, but still - * valid. - * @extends {jspb.Message} - * @constructor - */ -proto.rpc.IntegrationInsightResponse = function(opt_data) { - jspb.Message.initialize(this, opt_data, 0, -1, null, null); -}; -goog.inherits(proto.rpc.IntegrationInsightResponse, jspb.Message); -if (goog.DEBUG && !COMPILED) { - /** - * @public - * @override - */ - proto.rpc.IntegrationInsightResponse.displayName = 'proto.rpc.IntegrationInsightResponse'; -} - - - -if (jspb.Message.GENERATE_TO_OBJECT) { -/** - * Creates an object representation of this proto. - * Field names that are reserved in JavaScript and will be renamed to pb_name. - * Optional fields that are not set will be set to undefined. - * To access a reserved field use, foo.pb_, eg, foo.pb_default. - * For the list of reserved names please see: - * net/proto2/compiler/js/internal/generator.cc#kKeyword. - * @param {boolean=} opt_includeInstance Deprecated. whether to include the - * JSPB instance for transitional soy proto support: - * http://goto/soy-param-migration - * @return {!Object} - */ -proto.rpc.IntegrationInsightRequest.prototype.toObject = function(opt_includeInstance) { - return proto.rpc.IntegrationInsightRequest.toObject(opt_includeInstance, this); -}; - - -/** - * Static version of the {@see toObject} method. - * @param {boolean|undefined} includeInstance Deprecated. Whether to include - * the JSPB instance for transitional soy proto support: - * http://goto/soy-param-migration - * @param {!proto.rpc.IntegrationInsightRequest} msg The msg instance to transform. - * @return {!Object} - * @suppress {unusedLocalVariables} f is only used for nested messages - */ -proto.rpc.IntegrationInsightRequest.toObject = function(includeInstance, msg) { - var f, obj = { - log: jspb.Message.getFieldWithDefault(msg, 1, "") - }; - - if (includeInstance) { - obj.$jspbMessageInstance = msg; - } - return obj; -}; -} - - -/** - * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. - * @return {!proto.rpc.IntegrationInsightRequest} - */ -proto.rpc.IntegrationInsightRequest.deserializeBinary = function(bytes) { - var reader = new jspb.BinaryReader(bytes); - var msg = new proto.rpc.IntegrationInsightRequest; - return proto.rpc.IntegrationInsightRequest.deserializeBinaryFromReader(msg, reader); -}; - - -/** - * Deserializes binary data (in protobuf wire format) from the - * given reader into the given message object. - * @param {!proto.rpc.IntegrationInsightRequest} msg The message object to deserialize into. - * @param {!jspb.BinaryReader} reader The BinaryReader to use. - * @return {!proto.rpc.IntegrationInsightRequest} - */ -proto.rpc.IntegrationInsightRequest.deserializeBinaryFromReader = function(msg, reader) { - while (reader.nextField()) { - if (reader.isEndGroup()) { - break; - } - var field = reader.getFieldNumber(); - switch (field) { - case 1: - var value = /** @type {string} */ (reader.readString()); - msg.setLog(value); - break; - default: - reader.skipField(); - break; - } - } - return msg; -}; - - -/** - * Serializes the message to binary data (in protobuf wire format). - * @return {!Uint8Array} - */ -proto.rpc.IntegrationInsightRequest.prototype.serializeBinary = function() { - var writer = new jspb.BinaryWriter(); - proto.rpc.IntegrationInsightRequest.serializeBinaryToWriter(this, writer); - return writer.getResultBuffer(); -}; - - -/** - * Serializes the given message to binary data (in protobuf wire - * format), writing to the given BinaryWriter. - * @param {!proto.rpc.IntegrationInsightRequest} message - * @param {!jspb.BinaryWriter} writer - * @suppress {unusedLocalVariables} f is only used for nested messages - */ -proto.rpc.IntegrationInsightRequest.serializeBinaryToWriter = function(message, writer) { - var f = undefined; - f = message.getLog(); - if (f.length > 0) { - writer.writeString( - 1, - f - ); - } -}; - - -/** - * optional string log = 1; - * @return {string} - */ -proto.rpc.IntegrationInsightRequest.prototype.getLog = function() { - return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); -}; - - -/** - * @param {string} value - * @return {!proto.rpc.IntegrationInsightRequest} returns this - */ -proto.rpc.IntegrationInsightRequest.prototype.setLog = function(value) { - return jspb.Message.setProto3StringField(this, 1, value); -}; - - - - - -if (jspb.Message.GENERATE_TO_OBJECT) { -/** - * Creates an object representation of this proto. - * Field names that are reserved in JavaScript and will be renamed to pb_name. - * Optional fields that are not set will be set to undefined. - * To access a reserved field use, foo.pb_, eg, foo.pb_default. - * For the list of reserved names please see: - * net/proto2/compiler/js/internal/generator.cc#kKeyword. - * @param {boolean=} opt_includeInstance Deprecated. whether to include the - * JSPB instance for transitional soy proto support: - * http://goto/soy-param-migration - * @return {!Object} - */ -proto.rpc.IntegrationInsightResponse.prototype.toObject = function(opt_includeInstance) { - return proto.rpc.IntegrationInsightResponse.toObject(opt_includeInstance, this); -}; - - -/** - * Static version of the {@see toObject} method. - * @param {boolean|undefined} includeInstance Deprecated. Whether to include - * the JSPB instance for transitional soy proto support: - * http://goto/soy-param-migration - * @param {!proto.rpc.IntegrationInsightResponse} msg The msg instance to transform. - * @return {!Object} - * @suppress {unusedLocalVariables} f is only used for nested messages - */ -proto.rpc.IntegrationInsightResponse.toObject = function(includeInstance, msg) { - var f, obj = { - message: jspb.Message.getFieldWithDefault(msg, 1, "") - }; - - if (includeInstance) { - obj.$jspbMessageInstance = msg; - } - return obj; -}; -} - - -/** - * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. - * @return {!proto.rpc.IntegrationInsightResponse} - */ -proto.rpc.IntegrationInsightResponse.deserializeBinary = function(bytes) { - var reader = new jspb.BinaryReader(bytes); - var msg = new proto.rpc.IntegrationInsightResponse; - return proto.rpc.IntegrationInsightResponse.deserializeBinaryFromReader(msg, reader); -}; - - -/** - * Deserializes binary data (in protobuf wire format) from the - * given reader into the given message object. - * @param {!proto.rpc.IntegrationInsightResponse} msg The message object to deserialize into. - * @param {!jspb.BinaryReader} reader The BinaryReader to use. - * @return {!proto.rpc.IntegrationInsightResponse} - */ -proto.rpc.IntegrationInsightResponse.deserializeBinaryFromReader = function(msg, reader) { - while (reader.nextField()) { - if (reader.isEndGroup()) { - break; - } - var field = reader.getFieldNumber(); - switch (field) { - case 1: - var value = /** @type {string} */ (reader.readString()); - msg.setMessage(value); - break; - default: - reader.skipField(); - break; - } - } - return msg; -}; - - -/** - * Serializes the message to binary data (in protobuf wire format). - * @return {!Uint8Array} - */ -proto.rpc.IntegrationInsightResponse.prototype.serializeBinary = function() { - var writer = new jspb.BinaryWriter(); - proto.rpc.IntegrationInsightResponse.serializeBinaryToWriter(this, writer); - return writer.getResultBuffer(); -}; - - -/** - * Serializes the given message to binary data (in protobuf wire - * format), writing to the given BinaryWriter. - * @param {!proto.rpc.IntegrationInsightResponse} message - * @param {!jspb.BinaryWriter} writer - * @suppress {unusedLocalVariables} f is only used for nested messages - */ -proto.rpc.IntegrationInsightResponse.serializeBinaryToWriter = function(message, writer) { - var f = undefined; - f = message.getMessage(); - if (f.length > 0) { - writer.writeString( - 1, - f - ); - } -}; - - -/** - * optional string message = 1; - * @return {string} - */ -proto.rpc.IntegrationInsightResponse.prototype.getMessage = function() { - return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); -}; - - -/** - * @param {string} value - * @return {!proto.rpc.IntegrationInsightResponse} returns this - */ -proto.rpc.IntegrationInsightResponse.prototype.setMessage = function(value) { - return jspb.Message.setProto3StringField(this, 1, value); -}; - - -goog.object.extend(exports, proto.rpc); diff --git a/src/stripeLogsView.ts b/src/stripeLogsView.ts index 24b586eb..960327fb 100644 --- a/src/stripeLogsView.ts +++ b/src/stripeLogsView.ts @@ -6,22 +6,18 @@ import {camelToSnakeCase, recursivelyRenameKeys, unixToLocaleStringTZ} from './u import {ClientReadableStream} from '@grpc/grpc-js'; import {StripeClient} from './stripeClient'; import {StripeDaemon} from './daemon/stripeDaemon'; -import {StripeResourceDocumentContentProvider} from './stripeResourceDocumentContentProvider'; import {StripeTreeItem} from './stripeTreeItem'; export class StripeLogsViewProvider extends StreamingViewDataProvider { private extensionContext: vscode.ExtensionContext; - private logContentProvider: StripeResourceDocumentContentProvider; constructor( stripeClient: StripeClient, stripeDaemon: StripeDaemon, extensionContext: vscode.ExtensionContext, - logContentProvider: StripeResourceDocumentContentProvider ) { super(stripeClient, stripeDaemon); this.extensionContext = extensionContext; - this.logContentProvider = logContentProvider; } buildTree(): Promise { @@ -58,7 +54,7 @@ export class StripeLogsViewProvider extends StreamingViewDataProvider any) | undefined; - private asyncRetrieveResourceFromContext: ((context: vscode.ExtensionContext, id: string, daemonClient: StripeCLIClient) => any) | undefined; - private daemonClient: StripeCLIClient | undefined; - private isAsync: boolean; - - private _onDidChange = new vscode.EventEmitter(); - readonly onDidChange = this._onDidChange.event; + private retrieveResourceFromContext: (context: vscode.ExtensionContext, id: string) => any; constructor( extensionContext: vscode.ExtensionContext, resourceIdRegexp: RegExp, - retrieveResourceFromContext: ((context: vscode.ExtensionContext, id: string) => any) | undefined, - asyncRetrieveResourceFromContext: ((context: vscode.ExtensionContext, id: string, daemonClient: StripeCLIClient) => any) | undefined, - daemonClient: StripeCLIClient | undefined, - isAsync: boolean, + retrieveResourceFromContext: (context: vscode.ExtensionContext, id: string) => any, ) { this.extensionContext = extensionContext; this.resourceIdRegexp = resourceIdRegexp; this.retrieveResourceFromContext = retrieveResourceFromContext; - this.asyncRetrieveResourceFromContext = asyncRetrieveResourceFromContext; - this.daemonClient = daemonClient; - this.isAsync = isAsync; } - async provideTextDocumentContent(uri: vscode.Uri): Promise { + provideTextDocumentContent(uri: vscode.Uri): string | null { const resourceId = this.getResourceIdFromUri(uri); if (!resourceId) { return null; } - let resource = ''; - if (this.isAsync && !!this.asyncRetrieveResourceFromContext && !!this.daemonClient) { - resource = await this.asyncRetrieveResourceFromContext(this.extensionContext, resourceId, this.daemonClient); - } else if (!!this.retrieveResourceFromContext) { - resource = this.retrieveResourceFromContext(this.extensionContext, resourceId); - } else { - return null; - } + const resource = this.retrieveResourceFromContext(this.extensionContext, resourceId); // respect workspace tab settings, or default to 2 spaces const editorConfig = vscode.workspace.getConfiguration('editor'); @@ -54,10 +33,6 @@ export class StripeResourceDocumentContentProvider implements vscode.TextDocumen return resourceJsonString; } - public refresh(uri: vscode.Uri) { - this._onDidChange.fire(uri); - } - private getResourceIdFromUri(uri: vscode.Uri): string | null { const {path} = uri; const match = path.match(this.resourceIdRegexp); diff --git a/src/stripeWebhooksView.ts b/src/stripeWebhooksView.ts index 61b60aec..78eb8251 100644 --- a/src/stripeWebhooksView.ts +++ b/src/stripeWebhooksView.ts @@ -1,4 +1,3 @@ -import * as grpc from '@grpc/grpc-js'; import * as vscode from 'vscode'; import {StripeDaemon} from './daemon/stripeDaemon'; import {StripeTreeItem} from './stripeTreeItem'; @@ -42,7 +41,9 @@ export class StripeWebhooksViewProvider extends StripeTreeViewDataProvider { const daemonClient = await this.stripeDaemon.setupClient(); daemonClient.webhookEndpointsList(new WebhookEndpointsListRequest(), (error, response) => { if (error) { - if (error.code === grpc.status.UNIMPLEMENTED) { + if (error.code === 12) { + // https://grpc.github.io/grpc/core/md_doc_statuscodes.html + // 12: UNIMPLEMENTED vscode.window.showErrorMessage( 'Please upgrade your Stripe CLI to the latest version to use this feature.', ); diff --git a/src/stripeWorkspaceState.ts b/src/stripeWorkspaceState.ts index d7c7bfb8..21fdb14b 100644 --- a/src/stripeWorkspaceState.ts +++ b/src/stripeWorkspaceState.ts @@ -1,7 +1,4 @@ -import * as grpc from '@grpc/grpc-js'; import * as vscode from 'vscode'; -import {IntegrationInsightRequest} from './rpc/integration_insights_pb'; -import {StripeCLIClient} from './rpc/commands_grpc_pb'; // Set a limit on the number of eventNames we store in context. const recentEventsLimit = 100; @@ -92,46 +89,9 @@ export function addLogDetails( extensionContext.workspaceState.update(logDetailsKey, logDetailsMap); } -export async function retrieveLogDetails(extensionContext: vscode.ExtensionContext, logId: string, daemonClient: StripeCLIClient) { +export function retrieveLogDetails(extensionContext: vscode.ExtensionContext, logId: string) { const logDetailsMap = getLogDetailsMap(extensionContext); - const logDetails = logDetailsMap.get(logId); - - // if insight has not been retrieved or previously failed to be retrieved, then retrieve it - if (!('insight' in logDetails) || logDetails.insight.includes('Failed to retrieve insight') || logDetails.insight.includes('Please check back later')) { - const insight = await getIntegrationInsight(logId, daemonClient); - logDetails.insight = insight; - addLogDetails(extensionContext, logId, logDetails); - } - - return logDetails; -} - -async function getIntegrationInsight(logId: string, daemonClient: StripeCLIClient): Promise { - const request = new IntegrationInsightRequest(); - request.setLog(logId); - - const integrationInsight = await new Promise((resolve, reject) => { - daemonClient.integrationInsight(request, (error: any, response: any) => { - if (error) { - if (error.code === grpc.status.UNIMPLEMENTED) { - const errMessage = 'Please upgrade your Stripe CLI to the latest version to retrieve integration insight.'; - vscode.window.showErrorMessage(errMessage); - resolve(`(Failed to retrieve insight. ${errMessage})`); - } else { - resolve(`(Failed to retrieve insight: ${error})`); - } - } else if (response) { - const insight = response.getMessage(); - if (insight === 'log not found') { - resolve('(Insight generation in progress. Please check back later.)'); - } else { - resolve(insight); - } - } - }); - }); - - return integrationInsight; + return logDetailsMap.get(logId); } export function clearLogDetails(extensionContext: vscode.ExtensionContext) { diff --git a/test/suite/stripeLogsView.test.ts b/test/suite/stripeLogsView.test.ts index c171f127..dbf65ba8 100644 --- a/test/suite/stripeLogsView.test.ts +++ b/test/suite/stripeLogsView.test.ts @@ -10,8 +10,6 @@ import {StripeCLIClient} from '../../src/rpc/commands_grpc_pb'; import {StripeClient} from '../../src/stripeClient'; import {StripeDaemon} from '../../src/daemon/stripeDaemon'; import {StripeLogsViewProvider} from '../../src/stripeLogsView'; -import {StripeResourceDocumentContentProvider} from '../../src/stripeResourceDocumentContentProvider'; - suite('stripeLogsView', () => { let sandbox: sinon.SinonSandbox; @@ -29,8 +27,6 @@ suite('stripeLogsView', () => { setupClient: () => {}, }; - const contentProvider = >{}; - let logsTailStream: grpc.ClientReadableStream; let daemonClient: Partial; @@ -61,7 +57,6 @@ suite('stripeLogsView', () => { stripeClient, stripeDaemon, extensionContext, - contentProvider, ); await stripeLogsView.startStreaming(); @@ -91,7 +86,6 @@ suite('stripeLogsView', () => { stripeClient, stripeDaemon, extensionContext, - contentProvider, ); await stripeLogsView.startStreaming(); @@ -121,7 +115,6 @@ suite('stripeLogsView', () => { stripeClient, stripeDaemon, extensionContext, - contentProvider, ); await stripeLogsView.startStreaming(); @@ -151,7 +144,6 @@ suite('stripeLogsView', () => { stripeClient, stripeDaemon, extensionContext, - contentProvider, ); await stripeLogsView.startStreaming(); @@ -181,7 +173,6 @@ suite('stripeLogsView', () => { stripeClient, stripeDaemon, extensionContext, - contentProvider, ); await stripeLogsView.startStreaming(); @@ -212,7 +203,6 @@ suite('stripeLogsView', () => { stripeClient, stripeDaemon, extensionContext, - contentProvider, ); await stripeLogsView.startStreaming(); @@ -259,7 +249,6 @@ suite('stripeLogsView', () => { stripeClient, stripeDaemon, extensionContext, - contentProvider, ); await stripeLogsView.startStreaming(); @@ -292,7 +281,6 @@ suite('stripeLogsView', () => { stripeClient, stripeDaemon, extensionContext, - contentProvider, ); await stripeLogsView.startStreaming(); @@ -309,7 +297,6 @@ suite('stripeLogsView', () => { stripeClient, stripeDaemon, extensionContext, - contentProvider, ); await stripeLogsView.startStreaming(); @@ -333,7 +320,6 @@ suite('stripeLogsView', () => { stripeClient, stripeDaemon, extensionContext, - contentProvider, ); await stripeLogsView.startStreaming(); @@ -352,7 +338,6 @@ suite('stripeLogsView', () => { stripeClient, stripeDaemon, extensionContext, - contentProvider, ); await stripeLogsView.startStreaming(); diff --git a/test/suite/stripeWorkspaceState.test.ts b/test/suite/stripeWorkspaceState.test.ts index 08c2ceab..fe302327 100644 --- a/test/suite/stripeWorkspaceState.test.ts +++ b/test/suite/stripeWorkspaceState.test.ts @@ -26,7 +26,6 @@ import { setWebhookEndpoint, webhookEndpointKey, } from '../../src/stripeWorkspaceState'; -import {StripeCLIClient} from '../../src/rpc/commands_grpc_pb'; suite('stripeWorkspaceState', () => { let sandbox: sinon.SinonSandbox; @@ -128,18 +127,16 @@ suite('stripeWorkspaceState', () => { }); suite('LogDetails', () => { - test('add and retrieve log details', async () => { + test('add and retrieve log details', () => { const workspaceState = new TestMemento(); const extensionContext = {...mocks.extensionContextMock, workspaceState: workspaceState}; - const daemonClient = >{}; const logId = 'log_id'; - const logObject = {logId: logId, value: 'hello', insight: ''}; + const logObject = {logId: logId, value: 'hello'}; addLogDetails(extensionContext, logId, logObject); - const actual = await retrieveLogDetails(extensionContext, logId, daemonClient); - assert.deepStrictEqual(actual, logObject); + assert.deepStrictEqual(retrieveLogDetails(extensionContext, logId), logObject); }); test('clearLogDetails empties LogDetails key', () => {