-
Notifications
You must be signed in to change notification settings - Fork 130
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
Toml webhook subscription parsing #3064
Conversation
Thanks for your contribution! Depending on what you are working on, you may want to request a review from a Shopify team:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't look at the tests yet but great work so far Alex! my comments are mostly for my own understanding and minor things that you may address as you work on this
d0ba034
to
833bbcd
Compare
We detected some changes at either packages/*/src or packages/cli-kit/assets/cli-ruby/** and there are no updates in the .changeset. |
833bbcd
to
1289360
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work! Very nice validations and test suite 👌
I've fixed a couple of failing tests.
.optional(), | ||
pubsub_project: PubSubProjectValidation, | ||
pubsub_topic: PubSubTopicValidation, | ||
arn: ArnValidation, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using callback_url
for everything instead of subscription_endpoint_url
, pubsub_project
, pubsub_topic
and arn
? As we do in the server now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to float the question about this, it would definitely simplify things! I think the biggest question was around the pub sub config. @karenxie @jenstanicak what do we think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the endpoint types are those 3 different options. But here we want to refer to the URI of each one where the event is going to be delivered:
- URL for HTTPS
- ARN for EventBridge
- Project::Topic for Pub/Sub
My suggestion was to use the same field name for all of them, to simplify the TOML structure, because we won't allow multiple endpoint types at the same time. Something like callback_uri
, destination_uri
or endpoint_uri
.
Note
As @alexanderMontague commented recently, to be precise, we should use URI instead of URL. URI is a general resource identifier, while URL is a specific type of URI for Web (the ones starting with http, unlike the ARNs).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm on board with the single URI identifier if that fits in with our UX/DX. It will simplify the error checking, code and validation content. The only main thing is for pub sub you won't have both the project and topic level overrides, which I dont think is a huge deal as you'll save a toml line and you can just type out the whole pub sub URI if you want something different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For an update here, I've gone ahead and replaced the individual "destinations/endpoints" with a singular endpoint
key. Example of a full TOML would be:
[webhooks]
api_version = "2023-10"
endpoint = "https://my-app.com/webhooks"
topics = ['products/create', 'products/update', 'products/delete']
[[webhooks.subscriptions]]
topic = 'products/create'
path = '/my-neat-path'
endpoint = 'https://valid-url'
[[webhooks.subscriptions]]
topic = 'products/create'
sub_topic = 'something'
path = '/only-path'
[[webhooks.subscriptions]]
topic = 'products/create'
path = '/my-neat-path-new'
include_fields = ['variants', 'title']
metafield_namespaces = ['size']
endpoint = 'https://valid-url'
[[webhooks.subscriptions]]
topic = 'products/delete'
format = 'xml'
endpoint = 'https://valid-url'
[[webhooks.subscriptions]]
topic = 'products/delete'
format = 'json'
endpoint = "pubsub://absolute-feat-123:pub-sub-topic1"
[[webhooks.subscriptions]]
endpoint = 'https://valid-url'
topic = 'products/delete'
format = 'xml'
path = "/absolute-feat-123"
[[webhooks.subscriptions]]
endpoint = "arn:aws:events:us-west-2::event-source/aws.partner/shopify.com/123/SOMETHING"
topic = 'products/delete'
[[webhooks.subscriptions]]
topic = "orders/delete"
path = "/absolute-feat-123"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the name, let me add some extra confusion:
- In the REST API we call it
address
: Destination URI to which the webhook subscription should send the POST request when an event occurs. - In the GraphQL API there's a property called
endpoint
, which can contain:callbackUrl
arn
pubSubProject
/pubSubTopic
- In the database we store it as
address
.
So if we want to be consistent with the current APIs, maybe the most accurate term would be address
, which matches what we have here (the URI for any kind of endpoint type). What do you think?
Coverage report
Show new covered files 🐣
Show files with reduced coverage 🔻
Test suite run success1480 tests passing in 666 suites. Report generated by 🧪jest coverage report action from 14fb416 |
@@ -119,6 +125,66 @@ export async function deploy(options: DeployOptions) { | |||
}, | |||
] | |||
|
|||
if (partnersApp.betas?.declarativeWebhooks) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gonzaloriestra thoughts on keeping this as a separate task? I think the code should definitely be separate, but how does this play into the deploy task especially once we start consuming other declarative app config. I think they somehow have to be tied together as this will ultimately be part of the new deployed app version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, better to separate the code (I'd even extract the task to another function). Regarding the tasks, from a UX perspective, I also see two concepts here: deploying extensions and configuration.
But I'm wondering if it will happen too quickly to read the messages, so maybe it would be better to have a single task. It depends on the timing. We can decide later, once we can check it properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will definitely be too quick to read the messages, so agree it makes sense to keep under the main deploy task. We'll pull the code out eventually though once things are finalized. The versioned config getting update is still an atomic action of an app deploy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you finally using a single task?
finalize toml parser and validations, begin on finishing tests finish tests
finalize webhook config normalization task and tests
refactor and split out validations rebase and fix imports Fix tests fix type circular dependencies
36a7a2a
to
f0c6e87
Compare
Thanks for pulling the content into the table, Alex! So helpful for me. Couple of persistent things:
And then a few specific callouts (as long as these changes are accurate!):
|
9ecbcaf
to
f110b5d
Compare
message: 'To use a top-level `endpoint`, you must also provide a `topics` array or `[[webhooks.subscriptions]]`', | ||
fatal: true, | ||
} | ||
} | ||
|
||
if (!hasEndpoint && hasTopics) { | ||
return { | ||
code: zod.ZodIssueCode.custom, | ||
message: 'To use top-level topics, you must also provide a top-level `endpoint`', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jenstanicak the content / error messages for these scenarios changed slightly with the endpoint
rename
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏 👏 👏
@@ -119,6 +125,66 @@ export async function deploy(options: DeployOptions) { | |||
}, | |||
] | |||
|
|||
if (partnersApp.betas?.declarativeWebhooks) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you finally using a single task?
@gonzaloriestra This is still technically a separate task, once we wire up the mutation/connectivity I will combine it with the deploy task. I also want to sync with Phong on the best way to do this such that it scales with all the other config as well |
f110b5d
to
eaee6d2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fantastic work here Alex! 👏 All makes sense to me - my comments are non-blocking
eaee6d2
to
14fb416
Compare
WHY are these changes introduced?
closes: https://github.com/Shopify/develop-app-management/issues/1500
WHAT is this pull request doing?
How to test your changes?
👀 New TOML Fields
New Top Level Fields
New
subscriptions
Level Fields👀 New CLI Content
subscription_endpoint_url
is not httpssubscription_endpoint_url
ends with a forward slash (could conflict with path) ex.https://example.ca/
path
does not start with a forward slash or is only 1 character (only the/
)topics
array orsubscriptions
configuration"Checklist
dev
ordeploy
have been reflected in the internal flowchart.