diff --git a/.changeset/auto-bump-magicbell-1739167634.md b/.changeset/auto-bump-magicbell-1739167634.md new file mode 100644 index 000000000..5edbf8d09 --- /dev/null +++ b/.changeset/auto-bump-magicbell-1739167634.md @@ -0,0 +1,5 @@ +--- +'magicbell': minor +--- + +Automatic minor version bump for changes in `magicbell`. diff --git a/.changeset/auto-bump-project-client-1739167634.md b/.changeset/auto-bump-project-client-1739167634.md new file mode 100644 index 000000000..7586d441a --- /dev/null +++ b/.changeset/auto-bump-project-client-1739167634.md @@ -0,0 +1,5 @@ +--- +'@magicbell/project-client': minor +--- + +Automatic minor version bump for changes in `@magicbell/project-client`. diff --git a/.changeset/auto-bump-user-client-1739167634.md b/.changeset/auto-bump-user-client-1739167634.md new file mode 100644 index 000000000..8b4ab1af4 --- /dev/null +++ b/.changeset/auto-bump-user-client-1739167634.md @@ -0,0 +1,5 @@ +--- +'@magicbell/user-client': minor +--- + +Automatic minor version bump for changes in `@magicbell/user-client`. diff --git a/packages/in-app/src/components/internal/webpush.ts b/packages/in-app/src/components/internal/webpush.ts index a5ff45e8e..689975de2 100644 --- a/packages/in-app/src/components/internal/webpush.ts +++ b/packages/in-app/src/components/internal/webpush.ts @@ -40,9 +40,9 @@ export class WebPushClient { if (!activeSubscription?.endpoint) return false; return ( tokens.data?.data - ?.filter((x) => !x.metadata?.discardedAt) + ?.filter((x) => !x.discardedAt) .some((subscription) => { - return subscription.data?.endpoint === activeSubscription.endpoint; + return subscription.endpoint === activeSubscription.endpoint; }) ?? false ); } @@ -92,9 +92,9 @@ export class WebPushClient { void this.#client.channels .getWebPushTokens() .then(({ data }) => { - const token = data?.data?.find((token) => token.data?.endpoint === endpoint); + const token = data?.data?.find((token) => token.endpoint === endpoint); if (!token) return; - return this.#client.channels.discardWebPushToken(String(token.metadata?.id)); + return this.#client.channels.discardWebPushToken(String(token.id)); }) .catch(() => void 0); diff --git a/packages/magicbell/src/schemas/users/notifications.ts b/packages/magicbell/src/schemas/users/notifications.ts index cf3f763e2..accc5a39c 100644 --- a/packages/magicbell/src/schemas/users/notifications.ts +++ b/packages/magicbell/src/schemas/users/notifications.ts @@ -106,8 +106,8 @@ export const ListUsersNotificationsResponseSchema = { properties: { user: { - nullable: false, type: 'object', + nullable: false, additionalProperties: false, properties: { diff --git a/packages/project-client/README.md b/packages/project-client/README.md index f18ce6b0c..dc7c3f1b4 100644 --- a/packages/project-client/README.md +++ b/packages/project-client/README.md @@ -11,7 +11,7 @@ Welcome to the Client SDK documentation. This guide will help you get started wi ## About the API -OpenAPI 3.1.0 Specification for MagicBell API. +OpenAPI 3.0.3 Specification for MagicBell API. ## Table of Contents @@ -106,6 +106,7 @@ The SDK provides various services to interact with the API. | [EventsService](documentation/services/EventsService.md) | | [IntegrationsService](documentation/services/IntegrationsService.md) | | [JwtService](documentation/services/JwtService.md) | +| [UsersService](documentation/services/UsersService.md) | @@ -120,21 +121,20 @@ The SDK includes several models that represent the data structures used in API r | :------------------------------------------------------------------------------------------- | :---------- | | [ArrayOfBroadcasts](documentation/models/ArrayOfBroadcasts.md) | | | [Broadcast](documentation/models/Broadcast.md) | | -| [ProjectDeliveryConfig](documentation/models/ProjectDeliveryConfig.md) | | | [CategoryDeliveryConfig](documentation/models/CategoryDeliveryConfig.md) | | -| [ArrayOfMetadataApnsTokens](documentation/models/ArrayOfMetadataApnsTokens.md) | | -| [MetadataApnsToken](documentation/models/MetadataApnsToken.md) | | +| [ArrayOfApnsTokenResponses](documentation/models/ArrayOfApnsTokenResponses.md) | | +| [ApnsTokenResponse](documentation/models/ApnsTokenResponse.md) | | | [DiscardResult](documentation/models/DiscardResult.md) | | -| [ArrayOfMetadataExpoTokens](documentation/models/ArrayOfMetadataExpoTokens.md) | | -| [MetadataExpoToken](documentation/models/MetadataExpoToken.md) | | -| [ArrayOfMetadataFcmTokens](documentation/models/ArrayOfMetadataFcmTokens.md) | | -| [MetadataFcmToken](documentation/models/MetadataFcmToken.md) | | -| [ArrayOfMetadataSlackTokens](documentation/models/ArrayOfMetadataSlackTokens.md) | | -| [MetadataSlackToken](documentation/models/MetadataSlackToken.md) | | -| [ArrayOfMetadataTeamsTokens](documentation/models/ArrayOfMetadataTeamsTokens.md) | | -| [MetadataTeamsToken](documentation/models/MetadataTeamsToken.md) | | -| [ArrayOfMetadataWebPushTokens](documentation/models/ArrayOfMetadataWebPushTokens.md) | | -| [MetadataWebPushToken](documentation/models/MetadataWebPushToken.md) | | +| [ArrayOfExpoTokenResponses](documentation/models/ArrayOfExpoTokenResponses.md) | | +| [ExpoTokenResponse](documentation/models/ExpoTokenResponse.md) | | +| [ArrayOfFcmTokenResponses](documentation/models/ArrayOfFcmTokenResponses.md) | | +| [FcmTokenResponse](documentation/models/FcmTokenResponse.md) | | +| [ArrayOfSlackTokenResponses](documentation/models/ArrayOfSlackTokenResponses.md) | | +| [SlackTokenResponse](documentation/models/SlackTokenResponse.md) | | +| [ArrayOfTeamsTokenResponses](documentation/models/ArrayOfTeamsTokenResponses.md) | | +| [TeamsTokenResponse](documentation/models/TeamsTokenResponse.md) | | +| [ArrayOfWebPushTokenResponses](documentation/models/ArrayOfWebPushTokenResponses.md) | | +| [WebPushTokenResponse](documentation/models/WebPushTokenResponse.md) | | | [ArrayOfEvents](documentation/models/ArrayOfEvents.md) | | | [ArrayOfIntegrationObjects](documentation/models/ArrayOfIntegrationObjects.md) | | | [ArrayOfApnsConfigObjects](documentation/models/ArrayOfApnsConfigObjects.md) | | @@ -171,14 +171,8 @@ The SDK includes several models that represent the data structures used in API r | [AccessToken](documentation/models/AccessToken.md) | | | [DiscardTokenResponse](documentation/models/DiscardTokenResponse.md) | | | [CreateUserTokenRequest](documentation/models/CreateUserTokenRequest.md) | | +| [ArrayOfUsers](documentation/models/ArrayOfUsers.md) | | | [Links](documentation/models/Links.md) | | -| [ApnsToken](documentation/models/ApnsToken.md) | | -| [TokenMetadata](documentation/models/TokenMetadata.md) | | -| [ExpoToken](documentation/models/ExpoToken.md) | | -| [FcmToken](documentation/models/FcmToken.md) | | -| [SlackToken](documentation/models/SlackToken.md) | | -| [TeamsToken](documentation/models/TeamsToken.md) | | -| [WebPushToken](documentation/models/WebPushToken.md) | | | [Event](documentation/models/Event.md) | | | [IntegrationObject](documentation/models/IntegrationObject.md) | | | [ApnsConfigObject](documentation/models/ApnsConfigObject.md) | | @@ -197,5 +191,6 @@ The SDK includes several models that represent the data structures used in API r | [TwilioConfigObject](documentation/models/TwilioConfigObject.md) | | | [WebpushConfigObject](documentation/models/WebpushConfigObject.md) | | | [FetchTokensResponseToken](documentation/models/FetchTokensResponseToken.md) | | +| [User](documentation/models/User.md) | | diff --git a/packages/project-client/documentation/models/ApnsToken.md b/packages/project-client/documentation/models/ApnsToken.md deleted file mode 100644 index b9f3f5d95..000000000 --- a/packages/project-client/documentation/models/ApnsToken.md +++ /dev/null @@ -1,20 +0,0 @@ -# ApnsToken - -**Properties** - -| Name | Type | Required | Description | -| :------------- | :---------------------- | :------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| deviceToken | string | ✅ | | -| appId | string | ❌ | (Optional) The bundle identifier of the application that is registering this token. Use this field to override the default identifier specified in the projects APNs integration. | -| installationId | ApnsTokenInstallationId | ❌ | (Optional) The APNs environment the token is registered for. If none is provided we assume the token is used in `production`. | - -# ApnsTokenInstallationId - -(Optional) The APNs environment the token is registered for. If none is provided we assume the token is used in `production`. - -**Properties** - -| Name | Type | Required | Description | -| :---------- | :----- | :------- | :------------ | -| DEVELOPMENT | string | ✅ | "development" | -| PRODUCTION | string | ✅ | "production" | diff --git a/packages/project-client/documentation/models/ApnsTokenResponse.md b/packages/project-client/documentation/models/ApnsTokenResponse.md new file mode 100644 index 000000000..e34cf5bb5 --- /dev/null +++ b/packages/project-client/documentation/models/ApnsTokenResponse.md @@ -0,0 +1,24 @@ +# ApnsTokenResponse + +**Properties** + +| Name | Type | Required | Description | +| :------------- | :------------------------------ | :------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| createdAt | string | ✅ | | +| deviceToken | string | ✅ | | +| id | string | ✅ | | +| appId | string | ❌ | (Optional) The bundle identifier of the application that is registering this token. Use this field to override the default identifier specified in the projects APNs integration. | +| discardedAt | string | ❌ | | +| installationId | ApnsTokenResponseInstallationId | ❌ | (Optional) The APNs environment the token is registered for. If none is provided we assume the token is used in `production`. | +| updatedAt | string | ❌ | | + +# ApnsTokenResponseInstallationId + +(Optional) The APNs environment the token is registered for. If none is provided we assume the token is used in `production`. + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :----- | :------- | :------------ | +| DEVELOPMENT | string | ✅ | "development" | +| PRODUCTION | string | ✅ | "production" | diff --git a/packages/user-client/documentation/models/ArrayOfMetadataApnsTokens.md b/packages/project-client/documentation/models/ArrayOfApnsTokenResponses.md similarity index 68% rename from packages/user-client/documentation/models/ArrayOfMetadataApnsTokens.md rename to packages/project-client/documentation/models/ArrayOfApnsTokenResponses.md index 3b75abfc8..b711d15b2 100644 --- a/packages/user-client/documentation/models/ArrayOfMetadataApnsTokens.md +++ b/packages/project-client/documentation/models/ArrayOfApnsTokenResponses.md @@ -1,8 +1,8 @@ -# ArrayOfMetadataApnsTokens +# ArrayOfApnsTokenResponses **Properties** | Name | Type | Required | Description | | :---- | :------------------ | :------- | :---------- | -| data | MetadataApnsToken[] | ❌ | | +| data | ApnsTokenResponse[] | ❌ | | | links | Links | ❌ | | diff --git a/packages/project-client/documentation/models/ArrayOfMetadataApnsTokens.md b/packages/project-client/documentation/models/ArrayOfExpoTokenResponses.md similarity index 68% rename from packages/project-client/documentation/models/ArrayOfMetadataApnsTokens.md rename to packages/project-client/documentation/models/ArrayOfExpoTokenResponses.md index 3b75abfc8..d1dadf9a9 100644 --- a/packages/project-client/documentation/models/ArrayOfMetadataApnsTokens.md +++ b/packages/project-client/documentation/models/ArrayOfExpoTokenResponses.md @@ -1,8 +1,8 @@ -# ArrayOfMetadataApnsTokens +# ArrayOfExpoTokenResponses **Properties** | Name | Type | Required | Description | | :---- | :------------------ | :------- | :---------- | -| data | MetadataApnsToken[] | ❌ | | +| data | ExpoTokenResponse[] | ❌ | | | links | Links | ❌ | | diff --git a/packages/user-client/documentation/models/ArrayOfMetadataFcmTokens.md b/packages/project-client/documentation/models/ArrayOfFcmTokenResponses.md similarity index 68% rename from packages/user-client/documentation/models/ArrayOfMetadataFcmTokens.md rename to packages/project-client/documentation/models/ArrayOfFcmTokenResponses.md index c5cc06b26..7838be529 100644 --- a/packages/user-client/documentation/models/ArrayOfMetadataFcmTokens.md +++ b/packages/project-client/documentation/models/ArrayOfFcmTokenResponses.md @@ -1,8 +1,8 @@ -# ArrayOfMetadataFcmTokens +# ArrayOfFcmTokenResponses **Properties** | Name | Type | Required | Description | | :---- | :----------------- | :------- | :---------- | -| data | MetadataFcmToken[] | ❌ | | +| data | FcmTokenResponse[] | ❌ | | | links | Links | ❌ | | diff --git a/packages/project-client/documentation/models/ArrayOfMetadataFcmTokens.md b/packages/project-client/documentation/models/ArrayOfMetadataFcmTokens.md deleted file mode 100644 index c5cc06b26..000000000 --- a/packages/project-client/documentation/models/ArrayOfMetadataFcmTokens.md +++ /dev/null @@ -1,8 +0,0 @@ -# ArrayOfMetadataFcmTokens - -**Properties** - -| Name | Type | Required | Description | -| :---- | :----------------- | :------- | :---------- | -| data | MetadataFcmToken[] | ❌ | | -| links | Links | ❌ | | diff --git a/packages/project-client/documentation/models/ArrayOfMetadataSlackTokens.md b/packages/project-client/documentation/models/ArrayOfSlackTokenResponses.md similarity index 68% rename from packages/project-client/documentation/models/ArrayOfMetadataSlackTokens.md rename to packages/project-client/documentation/models/ArrayOfSlackTokenResponses.md index 195427ea1..5edb7cfad 100644 --- a/packages/project-client/documentation/models/ArrayOfMetadataSlackTokens.md +++ b/packages/project-client/documentation/models/ArrayOfSlackTokenResponses.md @@ -1,8 +1,8 @@ -# ArrayOfMetadataSlackTokens +# ArrayOfSlackTokenResponses **Properties** | Name | Type | Required | Description | | :---- | :------------------- | :------- | :---------- | -| data | MetadataSlackToken[] | ❌ | | +| data | SlackTokenResponse[] | ❌ | | | links | Links | ❌ | | diff --git a/packages/project-client/documentation/models/ArrayOfMetadataTeamsTokens.md b/packages/project-client/documentation/models/ArrayOfTeamsTokenResponses.md similarity index 68% rename from packages/project-client/documentation/models/ArrayOfMetadataTeamsTokens.md rename to packages/project-client/documentation/models/ArrayOfTeamsTokenResponses.md index 3ce987fa4..c57a97930 100644 --- a/packages/project-client/documentation/models/ArrayOfMetadataTeamsTokens.md +++ b/packages/project-client/documentation/models/ArrayOfTeamsTokenResponses.md @@ -1,8 +1,8 @@ -# ArrayOfMetadataTeamsTokens +# ArrayOfTeamsTokenResponses **Properties** | Name | Type | Required | Description | | :---- | :------------------- | :------- | :---------- | -| data | MetadataTeamsToken[] | ❌ | | +| data | TeamsTokenResponse[] | ❌ | | | links | Links | ❌ | | diff --git a/packages/project-client/documentation/models/ArrayOfUsers.md b/packages/project-client/documentation/models/ArrayOfUsers.md new file mode 100644 index 000000000..8ba3cf99b --- /dev/null +++ b/packages/project-client/documentation/models/ArrayOfUsers.md @@ -0,0 +1,8 @@ +# ArrayOfUsers + +**Properties** + +| Name | Type | Required | Description | +| :---- | :----- | :------- | :---------- | +| data | User[] | ❌ | | +| links | Links | ❌ | | diff --git a/packages/project-client/documentation/models/ArrayOfMetadataWebPushTokens.md b/packages/project-client/documentation/models/ArrayOfWebPushTokenResponses.md similarity index 68% rename from packages/project-client/documentation/models/ArrayOfMetadataWebPushTokens.md rename to packages/project-client/documentation/models/ArrayOfWebPushTokenResponses.md index d9ebc3ea1..fb37407f7 100644 --- a/packages/project-client/documentation/models/ArrayOfMetadataWebPushTokens.md +++ b/packages/project-client/documentation/models/ArrayOfWebPushTokenResponses.md @@ -1,8 +1,8 @@ -# ArrayOfMetadataWebPushTokens +# ArrayOfWebPushTokenResponses **Properties** | Name | Type | Required | Description | | :---- | :--------------------- | :------- | :---------- | -| data | MetadataWebPushToken[] | ❌ | | +| data | WebPushTokenResponse[] | ❌ | | | links | Links | ❌ | | diff --git a/packages/project-client/documentation/models/CategoryDeliveryConfig.md b/packages/project-client/documentation/models/CategoryDeliveryConfig.md index 00f791470..fa9d3de7f 100644 --- a/packages/project-client/documentation/models/CategoryDeliveryConfig.md +++ b/packages/project-client/documentation/models/CategoryDeliveryConfig.md @@ -4,23 +4,21 @@ | Name | Type | Required | Description | | :------- | :------------------------------- | :------- | :---------- | -| category | string | ✅ | | | channels | CategoryDeliveryConfigChannels[] | ✅ | | +| key | string | ✅ | | | disabled | boolean | ❌ | | # CategoryDeliveryConfigChannels **Properties** -| Name | Type | Required | Description | -| :------- | :--------------- | :------- | :---------- | -| channel | ChannelsChannel2 | ✅ | | -| delay | number | ❌ | | -| disabled | boolean | ❌ | | -| if | string | ❌ | | -| priority | number | ❌ | | +| Name | Type | Required | Description | +| :------ | :------ | :------- | :---------- | +| channel | Channel | ✅ | | +| delay | number | ❌ | | +| if | string | ❌ | | -# ChannelsChannel2 +# Channel **Properties** @@ -32,3 +30,4 @@ | MOBILE_PUSH | string | ✅ | "mobile_push" | | TEAMS | string | ✅ | "teams" | | EMAIL | string | ✅ | "email" | +| SMS | string | ✅ | "sms" | diff --git a/packages/project-client/documentation/models/ExpoToken.md b/packages/project-client/documentation/models/ExpoToken.md deleted file mode 100644 index 9dd824126..000000000 --- a/packages/project-client/documentation/models/ExpoToken.md +++ /dev/null @@ -1,7 +0,0 @@ -# ExpoToken - -**Properties** - -| Name | Type | Required | Description | -| :---------- | :----- | :------- | :---------- | -| deviceToken | string | ✅ | | diff --git a/packages/project-client/documentation/models/TokenMetadata.md b/packages/project-client/documentation/models/ExpoTokenResponse.md similarity index 81% rename from packages/project-client/documentation/models/TokenMetadata.md rename to packages/project-client/documentation/models/ExpoTokenResponse.md index f5ddc77b1..ab934cc6a 100644 --- a/packages/project-client/documentation/models/TokenMetadata.md +++ b/packages/project-client/documentation/models/ExpoTokenResponse.md @@ -1,10 +1,11 @@ -# TokenMetadata +# ExpoTokenResponse **Properties** | Name | Type | Required | Description | | :---------- | :----- | :------- | :---------- | | createdAt | string | ✅ | | +| deviceToken | string | ✅ | | | id | string | ✅ | | | discardedAt | string | ❌ | | | updatedAt | string | ❌ | | diff --git a/packages/project-client/documentation/models/FcmToken.md b/packages/project-client/documentation/models/FcmToken.md deleted file mode 100644 index b4548ec28..000000000 --- a/packages/project-client/documentation/models/FcmToken.md +++ /dev/null @@ -1,17 +0,0 @@ -# FcmToken - -**Properties** - -| Name | Type | Required | Description | -| :------------- | :--------------------- | :------- | :---------- | -| deviceToken | string | ✅ | | -| installationId | FcmTokenInstallationId | ❌ | | - -# FcmTokenInstallationId - -**Properties** - -| Name | Type | Required | Description | -| :---------- | :----- | :------- | :------------ | -| DEVELOPMENT | string | ✅ | "development" | -| PRODUCTION | string | ✅ | "production" | diff --git a/packages/project-client/documentation/models/FcmTokenResponse.md b/packages/project-client/documentation/models/FcmTokenResponse.md new file mode 100644 index 000000000..9b4421159 --- /dev/null +++ b/packages/project-client/documentation/models/FcmTokenResponse.md @@ -0,0 +1,21 @@ +# FcmTokenResponse + +**Properties** + +| Name | Type | Required | Description | +| :------------- | :----------------------------- | :------- | :---------- | +| createdAt | string | ✅ | | +| deviceToken | string | ✅ | | +| id | string | ✅ | | +| discardedAt | string | ❌ | | +| installationId | FcmTokenResponseInstallationId | ❌ | | +| updatedAt | string | ❌ | | + +# FcmTokenResponseInstallationId + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :----- | :------- | :------------ | +| DEVELOPMENT | string | ✅ | "development" | +| PRODUCTION | string | ✅ | "production" | diff --git a/packages/project-client/documentation/models/MetadataApnsToken.md b/packages/project-client/documentation/models/MetadataApnsToken.md deleted file mode 100644 index ce227ffc3..000000000 --- a/packages/project-client/documentation/models/MetadataApnsToken.md +++ /dev/null @@ -1,8 +0,0 @@ -# MetadataApnsToken - -**Properties** - -| Name | Type | Required | Description | -| :------- | :------------ | :------- | :---------- | -| data | ApnsToken | ✅ | | -| metadata | TokenMetadata | ✅ | | diff --git a/packages/project-client/documentation/models/MetadataExpoToken.md b/packages/project-client/documentation/models/MetadataExpoToken.md deleted file mode 100644 index 6cf24e93f..000000000 --- a/packages/project-client/documentation/models/MetadataExpoToken.md +++ /dev/null @@ -1,8 +0,0 @@ -# MetadataExpoToken - -**Properties** - -| Name | Type | Required | Description | -| :------- | :------------ | :------- | :---------- | -| data | ExpoToken | ✅ | | -| metadata | TokenMetadata | ✅ | | diff --git a/packages/project-client/documentation/models/MetadataFcmToken.md b/packages/project-client/documentation/models/MetadataFcmToken.md deleted file mode 100644 index 5eae39e53..000000000 --- a/packages/project-client/documentation/models/MetadataFcmToken.md +++ /dev/null @@ -1,8 +0,0 @@ -# MetadataFcmToken - -**Properties** - -| Name | Type | Required | Description | -| :------- | :------------ | :------- | :---------- | -| data | FcmToken | ✅ | | -| metadata | TokenMetadata | ✅ | | diff --git a/packages/project-client/documentation/models/MetadataSlackToken.md b/packages/project-client/documentation/models/MetadataSlackToken.md deleted file mode 100644 index e60292e20..000000000 --- a/packages/project-client/documentation/models/MetadataSlackToken.md +++ /dev/null @@ -1,8 +0,0 @@ -# MetadataSlackToken - -**Properties** - -| Name | Type | Required | Description | -| :------- | :------------ | :------- | :---------- | -| data | SlackToken | ✅ | | -| metadata | TokenMetadata | ✅ | | diff --git a/packages/project-client/documentation/models/MetadataTeamsToken.md b/packages/project-client/documentation/models/MetadataTeamsToken.md deleted file mode 100644 index 482ce7783..000000000 --- a/packages/project-client/documentation/models/MetadataTeamsToken.md +++ /dev/null @@ -1,8 +0,0 @@ -# MetadataTeamsToken - -**Properties** - -| Name | Type | Required | Description | -| :------- | :------------ | :------- | :---------- | -| data | TeamsToken | ✅ | | -| metadata | TokenMetadata | ✅ | | diff --git a/packages/project-client/documentation/models/MetadataWebPushToken.md b/packages/project-client/documentation/models/MetadataWebPushToken.md deleted file mode 100644 index daab50e6b..000000000 --- a/packages/project-client/documentation/models/MetadataWebPushToken.md +++ /dev/null @@ -1,8 +0,0 @@ -# MetadataWebPushToken - -**Properties** - -| Name | Type | Required | Description | -| :------- | :------------ | :------- | :---------- | -| data | WebPushToken | ✅ | | -| metadata | TokenMetadata | ✅ | | diff --git a/packages/project-client/documentation/models/ProjectDeliveryConfig.md b/packages/project-client/documentation/models/ProjectDeliveryConfig.md deleted file mode 100644 index 523735188..000000000 --- a/packages/project-client/documentation/models/ProjectDeliveryConfig.md +++ /dev/null @@ -1,33 +0,0 @@ -# ProjectDeliveryConfig - -**Properties** - -| Name | Type | Required | Description | -| :------- | :------------------------------ | :------- | :---------- | -| channels | ProjectDeliveryConfigChannels[] | ✅ | | - -# ProjectDeliveryConfigChannels - -**Properties** - -| Name | Type | Required | Description | -| :------- | :--------------- | :------- | :-------------------------------------------------------------------------------- | -| channel | ChannelsChannel1 | ✅ | | -| delay | number | ❌ | Delay (in seconds) since the last step, before the message is sent to the channel | -| disabled | boolean | ❌ | | -| if | string | ❌ | | -| priority | number | ❌ | | - -# ChannelsChannel1 - -**Properties** - -| Name | Type | Required | Description | -| :---------- | :----- | :------- | :------------ | -| IN_APP | string | ✅ | "in_app" | -| SLACK | string | ✅ | "slack" | -| WEB_PUSH | string | ✅ | "web_push" | -| MOBILE_PUSH | string | ✅ | "mobile_push" | -| TEAMS | string | ✅ | "teams" | -| EMAIL | string | ✅ | "email" | -| SMS | string | ✅ | "sms" | diff --git a/packages/project-client/documentation/models/SesConfig.md b/packages/project-client/documentation/models/SesConfig.md index 6c84da4f6..b7de68960 100644 --- a/packages/project-client/documentation/models/SesConfig.md +++ b/packages/project-client/documentation/models/SesConfig.md @@ -2,13 +2,12 @@ **Properties** -| Name | Type | Required | Description | -| :-------- | :------------ | :------- | :----------------------------------------------- | -| keyId | string | ✅ | AWS Access Key ID | -| region | string | ✅ | AWS Region | -| secretKey | string | ✅ | AWS Secret Key | -| endpoint | string | ❌ | HTTP endpoint to send requests to (testing only) | -| from | SesConfigFrom | ❌ | | +| Name | Type | Required | Description | +| :-------- | :------------ | :------- | :---------------- | +| keyId | string | ✅ | AWS Access Key ID | +| region | string | ✅ | AWS Region | +| secretKey | string | ✅ | AWS Secret Key | +| from | SesConfigFrom | ❌ | | # SesConfigFrom diff --git a/packages/project-client/documentation/models/SlackToken.md b/packages/project-client/documentation/models/SlackToken.md deleted file mode 100644 index 589406920..000000000 --- a/packages/project-client/documentation/models/SlackToken.md +++ /dev/null @@ -1,26 +0,0 @@ -# SlackToken - -**Properties** - -| Name | Type | Required | Description | -| :------ | :---------------- | :------- | :---------- | -| oauth | Oauth | ❌ | | -| webhook | SlackTokenWebhook | ❌ | | - -# Oauth - -**Properties** - -| Name | Type | Required | Description | -| :------------- | :----- | :------- | :---------- | -| channelId | string | ✅ | | -| installationId | string | ✅ | | -| scope | string | ❌ | | - -# SlackTokenWebhook - -**Properties** - -| Name | Type | Required | Description | -| :--- | :----- | :------- | :---------- | -| url | string | ✅ | | diff --git a/packages/project-client/documentation/models/SlackTokenResponse.md b/packages/project-client/documentation/models/SlackTokenResponse.md new file mode 100644 index 000000000..073e22488 --- /dev/null +++ b/packages/project-client/documentation/models/SlackTokenResponse.md @@ -0,0 +1,30 @@ +# SlackTokenResponse + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :------------------------ | :------- | :---------- | +| createdAt | string | ✅ | | +| id | string | ✅ | | +| discardedAt | string | ❌ | | +| oauth | Oauth | ❌ | | +| updatedAt | string | ❌ | | +| webhook | SlackTokenResponseWebhook | ❌ | | + +# Oauth + +**Properties** + +| Name | Type | Required | Description | +| :------------- | :----- | :------- | :---------- | +| channelId | string | ✅ | | +| installationId | string | ✅ | | +| scope | string | ❌ | | + +# SlackTokenResponseWebhook + +**Properties** + +| Name | Type | Required | Description | +| :--- | :----- | :------- | :---------- | +| url | string | ✅ | | diff --git a/packages/project-client/documentation/models/TeamsToken.md b/packages/project-client/documentation/models/TeamsToken.md deleted file mode 100644 index fb1418184..000000000 --- a/packages/project-client/documentation/models/TeamsToken.md +++ /dev/null @@ -1,15 +0,0 @@ -# TeamsToken - -**Properties** - -| Name | Type | Required | Description | -| :------ | :---------------- | :------- | :---------- | -| webhook | TeamsTokenWebhook | ❌ | | - -# TeamsTokenWebhook - -**Properties** - -| Name | Type | Required | Description | -| :--- | :----- | :------- | :---------- | -| url | string | ❌ | | diff --git a/packages/project-client/documentation/models/TeamsTokenResponse.md b/packages/project-client/documentation/models/TeamsTokenResponse.md new file mode 100644 index 000000000..a76987d94 --- /dev/null +++ b/packages/project-client/documentation/models/TeamsTokenResponse.md @@ -0,0 +1,19 @@ +# TeamsTokenResponse + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :------------------------ | :------- | :---------- | +| createdAt | string | ✅ | | +| id | string | ✅ | | +| discardedAt | string | ❌ | | +| updatedAt | string | ❌ | | +| webhook | TeamsTokenResponseWebhook | ❌ | | + +# TeamsTokenResponseWebhook + +**Properties** + +| Name | Type | Required | Description | +| :--- | :----- | :------- | :---------- | +| url | string | ❌ | | diff --git a/packages/project-client/documentation/models/User.md b/packages/project-client/documentation/models/User.md new file mode 100644 index 000000000..11f809930 --- /dev/null +++ b/packages/project-client/documentation/models/User.md @@ -0,0 +1,18 @@ +# User + +**Properties** + +| Name | Type | Required | Description | +| :--------------- | :------- | :------- | :---------- | +| createdAt | string | ✅ | | +| customAttributes | any | ✅ | | +| id | string | ✅ | | +| projectId | number | ✅ | | +| updatedAt | string | ✅ | | +| email | string | ❌ | | +| externalId | string | ❌ | | +| firstName | string | ❌ | | +| lastName | string | ❌ | | +| lastNotifiedAt | string | ❌ | | +| lastSeenAt | string | ❌ | | +| phoneNumbers | string[] | ❌ | | diff --git a/packages/project-client/documentation/models/WebPushToken.md b/packages/project-client/documentation/models/WebPushToken.md deleted file mode 100644 index 23e8a46df..000000000 --- a/packages/project-client/documentation/models/WebPushToken.md +++ /dev/null @@ -1,17 +0,0 @@ -# WebPushToken - -**Properties** - -| Name | Type | Required | Description | -| :------- | :----- | :------- | :---------- | -| endpoint | string | ✅ | | -| keys | Keys | ✅ | | - -# Keys - -**Properties** - -| Name | Type | Required | Description | -| :----- | :----- | :------- | :---------- | -| auth | string | ✅ | | -| p256dh | string | ✅ | | diff --git a/packages/project-client/documentation/models/WebPushTokenResponse.md b/packages/project-client/documentation/models/WebPushTokenResponse.md new file mode 100644 index 000000000..e41995741 --- /dev/null +++ b/packages/project-client/documentation/models/WebPushTokenResponse.md @@ -0,0 +1,21 @@ +# WebPushTokenResponse + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :----- | :------- | :---------- | +| createdAt | string | ✅ | | +| endpoint | string | ✅ | | +| id | string | ✅ | | +| keys | Keys | ✅ | | +| discardedAt | string | ❌ | | +| updatedAt | string | ❌ | | + +# Keys + +**Properties** + +| Name | Type | Required | Description | +| :----- | :----- | :------- | :---------- | +| auth | string | ✅ | | +| p256dh | string | ✅ | | diff --git a/packages/project-client/documentation/services/BroadcastsService.md b/packages/project-client/documentation/services/BroadcastsService.md index f320be344..d2f3260b2 100644 --- a/packages/project-client/documentation/services/BroadcastsService.md +++ b/packages/project-client/documentation/services/BroadcastsService.md @@ -141,8 +141,8 @@ import { Broadcast, Client } from '@magicbell/project-client'; const statusStatus = StatusStatus.ENQUEUED; const summary: Summary = { - failures: 2, - total: 9, + failures: 6, + total: 1, }; const broadcastStatus: BroadcastStatus = { diff --git a/packages/project-client/documentation/services/ChannelsService.md b/packages/project-client/documentation/services/ChannelsService.md index 47171220a..9ac4248c4 100644 --- a/packages/project-client/documentation/services/ChannelsService.md +++ b/packages/project-client/documentation/services/ChannelsService.md @@ -4,9 +4,8 @@ A list of all methods in the `ChannelsService` service. Click on the method name | Methods | Description | | :---------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| [getProjectDeliveryconfig](#getprojectdeliveryconfig) | | -| [saveProjectDeliveryconfig](#saveprojectdeliveryconfig) | | -| [saveCategoriesDeliveryconfig](#savecategoriesdeliveryconfig) | | +| [getDeliveryconfig](#getdeliveryconfig) | | +| [saveDeliveryconfig](#savedeliveryconfig) | | | [getMobilePushApnsUserTokens](#getmobilepushapnsusertokens) | Lists all mobile_push tokens associated with a specific user. This endpoint is available to project administrators and returns a paginated list of tokens, including both active and revoked tokens. | | [getMobilePushApnsUserToken](#getmobilepushapnsusertoken) | Retrieves a specific mobile_push token by its ID for a given user. This endpoint is available to project administrators and requires project-level authentication. Use this to inspect token details including its status, creation date, and associated metadata. | | [discardMobilePushApnsUserToken](#discardmobilepushapnsusertoken) | Revokes a specific user's mobile_push token. This endpoint is available to project administrators and permanently invalidates the specified token. Once revoked, the token can no longer be used to access channel features. This action cannot be undone. | @@ -26,80 +25,43 @@ A list of all methods in the `ChannelsService` service. Click on the method name | [getWebPushUserToken](#getwebpushusertoken) | Retrieves a specific web_push token by its ID for a given user. This endpoint is available to project administrators and requires project-level authentication. Use this to inspect token details including its status, creation date, and associated metadata. | | [discardWebPushUserToken](#discardwebpushusertoken) | Revokes a specific user's web_push token. This endpoint is available to project administrators and permanently invalidates the specified token. Once revoked, the token can no longer be used to access channel features. This action cannot be undone. | -## getProjectDeliveryconfig +## getDeliveryconfig - HTTP Method: `GET` - Endpoint: `/channels/deliveryconfig` -**Return Type** - -`ProjectDeliveryConfig` - -**Example Usage Code Snippet** - -```typescript -import { Client } from '@magicbell/project-client'; - -(async () => { - const client = new Client({ - token: 'YOUR_TOKEN', - }); - - const { data } = await client.channels.getProjectDeliveryconfig(); - - console.log(data); -})(); -``` - -## saveProjectDeliveryconfig - -- HTTP Method: `PUT` -- Endpoint: `/channels/deliveryconfig` - **Parameters** -| Name | Type | Required | Description | -| :--- | :---------------------------------------------------------- | :------- | :---------------- | -| body | [ProjectDeliveryConfig](../models/ProjectDeliveryConfig.md) | ❌ | The request body. | +| Name | Type | Required | Description | +| :--- | :----- | :------- | :---------- | +| key | string | ❌ | | **Return Type** -`ProjectDeliveryConfig` +`CategoryDeliveryConfig` **Example Usage Code Snippet** ```typescript -import { Client, ProjectDeliveryConfig } from '@magicbell/project-client'; +import { Client } from '@magicbell/project-client'; (async () => { const client = new Client({ token: 'YOUR_TOKEN', }); - const channelsChannel1 = ChannelsChannel1.IN_APP; - - const projectDeliveryConfigChannels: ProjectDeliveryConfigChannels = { - channel: channelsChannel1, - delay: 8, - disabled: true, - if: 'if', - priority: 3, - }; - - const projectDeliveryConfig: ProjectDeliveryConfig = { - channels: [projectDeliveryConfigChannels], - }; - - const { data } = await client.channels.saveProjectDeliveryconfig(projectDeliveryConfig); + const { data } = await client.channels.getDeliveryconfig({ + key: 'key', + }); console.log(data); })(); ``` -## saveCategoriesDeliveryconfig +## saveDeliveryconfig -- HTTP Method: `POST` -- Endpoint: `/channels/deliveryconfig/categories` +- HTTP Method: `PUT` +- Endpoint: `/channels/deliveryconfig` **Parameters** @@ -121,23 +83,21 @@ import { CategoryDeliveryConfig, Client } from '@magicbell/project-client'; token: 'YOUR_TOKEN', }); - const channelsChannel2 = ChannelsChannel2.IN_APP; + const channel = Channel.IN_APP; const categoryDeliveryConfigChannels: CategoryDeliveryConfigChannels = { - channel: channelsChannel2, - delay: 6, - disabled: true, + channel: channel, + delay: 4, if: 'if', - priority: 1, }; const categoryDeliveryConfig: CategoryDeliveryConfig = { - category: 'category', channels: [categoryDeliveryConfigChannels], disabled: true, + key: 'key', }; - const { data } = await client.channels.saveCategoriesDeliveryconfig(categoryDeliveryConfig); + const { data } = await client.channels.saveDeliveryconfig(categoryDeliveryConfig); console.log(data); })(); @@ -161,7 +121,7 @@ Lists all mobile_push tokens associated with a specific user. This endpoint is a **Return Type** -`ArrayOfMetadataApnsTokens` +`ArrayOfApnsTokenResponses` **Example Usage Code Snippet** @@ -174,7 +134,7 @@ import { Client } from '@magicbell/project-client'; }); const { data } = await client.channels.getMobilePushApnsUserTokens('user_id', { - pageSize: 3, + pageSize: 7, pageAfter: 'page[after]', pageBefore: 'page[before]', }); @@ -199,7 +159,7 @@ Retrieves a specific mobile_push token by its ID for a given user. This endpoint **Return Type** -`MetadataApnsToken` +`ApnsTokenResponse` **Example Usage Code Snippet** @@ -269,7 +229,7 @@ Lists all mobile_push tokens associated with a specific user. This endpoint is a **Return Type** -`ArrayOfMetadataExpoTokens` +`ArrayOfExpoTokenResponses` **Example Usage Code Snippet** @@ -282,7 +242,7 @@ import { Client } from '@magicbell/project-client'; }); const { data } = await client.channels.getMobilePushExpoUserTokens('user_id', { - pageSize: 6, + pageSize: 2, pageAfter: 'page[after]', pageBefore: 'page[before]', }); @@ -307,7 +267,7 @@ Retrieves a specific mobile_push token by its ID for a given user. This endpoint **Return Type** -`MetadataExpoToken` +`ExpoTokenResponse` **Example Usage Code Snippet** @@ -377,7 +337,7 @@ Lists all mobile_push tokens associated with a specific user. This endpoint is a **Return Type** -`ArrayOfMetadataFcmTokens` +`ArrayOfFcmTokenResponses` **Example Usage Code Snippet** @@ -390,7 +350,7 @@ import { Client } from '@magicbell/project-client'; }); const { data } = await client.channels.getMobilePushFcmUserTokens('user_id', { - pageSize: 4, + pageSize: 2, pageAfter: 'page[after]', pageBefore: 'page[before]', }); @@ -415,7 +375,7 @@ Retrieves a specific mobile_push token by its ID for a given user. This endpoint **Return Type** -`MetadataFcmToken` +`FcmTokenResponse` **Example Usage Code Snippet** @@ -485,7 +445,7 @@ Lists all slack tokens associated with a specific user. This endpoint is availab **Return Type** -`ArrayOfMetadataSlackTokens` +`ArrayOfSlackTokenResponses` **Example Usage Code Snippet** @@ -523,7 +483,7 @@ Retrieves a specific slack token by its ID for a given user. This endpoint is av **Return Type** -`MetadataSlackToken` +`SlackTokenResponse` **Example Usage Code Snippet** @@ -593,7 +553,7 @@ Lists all teams tokens associated with a specific user. This endpoint is availab **Return Type** -`ArrayOfMetadataTeamsTokens` +`ArrayOfTeamsTokenResponses` **Example Usage Code Snippet** @@ -606,7 +566,7 @@ import { Client } from '@magicbell/project-client'; }); const { data } = await client.channels.getTeamsUserTokens('user_id', { - pageSize: 8, + pageSize: 5, pageAfter: 'page[after]', pageBefore: 'page[before]', }); @@ -631,7 +591,7 @@ Retrieves a specific teams token by its ID for a given user. This endpoint is av **Return Type** -`MetadataTeamsToken` +`TeamsTokenResponse` **Example Usage Code Snippet** @@ -701,7 +661,7 @@ Lists all web_push tokens associated with a specific user. This endpoint is avai **Return Type** -`ArrayOfMetadataWebPushTokens` +`ArrayOfWebPushTokenResponses` **Example Usage Code Snippet** @@ -714,7 +674,7 @@ import { Client } from '@magicbell/project-client'; }); const { data } = await client.channels.getWebPushUserTokens('user_id', { - pageSize: 4, + pageSize: 3, pageAfter: 'page[after]', pageBefore: 'page[before]', }); @@ -739,7 +699,7 @@ Retrieves a specific web_push token by its ID for a given user. This endpoint is **Return Type** -`MetadataWebPushToken` +`WebPushTokenResponse` **Example Usage Code Snippet** diff --git a/packages/project-client/documentation/services/EventsService.md b/packages/project-client/documentation/services/EventsService.md index 33d247229..68a236a96 100644 --- a/packages/project-client/documentation/services/EventsService.md +++ b/packages/project-client/documentation/services/EventsService.md @@ -36,7 +36,7 @@ import { Client } from '@magicbell/project-client'; }); const { data } = await client.events.getEvents({ - pageSize: 8, + pageSize: 9, pageAfter: 'page[after]', pageBefore: 'page[before]', }); diff --git a/packages/project-client/documentation/services/IntegrationsService.md b/packages/project-client/documentation/services/IntegrationsService.md index 4723f48ab..34481983b 100644 --- a/packages/project-client/documentation/services/IntegrationsService.md +++ b/packages/project-client/documentation/services/IntegrationsService.md @@ -96,7 +96,7 @@ import { Client } from '@magicbell/project-client'; }); const { data } = await client.integrations.listIntegrations({ - pageSize: 3, + pageSize: 8, pageAfter: 'page[after]', pageBefore: 'page[before]', }); @@ -165,13 +165,13 @@ const payloadVersion = PayloadVersion._1; const apnsConfig: ApnsConfig = { appId: "app_id", badge: badge, - certificate: "----- BEGIN PRIVATE KEY---------- -42qmz9= ----- END PRIVATE KEY- + certificate: "BEGIN PRIVATE KEY------ +6vtVF= +-END PRIVATE KEYYYYYYYYYYY--------- ", - keyId: "mollit dol", + keyId: "commodo ir", payloadVersion: payloadVersion, - teamId: "enimmollit" + teamId: "cillum ex " }; const { data } = await client.integrations.saveApnsIntegration( @@ -527,10 +527,9 @@ const fcmConfig: FcmConfig = { clientEmail: "client_email", clientId: "client_id", clientX509CertUrl: "client_x509_cert_url", - privateKey: "BEGINNQX-------- -B+JvPM/f7Ms== -------ENDEPJVIYYY----- -", + privateKey: "BEGINDRFOCFDP---- +Ax9ayOxb== +---ENDOOCOIEC-----", privateKeyId: "private_key_id", projectId: "project_id", tokenUri: "token_uri", @@ -774,7 +773,7 @@ import { Client, InboxConfig } from '@magicbell/project-client'; const banner: Banner = { backgroundColor: 'backgroundColor', - backgroundOpacity: 4.92, + backgroundOpacity: 8.11, fontSize: 'fontSize', textColor: 'textColor', }; @@ -1362,7 +1361,6 @@ import { Client, SesConfig } from '@magicbell/project-client'; }; const sesConfig: SesConfig = { - endpoint: 'endpoint', from: sesConfigFrom, keyId: 'key_id', region: 'region', @@ -1482,10 +1480,10 @@ import { Client, SlackConfig } from '@magicbell/project-client'; }); const slackConfig: SlackConfig = { - appId: 'QTEIRE', - clientId: '7201.6182620', - clientSecret: 'ex dolore ametauteDuis culpaquis', - signingSecret: 'eu ex animmollit sunt consequat ', + appId: '92SOA', + clientId: '85317541010.82133160', + clientSecret: 'adaliqua ad laboris animnon do U', + signingSecret: 'eunisi ad in incididuntin mollit', }; const { data } = await client.integrations.saveSlackIntegration(slackConfig); @@ -1836,7 +1834,7 @@ import { Client, TwilioConfig } from '@magicbell/project-client'; accountSid: 'account_sid', apiKey: 'api_key', apiSecret: 'api_secret', - from: '+0528138710599', + from: '+8', region: twilioConfigRegion, }; diff --git a/packages/project-client/documentation/services/JwtService.md b/packages/project-client/documentation/services/JwtService.md index 58dfd3b4e..1bd8cea88 100644 --- a/packages/project-client/documentation/services/JwtService.md +++ b/packages/project-client/documentation/services/JwtService.md @@ -78,7 +78,7 @@ import { Client, CreateProjectTokenRequest } from '@magicbell/project-client'; }); const createProjectTokenRequest: CreateProjectTokenRequest = { - expiry: 8, + expiry: 3, name: 'name', }; @@ -150,7 +150,7 @@ import { Client, CreateUserTokenRequest } from '@magicbell/project-client'; const createUserTokenRequest: CreateUserTokenRequest = { email: 'email', - expiry: 8, + expiry: 3, externalId: 'external_id', name: 'name', }; @@ -225,7 +225,7 @@ import { Client } from '@magicbell/project-client'; }); const { data } = await client.jwt.fetchUserTokens('user_id', { - pageSize: 3, + pageSize: 2, pageAfter: 'page[after]', pageBefore: 'page[before]', }); diff --git a/packages/project-client/documentation/services/UsersService.md b/packages/project-client/documentation/services/UsersService.md new file mode 100644 index 000000000..765313d7e --- /dev/null +++ b/packages/project-client/documentation/services/UsersService.md @@ -0,0 +1,44 @@ +# UsersService + +A list of all methods in the `UsersService` service. Click on the method name to view detailed information about that method. + +| Methods | Description | +| :---------------------- | :---------- | +| [listUsers](#listusers) | | + +## listUsers + +- HTTP Method: `GET` +- Endpoint: `/users` + +**Parameters** + +| Name | Type | Required | Description | +| :--------- | :----- | :------- | :---------- | +| pageSize | number | ❌ | | +| pageAfter | string | ❌ | | +| pageBefore | string | ❌ | | + +**Return Type** + +`ArrayOfUsers` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.users.listUsers({ + pageSize: 9, + pageAfter: 'page[after]', + pageBefore: 'page[before]', + }); + + console.log(data); +})(); +``` diff --git a/packages/project-client/src/http/client.ts b/packages/project-client/src/http/client.ts index 597626168..186cf2a22 100644 --- a/packages/project-client/src/http/client.ts +++ b/packages/project-client/src/http/client.ts @@ -21,15 +21,15 @@ export class HttpClient { this.requestHandlerChain.addHandler(new TerminatingHandler()); } - call(request: Request): Promise> { + call(request: Request): Promise> { return this.requestHandlerChain.callChain(request); } - async *stream(request: Request): AsyncGenerator> { + async *stream(request: Request): AsyncGenerator> { yield* this.requestHandlerChain.streamChain(request); } - public async callPaginated(request: Request): Promise> { + public async callPaginated(request: Request): Promise> { const response = await this.call(request as any); if (!response.data) { @@ -50,7 +50,7 @@ export class HttpClient { this.config = config; } - private getPage(request: Request, data: FullResponse): Page { + private getPage(request: Request, data: FullResponse): Page { if (!request.pagination) { throw new Error('getPage called for request without pagination property'); } diff --git a/packages/project-client/src/http/handlers/auth-handler.ts b/packages/project-client/src/http/handlers/auth-handler.ts index 8fcf99d64..c338e8325 100644 --- a/packages/project-client/src/http/handlers/auth-handler.ts +++ b/packages/project-client/src/http/handlers/auth-handler.ts @@ -5,27 +5,27 @@ import { HttpResponse, RequestHandler } from '../types.js'; export class AuthHandler implements RequestHandler { next?: RequestHandler; - public async handle(request: Request): Promise> { + public async handle(request: Request): Promise> { const requestWithAuth = this.addAccessTokenHeader(request); if (!this.next) { throw new Error(`No next handler set in ${AuthHandler.name}`); } - return this.next.handle(requestWithAuth); + return this.next.handle(requestWithAuth); } - public async *stream(request: Request): AsyncGenerator> { + public async *stream(request: Request): AsyncGenerator> { const requestWithAuth = this.addAccessTokenHeader(request); if (!this.next) { throw new Error(`No next handler set in ${AuthHandler.name}`); } - yield* this.next.stream(requestWithAuth); + yield* this.next.stream(requestWithAuth); } - private addAccessTokenHeader(request: Request): Request { + private addAccessTokenHeader(request: Request): Request { const { token } = request.config; if (!token) { return request; diff --git a/packages/project-client/src/http/handlers/handler-chain.ts b/packages/project-client/src/http/handlers/handler-chain.ts index 7f55f13db..e794dac84 100644 --- a/packages/project-client/src/http/handlers/handler-chain.ts +++ b/packages/project-client/src/http/handlers/handler-chain.ts @@ -12,19 +12,19 @@ export class RequestHandlerChain { this.handlers.push(handler); } - async callChain(request: Request): Promise> { + async callChain(request: Request): Promise> { if (!this.handlers.length) { throw new Error('No handlers added to the chain'); } - return this.handlers[0].handle(request); + return this.handlers[0].handle(request); } - async *streamChain(request: Request): AsyncGenerator> { + async *streamChain(request: Request): AsyncGenerator> { if (!this.handlers.length) { throw new Error('No handlers added to the chain'); } - yield* this.handlers[0].stream(request); + yield* this.handlers[0].stream(request); } } diff --git a/packages/project-client/src/http/handlers/hook-handler.ts b/packages/project-client/src/http/handlers/hook-handler.ts index 0850a72c1..d7a1429e2 100644 --- a/packages/project-client/src/http/handlers/hook-handler.ts +++ b/packages/project-client/src/http/handlers/hook-handler.ts @@ -8,7 +8,7 @@ export class HookHandler implements RequestHandler { constructor(private readonly hook: Hook) {} - async handle(request: Request): Promise> { + async handle(request: Request): Promise> { if (!this.next) { throw new Error('No next handler set in hook handler.'); } @@ -19,7 +19,7 @@ export class HookHandler implements RequestHandler { const nextRequest = await hook.beforeRequest(request, hookParams); - const response = await this.next.handle(nextRequest); + const response = await this.next.handle(nextRequest); if (response.metadata.status < 400) { return await hook.afterResponse(nextRequest, response, hookParams); @@ -28,7 +28,7 @@ export class HookHandler implements RequestHandler { throw await hook.onError(nextRequest, response, hookParams); } - async *stream(request: Request): AsyncGenerator> { + async *stream(request: Request): AsyncGenerator> { if (!this.next) { throw new Error('No next handler set in hook handler.'); } @@ -39,7 +39,7 @@ export class HookHandler implements RequestHandler { const nextRequest = await hook.beforeRequest(request, hookParams); - const stream = this.next.stream(nextRequest); + const stream = this.next.stream(nextRequest); for await (const response of stream) { if (response.metadata.status < 400) { @@ -50,7 +50,7 @@ export class HookHandler implements RequestHandler { } } - private getHookParams(_request: Request): Map { + private getHookParams(_request: Request): Map { const hookParams: Map = new Map(); return hookParams; } diff --git a/packages/project-client/src/http/handlers/request-validation-handler.ts b/packages/project-client/src/http/handlers/request-validation-handler.ts index b35511fa9..6dc0056d5 100644 --- a/packages/project-client/src/http/handlers/request-validation-handler.ts +++ b/packages/project-client/src/http/handlers/request-validation-handler.ts @@ -4,27 +4,27 @@ import { ContentType, HttpResponse, RequestHandler } from '../types.js'; export class RequestValidationHandler implements RequestHandler { next?: RequestHandler; - async handle(request: Request): Promise> { + async handle(request: Request): Promise> { if (!this.next) { throw new Error('No next handler set in ContentTypeHandler.'); } this.validateRequest(request); - return this.next.handle(request); + return this.next.handle(request); } - async *stream(request: Request): AsyncGenerator> { + async *stream(request: Request): AsyncGenerator> { if (!this.next) { throw new Error('No next handler set in ContentTypeHandler.'); } this.validateRequest(request); - yield* this.next.stream(request); + yield* this.next.stream(request); } - validateRequest(request: Request): void { + validateRequest(request: Request): void { if (request.requestContentType === ContentType.Json) { request.body = JSON.stringify(request.requestSchema?.parse(request.body)); } else if ( @@ -42,7 +42,7 @@ export class RequestValidationHandler implements RequestHandler { } } - toFormUrlEncoded(request: Request): string { + toFormUrlEncoded(request: Request): string { if (request.body === undefined) { return ''; } diff --git a/packages/project-client/src/http/handlers/response-validation-handler.ts b/packages/project-client/src/http/handlers/response-validation-handler.ts index d1fa7370a..eec00a539 100644 --- a/packages/project-client/src/http/handlers/response-validation-handler.ts +++ b/packages/project-client/src/http/handlers/response-validation-handler.ts @@ -1,24 +1,25 @@ import { ZodUndefined } from 'zod'; -import { Request } from '../transport/request.js'; +import { Request, ResponseDefinition } from '../transport/request.js'; import { ContentType, HttpResponse, RequestHandler } from '../types.js'; +import { ResponseMatcher } from '../utils/response-matcher.js'; export class ResponseValidationHandler implements RequestHandler { next?: RequestHandler; - async handle(request: Request): Promise> { - const response = await this.next!.handle(request); + async handle(request: Request): Promise> { + const response = await this.next!.handle(request); - return this.decodeBody(request, response); + return this.decodeBody(request, response); } - async *stream(request: Request): AsyncGenerator> { - const stream = this.next!.stream(request); + async *stream(request: Request): AsyncGenerator> { + const stream = this.next!.stream(request); for await (const response of stream) { - const responseChunks = this.splitByDataChunks(response); + const responseChunks = this.splitByDataChunks(response); for (const chunk of responseChunks) { - yield this.decodeBody(request, chunk); + yield this.decodeBody(request, chunk); } } } @@ -39,70 +40,91 @@ export class ResponseValidationHandler implements RequestHandler { })); } - private decodeBody(request: Request, response: HttpResponse): HttpResponse { - if (!this.hasContent(request, response)) { - return response; - } - - if (request.responseContentType === ContentType.Binary || request.responseContentType === ContentType.Image) { - return this.decodeFile(request, response); - } + private decodeBody(request: Request, response: HttpResponse): HttpResponse { + const responseMatcher = new ResponseMatcher(request.responses); + const responseDefinition = responseMatcher.getResponseDefinition(response); - if (request.responseContentType === ContentType.MultipartFormData) { - return this.decodeMultipartFormData(request, response); + if (!responseDefinition || !this.hasContent(responseDefinition, response)) { + return response; } - if (request.responseContentType === ContentType.Text || request.responseContentType === ContentType.Xml) { - return this.decodeText(request, response); - } + const contentType = responseDefinition.contentType; + const contentTypeHandlers: { + [key: string]: (req: Request, resDef: ResponseDefinition, res: HttpResponse) => HttpResponse; + } = { + [ContentType.Binary]: this.decodeFile, + [ContentType.Image]: this.decodeFile, + [ContentType.MultipartFormData]: this.decodeMultipartFormData, + [ContentType.Text]: this.decodeText, + [ContentType.Xml]: this.decodeText, + [ContentType.FormUrlEncoded]: this.decodeFormUrlEncoded, + [ContentType.EventStream]: this.decodeEventStream, + }; - if (request.responseContentType === ContentType.FormUrlEncoded) { - return this.decodeFormUrlEncoded(request, response); + if (contentTypeHandlers[contentType]) { + return contentTypeHandlers[contentType].call(this, request, responseDefinition, response); } - if ( - request.responseContentType === ContentType.EventStream || - response.metadata.headers['content-type'].includes('text/event-stream') - ) { - return this.decodeEventStream(request, response); + if (response.metadata.headers['content-type']?.includes('text/event-stream')) { + return this.decodeEventStream(request, responseDefinition, response); } - return this.decodeJson(request, response); + return this.decodeJson(request, responseDefinition, response); } - private decodeFile(request: Request, response: HttpResponse): HttpResponse { + private decodeFile( + request: Request, + responseDefinition: ResponseDefinition, + response: HttpResponse, + ): HttpResponse { return { ...response, - data: this.validate(request, response.raw), + data: this.validate(request, responseDefinition, response.raw), }; } - private decodeMultipartFormData(request: Request, response: HttpResponse): HttpResponse { + private decodeMultipartFormData( + request: Request, + responseDefinition: ResponseDefinition, + response: HttpResponse, + ): HttpResponse { const formData = this.fromFormData(response.raw); return { ...response, - data: this.validate(request, formData), + data: this.validate(request, responseDefinition, formData), }; } - private decodeText(request: Request, response: HttpResponse): HttpResponse { + private decodeText( + request: Request, + responseDefinition: ResponseDefinition, + response: HttpResponse, + ): HttpResponse { const decodedBody = new TextDecoder().decode(response.raw); return { ...response, - data: this.validate(request, decodedBody), + data: this.validate(request, responseDefinition, decodedBody), }; } - private decodeFormUrlEncoded(request: Request, response: HttpResponse): HttpResponse { + private decodeFormUrlEncoded( + request: Request, + responseDefinition: ResponseDefinition, + response: HttpResponse, + ): HttpResponse { const decodedBody = new TextDecoder().decode(response.raw); const urlEncoded = this.fromUrlEncoded(decodedBody); return { ...response, - data: this.validate(request, urlEncoded), + data: this.validate(request, responseDefinition, urlEncoded), }; } - private decodeEventStream(request: Request, response: HttpResponse): HttpResponse { + private decodeEventStream( + request: Request, + responseDefinition: ResponseDefinition, + response: HttpResponse, + ): HttpResponse { let decodedBody = new TextDecoder().decode(response.raw); if (decodedBody.startsWith('data: ')) { decodedBody = decodedBody.substring(6); @@ -111,29 +133,35 @@ export class ResponseValidationHandler implements RequestHandler { const json = JSON.parse(decodedBody); return { ...response, - data: this.validate(request, json), + data: this.validate(request, responseDefinition, json), }; } - private decodeJson(request: Request, response: HttpResponse): HttpResponse { + private decodeJson( + request: Request, + responseDefinition: ResponseDefinition, + response: HttpResponse, + ): HttpResponse { const decodedBody = new TextDecoder().decode(response.raw); const json = JSON.parse(decodedBody); return { ...response, - data: this.validate(request, json), + data: this.validate(request, responseDefinition, json), }; } - private validate(request: Request, data: any): T { + private validate(request: Request, response: ResponseDefinition, data: any): T { if (request.validation?.responseValidation) { - return request.responseSchema.parse(data); + return response.schema.parse(data); } return data; } - private hasContent(request: Request, response: HttpResponse): boolean { + private hasContent(responseDefinition: ResponseDefinition, response: HttpResponse): boolean { return ( - !!request.responseSchema && !(request.responseSchema instanceof ZodUndefined) && response.metadata.status !== 204 + !!responseDefinition.schema && + !(responseDefinition.schema instanceof ZodUndefined) && + response.metadata.status !== 204 ); } diff --git a/packages/project-client/src/http/handlers/retry-handler.ts b/packages/project-client/src/http/handlers/retry-handler.ts index e9ac00351..bfe4adc94 100644 --- a/packages/project-client/src/http/handlers/retry-handler.ts +++ b/packages/project-client/src/http/handlers/retry-handler.ts @@ -5,14 +5,14 @@ import { HttpResponse, RequestHandler } from '../types.js'; export class RetryHandler implements RequestHandler { next?: RequestHandler; - async handle(request: Request): Promise> { + async handle(request: Request): Promise> { if (!this.next) { throw new Error('No next handler set in retry handler.'); } for (let attempt = 1; attempt <= request.retry.attempts; attempt++) { try { - return await this.next.handle(request); + return await this.next.handle(request); } catch (error: any) { if (!this.shouldRetry(error) || attempt === request.retry.attempts) { throw error; @@ -24,14 +24,14 @@ export class RetryHandler implements RequestHandler { throw new Error('Error retrying request.'); } - async *stream(request: Request): AsyncGenerator> { + async *stream(request: Request): AsyncGenerator> { if (!this.next) { throw new Error('No next handler set in retry handler.'); } for (let attempt = 1; attempt <= request.retry.attempts; attempt++) { try { - yield* this.next.stream(request); + yield* this.next.stream(request); return; } catch (error: any) { if (!this.shouldRetry(error) || attempt === request.retry.attempts) { diff --git a/packages/project-client/src/http/handlers/terminating-handler.ts b/packages/project-client/src/http/handlers/terminating-handler.ts index 43c7b77af..4225d9646 100644 --- a/packages/project-client/src/http/handlers/terminating-handler.ts +++ b/packages/project-client/src/http/handlers/terminating-handler.ts @@ -4,11 +4,11 @@ import { RequestFetchAdapter } from '../transport/request-fetch-adapter.js'; import { HttpResponse, RequestHandler } from '../types.js'; export class TerminatingHandler implements RequestHandler { - async handle(request: Request): Promise> { - return new RequestFetchAdapter(request).send(); + async handle(request: Request): Promise> { + return new RequestFetchAdapter(request).send(); } - async *stream(request: Request): AsyncGenerator> { - yield* new RequestFetchAdapter(request).stream(); + async *stream(request: Request): AsyncGenerator> { + yield* new RequestFetchAdapter(request).stream(); } } diff --git a/packages/project-client/src/http/transport/request-builder.ts b/packages/project-client/src/http/transport/request-builder.ts index e315a6096..0ba603923 100644 --- a/packages/project-client/src/http/transport/request-builder.ts +++ b/packages/project-client/src/http/transport/request-builder.ts @@ -3,10 +3,16 @@ import z, { ZodType } from 'zod'; import { Environment } from '../environment.js'; import { SerializationStyle } from '../serialization/base-serializer.js'; import { ContentType, HttpMethod, RequestConfig, RetryOptions, SdkConfig, ValidationOptions } from '../types.js'; -import { CreateRequestParameters, Request, RequestPagination, RequestParameter } from './request.js'; +import { + CreateRequestParameters, + Request, + RequestPagination, + RequestParameter, + ResponseDefinition, +} from './request.js'; -export class RequestBuilder { - private params: CreateRequestParameters; +export class RequestBuilder { + private params: CreateRequestParameters; constructor() { this.params = { @@ -14,10 +20,9 @@ export class RequestBuilder { method: 'GET', path: '', config: {}, - responseSchema: z.any(), + responses: [], requestSchema: z.any(), requestContentType: ContentType.Json, - responseContentType: ContentType.Json, retry: { attempts: 3, delayMs: 150, @@ -31,7 +36,7 @@ export class RequestBuilder { }; } - setRetryAttempts(sdkConfig?: SdkConfig, requestConfig?: RequestConfig): RequestBuilder { + setRetryAttempts(sdkConfig?: SdkConfig, requestConfig?: RequestConfig): RequestBuilder { if (requestConfig?.retry?.attempts !== undefined) { this.params.retry.attempts = requestConfig.retry.attempts; } else if (sdkConfig?.retry?.attempts !== undefined) { @@ -41,7 +46,7 @@ export class RequestBuilder { return this; } - setRetryDelayMs(sdkConfig?: SdkConfig, requestConfig?: RequestConfig): RequestBuilder { + setRetryDelayMs(sdkConfig?: SdkConfig, requestConfig?: RequestConfig): RequestBuilder { if (requestConfig?.retry?.delayMs !== undefined) { this.params.retry.delayMs = requestConfig.retry.delayMs; } else if (sdkConfig?.retry?.delayMs !== undefined) { @@ -51,7 +56,7 @@ export class RequestBuilder { return this; } - setResponseValidation(sdkConfig: SdkConfig, requestConfig?: RequestConfig): RequestBuilder { + setResponseValidation(sdkConfig: SdkConfig, requestConfig?: RequestConfig): RequestBuilder { if (requestConfig?.validation?.responseValidation !== undefined) { this.params.validation.responseValidation = requestConfig.validation.responseValidation; } else if (sdkConfig?.validation?.responseValidation !== undefined) { @@ -61,7 +66,7 @@ export class RequestBuilder { return this; } - setBaseUrl(sdkConfig: SdkConfig): RequestBuilder { + setBaseUrl(sdkConfig: SdkConfig): RequestBuilder { if (sdkConfig?.baseUrl !== undefined) { this.params.baseUrl = sdkConfig.baseUrl; } @@ -69,54 +74,49 @@ export class RequestBuilder { return this; } - setMethod(method: HttpMethod): RequestBuilder { + setMethod(method: HttpMethod): RequestBuilder { this.params.method = method; return this; } - setPath(path: string): RequestBuilder { + setPath(path: string): RequestBuilder { this.params.path = path; return this; } - setConfig(config: SdkConfig): RequestBuilder { + setConfig(config: SdkConfig): RequestBuilder { this.params.config = config; return this; } - setRequestContentType(contentType: ContentType): RequestBuilder { + setRequestContentType(contentType: ContentType): RequestBuilder { this.params.requestContentType = contentType; return this; } - setResponseContentType(contentType: ContentType): RequestBuilder { - this.params.responseContentType = contentType; - return this; - } - - setRequestSchema(requestSchema: ZodType): RequestBuilder { + setRequestSchema(requestSchema: ZodType): RequestBuilder { this.params.requestSchema = requestSchema; return this; } - setResponseSchema(responseSchema: ZodType): RequestBuilder { - this.params.responseSchema = responseSchema; + setPagination(pagination: RequestPagination): RequestBuilder { + this.params.pagination = pagination; return this; } - setPagination(pagination: RequestPagination): RequestBuilder { - this.params.pagination = pagination; + addResponse(response: ResponseDefinition): RequestBuilder { + this.params.responses.push(response); return this; } - addBody(body?: any): RequestBuilder { + addBody(body?: any): RequestBuilder { if (body !== undefined) { this.params.body = body; } return this; } - addPathParam(param: Partial): RequestBuilder { + addPathParam(param: Partial): RequestBuilder { if (param.value === undefined || param.key === undefined) { return this; } @@ -134,7 +134,7 @@ export class RequestBuilder { return this; } - addQueryParam(param: Partial): RequestBuilder { + addQueryParam(param: Partial): RequestBuilder { if (param.value === undefined || param.key === undefined) { return this; } @@ -152,7 +152,7 @@ export class RequestBuilder { return this; } - addHeaderParam(param: Partial): RequestBuilder { + addHeaderParam(param: Partial): RequestBuilder { if (param.value === undefined || param.key === undefined) { return this; } @@ -170,7 +170,7 @@ export class RequestBuilder { return this; } - public build(): Request { - return new Request(this.params); + public build(): Request { + return new Request(this.params); } } diff --git a/packages/project-client/src/http/transport/request-fetch-adapter.ts b/packages/project-client/src/http/transport/request-fetch-adapter.ts index 30f04f80e..36498f300 100644 --- a/packages/project-client/src/http/transport/request-fetch-adapter.ts +++ b/packages/project-client/src/http/transport/request-fetch-adapter.ts @@ -1,5 +1,6 @@ import { HttpError } from '../error.js'; import { HttpMetadata, HttpMethod, HttpResponse } from '../types.js'; +import { LineDecoder } from '../utils/line-decoder.js'; import { Request } from './request.js'; interface HttpAdapter { @@ -10,7 +11,7 @@ interface HttpAdapter { export class RequestFetchAdapter implements HttpAdapter { private requestInit: RequestInit = {}; - constructor(private request: Request) { + constructor(private request: Request) { this.setMethod(request.method); this.setHeaders(request.getHeaders()); this.setBody(request.body); @@ -53,15 +54,26 @@ export class RequestFetchAdapter implements HttpAdapter { } const reader = response.body.getReader(); + const lineDecoder = new LineDecoder(); while (true) { const { done, value } = await reader.read(); if (done) { break; } + + for (const line of lineDecoder.splitLines(value)) { + yield { + metadata, + raw: line, + }; + } + } + + for (const line of lineDecoder.flush()) { yield { metadata, - raw: value, + raw: line, }; } } diff --git a/packages/project-client/src/http/transport/request.ts b/packages/project-client/src/http/transport/request.ts index a523ff59c..e5c892f8b 100644 --- a/packages/project-client/src/http/transport/request.ts +++ b/packages/project-client/src/http/transport/request.ts @@ -7,7 +7,13 @@ import { PathSerializer } from '../serialization/path-serializer.js'; import { QuerySerializer } from '../serialization/query-serializer.js'; import { ContentType, HttpMethod, RetryOptions, SdkConfig, ValidationOptions } from '../types.js'; -export interface CreateRequestParameters { +export interface ResponseDefinition { + schema: ZodType; + contentType: ContentType; + status: number; +} + +export interface CreateRequestParameters { baseUrl: string; method: HttpMethod; body?: any; @@ -16,10 +22,9 @@ export interface CreateRequestParameters { pathParams: Map; path: string; config: SdkConfig; - responseSchema: ZodType; + responses: ResponseDefinition[]; requestSchema: ZodType; requestContentType: ContentType; - responseContentType: ContentType; validation: ValidationOptions; retry: RetryOptions; pagination?: RequestPagination; @@ -41,7 +46,7 @@ export interface RequestPagination { pageSchema?: ZodType; } -export class Request { +export class Request { public baseUrl = ''; public headers: Map = new Map(); @@ -58,14 +63,12 @@ export class Request { public config: SdkConfig; - public responseSchema: ZodType; + public responses: ResponseDefinition[]; public requestSchema: ZodType; public requestContentType: ContentType; - public responseContentType: ContentType; - public validation: ValidationOptions = {} as any; public retry: RetryOptions = {} as any; @@ -74,7 +77,7 @@ export class Request { private readonly pathPattern: string; - constructor(params: CreateRequestParameters) { + constructor(params: CreateRequestParameters) { this.baseUrl = params.baseUrl; this.method = params.method; this.pathPattern = params.path; @@ -84,10 +87,9 @@ export class Request { this.pathParams = params.pathParams; this.headers = params.headers; this.queryParams = params.queryParams; - this.responseSchema = params.responseSchema; + this.responses = params.responses; this.requestSchema = params.requestSchema; this.requestContentType = params.requestContentType; - this.responseContentType = params.responseContentType; this.retry = params.retry; this.validation = params.validation; this.pagination = params.pagination; @@ -171,11 +173,13 @@ export class Request { public constructFullUrl(): string { const queryString = new QuerySerializer().serialize(this.queryParams); const path = this.constructPath(); - return `${this.baseUrl}${path}${queryString}`; + const baseUrl = this.baseUrl; + + return `${baseUrl}${path}${queryString}`; } - public copy(overrides?: Partial>) { - const createRequestParams: CreateRequestParameters = { + public copy(overrides?: Partial) { + const createRequestParams: CreateRequestParameters = { baseUrl: overrides?.baseUrl ?? this.baseUrl, method: overrides?.method ?? this.method, path: overrides?.path ?? this.path, @@ -184,14 +188,13 @@ export class Request { pathParams: overrides?.pathParams ?? this.pathParams, queryParams: overrides?.queryParams ?? this.queryParams, headers: overrides?.headers ?? this.headers, - responseSchema: overrides?.responseSchema ?? this.responseSchema, + responses: overrides?.responses ?? this.responses, requestSchema: overrides?.requestSchema ?? this.requestSchema, requestContentType: overrides?.requestContentType ?? this.requestContentType, - responseContentType: overrides?.responseContentType ?? this.responseContentType, retry: overrides?.retry ?? this.retry, validation: overrides?.validation ?? this.validation, }; - return new Request({ + return new Request({ ...createRequestParams, ...overrides, }); @@ -205,7 +208,7 @@ export class Request { return new HeaderSerializer().serialize(this.headers); } - public nextPage() { + public nextPage(): void { if (!this.pagination) { return; } @@ -230,15 +233,15 @@ export class Request { private getAllParams(): RequestParameter[] { const allParams: RequestParameter[] = []; - this.headers.forEach((val, key) => { + this.headers.forEach((val, _) => { allParams.push(val); }); - this.queryParams.forEach((val, key) => { + this.queryParams.forEach((val, _) => { allParams.push(val); }); - this.pathParams.forEach((val, key) => { + this.pathParams.forEach((val, _) => { allParams.push(val); }); diff --git a/packages/project-client/src/http/transport/transport-hook-adapter.ts b/packages/project-client/src/http/transport/transport-hook-adapter.ts index d256295d5..c2b07cef0 100644 --- a/packages/project-client/src/http/transport/transport-hook-adapter.ts +++ b/packages/project-client/src/http/transport/transport-hook-adapter.ts @@ -7,7 +7,7 @@ import { Request, RequestParameter } from './request.js'; export class TransportHookAdapter { private hook: CustomHook = new CustomHook(); - public async beforeRequest(request: Request, params: Map): Promise> { + public async beforeRequest(request: Request, params: Map): Promise { const hookRequest = this.requestToHookRequest(request); const newRequest = await this.hook.beforeRequest(hookRequest, params); @@ -26,7 +26,7 @@ export class TransportHookAdapter { } public async afterResponse( - request: Request, + request: Request, response: HttpResponse, params: Map, ): Promise> { @@ -34,16 +34,12 @@ export class TransportHookAdapter { return this.hook.afterResponse(hookRequest, response, params); } - public async onError( - request: Request, - response: HttpResponse, - params: Map, - ): Promise { + public async onError(request: Request, response: HttpResponse, params: Map): Promise { const hookRequest = this.requestToHookRequest(request); return this.hook.onError(hookRequest, response, params); } - private requestToHookRequest(request: Request): HttpRequest { + private requestToHookRequest(request: Request): HttpRequest { const hookHeaders: Map = new Map(); request.headers.forEach((header, key) => { hookHeaders.set(key, header.value); diff --git a/packages/project-client/src/http/types.ts b/packages/project-client/src/http/types.ts index fb17dafc7..5fc1ccbc1 100644 --- a/packages/project-client/src/http/types.ts +++ b/packages/project-client/src/http/types.ts @@ -29,8 +29,8 @@ export interface HttpResponse { export interface RequestHandler { next?: RequestHandler; - handle(request: Request): Promise>; - stream(request: Request): AsyncGenerator>; + handle(request: Request): Promise>; + stream(request: Request): AsyncGenerator>; } export enum ContentType { @@ -44,6 +44,7 @@ export enum ContentType { Text = 'text', MultipartFormData = 'multipartFormData', EventStream = 'eventStream', + NoContent = 'noContent', } export interface Options { diff --git a/packages/project-client/src/http/utils/line-decoder.ts b/packages/project-client/src/http/utils/line-decoder.ts new file mode 100644 index 000000000..822414b87 --- /dev/null +++ b/packages/project-client/src/http/utils/line-decoder.ts @@ -0,0 +1,35 @@ +export class LineDecoder { + private lineBuffer = ''; + private decoder = new TextDecoder(); + private encoder = new TextEncoder(); + + /** + * Splits the given chunk into lines. + * Stores incomplete lines in a buffer and returns them when the next chunk arrives. + */ + public splitLines(chunk: Uint8Array): Uint8Array[] { + this.lineBuffer += this.decoder.decode(chunk); + + let lineEndIndex; + const lines: Uint8Array[] = []; + while ((lineEndIndex = this.lineBuffer.indexOf('\n')) >= 0) { + const line = this.lineBuffer.slice(0, lineEndIndex + 1); // Include the newline character + this.lineBuffer = this.lineBuffer.slice(lineEndIndex + 1); + if (line.length > 1) { + lines.push(this.encoder.encode(line)); + } + } + + return lines; + } + + /** Returns the remaining lines in the buffer. */ + public flush(): Uint8Array[] { + if (this.lineBuffer.length === 0) { + return []; + } + const lines = [this.encoder.encode(this.lineBuffer)]; + this.lineBuffer = ''; + return lines; + } +} diff --git a/packages/project-client/src/http/utils/response-matcher.ts b/packages/project-client/src/http/utils/response-matcher.ts new file mode 100644 index 000000000..70af48c92 --- /dev/null +++ b/packages/project-client/src/http/utils/response-matcher.ts @@ -0,0 +1,56 @@ +import { ResponseDefinition } from '../transport/request.js'; +import { ContentType, HttpResponse } from '../types.js'; + +export class ResponseMatcher { + constructor(private responses: ResponseDefinition[]) {} + + public getResponseDefinition(response: HttpResponse): ResponseDefinition | undefined { + const rawContentType = response.metadata.headers['content-type']?.toLocaleLowerCase() || ''; + const contentType = this.getContentTypeDefinition(rawContentType); + const statusCode = response.metadata.status; + + if (!this.responses.length) { + return; + } + + if (this.responses.length === 1) { + return this.responses[0]; + } + + return this.responses.find((response) => { + return response.contentType === contentType && response.status === statusCode; + }); + } + + private getContentTypeDefinition(contentType: string): ContentType { + if (contentType.startsWith('application/') && contentType.includes('xml')) { + return ContentType.Xml; + } + + if (contentType.toLowerCase() === 'application/x-www-form-urlencoded') { + return ContentType.FormUrlEncoded; + } + + if (contentType.toLowerCase() === 'text/event-stream') { + return ContentType.EventStream; + } + + if (contentType.toLowerCase().startsWith('text/')) { + return ContentType.Text; + } + + if (contentType.toLowerCase().startsWith('image/')) { + return ContentType.Image; + } + + if (contentType.toLowerCase() === 'application/octet-stream') { + return ContentType.Binary; + } + + if (contentType.toLowerCase() === 'application/json') { + return ContentType.Json; + } + + return ContentType.Json; + } +} diff --git a/packages/project-client/src/index.ts b/packages/project-client/src/index.ts index 010cc7e99..f34ff2dc8 100644 --- a/packages/project-client/src/index.ts +++ b/packages/project-client/src/index.ts @@ -5,6 +5,7 @@ import { ChannelsService } from './services/channels/index.js'; import { EventsService } from './services/events/index.js'; import { IntegrationsService } from './services/integrations/index.js'; import { JwtService } from './services/jwt/index.js'; +import { UsersService } from './services/users/index.js'; export type * from './http/index.js'; export * from './services/broadcasts/index.js'; @@ -13,6 +14,7 @@ export * from './services/common/index.js'; export * from './services/events/index.js'; export * from './services/integrations/index.js'; export * from './services/jwt/index.js'; +export * from './services/users/index.js'; export class Client { public readonly broadcasts: BroadcastsService; @@ -25,6 +27,8 @@ export class Client { public readonly jwt: JwtService; + public readonly users: UsersService; + constructor(public config: SdkConfig) { const baseUrl = config.environment || config.baseUrl || Environment.DEFAULT; this.config = { @@ -40,6 +44,8 @@ export class Client { this.integrations = new IntegrationsService(this.config); this.jwt = new JwtService(this.config); + + this.users = new UsersService(this.config); } set baseUrl(baseUrl: string) { @@ -48,6 +54,7 @@ export class Client { this.events.baseUrl = baseUrl; this.integrations.baseUrl = baseUrl; this.jwt.baseUrl = baseUrl; + this.users.baseUrl = baseUrl; } set environment(environment: Environment) { @@ -56,6 +63,7 @@ export class Client { this.events.baseUrl = environment; this.integrations.baseUrl = environment; this.jwt.baseUrl = environment; + this.users.baseUrl = environment; } set timeoutMs(timeoutMs: number) { @@ -64,6 +72,7 @@ export class Client { this.events.timeoutMs = timeoutMs; this.integrations.timeoutMs = timeoutMs; this.jwt.timeoutMs = timeoutMs; + this.users.timeoutMs = timeoutMs; } set token(token: string) { @@ -72,6 +81,7 @@ export class Client { this.events.token = token; this.integrations.token = token; this.jwt.token = token; + this.users.token = token; } } diff --git a/packages/project-client/src/services/broadcasts/broadcasts.ts b/packages/project-client/src/services/broadcasts/broadcasts.ts index 0c570b37b..a67cf2010 100644 --- a/packages/project-client/src/services/broadcasts/broadcasts.ts +++ b/packages/project-client/src/services/broadcasts/broadcasts.ts @@ -20,15 +20,18 @@ export class BroadcastsService extends BaseService { params?: ListBroadcastsParams, requestConfig?: RequestConfig, ): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/broadcasts') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfBroadcastsResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfBroadcastsResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -53,15 +56,18 @@ export class BroadcastsService extends BaseService { * @returns {Promise>} Created */ async createBroadcast(body: Broadcast, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('POST') .setPath('/broadcasts') .setRequestSchema(broadcastRequest) - .setResponseSchema(broadcastResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: broadcastResponse, + contentType: ContentType.Json, + status: 201, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -77,15 +83,18 @@ export class BroadcastsService extends BaseService { * @returns {Promise>} OK */ async fetchBroadcast(broadcastId: string, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/broadcasts/{broadcast_id}') .setRequestSchema(z.any()) - .setResponseSchema(broadcastResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: broadcastResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) diff --git a/packages/project-client/src/services/channels/channels.ts b/packages/project-client/src/services/channels/channels.ts index 3c628e0ec..c995df372 100644 --- a/packages/project-client/src/services/channels/channels.ts +++ b/packages/project-client/src/services/channels/channels.ts @@ -4,45 +4,41 @@ import { SerializationStyle } from '../../http/serialization/base-serializer.js' import { RequestBuilder } from '../../http/transport/request-builder.js'; import { ContentType, HttpResponse, RequestConfig } from '../../http/types.js'; import { BaseService } from '../base-service.js'; +import { ApnsTokenResponse, apnsTokenResponseResponse } from './models/apns-token-response.js'; import { - ArrayOfMetadataApnsTokens, - arrayOfMetadataApnsTokensResponse, -} from './models/array-of-metadata-apns-tokens.js'; + ArrayOfApnsTokenResponses, + arrayOfApnsTokenResponsesResponse, +} from './models/array-of-apns-token-responses.js'; import { - ArrayOfMetadataExpoTokens, - arrayOfMetadataExpoTokensResponse, -} from './models/array-of-metadata-expo-tokens.js'; -import { ArrayOfMetadataFcmTokens, arrayOfMetadataFcmTokensResponse } from './models/array-of-metadata-fcm-tokens.js'; + ArrayOfExpoTokenResponses, + arrayOfExpoTokenResponsesResponse, +} from './models/array-of-expo-token-responses.js'; +import { ArrayOfFcmTokenResponses, arrayOfFcmTokenResponsesResponse } from './models/array-of-fcm-token-responses.js'; import { - ArrayOfMetadataSlackTokens, - arrayOfMetadataSlackTokensResponse, -} from './models/array-of-metadata-slack-tokens.js'; + ArrayOfSlackTokenResponses, + arrayOfSlackTokenResponsesResponse, +} from './models/array-of-slack-token-responses.js'; import { - ArrayOfMetadataTeamsTokens, - arrayOfMetadataTeamsTokensResponse, -} from './models/array-of-metadata-teams-tokens.js'; + ArrayOfTeamsTokenResponses, + arrayOfTeamsTokenResponsesResponse, +} from './models/array-of-teams-token-responses.js'; import { - ArrayOfMetadataWebPushTokens, - arrayOfMetadataWebPushTokensResponse, -} from './models/array-of-metadata-web-push-tokens.js'; + ArrayOfWebPushTokenResponses, + arrayOfWebPushTokenResponsesResponse, +} from './models/array-of-web-push-token-responses.js'; import { CategoryDeliveryConfig, categoryDeliveryConfigRequest, categoryDeliveryConfigResponse, } from './models/category-delivery-config.js'; import { DiscardResult, discardResultResponse } from './models/discard-result.js'; -import { MetadataApnsToken, metadataApnsTokenResponse } from './models/metadata-apns-token.js'; -import { MetadataExpoToken, metadataExpoTokenResponse } from './models/metadata-expo-token.js'; -import { MetadataFcmToken, metadataFcmTokenResponse } from './models/metadata-fcm-token.js'; -import { MetadataSlackToken, metadataSlackTokenResponse } from './models/metadata-slack-token.js'; -import { MetadataTeamsToken, metadataTeamsTokenResponse } from './models/metadata-teams-token.js'; -import { MetadataWebPushToken, metadataWebPushTokenResponse } from './models/metadata-web-push-token.js'; -import { - ProjectDeliveryConfig, - projectDeliveryConfigRequest, - projectDeliveryConfigResponse, -} from './models/project-delivery-config.js'; +import { ExpoTokenResponse, expoTokenResponseResponse } from './models/expo-token-response.js'; +import { FcmTokenResponse, fcmTokenResponseResponse } from './models/fcm-token-response.js'; +import { SlackTokenResponse, slackTokenResponseResponse } from './models/slack-token-response.js'; +import { TeamsTokenResponse, teamsTokenResponseResponse } from './models/teams-token-response.js'; +import { WebPushTokenResponse, webPushTokenResponseResponse } from './models/web-push-token-response.js'; import { + GetDeliveryconfigParams, GetMobilePushApnsUserTokensParams, GetMobilePushExpoUserTokensParams, GetMobilePushFcmUserTokensParams, @@ -54,68 +50,56 @@ import { export class ChannelsService extends BaseService { /** * - * @returns {Promise>} OK + * @param {string} [key] - + * @returns {Promise>} OK */ - async getProjectDeliveryconfig(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async getDeliveryconfig( + params?: GetDeliveryconfigParams, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/channels/deliveryconfig') .setRequestSchema(z.any()) - .setResponseSchema(projectDeliveryConfigResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) - .setRetryAttempts(this.config, requestConfig) - .setRetryDelayMs(this.config, requestConfig) - .setResponseValidation(this.config, requestConfig) - .build(); - return this.client.call(request); - } - - /** - * - * @returns {Promise>} OK - */ - async saveProjectDeliveryconfig( - body: ProjectDeliveryConfig, - requestConfig?: RequestConfig, - ): Promise> { - const request = new RequestBuilder() - .setBaseUrl(this.config) - .setConfig(this.config) - .setMethod('PUT') - .setPath('/channels/deliveryconfig') - .setRequestSchema(projectDeliveryConfigRequest) - .setResponseSchema(projectDeliveryConfigResponse) - .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: categoryDeliveryConfigResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) - .addHeaderParam({ key: 'Content-Type', value: 'application/json' }) - .addBody(body) + .addQueryParam({ + key: 'key', + value: params?.key, + }) .build(); - return this.client.call(request); + return this.client.call(request); } /** * - * @returns {Promise>} Created + * @returns {Promise>} OK */ - async saveCategoriesDeliveryconfig( + async saveDeliveryconfig( body: CategoryDeliveryConfig, requestConfig?: RequestConfig, ): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) - .setMethod('POST') - .setPath('/channels/deliveryconfig/categories') + .setMethod('PUT') + .setPath('/channels/deliveryconfig') .setRequestSchema(categoryDeliveryConfigRequest) - .setResponseSchema(categoryDeliveryConfigResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: categoryDeliveryConfigResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -131,22 +115,25 @@ export class ChannelsService extends BaseService { * @param {number} [pageSize] - * @param {string} [pageAfter] - * @param {string} [pageBefore] - - * @returns {Promise>} OK + * @returns {Promise>} OK */ async getMobilePushApnsUserTokens( userId: string, params?: GetMobilePushApnsUserTokensParams, requestConfig?: RequestConfig, - ): Promise> { - const request = new RequestBuilder() + ): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/users/{user_id}/channels/mobile_push/apns/tokens') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfMetadataApnsTokensResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfApnsTokenResponsesResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -167,29 +154,32 @@ export class ChannelsService extends BaseService { value: params?.pageBefore, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** * Retrieves a specific mobile_push token by its ID for a given user. This endpoint is available to project administrators and requires project-level authentication. Use this to inspect token details including its status, creation date, and associated metadata. * @param {string} userId - * @param {string} tokenId - - * @returns {Promise>} OK + * @returns {Promise>} OK */ async getMobilePushApnsUserToken( userId: string, tokenId: string, requestConfig?: RequestConfig, - ): Promise> { - const request = new RequestBuilder() + ): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/users/{user_id}/channels/mobile_push/apns/tokens/{token_id}') .setRequestSchema(z.any()) - .setResponseSchema(metadataApnsTokenResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: apnsTokenResponseResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -202,7 +192,7 @@ export class ChannelsService extends BaseService { value: tokenId, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -216,15 +206,18 @@ export class ChannelsService extends BaseService { tokenId: string, requestConfig?: RequestConfig, ): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/users/{user_id}/channels/mobile_push/apns/tokens/{token_id}') .setRequestSchema(z.any()) - .setResponseSchema(discardResultResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: discardResultResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -246,22 +239,25 @@ export class ChannelsService extends BaseService { * @param {number} [pageSize] - * @param {string} [pageAfter] - * @param {string} [pageBefore] - - * @returns {Promise>} OK + * @returns {Promise>} OK */ async getMobilePushExpoUserTokens( userId: string, params?: GetMobilePushExpoUserTokensParams, requestConfig?: RequestConfig, - ): Promise> { - const request = new RequestBuilder() + ): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/users/{user_id}/channels/mobile_push/expo/tokens') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfMetadataExpoTokensResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfExpoTokenResponsesResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -282,29 +278,32 @@ export class ChannelsService extends BaseService { value: params?.pageBefore, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** * Retrieves a specific mobile_push token by its ID for a given user. This endpoint is available to project administrators and requires project-level authentication. Use this to inspect token details including its status, creation date, and associated metadata. * @param {string} userId - * @param {string} tokenId - - * @returns {Promise>} OK + * @returns {Promise>} OK */ async getMobilePushExpoUserToken( userId: string, tokenId: string, requestConfig?: RequestConfig, - ): Promise> { - const request = new RequestBuilder() + ): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/users/{user_id}/channels/mobile_push/expo/tokens/{token_id}') .setRequestSchema(z.any()) - .setResponseSchema(metadataExpoTokenResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: expoTokenResponseResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -317,7 +316,7 @@ export class ChannelsService extends BaseService { value: tokenId, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -331,15 +330,18 @@ export class ChannelsService extends BaseService { tokenId: string, requestConfig?: RequestConfig, ): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/users/{user_id}/channels/mobile_push/expo/tokens/{token_id}') .setRequestSchema(z.any()) - .setResponseSchema(discardResultResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: discardResultResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -361,22 +363,25 @@ export class ChannelsService extends BaseService { * @param {number} [pageSize] - * @param {string} [pageAfter] - * @param {string} [pageBefore] - - * @returns {Promise>} OK + * @returns {Promise>} OK */ async getMobilePushFcmUserTokens( userId: string, params?: GetMobilePushFcmUserTokensParams, requestConfig?: RequestConfig, - ): Promise> { - const request = new RequestBuilder() + ): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/users/{user_id}/channels/mobile_push/fcm/tokens') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfMetadataFcmTokensResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfFcmTokenResponsesResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -397,29 +402,32 @@ export class ChannelsService extends BaseService { value: params?.pageBefore, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** * Retrieves a specific mobile_push token by its ID for a given user. This endpoint is available to project administrators and requires project-level authentication. Use this to inspect token details including its status, creation date, and associated metadata. * @param {string} userId - * @param {string} tokenId - - * @returns {Promise>} OK + * @returns {Promise>} OK */ async getMobilePushFcmUserToken( userId: string, tokenId: string, requestConfig?: RequestConfig, - ): Promise> { - const request = new RequestBuilder() + ): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/users/{user_id}/channels/mobile_push/fcm/tokens/{token_id}') .setRequestSchema(z.any()) - .setResponseSchema(metadataFcmTokenResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: fcmTokenResponseResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -432,7 +440,7 @@ export class ChannelsService extends BaseService { value: tokenId, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -446,15 +454,18 @@ export class ChannelsService extends BaseService { tokenId: string, requestConfig?: RequestConfig, ): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/users/{user_id}/channels/mobile_push/fcm/tokens/{token_id}') .setRequestSchema(z.any()) - .setResponseSchema(discardResultResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: discardResultResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -476,22 +487,25 @@ export class ChannelsService extends BaseService { * @param {number} [pageSize] - * @param {string} [pageAfter] - * @param {string} [pageBefore] - - * @returns {Promise>} OK + * @returns {Promise>} OK */ async getSlackUserTokens( userId: string, params?: GetSlackUserTokensParams, requestConfig?: RequestConfig, - ): Promise> { - const request = new RequestBuilder() + ): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/users/{user_id}/channels/slack/tokens') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfMetadataSlackTokensResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfSlackTokenResponsesResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -512,29 +526,32 @@ export class ChannelsService extends BaseService { value: params?.pageBefore, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** * Retrieves a specific slack token by its ID for a given user. This endpoint is available to project administrators and requires project-level authentication. Use this to inspect token details including its status, creation date, and associated metadata. * @param {string} userId - * @param {string} tokenId - - * @returns {Promise>} OK + * @returns {Promise>} OK */ async getSlackUserToken( userId: string, tokenId: string, requestConfig?: RequestConfig, - ): Promise> { - const request = new RequestBuilder() + ): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/users/{user_id}/channels/slack/tokens/{token_id}') .setRequestSchema(z.any()) - .setResponseSchema(metadataSlackTokenResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: slackTokenResponseResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -547,7 +564,7 @@ export class ChannelsService extends BaseService { value: tokenId, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -561,15 +578,18 @@ export class ChannelsService extends BaseService { tokenId: string, requestConfig?: RequestConfig, ): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/users/{user_id}/channels/slack/tokens/{token_id}') .setRequestSchema(z.any()) - .setResponseSchema(discardResultResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: discardResultResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -591,22 +611,25 @@ export class ChannelsService extends BaseService { * @param {number} [pageSize] - * @param {string} [pageAfter] - * @param {string} [pageBefore] - - * @returns {Promise>} OK + * @returns {Promise>} OK */ async getTeamsUserTokens( userId: string, params?: GetTeamsUserTokensParams, requestConfig?: RequestConfig, - ): Promise> { - const request = new RequestBuilder() + ): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/users/{user_id}/channels/teams/tokens') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfMetadataTeamsTokensResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfTeamsTokenResponsesResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -627,29 +650,32 @@ export class ChannelsService extends BaseService { value: params?.pageBefore, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** * Retrieves a specific teams token by its ID for a given user. This endpoint is available to project administrators and requires project-level authentication. Use this to inspect token details including its status, creation date, and associated metadata. * @param {string} userId - * @param {string} tokenId - - * @returns {Promise>} OK + * @returns {Promise>} OK */ async getTeamsUserToken( userId: string, tokenId: string, requestConfig?: RequestConfig, - ): Promise> { - const request = new RequestBuilder() + ): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/users/{user_id}/channels/teams/tokens/{token_id}') .setRequestSchema(z.any()) - .setResponseSchema(metadataTeamsTokenResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: teamsTokenResponseResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -662,7 +688,7 @@ export class ChannelsService extends BaseService { value: tokenId, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -676,15 +702,18 @@ export class ChannelsService extends BaseService { tokenId: string, requestConfig?: RequestConfig, ): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/users/{user_id}/channels/teams/tokens/{token_id}') .setRequestSchema(z.any()) - .setResponseSchema(discardResultResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: discardResultResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -706,22 +735,25 @@ export class ChannelsService extends BaseService { * @param {number} [pageSize] - * @param {string} [pageAfter] - * @param {string} [pageBefore] - - * @returns {Promise>} OK + * @returns {Promise>} OK */ async getWebPushUserTokens( userId: string, params?: GetWebPushUserTokensParams, requestConfig?: RequestConfig, - ): Promise> { - const request = new RequestBuilder() + ): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/users/{user_id}/channels/web_push/tokens') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfMetadataWebPushTokensResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfWebPushTokenResponsesResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -742,29 +774,32 @@ export class ChannelsService extends BaseService { value: params?.pageBefore, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** * Retrieves a specific web_push token by its ID for a given user. This endpoint is available to project administrators and requires project-level authentication. Use this to inspect token details including its status, creation date, and associated metadata. * @param {string} userId - * @param {string} tokenId - - * @returns {Promise>} OK + * @returns {Promise>} OK */ async getWebPushUserToken( userId: string, tokenId: string, requestConfig?: RequestConfig, - ): Promise> { - const request = new RequestBuilder() + ): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/users/{user_id}/channels/web_push/tokens/{token_id}') .setRequestSchema(z.any()) - .setResponseSchema(metadataWebPushTokenResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: webPushTokenResponseResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -777,7 +812,7 @@ export class ChannelsService extends BaseService { value: tokenId, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -791,15 +826,18 @@ export class ChannelsService extends BaseService { tokenId: string, requestConfig?: RequestConfig, ): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/users/{user_id}/channels/web_push/tokens/{token_id}') .setRequestSchema(z.any()) - .setResponseSchema(discardResultResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: discardResultResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) diff --git a/packages/project-client/src/services/channels/models/apns-token-response-installation-id.ts b/packages/project-client/src/services/channels/models/apns-token-response-installation-id.ts new file mode 100644 index 000000000..3de2f2c7c --- /dev/null +++ b/packages/project-client/src/services/channels/models/apns-token-response-installation-id.ts @@ -0,0 +1,6 @@ +import { z } from 'zod'; + +export enum ApnsTokenResponseInstallationId { + DEVELOPMENT = 'development', + PRODUCTION = 'production', +} diff --git a/packages/project-client/src/services/channels/models/apns-token.ts b/packages/project-client/src/services/channels/models/apns-token-response.ts similarity index 52% rename from packages/project-client/src/services/channels/models/apns-token.ts rename to packages/project-client/src/services/channels/models/apns-token-response.ts index b5a4815a5..f1087a00f 100644 --- a/packages/project-client/src/services/channels/models/apns-token.ts +++ b/packages/project-client/src/services/channels/models/apns-token-response.ts @@ -3,44 +3,60 @@ import { z } from 'zod'; /** * The shape of the model inside the application code - what the users use */ -export const apnsToken = z.lazy(() => { +export const apnsTokenResponse = z.lazy(() => { return z.object({ appId: z .string() .regex(/^[a-zA-Z0-9]+(.[a-zA-Z0-9]+)*$/) .optional(), + createdAt: z.string(), deviceToken: z.string().min(64), + discardedAt: z.string().optional().nullable(), + id: z.string(), installationId: z.string().optional(), + updatedAt: z.string().optional().nullable(), }); }); /** * - * @typedef {ApnsToken} apnsToken + * @typedef {ApnsTokenResponse} apnsTokenResponse * @property {string} - (Optional) The bundle identifier of the application that is registering this token. Use this field to override the default identifier specified in the projects APNs integration. * @property {string} - * @property {ApnsTokenInstallationId} - (Optional) The APNs environment the token is registered for. If none is provided we assume the token is used in `production`. + * @property {string} + * @property {string} + * @property {string} + * @property {ApnsTokenResponseInstallationId} - (Optional) The APNs environment the token is registered for. If none is provided we assume the token is used in `production`. + * @property {string} */ -export type ApnsToken = z.infer; +export type ApnsTokenResponse = z.infer; /** * The shape of the model mapping from the api schema into the application shape. * Is equal to application shape if all property names match the api schema */ -export const apnsTokenResponse = z.lazy(() => { +export const apnsTokenResponseResponse = z.lazy(() => { return z .object({ app_id: z .string() .regex(/^[a-zA-Z0-9]+(.[a-zA-Z0-9]+)*$/) .optional(), + created_at: z.string(), device_token: z.string().min(64), + discarded_at: z.string().optional().nullable(), + id: z.string(), installation_id: z.string().optional(), + updated_at: z.string().optional().nullable(), }) .transform((data) => ({ appId: data['app_id'], + createdAt: data['created_at'], deviceToken: data['device_token'], + discardedAt: data['discarded_at'], + id: data['id'], installationId: data['installation_id'], + updatedAt: data['updated_at'], })); }); @@ -48,12 +64,24 @@ export const apnsTokenResponse = z.lazy(() => { * The shape of the model mapping from the application shape into the api schema. * Is equal to application shape if all property names match the api schema */ -export const apnsTokenRequest = z.lazy(() => { +export const apnsTokenResponseRequest = z.lazy(() => { return z - .object({ appId: z.string().nullish(), deviceToken: z.string().nullish(), installationId: z.string().nullish() }) + .object({ + appId: z.string().nullish(), + createdAt: z.string().nullish(), + deviceToken: z.string().nullish(), + discardedAt: z.string().nullish(), + id: z.string().nullish(), + installationId: z.string().nullish(), + updatedAt: z.string().nullish(), + }) .transform((data) => ({ app_id: data['appId'], + created_at: data['createdAt'], device_token: data['deviceToken'], + discarded_at: data['discardedAt'], + id: data['id'], installation_id: data['installationId'], + updated_at: data['updatedAt'], })); }); diff --git a/packages/project-client/src/services/channels/models/array-of-metadata-expo-tokens.ts b/packages/project-client/src/services/channels/models/array-of-apns-token-responses.ts similarity index 58% rename from packages/project-client/src/services/channels/models/array-of-metadata-expo-tokens.ts rename to packages/project-client/src/services/channels/models/array-of-apns-token-responses.ts index c3245fb63..0c72d34ff 100644 --- a/packages/project-client/src/services/channels/models/array-of-metadata-expo-tokens.ts +++ b/packages/project-client/src/services/channels/models/array-of-apns-token-responses.ts @@ -1,34 +1,34 @@ import { z } from 'zod'; import { links, linksRequest, linksResponse } from '../../common/links.js'; -import { metadataExpoToken, metadataExpoTokenRequest, metadataExpoTokenResponse } from './metadata-expo-token.js'; +import { apnsTokenResponse, apnsTokenResponseRequest, apnsTokenResponseResponse } from './apns-token-response.js'; /** * The shape of the model inside the application code - what the users use */ -export const arrayOfMetadataExpoTokens = z.lazy(() => { +export const arrayOfApnsTokenResponses = z.lazy(() => { return z.object({ - data: z.array(metadataExpoToken).optional(), + data: z.array(apnsTokenResponse).optional(), links: links.optional(), }); }); /** * - * @typedef {ArrayOfMetadataExpoTokens} arrayOfMetadataExpoTokens - * @property {MetadataExpoToken[]} + * @typedef {ArrayOfApnsTokenResponses} arrayOfApnsTokenResponses + * @property {ApnsTokenResponse[]} * @property {Links} */ -export type ArrayOfMetadataExpoTokens = z.infer; +export type ArrayOfApnsTokenResponses = z.infer; /** * The shape of the model mapping from the api schema into the application shape. * Is equal to application shape if all property names match the api schema */ -export const arrayOfMetadataExpoTokensResponse = z.lazy(() => { +export const arrayOfApnsTokenResponsesResponse = z.lazy(() => { return z .object({ - data: z.array(metadataExpoTokenResponse).optional(), + data: z.array(apnsTokenResponseResponse).optional(), links: linksResponse.optional(), }) .transform((data) => ({ @@ -41,9 +41,9 @@ export const arrayOfMetadataExpoTokensResponse = z.lazy(() => { * The shape of the model mapping from the application shape into the api schema. * Is equal to application shape if all property names match the api schema */ -export const arrayOfMetadataExpoTokensRequest = z.lazy(() => { +export const arrayOfApnsTokenResponsesRequest = z.lazy(() => { return z - .object({ data: z.array(metadataExpoTokenRequest).nullish(), links: linksRequest.nullish() }) + .object({ data: z.array(apnsTokenResponseRequest).nullish(), links: linksRequest.nullish() }) .transform((data) => ({ data: data['data'], links: data['links'], diff --git a/packages/project-client/src/services/channels/models/array-of-metadata-apns-tokens.ts b/packages/project-client/src/services/channels/models/array-of-expo-token-responses.ts similarity index 58% rename from packages/project-client/src/services/channels/models/array-of-metadata-apns-tokens.ts rename to packages/project-client/src/services/channels/models/array-of-expo-token-responses.ts index 98baa8907..4d6d59c89 100644 --- a/packages/project-client/src/services/channels/models/array-of-metadata-apns-tokens.ts +++ b/packages/project-client/src/services/channels/models/array-of-expo-token-responses.ts @@ -1,34 +1,34 @@ import { z } from 'zod'; import { links, linksRequest, linksResponse } from '../../common/links.js'; -import { metadataApnsToken, metadataApnsTokenRequest, metadataApnsTokenResponse } from './metadata-apns-token.js'; +import { expoTokenResponse, expoTokenResponseRequest, expoTokenResponseResponse } from './expo-token-response.js'; /** * The shape of the model inside the application code - what the users use */ -export const arrayOfMetadataApnsTokens = z.lazy(() => { +export const arrayOfExpoTokenResponses = z.lazy(() => { return z.object({ - data: z.array(metadataApnsToken).optional(), + data: z.array(expoTokenResponse).optional(), links: links.optional(), }); }); /** * - * @typedef {ArrayOfMetadataApnsTokens} arrayOfMetadataApnsTokens - * @property {MetadataApnsToken[]} + * @typedef {ArrayOfExpoTokenResponses} arrayOfExpoTokenResponses + * @property {ExpoTokenResponse[]} * @property {Links} */ -export type ArrayOfMetadataApnsTokens = z.infer; +export type ArrayOfExpoTokenResponses = z.infer; /** * The shape of the model mapping from the api schema into the application shape. * Is equal to application shape if all property names match the api schema */ -export const arrayOfMetadataApnsTokensResponse = z.lazy(() => { +export const arrayOfExpoTokenResponsesResponse = z.lazy(() => { return z .object({ - data: z.array(metadataApnsTokenResponse).optional(), + data: z.array(expoTokenResponseResponse).optional(), links: linksResponse.optional(), }) .transform((data) => ({ @@ -41,9 +41,9 @@ export const arrayOfMetadataApnsTokensResponse = z.lazy(() => { * The shape of the model mapping from the application shape into the api schema. * Is equal to application shape if all property names match the api schema */ -export const arrayOfMetadataApnsTokensRequest = z.lazy(() => { +export const arrayOfExpoTokenResponsesRequest = z.lazy(() => { return z - .object({ data: z.array(metadataApnsTokenRequest).nullish(), links: linksRequest.nullish() }) + .object({ data: z.array(expoTokenResponseRequest).nullish(), links: linksRequest.nullish() }) .transform((data) => ({ data: data['data'], links: data['links'], diff --git a/packages/project-client/src/services/channels/models/array-of-metadata-fcm-tokens.ts b/packages/project-client/src/services/channels/models/array-of-fcm-token-responses.ts similarity index 58% rename from packages/project-client/src/services/channels/models/array-of-metadata-fcm-tokens.ts rename to packages/project-client/src/services/channels/models/array-of-fcm-token-responses.ts index 10ef3b4db..7585dfb5b 100644 --- a/packages/project-client/src/services/channels/models/array-of-metadata-fcm-tokens.ts +++ b/packages/project-client/src/services/channels/models/array-of-fcm-token-responses.ts @@ -1,34 +1,34 @@ import { z } from 'zod'; import { links, linksRequest, linksResponse } from '../../common/links.js'; -import { metadataFcmToken, metadataFcmTokenRequest, metadataFcmTokenResponse } from './metadata-fcm-token.js'; +import { fcmTokenResponse, fcmTokenResponseRequest, fcmTokenResponseResponse } from './fcm-token-response.js'; /** * The shape of the model inside the application code - what the users use */ -export const arrayOfMetadataFcmTokens = z.lazy(() => { +export const arrayOfFcmTokenResponses = z.lazy(() => { return z.object({ - data: z.array(metadataFcmToken).optional(), + data: z.array(fcmTokenResponse).optional(), links: links.optional(), }); }); /** * - * @typedef {ArrayOfMetadataFcmTokens} arrayOfMetadataFcmTokens - * @property {MetadataFcmToken[]} + * @typedef {ArrayOfFcmTokenResponses} arrayOfFcmTokenResponses + * @property {FcmTokenResponse[]} * @property {Links} */ -export type ArrayOfMetadataFcmTokens = z.infer; +export type ArrayOfFcmTokenResponses = z.infer; /** * The shape of the model mapping from the api schema into the application shape. * Is equal to application shape if all property names match the api schema */ -export const arrayOfMetadataFcmTokensResponse = z.lazy(() => { +export const arrayOfFcmTokenResponsesResponse = z.lazy(() => { return z .object({ - data: z.array(metadataFcmTokenResponse).optional(), + data: z.array(fcmTokenResponseResponse).optional(), links: linksResponse.optional(), }) .transform((data) => ({ @@ -41,9 +41,9 @@ export const arrayOfMetadataFcmTokensResponse = z.lazy(() => { * The shape of the model mapping from the application shape into the api schema. * Is equal to application shape if all property names match the api schema */ -export const arrayOfMetadataFcmTokensRequest = z.lazy(() => { +export const arrayOfFcmTokenResponsesRequest = z.lazy(() => { return z - .object({ data: z.array(metadataFcmTokenRequest).nullish(), links: linksRequest.nullish() }) + .object({ data: z.array(fcmTokenResponseRequest).nullish(), links: linksRequest.nullish() }) .transform((data) => ({ data: data['data'], links: data['links'], diff --git a/packages/project-client/src/services/channels/models/array-of-metadata-teams-tokens.ts b/packages/project-client/src/services/channels/models/array-of-slack-token-responses.ts similarity index 57% rename from packages/project-client/src/services/channels/models/array-of-metadata-teams-tokens.ts rename to packages/project-client/src/services/channels/models/array-of-slack-token-responses.ts index a2d103110..95b314448 100644 --- a/packages/project-client/src/services/channels/models/array-of-metadata-teams-tokens.ts +++ b/packages/project-client/src/services/channels/models/array-of-slack-token-responses.ts @@ -1,34 +1,34 @@ import { z } from 'zod'; import { links, linksRequest, linksResponse } from '../../common/links.js'; -import { metadataTeamsToken, metadataTeamsTokenRequest, metadataTeamsTokenResponse } from './metadata-teams-token.js'; +import { slackTokenResponse, slackTokenResponseRequest, slackTokenResponseResponse } from './slack-token-response.js'; /** * The shape of the model inside the application code - what the users use */ -export const arrayOfMetadataTeamsTokens = z.lazy(() => { +export const arrayOfSlackTokenResponses = z.lazy(() => { return z.object({ - data: z.array(metadataTeamsToken).optional(), + data: z.array(slackTokenResponse).optional(), links: links.optional(), }); }); /** * - * @typedef {ArrayOfMetadataTeamsTokens} arrayOfMetadataTeamsTokens - * @property {MetadataTeamsToken[]} + * @typedef {ArrayOfSlackTokenResponses} arrayOfSlackTokenResponses + * @property {SlackTokenResponse[]} * @property {Links} */ -export type ArrayOfMetadataTeamsTokens = z.infer; +export type ArrayOfSlackTokenResponses = z.infer; /** * The shape of the model mapping from the api schema into the application shape. * Is equal to application shape if all property names match the api schema */ -export const arrayOfMetadataTeamsTokensResponse = z.lazy(() => { +export const arrayOfSlackTokenResponsesResponse = z.lazy(() => { return z .object({ - data: z.array(metadataTeamsTokenResponse).optional(), + data: z.array(slackTokenResponseResponse).optional(), links: linksResponse.optional(), }) .transform((data) => ({ @@ -41,9 +41,9 @@ export const arrayOfMetadataTeamsTokensResponse = z.lazy(() => { * The shape of the model mapping from the application shape into the api schema. * Is equal to application shape if all property names match the api schema */ -export const arrayOfMetadataTeamsTokensRequest = z.lazy(() => { +export const arrayOfSlackTokenResponsesRequest = z.lazy(() => { return z - .object({ data: z.array(metadataTeamsTokenRequest).nullish(), links: linksRequest.nullish() }) + .object({ data: z.array(slackTokenResponseRequest).nullish(), links: linksRequest.nullish() }) .transform((data) => ({ data: data['data'], links: data['links'], diff --git a/packages/project-client/src/services/channels/models/array-of-metadata-slack-tokens.ts b/packages/project-client/src/services/channels/models/array-of-teams-token-responses.ts similarity index 57% rename from packages/project-client/src/services/channels/models/array-of-metadata-slack-tokens.ts rename to packages/project-client/src/services/channels/models/array-of-teams-token-responses.ts index 755340711..0dedf9efa 100644 --- a/packages/project-client/src/services/channels/models/array-of-metadata-slack-tokens.ts +++ b/packages/project-client/src/services/channels/models/array-of-teams-token-responses.ts @@ -1,34 +1,34 @@ import { z } from 'zod'; import { links, linksRequest, linksResponse } from '../../common/links.js'; -import { metadataSlackToken, metadataSlackTokenRequest, metadataSlackTokenResponse } from './metadata-slack-token.js'; +import { teamsTokenResponse, teamsTokenResponseRequest, teamsTokenResponseResponse } from './teams-token-response.js'; /** * The shape of the model inside the application code - what the users use */ -export const arrayOfMetadataSlackTokens = z.lazy(() => { +export const arrayOfTeamsTokenResponses = z.lazy(() => { return z.object({ - data: z.array(metadataSlackToken).optional(), + data: z.array(teamsTokenResponse).optional(), links: links.optional(), }); }); /** * - * @typedef {ArrayOfMetadataSlackTokens} arrayOfMetadataSlackTokens - * @property {MetadataSlackToken[]} + * @typedef {ArrayOfTeamsTokenResponses} arrayOfTeamsTokenResponses + * @property {TeamsTokenResponse[]} * @property {Links} */ -export type ArrayOfMetadataSlackTokens = z.infer; +export type ArrayOfTeamsTokenResponses = z.infer; /** * The shape of the model mapping from the api schema into the application shape. * Is equal to application shape if all property names match the api schema */ -export const arrayOfMetadataSlackTokensResponse = z.lazy(() => { +export const arrayOfTeamsTokenResponsesResponse = z.lazy(() => { return z .object({ - data: z.array(metadataSlackTokenResponse).optional(), + data: z.array(teamsTokenResponseResponse).optional(), links: linksResponse.optional(), }) .transform((data) => ({ @@ -41,9 +41,9 @@ export const arrayOfMetadataSlackTokensResponse = z.lazy(() => { * The shape of the model mapping from the application shape into the api schema. * Is equal to application shape if all property names match the api schema */ -export const arrayOfMetadataSlackTokensRequest = z.lazy(() => { +export const arrayOfTeamsTokenResponsesRequest = z.lazy(() => { return z - .object({ data: z.array(metadataSlackTokenRequest).nullish(), links: linksRequest.nullish() }) + .object({ data: z.array(teamsTokenResponseRequest).nullish(), links: linksRequest.nullish() }) .transform((data) => ({ data: data['data'], links: data['links'], diff --git a/packages/project-client/src/services/channels/models/array-of-metadata-web-push-tokens.ts b/packages/project-client/src/services/channels/models/array-of-web-push-token-responses.ts similarity index 57% rename from packages/project-client/src/services/channels/models/array-of-metadata-web-push-tokens.ts rename to packages/project-client/src/services/channels/models/array-of-web-push-token-responses.ts index 1428a16bd..f0fd8f78c 100644 --- a/packages/project-client/src/services/channels/models/array-of-metadata-web-push-tokens.ts +++ b/packages/project-client/src/services/channels/models/array-of-web-push-token-responses.ts @@ -2,37 +2,37 @@ import { z } from 'zod'; import { links, linksRequest, linksResponse } from '../../common/links.js'; import { - metadataWebPushToken, - metadataWebPushTokenRequest, - metadataWebPushTokenResponse, -} from './metadata-web-push-token.js'; + webPushTokenResponse, + webPushTokenResponseRequest, + webPushTokenResponseResponse, +} from './web-push-token-response.js'; /** * The shape of the model inside the application code - what the users use */ -export const arrayOfMetadataWebPushTokens = z.lazy(() => { +export const arrayOfWebPushTokenResponses = z.lazy(() => { return z.object({ - data: z.array(metadataWebPushToken).optional(), + data: z.array(webPushTokenResponse).optional(), links: links.optional(), }); }); /** * - * @typedef {ArrayOfMetadataWebPushTokens} arrayOfMetadataWebPushTokens - * @property {MetadataWebPushToken[]} + * @typedef {ArrayOfWebPushTokenResponses} arrayOfWebPushTokenResponses + * @property {WebPushTokenResponse[]} * @property {Links} */ -export type ArrayOfMetadataWebPushTokens = z.infer; +export type ArrayOfWebPushTokenResponses = z.infer; /** * The shape of the model mapping from the api schema into the application shape. * Is equal to application shape if all property names match the api schema */ -export const arrayOfMetadataWebPushTokensResponse = z.lazy(() => { +export const arrayOfWebPushTokenResponsesResponse = z.lazy(() => { return z .object({ - data: z.array(metadataWebPushTokenResponse).optional(), + data: z.array(webPushTokenResponseResponse).optional(), links: linksResponse.optional(), }) .transform((data) => ({ @@ -45,9 +45,9 @@ export const arrayOfMetadataWebPushTokensResponse = z.lazy(() => { * The shape of the model mapping from the application shape into the api schema. * Is equal to application shape if all property names match the api schema */ -export const arrayOfMetadataWebPushTokensRequest = z.lazy(() => { +export const arrayOfWebPushTokenResponsesRequest = z.lazy(() => { return z - .object({ data: z.array(metadataWebPushTokenRequest).nullish(), links: linksRequest.nullish() }) + .object({ data: z.array(webPushTokenResponseRequest).nullish(), links: linksRequest.nullish() }) .transform((data) => ({ data: data['data'], links: data['links'], diff --git a/packages/project-client/src/services/channels/models/category-delivery-config-channels.ts b/packages/project-client/src/services/channels/models/category-delivery-config-channels.ts index a6828038e..bce0ecacd 100644 --- a/packages/project-client/src/services/channels/models/category-delivery-config-channels.ts +++ b/packages/project-client/src/services/channels/models/category-delivery-config-channels.ts @@ -7,20 +7,16 @@ export const categoryDeliveryConfigChannels = z.lazy(() => { return z.object({ channel: z.string(), delay: z.number().gte(0).optional(), - disabled: z.boolean().optional(), - if: z.string().optional(), - priority: z.number().gte(0).optional(), + if: z.string().optional().nullable(), }); }); /** * * @typedef {CategoryDeliveryConfigChannels} categoryDeliveryConfigChannels - * @property {ChannelsChannel2} + * @property {Channel} * @property {number} - * @property {boolean} * @property {string} - * @property {number} */ export type CategoryDeliveryConfigChannels = z.infer; @@ -33,16 +29,12 @@ export const categoryDeliveryConfigChannelsResponse = z.lazy(() => { .object({ channel: z.string(), delay: z.number().gte(0).optional(), - disabled: z.boolean().optional(), - if: z.string().optional(), - priority: z.number().gte(0).optional(), + if: z.string().optional().nullable(), }) .transform((data) => ({ channel: data['channel'], delay: data['delay'], - disabled: data['disabled'], if: data['if'], - priority: data['priority'], })); }); @@ -52,18 +44,10 @@ export const categoryDeliveryConfigChannelsResponse = z.lazy(() => { */ export const categoryDeliveryConfigChannelsRequest = z.lazy(() => { return z - .object({ - channel: z.string().nullish(), - delay: z.number().nullish(), - disabled: z.boolean().nullish(), - if: z.string().nullish(), - priority: z.number().nullish(), - }) + .object({ channel: z.string().nullish(), delay: z.number().nullish(), if: z.string().nullish() }) .transform((data) => ({ channel: data['channel'], delay: data['delay'], - disabled: data['disabled'], if: data['if'], - priority: data['priority'], })); }); diff --git a/packages/project-client/src/services/channels/models/category-delivery-config.ts b/packages/project-client/src/services/channels/models/category-delivery-config.ts index b3404b1d9..7bc8cd28f 100644 --- a/packages/project-client/src/services/channels/models/category-delivery-config.ts +++ b/packages/project-client/src/services/channels/models/category-delivery-config.ts @@ -11,21 +11,21 @@ import { */ export const categoryDeliveryConfig = z.lazy(() => { return z.object({ - category: z - .string() - .min(3) - .regex(/^[a-zA-Z0-9_]+$/), channels: z.array(categoryDeliveryConfigChannels), disabled: z.boolean().optional(), + key: z + .string() + .min(3) + .regex(/^[A-Za-z0-9_\.\-:]+$/), }); }); /** * * @typedef {CategoryDeliveryConfig} categoryDeliveryConfig - * @property {string} * @property {CategoryDeliveryConfigChannels[]} * @property {boolean} + * @property {string} */ export type CategoryDeliveryConfig = z.infer; @@ -36,17 +36,17 @@ export type CategoryDeliveryConfig = z.infer; export const categoryDeliveryConfigResponse = z.lazy(() => { return z .object({ - category: z - .string() - .min(3) - .regex(/^[a-zA-Z0-9_]+$/), channels: z.array(categoryDeliveryConfigChannelsResponse), disabled: z.boolean().optional(), + key: z + .string() + .min(3) + .regex(/^[A-Za-z0-9_\.\-:]+$/), }) .transform((data) => ({ - category: data['category'], channels: data['channels'], disabled: data['disabled'], + key: data['key'], })); }); @@ -57,13 +57,13 @@ export const categoryDeliveryConfigResponse = z.lazy(() => { export const categoryDeliveryConfigRequest = z.lazy(() => { return z .object({ - category: z.string().nullish(), channels: z.array(categoryDeliveryConfigChannelsRequest).nullish(), disabled: z.boolean().nullish(), + key: z.string().nullish(), }) .transform((data) => ({ - category: data['category'], channels: data['channels'], disabled: data['disabled'], + key: data['key'], })); }); diff --git a/packages/project-client/src/services/channels/models/channels-channel-1.ts b/packages/project-client/src/services/channels/models/channel.ts similarity index 85% rename from packages/project-client/src/services/channels/models/channels-channel-1.ts rename to packages/project-client/src/services/channels/models/channel.ts index 1d85ea00c..046e032cf 100644 --- a/packages/project-client/src/services/channels/models/channels-channel-1.ts +++ b/packages/project-client/src/services/channels/models/channel.ts @@ -1,6 +1,6 @@ import { z } from 'zod'; -export enum ChannelsChannel1 { +export enum Channel { IN_APP = 'in_app', SLACK = 'slack', WEB_PUSH = 'web_push', diff --git a/packages/project-client/src/services/channels/models/channels-channel-2.ts b/packages/project-client/src/services/channels/models/channels-channel-2.ts deleted file mode 100644 index 05181fcaa..000000000 --- a/packages/project-client/src/services/channels/models/channels-channel-2.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { z } from 'zod'; - -export enum ChannelsChannel2 { - IN_APP = 'in_app', - SLACK = 'slack', - WEB_PUSH = 'web_push', - MOBILE_PUSH = 'mobile_push', - TEAMS = 'teams', - EMAIL = 'email', -} diff --git a/packages/user-client/src/services/channels/models/token-metadata.ts b/packages/project-client/src/services/channels/models/expo-token-response.ts similarity index 74% rename from packages/user-client/src/services/channels/models/token-metadata.ts rename to packages/project-client/src/services/channels/models/expo-token-response.ts index d1d75bf41..eca964da9 100644 --- a/packages/user-client/src/services/channels/models/token-metadata.ts +++ b/packages/project-client/src/services/channels/models/expo-token-response.ts @@ -3,9 +3,10 @@ import { z } from 'zod'; /** * The shape of the model inside the application code - what the users use */ -export const tokenMetadata = z.lazy(() => { +export const expoTokenResponse = z.lazy(() => { return z.object({ createdAt: z.string(), + deviceToken: z.string().min(1), discardedAt: z.string().optional().nullable(), id: z.string(), updatedAt: z.string().optional().nullable(), @@ -14,28 +15,31 @@ export const tokenMetadata = z.lazy(() => { /** * - * @typedef {TokenMetadata} tokenMetadata + * @typedef {ExpoTokenResponse} expoTokenResponse + * @property {string} * @property {string} * @property {string} * @property {string} * @property {string} */ -export type TokenMetadata = z.infer; +export type ExpoTokenResponse = z.infer; /** * The shape of the model mapping from the api schema into the application shape. * Is equal to application shape if all property names match the api schema */ -export const tokenMetadataResponse = z.lazy(() => { +export const expoTokenResponseResponse = z.lazy(() => { return z .object({ created_at: z.string(), + device_token: z.string().min(1), discarded_at: z.string().optional().nullable(), id: z.string(), updated_at: z.string().optional().nullable(), }) .transform((data) => ({ createdAt: data['created_at'], + deviceToken: data['device_token'], discardedAt: data['discarded_at'], id: data['id'], updatedAt: data['updated_at'], @@ -46,16 +50,18 @@ export const tokenMetadataResponse = z.lazy(() => { * The shape of the model mapping from the application shape into the api schema. * Is equal to application shape if all property names match the api schema */ -export const tokenMetadataRequest = z.lazy(() => { +export const expoTokenResponseRequest = z.lazy(() => { return z .object({ createdAt: z.string().nullish(), + deviceToken: z.string().nullish(), discardedAt: z.string().nullish(), id: z.string().nullish(), updatedAt: z.string().nullish(), }) .transform((data) => ({ created_at: data['createdAt'], + device_token: data['deviceToken'], discarded_at: data['discardedAt'], id: data['id'], updated_at: data['updatedAt'], diff --git a/packages/project-client/src/services/channels/models/fcm-token-installation-id.ts b/packages/project-client/src/services/channels/models/fcm-token-response-installation-id.ts similarity index 66% rename from packages/project-client/src/services/channels/models/fcm-token-installation-id.ts rename to packages/project-client/src/services/channels/models/fcm-token-response-installation-id.ts index cca08dfa5..fccf7993f 100644 --- a/packages/project-client/src/services/channels/models/fcm-token-installation-id.ts +++ b/packages/project-client/src/services/channels/models/fcm-token-response-installation-id.ts @@ -1,6 +1,6 @@ import { z } from 'zod'; -export enum FcmTokenInstallationId { +export enum FcmTokenResponseInstallationId { DEVELOPMENT = 'development', PRODUCTION = 'production', } diff --git a/packages/project-client/src/services/channels/models/fcm-token-response.ts b/packages/project-client/src/services/channels/models/fcm-token-response.ts new file mode 100644 index 000000000..47cf1cecf --- /dev/null +++ b/packages/project-client/src/services/channels/models/fcm-token-response.ts @@ -0,0 +1,75 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const fcmTokenResponse = z.lazy(() => { + return z.object({ + createdAt: z.string(), + deviceToken: z.string().min(64), + discardedAt: z.string().optional().nullable(), + id: z.string(), + installationId: z.string().optional(), + updatedAt: z.string().optional().nullable(), + }); +}); + +/** + * + * @typedef {FcmTokenResponse} fcmTokenResponse + * @property {string} + * @property {string} + * @property {string} + * @property {string} + * @property {FcmTokenResponseInstallationId} + * @property {string} + */ +export type FcmTokenResponse = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const fcmTokenResponseResponse = z.lazy(() => { + return z + .object({ + created_at: z.string(), + device_token: z.string().min(64), + discarded_at: z.string().optional().nullable(), + id: z.string(), + installation_id: z.string().optional(), + updated_at: z.string().optional().nullable(), + }) + .transform((data) => ({ + createdAt: data['created_at'], + deviceToken: data['device_token'], + discardedAt: data['discarded_at'], + id: data['id'], + installationId: data['installation_id'], + updatedAt: data['updated_at'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const fcmTokenResponseRequest = z.lazy(() => { + return z + .object({ + createdAt: z.string().nullish(), + deviceToken: z.string().nullish(), + discardedAt: z.string().nullish(), + id: z.string().nullish(), + installationId: z.string().nullish(), + updatedAt: z.string().nullish(), + }) + .transform((data) => ({ + created_at: data['createdAt'], + device_token: data['deviceToken'], + discarded_at: data['discardedAt'], + id: data['id'], + installation_id: data['installationId'], + updated_at: data['updatedAt'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/fcm-token.ts b/packages/project-client/src/services/channels/models/fcm-token.ts deleted file mode 100644 index 8b9052d1a..000000000 --- a/packages/project-client/src/services/channels/models/fcm-token.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { z } from 'zod'; - -/** - * The shape of the model inside the application code - what the users use - */ -export const fcmToken = z.lazy(() => { - return z.object({ - deviceToken: z.string().min(64), - installationId: z.string().optional(), - }); -}); - -/** - * - * @typedef {FcmToken} fcmToken - * @property {string} - * @property {FcmTokenInstallationId} - */ -export type FcmToken = z.infer; - -/** - * The shape of the model mapping from the api schema into the application shape. - * Is equal to application shape if all property names match the api schema - */ -export const fcmTokenResponse = z.lazy(() => { - return z - .object({ - device_token: z.string().min(64), - installation_id: z.string().optional(), - }) - .transform((data) => ({ - deviceToken: data['device_token'], - installationId: data['installation_id'], - })); -}); - -/** - * The shape of the model mapping from the application shape into the api schema. - * Is equal to application shape if all property names match the api schema - */ -export const fcmTokenRequest = z.lazy(() => { - return z.object({ deviceToken: z.string().nullish(), installationId: z.string().nullish() }).transform((data) => ({ - device_token: data['deviceToken'], - installation_id: data['installationId'], - })); -}); diff --git a/packages/project-client/src/services/channels/models/index.ts b/packages/project-client/src/services/channels/models/index.ts index 0413abdf5..6118b985a 100644 --- a/packages/project-client/src/services/channels/models/index.ts +++ b/packages/project-client/src/services/channels/models/index.ts @@ -1,32 +1,22 @@ -export type { ApnsToken } from './apns-token.js'; -export { ApnsTokenInstallationId } from './apns-token-installation-id.js'; -export type { ArrayOfMetadataApnsTokens } from './array-of-metadata-apns-tokens.js'; -export type { ArrayOfMetadataExpoTokens } from './array-of-metadata-expo-tokens.js'; -export type { ArrayOfMetadataFcmTokens } from './array-of-metadata-fcm-tokens.js'; -export type { ArrayOfMetadataSlackTokens } from './array-of-metadata-slack-tokens.js'; -export type { ArrayOfMetadataTeamsTokens } from './array-of-metadata-teams-tokens.js'; -export type { ArrayOfMetadataWebPushTokens } from './array-of-metadata-web-push-tokens.js'; +export type { ApnsTokenResponse } from './apns-token-response.js'; +export { ApnsTokenResponseInstallationId } from './apns-token-response-installation-id.js'; +export type { ArrayOfApnsTokenResponses } from './array-of-apns-token-responses.js'; +export type { ArrayOfExpoTokenResponses } from './array-of-expo-token-responses.js'; +export type { ArrayOfFcmTokenResponses } from './array-of-fcm-token-responses.js'; +export type { ArrayOfSlackTokenResponses } from './array-of-slack-token-responses.js'; +export type { ArrayOfTeamsTokenResponses } from './array-of-teams-token-responses.js'; +export type { ArrayOfWebPushTokenResponses } from './array-of-web-push-token-responses.js'; export type { CategoryDeliveryConfig } from './category-delivery-config.js'; export type { CategoryDeliveryConfigChannels } from './category-delivery-config-channels.js'; -export { ChannelsChannel1 } from './channels-channel-1.js'; -export { ChannelsChannel2 } from './channels-channel-2.js'; +export { Channel } from './channel.js'; export type { DiscardResult } from './discard-result.js'; -export type { ExpoToken } from './expo-token.js'; -export type { FcmToken } from './fcm-token.js'; -export { FcmTokenInstallationId } from './fcm-token-installation-id.js'; +export type { ExpoTokenResponse } from './expo-token-response.js'; +export type { FcmTokenResponse } from './fcm-token-response.js'; +export { FcmTokenResponseInstallationId } from './fcm-token-response-installation-id.js'; export type { Keys } from './keys.js'; -export type { MetadataApnsToken } from './metadata-apns-token.js'; -export type { MetadataExpoToken } from './metadata-expo-token.js'; -export type { MetadataFcmToken } from './metadata-fcm-token.js'; -export type { MetadataSlackToken } from './metadata-slack-token.js'; -export type { MetadataTeamsToken } from './metadata-teams-token.js'; -export type { MetadataWebPushToken } from './metadata-web-push-token.js'; export type { Oauth } from './oauth.js'; -export type { ProjectDeliveryConfig } from './project-delivery-config.js'; -export type { ProjectDeliveryConfigChannels } from './project-delivery-config-channels.js'; -export type { SlackToken } from './slack-token.js'; -export type { SlackTokenWebhook } from './slack-token-webhook.js'; -export type { TeamsToken } from './teams-token.js'; -export type { TeamsTokenWebhook } from './teams-token-webhook.js'; -export type { TokenMetadata } from './token-metadata.js'; -export type { WebPushToken } from './web-push-token.js'; +export type { SlackTokenResponse } from './slack-token-response.js'; +export type { SlackTokenResponseWebhook } from './slack-token-response-webhook.js'; +export type { TeamsTokenResponse } from './teams-token-response.js'; +export type { TeamsTokenResponseWebhook } from './teams-token-response-webhook.js'; +export type { WebPushTokenResponse } from './web-push-token-response.js'; diff --git a/packages/project-client/src/services/channels/models/metadata-apns-token.ts b/packages/project-client/src/services/channels/models/metadata-apns-token.ts deleted file mode 100644 index 996fa6e8a..000000000 --- a/packages/project-client/src/services/channels/models/metadata-apns-token.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { z } from 'zod'; - -import { apnsToken, apnsTokenRequest, apnsTokenResponse } from './apns-token.js'; -import { tokenMetadata, tokenMetadataRequest, tokenMetadataResponse } from './token-metadata.js'; - -/** - * The shape of the model inside the application code - what the users use - */ -export const metadataApnsToken = z.lazy(() => { - return z.object({ - data: apnsToken, - metadata: tokenMetadata, - }); -}); - -/** - * - * @typedef {MetadataApnsToken} metadataApnsToken - * @property {ApnsToken} - * @property {TokenMetadata} - */ -export type MetadataApnsToken = z.infer; - -/** - * The shape of the model mapping from the api schema into the application shape. - * Is equal to application shape if all property names match the api schema - */ -export const metadataApnsTokenResponse = z.lazy(() => { - return z - .object({ - data: apnsTokenResponse, - metadata: tokenMetadataResponse, - }) - .transform((data) => ({ - data: data['data'], - metadata: data['metadata'], - })); -}); - -/** - * The shape of the model mapping from the application shape into the api schema. - * Is equal to application shape if all property names match the api schema - */ -export const metadataApnsTokenRequest = z.lazy(() => { - return z.object({ data: apnsTokenRequest.nullish(), metadata: tokenMetadataRequest.nullish() }).transform((data) => ({ - data: data['data'], - metadata: data['metadata'], - })); -}); diff --git a/packages/project-client/src/services/channels/models/metadata-expo-token.ts b/packages/project-client/src/services/channels/models/metadata-expo-token.ts deleted file mode 100644 index 970186972..000000000 --- a/packages/project-client/src/services/channels/models/metadata-expo-token.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { z } from 'zod'; - -import { expoToken, expoTokenRequest, expoTokenResponse } from './expo-token.js'; -import { tokenMetadata, tokenMetadataRequest, tokenMetadataResponse } from './token-metadata.js'; - -/** - * The shape of the model inside the application code - what the users use - */ -export const metadataExpoToken = z.lazy(() => { - return z.object({ - data: expoToken, - metadata: tokenMetadata, - }); -}); - -/** - * - * @typedef {MetadataExpoToken} metadataExpoToken - * @property {ExpoToken} - * @property {TokenMetadata} - */ -export type MetadataExpoToken = z.infer; - -/** - * The shape of the model mapping from the api schema into the application shape. - * Is equal to application shape if all property names match the api schema - */ -export const metadataExpoTokenResponse = z.lazy(() => { - return z - .object({ - data: expoTokenResponse, - metadata: tokenMetadataResponse, - }) - .transform((data) => ({ - data: data['data'], - metadata: data['metadata'], - })); -}); - -/** - * The shape of the model mapping from the application shape into the api schema. - * Is equal to application shape if all property names match the api schema - */ -export const metadataExpoTokenRequest = z.lazy(() => { - return z.object({ data: expoTokenRequest.nullish(), metadata: tokenMetadataRequest.nullish() }).transform((data) => ({ - data: data['data'], - metadata: data['metadata'], - })); -}); diff --git a/packages/project-client/src/services/channels/models/metadata-fcm-token.ts b/packages/project-client/src/services/channels/models/metadata-fcm-token.ts deleted file mode 100644 index c546ba661..000000000 --- a/packages/project-client/src/services/channels/models/metadata-fcm-token.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { z } from 'zod'; - -import { fcmToken, fcmTokenRequest, fcmTokenResponse } from './fcm-token.js'; -import { tokenMetadata, tokenMetadataRequest, tokenMetadataResponse } from './token-metadata.js'; - -/** - * The shape of the model inside the application code - what the users use - */ -export const metadataFcmToken = z.lazy(() => { - return z.object({ - data: fcmToken, - metadata: tokenMetadata, - }); -}); - -/** - * - * @typedef {MetadataFcmToken} metadataFcmToken - * @property {FcmToken} - * @property {TokenMetadata} - */ -export type MetadataFcmToken = z.infer; - -/** - * The shape of the model mapping from the api schema into the application shape. - * Is equal to application shape if all property names match the api schema - */ -export const metadataFcmTokenResponse = z.lazy(() => { - return z - .object({ - data: fcmTokenResponse, - metadata: tokenMetadataResponse, - }) - .transform((data) => ({ - data: data['data'], - metadata: data['metadata'], - })); -}); - -/** - * The shape of the model mapping from the application shape into the api schema. - * Is equal to application shape if all property names match the api schema - */ -export const metadataFcmTokenRequest = z.lazy(() => { - return z.object({ data: fcmTokenRequest.nullish(), metadata: tokenMetadataRequest.nullish() }).transform((data) => ({ - data: data['data'], - metadata: data['metadata'], - })); -}); diff --git a/packages/project-client/src/services/channels/models/metadata-slack-token.ts b/packages/project-client/src/services/channels/models/metadata-slack-token.ts deleted file mode 100644 index 48cffd8e3..000000000 --- a/packages/project-client/src/services/channels/models/metadata-slack-token.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { z } from 'zod'; - -import { slackToken, slackTokenRequest, slackTokenResponse } from './slack-token.js'; -import { tokenMetadata, tokenMetadataRequest, tokenMetadataResponse } from './token-metadata.js'; - -/** - * The shape of the model inside the application code - what the users use - */ -export const metadataSlackToken = z.lazy(() => { - return z.object({ - data: slackToken, - metadata: tokenMetadata, - }); -}); - -/** - * - * @typedef {MetadataSlackToken} metadataSlackToken - * @property {SlackToken} - * @property {TokenMetadata} - */ -export type MetadataSlackToken = z.infer; - -/** - * The shape of the model mapping from the api schema into the application shape. - * Is equal to application shape if all property names match the api schema - */ -export const metadataSlackTokenResponse = z.lazy(() => { - return z - .object({ - data: slackTokenResponse, - metadata: tokenMetadataResponse, - }) - .transform((data) => ({ - data: data['data'], - metadata: data['metadata'], - })); -}); - -/** - * The shape of the model mapping from the application shape into the api schema. - * Is equal to application shape if all property names match the api schema - */ -export const metadataSlackTokenRequest = z.lazy(() => { - return z - .object({ data: slackTokenRequest.nullish(), metadata: tokenMetadataRequest.nullish() }) - .transform((data) => ({ - data: data['data'], - metadata: data['metadata'], - })); -}); diff --git a/packages/project-client/src/services/channels/models/metadata-teams-token.ts b/packages/project-client/src/services/channels/models/metadata-teams-token.ts deleted file mode 100644 index a766297d1..000000000 --- a/packages/project-client/src/services/channels/models/metadata-teams-token.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { z } from 'zod'; - -import { teamsToken, teamsTokenRequest, teamsTokenResponse } from './teams-token.js'; -import { tokenMetadata, tokenMetadataRequest, tokenMetadataResponse } from './token-metadata.js'; - -/** - * The shape of the model inside the application code - what the users use - */ -export const metadataTeamsToken = z.lazy(() => { - return z.object({ - data: teamsToken, - metadata: tokenMetadata, - }); -}); - -/** - * - * @typedef {MetadataTeamsToken} metadataTeamsToken - * @property {TeamsToken} - * @property {TokenMetadata} - */ -export type MetadataTeamsToken = z.infer; - -/** - * The shape of the model mapping from the api schema into the application shape. - * Is equal to application shape if all property names match the api schema - */ -export const metadataTeamsTokenResponse = z.lazy(() => { - return z - .object({ - data: teamsTokenResponse, - metadata: tokenMetadataResponse, - }) - .transform((data) => ({ - data: data['data'], - metadata: data['metadata'], - })); -}); - -/** - * The shape of the model mapping from the application shape into the api schema. - * Is equal to application shape if all property names match the api schema - */ -export const metadataTeamsTokenRequest = z.lazy(() => { - return z - .object({ data: teamsTokenRequest.nullish(), metadata: tokenMetadataRequest.nullish() }) - .transform((data) => ({ - data: data['data'], - metadata: data['metadata'], - })); -}); diff --git a/packages/project-client/src/services/channels/models/metadata-web-push-token.ts b/packages/project-client/src/services/channels/models/metadata-web-push-token.ts deleted file mode 100644 index 168754a35..000000000 --- a/packages/project-client/src/services/channels/models/metadata-web-push-token.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { z } from 'zod'; - -import { tokenMetadata, tokenMetadataRequest, tokenMetadataResponse } from './token-metadata.js'; -import { webPushToken, webPushTokenRequest, webPushTokenResponse } from './web-push-token.js'; - -/** - * The shape of the model inside the application code - what the users use - */ -export const metadataWebPushToken = z.lazy(() => { - return z.object({ - data: webPushToken, - metadata: tokenMetadata, - }); -}); - -/** - * - * @typedef {MetadataWebPushToken} metadataWebPushToken - * @property {WebPushToken} - * @property {TokenMetadata} - */ -export type MetadataWebPushToken = z.infer; - -/** - * The shape of the model mapping from the api schema into the application shape. - * Is equal to application shape if all property names match the api schema - */ -export const metadataWebPushTokenResponse = z.lazy(() => { - return z - .object({ - data: webPushTokenResponse, - metadata: tokenMetadataResponse, - }) - .transform((data) => ({ - data: data['data'], - metadata: data['metadata'], - })); -}); - -/** - * The shape of the model mapping from the application shape into the api schema. - * Is equal to application shape if all property names match the api schema - */ -export const metadataWebPushTokenRequest = z.lazy(() => { - return z - .object({ data: webPushTokenRequest.nullish(), metadata: tokenMetadataRequest.nullish() }) - .transform((data) => ({ - data: data['data'], - metadata: data['metadata'], - })); -}); diff --git a/packages/project-client/src/services/channels/models/project-delivery-config-channels.ts b/packages/project-client/src/services/channels/models/project-delivery-config-channels.ts deleted file mode 100644 index f71c4a93e..000000000 --- a/packages/project-client/src/services/channels/models/project-delivery-config-channels.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { z } from 'zod'; - -/** - * The shape of the model inside the application code - what the users use - */ -export const projectDeliveryConfigChannels = z.lazy(() => { - return z.object({ - channel: z.string(), - delay: z.number().gte(0).optional(), - disabled: z.boolean().optional(), - if: z.string().optional(), - priority: z.number().gte(0).optional(), - }); -}); - -/** - * - * @typedef {ProjectDeliveryConfigChannels} projectDeliveryConfigChannels - * @property {ChannelsChannel1} - * @property {number} - Delay (in seconds) since the last step, before the message is sent to the channel - * @property {boolean} - * @property {string} - * @property {number} - */ -export type ProjectDeliveryConfigChannels = z.infer; - -/** - * The shape of the model mapping from the api schema into the application shape. - * Is equal to application shape if all property names match the api schema - */ -export const projectDeliveryConfigChannelsResponse = z.lazy(() => { - return z - .object({ - channel: z.string(), - delay: z.number().gte(0).optional(), - disabled: z.boolean().optional(), - if: z.string().optional(), - priority: z.number().gte(0).optional(), - }) - .transform((data) => ({ - channel: data['channel'], - delay: data['delay'], - disabled: data['disabled'], - if: data['if'], - priority: data['priority'], - })); -}); - -/** - * The shape of the model mapping from the application shape into the api schema. - * Is equal to application shape if all property names match the api schema - */ -export const projectDeliveryConfigChannelsRequest = z.lazy(() => { - return z - .object({ - channel: z.string().nullish(), - delay: z.number().nullish(), - disabled: z.boolean().nullish(), - if: z.string().nullish(), - priority: z.number().nullish(), - }) - .transform((data) => ({ - channel: data['channel'], - delay: data['delay'], - disabled: data['disabled'], - if: data['if'], - priority: data['priority'], - })); -}); diff --git a/packages/project-client/src/services/channels/models/project-delivery-config.ts b/packages/project-client/src/services/channels/models/project-delivery-config.ts deleted file mode 100644 index cbc9edd97..000000000 --- a/packages/project-client/src/services/channels/models/project-delivery-config.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { z } from 'zod'; - -import { - projectDeliveryConfigChannels, - projectDeliveryConfigChannelsRequest, - projectDeliveryConfigChannelsResponse, -} from './project-delivery-config-channels.js'; - -/** - * The shape of the model inside the application code - what the users use - */ -export const projectDeliveryConfig = z.lazy(() => { - return z.object({ - channels: z.array(projectDeliveryConfigChannels), - }); -}); - -/** - * - * @typedef {ProjectDeliveryConfig} projectDeliveryConfig - * @property {ProjectDeliveryConfigChannels[]} - */ -export type ProjectDeliveryConfig = z.infer; - -/** - * The shape of the model mapping from the api schema into the application shape. - * Is equal to application shape if all property names match the api schema - */ -export const projectDeliveryConfigResponse = z.lazy(() => { - return z - .object({ - channels: z.array(projectDeliveryConfigChannelsResponse), - }) - .transform((data) => ({ - channels: data['channels'], - })); -}); - -/** - * The shape of the model mapping from the application shape into the api schema. - * Is equal to application shape if all property names match the api schema - */ -export const projectDeliveryConfigRequest = z.lazy(() => { - return z.object({ channels: z.array(projectDeliveryConfigChannelsRequest).nullish() }).transform((data) => ({ - channels: data['channels'], - })); -}); diff --git a/packages/project-client/src/services/channels/models/slack-token-webhook.ts b/packages/project-client/src/services/channels/models/slack-token-response-webhook.ts similarity index 69% rename from packages/project-client/src/services/channels/models/slack-token-webhook.ts rename to packages/project-client/src/services/channels/models/slack-token-response-webhook.ts index 58eca4147..18d28b481 100644 --- a/packages/project-client/src/services/channels/models/slack-token-webhook.ts +++ b/packages/project-client/src/services/channels/models/slack-token-response-webhook.ts @@ -3,7 +3,7 @@ import { z } from 'zod'; /** * The shape of the model inside the application code - what the users use */ -export const slackTokenWebhook = z.lazy(() => { +export const slackTokenResponseWebhook = z.lazy(() => { return z.object({ url: z.string().min(1), }); @@ -11,16 +11,16 @@ export const slackTokenWebhook = z.lazy(() => { /** * - * @typedef {SlackTokenWebhook} slackTokenWebhook + * @typedef {SlackTokenResponseWebhook} slackTokenResponseWebhook * @property {string} */ -export type SlackTokenWebhook = z.infer; +export type SlackTokenResponseWebhook = z.infer; /** * The shape of the model mapping from the api schema into the application shape. * Is equal to application shape if all property names match the api schema */ -export const slackTokenWebhookResponse = z.lazy(() => { +export const slackTokenResponseWebhookResponse = z.lazy(() => { return z .object({ url: z.string().min(1), @@ -34,7 +34,7 @@ export const slackTokenWebhookResponse = z.lazy(() => { * The shape of the model mapping from the application shape into the api schema. * Is equal to application shape if all property names match the api schema */ -export const slackTokenWebhookRequest = z.lazy(() => { +export const slackTokenResponseWebhookRequest = z.lazy(() => { return z.object({ url: z.string().nullish() }).transform((data) => ({ url: data['url'], })); diff --git a/packages/project-client/src/services/channels/models/slack-token-response.ts b/packages/project-client/src/services/channels/models/slack-token-response.ts new file mode 100644 index 000000000..27fc3a951 --- /dev/null +++ b/packages/project-client/src/services/channels/models/slack-token-response.ts @@ -0,0 +1,82 @@ +import { z } from 'zod'; + +import { oauth, oauthRequest, oauthResponse } from './oauth.js'; +import { + slackTokenResponseWebhook, + slackTokenResponseWebhookRequest, + slackTokenResponseWebhookResponse, +} from './slack-token-response-webhook.js'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const slackTokenResponse = z.lazy(() => { + return z.object({ + createdAt: z.string(), + discardedAt: z.string().optional().nullable(), + id: z.string(), + oauth: oauth.optional(), + updatedAt: z.string().optional().nullable(), + webhook: slackTokenResponseWebhook.optional(), + }); +}); + +/** + * + * @typedef {SlackTokenResponse} slackTokenResponse + * @property {string} + * @property {string} + * @property {string} + * @property {Oauth} + * @property {string} + * @property {SlackTokenResponseWebhook} + */ +export type SlackTokenResponse = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const slackTokenResponseResponse = z.lazy(() => { + return z + .object({ + created_at: z.string(), + discarded_at: z.string().optional().nullable(), + id: z.string(), + oauth: oauthResponse.optional(), + updated_at: z.string().optional().nullable(), + webhook: slackTokenResponseWebhookResponse.optional(), + }) + .transform((data) => ({ + createdAt: data['created_at'], + discardedAt: data['discarded_at'], + id: data['id'], + oauth: data['oauth'], + updatedAt: data['updated_at'], + webhook: data['webhook'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const slackTokenResponseRequest = z.lazy(() => { + return z + .object({ + createdAt: z.string().nullish(), + discardedAt: z.string().nullish(), + id: z.string().nullish(), + oauth: oauthRequest.nullish(), + updatedAt: z.string().nullish(), + webhook: slackTokenResponseWebhookRequest.nullish(), + }) + .transform((data) => ({ + created_at: data['createdAt'], + discarded_at: data['discardedAt'], + id: data['id'], + oauth: data['oauth'], + updated_at: data['updatedAt'], + webhook: data['webhook'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/slack-token.ts b/packages/project-client/src/services/channels/models/slack-token.ts deleted file mode 100644 index 1a9bf6236..000000000 --- a/packages/project-client/src/services/channels/models/slack-token.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { z } from 'zod'; - -import { oauth, oauthRequest, oauthResponse } from './oauth.js'; -import { slackTokenWebhook, slackTokenWebhookRequest, slackTokenWebhookResponse } from './slack-token-webhook.js'; - -/** - * The shape of the model inside the application code - what the users use - */ -export const slackToken = z.lazy(() => { - return z.object({ - oauth: oauth.optional(), - webhook: slackTokenWebhook.optional(), - }); -}); - -/** - * - * @typedef {SlackToken} slackToken - * @property {Oauth} - * @property {SlackTokenWebhook} - */ -export type SlackToken = z.infer; - -/** - * The shape of the model mapping from the api schema into the application shape. - * Is equal to application shape if all property names match the api schema - */ -export const slackTokenResponse = z.lazy(() => { - return z - .object({ - oauth: oauthResponse.optional(), - webhook: slackTokenWebhookResponse.optional(), - }) - .transform((data) => ({ - oauth: data['oauth'], - webhook: data['webhook'], - })); -}); - -/** - * The shape of the model mapping from the application shape into the api schema. - * Is equal to application shape if all property names match the api schema - */ -export const slackTokenRequest = z.lazy(() => { - return z.object({ oauth: oauthRequest.nullish(), webhook: slackTokenWebhookRequest.nullish() }).transform((data) => ({ - oauth: data['oauth'], - webhook: data['webhook'], - })); -}); diff --git a/packages/project-client/src/services/channels/models/teams-token-webhook.ts b/packages/project-client/src/services/channels/models/teams-token-response-webhook.ts similarity index 69% rename from packages/project-client/src/services/channels/models/teams-token-webhook.ts rename to packages/project-client/src/services/channels/models/teams-token-response-webhook.ts index 95121613d..70dd62c5a 100644 --- a/packages/project-client/src/services/channels/models/teams-token-webhook.ts +++ b/packages/project-client/src/services/channels/models/teams-token-response-webhook.ts @@ -3,7 +3,7 @@ import { z } from 'zod'; /** * The shape of the model inside the application code - what the users use */ -export const teamsTokenWebhook = z.lazy(() => { +export const teamsTokenResponseWebhook = z.lazy(() => { return z.object({ url: z.string().optional(), }); @@ -11,16 +11,16 @@ export const teamsTokenWebhook = z.lazy(() => { /** * - * @typedef {TeamsTokenWebhook} teamsTokenWebhook + * @typedef {TeamsTokenResponseWebhook} teamsTokenResponseWebhook * @property {string} */ -export type TeamsTokenWebhook = z.infer; +export type TeamsTokenResponseWebhook = z.infer; /** * The shape of the model mapping from the api schema into the application shape. * Is equal to application shape if all property names match the api schema */ -export const teamsTokenWebhookResponse = z.lazy(() => { +export const teamsTokenResponseWebhookResponse = z.lazy(() => { return z .object({ url: z.string().optional(), @@ -34,7 +34,7 @@ export const teamsTokenWebhookResponse = z.lazy(() => { * The shape of the model mapping from the application shape into the api schema. * Is equal to application shape if all property names match the api schema */ -export const teamsTokenWebhookRequest = z.lazy(() => { +export const teamsTokenResponseWebhookRequest = z.lazy(() => { return z.object({ url: z.string().nullish() }).transform((data) => ({ url: data['url'], })); diff --git a/packages/project-client/src/services/channels/models/teams-token-response.ts b/packages/project-client/src/services/channels/models/teams-token-response.ts new file mode 100644 index 000000000..9d2978d8b --- /dev/null +++ b/packages/project-client/src/services/channels/models/teams-token-response.ts @@ -0,0 +1,75 @@ +import { z } from 'zod'; + +import { + teamsTokenResponseWebhook, + teamsTokenResponseWebhookRequest, + teamsTokenResponseWebhookResponse, +} from './teams-token-response-webhook.js'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const teamsTokenResponse = z.lazy(() => { + return z.object({ + createdAt: z.string(), + discardedAt: z.string().optional().nullable(), + id: z.string(), + updatedAt: z.string().optional().nullable(), + webhook: teamsTokenResponseWebhook.optional(), + }); +}); + +/** + * + * @typedef {TeamsTokenResponse} teamsTokenResponse + * @property {string} + * @property {string} + * @property {string} + * @property {string} + * @property {TeamsTokenResponseWebhook} + */ +export type TeamsTokenResponse = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const teamsTokenResponseResponse = z.lazy(() => { + return z + .object({ + created_at: z.string(), + discarded_at: z.string().optional().nullable(), + id: z.string(), + updated_at: z.string().optional().nullable(), + webhook: teamsTokenResponseWebhookResponse.optional(), + }) + .transform((data) => ({ + createdAt: data['created_at'], + discardedAt: data['discarded_at'], + id: data['id'], + updatedAt: data['updated_at'], + webhook: data['webhook'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const teamsTokenResponseRequest = z.lazy(() => { + return z + .object({ + createdAt: z.string().nullish(), + discardedAt: z.string().nullish(), + id: z.string().nullish(), + updatedAt: z.string().nullish(), + webhook: teamsTokenResponseWebhookRequest.nullish(), + }) + .transform((data) => ({ + created_at: data['createdAt'], + discarded_at: data['discardedAt'], + id: data['id'], + updated_at: data['updatedAt'], + webhook: data['webhook'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/teams-token.ts b/packages/project-client/src/services/channels/models/teams-token.ts deleted file mode 100644 index abadd2940..000000000 --- a/packages/project-client/src/services/channels/models/teams-token.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { z } from 'zod'; - -import { teamsTokenWebhook, teamsTokenWebhookRequest, teamsTokenWebhookResponse } from './teams-token-webhook.js'; - -/** - * The shape of the model inside the application code - what the users use - */ -export const teamsToken = z.lazy(() => { - return z.object({ - webhook: teamsTokenWebhook.optional(), - }); -}); - -/** - * - * @typedef {TeamsToken} teamsToken - * @property {TeamsTokenWebhook} - */ -export type TeamsToken = z.infer; - -/** - * The shape of the model mapping from the api schema into the application shape. - * Is equal to application shape if all property names match the api schema - */ -export const teamsTokenResponse = z.lazy(() => { - return z - .object({ - webhook: teamsTokenWebhookResponse.optional(), - }) - .transform((data) => ({ - webhook: data['webhook'], - })); -}); - -/** - * The shape of the model mapping from the application shape into the api schema. - * Is equal to application shape if all property names match the api schema - */ -export const teamsTokenRequest = z.lazy(() => { - return z.object({ webhook: teamsTokenWebhookRequest.nullish() }).transform((data) => ({ - webhook: data['webhook'], - })); -}); diff --git a/packages/project-client/src/services/channels/models/web-push-token-response.ts b/packages/project-client/src/services/channels/models/web-push-token-response.ts new file mode 100644 index 000000000..44909bc22 --- /dev/null +++ b/packages/project-client/src/services/channels/models/web-push-token-response.ts @@ -0,0 +1,77 @@ +import { z } from 'zod'; + +import { keys, keysRequest, keysResponse } from './keys.js'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const webPushTokenResponse = z.lazy(() => { + return z.object({ + createdAt: z.string(), + discardedAt: z.string().optional().nullable(), + endpoint: z.string(), + id: z.string(), + keys: keys, + updatedAt: z.string().optional().nullable(), + }); +}); + +/** + * + * @typedef {WebPushTokenResponse} webPushTokenResponse + * @property {string} + * @property {string} + * @property {string} + * @property {string} + * @property {Keys} + * @property {string} + */ +export type WebPushTokenResponse = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const webPushTokenResponseResponse = z.lazy(() => { + return z + .object({ + created_at: z.string(), + discarded_at: z.string().optional().nullable(), + endpoint: z.string(), + id: z.string(), + keys: keysResponse, + updated_at: z.string().optional().nullable(), + }) + .transform((data) => ({ + createdAt: data['created_at'], + discardedAt: data['discarded_at'], + endpoint: data['endpoint'], + id: data['id'], + keys: data['keys'], + updatedAt: data['updated_at'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const webPushTokenResponseRequest = z.lazy(() => { + return z + .object({ + createdAt: z.string().nullish(), + discardedAt: z.string().nullish(), + endpoint: z.string().nullish(), + id: z.string().nullish(), + keys: keysRequest.nullish(), + updatedAt: z.string().nullish(), + }) + .transform((data) => ({ + created_at: data['createdAt'], + discarded_at: data['discardedAt'], + endpoint: data['endpoint'], + id: data['id'], + keys: data['keys'], + updated_at: data['updatedAt'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/web-push-token.ts b/packages/project-client/src/services/channels/models/web-push-token.ts deleted file mode 100644 index 38ac7d1cc..000000000 --- a/packages/project-client/src/services/channels/models/web-push-token.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { z } from 'zod'; - -import { keys, keysRequest, keysResponse } from './keys.js'; - -/** - * The shape of the model inside the application code - what the users use - */ -export const webPushToken = z.lazy(() => { - return z.object({ - endpoint: z.string(), - keys: keys, - }); -}); - -/** - * - * @typedef {WebPushToken} webPushToken - * @property {string} - * @property {Keys} - */ -export type WebPushToken = z.infer; - -/** - * The shape of the model mapping from the api schema into the application shape. - * Is equal to application shape if all property names match the api schema - */ -export const webPushTokenResponse = z.lazy(() => { - return z - .object({ - endpoint: z.string(), - keys: keysResponse, - }) - .transform((data) => ({ - endpoint: data['endpoint'], - keys: data['keys'], - })); -}); - -/** - * The shape of the model mapping from the application shape into the api schema. - * Is equal to application shape if all property names match the api schema - */ -export const webPushTokenRequest = z.lazy(() => { - return z.object({ endpoint: z.string().nullish(), keys: keysRequest.nullish() }).transform((data) => ({ - endpoint: data['endpoint'], - keys: data['keys'], - })); -}); diff --git a/packages/project-client/src/services/channels/request-params.ts b/packages/project-client/src/services/channels/request-params.ts index 6a4259f14..6ed4af1f7 100644 --- a/packages/project-client/src/services/channels/request-params.ts +++ b/packages/project-client/src/services/channels/request-params.ts @@ -1,3 +1,7 @@ +export interface GetDeliveryconfigParams { + key?: string; +} + export interface GetMobilePushApnsUserTokensParams { pageSize?: number; pageAfter?: string; diff --git a/packages/project-client/src/services/events/events.ts b/packages/project-client/src/services/events/events.ts index 9a198fb35..3a0edaae4 100644 --- a/packages/project-client/src/services/events/events.ts +++ b/packages/project-client/src/services/events/events.ts @@ -16,15 +16,18 @@ export class EventsService extends BaseService { * @returns {Promise>} OK */ async getEvents(params?: GetEventsParams, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/events') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfEventsResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfEventsResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) diff --git a/packages/project-client/src/services/integrations/integrations.ts b/packages/project-client/src/services/integrations/integrations.ts index 7dedb6cdb..f8a89525a 100644 --- a/packages/project-client/src/services/integrations/integrations.ts +++ b/packages/project-client/src/services/integrations/integrations.ts @@ -78,15 +78,18 @@ export class IntegrationsService extends BaseService { params?: ListIntegrationsParams, requestConfig?: RequestConfig, ): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/integrations') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfIntegrationObjectsResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfIntegrationObjectsResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -111,15 +114,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async getApnsIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/integrations/apns') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfApnsConfigObjectsResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfApnsConfigObjectsResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -132,15 +138,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async saveApnsIntegration(body: ApnsConfig, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('PUT') .setPath('/integrations/apns') .setRequestSchema(apnsConfigRequest) - .setResponseSchema(apnsConfigResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: apnsConfigResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -154,21 +163,24 @@ export class IntegrationsService extends BaseService { * Removes a apns integration configuration from the project. This will disable the integration's functionality within the project. * @returns {Promise>} No Content */ - async deleteApnsIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteApnsIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/apns') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -176,16 +188,19 @@ export class IntegrationsService extends BaseService { * @param {string} id - * @returns {Promise>} No Content */ - async deleteApnsIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteApnsIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/apns/{id}') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -194,7 +209,7 @@ export class IntegrationsService extends BaseService { value: id, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -202,15 +217,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async getAwssnsIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/integrations/awssns') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfAwssnsConfigObjectsResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfAwssnsConfigObjectsResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -223,15 +241,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async saveAwssnsIntegration(body: AwssnsConfig, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('PUT') .setPath('/integrations/awssns') .setRequestSchema(awssnsConfigRequest) - .setResponseSchema(awssnsConfigResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: awssnsConfigResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -245,21 +266,24 @@ export class IntegrationsService extends BaseService { * Removes a awssns integration configuration from the project. This will disable the integration's functionality within the project. * @returns {Promise>} No Content */ - async deleteAwssnsIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteAwssnsIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/awssns') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -267,16 +291,19 @@ export class IntegrationsService extends BaseService { * @param {string} id - * @returns {Promise>} No Content */ - async deleteAwssnsIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteAwssnsIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/awssns/{id}') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -285,7 +312,7 @@ export class IntegrationsService extends BaseService { value: id, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -293,15 +320,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async getExpoIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/integrations/expo') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfExpoConfigObjectsResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfExpoConfigObjectsResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -314,15 +344,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async saveExpoIntegration(body: ExpoConfig, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('PUT') .setPath('/integrations/expo') .setRequestSchema(expoConfigRequest) - .setResponseSchema(expoConfigResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: expoConfigResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -336,21 +369,24 @@ export class IntegrationsService extends BaseService { * Removes a expo integration configuration from the project. This will disable the integration's functionality within the project. * @returns {Promise>} No Content */ - async deleteExpoIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteExpoIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/expo') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -358,16 +394,19 @@ export class IntegrationsService extends BaseService { * @param {string} id - * @returns {Promise>} No Content */ - async deleteExpoIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteExpoIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/expo/{id}') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -376,7 +415,7 @@ export class IntegrationsService extends BaseService { value: id, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -384,15 +423,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async getFcmIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/integrations/fcm') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfFcmConfigObjectsResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfFcmConfigObjectsResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -405,15 +447,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async saveFcmIntegration(body: FcmConfig, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('PUT') .setPath('/integrations/fcm') .setRequestSchema(fcmConfigRequest) - .setResponseSchema(fcmConfigResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: fcmConfigResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -427,21 +472,24 @@ export class IntegrationsService extends BaseService { * Removes a fcm integration configuration from the project. This will disable the integration's functionality within the project. * @returns {Promise>} No Content */ - async deleteFcmIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteFcmIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/fcm') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -449,16 +497,19 @@ export class IntegrationsService extends BaseService { * @param {string} id - * @returns {Promise>} No Content */ - async deleteFcmIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteFcmIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/fcm/{id}') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -467,7 +518,7 @@ export class IntegrationsService extends BaseService { value: id, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -475,15 +526,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async getGithubIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/integrations/github') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfGithubConfigObjectsResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfGithubConfigObjectsResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -496,15 +550,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async saveGithubIntegration(body: GithubConfig, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('PUT') .setPath('/integrations/github') .setRequestSchema(githubConfigRequest) - .setResponseSchema(githubConfigResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: githubConfigResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -518,21 +575,24 @@ export class IntegrationsService extends BaseService { * Removes a github integration configuration from the project. This will disable the integration's functionality within the project. * @returns {Promise>} No Content */ - async deleteGithubIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteGithubIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/github') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -540,16 +600,19 @@ export class IntegrationsService extends BaseService { * @param {string} id - * @returns {Promise>} No Content */ - async deleteGithubIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteGithubIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/github/{id}') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -558,7 +621,7 @@ export class IntegrationsService extends BaseService { value: id, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -566,15 +629,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async getInboxIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/integrations/inbox') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfInboxConfigObjectsResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfInboxConfigObjectsResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -587,15 +653,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async saveInboxIntegration(body: InboxConfig, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('PUT') .setPath('/integrations/inbox') .setRequestSchema(inboxConfigRequest) - .setResponseSchema(inboxConfigResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: inboxConfigResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -609,21 +678,24 @@ export class IntegrationsService extends BaseService { * Removes a inbox integration configuration from the project. This will disable the integration's functionality within the project. * @returns {Promise>} No Content */ - async deleteInboxIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteInboxIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/inbox') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -631,16 +703,19 @@ export class IntegrationsService extends BaseService { * @param {string} id - * @returns {Promise>} No Content */ - async deleteInboxIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteInboxIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/inbox/{id}') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -649,7 +724,7 @@ export class IntegrationsService extends BaseService { value: id, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -657,15 +732,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async getMailgunIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/integrations/mailgun') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfMailgunConfigObjectsResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfMailgunConfigObjectsResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -681,15 +759,18 @@ export class IntegrationsService extends BaseService { body: MailgunConfig, requestConfig?: RequestConfig, ): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('PUT') .setPath('/integrations/mailgun') .setRequestSchema(mailgunConfigRequest) - .setResponseSchema(mailgunConfigResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: mailgunConfigResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -703,21 +784,24 @@ export class IntegrationsService extends BaseService { * Removes a mailgun integration configuration from the project. This will disable the integration's functionality within the project. * @returns {Promise>} No Content */ - async deleteMailgunIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteMailgunIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/mailgun') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -725,16 +809,19 @@ export class IntegrationsService extends BaseService { * @param {string} id - * @returns {Promise>} No Content */ - async deleteMailgunIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteMailgunIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/mailgun/{id}') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -743,7 +830,7 @@ export class IntegrationsService extends BaseService { value: id, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -751,15 +838,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async getPingEmailIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/integrations/ping_email') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfPingConfigObjectsResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfPingConfigObjectsResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -772,15 +862,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async savePingEmailIntegration(body: PingConfig, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('PUT') .setPath('/integrations/ping_email') .setRequestSchema(pingConfigRequest) - .setResponseSchema(pingConfigResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: pingConfigResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -794,21 +887,24 @@ export class IntegrationsService extends BaseService { * Removes a ping_email integration configuration from the project. This will disable the integration's functionality within the project. * @returns {Promise>} No Content */ - async deletePingEmailIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deletePingEmailIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/ping_email') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -816,16 +912,19 @@ export class IntegrationsService extends BaseService { * @param {string} id - * @returns {Promise>} No Content */ - async deletePingEmailIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deletePingEmailIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/ping_email/{id}') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -834,7 +933,7 @@ export class IntegrationsService extends BaseService { value: id, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -842,15 +941,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async getSendgridIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/integrations/sendgrid') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfSendgridConfigObjectsResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfSendgridConfigObjectsResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -866,15 +968,18 @@ export class IntegrationsService extends BaseService { body: SendgridConfig, requestConfig?: RequestConfig, ): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('PUT') .setPath('/integrations/sendgrid') .setRequestSchema(sendgridConfigRequest) - .setResponseSchema(sendgridConfigResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: sendgridConfigResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -888,21 +993,24 @@ export class IntegrationsService extends BaseService { * Removes a sendgrid integration configuration from the project. This will disable the integration's functionality within the project. * @returns {Promise>} No Content */ - async deleteSendgridIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteSendgridIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/sendgrid') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -910,16 +1018,19 @@ export class IntegrationsService extends BaseService { * @param {string} id - * @returns {Promise>} No Content */ - async deleteSendgridIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteSendgridIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/sendgrid/{id}') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -928,7 +1039,7 @@ export class IntegrationsService extends BaseService { value: id, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -936,15 +1047,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async getSesIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/integrations/ses') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfSesConfigObjectsResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfSesConfigObjectsResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -957,15 +1071,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async saveSesIntegration(body: SesConfig, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('PUT') .setPath('/integrations/ses') .setRequestSchema(sesConfigRequest) - .setResponseSchema(sesConfigResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: sesConfigResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -979,21 +1096,24 @@ export class IntegrationsService extends BaseService { * Removes a ses integration configuration from the project. This will disable the integration's functionality within the project. * @returns {Promise>} No Content */ - async deleteSesIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteSesIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/ses') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -1001,16 +1121,19 @@ export class IntegrationsService extends BaseService { * @param {string} id - * @returns {Promise>} No Content */ - async deleteSesIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteSesIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/ses/{id}') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -1019,7 +1142,7 @@ export class IntegrationsService extends BaseService { value: id, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -1027,15 +1150,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async getSlackIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/integrations/slack') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfSlackConfigObjectsResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfSlackConfigObjectsResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -1048,15 +1174,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async saveSlackIntegration(body: SlackConfig, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('PUT') .setPath('/integrations/slack') .setRequestSchema(slackConfigRequest) - .setResponseSchema(slackConfigResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: slackConfigResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -1070,21 +1199,24 @@ export class IntegrationsService extends BaseService { * Removes a slack integration configuration from the project. This will disable the integration's functionality within the project. * @returns {Promise>} No Content */ - async deleteSlackIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteSlackIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/slack') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -1092,16 +1224,19 @@ export class IntegrationsService extends BaseService { * @param {string} id - * @returns {Promise>} No Content */ - async deleteSlackIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteSlackIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/slack/{id}') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -1110,7 +1245,7 @@ export class IntegrationsService extends BaseService { value: id, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -1118,15 +1253,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async getStripeIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/integrations/stripe') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfStripeConfigObjectsResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfStripeConfigObjectsResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -1139,15 +1277,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async saveStripeIntegration(body: StripeConfig, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('PUT') .setPath('/integrations/stripe') .setRequestSchema(stripeConfigRequest) - .setResponseSchema(stripeConfigResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: stripeConfigResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -1161,21 +1302,24 @@ export class IntegrationsService extends BaseService { * Removes a stripe integration configuration from the project. This will disable the integration's functionality within the project. * @returns {Promise>} No Content */ - async deleteStripeIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteStripeIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/stripe') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -1183,16 +1327,19 @@ export class IntegrationsService extends BaseService { * @param {string} id - * @returns {Promise>} No Content */ - async deleteStripeIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteStripeIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/stripe/{id}') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -1201,7 +1348,7 @@ export class IntegrationsService extends BaseService { value: id, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -1209,15 +1356,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async getTemplatesIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/integrations/templates') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfTemplatesConfigObjectsResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfTemplatesConfigObjectsResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -1230,15 +1380,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async saveTemplatesIntegration(body: any, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('PUT') .setPath('/integrations/templates') .setRequestSchema(z.any()) - .setResponseSchema(z.any()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.any(), + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -1252,21 +1405,24 @@ export class IntegrationsService extends BaseService { * Removes a templates integration configuration from the project. This will disable the integration's functionality within the project. * @returns {Promise>} No Content */ - async deleteTemplatesIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteTemplatesIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/templates') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -1274,16 +1430,19 @@ export class IntegrationsService extends BaseService { * @param {string} id - * @returns {Promise>} No Content */ - async deleteTemplatesIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteTemplatesIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/templates/{id}') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -1292,7 +1451,7 @@ export class IntegrationsService extends BaseService { value: id, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -1300,15 +1459,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async getTwilioIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/integrations/twilio') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfTwilioConfigObjectsResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfTwilioConfigObjectsResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -1321,15 +1483,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async saveTwilioIntegration(body: TwilioConfig, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('PUT') .setPath('/integrations/twilio') .setRequestSchema(twilioConfigRequest) - .setResponseSchema(twilioConfigResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: twilioConfigResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -1343,21 +1508,24 @@ export class IntegrationsService extends BaseService { * Removes a twilio integration configuration from the project. This will disable the integration's functionality within the project. * @returns {Promise>} No Content */ - async deleteTwilioIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteTwilioIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/twilio') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -1365,16 +1533,19 @@ export class IntegrationsService extends BaseService { * @param {string} id - * @returns {Promise>} No Content */ - async deleteTwilioIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteTwilioIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/twilio/{id}') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -1383,7 +1554,7 @@ export class IntegrationsService extends BaseService { value: id, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -1391,15 +1562,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} OK */ async getWebPushIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/integrations/web_push') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfWebpushConfigObjectsResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfWebpushConfigObjectsResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -1415,15 +1589,18 @@ export class IntegrationsService extends BaseService { body: WebpushConfig, requestConfig?: RequestConfig, ): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('PUT') .setPath('/integrations/web_push') .setRequestSchema(webpushConfigRequest) - .setResponseSchema(webpushConfigResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: webpushConfigResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -1437,21 +1614,24 @@ export class IntegrationsService extends BaseService { * Removes a web_push integration configuration from the project. This will disable the integration's functionality within the project. * @returns {Promise>} No Content */ - async deleteWebPushIntegration(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteWebPushIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/web_push') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -1459,16 +1639,19 @@ export class IntegrationsService extends BaseService { * @param {string} id - * @returns {Promise>} No Content */ - async deleteWebPushIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async deleteWebPushIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/integrations/web_push/{id}') .setRequestSchema(z.any()) - .setResponseSchema(z.undefined()) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: z.undefined(), + contentType: ContentType.NoContent, + status: 204, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -1477,6 +1660,6 @@ export class IntegrationsService extends BaseService { value: id, }) .build(); - return this.client.call(request); + return this.client.call(request); } } diff --git a/packages/project-client/src/services/integrations/models/ses-config.ts b/packages/project-client/src/services/integrations/models/ses-config.ts index efd40082c..bf6a83d37 100644 --- a/packages/project-client/src/services/integrations/models/ses-config.ts +++ b/packages/project-client/src/services/integrations/models/ses-config.ts @@ -7,7 +7,6 @@ import { sesConfigFrom, sesConfigFromRequest, sesConfigFromResponse } from './se */ export const sesConfig = z.lazy(() => { return z.object({ - endpoint: z.string().min(1).optional(), from: sesConfigFrom.optional(), keyId: z.string().min(1), region: z.string().min(1), @@ -18,7 +17,6 @@ export const sesConfig = z.lazy(() => { /** * * @typedef {SesConfig} sesConfig - * @property {string} - HTTP endpoint to send requests to (testing only) * @property {SesConfigFrom} * @property {string} - AWS Access Key ID * @property {string} - AWS Region @@ -33,14 +31,12 @@ export type SesConfig = z.infer; export const sesConfigResponse = z.lazy(() => { return z .object({ - endpoint: z.string().min(1).optional(), from: sesConfigFromResponse.optional(), key_id: z.string().min(1), region: z.string().min(1), secret_key: z.string().min(1), }) .transform((data) => ({ - endpoint: data['endpoint'], from: data['from'], keyId: data['key_id'], region: data['region'], @@ -55,14 +51,12 @@ export const sesConfigResponse = z.lazy(() => { export const sesConfigRequest = z.lazy(() => { return z .object({ - endpoint: z.string().nullish(), from: sesConfigFromRequest.nullish(), keyId: z.string().nullish(), region: z.string().nullish(), secretKey: z.string().nullish(), }) .transform((data) => ({ - endpoint: data['endpoint'], from: data['from'], key_id: data['keyId'], region: data['region'], diff --git a/packages/project-client/src/services/jwt/jwt.ts b/packages/project-client/src/services/jwt/jwt.ts index c9dcf58ef..403409674 100644 --- a/packages/project-client/src/services/jwt/jwt.ts +++ b/packages/project-client/src/services/jwt/jwt.ts @@ -26,15 +26,18 @@ export class JwtService extends BaseService { params?: FetchProjectTokensParams, requestConfig?: RequestConfig, ): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/jwt/project') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfFetchTokensResponseTokensResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfFetchTokensResponseTokensResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -62,15 +65,18 @@ export class JwtService extends BaseService { body: CreateProjectTokenRequest, requestConfig?: RequestConfig, ): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('POST') .setPath('/jwt/project') .setRequestSchema(createProjectTokenRequestRequest) - .setResponseSchema(accessTokenResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: accessTokenResponse, + contentType: ContentType.Json, + status: 201, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -86,15 +92,18 @@ export class JwtService extends BaseService { * @returns {Promise>} OK */ async discardProjectJwt(tokenId: string, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/jwt/project/{token_id}') .setRequestSchema(z.any()) - .setResponseSchema(discardTokenResponseResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: discardTokenResponseResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -111,15 +120,18 @@ export class JwtService extends BaseService { * @returns {Promise>} Created */ async createUserJwt(body: CreateUserTokenRequest, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('POST') .setPath('/jwt/user') .setRequestSchema(createUserTokenRequestRequest) - .setResponseSchema(accessTokenResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: accessTokenResponse, + contentType: ContentType.Json, + status: 201, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -135,15 +147,18 @@ export class JwtService extends BaseService { * @returns {Promise>} OK */ async discardUserJwt(tokenId: string, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/jwt/user/{token_id}') .setRequestSchema(z.any()) - .setResponseSchema(discardTokenResponseResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: discardTokenResponseResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -168,15 +183,18 @@ export class JwtService extends BaseService { params?: FetchUserTokensParams, requestConfig?: RequestConfig, ): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/jwt/user/{user_id}') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfFetchTokensResponseTokensResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfFetchTokensResponseTokensResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) diff --git a/packages/project-client/src/services/users/index.ts b/packages/project-client/src/services/users/index.ts new file mode 100644 index 000000000..a99b9437c --- /dev/null +++ b/packages/project-client/src/services/users/index.ts @@ -0,0 +1,2 @@ +export * from './models/index.js'; +export { UsersService } from './users.js'; diff --git a/packages/project-client/src/services/users/models/array-of-users.ts b/packages/project-client/src/services/users/models/array-of-users.ts new file mode 100644 index 000000000..d488f6deb --- /dev/null +++ b/packages/project-client/src/services/users/models/array-of-users.ts @@ -0,0 +1,49 @@ +import { z } from 'zod'; + +import { links, linksRequest, linksResponse } from '../../common/links.js'; +import { user, userRequest, userResponse } from './user.js'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const arrayOfUsers = z.lazy(() => { + return z.object({ + data: z.array(user).optional(), + links: links.optional(), + }); +}); + +/** + * + * @typedef {ArrayOfUsers} arrayOfUsers + * @property {User[]} + * @property {Links} + */ +export type ArrayOfUsers = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const arrayOfUsersResponse = z.lazy(() => { + return z + .object({ + data: z.array(userResponse).optional(), + links: linksResponse.optional(), + }) + .transform((data) => ({ + data: data['data'], + links: data['links'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const arrayOfUsersRequest = z.lazy(() => { + return z.object({ data: z.array(userRequest).nullish(), links: linksRequest.nullish() }).transform((data) => ({ + data: data['data'], + links: data['links'], + })); +}); diff --git a/packages/project-client/src/services/users/models/index.ts b/packages/project-client/src/services/users/models/index.ts new file mode 100644 index 000000000..f376fd8cd --- /dev/null +++ b/packages/project-client/src/services/users/models/index.ts @@ -0,0 +1,2 @@ +export type { ArrayOfUsers } from './array-of-users.js'; +export type { User } from './user.js'; diff --git a/packages/project-client/src/services/users/models/user.ts b/packages/project-client/src/services/users/models/user.ts new file mode 100644 index 000000000..383309da6 --- /dev/null +++ b/packages/project-client/src/services/users/models/user.ts @@ -0,0 +1,111 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const user = z.lazy(() => { + return z.object({ + createdAt: z.string(), + customAttributes: z.any(), + email: z.string().optional(), + externalId: z.string().optional(), + firstName: z.string().optional(), + id: z.string(), + lastName: z.string().optional(), + lastNotifiedAt: z.string().optional(), + lastSeenAt: z.string().optional(), + phoneNumbers: z.array(z.string()).optional(), + projectId: z.number(), + updatedAt: z.string(), + }); +}); + +/** + * + * @typedef {User} user + * @property {string} + * @property {any} + * @property {string} + * @property {string} + * @property {string} + * @property {string} + * @property {string} + * @property {string} + * @property {string} + * @property {string[]} + * @property {number} + * @property {string} + */ +export type User = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const userResponse = z.lazy(() => { + return z + .object({ + created_at: z.string(), + custom_attributes: z.any(), + email: z.string().optional(), + external_id: z.string().optional(), + first_name: z.string().optional(), + id: z.string(), + last_name: z.string().optional(), + last_notified_at: z.string().optional(), + last_seen_at: z.string().optional(), + phone_numbers: z.array(z.string()).optional(), + project_id: z.number(), + updated_at: z.string(), + }) + .transform((data) => ({ + createdAt: data['created_at'], + customAttributes: data['custom_attributes'], + email: data['email'], + externalId: data['external_id'], + firstName: data['first_name'], + id: data['id'], + lastName: data['last_name'], + lastNotifiedAt: data['last_notified_at'], + lastSeenAt: data['last_seen_at'], + phoneNumbers: data['phone_numbers'], + projectId: data['project_id'], + updatedAt: data['updated_at'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const userRequest = z.lazy(() => { + return z + .object({ + createdAt: z.string().nullish(), + customAttributes: z.any().nullish(), + email: z.string().nullish(), + externalId: z.string().nullish(), + firstName: z.string().nullish(), + id: z.string().nullish(), + lastName: z.string().nullish(), + lastNotifiedAt: z.string().nullish(), + lastSeenAt: z.string().nullish(), + phoneNumbers: z.array(z.string()).nullish(), + projectId: z.number().nullish(), + updatedAt: z.string().nullish(), + }) + .transform((data) => ({ + created_at: data['createdAt'], + custom_attributes: data['customAttributes'], + email: data['email'], + external_id: data['externalId'], + first_name: data['firstName'], + id: data['id'], + last_name: data['lastName'], + last_notified_at: data['lastNotifiedAt'], + last_seen_at: data['lastSeenAt'], + phone_numbers: data['phoneNumbers'], + project_id: data['projectId'], + updated_at: data['updatedAt'], + })); +}); diff --git a/packages/project-client/src/services/users/request-params.ts b/packages/project-client/src/services/users/request-params.ts new file mode 100644 index 000000000..c1acf5898 --- /dev/null +++ b/packages/project-client/src/services/users/request-params.ts @@ -0,0 +1,5 @@ +export interface ListUsersParams { + pageSize?: number; + pageAfter?: string; + pageBefore?: string; +} diff --git a/packages/project-client/src/services/users/users.ts b/packages/project-client/src/services/users/users.ts new file mode 100644 index 000000000..7d943026f --- /dev/null +++ b/packages/project-client/src/services/users/users.ts @@ -0,0 +1,49 @@ +import { z } from 'zod'; + +import { SerializationStyle } from '../../http/serialization/base-serializer.js'; +import { RequestBuilder } from '../../http/transport/request-builder.js'; +import { ContentType, HttpResponse, RequestConfig } from '../../http/types.js'; +import { BaseService } from '../base-service.js'; +import { ArrayOfUsers, arrayOfUsersResponse } from './models/array-of-users.js'; +import { ListUsersParams } from './request-params.js'; + +export class UsersService extends BaseService { + /** + * + * @param {number} [pageSize] - + * @param {string} [pageAfter] - + * @param {string} [pageBefore] - + * @returns {Promise>} OK + */ + async listUsers(params?: ListUsersParams, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setBaseUrl(this.config) + .setConfig(this.config) + .setMethod('GET') + .setPath('/users') + .setRequestSchema(z.any()) + .setRequestContentType(ContentType.Json) + .addResponse({ + schema: arrayOfUsersResponse, + contentType: ContentType.Json, + status: 200, + }) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addQueryParam({ + key: 'page[size]', + value: params?.pageSize, + }) + .addQueryParam({ + key: 'page[after]', + value: params?.pageAfter, + }) + .addQueryParam({ + key: 'page[before]', + value: params?.pageBefore, + }) + .build(); + return this.client.call(request); + } +} diff --git a/packages/user-client/README.md b/packages/user-client/README.md index f0e0c69db..13bde5ecc 100644 --- a/packages/user-client/README.md +++ b/packages/user-client/README.md @@ -11,7 +11,7 @@ Welcome to the Client SDK documentation. This guide will help you get started wi ## About the API -OpenAPI 3.1.0 Specification for MagicBell API. +OpenAPI 3.0.3 Specification for MagicBell API. ## Table of Contents @@ -115,25 +115,25 @@ The SDK includes several models that represent the data structures used in API r | Name | Description | | :------------------------------------------------------------------------------------------- | :---------- | -| [ArrayOfMetadataApnsTokens](documentation/models/ArrayOfMetadataApnsTokens.md) | | +| [ArrayOfApnsTokenResponses](documentation/models/ArrayOfApnsTokenResponses.md) | | | [ApnsToken](documentation/models/ApnsToken.md) | | -| [MetadataApnsToken](documentation/models/MetadataApnsToken.md) | | +| [ApnsTokenResponse1](documentation/models/ApnsTokenResponse1.md) | | | [DiscardResult](documentation/models/DiscardResult.md) | | -| [ArrayOfMetadataExpoTokens](documentation/models/ArrayOfMetadataExpoTokens.md) | | +| [ArrayOfExpoTokenResponses](documentation/models/ArrayOfExpoTokenResponses.md) | | | [ExpoToken](documentation/models/ExpoToken.md) | | -| [MetadataExpoToken](documentation/models/MetadataExpoToken.md) | | -| [ArrayOfMetadataFcmTokens](documentation/models/ArrayOfMetadataFcmTokens.md) | | +| [ExpoTokenResponse1](documentation/models/ExpoTokenResponse1.md) | | +| [ArrayOfFcmTokenResponses](documentation/models/ArrayOfFcmTokenResponses.md) | | | [FcmToken](documentation/models/FcmToken.md) | | -| [MetadataFcmToken](documentation/models/MetadataFcmToken.md) | | -| [ArrayOfMetadataSlackTokens](documentation/models/ArrayOfMetadataSlackTokens.md) | | +| [FcmTokenResponse1](documentation/models/FcmTokenResponse1.md) | | +| [ArrayOfSlackTokenResponses](documentation/models/ArrayOfSlackTokenResponses.md) | | | [SlackToken](documentation/models/SlackToken.md) | | -| [MetadataSlackToken](documentation/models/MetadataSlackToken.md) | | -| [ArrayOfMetadataTeamsTokens](documentation/models/ArrayOfMetadataTeamsTokens.md) | | +| [SlackTokenResponse1](documentation/models/SlackTokenResponse1.md) | | +| [ArrayOfTeamsTokenResponses](documentation/models/ArrayOfTeamsTokenResponses.md) | | | [TeamsToken](documentation/models/TeamsToken.md) | | -| [MetadataTeamsToken](documentation/models/MetadataTeamsToken.md) | | -| [ArrayOfMetadataWebPushTokens](documentation/models/ArrayOfMetadataWebPushTokens.md) | | +| [TeamsTokenResponse1](documentation/models/TeamsTokenResponse1.md) | | +| [ArrayOfWebPushTokenResponses](documentation/models/ArrayOfWebPushTokenResponses.md) | | | [WebPushToken](documentation/models/WebPushToken.md) | | -| [MetadataWebPushToken](documentation/models/MetadataWebPushToken.md) | | +| [WebPushTokenResponse](documentation/models/WebPushTokenResponse.md) | | | [InboxConfig](documentation/models/InboxConfig.md) | | | [SlackInstallation](documentation/models/SlackInstallation.md) | | | [SlackFinishInstallResponse](documentation/models/SlackFinishInstallResponse.md) | | @@ -142,6 +142,5 @@ The SDK includes several models that represent the data structures used in API r | [TemplatesInstallation](documentation/models/TemplatesInstallation.md) | | | [WebPushStartInstallationResponse](documentation/models/WebPushStartInstallationResponse.md) | | | [Links](documentation/models/Links.md) | | -| [TokenMetadata](documentation/models/TokenMetadata.md) | | diff --git a/packages/user-client/documentation/models/ApnsTokenResponse1.md b/packages/user-client/documentation/models/ApnsTokenResponse1.md new file mode 100644 index 000000000..b7917b1ec --- /dev/null +++ b/packages/user-client/documentation/models/ApnsTokenResponse1.md @@ -0,0 +1,24 @@ +# ApnsTokenResponse1 + +**Properties** + +| Name | Type | Required | Description | +| :------------- | :------------------------------ | :------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| createdAt | string | ✅ | | +| deviceToken | string | ✅ | | +| id | string | ✅ | | +| appId | string | ❌ | (Optional) The bundle identifier of the application that is registering this token. Use this field to override the default identifier specified in the projects APNs integration. | +| discardedAt | string | ❌ | | +| installationId | ApnsTokenResponseInstallationId | ❌ | (Optional) The APNs environment the token is registered for. If none is provided we assume the token is used in `production`. | +| updatedAt | string | ❌ | | + +# ApnsTokenResponseInstallationId + +(Optional) The APNs environment the token is registered for. If none is provided we assume the token is used in `production`. + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :----- | :------- | :------------ | +| DEVELOPMENT | string | ✅ | "development" | +| PRODUCTION | string | ✅ | "production" | diff --git a/packages/user-client/documentation/models/ArrayOfMetadataSlackTokens.md b/packages/user-client/documentation/models/ArrayOfApnsTokenResponses.md similarity index 68% rename from packages/user-client/documentation/models/ArrayOfMetadataSlackTokens.md rename to packages/user-client/documentation/models/ArrayOfApnsTokenResponses.md index 195427ea1..be1848970 100644 --- a/packages/user-client/documentation/models/ArrayOfMetadataSlackTokens.md +++ b/packages/user-client/documentation/models/ArrayOfApnsTokenResponses.md @@ -1,8 +1,8 @@ -# ArrayOfMetadataSlackTokens +# ArrayOfApnsTokenResponses **Properties** | Name | Type | Required | Description | | :---- | :------------------- | :------- | :---------- | -| data | MetadataSlackToken[] | ❌ | | +| data | ApnsTokenResponse1[] | ❌ | | | links | Links | ❌ | | diff --git a/packages/user-client/documentation/models/ArrayOfMetadataTeamsTokens.md b/packages/user-client/documentation/models/ArrayOfExpoTokenResponses.md similarity index 68% rename from packages/user-client/documentation/models/ArrayOfMetadataTeamsTokens.md rename to packages/user-client/documentation/models/ArrayOfExpoTokenResponses.md index 3ce987fa4..6e6012ec2 100644 --- a/packages/user-client/documentation/models/ArrayOfMetadataTeamsTokens.md +++ b/packages/user-client/documentation/models/ArrayOfExpoTokenResponses.md @@ -1,8 +1,8 @@ -# ArrayOfMetadataTeamsTokens +# ArrayOfExpoTokenResponses **Properties** | Name | Type | Required | Description | | :---- | :------------------- | :------- | :---------- | -| data | MetadataTeamsToken[] | ❌ | | +| data | ExpoTokenResponse1[] | ❌ | | | links | Links | ❌ | | diff --git a/packages/project-client/documentation/models/ArrayOfMetadataExpoTokens.md b/packages/user-client/documentation/models/ArrayOfFcmTokenResponses.md similarity index 68% rename from packages/project-client/documentation/models/ArrayOfMetadataExpoTokens.md rename to packages/user-client/documentation/models/ArrayOfFcmTokenResponses.md index e5dcc3c61..2a45fcae7 100644 --- a/packages/project-client/documentation/models/ArrayOfMetadataExpoTokens.md +++ b/packages/user-client/documentation/models/ArrayOfFcmTokenResponses.md @@ -1,8 +1,8 @@ -# ArrayOfMetadataExpoTokens +# ArrayOfFcmTokenResponses **Properties** | Name | Type | Required | Description | | :---- | :------------------ | :------- | :---------- | -| data | MetadataExpoToken[] | ❌ | | +| data | FcmTokenResponse1[] | ❌ | | | links | Links | ❌ | | diff --git a/packages/user-client/documentation/models/ArrayOfMetadataExpoTokens.md b/packages/user-client/documentation/models/ArrayOfMetadataExpoTokens.md deleted file mode 100644 index e5dcc3c61..000000000 --- a/packages/user-client/documentation/models/ArrayOfMetadataExpoTokens.md +++ /dev/null @@ -1,8 +0,0 @@ -# ArrayOfMetadataExpoTokens - -**Properties** - -| Name | Type | Required | Description | -| :---- | :------------------ | :------- | :---------- | -| data | MetadataExpoToken[] | ❌ | | -| links | Links | ❌ | | diff --git a/packages/user-client/documentation/models/ArrayOfSlackTokenResponses.md b/packages/user-client/documentation/models/ArrayOfSlackTokenResponses.md new file mode 100644 index 000000000..0bc76c6d6 --- /dev/null +++ b/packages/user-client/documentation/models/ArrayOfSlackTokenResponses.md @@ -0,0 +1,8 @@ +# ArrayOfSlackTokenResponses + +**Properties** + +| Name | Type | Required | Description | +| :---- | :-------------------- | :------- | :---------- | +| data | SlackTokenResponse1[] | ❌ | | +| links | Links | ❌ | | diff --git a/packages/user-client/documentation/models/ArrayOfTeamsTokenResponses.md b/packages/user-client/documentation/models/ArrayOfTeamsTokenResponses.md new file mode 100644 index 000000000..551cbb8ed --- /dev/null +++ b/packages/user-client/documentation/models/ArrayOfTeamsTokenResponses.md @@ -0,0 +1,8 @@ +# ArrayOfTeamsTokenResponses + +**Properties** + +| Name | Type | Required | Description | +| :---- | :-------------------- | :------- | :---------- | +| data | TeamsTokenResponse1[] | ❌ | | +| links | Links | ❌ | | diff --git a/packages/user-client/documentation/models/ArrayOfMetadataWebPushTokens.md b/packages/user-client/documentation/models/ArrayOfWebPushTokenResponses.md similarity index 68% rename from packages/user-client/documentation/models/ArrayOfMetadataWebPushTokens.md rename to packages/user-client/documentation/models/ArrayOfWebPushTokenResponses.md index d9ebc3ea1..fb37407f7 100644 --- a/packages/user-client/documentation/models/ArrayOfMetadataWebPushTokens.md +++ b/packages/user-client/documentation/models/ArrayOfWebPushTokenResponses.md @@ -1,8 +1,8 @@ -# ArrayOfMetadataWebPushTokens +# ArrayOfWebPushTokenResponses **Properties** | Name | Type | Required | Description | | :---- | :--------------------- | :------- | :---------- | -| data | MetadataWebPushToken[] | ❌ | | +| data | WebPushTokenResponse[] | ❌ | | | links | Links | ❌ | | diff --git a/packages/user-client/documentation/models/TokenMetadata.md b/packages/user-client/documentation/models/ExpoTokenResponse1.md similarity index 81% rename from packages/user-client/documentation/models/TokenMetadata.md rename to packages/user-client/documentation/models/ExpoTokenResponse1.md index f5ddc77b1..cddec40fb 100644 --- a/packages/user-client/documentation/models/TokenMetadata.md +++ b/packages/user-client/documentation/models/ExpoTokenResponse1.md @@ -1,10 +1,11 @@ -# TokenMetadata +# ExpoTokenResponse1 **Properties** | Name | Type | Required | Description | | :---------- | :----- | :------- | :---------- | | createdAt | string | ✅ | | +| deviceToken | string | ✅ | | | id | string | ✅ | | | discardedAt | string | ❌ | | | updatedAt | string | ❌ | | diff --git a/packages/user-client/documentation/models/FcmTokenResponse1.md b/packages/user-client/documentation/models/FcmTokenResponse1.md new file mode 100644 index 000000000..204788858 --- /dev/null +++ b/packages/user-client/documentation/models/FcmTokenResponse1.md @@ -0,0 +1,21 @@ +# FcmTokenResponse1 + +**Properties** + +| Name | Type | Required | Description | +| :------------- | :----------------------------- | :------- | :---------- | +| createdAt | string | ✅ | | +| deviceToken | string | ✅ | | +| id | string | ✅ | | +| discardedAt | string | ❌ | | +| installationId | FcmTokenResponseInstallationId | ❌ | | +| updatedAt | string | ❌ | | + +# FcmTokenResponseInstallationId + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :----- | :------- | :------------ | +| DEVELOPMENT | string | ✅ | "development" | +| PRODUCTION | string | ✅ | "production" | diff --git a/packages/user-client/documentation/models/MetadataApnsToken.md b/packages/user-client/documentation/models/MetadataApnsToken.md deleted file mode 100644 index ce227ffc3..000000000 --- a/packages/user-client/documentation/models/MetadataApnsToken.md +++ /dev/null @@ -1,8 +0,0 @@ -# MetadataApnsToken - -**Properties** - -| Name | Type | Required | Description | -| :------- | :------------ | :------- | :---------- | -| data | ApnsToken | ✅ | | -| metadata | TokenMetadata | ✅ | | diff --git a/packages/user-client/documentation/models/MetadataExpoToken.md b/packages/user-client/documentation/models/MetadataExpoToken.md deleted file mode 100644 index 6cf24e93f..000000000 --- a/packages/user-client/documentation/models/MetadataExpoToken.md +++ /dev/null @@ -1,8 +0,0 @@ -# MetadataExpoToken - -**Properties** - -| Name | Type | Required | Description | -| :------- | :------------ | :------- | :---------- | -| data | ExpoToken | ✅ | | -| metadata | TokenMetadata | ✅ | | diff --git a/packages/user-client/documentation/models/MetadataFcmToken.md b/packages/user-client/documentation/models/MetadataFcmToken.md deleted file mode 100644 index 5eae39e53..000000000 --- a/packages/user-client/documentation/models/MetadataFcmToken.md +++ /dev/null @@ -1,8 +0,0 @@ -# MetadataFcmToken - -**Properties** - -| Name | Type | Required | Description | -| :------- | :------------ | :------- | :---------- | -| data | FcmToken | ✅ | | -| metadata | TokenMetadata | ✅ | | diff --git a/packages/user-client/documentation/models/MetadataSlackToken.md b/packages/user-client/documentation/models/MetadataSlackToken.md deleted file mode 100644 index e60292e20..000000000 --- a/packages/user-client/documentation/models/MetadataSlackToken.md +++ /dev/null @@ -1,8 +0,0 @@ -# MetadataSlackToken - -**Properties** - -| Name | Type | Required | Description | -| :------- | :------------ | :------- | :---------- | -| data | SlackToken | ✅ | | -| metadata | TokenMetadata | ✅ | | diff --git a/packages/user-client/documentation/models/MetadataTeamsToken.md b/packages/user-client/documentation/models/MetadataTeamsToken.md deleted file mode 100644 index 482ce7783..000000000 --- a/packages/user-client/documentation/models/MetadataTeamsToken.md +++ /dev/null @@ -1,8 +0,0 @@ -# MetadataTeamsToken - -**Properties** - -| Name | Type | Required | Description | -| :------- | :------------ | :------- | :---------- | -| data | TeamsToken | ✅ | | -| metadata | TokenMetadata | ✅ | | diff --git a/packages/user-client/documentation/models/MetadataWebPushToken.md b/packages/user-client/documentation/models/MetadataWebPushToken.md deleted file mode 100644 index daab50e6b..000000000 --- a/packages/user-client/documentation/models/MetadataWebPushToken.md +++ /dev/null @@ -1,8 +0,0 @@ -# MetadataWebPushToken - -**Properties** - -| Name | Type | Required | Description | -| :------- | :------------ | :------- | :---------- | -| data | WebPushToken | ✅ | | -| metadata | TokenMetadata | ✅ | | diff --git a/packages/user-client/documentation/models/SlackToken.md b/packages/user-client/documentation/models/SlackToken.md index 589406920..7282a8589 100644 --- a/packages/user-client/documentation/models/SlackToken.md +++ b/packages/user-client/documentation/models/SlackToken.md @@ -4,10 +4,10 @@ | Name | Type | Required | Description | | :------ | :---------------- | :------- | :---------- | -| oauth | Oauth | ❌ | | +| oauth | SlackTokenOauth | ❌ | | | webhook | SlackTokenWebhook | ❌ | | -# Oauth +# SlackTokenOauth **Properties** diff --git a/packages/user-client/documentation/models/SlackTokenResponse1.md b/packages/user-client/documentation/models/SlackTokenResponse1.md new file mode 100644 index 000000000..966d47027 --- /dev/null +++ b/packages/user-client/documentation/models/SlackTokenResponse1.md @@ -0,0 +1,30 @@ +# SlackTokenResponse1 + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :------------------------ | :------- | :---------- | +| createdAt | string | ✅ | | +| id | string | ✅ | | +| discardedAt | string | ❌ | | +| oauth | SlackTokenResponseOauth | ❌ | | +| updatedAt | string | ❌ | | +| webhook | SlackTokenResponseWebhook | ❌ | | + +# SlackTokenResponseOauth + +**Properties** + +| Name | Type | Required | Description | +| :------------- | :----- | :------- | :---------- | +| channelId | string | ✅ | | +| installationId | string | ✅ | | +| scope | string | ❌ | | + +# SlackTokenResponseWebhook + +**Properties** + +| Name | Type | Required | Description | +| :--- | :----- | :------- | :---------- | +| url | string | ✅ | | diff --git a/packages/user-client/documentation/models/TeamsTokenResponse1.md b/packages/user-client/documentation/models/TeamsTokenResponse1.md new file mode 100644 index 000000000..076ee50b9 --- /dev/null +++ b/packages/user-client/documentation/models/TeamsTokenResponse1.md @@ -0,0 +1,19 @@ +# TeamsTokenResponse1 + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :------------------------ | :------- | :---------- | +| createdAt | string | ✅ | | +| id | string | ✅ | | +| discardedAt | string | ❌ | | +| updatedAt | string | ❌ | | +| webhook | TeamsTokenResponseWebhook | ❌ | | + +# TeamsTokenResponseWebhook + +**Properties** + +| Name | Type | Required | Description | +| :--- | :----- | :------- | :---------- | +| url | string | ❌ | | diff --git a/packages/user-client/documentation/models/WebPushToken.md b/packages/user-client/documentation/models/WebPushToken.md index 23e8a46df..550a05f50 100644 --- a/packages/user-client/documentation/models/WebPushToken.md +++ b/packages/user-client/documentation/models/WebPushToken.md @@ -2,12 +2,12 @@ **Properties** -| Name | Type | Required | Description | -| :------- | :----- | :------- | :---------- | -| endpoint | string | ✅ | | -| keys | Keys | ✅ | | +| Name | Type | Required | Description | +| :------- | :--------------- | :------- | :---------- | +| endpoint | string | ✅ | | +| keys | WebPushTokenKeys | ✅ | | -# Keys +# WebPushTokenKeys **Properties** diff --git a/packages/user-client/documentation/models/WebPushTokenResponse.md b/packages/user-client/documentation/models/WebPushTokenResponse.md new file mode 100644 index 000000000..3b0053131 --- /dev/null +++ b/packages/user-client/documentation/models/WebPushTokenResponse.md @@ -0,0 +1,21 @@ +# WebPushTokenResponse + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :----------------------- | :------- | :---------- | +| createdAt | string | ✅ | | +| endpoint | string | ✅ | | +| id | string | ✅ | | +| keys | WebPushTokenResponseKeys | ✅ | | +| discardedAt | string | ❌ | | +| updatedAt | string | ❌ | | + +# WebPushTokenResponseKeys + +**Properties** + +| Name | Type | Required | Description | +| :----- | :----- | :------- | :---------- | +| auth | string | ✅ | | +| p256dh | string | ✅ | | diff --git a/packages/user-client/documentation/services/ChannelsService.md b/packages/user-client/documentation/services/ChannelsService.md index a7b181d97..e569d15e1 100644 --- a/packages/user-client/documentation/services/ChannelsService.md +++ b/packages/user-client/documentation/services/ChannelsService.md @@ -46,7 +46,7 @@ Lists all mobile_push tokens belonging to the authenticated user. Returns a pagi **Return Type** -`ArrayOfMetadataApnsTokens` +`ArrayOfApnsTokenResponses` **Example Usage Code Snippet** @@ -99,7 +99,7 @@ import { ApnsToken, Client } from '@magicbell/user-client'; const apnsToken: ApnsToken = { appId: 'app_id', - deviceToken: 'voluptate paria', + deviceToken: 'nostrud elit do', installationId: apnsTokenInstallationId, }; @@ -124,7 +124,7 @@ Retrieves details of a specific mobile_push token belonging to the authenticated **Return Type** -`MetadataApnsToken` +`ApnsTokenResponse1` **Example Usage Code Snippet** @@ -192,7 +192,7 @@ Lists all mobile_push tokens belonging to the authenticated user. Returns a pagi **Return Type** -`ArrayOfMetadataExpoTokens` +`ArrayOfExpoTokenResponses` **Example Usage Code Snippet** @@ -205,7 +205,7 @@ import { Client } from '@magicbell/user-client'; }); const { data } = await client.channels.getMobilePushExpoTokens({ - pageSize: 6, + pageSize: 10, pageAfter: 'page[after]', pageBefore: 'page[before]', }); @@ -266,7 +266,7 @@ Retrieves details of a specific mobile_push token belonging to the authenticated **Return Type** -`MetadataExpoToken` +`ExpoTokenResponse1` **Example Usage Code Snippet** @@ -334,7 +334,7 @@ Lists all mobile_push tokens belonging to the authenticated user. Returns a pagi **Return Type** -`ArrayOfMetadataFcmTokens` +`ArrayOfFcmTokenResponses` **Example Usage Code Snippet** @@ -347,7 +347,7 @@ import { Client } from '@magicbell/user-client'; }); const { data } = await client.channels.getMobilePushFcmTokens({ - pageSize: 10, + pageSize: 9, pageAfter: 'page[after]', pageBefore: 'page[before]', }); @@ -386,7 +386,7 @@ import { Client, FcmToken } from '@magicbell/user-client'; const fcmTokenInstallationId = FcmTokenInstallationId.DEVELOPMENT; const fcmToken: FcmToken = { - deviceToken: 'eiusmod esse ni', + deviceToken: 'voluptate nulla', installationId: fcmTokenInstallationId, }; @@ -411,7 +411,7 @@ Retrieves details of a specific mobile_push token belonging to the authenticated **Return Type** -`MetadataFcmToken` +`FcmTokenResponse1` **Example Usage Code Snippet** @@ -479,7 +479,7 @@ Lists all slack tokens belonging to the authenticated user. Returns a paginated **Return Type** -`ArrayOfMetadataSlackTokens` +`ArrayOfSlackTokenResponses` **Example Usage Code Snippet** @@ -492,7 +492,7 @@ import { Client } from '@magicbell/user-client'; }); const { data } = await client.channels.getSlackTokens({ - pageSize: 2, + pageSize: 3, pageAfter: 'page[after]', pageBefore: 'page[before]', }); @@ -528,7 +528,7 @@ import { Client, SlackToken } from '@magicbell/user-client'; token: 'YOUR_TOKEN', }); - const oauth: Oauth = { + const slackTokenOauth: SlackTokenOauth = { channelId: 'channel_id', installationId: 'installation_id', scope: 'scope', @@ -539,7 +539,7 @@ import { Client, SlackToken } from '@magicbell/user-client'; }; const slackToken: SlackToken = { - oauth: oauth, + oauth: slackTokenOauth, webhook: slackTokenWebhook, }; @@ -564,7 +564,7 @@ Retrieves details of a specific slack token belonging to the authenticated user. **Return Type** -`MetadataSlackToken` +`SlackTokenResponse1` **Example Usage Code Snippet** @@ -632,7 +632,7 @@ Lists all teams tokens belonging to the authenticated user. Returns a paginated **Return Type** -`ArrayOfMetadataTeamsTokens` +`ArrayOfTeamsTokenResponses` **Example Usage Code Snippet** @@ -710,7 +710,7 @@ Retrieves details of a specific teams token belonging to the authenticated user. **Return Type** -`MetadataTeamsToken` +`TeamsTokenResponse1` **Example Usage Code Snippet** @@ -778,7 +778,7 @@ Lists all web_push tokens belonging to the authenticated user. Returns a paginat **Return Type** -`ArrayOfMetadataWebPushTokens` +`ArrayOfWebPushTokenResponses` **Example Usage Code Snippet** @@ -791,7 +791,7 @@ import { Client } from '@magicbell/user-client'; }); const { data } = await client.channels.getWebPushTokens({ - pageSize: 5, + pageSize: 1, pageAfter: 'page[after]', pageBefore: 'page[before]', }); @@ -827,14 +827,14 @@ import { Client, WebPushToken } from '@magicbell/user-client'; token: 'YOUR_TOKEN', }); - const keys: Keys = { + const webPushTokenKeys: WebPushTokenKeys = { auth: 'auth', p256dh: 'p256dh', }; const webPushToken: WebPushToken = { endpoint: 'endpoint', - keys: keys, + keys: webPushTokenKeys, }; const { data } = await client.channels.saveWebPushToken(webPushToken); @@ -858,7 +858,7 @@ Retrieves details of a specific web_push token belonging to the authenticated us **Return Type** -`MetadataWebPushToken` +`WebPushTokenResponse` **Example Usage Code Snippet** diff --git a/packages/user-client/documentation/services/IntegrationsService.md b/packages/user-client/documentation/services/IntegrationsService.md index 2e151e4fc..e3aa14f5d 100644 --- a/packages/user-client/documentation/services/IntegrationsService.md +++ b/packages/user-client/documentation/services/IntegrationsService.md @@ -46,7 +46,7 @@ import { Client, InboxConfig } from '@magicbell/user-client'; const banner: Banner = { backgroundColor: 'backgroundColor', - backgroundOpacity: 9.57, + backgroundOpacity: 1.63, fontSize: 'fontSize', textColor: 'textColor', }; @@ -214,7 +214,7 @@ import { Client, SlackInstallation } from '@magicbell/user-client'; const authedUser: AuthedUser = { accessToken: 'access_token', - expiresIn: 7, + expiresIn: 9, id: 'id', refreshToken: 'refresh_token', scope: 'scope', @@ -243,8 +243,8 @@ import { Client, SlackInstallation } from '@magicbell/user-client'; authedUser: authedUser, botUserId: 'bot_user_id', enterprise: enterprise, - expiresIn: 10, - id: 'YDW09447', + expiresIn: 5, + id: 'ZZYOJ3PL', incomingWebhook: incomingWebhook, isEnterpriseInstall: true, refreshToken: 'refresh_token', @@ -404,14 +404,14 @@ import { Client, WebPushToken } from '@magicbell/user-client'; token: 'YOUR_TOKEN', }); - const keys: Keys = { + const webPushTokenKeys: WebPushTokenKeys = { auth: 'auth', p256dh: 'p256dh', }; const webPushToken: WebPushToken = { endpoint: 'endpoint', - keys: keys, + keys: webPushTokenKeys, }; const { data } = await client.integrations.saveWebPushInstallation(webPushToken); diff --git a/packages/user-client/src/http/client.ts b/packages/user-client/src/http/client.ts index 597626168..186cf2a22 100644 --- a/packages/user-client/src/http/client.ts +++ b/packages/user-client/src/http/client.ts @@ -21,15 +21,15 @@ export class HttpClient { this.requestHandlerChain.addHandler(new TerminatingHandler()); } - call(request: Request): Promise> { + call(request: Request): Promise> { return this.requestHandlerChain.callChain(request); } - async *stream(request: Request): AsyncGenerator> { + async *stream(request: Request): AsyncGenerator> { yield* this.requestHandlerChain.streamChain(request); } - public async callPaginated(request: Request): Promise> { + public async callPaginated(request: Request): Promise> { const response = await this.call(request as any); if (!response.data) { @@ -50,7 +50,7 @@ export class HttpClient { this.config = config; } - private getPage(request: Request, data: FullResponse): Page { + private getPage(request: Request, data: FullResponse): Page { if (!request.pagination) { throw new Error('getPage called for request without pagination property'); } diff --git a/packages/user-client/src/http/handlers/auth-handler.ts b/packages/user-client/src/http/handlers/auth-handler.ts index 8fcf99d64..c338e8325 100644 --- a/packages/user-client/src/http/handlers/auth-handler.ts +++ b/packages/user-client/src/http/handlers/auth-handler.ts @@ -5,27 +5,27 @@ import { HttpResponse, RequestHandler } from '../types.js'; export class AuthHandler implements RequestHandler { next?: RequestHandler; - public async handle(request: Request): Promise> { + public async handle(request: Request): Promise> { const requestWithAuth = this.addAccessTokenHeader(request); if (!this.next) { throw new Error(`No next handler set in ${AuthHandler.name}`); } - return this.next.handle(requestWithAuth); + return this.next.handle(requestWithAuth); } - public async *stream(request: Request): AsyncGenerator> { + public async *stream(request: Request): AsyncGenerator> { const requestWithAuth = this.addAccessTokenHeader(request); if (!this.next) { throw new Error(`No next handler set in ${AuthHandler.name}`); } - yield* this.next.stream(requestWithAuth); + yield* this.next.stream(requestWithAuth); } - private addAccessTokenHeader(request: Request): Request { + private addAccessTokenHeader(request: Request): Request { const { token } = request.config; if (!token) { return request; diff --git a/packages/user-client/src/http/handlers/handler-chain.ts b/packages/user-client/src/http/handlers/handler-chain.ts index 7f55f13db..e794dac84 100644 --- a/packages/user-client/src/http/handlers/handler-chain.ts +++ b/packages/user-client/src/http/handlers/handler-chain.ts @@ -12,19 +12,19 @@ export class RequestHandlerChain { this.handlers.push(handler); } - async callChain(request: Request): Promise> { + async callChain(request: Request): Promise> { if (!this.handlers.length) { throw new Error('No handlers added to the chain'); } - return this.handlers[0].handle(request); + return this.handlers[0].handle(request); } - async *streamChain(request: Request): AsyncGenerator> { + async *streamChain(request: Request): AsyncGenerator> { if (!this.handlers.length) { throw new Error('No handlers added to the chain'); } - yield* this.handlers[0].stream(request); + yield* this.handlers[0].stream(request); } } diff --git a/packages/user-client/src/http/handlers/hook-handler.ts b/packages/user-client/src/http/handlers/hook-handler.ts index 0850a72c1..d7a1429e2 100644 --- a/packages/user-client/src/http/handlers/hook-handler.ts +++ b/packages/user-client/src/http/handlers/hook-handler.ts @@ -8,7 +8,7 @@ export class HookHandler implements RequestHandler { constructor(private readonly hook: Hook) {} - async handle(request: Request): Promise> { + async handle(request: Request): Promise> { if (!this.next) { throw new Error('No next handler set in hook handler.'); } @@ -19,7 +19,7 @@ export class HookHandler implements RequestHandler { const nextRequest = await hook.beforeRequest(request, hookParams); - const response = await this.next.handle(nextRequest); + const response = await this.next.handle(nextRequest); if (response.metadata.status < 400) { return await hook.afterResponse(nextRequest, response, hookParams); @@ -28,7 +28,7 @@ export class HookHandler implements RequestHandler { throw await hook.onError(nextRequest, response, hookParams); } - async *stream(request: Request): AsyncGenerator> { + async *stream(request: Request): AsyncGenerator> { if (!this.next) { throw new Error('No next handler set in hook handler.'); } @@ -39,7 +39,7 @@ export class HookHandler implements RequestHandler { const nextRequest = await hook.beforeRequest(request, hookParams); - const stream = this.next.stream(nextRequest); + const stream = this.next.stream(nextRequest); for await (const response of stream) { if (response.metadata.status < 400) { @@ -50,7 +50,7 @@ export class HookHandler implements RequestHandler { } } - private getHookParams(_request: Request): Map { + private getHookParams(_request: Request): Map { const hookParams: Map = new Map(); return hookParams; } diff --git a/packages/user-client/src/http/handlers/request-validation-handler.ts b/packages/user-client/src/http/handlers/request-validation-handler.ts index b35511fa9..6dc0056d5 100644 --- a/packages/user-client/src/http/handlers/request-validation-handler.ts +++ b/packages/user-client/src/http/handlers/request-validation-handler.ts @@ -4,27 +4,27 @@ import { ContentType, HttpResponse, RequestHandler } from '../types.js'; export class RequestValidationHandler implements RequestHandler { next?: RequestHandler; - async handle(request: Request): Promise> { + async handle(request: Request): Promise> { if (!this.next) { throw new Error('No next handler set in ContentTypeHandler.'); } this.validateRequest(request); - return this.next.handle(request); + return this.next.handle(request); } - async *stream(request: Request): AsyncGenerator> { + async *stream(request: Request): AsyncGenerator> { if (!this.next) { throw new Error('No next handler set in ContentTypeHandler.'); } this.validateRequest(request); - yield* this.next.stream(request); + yield* this.next.stream(request); } - validateRequest(request: Request): void { + validateRequest(request: Request): void { if (request.requestContentType === ContentType.Json) { request.body = JSON.stringify(request.requestSchema?.parse(request.body)); } else if ( @@ -42,7 +42,7 @@ export class RequestValidationHandler implements RequestHandler { } } - toFormUrlEncoded(request: Request): string { + toFormUrlEncoded(request: Request): string { if (request.body === undefined) { return ''; } diff --git a/packages/user-client/src/http/handlers/response-validation-handler.ts b/packages/user-client/src/http/handlers/response-validation-handler.ts index d1fa7370a..eec00a539 100644 --- a/packages/user-client/src/http/handlers/response-validation-handler.ts +++ b/packages/user-client/src/http/handlers/response-validation-handler.ts @@ -1,24 +1,25 @@ import { ZodUndefined } from 'zod'; -import { Request } from '../transport/request.js'; +import { Request, ResponseDefinition } from '../transport/request.js'; import { ContentType, HttpResponse, RequestHandler } from '../types.js'; +import { ResponseMatcher } from '../utils/response-matcher.js'; export class ResponseValidationHandler implements RequestHandler { next?: RequestHandler; - async handle(request: Request): Promise> { - const response = await this.next!.handle(request); + async handle(request: Request): Promise> { + const response = await this.next!.handle(request); - return this.decodeBody(request, response); + return this.decodeBody(request, response); } - async *stream(request: Request): AsyncGenerator> { - const stream = this.next!.stream(request); + async *stream(request: Request): AsyncGenerator> { + const stream = this.next!.stream(request); for await (const response of stream) { - const responseChunks = this.splitByDataChunks(response); + const responseChunks = this.splitByDataChunks(response); for (const chunk of responseChunks) { - yield this.decodeBody(request, chunk); + yield this.decodeBody(request, chunk); } } } @@ -39,70 +40,91 @@ export class ResponseValidationHandler implements RequestHandler { })); } - private decodeBody(request: Request, response: HttpResponse): HttpResponse { - if (!this.hasContent(request, response)) { - return response; - } - - if (request.responseContentType === ContentType.Binary || request.responseContentType === ContentType.Image) { - return this.decodeFile(request, response); - } + private decodeBody(request: Request, response: HttpResponse): HttpResponse { + const responseMatcher = new ResponseMatcher(request.responses); + const responseDefinition = responseMatcher.getResponseDefinition(response); - if (request.responseContentType === ContentType.MultipartFormData) { - return this.decodeMultipartFormData(request, response); + if (!responseDefinition || !this.hasContent(responseDefinition, response)) { + return response; } - if (request.responseContentType === ContentType.Text || request.responseContentType === ContentType.Xml) { - return this.decodeText(request, response); - } + const contentType = responseDefinition.contentType; + const contentTypeHandlers: { + [key: string]: (req: Request, resDef: ResponseDefinition, res: HttpResponse) => HttpResponse; + } = { + [ContentType.Binary]: this.decodeFile, + [ContentType.Image]: this.decodeFile, + [ContentType.MultipartFormData]: this.decodeMultipartFormData, + [ContentType.Text]: this.decodeText, + [ContentType.Xml]: this.decodeText, + [ContentType.FormUrlEncoded]: this.decodeFormUrlEncoded, + [ContentType.EventStream]: this.decodeEventStream, + }; - if (request.responseContentType === ContentType.FormUrlEncoded) { - return this.decodeFormUrlEncoded(request, response); + if (contentTypeHandlers[contentType]) { + return contentTypeHandlers[contentType].call(this, request, responseDefinition, response); } - if ( - request.responseContentType === ContentType.EventStream || - response.metadata.headers['content-type'].includes('text/event-stream') - ) { - return this.decodeEventStream(request, response); + if (response.metadata.headers['content-type']?.includes('text/event-stream')) { + return this.decodeEventStream(request, responseDefinition, response); } - return this.decodeJson(request, response); + return this.decodeJson(request, responseDefinition, response); } - private decodeFile(request: Request, response: HttpResponse): HttpResponse { + private decodeFile( + request: Request, + responseDefinition: ResponseDefinition, + response: HttpResponse, + ): HttpResponse { return { ...response, - data: this.validate(request, response.raw), + data: this.validate(request, responseDefinition, response.raw), }; } - private decodeMultipartFormData(request: Request, response: HttpResponse): HttpResponse { + private decodeMultipartFormData( + request: Request, + responseDefinition: ResponseDefinition, + response: HttpResponse, + ): HttpResponse { const formData = this.fromFormData(response.raw); return { ...response, - data: this.validate(request, formData), + data: this.validate(request, responseDefinition, formData), }; } - private decodeText(request: Request, response: HttpResponse): HttpResponse { + private decodeText( + request: Request, + responseDefinition: ResponseDefinition, + response: HttpResponse, + ): HttpResponse { const decodedBody = new TextDecoder().decode(response.raw); return { ...response, - data: this.validate(request, decodedBody), + data: this.validate(request, responseDefinition, decodedBody), }; } - private decodeFormUrlEncoded(request: Request, response: HttpResponse): HttpResponse { + private decodeFormUrlEncoded( + request: Request, + responseDefinition: ResponseDefinition, + response: HttpResponse, + ): HttpResponse { const decodedBody = new TextDecoder().decode(response.raw); const urlEncoded = this.fromUrlEncoded(decodedBody); return { ...response, - data: this.validate(request, urlEncoded), + data: this.validate(request, responseDefinition, urlEncoded), }; } - private decodeEventStream(request: Request, response: HttpResponse): HttpResponse { + private decodeEventStream( + request: Request, + responseDefinition: ResponseDefinition, + response: HttpResponse, + ): HttpResponse { let decodedBody = new TextDecoder().decode(response.raw); if (decodedBody.startsWith('data: ')) { decodedBody = decodedBody.substring(6); @@ -111,29 +133,35 @@ export class ResponseValidationHandler implements RequestHandler { const json = JSON.parse(decodedBody); return { ...response, - data: this.validate(request, json), + data: this.validate(request, responseDefinition, json), }; } - private decodeJson(request: Request, response: HttpResponse): HttpResponse { + private decodeJson( + request: Request, + responseDefinition: ResponseDefinition, + response: HttpResponse, + ): HttpResponse { const decodedBody = new TextDecoder().decode(response.raw); const json = JSON.parse(decodedBody); return { ...response, - data: this.validate(request, json), + data: this.validate(request, responseDefinition, json), }; } - private validate(request: Request, data: any): T { + private validate(request: Request, response: ResponseDefinition, data: any): T { if (request.validation?.responseValidation) { - return request.responseSchema.parse(data); + return response.schema.parse(data); } return data; } - private hasContent(request: Request, response: HttpResponse): boolean { + private hasContent(responseDefinition: ResponseDefinition, response: HttpResponse): boolean { return ( - !!request.responseSchema && !(request.responseSchema instanceof ZodUndefined) && response.metadata.status !== 204 + !!responseDefinition.schema && + !(responseDefinition.schema instanceof ZodUndefined) && + response.metadata.status !== 204 ); } diff --git a/packages/user-client/src/http/handlers/retry-handler.ts b/packages/user-client/src/http/handlers/retry-handler.ts index e9ac00351..bfe4adc94 100644 --- a/packages/user-client/src/http/handlers/retry-handler.ts +++ b/packages/user-client/src/http/handlers/retry-handler.ts @@ -5,14 +5,14 @@ import { HttpResponse, RequestHandler } from '../types.js'; export class RetryHandler implements RequestHandler { next?: RequestHandler; - async handle(request: Request): Promise> { + async handle(request: Request): Promise> { if (!this.next) { throw new Error('No next handler set in retry handler.'); } for (let attempt = 1; attempt <= request.retry.attempts; attempt++) { try { - return await this.next.handle(request); + return await this.next.handle(request); } catch (error: any) { if (!this.shouldRetry(error) || attempt === request.retry.attempts) { throw error; @@ -24,14 +24,14 @@ export class RetryHandler implements RequestHandler { throw new Error('Error retrying request.'); } - async *stream(request: Request): AsyncGenerator> { + async *stream(request: Request): AsyncGenerator> { if (!this.next) { throw new Error('No next handler set in retry handler.'); } for (let attempt = 1; attempt <= request.retry.attempts; attempt++) { try { - yield* this.next.stream(request); + yield* this.next.stream(request); return; } catch (error: any) { if (!this.shouldRetry(error) || attempt === request.retry.attempts) { diff --git a/packages/user-client/src/http/handlers/terminating-handler.ts b/packages/user-client/src/http/handlers/terminating-handler.ts index 43c7b77af..4225d9646 100644 --- a/packages/user-client/src/http/handlers/terminating-handler.ts +++ b/packages/user-client/src/http/handlers/terminating-handler.ts @@ -4,11 +4,11 @@ import { RequestFetchAdapter } from '../transport/request-fetch-adapter.js'; import { HttpResponse, RequestHandler } from '../types.js'; export class TerminatingHandler implements RequestHandler { - async handle(request: Request): Promise> { - return new RequestFetchAdapter(request).send(); + async handle(request: Request): Promise> { + return new RequestFetchAdapter(request).send(); } - async *stream(request: Request): AsyncGenerator> { - yield* new RequestFetchAdapter(request).stream(); + async *stream(request: Request): AsyncGenerator> { + yield* new RequestFetchAdapter(request).stream(); } } diff --git a/packages/user-client/src/http/transport/request-builder.ts b/packages/user-client/src/http/transport/request-builder.ts index e315a6096..0ba603923 100644 --- a/packages/user-client/src/http/transport/request-builder.ts +++ b/packages/user-client/src/http/transport/request-builder.ts @@ -3,10 +3,16 @@ import z, { ZodType } from 'zod'; import { Environment } from '../environment.js'; import { SerializationStyle } from '../serialization/base-serializer.js'; import { ContentType, HttpMethod, RequestConfig, RetryOptions, SdkConfig, ValidationOptions } from '../types.js'; -import { CreateRequestParameters, Request, RequestPagination, RequestParameter } from './request.js'; +import { + CreateRequestParameters, + Request, + RequestPagination, + RequestParameter, + ResponseDefinition, +} from './request.js'; -export class RequestBuilder { - private params: CreateRequestParameters; +export class RequestBuilder { + private params: CreateRequestParameters; constructor() { this.params = { @@ -14,10 +20,9 @@ export class RequestBuilder { method: 'GET', path: '', config: {}, - responseSchema: z.any(), + responses: [], requestSchema: z.any(), requestContentType: ContentType.Json, - responseContentType: ContentType.Json, retry: { attempts: 3, delayMs: 150, @@ -31,7 +36,7 @@ export class RequestBuilder { }; } - setRetryAttempts(sdkConfig?: SdkConfig, requestConfig?: RequestConfig): RequestBuilder { + setRetryAttempts(sdkConfig?: SdkConfig, requestConfig?: RequestConfig): RequestBuilder { if (requestConfig?.retry?.attempts !== undefined) { this.params.retry.attempts = requestConfig.retry.attempts; } else if (sdkConfig?.retry?.attempts !== undefined) { @@ -41,7 +46,7 @@ export class RequestBuilder { return this; } - setRetryDelayMs(sdkConfig?: SdkConfig, requestConfig?: RequestConfig): RequestBuilder { + setRetryDelayMs(sdkConfig?: SdkConfig, requestConfig?: RequestConfig): RequestBuilder { if (requestConfig?.retry?.delayMs !== undefined) { this.params.retry.delayMs = requestConfig.retry.delayMs; } else if (sdkConfig?.retry?.delayMs !== undefined) { @@ -51,7 +56,7 @@ export class RequestBuilder { return this; } - setResponseValidation(sdkConfig: SdkConfig, requestConfig?: RequestConfig): RequestBuilder { + setResponseValidation(sdkConfig: SdkConfig, requestConfig?: RequestConfig): RequestBuilder { if (requestConfig?.validation?.responseValidation !== undefined) { this.params.validation.responseValidation = requestConfig.validation.responseValidation; } else if (sdkConfig?.validation?.responseValidation !== undefined) { @@ -61,7 +66,7 @@ export class RequestBuilder { return this; } - setBaseUrl(sdkConfig: SdkConfig): RequestBuilder { + setBaseUrl(sdkConfig: SdkConfig): RequestBuilder { if (sdkConfig?.baseUrl !== undefined) { this.params.baseUrl = sdkConfig.baseUrl; } @@ -69,54 +74,49 @@ export class RequestBuilder { return this; } - setMethod(method: HttpMethod): RequestBuilder { + setMethod(method: HttpMethod): RequestBuilder { this.params.method = method; return this; } - setPath(path: string): RequestBuilder { + setPath(path: string): RequestBuilder { this.params.path = path; return this; } - setConfig(config: SdkConfig): RequestBuilder { + setConfig(config: SdkConfig): RequestBuilder { this.params.config = config; return this; } - setRequestContentType(contentType: ContentType): RequestBuilder { + setRequestContentType(contentType: ContentType): RequestBuilder { this.params.requestContentType = contentType; return this; } - setResponseContentType(contentType: ContentType): RequestBuilder { - this.params.responseContentType = contentType; - return this; - } - - setRequestSchema(requestSchema: ZodType): RequestBuilder { + setRequestSchema(requestSchema: ZodType): RequestBuilder { this.params.requestSchema = requestSchema; return this; } - setResponseSchema(responseSchema: ZodType): RequestBuilder { - this.params.responseSchema = responseSchema; + setPagination(pagination: RequestPagination): RequestBuilder { + this.params.pagination = pagination; return this; } - setPagination(pagination: RequestPagination): RequestBuilder { - this.params.pagination = pagination; + addResponse(response: ResponseDefinition): RequestBuilder { + this.params.responses.push(response); return this; } - addBody(body?: any): RequestBuilder { + addBody(body?: any): RequestBuilder { if (body !== undefined) { this.params.body = body; } return this; } - addPathParam(param: Partial): RequestBuilder { + addPathParam(param: Partial): RequestBuilder { if (param.value === undefined || param.key === undefined) { return this; } @@ -134,7 +134,7 @@ export class RequestBuilder { return this; } - addQueryParam(param: Partial): RequestBuilder { + addQueryParam(param: Partial): RequestBuilder { if (param.value === undefined || param.key === undefined) { return this; } @@ -152,7 +152,7 @@ export class RequestBuilder { return this; } - addHeaderParam(param: Partial): RequestBuilder { + addHeaderParam(param: Partial): RequestBuilder { if (param.value === undefined || param.key === undefined) { return this; } @@ -170,7 +170,7 @@ export class RequestBuilder { return this; } - public build(): Request { - return new Request(this.params); + public build(): Request { + return new Request(this.params); } } diff --git a/packages/user-client/src/http/transport/request-fetch-adapter.ts b/packages/user-client/src/http/transport/request-fetch-adapter.ts index 30f04f80e..36498f300 100644 --- a/packages/user-client/src/http/transport/request-fetch-adapter.ts +++ b/packages/user-client/src/http/transport/request-fetch-adapter.ts @@ -1,5 +1,6 @@ import { HttpError } from '../error.js'; import { HttpMetadata, HttpMethod, HttpResponse } from '../types.js'; +import { LineDecoder } from '../utils/line-decoder.js'; import { Request } from './request.js'; interface HttpAdapter { @@ -10,7 +11,7 @@ interface HttpAdapter { export class RequestFetchAdapter implements HttpAdapter { private requestInit: RequestInit = {}; - constructor(private request: Request) { + constructor(private request: Request) { this.setMethod(request.method); this.setHeaders(request.getHeaders()); this.setBody(request.body); @@ -53,15 +54,26 @@ export class RequestFetchAdapter implements HttpAdapter { } const reader = response.body.getReader(); + const lineDecoder = new LineDecoder(); while (true) { const { done, value } = await reader.read(); if (done) { break; } + + for (const line of lineDecoder.splitLines(value)) { + yield { + metadata, + raw: line, + }; + } + } + + for (const line of lineDecoder.flush()) { yield { metadata, - raw: value, + raw: line, }; } } diff --git a/packages/user-client/src/http/transport/request.ts b/packages/user-client/src/http/transport/request.ts index a523ff59c..e5c892f8b 100644 --- a/packages/user-client/src/http/transport/request.ts +++ b/packages/user-client/src/http/transport/request.ts @@ -7,7 +7,13 @@ import { PathSerializer } from '../serialization/path-serializer.js'; import { QuerySerializer } from '../serialization/query-serializer.js'; import { ContentType, HttpMethod, RetryOptions, SdkConfig, ValidationOptions } from '../types.js'; -export interface CreateRequestParameters { +export interface ResponseDefinition { + schema: ZodType; + contentType: ContentType; + status: number; +} + +export interface CreateRequestParameters { baseUrl: string; method: HttpMethod; body?: any; @@ -16,10 +22,9 @@ export interface CreateRequestParameters { pathParams: Map; path: string; config: SdkConfig; - responseSchema: ZodType; + responses: ResponseDefinition[]; requestSchema: ZodType; requestContentType: ContentType; - responseContentType: ContentType; validation: ValidationOptions; retry: RetryOptions; pagination?: RequestPagination; @@ -41,7 +46,7 @@ export interface RequestPagination { pageSchema?: ZodType; } -export class Request { +export class Request { public baseUrl = ''; public headers: Map = new Map(); @@ -58,14 +63,12 @@ export class Request { public config: SdkConfig; - public responseSchema: ZodType; + public responses: ResponseDefinition[]; public requestSchema: ZodType; public requestContentType: ContentType; - public responseContentType: ContentType; - public validation: ValidationOptions = {} as any; public retry: RetryOptions = {} as any; @@ -74,7 +77,7 @@ export class Request { private readonly pathPattern: string; - constructor(params: CreateRequestParameters) { + constructor(params: CreateRequestParameters) { this.baseUrl = params.baseUrl; this.method = params.method; this.pathPattern = params.path; @@ -84,10 +87,9 @@ export class Request { this.pathParams = params.pathParams; this.headers = params.headers; this.queryParams = params.queryParams; - this.responseSchema = params.responseSchema; + this.responses = params.responses; this.requestSchema = params.requestSchema; this.requestContentType = params.requestContentType; - this.responseContentType = params.responseContentType; this.retry = params.retry; this.validation = params.validation; this.pagination = params.pagination; @@ -171,11 +173,13 @@ export class Request { public constructFullUrl(): string { const queryString = new QuerySerializer().serialize(this.queryParams); const path = this.constructPath(); - return `${this.baseUrl}${path}${queryString}`; + const baseUrl = this.baseUrl; + + return `${baseUrl}${path}${queryString}`; } - public copy(overrides?: Partial>) { - const createRequestParams: CreateRequestParameters = { + public copy(overrides?: Partial) { + const createRequestParams: CreateRequestParameters = { baseUrl: overrides?.baseUrl ?? this.baseUrl, method: overrides?.method ?? this.method, path: overrides?.path ?? this.path, @@ -184,14 +188,13 @@ export class Request { pathParams: overrides?.pathParams ?? this.pathParams, queryParams: overrides?.queryParams ?? this.queryParams, headers: overrides?.headers ?? this.headers, - responseSchema: overrides?.responseSchema ?? this.responseSchema, + responses: overrides?.responses ?? this.responses, requestSchema: overrides?.requestSchema ?? this.requestSchema, requestContentType: overrides?.requestContentType ?? this.requestContentType, - responseContentType: overrides?.responseContentType ?? this.responseContentType, retry: overrides?.retry ?? this.retry, validation: overrides?.validation ?? this.validation, }; - return new Request({ + return new Request({ ...createRequestParams, ...overrides, }); @@ -205,7 +208,7 @@ export class Request { return new HeaderSerializer().serialize(this.headers); } - public nextPage() { + public nextPage(): void { if (!this.pagination) { return; } @@ -230,15 +233,15 @@ export class Request { private getAllParams(): RequestParameter[] { const allParams: RequestParameter[] = []; - this.headers.forEach((val, key) => { + this.headers.forEach((val, _) => { allParams.push(val); }); - this.queryParams.forEach((val, key) => { + this.queryParams.forEach((val, _) => { allParams.push(val); }); - this.pathParams.forEach((val, key) => { + this.pathParams.forEach((val, _) => { allParams.push(val); }); diff --git a/packages/user-client/src/http/transport/transport-hook-adapter.ts b/packages/user-client/src/http/transport/transport-hook-adapter.ts index d256295d5..c2b07cef0 100644 --- a/packages/user-client/src/http/transport/transport-hook-adapter.ts +++ b/packages/user-client/src/http/transport/transport-hook-adapter.ts @@ -7,7 +7,7 @@ import { Request, RequestParameter } from './request.js'; export class TransportHookAdapter { private hook: CustomHook = new CustomHook(); - public async beforeRequest(request: Request, params: Map): Promise> { + public async beforeRequest(request: Request, params: Map): Promise { const hookRequest = this.requestToHookRequest(request); const newRequest = await this.hook.beforeRequest(hookRequest, params); @@ -26,7 +26,7 @@ export class TransportHookAdapter { } public async afterResponse( - request: Request, + request: Request, response: HttpResponse, params: Map, ): Promise> { @@ -34,16 +34,12 @@ export class TransportHookAdapter { return this.hook.afterResponse(hookRequest, response, params); } - public async onError( - request: Request, - response: HttpResponse, - params: Map, - ): Promise { + public async onError(request: Request, response: HttpResponse, params: Map): Promise { const hookRequest = this.requestToHookRequest(request); return this.hook.onError(hookRequest, response, params); } - private requestToHookRequest(request: Request): HttpRequest { + private requestToHookRequest(request: Request): HttpRequest { const hookHeaders: Map = new Map(); request.headers.forEach((header, key) => { hookHeaders.set(key, header.value); diff --git a/packages/user-client/src/http/types.ts b/packages/user-client/src/http/types.ts index fb17dafc7..5fc1ccbc1 100644 --- a/packages/user-client/src/http/types.ts +++ b/packages/user-client/src/http/types.ts @@ -29,8 +29,8 @@ export interface HttpResponse { export interface RequestHandler { next?: RequestHandler; - handle(request: Request): Promise>; - stream(request: Request): AsyncGenerator>; + handle(request: Request): Promise>; + stream(request: Request): AsyncGenerator>; } export enum ContentType { @@ -44,6 +44,7 @@ export enum ContentType { Text = 'text', MultipartFormData = 'multipartFormData', EventStream = 'eventStream', + NoContent = 'noContent', } export interface Options { diff --git a/packages/user-client/src/http/utils/line-decoder.ts b/packages/user-client/src/http/utils/line-decoder.ts new file mode 100644 index 000000000..822414b87 --- /dev/null +++ b/packages/user-client/src/http/utils/line-decoder.ts @@ -0,0 +1,35 @@ +export class LineDecoder { + private lineBuffer = ''; + private decoder = new TextDecoder(); + private encoder = new TextEncoder(); + + /** + * Splits the given chunk into lines. + * Stores incomplete lines in a buffer and returns them when the next chunk arrives. + */ + public splitLines(chunk: Uint8Array): Uint8Array[] { + this.lineBuffer += this.decoder.decode(chunk); + + let lineEndIndex; + const lines: Uint8Array[] = []; + while ((lineEndIndex = this.lineBuffer.indexOf('\n')) >= 0) { + const line = this.lineBuffer.slice(0, lineEndIndex + 1); // Include the newline character + this.lineBuffer = this.lineBuffer.slice(lineEndIndex + 1); + if (line.length > 1) { + lines.push(this.encoder.encode(line)); + } + } + + return lines; + } + + /** Returns the remaining lines in the buffer. */ + public flush(): Uint8Array[] { + if (this.lineBuffer.length === 0) { + return []; + } + const lines = [this.encoder.encode(this.lineBuffer)]; + this.lineBuffer = ''; + return lines; + } +} diff --git a/packages/user-client/src/http/utils/response-matcher.ts b/packages/user-client/src/http/utils/response-matcher.ts new file mode 100644 index 000000000..70af48c92 --- /dev/null +++ b/packages/user-client/src/http/utils/response-matcher.ts @@ -0,0 +1,56 @@ +import { ResponseDefinition } from '../transport/request.js'; +import { ContentType, HttpResponse } from '../types.js'; + +export class ResponseMatcher { + constructor(private responses: ResponseDefinition[]) {} + + public getResponseDefinition(response: HttpResponse): ResponseDefinition | undefined { + const rawContentType = response.metadata.headers['content-type']?.toLocaleLowerCase() || ''; + const contentType = this.getContentTypeDefinition(rawContentType); + const statusCode = response.metadata.status; + + if (!this.responses.length) { + return; + } + + if (this.responses.length === 1) { + return this.responses[0]; + } + + return this.responses.find((response) => { + return response.contentType === contentType && response.status === statusCode; + }); + } + + private getContentTypeDefinition(contentType: string): ContentType { + if (contentType.startsWith('application/') && contentType.includes('xml')) { + return ContentType.Xml; + } + + if (contentType.toLowerCase() === 'application/x-www-form-urlencoded') { + return ContentType.FormUrlEncoded; + } + + if (contentType.toLowerCase() === 'text/event-stream') { + return ContentType.EventStream; + } + + if (contentType.toLowerCase().startsWith('text/')) { + return ContentType.Text; + } + + if (contentType.toLowerCase().startsWith('image/')) { + return ContentType.Image; + } + + if (contentType.toLowerCase() === 'application/octet-stream') { + return ContentType.Binary; + } + + if (contentType.toLowerCase() === 'application/json') { + return ContentType.Json; + } + + return ContentType.Json; + } +} diff --git a/packages/user-client/src/services/channels/channels.ts b/packages/user-client/src/services/channels/channels.ts index b12a0d92c..0610206b6 100644 --- a/packages/user-client/src/services/channels/channels.ts +++ b/packages/user-client/src/services/channels/channels.ts @@ -6,38 +6,38 @@ import { ContentType, HttpResponse, RequestConfig } from '../../http/types.js'; import { BaseService } from '../base-service.js'; import { WebPushToken, webPushTokenRequest, webPushTokenResponse } from '../common/web-push-token.js'; import { ApnsToken, apnsTokenRequest, apnsTokenResponse } from './models/apns-token.js'; +import { ApnsTokenResponse1, apnsTokenResponse1Response } from './models/apns-token-response-1.js'; import { - ArrayOfMetadataApnsTokens, - arrayOfMetadataApnsTokensResponse, -} from './models/array-of-metadata-apns-tokens.js'; + ArrayOfApnsTokenResponses, + arrayOfApnsTokenResponsesResponse, +} from './models/array-of-apns-token-responses.js'; import { - ArrayOfMetadataExpoTokens, - arrayOfMetadataExpoTokensResponse, -} from './models/array-of-metadata-expo-tokens.js'; -import { ArrayOfMetadataFcmTokens, arrayOfMetadataFcmTokensResponse } from './models/array-of-metadata-fcm-tokens.js'; + ArrayOfExpoTokenResponses, + arrayOfExpoTokenResponsesResponse, +} from './models/array-of-expo-token-responses.js'; +import { ArrayOfFcmTokenResponses, arrayOfFcmTokenResponsesResponse } from './models/array-of-fcm-token-responses.js'; import { - ArrayOfMetadataSlackTokens, - arrayOfMetadataSlackTokensResponse, -} from './models/array-of-metadata-slack-tokens.js'; + ArrayOfSlackTokenResponses, + arrayOfSlackTokenResponsesResponse, +} from './models/array-of-slack-token-responses.js'; import { - ArrayOfMetadataTeamsTokens, - arrayOfMetadataTeamsTokensResponse, -} from './models/array-of-metadata-teams-tokens.js'; + ArrayOfTeamsTokenResponses, + arrayOfTeamsTokenResponsesResponse, +} from './models/array-of-teams-token-responses.js'; import { - ArrayOfMetadataWebPushTokens, - arrayOfMetadataWebPushTokensResponse, -} from './models/array-of-metadata-web-push-tokens.js'; + ArrayOfWebPushTokenResponses, + arrayOfWebPushTokenResponsesResponse, +} from './models/array-of-web-push-token-responses.js'; import { DiscardResult, discardResultResponse } from './models/discard-result.js'; import { ExpoToken, expoTokenRequest, expoTokenResponse } from './models/expo-token.js'; +import { ExpoTokenResponse1, expoTokenResponse1Response } from './models/expo-token-response-1.js'; import { FcmToken, fcmTokenRequest, fcmTokenResponse } from './models/fcm-token.js'; -import { MetadataApnsToken, metadataApnsTokenResponse } from './models/metadata-apns-token.js'; -import { MetadataExpoToken, metadataExpoTokenResponse } from './models/metadata-expo-token.js'; -import { MetadataFcmToken, metadataFcmTokenResponse } from './models/metadata-fcm-token.js'; -import { MetadataSlackToken, metadataSlackTokenResponse } from './models/metadata-slack-token.js'; -import { MetadataTeamsToken, metadataTeamsTokenResponse } from './models/metadata-teams-token.js'; -import { MetadataWebPushToken, metadataWebPushTokenResponse } from './models/metadata-web-push-token.js'; +import { FcmTokenResponse1, fcmTokenResponse1Response } from './models/fcm-token-response-1.js'; import { SlackToken, slackTokenRequest, slackTokenResponse } from './models/slack-token.js'; +import { SlackTokenResponse1, slackTokenResponse1Response } from './models/slack-token-response-1.js'; import { TeamsToken, teamsTokenRequest, teamsTokenResponse } from './models/teams-token.js'; +import { TeamsTokenResponse1, teamsTokenResponse1Response } from './models/teams-token-response-1.js'; +import { WebPushTokenResponse, webPushTokenResponseResponse } from './models/web-push-token-response.js'; import { GetMobilePushApnsTokensParams, GetMobilePushExpoTokensParams, @@ -53,21 +53,24 @@ export class ChannelsService extends BaseService { * @param {number} [pageSize] - * @param {string} [pageAfter] - * @param {string} [pageBefore] - - * @returns {Promise>} OK + * @returns {Promise>} OK */ async getMobilePushApnsTokens( params?: GetMobilePushApnsTokensParams, requestConfig?: RequestConfig, - ): Promise> { - const request = new RequestBuilder() + ): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/channels/mobile_push/apns/tokens') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfMetadataApnsTokensResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfApnsTokenResponsesResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -84,7 +87,7 @@ export class ChannelsService extends BaseService { value: params?.pageBefore, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -92,15 +95,18 @@ export class ChannelsService extends BaseService { * @returns {Promise>} Created */ async saveMobilePushApnsToken(body: ApnsToken, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('POST') .setPath('/channels/mobile_push/apns/tokens') .setRequestSchema(apnsTokenRequest) - .setResponseSchema(apnsTokenResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: apnsTokenResponse, + contentType: ContentType.Json, + status: 201, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -113,21 +119,24 @@ export class ChannelsService extends BaseService { /** * Retrieves details of a specific mobile_push token belonging to the authenticated user. Returns information about the token's status, creation date, and any associated metadata. Users can only access their own tokens. * @param {string} tokenId - - * @returns {Promise>} OK + * @returns {Promise>} OK */ async getMobilePushApnsToken( tokenId: string, requestConfig?: RequestConfig, - ): Promise> { - const request = new RequestBuilder() + ): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/channels/mobile_push/apns/tokens/{token_id}') .setRequestSchema(z.any()) - .setResponseSchema(metadataApnsTokenResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: apnsTokenResponse1Response, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -136,7 +145,7 @@ export class ChannelsService extends BaseService { value: tokenId, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -148,15 +157,18 @@ export class ChannelsService extends BaseService { tokenId: string, requestConfig?: RequestConfig, ): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/channels/mobile_push/apns/tokens/{token_id}') .setRequestSchema(z.any()) - .setResponseSchema(discardResultResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: discardResultResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -173,21 +185,24 @@ export class ChannelsService extends BaseService { * @param {number} [pageSize] - * @param {string} [pageAfter] - * @param {string} [pageBefore] - - * @returns {Promise>} OK + * @returns {Promise>} OK */ async getMobilePushExpoTokens( params?: GetMobilePushExpoTokensParams, requestConfig?: RequestConfig, - ): Promise> { - const request = new RequestBuilder() + ): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/channels/mobile_push/expo/tokens') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfMetadataExpoTokensResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfExpoTokenResponsesResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -204,7 +219,7 @@ export class ChannelsService extends BaseService { value: params?.pageBefore, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -212,15 +227,18 @@ export class ChannelsService extends BaseService { * @returns {Promise>} Created */ async saveMobilePushExpoToken(body: ExpoToken, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('POST') .setPath('/channels/mobile_push/expo/tokens') .setRequestSchema(expoTokenRequest) - .setResponseSchema(expoTokenResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: expoTokenResponse, + contentType: ContentType.Json, + status: 201, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -233,21 +251,24 @@ export class ChannelsService extends BaseService { /** * Retrieves details of a specific mobile_push token belonging to the authenticated user. Returns information about the token's status, creation date, and any associated metadata. Users can only access their own tokens. * @param {string} tokenId - - * @returns {Promise>} OK + * @returns {Promise>} OK */ async getMobilePushExpoToken( tokenId: string, requestConfig?: RequestConfig, - ): Promise> { - const request = new RequestBuilder() + ): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/channels/mobile_push/expo/tokens/{token_id}') .setRequestSchema(z.any()) - .setResponseSchema(metadataExpoTokenResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: expoTokenResponse1Response, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -256,7 +277,7 @@ export class ChannelsService extends BaseService { value: tokenId, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -268,15 +289,18 @@ export class ChannelsService extends BaseService { tokenId: string, requestConfig?: RequestConfig, ): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/channels/mobile_push/expo/tokens/{token_id}') .setRequestSchema(z.any()) - .setResponseSchema(discardResultResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: discardResultResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -293,21 +317,24 @@ export class ChannelsService extends BaseService { * @param {number} [pageSize] - * @param {string} [pageAfter] - * @param {string} [pageBefore] - - * @returns {Promise>} OK + * @returns {Promise>} OK */ async getMobilePushFcmTokens( params?: GetMobilePushFcmTokensParams, requestConfig?: RequestConfig, - ): Promise> { - const request = new RequestBuilder() + ): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/channels/mobile_push/fcm/tokens') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfMetadataFcmTokensResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfFcmTokenResponsesResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -324,7 +351,7 @@ export class ChannelsService extends BaseService { value: params?.pageBefore, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -332,15 +359,18 @@ export class ChannelsService extends BaseService { * @returns {Promise>} Created */ async saveMobilePushFcmToken(body: FcmToken, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('POST') .setPath('/channels/mobile_push/fcm/tokens') .setRequestSchema(fcmTokenRequest) - .setResponseSchema(fcmTokenResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: fcmTokenResponse, + contentType: ContentType.Json, + status: 201, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -353,18 +383,24 @@ export class ChannelsService extends BaseService { /** * Retrieves details of a specific mobile_push token belonging to the authenticated user. Returns information about the token's status, creation date, and any associated metadata. Users can only access their own tokens. * @param {string} tokenId - - * @returns {Promise>} OK + * @returns {Promise>} OK */ - async getMobilePushFcmToken(tokenId: string, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async getMobilePushFcmToken( + tokenId: string, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/channels/mobile_push/fcm/tokens/{token_id}') .setRequestSchema(z.any()) - .setResponseSchema(metadataFcmTokenResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: fcmTokenResponse1Response, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -373,7 +409,7 @@ export class ChannelsService extends BaseService { value: tokenId, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -385,15 +421,18 @@ export class ChannelsService extends BaseService { tokenId: string, requestConfig?: RequestConfig, ): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/channels/mobile_push/fcm/tokens/{token_id}') .setRequestSchema(z.any()) - .setResponseSchema(discardResultResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: discardResultResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -410,21 +449,24 @@ export class ChannelsService extends BaseService { * @param {number} [pageSize] - * @param {string} [pageAfter] - * @param {string} [pageBefore] - - * @returns {Promise>} OK + * @returns {Promise>} OK */ async getSlackTokens( params?: GetSlackTokensParams, requestConfig?: RequestConfig, - ): Promise> { - const request = new RequestBuilder() + ): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/channels/slack/tokens') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfMetadataSlackTokensResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfSlackTokenResponsesResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -441,7 +483,7 @@ export class ChannelsService extends BaseService { value: params?.pageBefore, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -449,15 +491,18 @@ export class ChannelsService extends BaseService { * @returns {Promise>} Created */ async saveSlackToken(body: SlackToken, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('POST') .setPath('/channels/slack/tokens') .setRequestSchema(slackTokenRequest) - .setResponseSchema(slackTokenResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: slackTokenResponse, + contentType: ContentType.Json, + status: 201, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -470,18 +515,21 @@ export class ChannelsService extends BaseService { /** * Retrieves details of a specific slack token belonging to the authenticated user. Returns information about the token's status, creation date, and any associated metadata. Users can only access their own tokens. * @param {string} tokenId - - * @returns {Promise>} OK + * @returns {Promise>} OK */ - async getSlackToken(tokenId: string, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async getSlackToken(tokenId: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/channels/slack/tokens/{token_id}') .setRequestSchema(z.any()) - .setResponseSchema(metadataSlackTokenResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: slackTokenResponse1Response, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -490,7 +538,7 @@ export class ChannelsService extends BaseService { value: tokenId, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -499,15 +547,18 @@ export class ChannelsService extends BaseService { * @returns {Promise>} OK */ async discardSlackToken(tokenId: string, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/channels/slack/tokens/{token_id}') .setRequestSchema(z.any()) - .setResponseSchema(discardResultResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: discardResultResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -524,21 +575,24 @@ export class ChannelsService extends BaseService { * @param {number} [pageSize] - * @param {string} [pageAfter] - * @param {string} [pageBefore] - - * @returns {Promise>} OK + * @returns {Promise>} OK */ async getTeamsTokens( params?: GetTeamsTokensParams, requestConfig?: RequestConfig, - ): Promise> { - const request = new RequestBuilder() + ): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/channels/teams/tokens') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfMetadataTeamsTokensResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfTeamsTokenResponsesResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -555,7 +609,7 @@ export class ChannelsService extends BaseService { value: params?.pageBefore, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -563,15 +617,18 @@ export class ChannelsService extends BaseService { * @returns {Promise>} Created */ async saveTeamsToken(body: TeamsToken, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('POST') .setPath('/channels/teams/tokens') .setRequestSchema(teamsTokenRequest) - .setResponseSchema(teamsTokenResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: teamsTokenResponse, + contentType: ContentType.Json, + status: 201, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -584,18 +641,21 @@ export class ChannelsService extends BaseService { /** * Retrieves details of a specific teams token belonging to the authenticated user. Returns information about the token's status, creation date, and any associated metadata. Users can only access their own tokens. * @param {string} tokenId - - * @returns {Promise>} OK + * @returns {Promise>} OK */ - async getTeamsToken(tokenId: string, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async getTeamsToken(tokenId: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/channels/teams/tokens/{token_id}') .setRequestSchema(z.any()) - .setResponseSchema(metadataTeamsTokenResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: teamsTokenResponse1Response, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -604,7 +664,7 @@ export class ChannelsService extends BaseService { value: tokenId, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -613,15 +673,18 @@ export class ChannelsService extends BaseService { * @returns {Promise>} OK */ async discardTeamsToken(tokenId: string, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/channels/teams/tokens/{token_id}') .setRequestSchema(z.any()) - .setResponseSchema(discardResultResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: discardResultResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -638,21 +701,24 @@ export class ChannelsService extends BaseService { * @param {number} [pageSize] - * @param {string} [pageAfter] - * @param {string} [pageBefore] - - * @returns {Promise>} OK + * @returns {Promise>} OK */ async getWebPushTokens( params?: GetWebPushTokensParams, requestConfig?: RequestConfig, - ): Promise> { - const request = new RequestBuilder() + ): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/channels/web_push/tokens') .setRequestSchema(z.any()) - .setResponseSchema(arrayOfMetadataWebPushTokensResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: arrayOfWebPushTokenResponsesResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -669,7 +735,7 @@ export class ChannelsService extends BaseService { value: params?.pageBefore, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -677,15 +743,18 @@ export class ChannelsService extends BaseService { * @returns {Promise>} Created */ async saveWebPushToken(body: WebPushToken, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('POST') .setPath('/channels/web_push/tokens') .setRequestSchema(webPushTokenRequest) - .setResponseSchema(webPushTokenResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: webPushTokenResponse, + contentType: ContentType.Json, + status: 201, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -698,18 +767,21 @@ export class ChannelsService extends BaseService { /** * Retrieves details of a specific web_push token belonging to the authenticated user. Returns information about the token's status, creation date, and any associated metadata. Users can only access their own tokens. * @param {string} tokenId - - * @returns {Promise>} OK + * @returns {Promise>} OK */ - async getWebPushToken(tokenId: string, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + async getWebPushToken(tokenId: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('GET') .setPath('/channels/web_push/tokens/{token_id}') .setRequestSchema(z.any()) - .setResponseSchema(metadataWebPushTokenResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: webPushTokenResponseResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -718,7 +790,7 @@ export class ChannelsService extends BaseService { value: tokenId, }) .build(); - return this.client.call(request); + return this.client.call(request); } /** @@ -727,15 +799,18 @@ export class ChannelsService extends BaseService { * @returns {Promise>} OK */ async discardWebPushToken(tokenId: string, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('DELETE') .setPath('/channels/web_push/tokens/{token_id}') .setRequestSchema(z.any()) - .setResponseSchema(discardResultResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: discardResultResponse, + contentType: ContentType.Json, + status: 200, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) diff --git a/packages/user-client/src/services/channels/models/apns-token-response-1.ts b/packages/user-client/src/services/channels/models/apns-token-response-1.ts new file mode 100644 index 000000000..57a66133e --- /dev/null +++ b/packages/user-client/src/services/channels/models/apns-token-response-1.ts @@ -0,0 +1,87 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const apnsTokenResponse1 = z.lazy(() => { + return z.object({ + appId: z + .string() + .regex(/^[a-zA-Z0-9]+(.[a-zA-Z0-9]+)*$/) + .optional(), + createdAt: z.string(), + deviceToken: z.string().min(64), + discardedAt: z.string().optional().nullable(), + id: z.string(), + installationId: z.string().optional(), + updatedAt: z.string().optional().nullable(), + }); +}); + +/** + * + * @typedef {ApnsTokenResponse1} apnsTokenResponse1 + * @property {string} - (Optional) The bundle identifier of the application that is registering this token. Use this field to override the default identifier specified in the projects APNs integration. + * @property {string} + * @property {string} + * @property {string} + * @property {string} + * @property {ApnsTokenResponseInstallationId} - (Optional) The APNs environment the token is registered for. If none is provided we assume the token is used in `production`. + * @property {string} + */ +export type ApnsTokenResponse1 = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const apnsTokenResponse1Response = z.lazy(() => { + return z + .object({ + app_id: z + .string() + .regex(/^[a-zA-Z0-9]+(.[a-zA-Z0-9]+)*$/) + .optional(), + created_at: z.string(), + device_token: z.string().min(64), + discarded_at: z.string().optional().nullable(), + id: z.string(), + installation_id: z.string().optional(), + updated_at: z.string().optional().nullable(), + }) + .transform((data) => ({ + appId: data['app_id'], + createdAt: data['created_at'], + deviceToken: data['device_token'], + discardedAt: data['discarded_at'], + id: data['id'], + installationId: data['installation_id'], + updatedAt: data['updated_at'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const apnsTokenResponse1Request = z.lazy(() => { + return z + .object({ + appId: z.string().nullish(), + createdAt: z.string().nullish(), + deviceToken: z.string().nullish(), + discardedAt: z.string().nullish(), + id: z.string().nullish(), + installationId: z.string().nullish(), + updatedAt: z.string().nullish(), + }) + .transform((data) => ({ + app_id: data['appId'], + created_at: data['createdAt'], + device_token: data['deviceToken'], + discarded_at: data['discardedAt'], + id: data['id'], + installation_id: data['installationId'], + updated_at: data['updatedAt'], + })); +}); diff --git a/packages/user-client/src/services/channels/models/apns-token-response-installation-id.ts b/packages/user-client/src/services/channels/models/apns-token-response-installation-id.ts new file mode 100644 index 000000000..3de2f2c7c --- /dev/null +++ b/packages/user-client/src/services/channels/models/apns-token-response-installation-id.ts @@ -0,0 +1,6 @@ +import { z } from 'zod'; + +export enum ApnsTokenResponseInstallationId { + DEVELOPMENT = 'development', + PRODUCTION = 'production', +} diff --git a/packages/user-client/src/services/channels/models/array-of-metadata-teams-tokens.ts b/packages/user-client/src/services/channels/models/array-of-apns-token-responses.ts similarity index 57% rename from packages/user-client/src/services/channels/models/array-of-metadata-teams-tokens.ts rename to packages/user-client/src/services/channels/models/array-of-apns-token-responses.ts index fb05e6d4f..f5a5b7db5 100644 --- a/packages/user-client/src/services/channels/models/array-of-metadata-teams-tokens.ts +++ b/packages/user-client/src/services/channels/models/array-of-apns-token-responses.ts @@ -1,34 +1,34 @@ import { z } from 'zod'; +import { apnsTokenResponse1, apnsTokenResponse1Request, apnsTokenResponse1Response } from './apns-token-response-1.js'; import { links, linksRequest, linksResponse } from './links.js'; -import { metadataTeamsToken, metadataTeamsTokenRequest, metadataTeamsTokenResponse } from './metadata-teams-token.js'; /** * The shape of the model inside the application code - what the users use */ -export const arrayOfMetadataTeamsTokens = z.lazy(() => { +export const arrayOfApnsTokenResponses = z.lazy(() => { return z.object({ - data: z.array(metadataTeamsToken).optional(), + data: z.array(apnsTokenResponse1).optional(), links: links.optional(), }); }); /** * - * @typedef {ArrayOfMetadataTeamsTokens} arrayOfMetadataTeamsTokens - * @property {MetadataTeamsToken[]} + * @typedef {ArrayOfApnsTokenResponses} arrayOfApnsTokenResponses + * @property {ApnsTokenResponse1[]} * @property {Links} */ -export type ArrayOfMetadataTeamsTokens = z.infer; +export type ArrayOfApnsTokenResponses = z.infer; /** * The shape of the model mapping from the api schema into the application shape. * Is equal to application shape if all property names match the api schema */ -export const arrayOfMetadataTeamsTokensResponse = z.lazy(() => { +export const arrayOfApnsTokenResponsesResponse = z.lazy(() => { return z .object({ - data: z.array(metadataTeamsTokenResponse).optional(), + data: z.array(apnsTokenResponse1Response).optional(), links: linksResponse.optional(), }) .transform((data) => ({ @@ -41,9 +41,9 @@ export const arrayOfMetadataTeamsTokensResponse = z.lazy(() => { * The shape of the model mapping from the application shape into the api schema. * Is equal to application shape if all property names match the api schema */ -export const arrayOfMetadataTeamsTokensRequest = z.lazy(() => { +export const arrayOfApnsTokenResponsesRequest = z.lazy(() => { return z - .object({ data: z.array(metadataTeamsTokenRequest).nullish(), links: linksRequest.nullish() }) + .object({ data: z.array(apnsTokenResponse1Request).nullish(), links: linksRequest.nullish() }) .transform((data) => ({ data: data['data'], links: data['links'], diff --git a/packages/user-client/src/services/channels/models/array-of-metadata-slack-tokens.ts b/packages/user-client/src/services/channels/models/array-of-expo-token-responses.ts similarity index 57% rename from packages/user-client/src/services/channels/models/array-of-metadata-slack-tokens.ts rename to packages/user-client/src/services/channels/models/array-of-expo-token-responses.ts index d0f0ddc0c..f1eab830c 100644 --- a/packages/user-client/src/services/channels/models/array-of-metadata-slack-tokens.ts +++ b/packages/user-client/src/services/channels/models/array-of-expo-token-responses.ts @@ -1,34 +1,34 @@ import { z } from 'zod'; +import { expoTokenResponse1, expoTokenResponse1Request, expoTokenResponse1Response } from './expo-token-response-1.js'; import { links, linksRequest, linksResponse } from './links.js'; -import { metadataSlackToken, metadataSlackTokenRequest, metadataSlackTokenResponse } from './metadata-slack-token.js'; /** * The shape of the model inside the application code - what the users use */ -export const arrayOfMetadataSlackTokens = z.lazy(() => { +export const arrayOfExpoTokenResponses = z.lazy(() => { return z.object({ - data: z.array(metadataSlackToken).optional(), + data: z.array(expoTokenResponse1).optional(), links: links.optional(), }); }); /** * - * @typedef {ArrayOfMetadataSlackTokens} arrayOfMetadataSlackTokens - * @property {MetadataSlackToken[]} + * @typedef {ArrayOfExpoTokenResponses} arrayOfExpoTokenResponses + * @property {ExpoTokenResponse1[]} * @property {Links} */ -export type ArrayOfMetadataSlackTokens = z.infer; +export type ArrayOfExpoTokenResponses = z.infer; /** * The shape of the model mapping from the api schema into the application shape. * Is equal to application shape if all property names match the api schema */ -export const arrayOfMetadataSlackTokensResponse = z.lazy(() => { +export const arrayOfExpoTokenResponsesResponse = z.lazy(() => { return z .object({ - data: z.array(metadataSlackTokenResponse).optional(), + data: z.array(expoTokenResponse1Response).optional(), links: linksResponse.optional(), }) .transform((data) => ({ @@ -41,9 +41,9 @@ export const arrayOfMetadataSlackTokensResponse = z.lazy(() => { * The shape of the model mapping from the application shape into the api schema. * Is equal to application shape if all property names match the api schema */ -export const arrayOfMetadataSlackTokensRequest = z.lazy(() => { +export const arrayOfExpoTokenResponsesRequest = z.lazy(() => { return z - .object({ data: z.array(metadataSlackTokenRequest).nullish(), links: linksRequest.nullish() }) + .object({ data: z.array(expoTokenResponse1Request).nullish(), links: linksRequest.nullish() }) .transform((data) => ({ data: data['data'], links: data['links'], diff --git a/packages/user-client/src/services/channels/models/array-of-metadata-expo-tokens.ts b/packages/user-client/src/services/channels/models/array-of-fcm-token-responses.ts similarity index 58% rename from packages/user-client/src/services/channels/models/array-of-metadata-expo-tokens.ts rename to packages/user-client/src/services/channels/models/array-of-fcm-token-responses.ts index 8b82d8e40..7be7f214d 100644 --- a/packages/user-client/src/services/channels/models/array-of-metadata-expo-tokens.ts +++ b/packages/user-client/src/services/channels/models/array-of-fcm-token-responses.ts @@ -1,34 +1,34 @@ import { z } from 'zod'; +import { fcmTokenResponse1, fcmTokenResponse1Request, fcmTokenResponse1Response } from './fcm-token-response-1.js'; import { links, linksRequest, linksResponse } from './links.js'; -import { metadataExpoToken, metadataExpoTokenRequest, metadataExpoTokenResponse } from './metadata-expo-token.js'; /** * The shape of the model inside the application code - what the users use */ -export const arrayOfMetadataExpoTokens = z.lazy(() => { +export const arrayOfFcmTokenResponses = z.lazy(() => { return z.object({ - data: z.array(metadataExpoToken).optional(), + data: z.array(fcmTokenResponse1).optional(), links: links.optional(), }); }); /** * - * @typedef {ArrayOfMetadataExpoTokens} arrayOfMetadataExpoTokens - * @property {MetadataExpoToken[]} + * @typedef {ArrayOfFcmTokenResponses} arrayOfFcmTokenResponses + * @property {FcmTokenResponse1[]} * @property {Links} */ -export type ArrayOfMetadataExpoTokens = z.infer; +export type ArrayOfFcmTokenResponses = z.infer; /** * The shape of the model mapping from the api schema into the application shape. * Is equal to application shape if all property names match the api schema */ -export const arrayOfMetadataExpoTokensResponse = z.lazy(() => { +export const arrayOfFcmTokenResponsesResponse = z.lazy(() => { return z .object({ - data: z.array(metadataExpoTokenResponse).optional(), + data: z.array(fcmTokenResponse1Response).optional(), links: linksResponse.optional(), }) .transform((data) => ({ @@ -41,9 +41,9 @@ export const arrayOfMetadataExpoTokensResponse = z.lazy(() => { * The shape of the model mapping from the application shape into the api schema. * Is equal to application shape if all property names match the api schema */ -export const arrayOfMetadataExpoTokensRequest = z.lazy(() => { +export const arrayOfFcmTokenResponsesRequest = z.lazy(() => { return z - .object({ data: z.array(metadataExpoTokenRequest).nullish(), links: linksRequest.nullish() }) + .object({ data: z.array(fcmTokenResponse1Request).nullish(), links: linksRequest.nullish() }) .transform((data) => ({ data: data['data'], links: data['links'], diff --git a/packages/user-client/src/services/channels/models/array-of-metadata-fcm-tokens.ts b/packages/user-client/src/services/channels/models/array-of-slack-token-responses.ts similarity index 54% rename from packages/user-client/src/services/channels/models/array-of-metadata-fcm-tokens.ts rename to packages/user-client/src/services/channels/models/array-of-slack-token-responses.ts index 3346f0d7a..bd1a83283 100644 --- a/packages/user-client/src/services/channels/models/array-of-metadata-fcm-tokens.ts +++ b/packages/user-client/src/services/channels/models/array-of-slack-token-responses.ts @@ -1,34 +1,38 @@ import { z } from 'zod'; import { links, linksRequest, linksResponse } from './links.js'; -import { metadataFcmToken, metadataFcmTokenRequest, metadataFcmTokenResponse } from './metadata-fcm-token.js'; +import { + slackTokenResponse1, + slackTokenResponse1Request, + slackTokenResponse1Response, +} from './slack-token-response-1.js'; /** * The shape of the model inside the application code - what the users use */ -export const arrayOfMetadataFcmTokens = z.lazy(() => { +export const arrayOfSlackTokenResponses = z.lazy(() => { return z.object({ - data: z.array(metadataFcmToken).optional(), + data: z.array(slackTokenResponse1).optional(), links: links.optional(), }); }); /** * - * @typedef {ArrayOfMetadataFcmTokens} arrayOfMetadataFcmTokens - * @property {MetadataFcmToken[]} + * @typedef {ArrayOfSlackTokenResponses} arrayOfSlackTokenResponses + * @property {SlackTokenResponse1[]} * @property {Links} */ -export type ArrayOfMetadataFcmTokens = z.infer; +export type ArrayOfSlackTokenResponses = z.infer; /** * The shape of the model mapping from the api schema into the application shape. * Is equal to application shape if all property names match the api schema */ -export const arrayOfMetadataFcmTokensResponse = z.lazy(() => { +export const arrayOfSlackTokenResponsesResponse = z.lazy(() => { return z .object({ - data: z.array(metadataFcmTokenResponse).optional(), + data: z.array(slackTokenResponse1Response).optional(), links: linksResponse.optional(), }) .transform((data) => ({ @@ -41,9 +45,9 @@ export const arrayOfMetadataFcmTokensResponse = z.lazy(() => { * The shape of the model mapping from the application shape into the api schema. * Is equal to application shape if all property names match the api schema */ -export const arrayOfMetadataFcmTokensRequest = z.lazy(() => { +export const arrayOfSlackTokenResponsesRequest = z.lazy(() => { return z - .object({ data: z.array(metadataFcmTokenRequest).nullish(), links: linksRequest.nullish() }) + .object({ data: z.array(slackTokenResponse1Request).nullish(), links: linksRequest.nullish() }) .transform((data) => ({ data: data['data'], links: data['links'], diff --git a/packages/user-client/src/services/channels/models/array-of-metadata-apns-tokens.ts b/packages/user-client/src/services/channels/models/array-of-teams-token-responses.ts similarity index 54% rename from packages/user-client/src/services/channels/models/array-of-metadata-apns-tokens.ts rename to packages/user-client/src/services/channels/models/array-of-teams-token-responses.ts index a480b6d96..e1b2282a5 100644 --- a/packages/user-client/src/services/channels/models/array-of-metadata-apns-tokens.ts +++ b/packages/user-client/src/services/channels/models/array-of-teams-token-responses.ts @@ -1,34 +1,38 @@ import { z } from 'zod'; import { links, linksRequest, linksResponse } from './links.js'; -import { metadataApnsToken, metadataApnsTokenRequest, metadataApnsTokenResponse } from './metadata-apns-token.js'; +import { + teamsTokenResponse1, + teamsTokenResponse1Request, + teamsTokenResponse1Response, +} from './teams-token-response-1.js'; /** * The shape of the model inside the application code - what the users use */ -export const arrayOfMetadataApnsTokens = z.lazy(() => { +export const arrayOfTeamsTokenResponses = z.lazy(() => { return z.object({ - data: z.array(metadataApnsToken).optional(), + data: z.array(teamsTokenResponse1).optional(), links: links.optional(), }); }); /** * - * @typedef {ArrayOfMetadataApnsTokens} arrayOfMetadataApnsTokens - * @property {MetadataApnsToken[]} + * @typedef {ArrayOfTeamsTokenResponses} arrayOfTeamsTokenResponses + * @property {TeamsTokenResponse1[]} * @property {Links} */ -export type ArrayOfMetadataApnsTokens = z.infer; +export type ArrayOfTeamsTokenResponses = z.infer; /** * The shape of the model mapping from the api schema into the application shape. * Is equal to application shape if all property names match the api schema */ -export const arrayOfMetadataApnsTokensResponse = z.lazy(() => { +export const arrayOfTeamsTokenResponsesResponse = z.lazy(() => { return z .object({ - data: z.array(metadataApnsTokenResponse).optional(), + data: z.array(teamsTokenResponse1Response).optional(), links: linksResponse.optional(), }) .transform((data) => ({ @@ -41,9 +45,9 @@ export const arrayOfMetadataApnsTokensResponse = z.lazy(() => { * The shape of the model mapping from the application shape into the api schema. * Is equal to application shape if all property names match the api schema */ -export const arrayOfMetadataApnsTokensRequest = z.lazy(() => { +export const arrayOfTeamsTokenResponsesRequest = z.lazy(() => { return z - .object({ data: z.array(metadataApnsTokenRequest).nullish(), links: linksRequest.nullish() }) + .object({ data: z.array(teamsTokenResponse1Request).nullish(), links: linksRequest.nullish() }) .transform((data) => ({ data: data['data'], links: data['links'], diff --git a/packages/user-client/src/services/channels/models/array-of-metadata-web-push-tokens.ts b/packages/user-client/src/services/channels/models/array-of-web-push-token-responses.ts similarity index 57% rename from packages/user-client/src/services/channels/models/array-of-metadata-web-push-tokens.ts rename to packages/user-client/src/services/channels/models/array-of-web-push-token-responses.ts index d1ac5a1fe..7bbaa3204 100644 --- a/packages/user-client/src/services/channels/models/array-of-metadata-web-push-tokens.ts +++ b/packages/user-client/src/services/channels/models/array-of-web-push-token-responses.ts @@ -2,37 +2,37 @@ import { z } from 'zod'; import { links, linksRequest, linksResponse } from './links.js'; import { - metadataWebPushToken, - metadataWebPushTokenRequest, - metadataWebPushTokenResponse, -} from './metadata-web-push-token.js'; + webPushTokenResponse, + webPushTokenResponseRequest, + webPushTokenResponseResponse, +} from './web-push-token-response.js'; /** * The shape of the model inside the application code - what the users use */ -export const arrayOfMetadataWebPushTokens = z.lazy(() => { +export const arrayOfWebPushTokenResponses = z.lazy(() => { return z.object({ - data: z.array(metadataWebPushToken).optional(), + data: z.array(webPushTokenResponse).optional(), links: links.optional(), }); }); /** * - * @typedef {ArrayOfMetadataWebPushTokens} arrayOfMetadataWebPushTokens - * @property {MetadataWebPushToken[]} + * @typedef {ArrayOfWebPushTokenResponses} arrayOfWebPushTokenResponses + * @property {WebPushTokenResponse[]} * @property {Links} */ -export type ArrayOfMetadataWebPushTokens = z.infer; +export type ArrayOfWebPushTokenResponses = z.infer; /** * The shape of the model mapping from the api schema into the application shape. * Is equal to application shape if all property names match the api schema */ -export const arrayOfMetadataWebPushTokensResponse = z.lazy(() => { +export const arrayOfWebPushTokenResponsesResponse = z.lazy(() => { return z .object({ - data: z.array(metadataWebPushTokenResponse).optional(), + data: z.array(webPushTokenResponseResponse).optional(), links: linksResponse.optional(), }) .transform((data) => ({ @@ -45,9 +45,9 @@ export const arrayOfMetadataWebPushTokensResponse = z.lazy(() => { * The shape of the model mapping from the application shape into the api schema. * Is equal to application shape if all property names match the api schema */ -export const arrayOfMetadataWebPushTokensRequest = z.lazy(() => { +export const arrayOfWebPushTokenResponsesRequest = z.lazy(() => { return z - .object({ data: z.array(metadataWebPushTokenRequest).nullish(), links: linksRequest.nullish() }) + .object({ data: z.array(webPushTokenResponseRequest).nullish(), links: linksRequest.nullish() }) .transform((data) => ({ data: data['data'], links: data['links'], diff --git a/packages/project-client/src/services/channels/models/token-metadata.ts b/packages/user-client/src/services/channels/models/expo-token-response-1.ts similarity index 74% rename from packages/project-client/src/services/channels/models/token-metadata.ts rename to packages/user-client/src/services/channels/models/expo-token-response-1.ts index d1d75bf41..346b54345 100644 --- a/packages/project-client/src/services/channels/models/token-metadata.ts +++ b/packages/user-client/src/services/channels/models/expo-token-response-1.ts @@ -3,9 +3,10 @@ import { z } from 'zod'; /** * The shape of the model inside the application code - what the users use */ -export const tokenMetadata = z.lazy(() => { +export const expoTokenResponse1 = z.lazy(() => { return z.object({ createdAt: z.string(), + deviceToken: z.string().min(1), discardedAt: z.string().optional().nullable(), id: z.string(), updatedAt: z.string().optional().nullable(), @@ -14,28 +15,31 @@ export const tokenMetadata = z.lazy(() => { /** * - * @typedef {TokenMetadata} tokenMetadata + * @typedef {ExpoTokenResponse1} expoTokenResponse1 + * @property {string} * @property {string} * @property {string} * @property {string} * @property {string} */ -export type TokenMetadata = z.infer; +export type ExpoTokenResponse1 = z.infer; /** * The shape of the model mapping from the api schema into the application shape. * Is equal to application shape if all property names match the api schema */ -export const tokenMetadataResponse = z.lazy(() => { +export const expoTokenResponse1Response = z.lazy(() => { return z .object({ created_at: z.string(), + device_token: z.string().min(1), discarded_at: z.string().optional().nullable(), id: z.string(), updated_at: z.string().optional().nullable(), }) .transform((data) => ({ createdAt: data['created_at'], + deviceToken: data['device_token'], discardedAt: data['discarded_at'], id: data['id'], updatedAt: data['updated_at'], @@ -46,16 +50,18 @@ export const tokenMetadataResponse = z.lazy(() => { * The shape of the model mapping from the application shape into the api schema. * Is equal to application shape if all property names match the api schema */ -export const tokenMetadataRequest = z.lazy(() => { +export const expoTokenResponse1Request = z.lazy(() => { return z .object({ createdAt: z.string().nullish(), + deviceToken: z.string().nullish(), discardedAt: z.string().nullish(), id: z.string().nullish(), updatedAt: z.string().nullish(), }) .transform((data) => ({ created_at: data['createdAt'], + device_token: data['deviceToken'], discarded_at: data['discardedAt'], id: data['id'], updated_at: data['updatedAt'], diff --git a/packages/user-client/src/services/channels/models/fcm-token-response-1.ts b/packages/user-client/src/services/channels/models/fcm-token-response-1.ts new file mode 100644 index 000000000..105da82fa --- /dev/null +++ b/packages/user-client/src/services/channels/models/fcm-token-response-1.ts @@ -0,0 +1,75 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const fcmTokenResponse1 = z.lazy(() => { + return z.object({ + createdAt: z.string(), + deviceToken: z.string().min(64), + discardedAt: z.string().optional().nullable(), + id: z.string(), + installationId: z.string().optional(), + updatedAt: z.string().optional().nullable(), + }); +}); + +/** + * + * @typedef {FcmTokenResponse1} fcmTokenResponse1 + * @property {string} + * @property {string} + * @property {string} + * @property {string} + * @property {FcmTokenResponseInstallationId} + * @property {string} + */ +export type FcmTokenResponse1 = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const fcmTokenResponse1Response = z.lazy(() => { + return z + .object({ + created_at: z.string(), + device_token: z.string().min(64), + discarded_at: z.string().optional().nullable(), + id: z.string(), + installation_id: z.string().optional(), + updated_at: z.string().optional().nullable(), + }) + .transform((data) => ({ + createdAt: data['created_at'], + deviceToken: data['device_token'], + discardedAt: data['discarded_at'], + id: data['id'], + installationId: data['installation_id'], + updatedAt: data['updated_at'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const fcmTokenResponse1Request = z.lazy(() => { + return z + .object({ + createdAt: z.string().nullish(), + deviceToken: z.string().nullish(), + discardedAt: z.string().nullish(), + id: z.string().nullish(), + installationId: z.string().nullish(), + updatedAt: z.string().nullish(), + }) + .transform((data) => ({ + created_at: data['createdAt'], + device_token: data['deviceToken'], + discarded_at: data['discardedAt'], + id: data['id'], + installation_id: data['installationId'], + updated_at: data['updatedAt'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/apns-token-installation-id.ts b/packages/user-client/src/services/channels/models/fcm-token-response-installation-id.ts similarity index 66% rename from packages/project-client/src/services/channels/models/apns-token-installation-id.ts rename to packages/user-client/src/services/channels/models/fcm-token-response-installation-id.ts index a3cc702cf..fccf7993f 100644 --- a/packages/project-client/src/services/channels/models/apns-token-installation-id.ts +++ b/packages/user-client/src/services/channels/models/fcm-token-response-installation-id.ts @@ -1,6 +1,6 @@ import { z } from 'zod'; -export enum ApnsTokenInstallationId { +export enum FcmTokenResponseInstallationId { DEVELOPMENT = 'development', PRODUCTION = 'production', } diff --git a/packages/user-client/src/services/channels/models/index.ts b/packages/user-client/src/services/channels/models/index.ts index 5ae739ffc..3a114570f 100644 --- a/packages/user-client/src/services/channels/models/index.ts +++ b/packages/user-client/src/services/channels/models/index.ts @@ -1,25 +1,30 @@ export type { ApnsToken } from './apns-token.js'; export { ApnsTokenInstallationId } from './apns-token-installation-id.js'; -export type { ArrayOfMetadataApnsTokens } from './array-of-metadata-apns-tokens.js'; -export type { ArrayOfMetadataExpoTokens } from './array-of-metadata-expo-tokens.js'; -export type { ArrayOfMetadataFcmTokens } from './array-of-metadata-fcm-tokens.js'; -export type { ArrayOfMetadataSlackTokens } from './array-of-metadata-slack-tokens.js'; -export type { ArrayOfMetadataTeamsTokens } from './array-of-metadata-teams-tokens.js'; -export type { ArrayOfMetadataWebPushTokens } from './array-of-metadata-web-push-tokens.js'; +export type { ApnsTokenResponse1 } from './apns-token-response-1.js'; +export { ApnsTokenResponseInstallationId } from './apns-token-response-installation-id.js'; +export type { ArrayOfApnsTokenResponses } from './array-of-apns-token-responses.js'; +export type { ArrayOfExpoTokenResponses } from './array-of-expo-token-responses.js'; +export type { ArrayOfFcmTokenResponses } from './array-of-fcm-token-responses.js'; +export type { ArrayOfSlackTokenResponses } from './array-of-slack-token-responses.js'; +export type { ArrayOfTeamsTokenResponses } from './array-of-teams-token-responses.js'; +export type { ArrayOfWebPushTokenResponses } from './array-of-web-push-token-responses.js'; export type { DiscardResult } from './discard-result.js'; export type { ExpoToken } from './expo-token.js'; +export type { ExpoTokenResponse1 } from './expo-token-response-1.js'; export type { FcmToken } from './fcm-token.js'; export { FcmTokenInstallationId } from './fcm-token-installation-id.js'; +export type { FcmTokenResponse1 } from './fcm-token-response-1.js'; +export { FcmTokenResponseInstallationId } from './fcm-token-response-installation-id.js'; export type { Links } from './links.js'; -export type { MetadataApnsToken } from './metadata-apns-token.js'; -export type { MetadataExpoToken } from './metadata-expo-token.js'; -export type { MetadataFcmToken } from './metadata-fcm-token.js'; -export type { MetadataSlackToken } from './metadata-slack-token.js'; -export type { MetadataTeamsToken } from './metadata-teams-token.js'; -export type { MetadataWebPushToken } from './metadata-web-push-token.js'; -export type { Oauth } from './oauth.js'; export type { SlackToken } from './slack-token.js'; +export type { SlackTokenOauth } from './slack-token-oauth.js'; +export type { SlackTokenResponse1 } from './slack-token-response-1.js'; +export type { SlackTokenResponseOauth } from './slack-token-response-oauth.js'; +export type { SlackTokenResponseWebhook } from './slack-token-response-webhook.js'; export type { SlackTokenWebhook } from './slack-token-webhook.js'; export type { TeamsToken } from './teams-token.js'; +export type { TeamsTokenResponse1 } from './teams-token-response-1.js'; +export type { TeamsTokenResponseWebhook } from './teams-token-response-webhook.js'; export type { TeamsTokenWebhook } from './teams-token-webhook.js'; -export type { TokenMetadata } from './token-metadata.js'; +export type { WebPushTokenResponse } from './web-push-token-response.js'; +export type { WebPushTokenResponseKeys } from './web-push-token-response-keys.js'; diff --git a/packages/user-client/src/services/channels/models/metadata-apns-token.ts b/packages/user-client/src/services/channels/models/metadata-apns-token.ts deleted file mode 100644 index 996fa6e8a..000000000 --- a/packages/user-client/src/services/channels/models/metadata-apns-token.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { z } from 'zod'; - -import { apnsToken, apnsTokenRequest, apnsTokenResponse } from './apns-token.js'; -import { tokenMetadata, tokenMetadataRequest, tokenMetadataResponse } from './token-metadata.js'; - -/** - * The shape of the model inside the application code - what the users use - */ -export const metadataApnsToken = z.lazy(() => { - return z.object({ - data: apnsToken, - metadata: tokenMetadata, - }); -}); - -/** - * - * @typedef {MetadataApnsToken} metadataApnsToken - * @property {ApnsToken} - * @property {TokenMetadata} - */ -export type MetadataApnsToken = z.infer; - -/** - * The shape of the model mapping from the api schema into the application shape. - * Is equal to application shape if all property names match the api schema - */ -export const metadataApnsTokenResponse = z.lazy(() => { - return z - .object({ - data: apnsTokenResponse, - metadata: tokenMetadataResponse, - }) - .transform((data) => ({ - data: data['data'], - metadata: data['metadata'], - })); -}); - -/** - * The shape of the model mapping from the application shape into the api schema. - * Is equal to application shape if all property names match the api schema - */ -export const metadataApnsTokenRequest = z.lazy(() => { - return z.object({ data: apnsTokenRequest.nullish(), metadata: tokenMetadataRequest.nullish() }).transform((data) => ({ - data: data['data'], - metadata: data['metadata'], - })); -}); diff --git a/packages/user-client/src/services/channels/models/metadata-expo-token.ts b/packages/user-client/src/services/channels/models/metadata-expo-token.ts deleted file mode 100644 index 970186972..000000000 --- a/packages/user-client/src/services/channels/models/metadata-expo-token.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { z } from 'zod'; - -import { expoToken, expoTokenRequest, expoTokenResponse } from './expo-token.js'; -import { tokenMetadata, tokenMetadataRequest, tokenMetadataResponse } from './token-metadata.js'; - -/** - * The shape of the model inside the application code - what the users use - */ -export const metadataExpoToken = z.lazy(() => { - return z.object({ - data: expoToken, - metadata: tokenMetadata, - }); -}); - -/** - * - * @typedef {MetadataExpoToken} metadataExpoToken - * @property {ExpoToken} - * @property {TokenMetadata} - */ -export type MetadataExpoToken = z.infer; - -/** - * The shape of the model mapping from the api schema into the application shape. - * Is equal to application shape if all property names match the api schema - */ -export const metadataExpoTokenResponse = z.lazy(() => { - return z - .object({ - data: expoTokenResponse, - metadata: tokenMetadataResponse, - }) - .transform((data) => ({ - data: data['data'], - metadata: data['metadata'], - })); -}); - -/** - * The shape of the model mapping from the application shape into the api schema. - * Is equal to application shape if all property names match the api schema - */ -export const metadataExpoTokenRequest = z.lazy(() => { - return z.object({ data: expoTokenRequest.nullish(), metadata: tokenMetadataRequest.nullish() }).transform((data) => ({ - data: data['data'], - metadata: data['metadata'], - })); -}); diff --git a/packages/user-client/src/services/channels/models/metadata-fcm-token.ts b/packages/user-client/src/services/channels/models/metadata-fcm-token.ts deleted file mode 100644 index c546ba661..000000000 --- a/packages/user-client/src/services/channels/models/metadata-fcm-token.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { z } from 'zod'; - -import { fcmToken, fcmTokenRequest, fcmTokenResponse } from './fcm-token.js'; -import { tokenMetadata, tokenMetadataRequest, tokenMetadataResponse } from './token-metadata.js'; - -/** - * The shape of the model inside the application code - what the users use - */ -export const metadataFcmToken = z.lazy(() => { - return z.object({ - data: fcmToken, - metadata: tokenMetadata, - }); -}); - -/** - * - * @typedef {MetadataFcmToken} metadataFcmToken - * @property {FcmToken} - * @property {TokenMetadata} - */ -export type MetadataFcmToken = z.infer; - -/** - * The shape of the model mapping from the api schema into the application shape. - * Is equal to application shape if all property names match the api schema - */ -export const metadataFcmTokenResponse = z.lazy(() => { - return z - .object({ - data: fcmTokenResponse, - metadata: tokenMetadataResponse, - }) - .transform((data) => ({ - data: data['data'], - metadata: data['metadata'], - })); -}); - -/** - * The shape of the model mapping from the application shape into the api schema. - * Is equal to application shape if all property names match the api schema - */ -export const metadataFcmTokenRequest = z.lazy(() => { - return z.object({ data: fcmTokenRequest.nullish(), metadata: tokenMetadataRequest.nullish() }).transform((data) => ({ - data: data['data'], - metadata: data['metadata'], - })); -}); diff --git a/packages/user-client/src/services/channels/models/metadata-slack-token.ts b/packages/user-client/src/services/channels/models/metadata-slack-token.ts deleted file mode 100644 index 48cffd8e3..000000000 --- a/packages/user-client/src/services/channels/models/metadata-slack-token.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { z } from 'zod'; - -import { slackToken, slackTokenRequest, slackTokenResponse } from './slack-token.js'; -import { tokenMetadata, tokenMetadataRequest, tokenMetadataResponse } from './token-metadata.js'; - -/** - * The shape of the model inside the application code - what the users use - */ -export const metadataSlackToken = z.lazy(() => { - return z.object({ - data: slackToken, - metadata: tokenMetadata, - }); -}); - -/** - * - * @typedef {MetadataSlackToken} metadataSlackToken - * @property {SlackToken} - * @property {TokenMetadata} - */ -export type MetadataSlackToken = z.infer; - -/** - * The shape of the model mapping from the api schema into the application shape. - * Is equal to application shape if all property names match the api schema - */ -export const metadataSlackTokenResponse = z.lazy(() => { - return z - .object({ - data: slackTokenResponse, - metadata: tokenMetadataResponse, - }) - .transform((data) => ({ - data: data['data'], - metadata: data['metadata'], - })); -}); - -/** - * The shape of the model mapping from the application shape into the api schema. - * Is equal to application shape if all property names match the api schema - */ -export const metadataSlackTokenRequest = z.lazy(() => { - return z - .object({ data: slackTokenRequest.nullish(), metadata: tokenMetadataRequest.nullish() }) - .transform((data) => ({ - data: data['data'], - metadata: data['metadata'], - })); -}); diff --git a/packages/user-client/src/services/channels/models/metadata-teams-token.ts b/packages/user-client/src/services/channels/models/metadata-teams-token.ts deleted file mode 100644 index a766297d1..000000000 --- a/packages/user-client/src/services/channels/models/metadata-teams-token.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { z } from 'zod'; - -import { teamsToken, teamsTokenRequest, teamsTokenResponse } from './teams-token.js'; -import { tokenMetadata, tokenMetadataRequest, tokenMetadataResponse } from './token-metadata.js'; - -/** - * The shape of the model inside the application code - what the users use - */ -export const metadataTeamsToken = z.lazy(() => { - return z.object({ - data: teamsToken, - metadata: tokenMetadata, - }); -}); - -/** - * - * @typedef {MetadataTeamsToken} metadataTeamsToken - * @property {TeamsToken} - * @property {TokenMetadata} - */ -export type MetadataTeamsToken = z.infer; - -/** - * The shape of the model mapping from the api schema into the application shape. - * Is equal to application shape if all property names match the api schema - */ -export const metadataTeamsTokenResponse = z.lazy(() => { - return z - .object({ - data: teamsTokenResponse, - metadata: tokenMetadataResponse, - }) - .transform((data) => ({ - data: data['data'], - metadata: data['metadata'], - })); -}); - -/** - * The shape of the model mapping from the application shape into the api schema. - * Is equal to application shape if all property names match the api schema - */ -export const metadataTeamsTokenRequest = z.lazy(() => { - return z - .object({ data: teamsTokenRequest.nullish(), metadata: tokenMetadataRequest.nullish() }) - .transform((data) => ({ - data: data['data'], - metadata: data['metadata'], - })); -}); diff --git a/packages/user-client/src/services/channels/models/metadata-web-push-token.ts b/packages/user-client/src/services/channels/models/metadata-web-push-token.ts deleted file mode 100644 index 44172307d..000000000 --- a/packages/user-client/src/services/channels/models/metadata-web-push-token.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { z } from 'zod'; - -import { webPushToken, webPushTokenRequest, webPushTokenResponse } from '../../common/web-push-token.js'; -import { tokenMetadata, tokenMetadataRequest, tokenMetadataResponse } from './token-metadata.js'; - -/** - * The shape of the model inside the application code - what the users use - */ -export const metadataWebPushToken = z.lazy(() => { - return z.object({ - data: webPushToken, - metadata: tokenMetadata, - }); -}); - -/** - * - * @typedef {MetadataWebPushToken} metadataWebPushToken - * @property {WebPushToken} - * @property {TokenMetadata} - */ -export type MetadataWebPushToken = z.infer; - -/** - * The shape of the model mapping from the api schema into the application shape. - * Is equal to application shape if all property names match the api schema - */ -export const metadataWebPushTokenResponse = z.lazy(() => { - return z - .object({ - data: webPushTokenResponse, - metadata: tokenMetadataResponse, - }) - .transform((data) => ({ - data: data['data'], - metadata: data['metadata'], - })); -}); - -/** - * The shape of the model mapping from the application shape into the api schema. - * Is equal to application shape if all property names match the api schema - */ -export const metadataWebPushTokenRequest = z.lazy(() => { - return z - .object({ data: webPushTokenRequest.nullish(), metadata: tokenMetadataRequest.nullish() }) - .transform((data) => ({ - data: data['data'], - metadata: data['metadata'], - })); -}); diff --git a/packages/user-client/src/services/channels/models/oauth.ts b/packages/user-client/src/services/channels/models/slack-token-oauth.ts similarity index 82% rename from packages/user-client/src/services/channels/models/oauth.ts rename to packages/user-client/src/services/channels/models/slack-token-oauth.ts index e5802f93b..41fdf46d1 100644 --- a/packages/user-client/src/services/channels/models/oauth.ts +++ b/packages/user-client/src/services/channels/models/slack-token-oauth.ts @@ -3,7 +3,7 @@ import { z } from 'zod'; /** * The shape of the model inside the application code - what the users use */ -export const oauth = z.lazy(() => { +export const slackTokenOauth = z.lazy(() => { return z.object({ channelId: z.string(), installationId: z.string(), @@ -13,18 +13,18 @@ export const oauth = z.lazy(() => { /** * - * @typedef {Oauth} oauth + * @typedef {SlackTokenOauth} slackTokenOauth * @property {string} * @property {string} * @property {string} */ -export type Oauth = z.infer; +export type SlackTokenOauth = z.infer; /** * The shape of the model mapping from the api schema into the application shape. * Is equal to application shape if all property names match the api schema */ -export const oauthResponse = z.lazy(() => { +export const slackTokenOauthResponse = z.lazy(() => { return z .object({ channel_id: z.string(), @@ -42,7 +42,7 @@ export const oauthResponse = z.lazy(() => { * The shape of the model mapping from the application shape into the api schema. * Is equal to application shape if all property names match the api schema */ -export const oauthRequest = z.lazy(() => { +export const slackTokenOauthRequest = z.lazy(() => { return z .object({ channelId: z.string().nullish(), installationId: z.string().nullish(), scope: z.string().nullish() }) .transform((data) => ({ diff --git a/packages/user-client/src/services/channels/models/slack-token-response-1.ts b/packages/user-client/src/services/channels/models/slack-token-response-1.ts new file mode 100644 index 000000000..d4d1d915f --- /dev/null +++ b/packages/user-client/src/services/channels/models/slack-token-response-1.ts @@ -0,0 +1,86 @@ +import { z } from 'zod'; + +import { + slackTokenResponseOauth, + slackTokenResponseOauthRequest, + slackTokenResponseOauthResponse, +} from './slack-token-response-oauth.js'; +import { + slackTokenResponseWebhook, + slackTokenResponseWebhookRequest, + slackTokenResponseWebhookResponse, +} from './slack-token-response-webhook.js'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const slackTokenResponse1 = z.lazy(() => { + return z.object({ + createdAt: z.string(), + discardedAt: z.string().optional().nullable(), + id: z.string(), + oauth: slackTokenResponseOauth.optional(), + updatedAt: z.string().optional().nullable(), + webhook: slackTokenResponseWebhook.optional(), + }); +}); + +/** + * + * @typedef {SlackTokenResponse1} slackTokenResponse1 + * @property {string} + * @property {string} + * @property {string} + * @property {SlackTokenResponseOauth} + * @property {string} + * @property {SlackTokenResponseWebhook} + */ +export type SlackTokenResponse1 = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const slackTokenResponse1Response = z.lazy(() => { + return z + .object({ + created_at: z.string(), + discarded_at: z.string().optional().nullable(), + id: z.string(), + oauth: slackTokenResponseOauthResponse.optional(), + updated_at: z.string().optional().nullable(), + webhook: slackTokenResponseWebhookResponse.optional(), + }) + .transform((data) => ({ + createdAt: data['created_at'], + discardedAt: data['discarded_at'], + id: data['id'], + oauth: data['oauth'], + updatedAt: data['updated_at'], + webhook: data['webhook'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const slackTokenResponse1Request = z.lazy(() => { + return z + .object({ + createdAt: z.string().nullish(), + discardedAt: z.string().nullish(), + id: z.string().nullish(), + oauth: slackTokenResponseOauthRequest.nullish(), + updatedAt: z.string().nullish(), + webhook: slackTokenResponseWebhookRequest.nullish(), + }) + .transform((data) => ({ + created_at: data['createdAt'], + discarded_at: data['discardedAt'], + id: data['id'], + oauth: data['oauth'], + updated_at: data['updatedAt'], + webhook: data['webhook'], + })); +}); diff --git a/packages/user-client/src/services/channels/models/slack-token-response-oauth.ts b/packages/user-client/src/services/channels/models/slack-token-response-oauth.ts new file mode 100644 index 000000000..cf10d9351 --- /dev/null +++ b/packages/user-client/src/services/channels/models/slack-token-response-oauth.ts @@ -0,0 +1,53 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const slackTokenResponseOauth = z.lazy(() => { + return z.object({ + channelId: z.string(), + installationId: z.string(), + scope: z.string().optional(), + }); +}); + +/** + * + * @typedef {SlackTokenResponseOauth} slackTokenResponseOauth + * @property {string} + * @property {string} + * @property {string} + */ +export type SlackTokenResponseOauth = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const slackTokenResponseOauthResponse = z.lazy(() => { + return z + .object({ + channel_id: z.string(), + installation_id: z.string(), + scope: z.string().optional(), + }) + .transform((data) => ({ + channelId: data['channel_id'], + installationId: data['installation_id'], + scope: data['scope'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const slackTokenResponseOauthRequest = z.lazy(() => { + return z + .object({ channelId: z.string().nullish(), installationId: z.string().nullish(), scope: z.string().nullish() }) + .transform((data) => ({ + channel_id: data['channelId'], + installation_id: data['installationId'], + scope: data['scope'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/expo-token.ts b/packages/user-client/src/services/channels/models/slack-token-response-webhook.ts similarity index 53% rename from packages/project-client/src/services/channels/models/expo-token.ts rename to packages/user-client/src/services/channels/models/slack-token-response-webhook.ts index 56d74a954..18d28b481 100644 --- a/packages/project-client/src/services/channels/models/expo-token.ts +++ b/packages/user-client/src/services/channels/models/slack-token-response-webhook.ts @@ -3,30 +3,30 @@ import { z } from 'zod'; /** * The shape of the model inside the application code - what the users use */ -export const expoToken = z.lazy(() => { +export const slackTokenResponseWebhook = z.lazy(() => { return z.object({ - deviceToken: z.string().min(1), + url: z.string().min(1), }); }); /** * - * @typedef {ExpoToken} expoToken + * @typedef {SlackTokenResponseWebhook} slackTokenResponseWebhook * @property {string} */ -export type ExpoToken = z.infer; +export type SlackTokenResponseWebhook = z.infer; /** * The shape of the model mapping from the api schema into the application shape. * Is equal to application shape if all property names match the api schema */ -export const expoTokenResponse = z.lazy(() => { +export const slackTokenResponseWebhookResponse = z.lazy(() => { return z .object({ - device_token: z.string().min(1), + url: z.string().min(1), }) .transform((data) => ({ - deviceToken: data['device_token'], + url: data['url'], })); }); @@ -34,8 +34,8 @@ export const expoTokenResponse = z.lazy(() => { * The shape of the model mapping from the application shape into the api schema. * Is equal to application shape if all property names match the api schema */ -export const expoTokenRequest = z.lazy(() => { - return z.object({ deviceToken: z.string().nullish() }).transform((data) => ({ - device_token: data['deviceToken'], +export const slackTokenResponseWebhookRequest = z.lazy(() => { + return z.object({ url: z.string().nullish() }).transform((data) => ({ + url: data['url'], })); }); diff --git a/packages/user-client/src/services/channels/models/slack-token.ts b/packages/user-client/src/services/channels/models/slack-token.ts index 1a9bf6236..0def0cddc 100644 --- a/packages/user-client/src/services/channels/models/slack-token.ts +++ b/packages/user-client/src/services/channels/models/slack-token.ts @@ -1,6 +1,6 @@ import { z } from 'zod'; -import { oauth, oauthRequest, oauthResponse } from './oauth.js'; +import { slackTokenOauth, slackTokenOauthRequest, slackTokenOauthResponse } from './slack-token-oauth.js'; import { slackTokenWebhook, slackTokenWebhookRequest, slackTokenWebhookResponse } from './slack-token-webhook.js'; /** @@ -8,7 +8,7 @@ import { slackTokenWebhook, slackTokenWebhookRequest, slackTokenWebhookResponse */ export const slackToken = z.lazy(() => { return z.object({ - oauth: oauth.optional(), + oauth: slackTokenOauth.optional(), webhook: slackTokenWebhook.optional(), }); }); @@ -16,7 +16,7 @@ export const slackToken = z.lazy(() => { /** * * @typedef {SlackToken} slackToken - * @property {Oauth} + * @property {SlackTokenOauth} * @property {SlackTokenWebhook} */ export type SlackToken = z.infer; @@ -28,7 +28,7 @@ export type SlackToken = z.infer; export const slackTokenResponse = z.lazy(() => { return z .object({ - oauth: oauthResponse.optional(), + oauth: slackTokenOauthResponse.optional(), webhook: slackTokenWebhookResponse.optional(), }) .transform((data) => ({ @@ -42,8 +42,10 @@ export const slackTokenResponse = z.lazy(() => { * Is equal to application shape if all property names match the api schema */ export const slackTokenRequest = z.lazy(() => { - return z.object({ oauth: oauthRequest.nullish(), webhook: slackTokenWebhookRequest.nullish() }).transform((data) => ({ - oauth: data['oauth'], - webhook: data['webhook'], - })); + return z + .object({ oauth: slackTokenOauthRequest.nullish(), webhook: slackTokenWebhookRequest.nullish() }) + .transform((data) => ({ + oauth: data['oauth'], + webhook: data['webhook'], + })); }); diff --git a/packages/user-client/src/services/channels/models/teams-token-response-1.ts b/packages/user-client/src/services/channels/models/teams-token-response-1.ts new file mode 100644 index 000000000..1d9a689e5 --- /dev/null +++ b/packages/user-client/src/services/channels/models/teams-token-response-1.ts @@ -0,0 +1,75 @@ +import { z } from 'zod'; + +import { + teamsTokenResponseWebhook, + teamsTokenResponseWebhookRequest, + teamsTokenResponseWebhookResponse, +} from './teams-token-response-webhook.js'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const teamsTokenResponse1 = z.lazy(() => { + return z.object({ + createdAt: z.string(), + discardedAt: z.string().optional().nullable(), + id: z.string(), + updatedAt: z.string().optional().nullable(), + webhook: teamsTokenResponseWebhook.optional(), + }); +}); + +/** + * + * @typedef {TeamsTokenResponse1} teamsTokenResponse1 + * @property {string} + * @property {string} + * @property {string} + * @property {string} + * @property {TeamsTokenResponseWebhook} + */ +export type TeamsTokenResponse1 = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const teamsTokenResponse1Response = z.lazy(() => { + return z + .object({ + created_at: z.string(), + discarded_at: z.string().optional().nullable(), + id: z.string(), + updated_at: z.string().optional().nullable(), + webhook: teamsTokenResponseWebhookResponse.optional(), + }) + .transform((data) => ({ + createdAt: data['created_at'], + discardedAt: data['discarded_at'], + id: data['id'], + updatedAt: data['updated_at'], + webhook: data['webhook'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const teamsTokenResponse1Request = z.lazy(() => { + return z + .object({ + createdAt: z.string().nullish(), + discardedAt: z.string().nullish(), + id: z.string().nullish(), + updatedAt: z.string().nullish(), + webhook: teamsTokenResponseWebhookRequest.nullish(), + }) + .transform((data) => ({ + created_at: data['createdAt'], + discarded_at: data['discardedAt'], + id: data['id'], + updated_at: data['updatedAt'], + webhook: data['webhook'], + })); +}); diff --git a/packages/user-client/src/services/channels/models/teams-token-response-webhook.ts b/packages/user-client/src/services/channels/models/teams-token-response-webhook.ts new file mode 100644 index 000000000..70dd62c5a --- /dev/null +++ b/packages/user-client/src/services/channels/models/teams-token-response-webhook.ts @@ -0,0 +1,41 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const teamsTokenResponseWebhook = z.lazy(() => { + return z.object({ + url: z.string().optional(), + }); +}); + +/** + * + * @typedef {TeamsTokenResponseWebhook} teamsTokenResponseWebhook + * @property {string} + */ +export type TeamsTokenResponseWebhook = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const teamsTokenResponseWebhookResponse = z.lazy(() => { + return z + .object({ + url: z.string().optional(), + }) + .transform((data) => ({ + url: data['url'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const teamsTokenResponseWebhookRequest = z.lazy(() => { + return z.object({ url: z.string().nullish() }).transform((data) => ({ + url: data['url'], + })); +}); diff --git a/packages/user-client/src/services/channels/models/web-push-token-response-keys.ts b/packages/user-client/src/services/channels/models/web-push-token-response-keys.ts new file mode 100644 index 000000000..5b895afe7 --- /dev/null +++ b/packages/user-client/src/services/channels/models/web-push-token-response-keys.ts @@ -0,0 +1,46 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const webPushTokenResponseKeys = z.lazy(() => { + return z.object({ + auth: z.string(), + p256dh: z.string(), + }); +}); + +/** + * + * @typedef {WebPushTokenResponseKeys} webPushTokenResponseKeys + * @property {string} + * @property {string} + */ +export type WebPushTokenResponseKeys = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const webPushTokenResponseKeysResponse = z.lazy(() => { + return z + .object({ + auth: z.string(), + p256dh: z.string(), + }) + .transform((data) => ({ + auth: data['auth'], + p256dh: data['p256dh'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const webPushTokenResponseKeysRequest = z.lazy(() => { + return z.object({ auth: z.string().nullish(), p256dh: z.string().nullish() }).transform((data) => ({ + auth: data['auth'], + p256dh: data['p256dh'], + })); +}); diff --git a/packages/user-client/src/services/channels/models/web-push-token-response.ts b/packages/user-client/src/services/channels/models/web-push-token-response.ts new file mode 100644 index 000000000..d1a68d01c --- /dev/null +++ b/packages/user-client/src/services/channels/models/web-push-token-response.ts @@ -0,0 +1,81 @@ +import { z } from 'zod'; + +import { + webPushTokenResponseKeys, + webPushTokenResponseKeysRequest, + webPushTokenResponseKeysResponse, +} from './web-push-token-response-keys.js'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const webPushTokenResponse = z.lazy(() => { + return z.object({ + createdAt: z.string(), + discardedAt: z.string().optional().nullable(), + endpoint: z.string(), + id: z.string(), + keys: webPushTokenResponseKeys, + updatedAt: z.string().optional().nullable(), + }); +}); + +/** + * + * @typedef {WebPushTokenResponse} webPushTokenResponse + * @property {string} + * @property {string} + * @property {string} + * @property {string} + * @property {WebPushTokenResponseKeys} + * @property {string} + */ +export type WebPushTokenResponse = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const webPushTokenResponseResponse = z.lazy(() => { + return z + .object({ + created_at: z.string(), + discarded_at: z.string().optional().nullable(), + endpoint: z.string(), + id: z.string(), + keys: webPushTokenResponseKeysResponse, + updated_at: z.string().optional().nullable(), + }) + .transform((data) => ({ + createdAt: data['created_at'], + discardedAt: data['discarded_at'], + endpoint: data['endpoint'], + id: data['id'], + keys: data['keys'], + updatedAt: data['updated_at'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const webPushTokenResponseRequest = z.lazy(() => { + return z + .object({ + createdAt: z.string().nullish(), + discardedAt: z.string().nullish(), + endpoint: z.string().nullish(), + id: z.string().nullish(), + keys: webPushTokenResponseKeysRequest.nullish(), + updatedAt: z.string().nullish(), + }) + .transform((data) => ({ + created_at: data['createdAt'], + discarded_at: data['discardedAt'], + endpoint: data['endpoint'], + id: data['id'], + keys: data['keys'], + updated_at: data['updatedAt'], + })); +}); diff --git a/packages/user-client/src/services/common/index.ts b/packages/user-client/src/services/common/index.ts index 874b5948a..db3007144 100644 --- a/packages/user-client/src/services/common/index.ts +++ b/packages/user-client/src/services/common/index.ts @@ -1,2 +1,2 @@ -export type { Keys } from './keys.js'; export type { WebPushToken } from './web-push-token.js'; +export type { WebPushTokenKeys } from './web-push-token-keys.js'; diff --git a/packages/user-client/src/services/common/keys.ts b/packages/user-client/src/services/common/web-push-token-keys.ts similarity index 77% rename from packages/user-client/src/services/common/keys.ts rename to packages/user-client/src/services/common/web-push-token-keys.ts index 3c59e4017..b7704e1d0 100644 --- a/packages/user-client/src/services/common/keys.ts +++ b/packages/user-client/src/services/common/web-push-token-keys.ts @@ -3,7 +3,7 @@ import { z } from 'zod'; /** * The shape of the model inside the application code - what the users use */ -export const keys = z.lazy(() => { +export const webPushTokenKeys = z.lazy(() => { return z.object({ auth: z.string(), p256dh: z.string(), @@ -12,17 +12,17 @@ export const keys = z.lazy(() => { /** * - * @typedef {Keys} keys + * @typedef {WebPushTokenKeys} webPushTokenKeys * @property {string} * @property {string} */ -export type Keys = z.infer; +export type WebPushTokenKeys = z.infer; /** * The shape of the model mapping from the api schema into the application shape. * Is equal to application shape if all property names match the api schema */ -export const keysResponse = z.lazy(() => { +export const webPushTokenKeysResponse = z.lazy(() => { return z .object({ auth: z.string(), @@ -38,7 +38,7 @@ export const keysResponse = z.lazy(() => { * The shape of the model mapping from the application shape into the api schema. * Is equal to application shape if all property names match the api schema */ -export const keysRequest = z.lazy(() => { +export const webPushTokenKeysRequest = z.lazy(() => { return z.object({ auth: z.string().nullish(), p256dh: z.string().nullish() }).transform((data) => ({ auth: data['auth'], p256dh: data['p256dh'], diff --git a/packages/user-client/src/services/common/web-push-token.ts b/packages/user-client/src/services/common/web-push-token.ts index 38ac7d1cc..c5e9945cc 100644 --- a/packages/user-client/src/services/common/web-push-token.ts +++ b/packages/user-client/src/services/common/web-push-token.ts @@ -1,6 +1,6 @@ import { z } from 'zod'; -import { keys, keysRequest, keysResponse } from './keys.js'; +import { webPushTokenKeys, webPushTokenKeysRequest, webPushTokenKeysResponse } from './web-push-token-keys.js'; /** * The shape of the model inside the application code - what the users use @@ -8,7 +8,7 @@ import { keys, keysRequest, keysResponse } from './keys.js'; export const webPushToken = z.lazy(() => { return z.object({ endpoint: z.string(), - keys: keys, + keys: webPushTokenKeys, }); }); @@ -16,7 +16,7 @@ export const webPushToken = z.lazy(() => { * * @typedef {WebPushToken} webPushToken * @property {string} - * @property {Keys} + * @property {WebPushTokenKeys} */ export type WebPushToken = z.infer; @@ -28,7 +28,7 @@ export const webPushTokenResponse = z.lazy(() => { return z .object({ endpoint: z.string(), - keys: keysResponse, + keys: webPushTokenKeysResponse, }) .transform((data) => ({ endpoint: data['endpoint'], @@ -41,7 +41,7 @@ export const webPushTokenResponse = z.lazy(() => { * Is equal to application shape if all property names match the api schema */ export const webPushTokenRequest = z.lazy(() => { - return z.object({ endpoint: z.string().nullish(), keys: keysRequest.nullish() }).transform((data) => ({ + return z.object({ endpoint: z.string().nullish(), keys: webPushTokenKeysRequest.nullish() }).transform((data) => ({ endpoint: data['endpoint'], keys: data['keys'], })); diff --git a/packages/user-client/src/services/integrations/integrations.ts b/packages/user-client/src/services/integrations/integrations.ts index 99175542c..2793bcaaf 100644 --- a/packages/user-client/src/services/integrations/integrations.ts +++ b/packages/user-client/src/services/integrations/integrations.ts @@ -32,15 +32,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} Created */ async saveInboxInstallation(body: InboxConfig, requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('POST') .setPath('/integrations/inbox/installations') .setRequestSchema(inboxConfigRequest) - .setResponseSchema(inboxConfigResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: inboxConfigResponse, + contentType: ContentType.Json, + status: 201, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -55,15 +58,18 @@ export class IntegrationsService extends BaseService { * @returns {Promise>} Created */ async startInboxInstallation(requestConfig?: RequestConfig): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('POST') .setPath('/integrations/inbox/installations/start') .setRequestSchema(z.any()) - .setResponseSchema(inboxConfigResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: inboxConfigResponse, + contentType: ContentType.Json, + status: 201, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -79,15 +85,18 @@ export class IntegrationsService extends BaseService { body: SlackInstallation, requestConfig?: RequestConfig, ): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('POST') .setPath('/integrations/slack/installations') .setRequestSchema(slackInstallationRequest) - .setResponseSchema(slackInstallationResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: slackInstallationResponse, + contentType: ContentType.Json, + status: 201, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -105,15 +114,18 @@ export class IntegrationsService extends BaseService { body: SlackFinishInstallResponse, requestConfig?: RequestConfig, ): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('POST') .setPath('/integrations/slack/installations/finish') .setRequestSchema(slackFinishInstallResponseRequest) - .setResponseSchema(slackInstallationResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: slackInstallationResponse, + contentType: ContentType.Json, + status: 201, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -131,15 +143,18 @@ export class IntegrationsService extends BaseService { body: SlackStartInstall, requestConfig?: RequestConfig, ): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('POST') .setPath('/integrations/slack/installations/start') .setRequestSchema(slackStartInstallRequest) - .setResponseSchema(slackStartInstallResponseContentResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: slackStartInstallResponseContentResponse, + contentType: ContentType.Json, + status: 201, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -157,15 +172,18 @@ export class IntegrationsService extends BaseService { body: TemplatesInstallation, requestConfig?: RequestConfig, ): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('POST') .setPath('/integrations/templates/installations') .setRequestSchema(templatesInstallationRequest) - .setResponseSchema(templatesInstallationResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: templatesInstallationResponse, + contentType: ContentType.Json, + status: 201, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -183,15 +201,18 @@ export class IntegrationsService extends BaseService { body: WebPushToken, requestConfig?: RequestConfig, ): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('POST') .setPath('/integrations/web_push/installations') .setRequestSchema(webPushTokenRequest) - .setResponseSchema(webPushTokenResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: webPushTokenResponse, + contentType: ContentType.Json, + status: 201, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) @@ -208,15 +229,18 @@ export class IntegrationsService extends BaseService { async startWebPushInstallation( requestConfig?: RequestConfig, ): Promise> { - const request = new RequestBuilder() + const request = new RequestBuilder() .setBaseUrl(this.config) .setConfig(this.config) .setMethod('POST') .setPath('/integrations/web_push/installations/start') .setRequestSchema(z.any()) - .setResponseSchema(webPushStartInstallationResponseResponse) .setRequestContentType(ContentType.Json) - .setResponseContentType(ContentType.Json) + .addResponse({ + schema: webPushStartInstallationResponseResponse, + contentType: ContentType.Json, + status: 201, + }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig)