diff --git a/apps/api/src/app/subscribers-v2/dtos/create-subscriber.dto.ts b/apps/api/src/app/subscribers-v2/dtos/create-subscriber.dto.ts new file mode 100644 index 000000000000..ec4f343eaeb5 --- /dev/null +++ b/apps/api/src/app/subscribers-v2/dtos/create-subscriber.dto.ts @@ -0,0 +1,91 @@ +import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; +import { IsEmail, IsLocale, IsObject, IsOptional, IsString, IsTimeZone, ValidateIf } from 'class-validator'; + +export class CreateSubscriberRequestDto { + @ApiProperty({ + type: String, + description: 'Unique identifier of the subscriber', + }) + @IsString() + subscriberId: string; + + @ApiPropertyOptional({ + type: String, + description: 'First name of the subscriber', + nullable: true, + }) + @IsOptional() + @ValidateIf((obj) => obj.firstName !== null) + @IsString() + firstName?: string | null; + + @ApiPropertyOptional({ + type: String, + description: 'Last name of the subscriber', + nullable: true, + }) + @IsOptional() + @ValidateIf((obj) => obj.lastName !== null) + @IsString() + lastName?: string | null; + + @ApiPropertyOptional({ + type: String, + description: 'Email address of the subscriber', + nullable: true, + }) + @IsOptional() + @ValidateIf((obj) => obj.email !== null) + @IsEmail() + email?: string | null; + + @ApiPropertyOptional({ + type: String, + description: 'Phone number of the subscriber', + nullable: true, + }) + @IsOptional() + @ValidateIf((obj) => obj.phone !== null) + @IsString() + phone?: string | null; + + @ApiPropertyOptional({ + type: String, + description: 'Avatar URL or identifier', + nullable: true, + }) + @IsOptional() + @ValidateIf((obj) => obj.avatar !== null) + @IsString() + avatar?: string | null; + + @ApiPropertyOptional({ + type: String, + description: 'Timezone of the subscriber', + nullable: true, + }) + @IsOptional() + @ValidateIf((obj) => obj.timezone !== null) + @IsTimeZone() + timezone?: string | null; + + @ApiPropertyOptional({ + type: String, + description: 'Locale of the subscriber', + nullable: true, + }) + @IsOptional() + @ValidateIf((obj) => obj.locale !== null) + @IsLocale() + locale?: string | null; + + @ApiPropertyOptional({ + type: Object, + description: 'Additional custom data for the subscriber', + nullable: true, + }) + @IsOptional() + @ValidateIf((obj) => obj.data !== null) + @IsObject() + data?: Record | null; +} diff --git a/apps/api/src/app/subscribers-v2/e2e/create-subscriber.e2e.ts b/apps/api/src/app/subscribers-v2/e2e/create-subscriber.e2e.ts new file mode 100644 index 000000000000..256fb408f62a --- /dev/null +++ b/apps/api/src/app/subscribers-v2/e2e/create-subscriber.e2e.ts @@ -0,0 +1,57 @@ +import { expect } from 'chai'; +import { Novu } from '@novu/api'; +import { UserSession } from '@novu/testing'; +import { randomBytes } from 'crypto'; +import { expectSdkExceptionGeneric, initNovuClassSdk } from '../../shared/helpers/e2e/sdk/e2e-sdk.helper'; + +let session: UserSession; + +describe('Create Subscriber - /subscribers (POST) #novu-v2', () => { + let novuClient: Novu; + + beforeEach(async () => { + session = new UserSession(); + await session.initialize(); + novuClient = initNovuClassSdk(session); + }); + + it('should create the subscriber', async () => { + const subscriberId = `test-subscriber-${`${randomBytes(4).toString('hex')}`}`; + const payload = { + subscriberId, + firstName: 'First Name', + lastName: 'Last Name', + locale: 'en_US', + timezone: 'America/New_York', + }; + + const res = await novuClient.subscribers.create(payload, payload.subscriberId); + + const subscriber = res.result; + + expect(subscriber.subscriberId).to.equal(payload.subscriberId); + expect(subscriber.firstName).to.equal(payload.firstName); + expect(subscriber.lastName).to.equal(payload.lastName); + expect(subscriber.locale).to.equal(payload.locale); + expect(subscriber.timezone).to.equal(payload.timezone); + }); + + it('should return 409 if subscriberId already exists', async () => { + const subscriberId = `test-subscriber-${`${randomBytes(4).toString('hex')}`}`; + const payload = { + subscriberId, + firstName: 'First Name', + lastName: 'Last Name', + locale: 'en_US', + timezone: 'America/New_York', + }; + + await novuClient.subscribers.create(payload, payload.subscriberId); + + const { error } = await expectSdkExceptionGeneric(() => + novuClient.subscribers.create(payload, payload.subscriberId) + ); + + expect(error?.statusCode).to.equal(409); + }); +}); diff --git a/apps/api/src/app/subscribers-v2/subscribers.controller.ts b/apps/api/src/app/subscribers-v2/subscribers.controller.ts index f27eb41114ac..6edff70151b3 100644 --- a/apps/api/src/app/subscribers-v2/subscribers.controller.ts +++ b/apps/api/src/app/subscribers-v2/subscribers.controller.ts @@ -6,6 +6,7 @@ import { Get, Param, Patch, + Post, Query, UseInterceptors, } from '@nestjs/common'; @@ -27,7 +28,7 @@ import { ListSubscribersResponseDto } from './dtos/list-subscribers-response.dto import { SdkGroupName, SdkMethodName } from '../shared/framework/swagger/sdk.decorators'; import { DirectionEnum } from '../shared/dtos/base-responses'; import { PatchSubscriberRequestDto } from './dtos/patch-subscriber.dto'; -import { SubscriberResponseDto } from '../subscribers/dtos'; +import { CreateSubscriberRequestDto, SubscriberResponseDto } from '../subscribers/dtos'; import { RemoveSubscriberCommand } from './usecases/remove-subscriber/remove-subscriber.command'; import { RemoveSubscriber } from './usecases/remove-subscriber/remove-subscriber.usecase'; import { RemoveSubscriberResponseDto } from './dtos/remove-subscriber.dto'; @@ -36,6 +37,8 @@ import { PatchSubscriberPreferencesDto } from './dtos/patch-subscriber-preferenc import { UpdateSubscriberPreferencesCommand } from './usecases/update-subscriber-preferences/update-subscriber-preferences.command'; import { UpdateSubscriberPreferences } from './usecases/update-subscriber-preferences/update-subscriber-preferences.usecase'; import { ThrottlerCategory } from '../rate-limiting/guards/throttler.decorator'; +import { CreateSubscriber } from './usecases/create-subscriber/create-subscriber.usecase'; +import { CreateSubscriberCommand } from './usecases/create-subscriber/create-subscriber.command'; @ThrottlerCategory(ApiRateLimitCategoryEnum.CONFIGURATION) @Controller({ path: '/subscribers', version: '2' }) @@ -50,7 +53,8 @@ export class SubscribersController { private patchSubscriberUsecase: PatchSubscriber, private removeSubscriberUsecase: RemoveSubscriber, private getSubscriberPreferencesUsecase: GetSubscriberPreferences, - private updateSubscriberPreferencesUsecase: UpdateSubscriberPreferences + private updateSubscriberPreferencesUsecase: UpdateSubscriberPreferences, + private createSubscriberUsecase: CreateSubscriber ) {} @Get('') @@ -101,6 +105,28 @@ export class SubscribersController { ); } + @Post('') + @UserAuthentication() + @ExternalApiAccessible() + @ApiOperation({ + summary: 'Create subscriber', + description: 'Create subscriber with the given data', + }) + @ApiResponse(SubscriberResponseDto) + @SdkMethodName('create') + async createSubscriber( + @UserSession() user: UserSessionData, + @Body() body: CreateSubscriberRequestDto + ): Promise { + return await this.createSubscriberUsecase.execute( + CreateSubscriberCommand.create({ + environmentId: user.environmentId, + organizationId: user.organizationId, + createSubscriberRequestDto: body, + }) + ); + } + @Patch('/:subscriberId') @UserAuthentication() @ExternalApiAccessible() diff --git a/apps/api/src/app/subscribers-v2/subscribers.module.ts b/apps/api/src/app/subscribers-v2/subscribers.module.ts index cbdd663a77ea..e2517c5bbca4 100644 --- a/apps/api/src/app/subscribers-v2/subscribers.module.ts +++ b/apps/api/src/app/subscribers-v2/subscribers.module.ts @@ -26,6 +26,7 @@ import { UpdateSubscriberPreferences } from './usecases/update-subscriber-prefer import { UpdatePreferences } from '../inbox/usecases/update-preferences/update-preferences.usecase'; import { GetSubscriberGlobalPreference } from '../subscribers/usecases/get-subscriber-global-preference'; import { GetSubscriberPreference } from '../subscribers/usecases/get-subscriber-preference'; +import { CreateSubscriber } from './usecases/create-subscriber/create-subscriber.usecase'; const USE_CASES = [ ListSubscribersUseCase, @@ -40,6 +41,7 @@ const USE_CASES = [ UpdatePreferences, GetSubscriberTemplatePreference, UpsertPreferences, + CreateSubscriber, ]; const DAL_MODELS = [ diff --git a/apps/api/src/app/subscribers-v2/usecases/create-subscriber/create-subscriber.command.ts b/apps/api/src/app/subscribers-v2/usecases/create-subscriber/create-subscriber.command.ts new file mode 100644 index 000000000000..c3725f8f9145 --- /dev/null +++ b/apps/api/src/app/subscribers-v2/usecases/create-subscriber/create-subscriber.command.ts @@ -0,0 +1,10 @@ +import { Type } from 'class-transformer'; +import { ValidateNested } from 'class-validator'; +import { EnvironmentCommand } from '../../../shared/commands/project.command'; +import { CreateSubscriberRequestDto } from '../../dtos/create-subscriber.dto'; + +export class CreateSubscriberCommand extends EnvironmentCommand { + @ValidateNested() + @Type(() => CreateSubscriberRequestDto) + createSubscriberRequestDto: CreateSubscriberRequestDto; +} diff --git a/apps/api/src/app/subscribers-v2/usecases/create-subscriber/create-subscriber.usecase.ts b/apps/api/src/app/subscribers-v2/usecases/create-subscriber/create-subscriber.usecase.ts new file mode 100644 index 000000000000..a432659135dd --- /dev/null +++ b/apps/api/src/app/subscribers-v2/usecases/create-subscriber/create-subscriber.usecase.ts @@ -0,0 +1,30 @@ +import { Injectable, ConflictException } from '@nestjs/common'; +import { SubscriberRepository } from '@novu/dal'; +import { SubscriberResponseDto } from '../../../subscribers/dtos'; +import { mapSubscriberEntityToDto } from '../list-subscribers/map-subscriber-entity-to.dto'; +import { CreateSubscriberCommand } from './create-subscriber.command'; + +@Injectable() +export class CreateSubscriber { + constructor(private subscriberRepository: SubscriberRepository) {} + + async execute(command: CreateSubscriberCommand): Promise { + const existingSubscriber = await this.subscriberRepository.findOne({ + subscriberId: command.createSubscriberRequestDto.subscriberId, + _environmentId: command.environmentId, + _organizationId: command.organizationId, + }); + + if (existingSubscriber) { + throw new ConflictException(`Subscriber: ${command.createSubscriberRequestDto.subscriberId} already exists`); + } + + const createdSubscriber = await this.subscriberRepository.create({ + ...command.createSubscriberRequestDto, + _environmentId: command.environmentId, + _organizationId: command.organizationId, + }); + + return mapSubscriberEntityToDto(createdSubscriber); + } +} diff --git a/apps/api/src/app/subscribers/e2e/get-preferences.e2e.ts b/apps/api/src/app/subscribers/e2e/get-preferences.e2e.ts index 3f5e3c8c108a..a82cac488c6e 100644 --- a/apps/api/src/app/subscribers/e2e/get-preferences.e2e.ts +++ b/apps/api/src/app/subscribers/e2e/get-preferences.e2e.ts @@ -21,7 +21,7 @@ describe('Get Subscribers workflow preferences - /subscribers/:subscriberId/pref }); it('should get subscriber workflow preferences with inactive channels by default', async function () { - const response = await novuClient.subscribers.preferences.list(session.subscriberId); + const response = await novuClient.subscribers.preferences.listLegacy(session.subscriberId); const data = response.result[0]; expect(data.preference.channels).to.deep.equal({ @@ -34,7 +34,7 @@ describe('Get Subscribers workflow preferences - /subscribers/:subscriberId/pref }); it('should get subscriber workflow preferences with inactive channels when includeInactiveChannels is true', async function () { - const response = await novuClient.subscribers.preferences.list(session.subscriberId, true); + const response = await novuClient.subscribers.preferences.listLegacy(session.subscriberId, true); const data = response.result[0]; expect(data.preference.channels).to.deep.equal({ @@ -47,7 +47,7 @@ describe('Get Subscribers workflow preferences - /subscribers/:subscriberId/pref }); it('should get subscriber workflow preferences with active channels when includeInactiveChannels is false', async function () { - const response = await novuClient.subscribers.preferences.list(session.subscriberId, false); + const response = await novuClient.subscribers.preferences.listLegacy(session.subscriberId, false); const data = response.result[0]; expect(data.preference.channels).to.deep.equal({ @@ -58,7 +58,7 @@ describe('Get Subscribers workflow preferences - /subscribers/:subscriberId/pref it('should handle un existing subscriberId', async function () { const { error } = await expectSdkExceptionGeneric(() => - novuClient.subscribers.preferences.list('unexisting-subscriber-id') + novuClient.subscribers.preferences.listLegacy('unexisting-subscriber-id') ); expect(error).to.be.ok; expect(error?.message).to.contain('not found'); @@ -83,7 +83,7 @@ describe('Get Subscribers preferences by level - /subscribers/:subscriberId/pref levels.forEach((level) => { it(`should get subscriber ${level} preferences with inactive channels by default`, async function () { - const response = await novuClient.subscribers.preferences.retrieveByLevel({ + const response = await novuClient.subscribers.preferences.retrieveByLevelLegacy({ preferenceLevel: level, subscriberId: session.subscriberId, }); @@ -99,7 +99,7 @@ describe('Get Subscribers preferences by level - /subscribers/:subscriberId/pref }); it(`should get subscriber ${level} preferences with inactive channels when includeInactiveChannels is true`, async function () { - const response = await novuClient.subscribers.preferences.retrieveByLevel({ + const response = await novuClient.subscribers.preferences.retrieveByLevelLegacy({ preferenceLevel: level, subscriberId: session.subscriberId, includeInactiveChannels: { @@ -118,7 +118,7 @@ describe('Get Subscribers preferences by level - /subscribers/:subscriberId/pref }); it(`should get subscriber ${level} preferences with active channels when includeInactiveChannels is false`, async function () { - const response = await novuClient.subscribers.preferences.retrieveByLevel({ + const response = await novuClient.subscribers.preferences.retrieveByLevelLegacy({ preferenceLevel: level, subscriberId: session.subscriberId, includeInactiveChannels: { diff --git a/apps/api/src/app/subscribers/e2e/update-global-preference.e2e.ts b/apps/api/src/app/subscribers/e2e/update-global-preference.e2e.ts index 3870c9ca5833..9ad0b41162c3 100644 --- a/apps/api/src/app/subscribers/e2e/update-global-preference.e2e.ts +++ b/apps/api/src/app/subscribers/e2e/update-global-preference.e2e.ts @@ -27,7 +27,7 @@ describe('Update Subscribers global preferences - /subscribers/:subscriberId/pre }; try { - const firstResponse = await novuClient.subscribers.preferences.updateGlobal( + const firstResponse = await novuClient.subscribers.preferences.legacy.updateGlobal( badPayload as any, session.subscriberId ); @@ -43,7 +43,7 @@ describe('Update Subscribers global preferences - /subscribers/:subscriberId/pre preferences: [{ type: ChannelTypeEnum.Email, enabled: true }], }; - const response = await novuClient.subscribers.preferences.updateGlobal(payload, session.subscriberId); + const response = await novuClient.subscribers.preferences.legacy.updateGlobal(payload, session.subscriberId); expect(response.result.preference.enabled).to.eql(true); expect(response.result.preference.channels).to.not.eql({ @@ -68,7 +68,7 @@ describe('Update Subscribers global preferences - /subscribers/:subscriberId/pre ], }; - const response = await novuClient.subscribers.preferences.updateGlobal(payload, session.subscriberId); + const response = await novuClient.subscribers.preferences.legacy.updateGlobal(payload, session.subscriberId); expect(response.result.preference.enabled).to.eql(true); expect(response.result.preference.channels).to.deep.eq({ @@ -111,7 +111,7 @@ describe('Update Subscribers global preferences - /subscribers/:subscriberId/pre await session.switchToDevEnvironment(); // update the subscriber global preferences in dev environment - const response = await novuClient.subscribers.preferences.updateGlobal( + const response = await novuClient.subscribers.preferences.legacy.updateGlobal( { enabled: true, preferences: [{ type: ChannelTypeEnumInShared.IN_APP, enabled: false }], @@ -129,7 +129,7 @@ describe('Update Subscribers global preferences - /subscribers/:subscriberId/pre } as PreferenceChannels); // get the subscriber preferences in dev environment - const getDevPreferencesResponse = await novuClient.subscribers.preferences.list(session.subscriberId); + const getDevPreferencesResponse = await novuClient.subscribers.preferences.listLegacy(session.subscriberId); const devPreferences = getDevPreferencesResponse.result; expect(devPreferences.every((item) => !!item.preference.channels.inApp)).to.be.false; @@ -138,7 +138,9 @@ describe('Update Subscribers global preferences - /subscribers/:subscriberId/pre // get the subscriber preferences in prod environment session.apiKey = session.environment.apiKeys[0].key; const novuClientForProduction = initNovuClassSdk(session); - const getProdPreferencesResponse = await novuClientForProduction.subscribers.preferences.list(session.subscriberId); + const getProdPreferencesResponse = await novuClientForProduction.subscribers.preferences.listLegacy( + session.subscriberId + ); const prodPreferences = getProdPreferencesResponse.result; expect(prodPreferences.every((item) => !!item.preference.channels.inApp)).to.be.true; }); diff --git a/apps/api/src/app/subscribers/e2e/update-preference.e2e.ts b/apps/api/src/app/subscribers/e2e/update-preference.e2e.ts index 6517936e6c71..0511e5173984 100644 --- a/apps/api/src/app/subscribers/e2e/update-preference.e2e.ts +++ b/apps/api/src/app/subscribers/e2e/update-preference.e2e.ts @@ -128,7 +128,7 @@ describe('Update Subscribers preferences - /subscribers/:subscriberId/preference }); it('should not do any action or error when sending an empty channels property', async function () { - const initialPreferences = (await novuClient.subscribers.preferences.list(session.subscriberId)).result[0]; + const initialPreferences = (await novuClient.subscribers.preferences.listLegacy(session.subscriberId)).result[0]; expect(initialPreferences.preference.enabled).to.eql(true); expect(initialPreferences.preference.channels).to.eql({ email: true, @@ -148,7 +148,7 @@ describe('Update Subscribers preferences - /subscribers/:subscriberId/preference updateSubscriberPreferenceRequestDto: emptyPreferenceData as any, }); - const preferences = (await novuClient.subscribers.preferences.list(session.subscriberId)).result[0]; + const preferences = (await novuClient.subscribers.preferences.listLegacy(session.subscriberId)).result[0]; expect(preferences.preference.enabled).to.eql(true); expect(preferences.preference.channels).to.eql({ @@ -162,7 +162,7 @@ describe('Update Subscribers preferences - /subscribers/:subscriberId/preference // `enabled` flag is not used anymore. The presence of a preference object means that the subscriber has enabled notifications. it.skip('should update user preference and disable the flag for the future general notification template preference', async function () { - const initialPreferences = (await novuClient.subscribers.preferences.list(session.subscriberId)).result[0]; + const initialPreferences = (await novuClient.subscribers.preferences.listLegacy(session.subscriberId)).result[0]; expect(initialPreferences.preference.enabled).to.eql(true); expect(initialPreferences.preference.channels).to.eql({ email: true, @@ -182,7 +182,7 @@ describe('Update Subscribers preferences - /subscribers/:subscriberId/preference updateSubscriberPreferenceRequestDto: disablePreferenceData, }); - const midwayPreferences = (await novuClient.subscribers.preferences.list(session.subscriberId)).result[0]; + const midwayPreferences = (await novuClient.subscribers.preferences.listLegacy(session.subscriberId)).result[0]; expect(midwayPreferences.preference.enabled).to.eql(false); expect(midwayPreferences.preference.channels).to.eql({ email: true, @@ -205,7 +205,7 @@ describe('Update Subscribers preferences - /subscribers/:subscriberId/preference updateSubscriberPreferenceRequestDto: updateEmailPreferenceData, }); - const finalPreferences = (await novuClient.subscribers.preferences.list(session.subscriberId)).result[0]; + const finalPreferences = (await novuClient.subscribers.preferences.listLegacy(session.subscriberId)).result[0]; expect(finalPreferences.preference.enabled).to.eql(false); expect(finalPreferences.preference.channels).to.eql({ email: false, @@ -218,7 +218,7 @@ describe('Update Subscribers preferences - /subscribers/:subscriberId/preference // `enabled` flag is not used anymore. The presence of a preference object means that the subscriber has enabled notifications. it.skip('should update user preference and enable the flag for the future general notification template preference', async function () { - const initialPreferences = (await novuClient.subscribers.preferences.list(session.subscriberId)).result[0]; + const initialPreferences = (await novuClient.subscribers.preferences.listLegacy(session.subscriberId)).result[0]; expect(initialPreferences.preference.enabled).to.eql(true); expect(initialPreferences.preference.channels).to.eql({ email: true, @@ -238,7 +238,7 @@ describe('Update Subscribers preferences - /subscribers/:subscriberId/preference updateSubscriberPreferenceRequestDto: disablePreferenceData, }); - const midwayPreferences = (await novuClient.subscribers.preferences.list(session.subscriberId)).result[0]; + const midwayPreferences = (await novuClient.subscribers.preferences.listLegacy(session.subscriberId)).result[0]; expect(midwayPreferences.preference.enabled).to.eql(false); expect(midwayPreferences.preference.channels).to.eql({ email: true, @@ -258,7 +258,7 @@ describe('Update Subscribers preferences - /subscribers/:subscriberId/preference updateSubscriberPreferenceRequestDto: enablePreferenceData, }); - const finalPreferences = (await novuClient.subscribers.preferences.list(session.subscriberId)).result[0]; + const finalPreferences = (await novuClient.subscribers.preferences.listLegacy(session.subscriberId)).result[0]; expect(finalPreferences.preference.enabled).to.eql(true); expect(finalPreferences.preference.channels).to.eql({ email: true, @@ -270,7 +270,7 @@ describe('Update Subscribers preferences - /subscribers/:subscriberId/preference }); it('should be able to update the subscriber preference for an active channel of the template', async function () { - const initialPreferences = (await novuClient.subscribers.preferences.list(session.subscriberId)).result[0]; + const initialPreferences = (await novuClient.subscribers.preferences.listLegacy(session.subscriberId)).result[0]; expect(initialPreferences.preference.enabled).to.eql(true); expect(initialPreferences.preference.channels).to.eql({ email: true, @@ -293,7 +293,7 @@ describe('Update Subscribers preferences - /subscribers/:subscriberId/preference updateSubscriberPreferenceRequestDto: disableEmailPreferenceData, }); - const updatedPreferences = (await novuClient.subscribers.preferences.list(session.subscriberId)).result[0]; + const updatedPreferences = (await novuClient.subscribers.preferences.listLegacy(session.subscriberId)).result[0]; expect(updatedPreferences.preference.enabled).to.eql(true); expect(updatedPreferences.preference.channels).to.eql({ email: false, @@ -316,7 +316,7 @@ describe('Update Subscribers preferences - /subscribers/:subscriberId/preference updateSubscriberPreferenceRequestDto: enableEmailPreferenceData, }); - const finalPreferences = (await novuClient.subscribers.preferences.list(session.subscriberId)).result[0]; + const finalPreferences = (await novuClient.subscribers.preferences.listLegacy(session.subscriberId)).result[0]; expect(finalPreferences.preference.enabled).to.eql(true); expect(finalPreferences.preference.channels).to.eql({ email: true, @@ -328,7 +328,7 @@ describe('Update Subscribers preferences - /subscribers/:subscriberId/preference }); it('should ignore the channel update if channel not being used in the notification template', async function () { - const initialPreferences = (await novuClient.subscribers.preferences.list(session.subscriberId)).result[0]; + const initialPreferences = (await novuClient.subscribers.preferences.listLegacy(session.subscriberId)).result[0]; expect(initialPreferences.preference.enabled).to.eql(true); expect(initialPreferences.preference.channels).to.eql({ email: true, @@ -351,7 +351,7 @@ describe('Update Subscribers preferences - /subscribers/:subscriberId/preference updateSubscriberPreferenceRequestDto: updateSmsPreferenceData, }); - const finalPreferences = (await novuClient.subscribers.preferences.list(session.subscriberId)).result[0]; + const finalPreferences = (await novuClient.subscribers.preferences.listLegacy(session.subscriberId)).result[0]; expect(finalPreferences.preference.enabled).to.eql(true); expect(finalPreferences.preference.channels).to.eql({ email: true, @@ -384,7 +384,7 @@ describe('Update Subscribers preferences - /subscribers/:subscriberId/preference const updatedNotificationTemplate = (await getNotificationTemplate(session, template._id)).data.data; expect(updatedNotificationTemplate.steps.length).to.eql(3); - const initialPreferences = (await novuClient.subscribers.preferences.list(session.subscriberId)).result[0]; + const initialPreferences = (await novuClient.subscribers.preferences.listLegacy(session.subscriberId)).result[0]; expect(initialPreferences.preference.enabled).to.eql(true); expect(initialPreferences.preference.channels).to.eql({ email: true, @@ -407,7 +407,7 @@ describe('Update Subscribers preferences - /subscribers/:subscriberId/preference updateSubscriberPreferenceRequestDto: updateSmsPreferenceData, }); - const finalPreferences = (await novuClient.subscribers.preferences.list(session.subscriberId)).result[0]; + const finalPreferences = (await novuClient.subscribers.preferences.listLegacy(session.subscriberId)).result[0]; expect(finalPreferences.preference.enabled).to.eql(true); expect(finalPreferences.preference.channels).to.eql({ email: true, @@ -446,7 +446,7 @@ describe('Update Subscribers preferences - /subscribers/:subscriberId/preference const updatedNotificationTemplate = (await getNotificationTemplate(session, template._id)).data.data; expect(updatedNotificationTemplate.steps.length).to.eql(3); - const initialPreferences = (await novuClient.subscribers.preferences.list(session.subscriberId)).result[0]; + const initialPreferences = (await novuClient.subscribers.preferences.listLegacy(session.subscriberId)).result[0]; expect(initialPreferences.preference.enabled).to.eql(true); expect(initialPreferences.preference.channels).to.eql({ email: true, @@ -469,7 +469,7 @@ describe('Update Subscribers preferences - /subscribers/:subscriberId/preference updateSubscriberPreferenceRequestDto: updateSmsPreferenceData, }); - const finalPreferences = (await novuClient.subscribers.preferences.list(session.subscriberId)).result[0]; + const finalPreferences = (await novuClient.subscribers.preferences.listLegacy(session.subscriberId)).result[0]; expect(finalPreferences.preference.enabled).to.eql(true); expect(finalPreferences.preference.channels).to.eql({ email: false, diff --git a/apps/api/src/app/subscribers/e2e/update-subscriber.e2e.ts b/apps/api/src/app/subscribers/e2e/update-subscriber.e2e.ts index 04e209b90c7e..026683041169 100644 --- a/apps/api/src/app/subscribers/e2e/update-subscriber.e2e.ts +++ b/apps/api/src/app/subscribers/e2e/update-subscriber.e2e.ts @@ -23,7 +23,7 @@ describe('Update Subscriber - /subscribers/:subscriberId (PUT) #novu-v2', functi email: 'john@doe.com', }); - const response = await novuClient.subscribers.update( + const response = await novuClient.subscribers.updateLegacy( { lastName: 'Test Changed', email: 'changed@mail.com', @@ -55,7 +55,7 @@ describe('Update Subscriber - /subscribers/:subscriberId (PUT) #novu-v2', functi email: 'john@doe.com', }); - const response = await novuClient.subscribers.update( + const response = await novuClient.subscribers.updateLegacy( { lastName: 'Test Changed', phone: '+972523333333', diff --git a/apps/api/src/app/subscribers/subscribersV1.controller.ts b/apps/api/src/app/subscribers/subscribersV1.controller.ts index e57a5ebff347..52cd1c4dd776 100644 --- a/apps/api/src/app/subscribers/subscribersV1.controller.ts +++ b/apps/api/src/app/subscribers/subscribersV1.controller.ts @@ -197,6 +197,7 @@ export class SubscribersV1Controller { @ExternalApiAccessible() @UserAuthentication() @ApiResponse(SubscriberResponseDto, 201) + @SdkMethodName('createLegacy') @ApiOperation({ summary: 'Create subscriber', description: diff --git a/libs/internal-sdk/.speakeasy/workflow.yaml b/libs/internal-sdk/.speakeasy/workflow.yaml index e4c8e3222dcf..27e9c6681511 100644 --- a/libs/internal-sdk/.speakeasy/workflow.yaml +++ b/libs/internal-sdk/.speakeasy/workflow.yaml @@ -15,5 +15,5 @@ targets: source: internal-sdk-OAS codeSamples: registry: - location: registry.speakeasyapi.dev/novu/novu/json-development-internal-code-samples + location: registry.speakeasyapi.dev/novu/novu/json-development-internal-typescript-code-samples blocking: false diff --git a/libs/internal-sdk/src/funcs/subscribersCreate.ts b/libs/internal-sdk/src/funcs/subscribersCreate.ts index cb31f977fc2a..e452d17938df 100644 --- a/libs/internal-sdk/src/funcs/subscribersCreate.ts +++ b/libs/internal-sdk/src/funcs/subscribersCreate.ts @@ -28,7 +28,7 @@ import { Result } from "../types/fp.js"; * Create subscriber * * @remarks - * Creates a subscriber entity, in the Novu platform. The subscriber will be later used to receive notifications, and access notification feeds. Communication credentials such as email, phone number, and 3 rd party credentials i.e slack tokens could be later associated to this entity. + * Create subscriber with the given data */ export async function subscribersCreate( client: NovuCore, @@ -37,7 +37,7 @@ export async function subscribersCreate( options?: RequestOptions, ): Promise< Result< - operations.SubscribersV1ControllerCreateSubscriberResponse, + operations.SubscribersControllerCreateSubscriberResponse, | errors.ErrorDto | errors.ErrorDto | errors.ValidationErrorDto @@ -51,7 +51,7 @@ export async function subscribersCreate( | ConnectionError > > { - const input: operations.SubscribersV1ControllerCreateSubscriberRequest = { + const input: operations.SubscribersControllerCreateSubscriberRequest = { createSubscriberRequestDto: createSubscriberRequestDto, idempotencyKey: idempotencyKey, }; @@ -59,7 +59,7 @@ export async function subscribersCreate( const parsed = safeParse( input, (value) => - operations.SubscribersV1ControllerCreateSubscriberRequest$outboundSchema + operations.SubscribersControllerCreateSubscriberRequest$outboundSchema .parse(value), "Input validation failed", ); @@ -71,7 +71,7 @@ export async function subscribersCreate( explode: true, }); - const path = pathToFunc("/v1/subscribers")(); + const path = pathToFunc("/v2/subscribers")(); const headers = new Headers(compactMap({ "Content-Type": "application/json", @@ -87,7 +87,7 @@ export async function subscribersCreate( const requestSecurity = resolveGlobalSecurity(securityInput); const context = { - operationID: "SubscribersV1Controller_createSubscriber", + operationID: "SubscribersController_createSubscriber", oAuth2Scopes: [], resolvedSecurity: requestSecurity, @@ -155,7 +155,7 @@ export async function subscribersCreate( }; const [result] = await M.match< - operations.SubscribersV1ControllerCreateSubscriberResponse, + operations.SubscribersControllerCreateSubscriberResponse, | errors.ErrorDto | errors.ErrorDto | errors.ValidationErrorDto @@ -169,8 +169,8 @@ export async function subscribersCreate( | ConnectionError >( M.json( - 201, - operations.SubscribersV1ControllerCreateSubscriberResponse$inboundSchema, + 200, + operations.SubscribersControllerCreateSubscriberResponse$inboundSchema, { hdrs: true, key: "Result" }, ), M.jsonErr(414, errors.ErrorDto$inboundSchema), diff --git a/libs/internal-sdk/src/funcs/subscribersCreateLegacy.ts b/libs/internal-sdk/src/funcs/subscribersCreateLegacy.ts new file mode 100644 index 000000000000..daa05ded204b --- /dev/null +++ b/libs/internal-sdk/src/funcs/subscribersCreateLegacy.ts @@ -0,0 +1,194 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import { NovuCore } from "../core.js"; +import { encodeJSON, encodeSimple } from "../lib/encodings.js"; +import * as M from "../lib/matchers.js"; +import { compactMap } from "../lib/primitives.js"; +import { safeParse } from "../lib/schemas.js"; +import { RequestOptions } from "../lib/sdks.js"; +import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js"; +import { pathToFunc } from "../lib/url.js"; +import * as components from "../models/components/index.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../models/errors/httpclienterrors.js"; +import * as errors from "../models/errors/index.js"; +import { SDKError } from "../models/errors/sdkerror.js"; +import { SDKValidationError } from "../models/errors/sdkvalidationerror.js"; +import * as operations from "../models/operations/index.js"; +import { Result } from "../types/fp.js"; + +/** + * Create subscriber + * + * @remarks + * Creates a subscriber entity, in the Novu platform. The subscriber will be later used to receive notifications, and access notification feeds. Communication credentials such as email, phone number, and 3 rd party credentials i.e slack tokens could be later associated to this entity. + */ +export async function subscribersCreateLegacy( + client: NovuCore, + createSubscriberRequestDto: components.CreateSubscriberRequestDto, + idempotencyKey?: string | undefined, + options?: RequestOptions, +): Promise< + Result< + operations.SubscribersV1ControllerCreateSubscriberResponse, + | errors.ErrorDto + | errors.ErrorDto + | errors.ValidationErrorDto + | errors.ErrorDto + | SDKError + | SDKValidationError + | UnexpectedClientError + | InvalidRequestError + | RequestAbortedError + | RequestTimeoutError + | ConnectionError + > +> { + const input: operations.SubscribersV1ControllerCreateSubscriberRequest = { + createSubscriberRequestDto: createSubscriberRequestDto, + idempotencyKey: idempotencyKey, + }; + + const parsed = safeParse( + input, + (value) => + operations.SubscribersV1ControllerCreateSubscriberRequest$outboundSchema + .parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return parsed; + } + const payload = parsed.value; + const body = encodeJSON("body", payload.CreateSubscriberRequestDto, { + explode: true, + }); + + const path = pathToFunc("/v1/subscribers")(); + + const headers = new Headers(compactMap({ + "Content-Type": "application/json", + Accept: "application/json", + "idempotency-key": encodeSimple( + "idempotency-key", + payload["idempotency-key"], + { explode: false, charEncoding: "none" }, + ), + })); + + const securityInput = await extractSecurity(client._options.security); + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + operationID: "SubscribersV1Controller_createSubscriber", + oAuth2Scopes: [], + + resolvedSecurity: requestSecurity, + + securitySource: client._options.security, + retryConfig: options?.retries + || client._options.retryConfig + || { + strategy: "backoff", + backoff: { + initialInterval: 1000, + maxInterval: 30000, + exponent: 1.5, + maxElapsedTime: 3600000, + }, + retryConnectionErrors: true, + } + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["408", "409", "429", "5XX"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "POST", + baseURL: options?.serverURL, + path: path, + headers: headers, + body: body, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: [ + "400", + "401", + "403", + "404", + "405", + "409", + "413", + "414", + "415", + "422", + "429", + "4XX", + "500", + "503", + "5XX", + ], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.SubscribersV1ControllerCreateSubscriberResponse, + | errors.ErrorDto + | errors.ErrorDto + | errors.ValidationErrorDto + | errors.ErrorDto + | SDKError + | SDKValidationError + | UnexpectedClientError + | InvalidRequestError + | RequestAbortedError + | RequestTimeoutError + | ConnectionError + >( + M.json( + 201, + operations.SubscribersV1ControllerCreateSubscriberResponse$inboundSchema, + { hdrs: true, key: "Result" }, + ), + M.jsonErr(414, errors.ErrorDto$inboundSchema), + M.jsonErr( + [400, 401, 403, 404, 405, 409, 413, 415], + errors.ErrorDto$inboundSchema, + { hdrs: true }, + ), + M.jsonErr(422, errors.ValidationErrorDto$inboundSchema, { hdrs: true }), + M.fail(429), + M.jsonErr(500, errors.ErrorDto$inboundSchema, { hdrs: true }), + M.fail(503), + M.fail("4XX"), + M.fail("5XX"), + )(response, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} diff --git a/libs/internal-sdk/src/funcs/subscribersPreferencesLegacyUpdateGlobal.ts b/libs/internal-sdk/src/funcs/subscribersPreferencesLegacyUpdateGlobal.ts new file mode 100644 index 000000000000..6a8892d330ae --- /dev/null +++ b/libs/internal-sdk/src/funcs/subscribersPreferencesLegacyUpdateGlobal.ts @@ -0,0 +1,210 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import { NovuCore } from "../core.js"; +import { encodeJSON, encodeSimple } from "../lib/encodings.js"; +import * as M from "../lib/matchers.js"; +import { compactMap } from "../lib/primitives.js"; +import { safeParse } from "../lib/schemas.js"; +import { RequestOptions } from "../lib/sdks.js"; +import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js"; +import { pathToFunc } from "../lib/url.js"; +import * as components from "../models/components/index.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../models/errors/httpclienterrors.js"; +import * as errors from "../models/errors/index.js"; +import { SDKError } from "../models/errors/sdkerror.js"; +import { SDKValidationError } from "../models/errors/sdkvalidationerror.js"; +import * as operations from "../models/operations/index.js"; +import { Result } from "../types/fp.js"; + +/** + * Update subscriber global preferences + */ +export async function subscribersPreferencesLegacyUpdateGlobal( + client: NovuCore, + updateSubscriberGlobalPreferencesRequestDto: + components.UpdateSubscriberGlobalPreferencesRequestDto, + subscriberId: string, + idempotencyKey?: string | undefined, + options?: RequestOptions, +): Promise< + Result< + operations.SubscribersV1ControllerUpdateSubscriberGlobalPreferencesResponse, + | errors.ErrorDto + | errors.ErrorDto + | errors.ValidationErrorDto + | errors.ErrorDto + | SDKError + | SDKValidationError + | UnexpectedClientError + | InvalidRequestError + | RequestAbortedError + | RequestTimeoutError + | ConnectionError + > +> { + const input: + operations.SubscribersV1ControllerUpdateSubscriberGlobalPreferencesRequest = + { + updateSubscriberGlobalPreferencesRequestDto: + updateSubscriberGlobalPreferencesRequestDto, + subscriberId: subscriberId, + idempotencyKey: idempotencyKey, + }; + + const parsed = safeParse( + input, + (value) => + operations + .SubscribersV1ControllerUpdateSubscriberGlobalPreferencesRequest$outboundSchema + .parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return parsed; + } + const payload = parsed.value; + const body = encodeJSON( + "body", + payload.UpdateSubscriberGlobalPreferencesRequestDto, + { explode: true }, + ); + + const pathParams = { + subscriberId: encodeSimple("subscriberId", payload.subscriberId, { + explode: false, + charEncoding: "percent", + }), + }; + + const path = pathToFunc("/v1/subscribers/{subscriberId}/preferences")( + pathParams, + ); + + const headers = new Headers(compactMap({ + "Content-Type": "application/json", + Accept: "application/json", + "idempotency-key": encodeSimple( + "idempotency-key", + payload["idempotency-key"], + { explode: false, charEncoding: "none" }, + ), + })); + + const securityInput = await extractSecurity(client._options.security); + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + operationID: "SubscribersV1Controller_updateSubscriberGlobalPreferences", + oAuth2Scopes: [], + + resolvedSecurity: requestSecurity, + + securitySource: client._options.security, + retryConfig: options?.retries + || client._options.retryConfig + || { + strategy: "backoff", + backoff: { + initialInterval: 1000, + maxInterval: 30000, + exponent: 1.5, + maxElapsedTime: 3600000, + }, + retryConnectionErrors: true, + } + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["408", "409", "429", "5XX"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "PATCH", + baseURL: options?.serverURL, + path: path, + headers: headers, + body: body, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: [ + "400", + "401", + "403", + "404", + "405", + "409", + "413", + "414", + "415", + "422", + "429", + "4XX", + "500", + "503", + "5XX", + ], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.SubscribersV1ControllerUpdateSubscriberGlobalPreferencesResponse, + | errors.ErrorDto + | errors.ErrorDto + | errors.ValidationErrorDto + | errors.ErrorDto + | SDKError + | SDKValidationError + | UnexpectedClientError + | InvalidRequestError + | RequestAbortedError + | RequestTimeoutError + | ConnectionError + >( + M.json( + 200, + operations + .SubscribersV1ControllerUpdateSubscriberGlobalPreferencesResponse$inboundSchema, + { hdrs: true, key: "Result" }, + ), + M.jsonErr(414, errors.ErrorDto$inboundSchema), + M.jsonErr( + [400, 401, 403, 404, 405, 409, 413, 415], + errors.ErrorDto$inboundSchema, + { hdrs: true }, + ), + M.jsonErr(422, errors.ValidationErrorDto$inboundSchema, { hdrs: true }), + M.fail(429), + M.jsonErr(500, errors.ErrorDto$inboundSchema, { hdrs: true }), + M.fail(503), + M.fail("4XX"), + M.fail("5XX"), + )(response, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} diff --git a/libs/internal-sdk/src/funcs/subscribersPreferencesListLegacy.ts b/libs/internal-sdk/src/funcs/subscribersPreferencesListLegacy.ts new file mode 100644 index 000000000000..5f9ec8ffc594 --- /dev/null +++ b/libs/internal-sdk/src/funcs/subscribersPreferencesListLegacy.ts @@ -0,0 +1,208 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import { NovuCore } from "../core.js"; +import { encodeFormQuery, encodeSimple } from "../lib/encodings.js"; +import * as M from "../lib/matchers.js"; +import { compactMap } from "../lib/primitives.js"; +import { safeParse } from "../lib/schemas.js"; +import { RequestOptions } from "../lib/sdks.js"; +import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js"; +import { pathToFunc } from "../lib/url.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../models/errors/httpclienterrors.js"; +import * as errors from "../models/errors/index.js"; +import { SDKError } from "../models/errors/sdkerror.js"; +import { SDKValidationError } from "../models/errors/sdkvalidationerror.js"; +import * as operations from "../models/operations/index.js"; +import { Result } from "../types/fp.js"; + +/** + * Get subscriber preferences + * + * @deprecated method: This will be removed in a future release, please migrate away from it as soon as possible. + */ +export async function subscribersPreferencesListLegacy( + client: NovuCore, + subscriberId: string, + includeInactiveChannels?: boolean | undefined, + idempotencyKey?: string | undefined, + options?: RequestOptions, +): Promise< + Result< + operations.SubscribersV1ControllerListSubscriberPreferencesResponse, + | errors.ErrorDto + | errors.ErrorDto + | errors.ValidationErrorDto + | errors.ErrorDto + | SDKError + | SDKValidationError + | UnexpectedClientError + | InvalidRequestError + | RequestAbortedError + | RequestTimeoutError + | ConnectionError + > +> { + const input: + operations.SubscribersV1ControllerListSubscriberPreferencesRequest = { + subscriberId: subscriberId, + includeInactiveChannels: includeInactiveChannels, + idempotencyKey: idempotencyKey, + }; + + const parsed = safeParse( + input, + (value) => + operations + .SubscribersV1ControllerListSubscriberPreferencesRequest$outboundSchema + .parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return parsed; + } + const payload = parsed.value; + const body = null; + + const pathParams = { + subscriberId: encodeSimple("subscriberId", payload.subscriberId, { + explode: false, + charEncoding: "percent", + }), + }; + + const path = pathToFunc("/v1/subscribers/{subscriberId}/preferences")( + pathParams, + ); + + const query = encodeFormQuery({ + "includeInactiveChannels": payload.includeInactiveChannels, + }); + + const headers = new Headers(compactMap({ + Accept: "application/json", + "idempotency-key": encodeSimple( + "idempotency-key", + payload["idempotency-key"], + { explode: false, charEncoding: "none" }, + ), + })); + + const securityInput = await extractSecurity(client._options.security); + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + operationID: "SubscribersV1Controller_listSubscriberPreferences", + oAuth2Scopes: [], + + resolvedSecurity: requestSecurity, + + securitySource: client._options.security, + retryConfig: options?.retries + || client._options.retryConfig + || { + strategy: "backoff", + backoff: { + initialInterval: 1000, + maxInterval: 30000, + exponent: 1.5, + maxElapsedTime: 3600000, + }, + retryConnectionErrors: true, + } + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["408", "409", "429", "5XX"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "GET", + baseURL: options?.serverURL, + path: path, + headers: headers, + query: query, + body: body, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: [ + "400", + "401", + "403", + "404", + "405", + "409", + "413", + "414", + "415", + "422", + "429", + "4XX", + "500", + "503", + "5XX", + ], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.SubscribersV1ControllerListSubscriberPreferencesResponse, + | errors.ErrorDto + | errors.ErrorDto + | errors.ValidationErrorDto + | errors.ErrorDto + | SDKError + | SDKValidationError + | UnexpectedClientError + | InvalidRequestError + | RequestAbortedError + | RequestTimeoutError + | ConnectionError + >( + M.json( + 200, + operations + .SubscribersV1ControllerListSubscriberPreferencesResponse$inboundSchema, + { hdrs: true, key: "Result" }, + ), + M.jsonErr(414, errors.ErrorDto$inboundSchema), + M.jsonErr( + [400, 401, 403, 404, 405, 409, 413, 415], + errors.ErrorDto$inboundSchema, + { hdrs: true }, + ), + M.jsonErr(422, errors.ValidationErrorDto$inboundSchema, { hdrs: true }), + M.fail(429), + M.jsonErr(500, errors.ErrorDto$inboundSchema, { hdrs: true }), + M.fail(503), + M.fail("4XX"), + M.fail("5XX"), + )(response, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} diff --git a/libs/internal-sdk/src/funcs/subscribersPreferencesRetrieveByLevelLegacy.ts b/libs/internal-sdk/src/funcs/subscribersPreferencesRetrieveByLevelLegacy.ts new file mode 100644 index 000000000000..34133d5aa528 --- /dev/null +++ b/libs/internal-sdk/src/funcs/subscribersPreferencesRetrieveByLevelLegacy.ts @@ -0,0 +1,204 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import { NovuCore } from "../core.js"; +import { encodeFormQuery, encodeSimple } from "../lib/encodings.js"; +import * as M from "../lib/matchers.js"; +import { compactMap } from "../lib/primitives.js"; +import { safeParse } from "../lib/schemas.js"; +import { RequestOptions } from "../lib/sdks.js"; +import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js"; +import { pathToFunc } from "../lib/url.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../models/errors/httpclienterrors.js"; +import * as errors from "../models/errors/index.js"; +import { SDKError } from "../models/errors/sdkerror.js"; +import { SDKValidationError } from "../models/errors/sdkvalidationerror.js"; +import * as operations from "../models/operations/index.js"; +import { Result } from "../types/fp.js"; + +/** + * Get subscriber preferences by level + * + * @deprecated method: This will be removed in a future release, please migrate away from it as soon as possible. + */ +export async function subscribersPreferencesRetrieveByLevelLegacy( + client: NovuCore, + request: + operations.SubscribersV1ControllerGetSubscriberPreferenceByLevelRequest, + options?: RequestOptions, +): Promise< + Result< + operations.SubscribersV1ControllerGetSubscriberPreferenceByLevelResponse, + | errors.ErrorDto + | errors.ErrorDto + | errors.ValidationErrorDto + | errors.ErrorDto + | SDKError + | SDKValidationError + | UnexpectedClientError + | InvalidRequestError + | RequestAbortedError + | RequestTimeoutError + | ConnectionError + > +> { + const parsed = safeParse( + request, + (value) => + operations + .SubscribersV1ControllerGetSubscriberPreferenceByLevelRequest$outboundSchema + .parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return parsed; + } + const payload = parsed.value; + const body = null; + + const pathParams = { + parameter: encodeSimple("parameter", payload.preferenceLevel, { + explode: false, + charEncoding: "percent", + }), + subscriberId: encodeSimple("subscriberId", payload.subscriberId, { + explode: false, + charEncoding: "percent", + }), + }; + + const path = pathToFunc( + "/v1/subscribers/{subscriberId}/preferences/{parameter}", + )(pathParams); + + const query = encodeFormQuery({ + "includeInactiveChannels": payload.includeInactiveChannels, + }); + + const headers = new Headers(compactMap({ + Accept: "application/json", + "idempotency-key": encodeSimple( + "idempotency-key", + payload["idempotency-key"], + { explode: false, charEncoding: "none" }, + ), + })); + + const securityInput = await extractSecurity(client._options.security); + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + operationID: "SubscribersV1Controller_getSubscriberPreferenceByLevel", + oAuth2Scopes: [], + + resolvedSecurity: requestSecurity, + + securitySource: client._options.security, + retryConfig: options?.retries + || client._options.retryConfig + || { + strategy: "backoff", + backoff: { + initialInterval: 1000, + maxInterval: 30000, + exponent: 1.5, + maxElapsedTime: 3600000, + }, + retryConnectionErrors: true, + } + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["408", "409", "429", "5XX"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "GET", + baseURL: options?.serverURL, + path: path, + headers: headers, + query: query, + body: body, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: [ + "400", + "401", + "403", + "404", + "405", + "409", + "413", + "414", + "415", + "422", + "429", + "4XX", + "500", + "503", + "5XX", + ], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.SubscribersV1ControllerGetSubscriberPreferenceByLevelResponse, + | errors.ErrorDto + | errors.ErrorDto + | errors.ValidationErrorDto + | errors.ErrorDto + | SDKError + | SDKValidationError + | UnexpectedClientError + | InvalidRequestError + | RequestAbortedError + | RequestTimeoutError + | ConnectionError + >( + M.json( + 200, + operations + .SubscribersV1ControllerGetSubscriberPreferenceByLevelResponse$inboundSchema, + { hdrs: true, key: "Result" }, + ), + M.jsonErr(414, errors.ErrorDto$inboundSchema), + M.jsonErr( + [400, 401, 403, 404, 405, 409, 413, 415], + errors.ErrorDto$inboundSchema, + { hdrs: true }, + ), + M.jsonErr(422, errors.ValidationErrorDto$inboundSchema, { hdrs: true }), + M.fail(429), + M.jsonErr(500, errors.ErrorDto$inboundSchema, { hdrs: true }), + M.fail(503), + M.fail("4XX"), + M.fail("5XX"), + )(response, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} diff --git a/libs/internal-sdk/src/funcs/subscribersUpdateLegacy.ts b/libs/internal-sdk/src/funcs/subscribersUpdateLegacy.ts new file mode 100644 index 000000000000..0f23ea3327db --- /dev/null +++ b/libs/internal-sdk/src/funcs/subscribersUpdateLegacy.ts @@ -0,0 +1,203 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import { NovuCore } from "../core.js"; +import { encodeJSON, encodeSimple } from "../lib/encodings.js"; +import * as M from "../lib/matchers.js"; +import { compactMap } from "../lib/primitives.js"; +import { safeParse } from "../lib/schemas.js"; +import { RequestOptions } from "../lib/sdks.js"; +import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js"; +import { pathToFunc } from "../lib/url.js"; +import * as components from "../models/components/index.js"; +import { + ConnectionError, + InvalidRequestError, + RequestAbortedError, + RequestTimeoutError, + UnexpectedClientError, +} from "../models/errors/httpclienterrors.js"; +import * as errors from "../models/errors/index.js"; +import { SDKError } from "../models/errors/sdkerror.js"; +import { SDKValidationError } from "../models/errors/sdkvalidationerror.js"; +import * as operations from "../models/operations/index.js"; +import { Result } from "../types/fp.js"; + +/** + * Update subscriber + * + * @remarks + * Used to update the subscriber entity with new information + */ +export async function subscribersUpdateLegacy( + client: NovuCore, + updateSubscriberRequestDto: components.UpdateSubscriberRequestDto, + subscriberId: string, + idempotencyKey?: string | undefined, + options?: RequestOptions, +): Promise< + Result< + operations.SubscribersV1ControllerUpdateSubscriberResponse, + | errors.ErrorDto + | errors.ErrorDto + | errors.ValidationErrorDto + | errors.ErrorDto + | SDKError + | SDKValidationError + | UnexpectedClientError + | InvalidRequestError + | RequestAbortedError + | RequestTimeoutError + | ConnectionError + > +> { + const input: operations.SubscribersV1ControllerUpdateSubscriberRequest = { + updateSubscriberRequestDto: updateSubscriberRequestDto, + subscriberId: subscriberId, + idempotencyKey: idempotencyKey, + }; + + const parsed = safeParse( + input, + (value) => + operations.SubscribersV1ControllerUpdateSubscriberRequest$outboundSchema + .parse(value), + "Input validation failed", + ); + if (!parsed.ok) { + return parsed; + } + const payload = parsed.value; + const body = encodeJSON("body", payload.UpdateSubscriberRequestDto, { + explode: true, + }); + + const pathParams = { + subscriberId: encodeSimple("subscriberId", payload.subscriberId, { + explode: false, + charEncoding: "percent", + }), + }; + + const path = pathToFunc("/v1/subscribers/{subscriberId}")(pathParams); + + const headers = new Headers(compactMap({ + "Content-Type": "application/json", + Accept: "application/json", + "idempotency-key": encodeSimple( + "idempotency-key", + payload["idempotency-key"], + { explode: false, charEncoding: "none" }, + ), + })); + + const securityInput = await extractSecurity(client._options.security); + const requestSecurity = resolveGlobalSecurity(securityInput); + + const context = { + operationID: "SubscribersV1Controller_updateSubscriber", + oAuth2Scopes: [], + + resolvedSecurity: requestSecurity, + + securitySource: client._options.security, + retryConfig: options?.retries + || client._options.retryConfig + || { + strategy: "backoff", + backoff: { + initialInterval: 1000, + maxInterval: 30000, + exponent: 1.5, + maxElapsedTime: 3600000, + }, + retryConnectionErrors: true, + } + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["408", "409", "429", "5XX"], + }; + + const requestRes = client._createRequest(context, { + security: requestSecurity, + method: "PUT", + baseURL: options?.serverURL, + path: path, + headers: headers, + body: body, + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, + }, options); + if (!requestRes.ok) { + return requestRes; + } + const req = requestRes.value; + + const doResult = await client._do(req, { + context, + errorCodes: [ + "400", + "401", + "403", + "404", + "405", + "409", + "413", + "414", + "415", + "422", + "429", + "4XX", + "500", + "503", + "5XX", + ], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, + }); + if (!doResult.ok) { + return doResult; + } + const response = doResult.value; + + const responseFields = { + HttpMeta: { Response: response, Request: req }, + }; + + const [result] = await M.match< + operations.SubscribersV1ControllerUpdateSubscriberResponse, + | errors.ErrorDto + | errors.ErrorDto + | errors.ValidationErrorDto + | errors.ErrorDto + | SDKError + | SDKValidationError + | UnexpectedClientError + | InvalidRequestError + | RequestAbortedError + | RequestTimeoutError + | ConnectionError + >( + M.json( + 200, + operations.SubscribersV1ControllerUpdateSubscriberResponse$inboundSchema, + { hdrs: true, key: "Result" }, + ), + M.jsonErr(414, errors.ErrorDto$inboundSchema), + M.jsonErr( + [400, 401, 403, 404, 405, 409, 413, 415], + errors.ErrorDto$inboundSchema, + { hdrs: true }, + ), + M.jsonErr(422, errors.ValidationErrorDto$inboundSchema, { hdrs: true }), + M.fail(429), + M.jsonErr(500, errors.ErrorDto$inboundSchema, { hdrs: true }), + M.fail(503), + M.fail("4XX"), + M.fail("5XX"), + )(response, { extraFields: responseFields }); + if (!result.ok) { + return result; + } + + return result; +} diff --git a/libs/internal-sdk/src/lib/config.ts b/libs/internal-sdk/src/lib/config.ts index 1666c52d0288..ceb29dd1491a 100644 --- a/libs/internal-sdk/src/lib/config.ts +++ b/libs/internal-sdk/src/lib/config.ts @@ -60,6 +60,6 @@ export const SDK_METADATA = { language: "typescript", openapiDocVersion: "1.0", sdkVersion: "0.1.19", - genVersion: "2.499.0", - userAgent: "speakeasy-sdk/typescript 0.1.19 2.499.0 1.0 @novu/api", + genVersion: "2.503.2", + userAgent: "speakeasy-sdk/typescript 0.1.19 2.503.2 1.0 @novu/api", } as const; diff --git a/libs/internal-sdk/src/models/components/subscriberresponsedto.ts b/libs/internal-sdk/src/models/components/subscriberresponsedto.ts index cd0a88e7963d..a8db7f381d2e 100644 --- a/libs/internal-sdk/src/models/components/subscriberresponsedto.ts +++ b/libs/internal-sdk/src/models/components/subscriberresponsedto.ts @@ -93,7 +93,6 @@ export type SubscriberResponseDto = { * Additional custom data for the subscriber */ data?: { [k: string]: any } | null | undefined; - /** * Timezone of the subscriber */ @@ -125,6 +124,7 @@ export const SubscriberResponseDto$inboundSchema: z.ZodType< updatedAt: z.string(), __v: z.number().optional(), data: z.nullable(z.record(z.any())).optional(), + timezone: z.string().optional(), }).transform((v) => { return remap$(v, { "_id": "id", @@ -155,6 +155,7 @@ export type SubscriberResponseDto$Outbound = { updatedAt: string; __v?: number | undefined; data?: { [k: string]: any } | null | undefined; + timezone?: string | undefined; }; /** @internal */ @@ -182,6 +183,7 @@ export const SubscriberResponseDto$outboundSchema: z.ZodType< updatedAt: z.string(), v: z.number().optional(), data: z.nullable(z.record(z.any())).optional(), + timezone: z.string().optional(), }).transform((v) => { return remap$(v, { id: "_id", diff --git a/libs/internal-sdk/src/models/operations/index.ts b/libs/internal-sdk/src/models/operations/index.ts index 9e72d0feb125..52f6d477f70c 100644 --- a/libs/internal-sdk/src/models/operations/index.ts +++ b/libs/internal-sdk/src/models/operations/index.ts @@ -20,6 +20,7 @@ export * from "./notificationscontrollergetactivitygraphstats.js"; export * from "./notificationscontrollergetactivitystats.js"; export * from "./notificationscontrollergetnotification.js"; export * from "./notificationscontrollerlistnotifications.js"; +export * from "./subscriberscontrollercreatesubscriber.js"; export * from "./subscriberscontrollergetsubscriber.js"; export * from "./subscriberscontrollergetsubscriberpreferences.js"; export * from "./subscriberscontrollerpatchsubscriber.js"; diff --git a/libs/internal-sdk/src/models/operations/subscriberscontrollercreatesubscriber.ts b/libs/internal-sdk/src/models/operations/subscriberscontrollercreatesubscriber.ts new file mode 100644 index 000000000000..6daa1b2425e9 --- /dev/null +++ b/libs/internal-sdk/src/models/operations/subscriberscontrollercreatesubscriber.ts @@ -0,0 +1,185 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import * as z from "zod"; +import { remap as remap$ } from "../../lib/primitives.js"; +import { safeParse } from "../../lib/schemas.js"; +import { Result as SafeParseResult } from "../../types/fp.js"; +import * as components from "../components/index.js"; +import { SDKValidationError } from "../errors/sdkvalidationerror.js"; + +export type SubscribersControllerCreateSubscriberRequest = { + /** + * A header for idempotency purposes + */ + idempotencyKey?: string | undefined; + createSubscriberRequestDto: components.CreateSubscriberRequestDto; +}; + +export type SubscribersControllerCreateSubscriberResponse = { + headers: { [k: string]: Array }; + result: components.SubscriberResponseDto; +}; + +/** @internal */ +export const SubscribersControllerCreateSubscriberRequest$inboundSchema: + z.ZodType< + SubscribersControllerCreateSubscriberRequest, + z.ZodTypeDef, + unknown + > = z.object({ + "idempotency-key": z.string().optional(), + CreateSubscriberRequestDto: + components.CreateSubscriberRequestDto$inboundSchema, + }).transform((v) => { + return remap$(v, { + "idempotency-key": "idempotencyKey", + "CreateSubscriberRequestDto": "createSubscriberRequestDto", + }); + }); + +/** @internal */ +export type SubscribersControllerCreateSubscriberRequest$Outbound = { + "idempotency-key"?: string | undefined; + CreateSubscriberRequestDto: components.CreateSubscriberRequestDto$Outbound; +}; + +/** @internal */ +export const SubscribersControllerCreateSubscriberRequest$outboundSchema: + z.ZodType< + SubscribersControllerCreateSubscriberRequest$Outbound, + z.ZodTypeDef, + SubscribersControllerCreateSubscriberRequest + > = z.object({ + idempotencyKey: z.string().optional(), + createSubscriberRequestDto: + components.CreateSubscriberRequestDto$outboundSchema, + }).transform((v) => { + return remap$(v, { + idempotencyKey: "idempotency-key", + createSubscriberRequestDto: "CreateSubscriberRequestDto", + }); + }); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace SubscribersControllerCreateSubscriberRequest$ { + /** @deprecated use `SubscribersControllerCreateSubscriberRequest$inboundSchema` instead. */ + export const inboundSchema = + SubscribersControllerCreateSubscriberRequest$inboundSchema; + /** @deprecated use `SubscribersControllerCreateSubscriberRequest$outboundSchema` instead. */ + export const outboundSchema = + SubscribersControllerCreateSubscriberRequest$outboundSchema; + /** @deprecated use `SubscribersControllerCreateSubscriberRequest$Outbound` instead. */ + export type Outbound = SubscribersControllerCreateSubscriberRequest$Outbound; +} + +export function subscribersControllerCreateSubscriberRequestToJSON( + subscribersControllerCreateSubscriberRequest: + SubscribersControllerCreateSubscriberRequest, +): string { + return JSON.stringify( + SubscribersControllerCreateSubscriberRequest$outboundSchema.parse( + subscribersControllerCreateSubscriberRequest, + ), + ); +} + +export function subscribersControllerCreateSubscriberRequestFromJSON( + jsonString: string, +): SafeParseResult< + SubscribersControllerCreateSubscriberRequest, + SDKValidationError +> { + return safeParse( + jsonString, + (x) => + SubscribersControllerCreateSubscriberRequest$inboundSchema.parse( + JSON.parse(x), + ), + `Failed to parse 'SubscribersControllerCreateSubscriberRequest' from JSON`, + ); +} + +/** @internal */ +export const SubscribersControllerCreateSubscriberResponse$inboundSchema: + z.ZodType< + SubscribersControllerCreateSubscriberResponse, + z.ZodTypeDef, + unknown + > = z.object({ + Headers: z.record(z.array(z.string())), + Result: components.SubscriberResponseDto$inboundSchema, + }).transform((v) => { + return remap$(v, { + "Headers": "headers", + "Result": "result", + }); + }); + +/** @internal */ +export type SubscribersControllerCreateSubscriberResponse$Outbound = { + Headers: { [k: string]: Array }; + Result: components.SubscriberResponseDto$Outbound; +}; + +/** @internal */ +export const SubscribersControllerCreateSubscriberResponse$outboundSchema: + z.ZodType< + SubscribersControllerCreateSubscriberResponse$Outbound, + z.ZodTypeDef, + SubscribersControllerCreateSubscriberResponse + > = z.object({ + headers: z.record(z.array(z.string())), + result: components.SubscriberResponseDto$outboundSchema, + }).transform((v) => { + return remap$(v, { + headers: "Headers", + result: "Result", + }); + }); + +/** + * @internal + * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. + */ +export namespace SubscribersControllerCreateSubscriberResponse$ { + /** @deprecated use `SubscribersControllerCreateSubscriberResponse$inboundSchema` instead. */ + export const inboundSchema = + SubscribersControllerCreateSubscriberResponse$inboundSchema; + /** @deprecated use `SubscribersControllerCreateSubscriberResponse$outboundSchema` instead. */ + export const outboundSchema = + SubscribersControllerCreateSubscriberResponse$outboundSchema; + /** @deprecated use `SubscribersControllerCreateSubscriberResponse$Outbound` instead. */ + export type Outbound = SubscribersControllerCreateSubscriberResponse$Outbound; +} + +export function subscribersControllerCreateSubscriberResponseToJSON( + subscribersControllerCreateSubscriberResponse: + SubscribersControllerCreateSubscriberResponse, +): string { + return JSON.stringify( + SubscribersControllerCreateSubscriberResponse$outboundSchema.parse( + subscribersControllerCreateSubscriberResponse, + ), + ); +} + +export function subscribersControllerCreateSubscriberResponseFromJSON( + jsonString: string, +): SafeParseResult< + SubscribersControllerCreateSubscriberResponse, + SDKValidationError +> { + return safeParse( + jsonString, + (x) => + SubscribersControllerCreateSubscriberResponse$inboundSchema.parse( + JSON.parse(x), + ), + `Failed to parse 'SubscribersControllerCreateSubscriberResponse' from JSON`, + ); +} diff --git a/libs/internal-sdk/src/react-query/index.ts b/libs/internal-sdk/src/react-query/index.ts index 71e7aee38aed..e4f5510e4c43 100644 --- a/libs/internal-sdk/src/react-query/index.ts +++ b/libs/internal-sdk/src/react-query/index.ts @@ -24,6 +24,7 @@ export * from "./subscribersAuthenticationChatAccessOauth.js"; export * from "./subscribersAuthenticationChatAccessOauthCallBack.js"; export * from "./subscribersCreate.js"; export * from "./subscribersCreateBulk.js"; +export * from "./subscribersCreateLegacy.js"; export * from "./subscribersCredentialsAppend.js"; export * from "./subscribersCredentialsDelete.js"; export * from "./subscribersCredentialsUpdate.js"; @@ -36,17 +37,17 @@ export * from "./subscribersMessagesUpdateAsSeen.js"; export * from "./subscribersNotificationsFeed.js"; export * from "./subscribersNotificationsUnseenCount.js"; export * from "./subscribersPatch.js"; -export * from "./subscribersPreferencesList.js"; +export * from "./subscribersPreferencesLegacyUpdateGlobal.js"; +export * from "./subscribersPreferencesListLegacy.js"; export * from "./subscribersPreferencesRetrieve.js"; -export * from "./subscribersPreferencesRetrieveByLevel.js"; +export * from "./subscribersPreferencesRetrieveByLevelLegacy.js"; export * from "./subscribersPreferencesUpdate.js"; -export * from "./subscribersPreferencesUpdateGlobal.js"; export * from "./subscribersPreferencesUpdateLegacy.js"; export * from "./subscribersPropertiesUpdateOnlineFlag.js"; export * from "./subscribersRetrieve.js"; export * from "./subscribersRetrieveLegacy.js"; export * from "./subscribersSearch.js"; -export * from "./subscribersUpdate.js"; +export * from "./subscribersUpdateLegacy.js"; export * from "./topicsCreate.js"; export * from "./topicsDelete.js"; export * from "./topicsList.js"; diff --git a/libs/internal-sdk/src/react-query/subscribersCreate.ts b/libs/internal-sdk/src/react-query/subscribersCreate.ts index 3763a898ae57..13ea4199ce86 100644 --- a/libs/internal-sdk/src/react-query/subscribersCreate.ts +++ b/libs/internal-sdk/src/react-query/subscribersCreate.ts @@ -24,13 +24,13 @@ export type SubscribersCreateMutationVariables = { }; export type SubscribersCreateMutationData = - operations.SubscribersV1ControllerCreateSubscriberResponse; + operations.SubscribersControllerCreateSubscriberResponse; /** * Create subscriber * * @remarks - * Creates a subscriber entity, in the Novu platform. The subscriber will be later used to receive notifications, and access notification feeds. Communication credentials such as email, phone number, and 3 rd party credentials i.e slack tokens could be later associated to this entity. + * Create subscriber with the given data */ export function useSubscribersCreateMutation( options?: MutationHookOptions< diff --git a/libs/internal-sdk/src/react-query/subscribersCreateLegacy.ts b/libs/internal-sdk/src/react-query/subscribersCreateLegacy.ts new file mode 100644 index 000000000000..78d21473e9e4 --- /dev/null +++ b/libs/internal-sdk/src/react-query/subscribersCreateLegacy.ts @@ -0,0 +1,93 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import { + MutationKey, + useMutation, + UseMutationResult, +} from "@tanstack/react-query"; +import { NovuCore } from "../core.js"; +import { subscribersCreateLegacy } from "../funcs/subscribersCreateLegacy.js"; +import { combineSignals } from "../lib/primitives.js"; +import { RequestOptions } from "../lib/sdks.js"; +import * as components from "../models/components/index.js"; +import * as operations from "../models/operations/index.js"; +import { unwrapAsync } from "../types/fp.js"; +import { useNovuContext } from "./_context.js"; +import { MutationHookOptions } from "./_types.js"; + +export type SubscribersCreateLegacyMutationVariables = { + createSubscriberRequestDto: components.CreateSubscriberRequestDto; + idempotencyKey?: string | undefined; + options?: RequestOptions; +}; + +export type SubscribersCreateLegacyMutationData = + operations.SubscribersV1ControllerCreateSubscriberResponse; + +/** + * Create subscriber + * + * @remarks + * Creates a subscriber entity, in the Novu platform. The subscriber will be later used to receive notifications, and access notification feeds. Communication credentials such as email, phone number, and 3 rd party credentials i.e slack tokens could be later associated to this entity. + */ +export function useSubscribersCreateLegacyMutation( + options?: MutationHookOptions< + SubscribersCreateLegacyMutationData, + Error, + SubscribersCreateLegacyMutationVariables + >, +): UseMutationResult< + SubscribersCreateLegacyMutationData, + Error, + SubscribersCreateLegacyMutationVariables +> { + const client = useNovuContext(); + return useMutation({ + ...buildSubscribersCreateLegacyMutation(client, options), + ...options, + }); +} + +export function mutationKeySubscribersCreateLegacy(): MutationKey { + return ["@novu/api", "Subscribers", "createLegacy"]; +} + +export function buildSubscribersCreateLegacyMutation( + client$: NovuCore, + hookOptions?: RequestOptions, +): { + mutationKey: MutationKey; + mutationFn: ( + variables: SubscribersCreateLegacyMutationVariables, + ) => Promise; +} { + return { + mutationKey: mutationKeySubscribersCreateLegacy(), + mutationFn: function subscribersCreateLegacyMutationFn({ + createSubscriberRequestDto, + idempotencyKey, + options, + }): Promise { + const mergedOptions = { + ...hookOptions, + ...options, + fetchOptions: { + ...hookOptions?.fetchOptions, + ...options?.fetchOptions, + signal: combineSignals( + hookOptions?.fetchOptions?.signal, + options?.fetchOptions?.signal, + ), + }, + }; + return unwrapAsync(subscribersCreateLegacy( + client$, + createSubscriberRequestDto, + idempotencyKey, + mergedOptions, + )); + }, + }; +} diff --git a/libs/internal-sdk/src/react-query/subscribersPreferencesLegacyUpdateGlobal.ts b/libs/internal-sdk/src/react-query/subscribersPreferencesLegacyUpdateGlobal.ts new file mode 100644 index 000000000000..81ecbe70a1d7 --- /dev/null +++ b/libs/internal-sdk/src/react-query/subscribersPreferencesLegacyUpdateGlobal.ts @@ -0,0 +1,94 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import { + MutationKey, + useMutation, + UseMutationResult, +} from "@tanstack/react-query"; +import { NovuCore } from "../core.js"; +import { subscribersPreferencesLegacyUpdateGlobal } from "../funcs/subscribersPreferencesLegacyUpdateGlobal.js"; +import { combineSignals } from "../lib/primitives.js"; +import { RequestOptions } from "../lib/sdks.js"; +import * as components from "../models/components/index.js"; +import * as operations from "../models/operations/index.js"; +import { unwrapAsync } from "../types/fp.js"; +import { useNovuContext } from "./_context.js"; +import { MutationHookOptions } from "./_types.js"; + +export type SubscribersPreferencesLegacyUpdateGlobalMutationVariables = { + updateSubscriberGlobalPreferencesRequestDto: + components.UpdateSubscriberGlobalPreferencesRequestDto; + subscriberId: string; + idempotencyKey?: string | undefined; + options?: RequestOptions; +}; + +export type SubscribersPreferencesLegacyUpdateGlobalMutationData = + operations.SubscribersV1ControllerUpdateSubscriberGlobalPreferencesResponse; + +/** + * Update subscriber global preferences + */ +export function useSubscribersPreferencesLegacyUpdateGlobalMutation( + options?: MutationHookOptions< + SubscribersPreferencesLegacyUpdateGlobalMutationData, + Error, + SubscribersPreferencesLegacyUpdateGlobalMutationVariables + >, +): UseMutationResult< + SubscribersPreferencesLegacyUpdateGlobalMutationData, + Error, + SubscribersPreferencesLegacyUpdateGlobalMutationVariables +> { + const client = useNovuContext(); + return useMutation({ + ...buildSubscribersPreferencesLegacyUpdateGlobalMutation(client, options), + ...options, + }); +} + +export function mutationKeySubscribersPreferencesLegacyUpdateGlobal(): MutationKey { + return ["@novu/api", "legacy", "updateGlobal"]; +} + +export function buildSubscribersPreferencesLegacyUpdateGlobalMutation( + client$: NovuCore, + hookOptions?: RequestOptions, +): { + mutationKey: MutationKey; + mutationFn: ( + variables: SubscribersPreferencesLegacyUpdateGlobalMutationVariables, + ) => Promise; +} { + return { + mutationKey: mutationKeySubscribersPreferencesLegacyUpdateGlobal(), + mutationFn: function subscribersPreferencesLegacyUpdateGlobalMutationFn({ + updateSubscriberGlobalPreferencesRequestDto, + subscriberId, + idempotencyKey, + options, + }): Promise { + const mergedOptions = { + ...hookOptions, + ...options, + fetchOptions: { + ...hookOptions?.fetchOptions, + ...options?.fetchOptions, + signal: combineSignals( + hookOptions?.fetchOptions?.signal, + options?.fetchOptions?.signal, + ), + }, + }; + return unwrapAsync(subscribersPreferencesLegacyUpdateGlobal( + client$, + updateSubscriberGlobalPreferencesRequestDto, + subscriberId, + idempotencyKey, + mergedOptions, + )); + }, + }; +} diff --git a/libs/internal-sdk/src/react-query/subscribersPreferencesListLegacy.ts b/libs/internal-sdk/src/react-query/subscribersPreferencesListLegacy.ts new file mode 100644 index 000000000000..39e3f800d7a1 --- /dev/null +++ b/libs/internal-sdk/src/react-query/subscribersPreferencesListLegacy.ts @@ -0,0 +1,189 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import { + InvalidateQueryFilters, + QueryClient, + QueryFunctionContext, + QueryKey, + useQuery, + UseQueryResult, + useSuspenseQuery, + UseSuspenseQueryResult, +} from "@tanstack/react-query"; +import { NovuCore } from "../core.js"; +import { subscribersPreferencesListLegacy } from "../funcs/subscribersPreferencesListLegacy.js"; +import { combineSignals } from "../lib/primitives.js"; +import { RequestOptions } from "../lib/sdks.js"; +import * as operations from "../models/operations/index.js"; +import { unwrapAsync } from "../types/fp.js"; +import { useNovuContext } from "./_context.js"; +import { + QueryHookOptions, + SuspenseQueryHookOptions, + TupleToPrefixes, +} from "./_types.js"; + +export type SubscribersPreferencesListLegacyQueryData = + operations.SubscribersV1ControllerListSubscriberPreferencesResponse; + +/** + * Get subscriber preferences + * + * @deprecated method: This will be removed in a future release, please migrate away from it as soon as possible. + */ +export function useSubscribersPreferencesListLegacy( + subscriberId: string, + includeInactiveChannels?: boolean | undefined, + idempotencyKey?: string | undefined, + options?: QueryHookOptions, +): UseQueryResult { + const client = useNovuContext(); + return useQuery({ + ...buildSubscribersPreferencesListLegacyQuery( + client, + subscriberId, + includeInactiveChannels, + idempotencyKey, + options, + ), + ...options, + }); +} + +/** + * Get subscriber preferences + * + * @deprecated method: This will be removed in a future release, please migrate away from it as soon as possible. + */ +export function useSubscribersPreferencesListLegacySuspense( + subscriberId: string, + includeInactiveChannels?: boolean | undefined, + idempotencyKey?: string | undefined, + options?: SuspenseQueryHookOptions, +): UseSuspenseQueryResult { + const client = useNovuContext(); + return useSuspenseQuery({ + ...buildSubscribersPreferencesListLegacyQuery( + client, + subscriberId, + includeInactiveChannels, + idempotencyKey, + options, + ), + ...options, + }); +} + +export function prefetchSubscribersPreferencesListLegacy( + queryClient: QueryClient, + client$: NovuCore, + subscriberId: string, + includeInactiveChannels?: boolean | undefined, + idempotencyKey?: string | undefined, +): Promise { + return queryClient.prefetchQuery({ + ...buildSubscribersPreferencesListLegacyQuery( + client$, + subscriberId, + includeInactiveChannels, + idempotencyKey, + ), + }); +} + +export function setSubscribersPreferencesListLegacyData( + client: QueryClient, + queryKeyBase: [ + subscriberId: string, + parameters: { + includeInactiveChannels?: boolean | undefined; + idempotencyKey?: string | undefined; + }, + ], + data: SubscribersPreferencesListLegacyQueryData, +): SubscribersPreferencesListLegacyQueryData | undefined { + const key = queryKeySubscribersPreferencesListLegacy(...queryKeyBase); + + return client.setQueryData( + key, + data, + ); +} + +export function invalidateSubscribersPreferencesListLegacy( + client: QueryClient, + queryKeyBase: TupleToPrefixes< + [ + subscriberId: string, + parameters: { + includeInactiveChannels?: boolean | undefined; + idempotencyKey?: string | undefined; + }, + ] + >, + filters?: Omit, +): Promise { + return client.invalidateQueries({ + ...filters, + queryKey: ["@novu/api", "Preferences", "listLegacy", ...queryKeyBase], + }); +} + +export function invalidateAllSubscribersPreferencesListLegacy( + client: QueryClient, + filters?: Omit, +): Promise { + return client.invalidateQueries({ + ...filters, + queryKey: ["@novu/api", "Preferences", "listLegacy"], + }); +} + +export function buildSubscribersPreferencesListLegacyQuery( + client$: NovuCore, + subscriberId: string, + includeInactiveChannels?: boolean | undefined, + idempotencyKey?: string | undefined, + options?: RequestOptions, +): { + queryKey: QueryKey; + queryFn: ( + context: QueryFunctionContext, + ) => Promise; +} { + return { + queryKey: queryKeySubscribersPreferencesListLegacy(subscriberId, { + includeInactiveChannels, + idempotencyKey, + }), + queryFn: async function subscribersPreferencesListLegacyQueryFn( + ctx, + ): Promise { + const sig = combineSignals(ctx.signal, options?.fetchOptions?.signal); + const mergedOptions = { + ...options, + fetchOptions: { ...options?.fetchOptions, signal: sig }, + }; + + return unwrapAsync(subscribersPreferencesListLegacy( + client$, + subscriberId, + includeInactiveChannels, + idempotencyKey, + mergedOptions, + )); + }, + }; +} + +export function queryKeySubscribersPreferencesListLegacy( + subscriberId: string, + parameters: { + includeInactiveChannels?: boolean | undefined; + idempotencyKey?: string | undefined; + }, +): QueryKey { + return ["@novu/api", "Preferences", "listLegacy", subscriberId, parameters]; +} diff --git a/libs/internal-sdk/src/react-query/subscribersPreferencesRetrieveByLevelLegacy.ts b/libs/internal-sdk/src/react-query/subscribersPreferencesRetrieveByLevelLegacy.ts new file mode 100644 index 000000000000..bfedf6b4cdce --- /dev/null +++ b/libs/internal-sdk/src/react-query/subscribersPreferencesRetrieveByLevelLegacy.ts @@ -0,0 +1,204 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import { + InvalidateQueryFilters, + QueryClient, + QueryFunctionContext, + QueryKey, + useQuery, + UseQueryResult, + useSuspenseQuery, + UseSuspenseQueryResult, +} from "@tanstack/react-query"; +import { NovuCore } from "../core.js"; +import { subscribersPreferencesRetrieveByLevelLegacy } from "../funcs/subscribersPreferencesRetrieveByLevelLegacy.js"; +import { combineSignals } from "../lib/primitives.js"; +import { RequestOptions } from "../lib/sdks.js"; +import * as operations from "../models/operations/index.js"; +import { unwrapAsync } from "../types/fp.js"; +import { useNovuContext } from "./_context.js"; +import { + QueryHookOptions, + SuspenseQueryHookOptions, + TupleToPrefixes, +} from "./_types.js"; + +export type SubscribersPreferencesRetrieveByLevelLegacyQueryData = + operations.SubscribersV1ControllerGetSubscriberPreferenceByLevelResponse; + +/** + * Get subscriber preferences by level + * + * @deprecated method: This will be removed in a future release, please migrate away from it as soon as possible. + */ +export function useSubscribersPreferencesRetrieveByLevelLegacy( + request: + operations.SubscribersV1ControllerGetSubscriberPreferenceByLevelRequest, + options?: QueryHookOptions< + SubscribersPreferencesRetrieveByLevelLegacyQueryData + >, +): UseQueryResult { + const client = useNovuContext(); + return useQuery({ + ...buildSubscribersPreferencesRetrieveByLevelLegacyQuery( + client, + request, + options, + ), + ...options, + }); +} + +/** + * Get subscriber preferences by level + * + * @deprecated method: This will be removed in a future release, please migrate away from it as soon as possible. + */ +export function useSubscribersPreferencesRetrieveByLevelLegacySuspense( + request: + operations.SubscribersV1ControllerGetSubscriberPreferenceByLevelRequest, + options?: SuspenseQueryHookOptions< + SubscribersPreferencesRetrieveByLevelLegacyQueryData + >, +): UseSuspenseQueryResult< + SubscribersPreferencesRetrieveByLevelLegacyQueryData, + Error +> { + const client = useNovuContext(); + return useSuspenseQuery({ + ...buildSubscribersPreferencesRetrieveByLevelLegacyQuery( + client, + request, + options, + ), + ...options, + }); +} + +export function prefetchSubscribersPreferencesRetrieveByLevelLegacy( + queryClient: QueryClient, + client$: NovuCore, + request: + operations.SubscribersV1ControllerGetSubscriberPreferenceByLevelRequest, +): Promise { + return queryClient.prefetchQuery({ + ...buildSubscribersPreferencesRetrieveByLevelLegacyQuery( + client$, + request, + ), + }); +} + +export function setSubscribersPreferencesRetrieveByLevelLegacyData( + client: QueryClient, + queryKeyBase: [ + preferenceLevel: operations.Parameter, + subscriberId: string, + parameters: { + includeInactiveChannels?: boolean | undefined; + idempotencyKey?: string | undefined; + }, + ], + data: SubscribersPreferencesRetrieveByLevelLegacyQueryData, +): SubscribersPreferencesRetrieveByLevelLegacyQueryData | undefined { + const key = queryKeySubscribersPreferencesRetrieveByLevelLegacy( + ...queryKeyBase, + ); + + return client.setQueryData< + SubscribersPreferencesRetrieveByLevelLegacyQueryData + >(key, data); +} + +export function invalidateSubscribersPreferencesRetrieveByLevelLegacy( + client: QueryClient, + queryKeyBase: TupleToPrefixes< + [ + preferenceLevel: operations.Parameter, + subscriberId: string, + parameters: { + includeInactiveChannels?: boolean | undefined; + idempotencyKey?: string | undefined; + }, + ] + >, + filters?: Omit, +): Promise { + return client.invalidateQueries({ + ...filters, + queryKey: [ + "@novu/api", + "Preferences", + "retrieveByLevelLegacy", + ...queryKeyBase, + ], + }); +} + +export function invalidateAllSubscribersPreferencesRetrieveByLevelLegacy( + client: QueryClient, + filters?: Omit, +): Promise { + return client.invalidateQueries({ + ...filters, + queryKey: ["@novu/api", "Preferences", "retrieveByLevelLegacy"], + }); +} + +export function buildSubscribersPreferencesRetrieveByLevelLegacyQuery( + client$: NovuCore, + request: + operations.SubscribersV1ControllerGetSubscriberPreferenceByLevelRequest, + options?: RequestOptions, +): { + queryKey: QueryKey; + queryFn: ( + context: QueryFunctionContext, + ) => Promise; +} { + return { + queryKey: queryKeySubscribersPreferencesRetrieveByLevelLegacy( + request.preferenceLevel, + request.subscriberId, + { + includeInactiveChannels: request.includeInactiveChannels, + idempotencyKey: request.idempotencyKey, + }, + ), + queryFn: async function subscribersPreferencesRetrieveByLevelLegacyQueryFn( + ctx, + ): Promise { + const sig = combineSignals(ctx.signal, options?.fetchOptions?.signal); + const mergedOptions = { + ...options, + fetchOptions: { ...options?.fetchOptions, signal: sig }, + }; + + return unwrapAsync(subscribersPreferencesRetrieveByLevelLegacy( + client$, + request, + mergedOptions, + )); + }, + }; +} + +export function queryKeySubscribersPreferencesRetrieveByLevelLegacy( + preferenceLevel: operations.Parameter, + subscriberId: string, + parameters: { + includeInactiveChannels?: boolean | undefined; + idempotencyKey?: string | undefined; + }, +): QueryKey { + return [ + "@novu/api", + "Preferences", + "retrieveByLevelLegacy", + preferenceLevel, + subscriberId, + parameters, + ]; +} diff --git a/libs/internal-sdk/src/react-query/subscribersUpdateLegacy.ts b/libs/internal-sdk/src/react-query/subscribersUpdateLegacy.ts new file mode 100644 index 000000000000..bf07adc1247d --- /dev/null +++ b/libs/internal-sdk/src/react-query/subscribersUpdateLegacy.ts @@ -0,0 +1,96 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import { + MutationKey, + useMutation, + UseMutationResult, +} from "@tanstack/react-query"; +import { NovuCore } from "../core.js"; +import { subscribersUpdateLegacy } from "../funcs/subscribersUpdateLegacy.js"; +import { combineSignals } from "../lib/primitives.js"; +import { RequestOptions } from "../lib/sdks.js"; +import * as components from "../models/components/index.js"; +import * as operations from "../models/operations/index.js"; +import { unwrapAsync } from "../types/fp.js"; +import { useNovuContext } from "./_context.js"; +import { MutationHookOptions } from "./_types.js"; + +export type SubscribersUpdateLegacyMutationVariables = { + updateSubscriberRequestDto: components.UpdateSubscriberRequestDto; + subscriberId: string; + idempotencyKey?: string | undefined; + options?: RequestOptions; +}; + +export type SubscribersUpdateLegacyMutationData = + operations.SubscribersV1ControllerUpdateSubscriberResponse; + +/** + * Update subscriber + * + * @remarks + * Used to update the subscriber entity with new information + */ +export function useSubscribersUpdateLegacyMutation( + options?: MutationHookOptions< + SubscribersUpdateLegacyMutationData, + Error, + SubscribersUpdateLegacyMutationVariables + >, +): UseMutationResult< + SubscribersUpdateLegacyMutationData, + Error, + SubscribersUpdateLegacyMutationVariables +> { + const client = useNovuContext(); + return useMutation({ + ...buildSubscribersUpdateLegacyMutation(client, options), + ...options, + }); +} + +export function mutationKeySubscribersUpdateLegacy(): MutationKey { + return ["@novu/api", "Subscribers", "updateLegacy"]; +} + +export function buildSubscribersUpdateLegacyMutation( + client$: NovuCore, + hookOptions?: RequestOptions, +): { + mutationKey: MutationKey; + mutationFn: ( + variables: SubscribersUpdateLegacyMutationVariables, + ) => Promise; +} { + return { + mutationKey: mutationKeySubscribersUpdateLegacy(), + mutationFn: function subscribersUpdateLegacyMutationFn({ + updateSubscriberRequestDto, + subscriberId, + idempotencyKey, + options, + }): Promise { + const mergedOptions = { + ...hookOptions, + ...options, + fetchOptions: { + ...hookOptions?.fetchOptions, + ...options?.fetchOptions, + signal: combineSignals( + hookOptions?.fetchOptions?.signal, + options?.fetchOptions?.signal, + ), + }, + }; + return unwrapAsync(subscribersUpdateLegacy( + client$, + updateSubscriberRequestDto, + subscriberId, + idempotencyKey, + mergedOptions, + )); + }, + }; +} diff --git a/libs/internal-sdk/src/sdk/legacy.ts b/libs/internal-sdk/src/sdk/legacy.ts new file mode 100644 index 000000000000..727d981c2e69 --- /dev/null +++ b/libs/internal-sdk/src/sdk/legacy.ts @@ -0,0 +1,32 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +import { subscribersPreferencesLegacyUpdateGlobal } from "../funcs/subscribersPreferencesLegacyUpdateGlobal.js"; +import { ClientSDK, RequestOptions } from "../lib/sdks.js"; +import * as components from "../models/components/index.js"; +import * as operations from "../models/operations/index.js"; +import { unwrapAsync } from "../types/fp.js"; + +export class Legacy extends ClientSDK { + /** + * Update subscriber global preferences + */ + async updateGlobal( + updateSubscriberGlobalPreferencesRequestDto: + components.UpdateSubscriberGlobalPreferencesRequestDto, + subscriberId: string, + idempotencyKey?: string | undefined, + options?: RequestOptions, + ): Promise< + operations.SubscribersV1ControllerUpdateSubscriberGlobalPreferencesResponse + > { + return unwrapAsync(subscribersPreferencesLegacyUpdateGlobal( + this, + updateSubscriberGlobalPreferencesRequestDto, + subscriberId, + idempotencyKey, + options, + )); + } +} diff --git a/libs/internal-sdk/src/sdk/preferences.ts b/libs/internal-sdk/src/sdk/preferences.ts index 81dedfe318d8..870c0aa0819e 100644 --- a/libs/internal-sdk/src/sdk/preferences.ts +++ b/libs/internal-sdk/src/sdk/preferences.ts @@ -2,22 +2,29 @@ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ -import { subscribersPreferencesList } from "../funcs/subscribersPreferencesList.js"; +import { subscribersPreferencesListLegacy } from "../funcs/subscribersPreferencesListLegacy.js"; import { subscribersPreferencesRetrieve } from "../funcs/subscribersPreferencesRetrieve.js"; -import { subscribersPreferencesRetrieveByLevel } from "../funcs/subscribersPreferencesRetrieveByLevel.js"; +import { subscribersPreferencesRetrieveByLevelLegacy } from "../funcs/subscribersPreferencesRetrieveByLevelLegacy.js"; import { subscribersPreferencesUpdate } from "../funcs/subscribersPreferencesUpdate.js"; -import { subscribersPreferencesUpdateGlobal } from "../funcs/subscribersPreferencesUpdateGlobal.js"; import { subscribersPreferencesUpdateLegacy } from "../funcs/subscribersPreferencesUpdateLegacy.js"; import { ClientSDK, RequestOptions } from "../lib/sdks.js"; import * as components from "../models/components/index.js"; import * as operations from "../models/operations/index.js"; import { unwrapAsync } from "../types/fp.js"; +import { Legacy } from "./legacy.js"; export class Preferences extends ClientSDK { + private _legacy?: Legacy; + get legacy(): Legacy { + return (this._legacy ??= new Legacy(this._options)); + } + /** * Get subscriber preferences + * + * @deprecated method: This will be removed in a future release, please migrate away from it as soon as possible. */ - async list( + async listLegacy( subscriberId: string, includeInactiveChannels?: boolean | undefined, idempotencyKey?: string | undefined, @@ -25,7 +32,7 @@ export class Preferences extends ClientSDK { ): Promise< operations.SubscribersV1ControllerListSubscriberPreferencesResponse > { - return unwrapAsync(subscribersPreferencesList( + return unwrapAsync(subscribersPreferencesListLegacy( this, subscriberId, includeInactiveChannels, @@ -34,38 +41,19 @@ export class Preferences extends ClientSDK { )); } - /** - * Update subscriber global preferences - */ - async updateGlobal( - updateSubscriberGlobalPreferencesRequestDto: - components.UpdateSubscriberGlobalPreferencesRequestDto, - subscriberId: string, - idempotencyKey?: string | undefined, - options?: RequestOptions, - ): Promise< - operations.SubscribersV1ControllerUpdateSubscriberGlobalPreferencesResponse - > { - return unwrapAsync(subscribersPreferencesUpdateGlobal( - this, - updateSubscriberGlobalPreferencesRequestDto, - subscriberId, - idempotencyKey, - options, - )); - } - /** * Get subscriber preferences by level + * + * @deprecated method: This will be removed in a future release, please migrate away from it as soon as possible. */ - async retrieveByLevel( + async retrieveByLevelLegacy( request: operations.SubscribersV1ControllerGetSubscriberPreferenceByLevelRequest, options?: RequestOptions, ): Promise< operations.SubscribersV1ControllerGetSubscriberPreferenceByLevelResponse > { - return unwrapAsync(subscribersPreferencesRetrieveByLevel( + return unwrapAsync(subscribersPreferencesRetrieveByLevelLegacy( this, request, options, diff --git a/libs/internal-sdk/src/sdk/subscribers.ts b/libs/internal-sdk/src/sdk/subscribers.ts index b7e4a4657427..e555a88ddf56 100644 --- a/libs/internal-sdk/src/sdk/subscribers.ts +++ b/libs/internal-sdk/src/sdk/subscribers.ts @@ -4,6 +4,7 @@ import { subscribersCreate } from "../funcs/subscribersCreate.js"; import { subscribersCreateBulk } from "../funcs/subscribersCreateBulk.js"; +import { subscribersCreateLegacy } from "../funcs/subscribersCreateLegacy.js"; import { subscribersDelete } from "../funcs/subscribersDelete.js"; import { subscribersDeleteLegacy } from "../funcs/subscribersDeleteLegacy.js"; import { subscribersList } from "../funcs/subscribersList.js"; @@ -11,7 +12,7 @@ import { subscribersPatch } from "../funcs/subscribersPatch.js"; import { subscribersRetrieve } from "../funcs/subscribersRetrieve.js"; import { subscribersRetrieveLegacy } from "../funcs/subscribersRetrieveLegacy.js"; import { subscribersSearch } from "../funcs/subscribersSearch.js"; -import { subscribersUpdate } from "../funcs/subscribersUpdate.js"; +import { subscribersUpdateLegacy } from "../funcs/subscribersUpdateLegacy.js"; import { ClientSDK, RequestOptions } from "../lib/sdks.js"; import * as components from "../models/components/index.js"; import * as operations from "../models/operations/index.js"; @@ -87,12 +88,12 @@ export class Subscribers extends ClientSDK { * @remarks * Creates a subscriber entity, in the Novu platform. The subscriber will be later used to receive notifications, and access notification feeds. Communication credentials such as email, phone number, and 3 rd party credentials i.e slack tokens could be later associated to this entity. */ - async create( + async createLegacy( createSubscriberRequestDto: components.CreateSubscriberRequestDto, idempotencyKey?: string | undefined, options?: RequestOptions, ): Promise { - return unwrapAsync(subscribersCreate( + return unwrapAsync(subscribersCreateLegacy( this, createSubscriberRequestDto, idempotencyKey, @@ -127,13 +128,13 @@ export class Subscribers extends ClientSDK { * @remarks * Used to update the subscriber entity with new information */ - async update( + async updateLegacy( updateSubscriberRequestDto: components.UpdateSubscriberRequestDto, subscriberId: string, idempotencyKey?: string | undefined, options?: RequestOptions, ): Promise { - return unwrapAsync(subscribersUpdate( + return unwrapAsync(subscribersUpdateLegacy( this, updateSubscriberRequestDto, subscriberId, @@ -198,6 +199,25 @@ export class Subscribers extends ClientSDK { )); } + /** + * Create subscriber + * + * @remarks + * Create subscriber with the given data + */ + async create( + createSubscriberRequestDto: components.CreateSubscriberRequestDto, + idempotencyKey?: string | undefined, + options?: RequestOptions, + ): Promise { + return unwrapAsync(subscribersCreate( + this, + createSubscriberRequestDto, + idempotencyKey, + options, + )); + } + /** * Get subscriber * diff --git a/libs/internal-sdk/src/sdk/workflows.ts b/libs/internal-sdk/src/sdk/workflows.ts index 76a2d4918f6d..656800b9ac9d 100644 --- a/libs/internal-sdk/src/sdk/workflows.ts +++ b/libs/internal-sdk/src/sdk/workflows.ts @@ -60,10 +60,10 @@ export class Workflows extends ClientSDK { } /** - * Update subscriber + * Update subscriber global or workflow specific preferences * * @remarks - * Used to update the subscriber entity with new information + * Update subscriber global or workflow specific preferences */ async update( workflowId: string,