From 90245470285ed1f626382fabe3e8938281e5228f Mon Sep 17 00:00:00 2001 From: Alan Bridgeman Date: Sat, 24 Jan 2026 10:06:47 -0600 Subject: [PATCH] Added webhook support stuff --- src/oauth/index.ts | 4 ++ .../types/BridgemanAccessibleAppClaims.ts | 4 ++ src/oauth/types/Webhook.ts | 9 ++++ src/oauth/types/WebhookPurpose.ts | 54 +++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 src/oauth/types/Webhook.ts create mode 100644 src/oauth/types/WebhookPurpose.ts diff --git a/src/oauth/index.ts b/src/oauth/index.ts index ac44624..6912d48 100644 --- a/src/oauth/index.ts +++ b/src/oauth/index.ts @@ -1,6 +1,8 @@ import { OAuthApp } from './OAuthApp.js'; import type { BridgemanAccessibleAppClaims } from './types/BridgemanAccessibleAppClaims.js'; import type { AppSubscriptionTier } from './types/AppSubscriptionTier.js'; +import type { Webhook } from './types/Webhook.js'; +import { WebhookPurpose } from './types/WebhookPurpose.js'; import type { Addon } from './types/addons/Addon.js'; import { AddonType } from './types/addons/AddonType.js'; import { BillingCadence as AddonBillingCadence } from './types/addons/BillingCadence.js'; @@ -11,6 +13,8 @@ export { OAuthApp, BridgemanAccessibleAppClaims, AppSubscriptionTier, + Webhook, + WebhookPurpose, Addon, AddonType, AddonBillingCadence, diff --git a/src/oauth/types/BridgemanAccessibleAppClaims.ts b/src/oauth/types/BridgemanAccessibleAppClaims.ts index 8aefa91..27c3deb 100644 --- a/src/oauth/types/BridgemanAccessibleAppClaims.ts +++ b/src/oauth/types/BridgemanAccessibleAppClaims.ts @@ -1,6 +1,7 @@ import { ClientCustomClaims } from '@BridgemanAccessible/ba-auth/server'; import { AppSubscriptionTier } from './AppSubscriptionTier.js'; +import { Webhook } from './Webhook.js'; import { Addon } from './addons/Addon.js'; @@ -28,6 +29,9 @@ export interface BridgemanAccessibleAppClaims extends ClientCustomClaims { */ client_abbreviation: string; + /** The webhooks registered for this app */ + webhooks: Webhook[]; + /** Whether a paid subscription is mandatory to use the app */ subscription_required: boolean; diff --git a/src/oauth/types/Webhook.ts b/src/oauth/types/Webhook.ts new file mode 100644 index 0000000..7380358 --- /dev/null +++ b/src/oauth/types/Webhook.ts @@ -0,0 +1,9 @@ +import { WebhookPurpose } from './WebhookPurpose.js'; + +export interface Webhook { + /** The URL to which the webhook payloads will be sent */ + url: string; + + /** The purpose(s) for which this webhook is registered */ + purpose: WebhookPurpose[]; +} \ No newline at end of file diff --git a/src/oauth/types/WebhookPurpose.ts b/src/oauth/types/WebhookPurpose.ts new file mode 100644 index 0000000..8be69eb --- /dev/null +++ b/src/oauth/types/WebhookPurpose.ts @@ -0,0 +1,54 @@ +export enum WebhookPurpose { + /** + * When a user who hasn't had a subscription before gets one + * Note, if this isn't specified, but a SUBSCRIPTION_CHANGED is, + * the SUBSCRIPTION_CHANGED will be sent instead + * Because this allows for more specific handling but is less commonly needed + */ + SUBSCRIPTION_ADDED = 'SUBSCRIPTION_ADDED', + + /** + * When a user's subscription changes in any way. + * If implementing any of the SUBSCRIPTION_* webhooks, + * this should be the one implemented to cover all bases + */ + SUBSCRIPTION_CHANGED = 'SUBSCRIPTION_CHANGED', + + /** + * When a user's subscription is canceled + * Note, if this isn't specified, but a SUBSCRIPTION_CHANGED is, + * the SUBSCRIPTION_CHANGED will be sent instead + * Because this allows for more specific handling but is less commonly needed + */ + SUBSCRIPTION_CANCELED = 'SUBSCRIPTION_CANCELED', + + /** When a user purchases an add-on */ + ADDON_PURCHASED = 'ADDON_PURCHASED', + + /** + * When a user removes an add-on + * + * This is usually for subscription type addons that aren't renewed. + * One-time addons can't really be removed. + */ + ADDON_REMOVED = 'ADDON_REMOVED', + + /** + * When an add-on's settings are changed. + * + * This is usually for subscription type addons that have configurable options. + * One-time addons can't really have configurable settings. + */ + ADDON_CHANGED = 'ADDON_CHANGED', + + /** + * When a user's permissions are changed. + * + * This is usually an account level change that applies to the user (ex. an admin changes their role or policies). + * But this isn't restricted to that just any time the user's permissions change this webhook will be sent. + */ + PERMISSION_CHANGED = 'PERMISSION_CHANGED', + + /** When a user is deleted. */ + USER_DELETED = 'USER_DELETED' +} \ No newline at end of file