Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve and refresh integration insight on demand #499

Merged
merged 6 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as grpc from '@grpc/grpc-js';
import * as querystring from 'querystring';
import * as vscode from 'vscode';
import {
Expand Down Expand Up @@ -351,9 +352,10 @@ export class Commands {

openLogDetails = (data: any) => {
this.telemetry.sendEvent('openLogDetails');
const {id} = data;
const {id, provider} = 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'))
Expand Down Expand Up @@ -416,9 +418,7 @@ export class Commands {
fixtureRequest.setEvent(eventName);
daemonClient.fixture(fixtureRequest, (error, response) => {
if (error) {
if (error.code === 12) {
// https://grpc.github.io/grpc/core/md_doc_statuscodes.html
// 12: UNIMPLEMENTED
if (error.code === grpc.status.UNIMPLEMENTED) {
vscode.window.showErrorMessage(
'Please upgrade your Stripe CLI to the latest version to use this feature.',
);
Expand Down Expand Up @@ -494,9 +494,7 @@ export class Commands {

daemonClient.trigger(triggerRequest, (error, response) => {
if (error) {
if (error.code === 12) {
// https://grpc.github.io/grpc/core/md_doc_statuscodes.html
// 12: UNIMPLEMENTED
if (error.code === grpc.status.UNIMPLEMENTED) {
vscode.window.showErrorMessage(
'Please upgrade your Stripe CLI to the latest version to use this feature.',
);
Expand Down
36 changes: 19 additions & 17 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {SurveyPrompt} from './surveyPrompt';
import {TelemetryPrompt} from './telemetryPrompt';
import path from 'path';

export function activate(this: any, context: ExtensionContext) {
export async function activate(this: any, context: ExtensionContext) {
initializeStripeWorkspaceState(context);

new TelemetryPrompt(context).activate();
Expand All @@ -52,6 +52,23 @@ export 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,
Expand All @@ -63,7 +80,7 @@ export function activate(this: any, context: ExtensionContext) {
showCollapseAll: true,
});

const stripeLogsViewProvider = new StripeLogsViewProvider(stripeClient, stripeDaemon, context);
const stripeLogsViewProvider = new StripeLogsViewProvider(stripeClient, stripeDaemon, context, logContentProvider);
window.createTreeView('stripeLogsView', {
treeDataProvider: stripeLogsViewProvider,
showCollapseAll: true,
Expand Down Expand Up @@ -94,21 +111,6 @@ export 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();

Expand Down
6 changes: 6 additions & 0 deletions src/rpc/commands_grpc_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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";
Expand All @@ -22,6 +23,7 @@ import * as grpc from "@grpc/grpc-js";
interface IStripeCLIService extends grpc.ServiceDefinition<grpc.UntypedServiceImplementation> {
eventsResend: grpc.MethodDefinition<events_resend_pb.EventsResendRequest, events_resend_pb.EventsResendResponse>;
fixture: grpc.MethodDefinition<fixtures_pb.FixtureRequest, fixtures_pb.FixtureResponse>;
integrationInsight: grpc.MethodDefinition<integration_insights_pb.IntegrationInsightRequest, integration_insights_pb.IntegrationInsightResponse>;
listen: grpc.MethodDefinition<listen_pb.ListenRequest, listen_pb.ListenResponse>;
login: grpc.MethodDefinition<login_pb.LoginRequest, login_pb.LoginResponse>;
loginStatus: grpc.MethodDefinition<login_status_pb.LoginStatusRequest, login_status_pb.LoginStatusResponse>;
Expand All @@ -40,6 +42,7 @@ export const StripeCLIService: IStripeCLIService;
export interface IStripeCLIServer extends grpc.UntypedServiceImplementation {
eventsResend: grpc.handleUnaryCall<events_resend_pb.EventsResendRequest, events_resend_pb.EventsResendResponse>;
fixture: grpc.handleUnaryCall<fixtures_pb.FixtureRequest, fixtures_pb.FixtureResponse>;
integrationInsight: grpc.handleUnaryCall<integration_insights_pb.IntegrationInsightRequest, integration_insights_pb.IntegrationInsightResponse>;
listen: grpc.handleServerStreamingCall<listen_pb.ListenRequest, listen_pb.ListenResponse>;
login: grpc.handleUnaryCall<login_pb.LoginRequest, login_pb.LoginResponse>;
loginStatus: grpc.handleUnaryCall<login_status_pb.LoginStatusRequest, login_status_pb.LoginStatusResponse>;
Expand All @@ -61,6 +64,9 @@ export class StripeCLIClient extends grpc.Client {
fixture(argument: fixtures_pb.FixtureRequest, callback: grpc.requestCallback<fixtures_pb.FixtureResponse>): grpc.ClientUnaryCall;
fixture(argument: fixtures_pb.FixtureRequest, metadataOrOptions: grpc.Metadata | grpc.CallOptions | null, callback: grpc.requestCallback<fixtures_pb.FixtureResponse>): grpc.ClientUnaryCall;
fixture(argument: fixtures_pb.FixtureRequest, metadata: grpc.Metadata | null, options: grpc.CallOptions | null, callback: grpc.requestCallback<fixtures_pb.FixtureResponse>): grpc.ClientUnaryCall;
integrationInsight(argument: integration_insights_pb.IntegrationInsightRequest, callback: grpc.requestCallback<integration_insights_pb.IntegrationInsightResponse>): grpc.ClientUnaryCall;
integrationInsight(argument: integration_insights_pb.IntegrationInsightRequest, metadataOrOptions: grpc.Metadata | grpc.CallOptions | null, callback: grpc.requestCallback<integration_insights_pb.IntegrationInsightResponse>): grpc.ClientUnaryCall;
integrationInsight(argument: integration_insights_pb.IntegrationInsightRequest, metadata: grpc.Metadata | null, options: grpc.CallOptions | null, callback: grpc.requestCallback<integration_insights_pb.IntegrationInsightResponse>): grpc.ClientUnaryCall;
listen(argument: listen_pb.ListenRequest, metadataOrOptions?: grpc.Metadata | grpc.CallOptions | null): grpc.ClientReadableStream<listen_pb.ListenResponse>;
listen(argument: listen_pb.ListenRequest, metadata?: grpc.Metadata | null, options?: grpc.CallOptions | null): grpc.ClientReadableStream<listen_pb.ListenResponse>;
login(argument: login_pb.LoginRequest, callback: grpc.requestCallback<login_pb.LoginResponse>): grpc.ClientUnaryCall;
Expand Down
35 changes: 35 additions & 0 deletions src/rpc/commands_grpc_pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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');
Expand Down Expand Up @@ -60,6 +61,28 @@ 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');
Expand Down Expand Up @@ -328,6 +351,18 @@ 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',
Expand Down
1 change: 1 addition & 0 deletions src/rpc/commands_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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";
Expand Down
2 changes: 2 additions & 0 deletions src/rpc/commands_pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ 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');
Expand Down
1 change: 1 addition & 0 deletions src/rpc/integration_insights_grpc_pb.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// GENERATED CODE -- NO SERVICES IN PROTO
1 change: 1 addition & 0 deletions src/rpc/integration_insights_grpc_pb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// GENERATED CODE -- NO SERVICES IN PROTO
45 changes: 45 additions & 0 deletions src/rpc/integration_insights_pb.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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<jspb.Message>};
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
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<jspb.Message>};
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
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,
}
}

Loading