Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Simulations): narrow down simulation payload types #52

Merged
merged 4 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
/**
* ! Autogenerated code !
* Do not make changes to this file.
* Changes may be overwritten as part of auto-generation.
*/

import type { SimulationScenarioType } from '../../../enums';
import type { IEventName } from '../../../notifications';
import type { DiscriminatedSimulationEventResponse } from '../../../types';

export interface CreateSimulationRequestBody {
interface BaseCreateSimulationRequestBody {
notificationSettingId: string;
type: IEventName | SimulationScenarioType;
samcolby marked this conversation as resolved.
Show resolved Hide resolved
name: string;
payload?: any;
type: IEventName | SimulationScenarioType;
}

export type CreateSimulationRequestBody = DiscriminatedSimulationEventResponse<BaseCreateSimulationRequestBody>;
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
/**
* ! Autogenerated code !
* Do not make changes to this file.
* Changes may be overwritten as part of auto-generation.
*/
import type { Status } from '../../../enums';
import type { DiscriminatedSimulationEventResponse } from '../../../types';

import type { SimulationScenarioType, Status } from '../../../enums';
import type { IEventName } from '../../../notifications';

export interface UpdateSimulationRequestBody {
interface BaseUpdateSimulationRequestBody {
notificationSettingId?: string;
name?: string;
status?: Status;
type?: IEventName | SimulationScenarioType;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another type here we should reenable.

payload?: any;
}

type RawUpdateSimulationRequestBody = DiscriminatedSimulationEventResponse<BaseUpdateSimulationRequestBody>;

// Map all properties to be optional
export type UpdateSimulationRequestBody = {
[Key in keyof RawUpdateSimulationRequestBody]?: RawUpdateSimulationRequestBody[Key];
};
1 change: 1 addition & 0 deletions src/types/shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ export * from './custom-data';
export * from './import-meta-response';
export * from './simulation-event-request';
export * from './simulation-event-response';
export * from './simulation-payload';
102 changes: 102 additions & 0 deletions src/types/shared/simulation-payload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import type { IEventName } from '../../notifications';
import {
type AddressCreatedEvent,
type AddressImportedEvent,
type AddressUpdatedEvent,
type AdjustmentCreatedEvent,
type AdjustmentUpdatedEvent,
type BusinessCreatedEvent,
type BusinessImportedEvent,
type BusinessUpdatedEvent,
type CustomerCreatedEvent,
type CustomerImportedEvent,
type CustomerUpdatedEvent,
type DiscountCreatedEvent,
type DiscountImportedEvent,
type DiscountUpdatedEvent,
type PayoutCreatedEvent,
type PayoutPaidEvent,
type PriceCreatedEvent,
type PriceImportedEvent,
type PriceUpdatedEvent,
type ProductCreatedEvent,
type ProductImportedEvent,
type ProductUpdatedEvent,
type ReportCreatedEvent,
type ReportUpdatedEvent,
type SubscriptionActivatedEvent,
type SubscriptionCanceledEvent,
type SubscriptionCreatedEvent,
type SubscriptionImportedEvent,
type SubscriptionPastDueEvent,
type SubscriptionPausedEvent,
type SubscriptionResumedEvent,
type SubscriptionTrialingEvent,
type SubscriptionUpdatedEvent,
type TransactionBilledEvent,
type TransactionCanceledEvent,
type TransactionCompletedEvent,
type TransactionCreatedEvent,
type TransactionPaidEvent,
type TransactionPastDueEvent,
type TransactionPaymentFailedEvent,
type TransactionReadyEvent,
type TransactionUpdatedEvent,
} from '../../notifications/events';

interface SimulationEventPayloadMap {
'address.created': AddressCreatedEvent;
'address.updated': AddressUpdatedEvent;
'address.imported': AddressImportedEvent;
'adjustment.created': AdjustmentCreatedEvent;
'adjustment.updated': AdjustmentUpdatedEvent;
'business.created': BusinessCreatedEvent;
'business.updated': BusinessUpdatedEvent;
'business.imported': BusinessImportedEvent;
'customer.created': CustomerCreatedEvent;
'customer.updated': CustomerUpdatedEvent;
'customer.imported': CustomerImportedEvent;
'discount.created': DiscountCreatedEvent;
'discount.updated': DiscountUpdatedEvent;
'discount.imported': DiscountImportedEvent;
'payout.created': PayoutCreatedEvent;
'payout.paid': PayoutPaidEvent;
'price.created': PriceCreatedEvent;
'price.updated': PriceUpdatedEvent;
'price.imported': PriceImportedEvent;
'product.created': ProductCreatedEvent;
'product.updated': ProductUpdatedEvent;
'product.imported': ProductImportedEvent;
'subscription.created': SubscriptionCreatedEvent;
'subscription.past_due': SubscriptionPastDueEvent;
'subscription.activated': SubscriptionActivatedEvent;
'subscription.canceled': SubscriptionCanceledEvent;
'subscription.imported': SubscriptionImportedEvent;
'subscription.paused': SubscriptionPausedEvent;
'subscription.resumed': SubscriptionResumedEvent;
'subscription.trialing': SubscriptionTrialingEvent;
'subscription.updated': SubscriptionUpdatedEvent;
'transaction.billed': TransactionBilledEvent;
'transaction.canceled': TransactionCanceledEvent;
'transaction.completed': TransactionCompletedEvent;
'transaction.created': TransactionCreatedEvent;
'transaction.paid': TransactionPaidEvent;
'transaction.past_due': TransactionPastDueEvent;
'transaction.payment_failed': TransactionPaymentFailedEvent;
'transaction.ready': TransactionReadyEvent;
'transaction.updated': TransactionUpdatedEvent;
'report.created': ReportCreatedEvent;
'report.updated': ReportUpdatedEvent;
subscription_creation: never;
subscription_renewal: never;
subscription_pause: never;
subscription_resume: never;
subscription_cancellation: never;
}

export type DiscriminatedSimulationEventResponse<Base> = {
[K in keyof SimulationEventPayloadMap]: Base & {
type: K;
payload?: K extends IEventName ? Partial<SimulationEventPayloadMap[K]['data']> | null : null;
};
}[keyof SimulationEventPayloadMap];
14 changes: 4 additions & 10 deletions src/types/simulation/simulation-response.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
/**
* ! Autogenerated code !
* Do not make changes to this file.
* Changes may be overwritten as part of auto-generation.
*/
import type { Status } from '../../enums';
import type { DiscriminatedSimulationEventResponse } from '../shared/simulation-payload';

import type { SimulationScenarioType, Status } from '../../enums';
import type { IEventName } from '../../notifications';
export type ISimulationResponse = DiscriminatedSimulationEventResponse<BaseSimulationResponse>;

export interface ISimulationResponse {
interface BaseSimulationResponse {
id: string;
status: Status;
notification_setting_id: string;
name: string;
type: IEventName | SimulationScenarioType;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe another type here?

payload?: any;
last_run_at?: string | null;
created_at: string;
updated_at: string;
Expand Down