diff --git a/package.json b/package.json index bc479c45..2f17d360 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "onView:stripeQuickLinksView", "onView:stripeHelpView", "onCommand:stripe.createStripeSample", + "onCommand:stripe.createWebhookEndpoint", "onCommand:stripe.login", "onCommand:stripe.openCLI", "onCommand:stripe.openWebhooksListen", @@ -152,6 +153,11 @@ "command": "stripe.openWebhooksDebugConfigure", "title": "Configure webhooks debugging" }, + { + "category": "Stripe", + "command": "stripe.createWebhookEndpoint", + "title": "Create a new webhook endpoint" + }, { "category": "Stripe", "command": "stripe.startEventsStreaming", diff --git a/src/commands.ts b/src/commands.ts index abfd1c3b..9ccae0cd 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -1,3 +1,4 @@ +import * as grpc from '@grpc/grpc-js'; import * as querystring from 'querystring'; import * as vscode from 'vscode'; import { @@ -29,10 +30,12 @@ import {StripeLogsViewProvider} from './stripeLogsView'; import {StripeSamples} from './stripeSamples'; import {StripeTerminal} from './stripeTerminal'; import {StripeTreeItem} from './stripeTreeItem'; +import {StripeWebhooksViewProvider} from './stripeWebhooksView'; import {SurveyPrompt} from './surveyPrompt'; import {Telemetry} from './telemetry'; import {TriggerRequest} from './rpc/trigger_pb'; import {TriggersListRequest} from './rpc/triggers_list_pb'; +import {WebhookEndpointCreateRequest} from './rpc/webhook_endpoint_create_pb'; export class Commands { telemetry: Telemetry; @@ -416,9 +419,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.', ); @@ -494,9 +495,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.', ); @@ -628,4 +627,48 @@ export class Commands { this.telemetry.sendEvent('createStripeSample'); await stripeSamples.selectAndCloneSample(); }; + + createWebhookEndpoint = async ( + stripeDaemon: StripeDaemon, + stripeOutputChannel: vscode.OutputChannel, + stripeWebhooksViewProvider: StripeWebhooksViewProvider, + ) => { + const url = await vscode.window.showInputBox({ + prompt: 'URL of the webhook endpoint.', + value: 'https://', + }); + const description = await vscode.window.showInputBox({ + prompt: 'Optional description of what the webhook is used for.', + }); + const connect = await vscode.window.showQuickPick(['Connected accounts', 'Your account only'], { + placeHolder: 'Should this endpoint receive events from connected accounts or from your account.', + }); + const isConnect = connect === 'Connected accounts'; + + const createRequest = new WebhookEndpointCreateRequest(); + createRequest.setUrl(url || ''); + createRequest.setDescription(description || ''); + createRequest.setConnect(isConnect); + + const daemonClient = await stripeDaemon.setupClient(); + daemonClient.webhookEndpointCreate(createRequest, (error, response) => { + if (error) { + if (error.code === grpc.status.UNIMPLEMENTED) { + vscode.window.showErrorMessage( + 'Please upgrade your Stripe CLI to the latest version to use this feature.', + ); + } else { + vscode.window.showErrorMessage( + `Failed to create webhook endpoint ${url}. ${error.details}`, + ); + } + } else if (response) { + stripeOutputChannel.appendLine(`Webhook endpoint ${url} created. Please go to the developer dashboard to update the details of the endpoint.`); + this.telemetry.sendEvent('createWebhookEndpoint'); + + // refresh webhook endpoints tree + stripeWebhooksViewProvider.refreshEndpoints(); + } + }); + }; } diff --git a/src/extension.ts b/src/extension.ts index d0bfd770..838b1547 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -166,6 +166,10 @@ export function activate(this: any, context: ExtensionContext) { ], ['stripe.openWebhooksDebugConfigure', stripeCommands.openWebhooksDebugConfigure], ['stripe.openWebhooksListen', stripeCommands.openWebhooksListen], + [ + 'stripe.createWebhookEndpoint', + () => stripeCommands.createWebhookEndpoint(stripeDaemon, stripeOutputChannel, stripeWebhooksViewProvider), + ], [ 'stripe.resendEvent', (treeItem) => stripeCommands.resendEvent(treeItem, stripeDaemon, stripeOutputChannel), diff --git a/src/rpc/commands_grpc_pb.d.ts b/src/rpc/commands_grpc_pb.d.ts index 7f94a156..6d5cb8c5 100644 --- a/src/rpc/commands_grpc_pb.d.ts +++ b/src/rpc/commands_grpc_pb.d.ts @@ -16,6 +16,7 @@ import * as samples_list_pb from "./samples_list_pb"; import * as trigger_pb from "./trigger_pb"; import * as triggers_list_pb from "./triggers_list_pb"; import * as version_pb from "./version_pb"; +import * as webhook_endpoint_create_pb from "./webhook_endpoint_create_pb"; import * as webhook_endpoints_list_pb from "./webhook_endpoints_list_pb"; import * as grpc from "@grpc/grpc-js"; @@ -32,6 +33,7 @@ interface IStripeCLIService extends grpc.ServiceDefinition; triggersList: grpc.MethodDefinition; version: grpc.MethodDefinition; + webhookEndpointCreate: grpc.MethodDefinition; webhookEndpointsList: grpc.MethodDefinition; } @@ -50,6 +52,7 @@ export interface IStripeCLIServer extends grpc.UntypedServiceImplementation { trigger: grpc.handleUnaryCall; triggersList: grpc.handleUnaryCall; version: grpc.handleUnaryCall; + webhookEndpointCreate: grpc.handleUnaryCall; webhookEndpointsList: grpc.handleUnaryCall; } @@ -89,6 +92,9 @@ export class StripeCLIClient extends grpc.Client { version(argument: version_pb.VersionRequest, callback: grpc.requestCallback): grpc.ClientUnaryCall; version(argument: version_pb.VersionRequest, metadataOrOptions: grpc.Metadata | grpc.CallOptions | null, callback: grpc.requestCallback): grpc.ClientUnaryCall; version(argument: version_pb.VersionRequest, metadata: grpc.Metadata | null, options: grpc.CallOptions | null, callback: grpc.requestCallback): grpc.ClientUnaryCall; + webhookEndpointCreate(argument: webhook_endpoint_create_pb.WebhookEndpointCreateRequest, callback: grpc.requestCallback): grpc.ClientUnaryCall; + webhookEndpointCreate(argument: webhook_endpoint_create_pb.WebhookEndpointCreateRequest, metadataOrOptions: grpc.Metadata | grpc.CallOptions | null, callback: grpc.requestCallback): grpc.ClientUnaryCall; + webhookEndpointCreate(argument: webhook_endpoint_create_pb.WebhookEndpointCreateRequest, metadata: grpc.Metadata | null, options: grpc.CallOptions | null, callback: grpc.requestCallback): grpc.ClientUnaryCall; webhookEndpointsList(argument: webhook_endpoints_list_pb.WebhookEndpointsListRequest, callback: grpc.requestCallback): grpc.ClientUnaryCall; webhookEndpointsList(argument: webhook_endpoints_list_pb.WebhookEndpointsListRequest, metadataOrOptions: grpc.Metadata | grpc.CallOptions | null, callback: grpc.requestCallback): grpc.ClientUnaryCall; webhookEndpointsList(argument: webhook_endpoints_list_pb.WebhookEndpointsListRequest, metadata: grpc.Metadata | null, options: grpc.CallOptions | null, callback: grpc.requestCallback): grpc.ClientUnaryCall; diff --git a/src/rpc/commands_grpc_pb.js b/src/rpc/commands_grpc_pb.js index 2593151a..8b6cade5 100644 --- a/src/rpc/commands_grpc_pb.js +++ b/src/rpc/commands_grpc_pb.js @@ -14,6 +14,7 @@ var samples_list_pb = require('./samples_list_pb.js'); var trigger_pb = require('./trigger_pb.js'); var triggers_list_pb = require('./triggers_list_pb.js'); var version_pb = require('./version_pb.js'); +var webhook_endpoint_create_pb = require('./webhook_endpoint_create_pb.js'); var webhook_endpoints_list_pb = require('./webhook_endpoints_list_pb.js'); function serialize_rpc_EventsResendRequest(arg) { @@ -280,6 +281,28 @@ function deserialize_rpc_VersionResponse(buffer_arg) { return version_pb.VersionResponse.deserializeBinary(new Uint8Array(buffer_arg)); } +function serialize_rpc_WebhookEndpointCreateRequest(arg) { + if (!(arg instanceof webhook_endpoint_create_pb.WebhookEndpointCreateRequest)) { + throw new Error('Expected argument of type rpc.WebhookEndpointCreateRequest'); + } + return Buffer.from(arg.serializeBinary()); +} + +function deserialize_rpc_WebhookEndpointCreateRequest(buffer_arg) { + return webhook_endpoint_create_pb.WebhookEndpointCreateRequest.deserializeBinary(new Uint8Array(buffer_arg)); +} + +function serialize_rpc_WebhookEndpointCreateResponse(arg) { + if (!(arg instanceof webhook_endpoint_create_pb.WebhookEndpointCreateResponse)) { + throw new Error('Expected argument of type rpc.WebhookEndpointCreateResponse'); + } + return Buffer.from(arg.serializeBinary()); +} + +function deserialize_rpc_WebhookEndpointCreateResponse(buffer_arg) { + return webhook_endpoint_create_pb.WebhookEndpointCreateResponse.deserializeBinary(new Uint8Array(buffer_arg)); +} + function serialize_rpc_WebhookEndpointsListRequest(arg) { if (!(arg instanceof webhook_endpoints_list_pb.WebhookEndpointsListRequest)) { throw new Error('Expected argument of type rpc.WebhookEndpointsListRequest'); @@ -450,6 +473,18 @@ version: { responseSerialize: serialize_rpc_VersionResponse, responseDeserialize: deserialize_rpc_VersionResponse, }, + // Create a new webhook endpoint +webhookEndpointCreate: { + path: '/rpc.StripeCLI/WebhookEndpointCreate', + requestStream: false, + responseStream: false, + requestType: webhook_endpoint_create_pb.WebhookEndpointCreateRequest, + responseType: webhook_endpoint_create_pb.WebhookEndpointCreateResponse, + requestSerialize: serialize_rpc_WebhookEndpointCreateRequest, + requestDeserialize: deserialize_rpc_WebhookEndpointCreateRequest, + responseSerialize: serialize_rpc_WebhookEndpointCreateResponse, + responseDeserialize: deserialize_rpc_WebhookEndpointCreateResponse, + }, // Get the list of webhook endpoints. webhookEndpointsList: { path: '/rpc.StripeCLI/WebhookEndpointsList', diff --git a/src/rpc/commands_pb.d.ts b/src/rpc/commands_pb.d.ts index 11e93d5b..c6da4555 100644 --- a/src/rpc/commands_pb.d.ts +++ b/src/rpc/commands_pb.d.ts @@ -14,5 +14,6 @@ import * as samples_list_pb from "./samples_list_pb"; import * as trigger_pb from "./trigger_pb"; import * as triggers_list_pb from "./triggers_list_pb"; import * as version_pb from "./version_pb"; +import * as webhook_endpoint_create_pb from "./webhook_endpoint_create_pb"; import * as webhook_endpoints_list_pb from "./webhook_endpoints_list_pb"; diff --git a/src/rpc/commands_pb.js b/src/rpc/commands_pb.js index 9cb52b0e..2564e290 100644 --- a/src/rpc/commands_pb.js +++ b/src/rpc/commands_pb.js @@ -39,5 +39,7 @@ var triggers_list_pb = require('./triggers_list_pb.js'); goog.object.extend(proto, triggers_list_pb); var version_pb = require('./version_pb.js'); goog.object.extend(proto, version_pb); +var webhook_endpoint_create_pb = require('./webhook_endpoint_create_pb.js'); +goog.object.extend(proto, webhook_endpoint_create_pb); var webhook_endpoints_list_pb = require('./webhook_endpoints_list_pb.js'); goog.object.extend(proto, webhook_endpoints_list_pb); diff --git a/src/rpc/webhook_endpoint_create_grpc_pb.d.ts b/src/rpc/webhook_endpoint_create_grpc_pb.d.ts new file mode 100644 index 00000000..51b4d695 --- /dev/null +++ b/src/rpc/webhook_endpoint_create_grpc_pb.d.ts @@ -0,0 +1 @@ +// GENERATED CODE -- NO SERVICES IN PROTO diff --git a/src/rpc/webhook_endpoint_create_grpc_pb.js b/src/rpc/webhook_endpoint_create_grpc_pb.js new file mode 100644 index 00000000..97b3a246 --- /dev/null +++ b/src/rpc/webhook_endpoint_create_grpc_pb.js @@ -0,0 +1 @@ +// GENERATED CODE -- NO SERVICES IN PROTO \ No newline at end of file diff --git a/src/rpc/webhook_endpoint_create_pb.d.ts b/src/rpc/webhook_endpoint_create_pb.d.ts new file mode 100644 index 00000000..94633969 --- /dev/null +++ b/src/rpc/webhook_endpoint_create_pb.d.ts @@ -0,0 +1,49 @@ +// package: rpc +// file: webhook_endpoint_create.proto + +import * as jspb from "google-protobuf"; + +export class WebhookEndpointCreateRequest extends jspb.Message { + getUrl(): string; + setUrl(value: string): void; + + getDescription(): string; + setDescription(value: string): void; + + getConnect(): boolean; + setConnect(value: boolean): void; + + serializeBinary(): Uint8Array; + toObject(includeInstance?: boolean): WebhookEndpointCreateRequest.AsObject; + static toObject(includeInstance: boolean, msg: WebhookEndpointCreateRequest): WebhookEndpointCreateRequest.AsObject; + static extensions: {[key: number]: jspb.ExtensionFieldInfo}; + static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; + static serializeBinaryToWriter(message: WebhookEndpointCreateRequest, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): WebhookEndpointCreateRequest; + static deserializeBinaryFromReader(message: WebhookEndpointCreateRequest, reader: jspb.BinaryReader): WebhookEndpointCreateRequest; +} + +export namespace WebhookEndpointCreateRequest { + export type AsObject = { + url: string, + description: string, + connect: boolean, + } +} + +export class WebhookEndpointCreateResponse extends jspb.Message { + serializeBinary(): Uint8Array; + toObject(includeInstance?: boolean): WebhookEndpointCreateResponse.AsObject; + static toObject(includeInstance: boolean, msg: WebhookEndpointCreateResponse): WebhookEndpointCreateResponse.AsObject; + static extensions: {[key: number]: jspb.ExtensionFieldInfo}; + static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; + static serializeBinaryToWriter(message: WebhookEndpointCreateResponse, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): WebhookEndpointCreateResponse; + static deserializeBinaryFromReader(message: WebhookEndpointCreateResponse, reader: jspb.BinaryReader): WebhookEndpointCreateResponse; +} + +export namespace WebhookEndpointCreateResponse { + export type AsObject = { + } +} + diff --git a/src/rpc/webhook_endpoint_create_pb.js b/src/rpc/webhook_endpoint_create_pb.js new file mode 100644 index 00000000..933b901a --- /dev/null +++ b/src/rpc/webhook_endpoint_create_pb.js @@ -0,0 +1,353 @@ +// source: webhook_endpoint_create.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.WebhookEndpointCreateRequest', null, global); +goog.exportSymbol('proto.rpc.WebhookEndpointCreateResponse', 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.WebhookEndpointCreateRequest = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.rpc.WebhookEndpointCreateRequest, jspb.Message); +if (goog.DEBUG && !COMPILED) { + /** + * @public + * @override + */ + proto.rpc.WebhookEndpointCreateRequest.displayName = 'proto.rpc.WebhookEndpointCreateRequest'; +} +/** + * 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.WebhookEndpointCreateResponse = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.rpc.WebhookEndpointCreateResponse, jspb.Message); +if (goog.DEBUG && !COMPILED) { + /** + * @public + * @override + */ + proto.rpc.WebhookEndpointCreateResponse.displayName = 'proto.rpc.WebhookEndpointCreateResponse'; +} + + + +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.WebhookEndpointCreateRequest.prototype.toObject = function(opt_includeInstance) { + return proto.rpc.WebhookEndpointCreateRequest.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.WebhookEndpointCreateRequest} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.rpc.WebhookEndpointCreateRequest.toObject = function(includeInstance, msg) { + var f, obj = { + url: jspb.Message.getFieldWithDefault(msg, 1, ""), + description: jspb.Message.getFieldWithDefault(msg, 2, ""), + connect: jspb.Message.getBooleanFieldWithDefault(msg, 3, false) + }; + + 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.WebhookEndpointCreateRequest} + */ +proto.rpc.WebhookEndpointCreateRequest.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.rpc.WebhookEndpointCreateRequest; + return proto.rpc.WebhookEndpointCreateRequest.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.rpc.WebhookEndpointCreateRequest} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.rpc.WebhookEndpointCreateRequest} + */ +proto.rpc.WebhookEndpointCreateRequest.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.setUrl(value); + break; + case 2: + var value = /** @type {string} */ (reader.readString()); + msg.setDescription(value); + break; + case 3: + var value = /** @type {boolean} */ (reader.readBool()); + msg.setConnect(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.rpc.WebhookEndpointCreateRequest.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.rpc.WebhookEndpointCreateRequest.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.WebhookEndpointCreateRequest} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.rpc.WebhookEndpointCreateRequest.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getUrl(); + if (f.length > 0) { + writer.writeString( + 1, + f + ); + } + f = message.getDescription(); + if (f.length > 0) { + writer.writeString( + 2, + f + ); + } + f = message.getConnect(); + if (f) { + writer.writeBool( + 3, + f + ); + } +}; + + +/** + * optional string url = 1; + * @return {string} + */ +proto.rpc.WebhookEndpointCreateRequest.prototype.getUrl = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); +}; + + +/** + * @param {string} value + * @return {!proto.rpc.WebhookEndpointCreateRequest} returns this + */ +proto.rpc.WebhookEndpointCreateRequest.prototype.setUrl = function(value) { + return jspb.Message.setProto3StringField(this, 1, value); +}; + + +/** + * optional string description = 2; + * @return {string} + */ +proto.rpc.WebhookEndpointCreateRequest.prototype.getDescription = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 2, "")); +}; + + +/** + * @param {string} value + * @return {!proto.rpc.WebhookEndpointCreateRequest} returns this + */ +proto.rpc.WebhookEndpointCreateRequest.prototype.setDescription = function(value) { + return jspb.Message.setProto3StringField(this, 2, value); +}; + + +/** + * optional bool connect = 3; + * @return {boolean} + */ +proto.rpc.WebhookEndpointCreateRequest.prototype.getConnect = function() { + return /** @type {boolean} */ (jspb.Message.getBooleanFieldWithDefault(this, 3, false)); +}; + + +/** + * @param {boolean} value + * @return {!proto.rpc.WebhookEndpointCreateRequest} returns this + */ +proto.rpc.WebhookEndpointCreateRequest.prototype.setConnect = function(value) { + return jspb.Message.setProto3BooleanField(this, 3, 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.WebhookEndpointCreateResponse.prototype.toObject = function(opt_includeInstance) { + return proto.rpc.WebhookEndpointCreateResponse.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.WebhookEndpointCreateResponse} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.rpc.WebhookEndpointCreateResponse.toObject = function(includeInstance, msg) { + var f, obj = { + + }; + + 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.WebhookEndpointCreateResponse} + */ +proto.rpc.WebhookEndpointCreateResponse.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.rpc.WebhookEndpointCreateResponse; + return proto.rpc.WebhookEndpointCreateResponse.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.rpc.WebhookEndpointCreateResponse} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.rpc.WebhookEndpointCreateResponse} + */ +proto.rpc.WebhookEndpointCreateResponse.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.rpc.WebhookEndpointCreateResponse.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.rpc.WebhookEndpointCreateResponse.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.WebhookEndpointCreateResponse} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.rpc.WebhookEndpointCreateResponse.serializeBinaryToWriter = function(message, writer) { + var f = undefined; +}; + + +goog.object.extend(exports, proto.rpc); diff --git a/src/stripeWebhooksView.ts b/src/stripeWebhooksView.ts index 78eb8251..979f37eb 100644 --- a/src/stripeWebhooksView.ts +++ b/src/stripeWebhooksView.ts @@ -1,8 +1,9 @@ +import * as grpc from '@grpc/grpc-js'; import * as vscode from 'vscode'; import {StripeDaemon} from './daemon/stripeDaemon'; import {StripeTreeItem} from './stripeTreeItem'; import {StripeTreeViewDataProvider} from './stripeTreeViewDataProvider'; -// import {ThemeIcon} from 'vscode'; +import {ThemeIcon} from 'vscode'; import {WebhookEndpointsListRequest} from './rpc/webhook_endpoints_list_pb'; export class StripeWebhooksViewProvider extends StripeTreeViewDataProvider { @@ -18,14 +19,13 @@ export class StripeWebhooksViewProvider extends StripeTreeViewDataProvider { buildTree(): Promise { const items = []; - // DX-7014 - // const createEndpoint = new StripeTreeItem('Create a new webhook endpoint', { - // commandString: 'createWebhookEndpoint', - // iconPath: new ThemeIcon('add'), - // tooltip: 'Create a new webhook endpoint', - // contextValue: 'createWebhookEndpoint', - // }); - // items.push(createEndpoint); + const createEndpoint = new StripeTreeItem('Create a new webhook endpoint', { + commandString: 'createWebhookEndpoint', + iconPath: new ThemeIcon('add'), + tooltip: 'Create a new webhook endpoint', + contextValue: 'createWebhookEndpoint', + }); + items.push(createEndpoint); if (this.endpointItems.length > 0) { const endpointsRootItem = new StripeTreeItem('All webhook endpoints'); @@ -41,9 +41,7 @@ export class StripeWebhooksViewProvider extends StripeTreeViewDataProvider { const daemonClient = await this.stripeDaemon.setupClient(); daemonClient.webhookEndpointsList(new WebhookEndpointsListRequest(), (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.', ); @@ -59,7 +57,12 @@ export class StripeWebhooksViewProvider extends StripeTreeViewDataProvider { const enabledEventsRootItem = new StripeTreeItem('Enabled events'); const enabledEvents = e.getEnabledeventsList(); enabledEventsRootItem.children = enabledEvents.map( - (event) => new StripeTreeItem(event), + (event) => { + if (event === '*') { + return new StripeTreeItem('* (All events except those that require explicit selection)'); + } + return new StripeTreeItem(event); + } ); enabledEventsRootItem.makeCollapsible();