Skip to content

Commit

Permalink
just store operations as merged legacy and current version for impl s…
Browse files Browse the repository at this point in the history
…implicity
  • Loading branch information
osdiab committed Nov 5, 2018
1 parent 9be742a commit 782072f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 166 deletions.
105 changes: 34 additions & 71 deletions packages/shared/src/models/Operation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// TODO: change all to_uid to to_member_id
import { MemberId, MemberUsername, OperationId } from "./identifiers";
import { VideoReference } from "./MediaReference";
import { Omit } from "../helpers/Omit";

export enum OperationType {
CREATE_MEMBER = "CREATE_MEMBER",
Expand All @@ -22,6 +21,16 @@ export interface CreateMemberPayload {
username: MemberUsername;
videoReference: VideoReference;
}
// START [video-reference] legacy types
export interface LegacyCreateMemberPayload {
full_name: string;
request_invite_from_member_id?: MemberId;
username: MemberUsername;
video_url: string;
}
export type LegacyCompatCreateMemberPayload = CreateMemberPayload &
LegacyCreateMemberPayload;
// END [video-reference] legacy types

export interface EditMemberPayload {
full_name?: string;
Expand All @@ -44,12 +53,27 @@ export interface VerifyPayload {
to_uid: MemberId;
videoReference: VideoReference;
}
// START [video-reference] legacy types
export interface LegacyVerifyPayload {
to_uid: MemberId;
video_url: string;
}
export type LegacyCompatVerifyPayload = VerifyPayload & LegacyVerifyPayload;
// END [video-reference] legacy types

export interface InvitePayload {
invite_token: string;
is_joint_video: boolean;
videoReference: VideoReference;
}
// START [video-reference] legacy types
export interface LegacyInvitePayload {
invite_token: string;
is_joint_video: boolean;
video_token: string;
}
export type LegacyCompatInvitePayload = InvitePayload & LegacyInvitePayload;
// END [video-reference] legacy types

export interface TrustPayload {
to_uid: MemberId;
Expand Down Expand Up @@ -90,7 +114,9 @@ export interface SavedOperationBase {

interface CreateMemberOperationMetadata {
op_code: OperationType.CREATE_MEMBER;
data: CreateMemberPayload;
// TODO: [video-reference] legacy - once apps updated, use CreateMemberPayload
// data: CreateMemberPayload;
data: LegacyCompatCreateMemberPayload;
}

export type CreateMemberOperation = SavedOperationBase &
Expand Down Expand Up @@ -136,7 +162,9 @@ export type RequestVerificationOperationToBeCreated = ToSaveOperationBase &

interface VerifyOperationMetadata {
op_code: OperationType.VERIFY;
data: VerifyPayload;
// TODO: [video-reference] legacy - once apps updated, use VerifyPayload
// data: VerifyPayload;
data: LegacyCompatVerifyPayload;
}

export type VerifyOperation = SavedOperationBase & VerifyOperationMetadata;
Expand All @@ -145,7 +173,9 @@ export type VerifyOperationToBeCreated = ToSaveOperationBase &

interface InviteOperationMetadata {
op_code: OperationType.INVITE;
data: InvitePayload;
// TODO: [video-reference] legacy - once apps updated, use InvitePayload
// data: InviteMemberPayload;
data: LegacyCompatInvitePayload;
}
export type InviteOperation = SavedOperationBase & InviteOperationMetadata;
export type InviteOperationToBeCreated = ToSaveOperationBase &
Expand Down Expand Up @@ -198,70 +228,3 @@ export type OperationToBeCreated =
| TrustOperationToBeCreated
| MintOperationToBeCreated
| GiveOperationToBeCreated;

// LEGACY TYPES START---------------------
// TODO: remove legacy types
// missing videoReference means video location is inferred from member ID
export type LegacyCreateMemberPayload = Omit<
CreateMemberPayload,
"videoReference"
>;
interface LegacyCreateMemberOperationMetadata
extends Omit<CreateMemberOperationMetadata, "data"> {
data: LegacyCreateMemberPayload;
}
export type LegacyCreateMemberOperation = SavedOperationBase &
LegacyCreateMemberOperationMetadata;
export type LegacyCreateMemberOperationToBeCreated = ToSaveOperationBase &
LegacyCreateMemberOperationMetadata;

// Presence of video_url instead of videoReference indicates legacy request
export interface LegacyVerifyPayload
extends Omit<VerifyPayload, "videoReference"> {
video_url: string;
}
export interface LegacyVerifyOperationMetadata
extends Omit<VerifyOperationMetadata, "data"> {
data: LegacyVerifyPayload;
}
export type LegacyVerifyOperation = SavedOperationBase &
LegacyVerifyOperationMetadata;
export type LegacyVerifyOperationToBeCreated = ToSaveOperationBase &
LegacyVerifyOperationMetadata;

export interface LegacyInvitePayload
extends Omit<InvitePayload, "videoReference"> {
video_token: string;
}
export interface LegacyInviteOperationMetadata
extends Omit<InviteOperationMetadata, "data"> {
data: LegacyInvitePayload;
}
export type LegacyInviteOperation = SavedOperationBase &
LegacyInviteOperationMetadata;
export type LegacyInviteOperationToBeCreated = ToSaveOperationBase &
LegacyInviteOperationMetadata;

export type LegacyOperation =
| LegacyCreateMemberOperation
| LegacyVerifyOperation
| LegacyInviteOperation
| EditMemberOperation
| FlagMemberOperation
| ResolveFlagMemberOperation
| RequestVerificationOperation
| TrustOperation
| MintOperation
| GiveOperation;
export type LegacyOperationToBeCreated =
| LegacyCreateMemberOperationToBeCreated
| LegacyVerifyOperationToBeCreated
| LegacyInviteOperationToBeCreated
| EditMemberOperationToBeCreated
| FlagMemberOperationToBeCreated
| ResolveFlagMemberOperationToBeCreated
| RequestVerificationOperationToBeCreated
| TrustOperationToBeCreated
| MintOperationToBeCreated
| GiveOperationToBeCreated;
// LEGACY TYPES END---------------------
7 changes: 1 addition & 6 deletions packages/shared/src/routes/ApiEndpoint/ApiResponse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Operation, LegacyOperation } from "../../models/Operation";
import { Operation } from "../../models/Operation";
import { HttpStatusCode } from "../../helpers/http";
import { ApiEndpoint } from ".";
import { PublicMemberFields } from "../../models/Member";
Expand All @@ -16,8 +16,3 @@ export interface ApiResponseDefinition<Status extends HttpStatusCode, Body> {
}

export type ApiResponse = ApiEndpoint["response"];

// START LEGACY TYPES------------
export type LegacyOperationApiResponseBody = LegacyOperation;
export type LegacyOperationsApiResponseBody = LegacyOperation[];
// END LEGACY TYPES------------
34 changes: 7 additions & 27 deletions packages/shared/src/routes/me/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
OperationApiResponseBody,
MessageApiResponseBody
} from "../ApiEndpoint/ApiResponse";
import { ApiLocationDefinition, ApiCall } from "../ApiEndpoint/ApiCall";
import { ApiLocationDefinition } from "../ApiEndpoint/ApiCall";
import { MintPayload, EditMemberPayload } from "../../models/Operation";
import { VideoReference } from "../../models/MediaReference";

Expand Down Expand Up @@ -70,32 +70,12 @@ export type SendInviteApiResponse = ApiResponseDefinition<
201,
MessageApiResponseBody
>;
// START LEGACY TYPES---------------
export interface LegacySendInviteApiBody {
inviteEmail: string;
isJointVideo: boolean;
videoToken: string;
}
export type LegacySendInviteApiCall = ApiCallDefinition<
SendInviteApiLocation["uri"],
SendInviteApiLocation["method"],
SendInviteApiLocation["authenticated"],
void,
LegacySendInviteApiBody
>;
// END LEGACY TYPES---------------
// TODO: remove legacy api endpoint definition from below
export type SendInviteApiEndpoint =
| ApiEndpointDefinition<
ApiEndpointName.SEND_INVITE,
SendInviteApiCall,
SendInviteApiResponse
>
| ApiEndpointDefinition<
ApiEndpointName.SEND_INVITE,
LegacySendInviteApiCall,
SendInviteApiResponse
>;

export type SendInviteApiEndpoint = ApiEndpointDefinition<
ApiEndpointName.SEND_INVITE,
SendInviteApiCall,
SendInviteApiResponse
>;

/*
* TODO: find a better way to narrow the types precisely than this repetitive type declaration
Expand Down
71 changes: 9 additions & 62 deletions packages/shared/src/routes/members/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import {
import {
OperationApiResponseBody,
OperationsApiResponseBody,
MembersApiResponseBody,
LegacyOperationApiResponseBody,
LegacyOperationsApiResponseBody
MembersApiResponseBody
} from "../ApiEndpoint/ApiResponse";
import { HttpVerb } from "../../helpers/http";
import { ApiLocationDefinition } from "../ApiEndpoint/ApiCall";
Expand Down Expand Up @@ -139,39 +137,11 @@ export type CreateMemberApiResponse = ApiResponseDefinition<
OperationsApiResponseBody
>;

// START LEGACY TYPES-------------
export interface LegacyCreateMemberApiCallBody {
fullName: string;
emailAddress: string;
username: string;
inviteToken?: string;
subscribeToNewsletter?: boolean;
videoToken: string;
}
export type LegacyCreateMemberApiCall = ApiCallDefinition<
CreateMemberApiLocation["uri"],
CreateMemberApiLocation["method"],
CreateMemberApiLocation["authenticated"],
void,
LegacyCreateMemberApiCallBody
>;
export type LegacyCreateMemberApiResponse = ApiResponseDefinition<
201,
LegacyOperationsApiResponseBody
export type CreateMemberApiEndpoint = ApiEndpointDefinition<
ApiEndpointName.CREATE_MEMBER,
CreateMemberApiCall,
CreateMemberApiResponse
>;
// END LEGACY TYPES-------------
// TODO: remove legacy endpoint definition below
export type CreateMemberApiEndpoint =
| ApiEndpointDefinition<
ApiEndpointName.CREATE_MEMBER,
CreateMemberApiCall,
CreateMemberApiResponse
>
| ApiEndpointDefinition<
ApiEndpointName.CREATE_MEMBER,
LegacyCreateMemberApiCall,
LegacyCreateMemberApiResponse
>;

export type VerifyMemberApiLocation = ApiLocationDefinition<
ApiEndpointUri.VERIFY_MEMBER,
Expand All @@ -197,34 +167,11 @@ export type VerifyMemberApiResponse = ApiResponseDefinition<
201,
OperationApiResponseBody
>;
// START LEGACY TYPES-------------
export type LegacyVerifyMemberApiCall = ApiCallDefinition<
VerifyMemberApiLocation["uri"],
VerifyMemberApiLocation["method"],
VerifyMemberApiLocation["authenticated"],
{ memberId: MemberId },
LegacyVerifyMemberApiCallBody
>;
export type LegacyVerifyMemberApiResponse = ApiResponseDefinition<
201,
LegacyOperationApiResponseBody
export type VerifyMemberApiEndpoint = ApiEndpointDefinition<
ApiEndpointName.CREATE_MEMBER,
VerifyMemberApiCall,
VerifyMemberApiResponse
>;
export interface LegacyVerifyMemberApiCallBody {
videoToken: string;
}
// END LEGACY TYPES-----------
// TODO: remove legacy api definition below
export type VerifyMemberApiEndpoint =
| ApiEndpointDefinition<
ApiEndpointName.CREATE_MEMBER,
VerifyMemberApiCall,
VerifyMemberApiResponse
>
| ApiEndpointDefinition<
ApiEndpointName.CREATE_MEMBER,
LegacyVerifyMemberApiCall,
LegacyVerifyMemberApiResponse
>;

export type FlagMemberApiLocation = ApiLocationDefinition<
ApiEndpointUri.FLAG_MEMBER,
Expand Down

0 comments on commit 782072f

Please sign in to comment.