From 535534f91034ce88a1a9cc4280cb872102db1665 Mon Sep 17 00:00:00 2001 From: Stephan Meijer Date: Tue, 15 Oct 2024 11:46:17 +0200 Subject: [PATCH] chore: regenerate api clients to include deliveryconfig (#374) --- .changeset/giant-dingos-laugh.md | 5 + .../models/CategoryDeliveryPlan.md | 32 +++++ .../documentation/models/DeliveryPlan.md | 31 +++++ .../documentation/services/ChannelsService.md | 116 ++++++++++++++++++ packages/project-client/src/index.ts | 16 +-- .../src/services/broadcasts/models/index.ts | 2 +- .../{channels.ts => overrides-channels.ts} | 10 +- .../services/broadcasts/models/overrides.ts | 18 +-- .../src/services/channels/channels.ts | 79 ++++++++++++ .../models/category-delivery-plan-channels.ts | 53 ++++++++ .../channels/models/category-delivery-plan.ts | 69 +++++++++++ .../channels/models/channels-channel-1.ts | 9 ++ .../channels/models/channels-channel-2.ts | 8 ++ .../channels/models/delivery-plan-channels.ts | 53 ++++++++ .../services/channels/models/delivery-plan.ts | 47 +++++++ .../src/services/channels/models/index.ts | 6 + 16 files changed, 532 insertions(+), 22 deletions(-) create mode 100644 .changeset/giant-dingos-laugh.md create mode 100644 packages/project-client/documentation/models/CategoryDeliveryPlan.md create mode 100644 packages/project-client/documentation/models/DeliveryPlan.md rename packages/project-client/src/services/broadcasts/models/{channels.ts => overrides-channels.ts} (88%) create mode 100644 packages/project-client/src/services/channels/models/category-delivery-plan-channels.ts create mode 100644 packages/project-client/src/services/channels/models/category-delivery-plan.ts create mode 100644 packages/project-client/src/services/channels/models/channels-channel-1.ts create mode 100644 packages/project-client/src/services/channels/models/channels-channel-2.ts create mode 100644 packages/project-client/src/services/channels/models/delivery-plan-channels.ts create mode 100644 packages/project-client/src/services/channels/models/delivery-plan.ts diff --git a/.changeset/giant-dingos-laugh.md b/.changeset/giant-dingos-laugh.md new file mode 100644 index 000000000..5ef88b50d --- /dev/null +++ b/.changeset/giant-dingos-laugh.md @@ -0,0 +1,5 @@ +--- +'@magicbell/project-client': minor +--- + +add deliveryconfig endpoints diff --git a/packages/project-client/documentation/models/CategoryDeliveryPlan.md b/packages/project-client/documentation/models/CategoryDeliveryPlan.md new file mode 100644 index 000000000..c3945aa74 --- /dev/null +++ b/packages/project-client/documentation/models/CategoryDeliveryPlan.md @@ -0,0 +1,32 @@ +# CategoryDeliveryPlan + +**Properties** + +| Name | Type | Required | Description | +| :------- | :----------------------------- | :------- | :---------- | +| category | string | ✅ | | +| channels | CategoryDeliveryPlanChannels[] | ✅ | | +| disabled | boolean | ❌ | | + +# CategoryDeliveryPlanChannels + +**Properties** + +| Name | Type | Required | Description | +| :------ | :--------------- | :------- | :---------- | +| channel | ChannelsChannel2 | ✅ | | +| delay | number | ❌ | | +| if | string | ❌ | | + +# ChannelsChannel2 + +**Properties** + +| Name | Type | Required | Description | +| :--------- | :----- | :------- | :------------ | +| INAPP | string | ✅ | "in_app" | +| SLACK | string | ✅ | "slack" | +| WEBPUSH | string | ✅ | "web_push" | +| MOBILEPUSH | string | ✅ | "mobile_push" | +| TEAMS | string | ✅ | "teams" | +| EMAIL | string | ✅ | "email" | diff --git a/packages/project-client/documentation/models/DeliveryPlan.md b/packages/project-client/documentation/models/DeliveryPlan.md new file mode 100644 index 000000000..b6bb1d715 --- /dev/null +++ b/packages/project-client/documentation/models/DeliveryPlan.md @@ -0,0 +1,31 @@ +# DeliveryPlan + +**Properties** + +| Name | Type | Required | Description | +| :------- | :--------------------- | :------- | :---------- | +| channels | DeliveryPlanChannels[] | ✅ | | + +# DeliveryPlanChannels + +**Properties** + +| Name | Type | Required | Description | +| :------ | :--------------- | :------- | :---------- | +| channel | ChannelsChannel1 | ✅ | | +| delay | number | ❌ | | +| if | string | ❌ | | + +# ChannelsChannel1 + +**Properties** + +| Name | Type | Required | Description | +| :--------- | :----- | :------- | :------------ | +| INAPP | string | ✅ | "in_app" | +| SLACK | string | ✅ | "slack" | +| WEBPUSH | string | ✅ | "web_push" | +| MOBILEPUSH | string | ✅ | "mobile_push" | +| TEAMS | string | ✅ | "teams" | +| EMAIL | string | ✅ | "email" | +| SMS | string | ✅ | "sms" | diff --git a/packages/project-client/documentation/services/ChannelsService.md b/packages/project-client/documentation/services/ChannelsService.md index b1e93c69a..a461b2b1e 100644 --- a/packages/project-client/documentation/services/ChannelsService.md +++ b/packages/project-client/documentation/services/ChannelsService.md @@ -4,6 +4,9 @@ A list of all methods in the `ChannelsService` service. Click on the method name | Methods | Description | | :---------------------------------------------------------------- | :---------- | +| [getProjectDeliveryconfig](#getprojectdeliveryconfig) | | +| [saveProjectDeliveryconfig](#saveprojectdeliveryconfig) | | +| [saveCategoriesDeliveryconfig](#savecategoriesdeliveryconfig) | | | [getMobilePushApnsUserTokens](#getmobilepushapnsusertokens) | | | [getMobilePushApnsUserToken](#getmobilepushapnsusertoken) | | | [discardMobilePushApnsUserToken](#discardmobilepushapnsusertoken) | | @@ -23,6 +26,119 @@ A list of all methods in the `ChannelsService` service. Click on the method name | [getWebPushUserToken](#getwebpushusertoken) | | | [discardWebPushUserToken](#discardwebpushusertoken) | | +## getProjectDeliveryconfig + +- HTTP Method: `GET` +- Endpoint: `/channels/deliveryconfig` + +**Return Type** + +`DeliveryPlan` + +**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 | [DeliveryPlan](../models/DeliveryPlan.md) | ❌ | The request body. | + +**Return Type** + +`DeliveryPlan` + +**Example Usage Code Snippet** + +```typescript +import { Client, DeliveryPlan } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const channelsChannel1 = ChannelsChannel1.INAPP; + + const deliveryPlanChannels: DeliveryPlanChannels = { + channel: channelsChannel1, + delay: 7, + if: 'if', + }; + + const deliveryPlan: DeliveryPlan = { + channels: [deliveryPlanChannels], + }; + + const { data } = await client.channels.saveProjectDeliveryconfig(input); + + console.log(data); +})(); +``` + +## saveCategoriesDeliveryconfig + +- HTTP Method: `POST` +- Endpoint: `/channels/deliveryconfig/categories` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :-------------------------------------------------------- | :------- | :---------------- | +| body | [CategoryDeliveryPlan](../models/CategoryDeliveryPlan.md) | ❌ | The request body. | + +**Return Type** + +`CategoryDeliveryPlan` + +**Example Usage Code Snippet** + +```typescript +import { CategoryDeliveryPlan, Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const channelsChannel2 = ChannelsChannel2.INAPP; + + const categoryDeliveryPlanChannels: CategoryDeliveryPlanChannels = { + channel: channelsChannel2, + delay: 1, + if: 'if', + }; + + const categoryDeliveryPlan: CategoryDeliveryPlan = { + category: '62Lu', + channels: [categoryDeliveryPlanChannels], + disabled: true, + }; + + const { data } = await client.channels.saveCategoriesDeliveryconfig(input); + + console.log(data); +})(); +``` + ## getMobilePushApnsUserTokens - HTTP Method: `GET` diff --git a/packages/project-client/src/index.ts b/packages/project-client/src/index.ts index 034d12404..b0be13e87 100644 --- a/packages/project-client/src/index.ts +++ b/packages/project-client/src/index.ts @@ -14,12 +14,12 @@ export * from './services/jwt/index.js'; export class Client { public readonly broadcasts: BroadcastsService; + public readonly channels: ChannelsService; + public readonly integrations: IntegrationsService; public readonly jwt: JwtService; - public readonly channels: ChannelsService; - constructor(public config: SdkConfig) { const baseUrl = config.environment || config.baseUrl || Environment.DEFAULT; this.config = { @@ -28,39 +28,39 @@ export class Client { }; this.broadcasts = new BroadcastsService(this.config); + this.channels = new ChannelsService(this.config); + this.integrations = new IntegrationsService(this.config); this.jwt = new JwtService(this.config); - - this.channels = new ChannelsService(this.config); } set baseUrl(baseUrl: string) { this.broadcasts.baseUrl = baseUrl; + this.channels.baseUrl = baseUrl; this.integrations.baseUrl = baseUrl; this.jwt.baseUrl = baseUrl; - this.channels.baseUrl = baseUrl; } set environment(environment: Environment) { this.broadcasts.baseUrl = environment; + this.channels.baseUrl = environment; this.integrations.baseUrl = environment; this.jwt.baseUrl = environment; - this.channels.baseUrl = environment; } set timeout(timeout: number) { this.broadcasts.timeout = timeout; + this.channels.timeout = timeout; this.integrations.timeout = timeout; this.jwt.timeout = timeout; - this.channels.timeout = timeout; } set token(token: string) { this.broadcasts.token = token; + this.channels.token = token; this.integrations.token = token; this.jwt.token = token; - this.channels.token = token; } } diff --git a/packages/project-client/src/services/broadcasts/models/index.ts b/packages/project-client/src/services/broadcasts/models/index.ts index cac0fa515..210c6b8cb 100644 --- a/packages/project-client/src/services/broadcasts/models/index.ts +++ b/packages/project-client/src/services/broadcasts/models/index.ts @@ -1,12 +1,12 @@ export type { Broadcast } from './broadcast.js'; export type { BroadcastListResponse } from './broadcast-list-response.js'; export type { Category } from './category.js'; -export type { Channels } from './channels.js'; export type { Email } from './email.js'; export type { InApp } from './in-app.js'; export type { Links } from './links.js'; export type { MobilePush } from './mobile-push.js'; export type { Overrides } from './overrides.js'; +export type { OverridesChannels } from './overrides-channels.js'; export type { Providers } from './providers.js'; export type { Slack } from './slack.js'; export type { Sms } from './sms.js'; diff --git a/packages/project-client/src/services/broadcasts/models/channels.ts b/packages/project-client/src/services/broadcasts/models/overrides-channels.ts similarity index 88% rename from packages/project-client/src/services/broadcasts/models/channels.ts rename to packages/project-client/src/services/broadcasts/models/overrides-channels.ts index 914e01a55..246a9346c 100644 --- a/packages/project-client/src/services/broadcasts/models/channels.ts +++ b/packages/project-client/src/services/broadcasts/models/overrides-channels.ts @@ -10,7 +10,7 @@ import { webPush, webPushRequest, webPushResponse } from './web-push.js'; /** * The shape of the model inside the application code - what the users use */ -export const channels = z.lazy(() => { +export const overridesChannels = z.lazy(() => { return z.object({ email: email.optional(), inApp: inApp.optional(), @@ -23,7 +23,7 @@ export const channels = z.lazy(() => { /** * - * @typedef {Channels} channels + * @typedef {OverridesChannels} overridesChannels * @property {Email} * @property {InApp} * @property {MobilePush} @@ -31,13 +31,13 @@ export const channels = z.lazy(() => { * @property {Sms} * @property {WebPush} */ -export type Channels = z.infer; +export type OverridesChannels = 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 channelsResponse = z.lazy(() => { +export const overridesChannelsResponse = z.lazy(() => { return z .object({ email: emailResponse.optional(), @@ -61,7 +61,7 @@ export const channelsResponse = 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 channelsRequest = z.lazy(() => { +export const overridesChannelsRequest = z.lazy(() => { return z .object({ email: emailRequest.nullish(), diff --git a/packages/project-client/src/services/broadcasts/models/overrides.ts b/packages/project-client/src/services/broadcasts/models/overrides.ts index deb7da1e7..222a9acc2 100644 --- a/packages/project-client/src/services/broadcasts/models/overrides.ts +++ b/packages/project-client/src/services/broadcasts/models/overrides.ts @@ -1,6 +1,6 @@ import { z } from 'zod'; -import { channels, channelsRequest, channelsResponse } from './channels.js'; +import { overridesChannels, overridesChannelsRequest, overridesChannelsResponse } from './overrides-channels.js'; import { providers, providersRequest, providersResponse } from './providers.js'; /** @@ -8,7 +8,7 @@ import { providers, providersRequest, providersResponse } from './providers.js'; */ export const overrides = z.lazy(() => { return z.object({ - channels: channels.optional(), + channels: overridesChannels.optional(), providers: providers.optional(), }); }); @@ -16,7 +16,7 @@ export const overrides = z.lazy(() => { /** * * @typedef {Overrides} overrides - * @property {Channels} + * @property {OverridesChannels} * @property {Providers} */ export type Overrides = z.infer; @@ -28,7 +28,7 @@ export type Overrides = z.infer; export const overridesResponse = z.lazy(() => { return z .object({ - channels: channelsResponse.optional(), + channels: overridesChannelsResponse.optional(), providers: providersResponse.optional(), }) .transform((data) => ({ @@ -42,8 +42,10 @@ export const overridesResponse = z.lazy(() => { * Is equal to application shape if all property names match the api schema */ export const overridesRequest = z.lazy(() => { - return z.object({ channels: channelsRequest.nullish(), providers: providersRequest.nullish() }).transform((data) => ({ - channels: data['channels'], - providers: data['providers'], - })); + return z + .object({ channels: overridesChannelsRequest.nullish(), providers: providersRequest.nullish() }) + .transform((data) => ({ + channels: data['channels'], + providers: data['providers'], + })); }); diff --git a/packages/project-client/src/services/channels/channels.ts b/packages/project-client/src/services/channels/channels.ts index c9a326df2..bcceafb53 100644 --- a/packages/project-client/src/services/channels/channels.ts +++ b/packages/project-client/src/services/channels/channels.ts @@ -28,6 +28,12 @@ import { ArrayWithMetadataOfWebPushToken, arrayWithMetadataOfWebPushTokenResponse, } from './models/array-with-metadata-of-web-push-token.js'; +import { + CategoryDeliveryPlan, + categoryDeliveryPlanRequest, + categoryDeliveryPlanResponse, +} from './models/category-delivery-plan.js'; +import { DeliveryPlan, deliveryPlanRequest, deliveryPlanResponse } from './models/delivery-plan.js'; import { DiscardResult, discardResultResponse } from './models/discard-result.js'; import { ExpoTokenWithMetadata, expoTokenWithMetadataResponse } from './models/expo-token-with-metadata.js'; import { FcmTokenWithMetadata, fcmTokenWithMetadataResponse } from './models/fcm-token-with-metadata.js'; @@ -36,6 +42,79 @@ import { TeamsTokenWithMetadata, teamsTokenWithMetadataResponse } from './models import { WebPushTokenWithMetadata, webPushTokenWithMetadataResponse } from './models/web-push-token-with-metadata.js'; export class ChannelsService extends BaseService { + /** + * + * @returns {Promise>} OK + */ + async getProjectDeliveryconfig(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/channels/deliveryconfig') + .setRequestSchema(z.any()) + .setResponseSchema(deliveryPlanResponse) + .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: DeliveryPlan, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('PUT') + .setPath('/channels/deliveryconfig') + .setRequestSchema(deliveryPlanRequest) + .setResponseSchema(deliveryPlanResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addHeaderParam({ key: 'Content-Type', value: 'application/json' }) + .addBody(body) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} Created + */ + async saveCategoriesDeliveryconfig( + body: CategoryDeliveryPlan, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('POST') + .setPath('/channels/deliveryconfig/categories') + .setRequestSchema(categoryDeliveryPlanRequest) + .setResponseSchema(categoryDeliveryPlanResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addHeaderParam({ key: 'Content-Type', value: 'application/json' }) + .addBody(body) + .build(); + return this.client.call(request); + } + /** * * @param {string} userId - diff --git a/packages/project-client/src/services/channels/models/category-delivery-plan-channels.ts b/packages/project-client/src/services/channels/models/category-delivery-plan-channels.ts new file mode 100644 index 000000000..41aaba046 --- /dev/null +++ b/packages/project-client/src/services/channels/models/category-delivery-plan-channels.ts @@ -0,0 +1,53 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const categoryDeliveryPlanChannels = z.lazy(() => { + return z.object({ + channel: z.string(), + delay: z.number().gte(0).optional(), + if: z.string().optional(), + }); +}); + +/** + * + * @typedef {CategoryDeliveryPlanChannels} categoryDeliveryPlanChannels + * @property {ChannelsChannel2} + * @property {number} + * @property {string} + */ +export type CategoryDeliveryPlanChannels = 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 categoryDeliveryPlanChannelsResponse = z.lazy(() => { + return z + .object({ + channel: z.string(), + delay: z.number().gte(0).optional(), + if: z.string().optional(), + }) + .transform((data) => ({ + channel: data['channel'], + delay: data['delay'], + if: data['if'], + })); +}); + +/** + * 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 categoryDeliveryPlanChannelsRequest = z.lazy(() => { + return z + .object({ channel: z.string().nullish(), delay: z.number().nullish(), if: z.string().nullish() }) + .transform((data) => ({ + channel: data['channel'], + delay: data['delay'], + if: data['if'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/category-delivery-plan.ts b/packages/project-client/src/services/channels/models/category-delivery-plan.ts new file mode 100644 index 000000000..0a4aa876f --- /dev/null +++ b/packages/project-client/src/services/channels/models/category-delivery-plan.ts @@ -0,0 +1,69 @@ +import { z } from 'zod'; + +import { + categoryDeliveryPlanChannels, + categoryDeliveryPlanChannelsRequest, + categoryDeliveryPlanChannelsResponse, +} from './category-delivery-plan-channels.js'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const categoryDeliveryPlan = z.lazy(() => { + return z.object({ + category: z + .string() + .min(3) + .regex(/^[a-zA-Z0-9_]+$/), + channels: z.array(categoryDeliveryPlanChannels), + disabled: z.boolean().optional(), + }); +}); + +/** + * + * @typedef {CategoryDeliveryPlan} categoryDeliveryPlan + * @property {string} + * @property {CategoryDeliveryPlanChannels[]} + * @property {boolean} + */ +export type CategoryDeliveryPlan = 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 categoryDeliveryPlanResponse = z.lazy(() => { + return z + .object({ + category: z + .string() + .min(3) + .regex(/^[a-zA-Z0-9_]+$/), + channels: z.array(categoryDeliveryPlanChannelsResponse), + disabled: z.boolean().optional(), + }) + .transform((data) => ({ + category: data['category'], + channels: data['channels'], + disabled: data['disabled'], + })); +}); + +/** + * 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 categoryDeliveryPlanRequest = z.lazy(() => { + return z + .object({ + category: z.string().nullish(), + channels: z.array(categoryDeliveryPlanChannelsRequest).nullish(), + disabled: z.boolean().nullish(), + }) + .transform((data) => ({ + category: data['category'], + channels: data['channels'], + disabled: data['disabled'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/channels-channel-1.ts b/packages/project-client/src/services/channels/models/channels-channel-1.ts new file mode 100644 index 000000000..df3228436 --- /dev/null +++ b/packages/project-client/src/services/channels/models/channels-channel-1.ts @@ -0,0 +1,9 @@ +export enum ChannelsChannel1 { + INAPP = 'in_app', + SLACK = 'slack', + WEBPUSH = 'web_push', + MOBILEPUSH = 'mobile_push', + TEAMS = 'teams', + EMAIL = 'email', + SMS = 'sms', +} 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 new file mode 100644 index 000000000..b8919c691 --- /dev/null +++ b/packages/project-client/src/services/channels/models/channels-channel-2.ts @@ -0,0 +1,8 @@ +export enum ChannelsChannel2 { + INAPP = 'in_app', + SLACK = 'slack', + WEBPUSH = 'web_push', + MOBILEPUSH = 'mobile_push', + TEAMS = 'teams', + EMAIL = 'email', +} diff --git a/packages/project-client/src/services/channels/models/delivery-plan-channels.ts b/packages/project-client/src/services/channels/models/delivery-plan-channels.ts new file mode 100644 index 000000000..cbff17b5b --- /dev/null +++ b/packages/project-client/src/services/channels/models/delivery-plan-channels.ts @@ -0,0 +1,53 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const deliveryPlanChannels = z.lazy(() => { + return z.object({ + channel: z.string(), + delay: z.number().gte(0).optional(), + if: z.string().optional(), + }); +}); + +/** + * + * @typedef {DeliveryPlanChannels} deliveryPlanChannels + * @property {ChannelsChannel1} + * @property {number} + * @property {string} + */ +export type DeliveryPlanChannels = 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 deliveryPlanChannelsResponse = z.lazy(() => { + return z + .object({ + channel: z.string(), + delay: z.number().gte(0).optional(), + if: z.string().optional(), + }) + .transform((data) => ({ + channel: data['channel'], + delay: data['delay'], + if: data['if'], + })); +}); + +/** + * 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 deliveryPlanChannelsRequest = z.lazy(() => { + return z + .object({ channel: z.string().nullish(), delay: z.number().nullish(), if: z.string().nullish() }) + .transform((data) => ({ + channel: data['channel'], + delay: data['delay'], + if: data['if'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/delivery-plan.ts b/packages/project-client/src/services/channels/models/delivery-plan.ts new file mode 100644 index 000000000..068157514 --- /dev/null +++ b/packages/project-client/src/services/channels/models/delivery-plan.ts @@ -0,0 +1,47 @@ +import { z } from 'zod'; + +import { + deliveryPlanChannels, + deliveryPlanChannelsRequest, + deliveryPlanChannelsResponse, +} from './delivery-plan-channels.js'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const deliveryPlan = z.lazy(() => { + return z.object({ + channels: z.array(deliveryPlanChannels), + }); +}); + +/** + * + * @typedef {DeliveryPlan} deliveryPlan + * @property {DeliveryPlanChannels[]} + */ +export type DeliveryPlan = 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 deliveryPlanResponse = z.lazy(() => { + return z + .object({ + channels: z.array(deliveryPlanChannelsResponse), + }) + .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 deliveryPlanRequest = z.lazy(() => { + return z.object({ channels: z.array(deliveryPlanChannelsRequest).nullish() }).transform((data) => ({ + channels: data['channels'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/index.ts b/packages/project-client/src/services/channels/models/index.ts index 4bbd1059f..1a552aa67 100644 --- a/packages/project-client/src/services/channels/models/index.ts +++ b/packages/project-client/src/services/channels/models/index.ts @@ -14,12 +14,18 @@ export type { ArrayWithMetadataOfTeamsToken } from './array-with-metadata-of-tea export type { ArrayWithMetadataOfTeamsTokenData } from './array-with-metadata-of-teams-token-data.js'; export type { ArrayWithMetadataOfWebPushToken } from './array-with-metadata-of-web-push-token.js'; export type { ArrayWithMetadataOfWebPushTokenData } from './array-with-metadata-of-web-push-token-data.js'; +export type { CategoryDeliveryPlan } from './category-delivery-plan.js'; +export type { CategoryDeliveryPlanChannels } from './category-delivery-plan-channels.js'; +export { ChannelsChannel1 } from './channels-channel-1.js'; +export { ChannelsChannel2 } from './channels-channel-2.js'; export type { DataMetadata1 } from './data-metadata-1.js'; export type { DataMetadata2 } from './data-metadata-2.js'; export type { DataMetadata3 } from './data-metadata-3.js'; export type { DataMetadata4 } from './data-metadata-4.js'; export type { DataMetadata5 } from './data-metadata-5.js'; export type { DataMetadata6 } from './data-metadata-6.js'; +export type { DeliveryPlan } from './delivery-plan.js'; +export type { DeliveryPlanChannels } from './delivery-plan-channels.js'; export type { DiscardResult } from './discard-result.js'; export type { ExpoToken } from './expo-token.js'; export type { ExpoTokenWithMetadata } from './expo-token-with-metadata.js';