Skip to content

Create webhook when config is created #1873

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

Merged
merged 18 commits into from
Apr 22, 2025
Merged

Create webhook when config is created #1873

merged 18 commits into from
Apr 22, 2025

Conversation

lkostrowski
Copy link
Member

Scope of the PR

Related issues

Checklist

Copy link

changeset-bot bot commented Apr 17, 2025

⚠️ No Changeset found

Latest commit: 5517b00

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Apr 17, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
apps-stripe ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 22, 2025 9:44am
7 Skipped Deployments
Name Status Preview Comments Updated (UTC)
saleor-app-avatax ⬜️ Ignored (Inspect) Visit Preview Apr 22, 2025 9:44am
saleor-app-cms ⬜️ Ignored (Inspect) Visit Preview Apr 22, 2025 9:44am
saleor-app-klaviyo ⬜️ Ignored (Inspect) Visit Preview Apr 22, 2025 9:44am
saleor-app-products-feed ⬜️ Ignored (Inspect) Visit Preview Apr 22, 2025 9:44am
saleor-app-search ⬜️ Ignored (Inspect) Visit Preview Apr 22, 2025 9:44am
saleor-app-segment ⬜️ Ignored (Inspect) Visit Preview Apr 22, 2025 9:44am
saleor-app-smtp ⬜️ Ignored (Inspect) Visit Preview Apr 22, 2025 9:44am

Copy link

codecov bot commented Apr 17, 2025

Codecov Report

Attention: Patch coverage is 80.39216% with 50 lines in your changes missing coverage. Please review.

Project coverage is 26.29%. Comparing base (3725d73) to head (5517b00).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...ig/trpc-handlers/new-stripe-config-trpc-handler.ts 63.95% 31 Missing ⚠️
...ransactions-recording/transaction-recorder-file.ts 0.00% 5 Missing ⚠️
...dules/ui/stripe-configs/new-stripe-config-form.tsx 0.00% 5 Missing ⚠️
...ipe/src/modules/app-config/file-app-config-repo.ts 0.00% 4 Missing ⚠️
...ules/app-config/trpc-handlers/app-config-router.ts 0.00% 4 Missing ⚠️
apps/stripe/src/modules/trpc/context-app-router.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1873      +/-   ##
==========================================
+ Coverage   26.04%   26.29%   +0.24%     
==========================================
  Files         784      788       +4     
  Lines       54526    54769     +243     
  Branches     1908     1936      +28     
==========================================
+ Hits        14202    14401     +199     
- Misses      39955    39999      +44     
  Partials      369      369              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

Differences Found

✅ No packages or licenses were added.

Summary

Expand
License Name Package Count Packages
0BSD 1
Packages
  • tslib
CC BY-SA 4.0 1
Packages
  • @cspell/dict-en-common-misspellings
CC-BY-3.0 1
Packages
  • spdx-exceptions
MIT (http://mootools.net/license.txt) 1
Packages
  • slick
MIT/X11 1
Packages
  • nub
Public Domain 1
Packages
  • jsonify
Python-2.0 1
Packages
  • argparse
SEE LICENSE IN LICENSE 1
Packages
  • spawndamnit
SEE LICENSE IN LICENSE.md 1
Packages
  • lightcookie
Unlicense 1
Packages
  • @sinonjs/text-encoding
WTFPL 1
Packages
  • opener
CC-BY-4.0 2
Packages
  • @saleor/macaw-ui
  • caniuse-lite
CC0-1.0 2
Packages
  • spdx-license-ids
  • type-fest
BlueOak-1.0.0 3
Packages
  • jackspeak
  • package-json-from-dist
  • path-scurry
<<missing>> 4
Packages
  • bruno
  • busboy
  • json-query
  • streamsearch
LGPL-3.0-or-later 11
Packages
  • @img/sharp-libvips-darwin-arm64
  • @img/sharp-libvips-darwin-x64
  • @img/sharp-libvips-linux-arm
  • @img/sharp-libvips-linux-arm64
  • @img/sharp-libvips-linux-s390x
  • @img/sharp-libvips-linux-x64
  • @img/sharp-libvips-linuxmusl-arm64
  • @img/sharp-libvips-linuxmusl-x64
  • @img/sharp-wasm32
  • @img/sharp-win32-ia32
  • @img/sharp-win32-x64
BSD-2-Clause 23
Packages
  • cheerio-select
  • css-select
  • css-what
  • domelementtype
  • domhandler
  • domutils
  • dotenv
  • entities
  • escodegen
  • eslint-scope
  • espree
  • esprima
  • esrecurse
  • estraverse
  • esutils
  • glob-to-regexp
  • normalize-package-data
  • nth-check
  • shimmer
  • terser
  • And 3 more...
BSD-3-Clause 47
Packages
  • @protobufjs/aspromise
  • @protobufjs/base64
  • @protobufjs/codegen
  • @protobufjs/eventemitter
  • @protobufjs/fetch
  • @protobufjs/float
  • @protobufjs/inquire
  • @protobufjs/path
  • @protobufjs/pool
  • @protobufjs/utf8
  • @saleor/app-sdk
  • @saleor/eslint-plugin-saleor-app
  • @sentry/cli
  • @sentry/cli-darwin
  • @sentry/cli-linux-arm
  • @sentry/cli-linux-arm64
  • @sentry/cli-linux-i686
  • @sentry/cli-linux-x64
  • @sentry/cli-win32-i686
  • @sentry/cli-win32-x64
  • And 27 more...
ISC 51
Packages
  • @isaacs/cliui
  • abbrev
  • anymatch
  • boolbase
  • cli-width
  • cliui
  • concat-with-sourcemaps
  • electron-to-chromium
  • fastq
  • flatted
  • foreground-child
  • form-data-lite
  • fs.realpath
  • get-caller-file
  • glob
  • glob-parent
  • graceful-fs
  • hosted-git-info
  • inflight
  • inherits
  • And 31 more...
Apache-2.0 230
Packages
  • @ampproject/remapping
  • @aws-crypto/crc32
  • @aws-crypto/crc32c
  • @aws-crypto/ie11-detection
  • @aws-crypto/sha1-browser
  • @aws-crypto/sha256-browser
  • @aws-crypto/sha256-js
  • @aws-crypto/supports-web-crypto
  • @aws-crypto/util
  • @aws-sdk/abort-controller
  • @aws-sdk/chunked-blob-reader
  • @aws-sdk/client-dynamodb
  • @aws-sdk/client-s3
  • @aws-sdk/client-sso
  • @aws-sdk/client-sso-oidc
  • @aws-sdk/client-sts
  • @aws-sdk/config-resolver
  • @aws-sdk/core
  • @aws-sdk/credential-provider-env
  • @aws-sdk/credential-provider-http
  • And 210 more...
MIT 1403
Packages
  • @0no-co/graphql.web
  • @algolia/cache-browser-local-storage
  • @algolia/cache-common
  • @algolia/cache-in-memory
  • @algolia/client-account
  • @algolia/client-analytics
  • @algolia/client-common
  • @algolia/client-personalization
  • @algolia/client-search
  • @algolia/logger-common
  • @algolia/logger-console
  • @algolia/recommend
  • @algolia/requester-browser-xhr
  • @algolia/requester-common
  • @algolia/requester-node-http
  • @algolia/transporter
  • @ardatan/relay-compiler
  • @ardatan/sync-fetch
  • @arr/every
  • @babel/code-frame
  • And 1383 more...

@vercel vercel bot temporarily deployed to Preview – saleor-app-products-feed April 17, 2025 12:39 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-segment April 17, 2025 12:39 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-smtp April 17, 2025 12:39 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-avatax April 17, 2025 12:39 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-klaviyo April 17, 2025 12:39 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-search April 17, 2025 12:39 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-cms April 17, 2025 12:39 Inactive
@@ -0,0 +1,16 @@
import type { Stripe } from "stripe";

export const supportedStripeEvents: Array<Stripe.WebhookEndpointCreateParams.EnabledEvent> = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to support all those events? I'm wondering e.g what should app report payment_intent.created - maybe we can start with supporting:

payment_intent.succeeded
payment_intent.amount_capturable_updated

Or we want to create webhook with the most events covered and then add case by case? If yes - maybe we can still add support for new event both here and in webhook handler (at least in development).

We should also think if it is possible to migrate existing webhooks e.g if we decided to add new event in the future

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied them blindly, I will add only the ones we support NOW and we can keep adding

@vercel vercel bot temporarily deployed to Preview – saleor-app-cms April 22, 2025 09:29 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-avatax April 22, 2025 09:29 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-segment April 22, 2025 09:29 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-search April 22, 2025 09:29 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-products-feed April 22, 2025 09:29 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-klaviyo April 22, 2025 09:29 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-smtp April 22, 2025 09:29 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-smtp April 22, 2025 09:31 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-search April 22, 2025 09:31 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-segment April 22, 2025 09:31 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-cms April 22, 2025 09:31 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-products-feed April 22, 2025 09:31 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-avatax April 22, 2025 09:31 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-klaviyo April 22, 2025 09:31 Inactive
@lkostrowski lkostrowski marked this pull request as ready for review April 22, 2025 09:31
@lkostrowski lkostrowski requested a review from a team as a code owner April 22, 2025 09:31
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements webhook creation when a new Stripe configuration is created. Key changes include:

  • Adding the new "appUrl" field in the TRPC context and updating webhook URL building.
  • Introducing "webhookId" as a required field in Stripe configuration and propagating it through repo, tests, and model validation.
  • Enhancing Stripe webhook management and TRPC handlers to support proper webhook creation and Stripe authentication checks.

Reviewed Changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
apps/stripe/src/modules/trpc/context-app-router.ts Added "appUrl" from the request header to the context.
apps/stripe/src/modules/transactions-recording/transaction-recorder-file.ts Added a check to ensure a transaction exists before proceeding.
apps/stripe/src/modules/stripe/supported-stripe-events.ts Defined supported Stripe event types.
apps/stripe/src/modules/stripe/stripe-webhook-url-builder.ts Implemented URL builder for Stripe webhooks with proper error handling.
apps/stripe/src/modules/stripe/stripe-webhook-manager.ts Created a new manager for handling webhook creation including error categorization.
apps/stripe/src/modules/stripe/stripe-client.ts Changed the constructor from private to public for instance creation.
apps/stripe/src/modules/stripe/stripe-auth-validator.ts Added auth validation integration with Stripe.
apps/stripe/src/modules/app-config/trpc-handlers/new-stripe-config-trpc-handler.ts Integrated webhook creation, URL validation, and authentication checks into the TRPC handler.
apps/stripe/src/modules/app-config/stripe-config.ts Updated the StripeConfig model with a new "webhookId" field.
Other test and repository files Updated mocks and test cases to cover the new webhookId and webhook URL functionalities.
Comments suppressed due to low confidence (1)

apps/stripe/src/modules/app-config/stripe-config.test.ts:25

  • [nitpick] Ensure that using mockStripeWebhookSecret as the value for webhookId is intentional and aligns with the expected identifier format for a webhook.
webhookId: mockStripeWebhookSecret,

Comment on lines +14 to 15
constructor(nativeClient: Stripe) {
this.nativeClient = nativeClient;
Copy link
Preview

Copilot AI Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider confirming that making the constructor public is intentional, as the previous private constructor enforced controlled instance creation via createFromRestrictedKey.

Suggested change
constructor(nativeClient: Stripe) {
this.nativeClient = nativeClient;
private constructor(nativeClient: Stripe) {

Copilot uses AI. Check for mistakes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made it public for easier testing, this class is just a wrapper

@lkostrowski lkostrowski merged commit 3d2a45b into main Apr 22, 2025
29 checks passed
@lkostrowski lkostrowski deleted the webhook-creatio branch April 22, 2025 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
App Payment: Stripe skip changeset Attach this label to PRs which does not need changes description for the release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants