Skip to content

Commit

Permalink
fix: remove unecessary WithUrl typing
Browse files Browse the repository at this point in the history
  • Loading branch information
marrouchi committed Jan 9, 2025
1 parent d831da2 commit d48b88f
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 34 deletions.
9 changes: 3 additions & 6 deletions api/src/channel/lib/__test__/common.mock.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
* Copyright © 2025 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/

import { Attachment } from '@/attachment/schemas/attachment.schema';
import { WithUrl } from '@/chat/schemas/types/attachment';
import { ButtonType } from '@/chat/schemas/types/button';
import {
FileType,
Expand Down Expand Up @@ -93,7 +92,7 @@ const attachment: Attachment = {
updatedAt: new Date(),
};

const attachmentWithUrl: WithUrl<Attachment> = {
const attachmentWithUrl: Attachment = {
...attachment,
url: 'http://localhost:4000/attachment/download/1/attachment.jpg',
};
Expand Down Expand Up @@ -154,9 +153,7 @@ export const contentMessage: StdOutgoingListMessage = {
},
};

export const attachmentMessage: StdOutgoingAttachmentMessage<
WithUrl<Attachment>
> = {
export const attachmentMessage: StdOutgoingAttachmentMessage<Attachment> = {
attachment: {
type: FileType.image,
payload: attachmentWithUrl,
Expand Down
6 changes: 2 additions & 4 deletions api/src/chat/schemas/types/attachment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
* Copyright © 2025 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
Expand All @@ -21,10 +21,8 @@ export type AttachmentForeignKey = {
attachment_id: string;
};

export type WithUrl<A> = A & { url?: string };

export interface AttachmentPayload<
A extends WithUrl<Attachment> | AttachmentForeignKey,
A extends Attachment | AttachmentForeignKey,
> {
type: FileType;
payload: A;
Expand Down
9 changes: 4 additions & 5 deletions api/src/chat/schemas/types/message.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
* Copyright © 2025 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
Expand All @@ -15,7 +15,6 @@ import {
AttachmentForeignKey,
AttachmentPayload,
IncomingAttachmentPayload,
WithUrl,
} from './attachment';
import { Button } from './button';
import { ContentOptions } from './options';
Expand Down Expand Up @@ -102,7 +101,7 @@ export type StdOutgoingListMessage = {
};

export type StdOutgoingAttachmentMessage<
A extends WithUrl<Attachment> | AttachmentForeignKey,
A extends Attachment | AttachmentForeignKey,
> = {
// Stored in DB as `AttachmentPayload`, `Attachment` when populated for channels relaying
attachment: AttachmentPayload<A>;
Expand All @@ -128,7 +127,7 @@ export type StdOutgoingMessage =
| StdOutgoingQuickRepliesMessage
| StdOutgoingButtonsMessage
| StdOutgoingListMessage
| StdOutgoingAttachmentMessage<WithUrl<Attachment>>;
| StdOutgoingAttachmentMessage<Attachment>;

type StdIncomingTextMessage = { text: string };

Expand Down Expand Up @@ -192,7 +191,7 @@ export interface StdOutgoingListEnvelope {

export interface StdOutgoingAttachmentEnvelope {
format: OutgoingMessageFormat.attachment;
message: StdOutgoingAttachmentMessage<WithUrl<Attachment>>;
message: StdOutgoingAttachmentMessage<Attachment>;
}

export type StdOutgoingEnvelope =
Expand Down
6 changes: 2 additions & 4 deletions api/src/chat/services/block.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
* Copyright © 2025 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
Expand All @@ -8,7 +8,6 @@

import { Injectable } from '@nestjs/common';

import { Attachment } from '@/attachment/schemas/attachment.schema';
import { AttachmentService } from '@/attachment/services/attachment.service';
import EventWrapper from '@/channel/lib/EventWrapper';
import { ContentService } from '@/cms/services/content.service';
Expand All @@ -25,7 +24,6 @@ import { getRandom } from '@/utils/helpers/safeRandom';

import { BlockRepository } from '../repositories/block.repository';
import { Block, BlockFull, BlockPopulate } from '../schemas/block.schema';
import { WithUrl } from '../schemas/types/attachment';
import { Context } from '../schemas/types/context';
import {
BlockMessage,
Expand Down Expand Up @@ -545,7 +543,7 @@ export class BlockService extends BaseService<Block, BlockPopulate, BlockFull> {
message: {
attachment: {
type: blockMessage.attachment.type,
payload: attachment as WithUrl<Attachment>,
payload: attachment,
},
quickReplies: blockMessage.quickReplies
? [...blockMessage.quickReplies]
Expand Down
5 changes: 2 additions & 3 deletions api/src/cms/services/content.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
* Copyright © 2025 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
Expand All @@ -10,7 +10,6 @@ import { Injectable } from '@nestjs/common';

import { Attachment } from '@/attachment/schemas/attachment.schema';
import { AttachmentService } from '@/attachment/services/attachment.service';
import { WithUrl } from '@/chat/schemas/types/attachment';
import {
ContentElement,
StdOutgoingListMessage,
Expand Down Expand Up @@ -108,7 +107,7 @@ export class ContentService extends BaseService<
acc[curr.id] = curr;
return acc;
},
{} as { [key: string]: WithUrl<Attachment> },
{} as { [key: string]: Attachment },
);
const populatedContents = elements.map((content) => {
const attachmentField = content[attachmentFieldName];
Expand Down
5 changes: 2 additions & 3 deletions api/src/extensions/channels/web/base-web-channel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
* Copyright © 2025 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
Expand All @@ -22,7 +22,6 @@ import { MessageCreateDto } from '@/chat/dto/message.dto';
import { SubscriberCreateDto } from '@/chat/dto/subscriber.dto';
import { VIEW_MORE_PAYLOAD } from '@/chat/helpers/constants';
import { Subscriber, SubscriberFull } from '@/chat/schemas/subscriber.schema';
import { WithUrl } from '@/chat/schemas/types/attachment';
import { Button, ButtonType } from '@/chat/schemas/types/button';
import {
AnyMessage,
Expand Down Expand Up @@ -959,7 +958,7 @@ export default abstract class BaseWebChannelHandler<
* @returns A ready to be sent attachment message
*/
_attachmentFormat(
message: StdOutgoingAttachmentMessage<WithUrl<Attachment>>,
message: StdOutgoingAttachmentMessage<Attachment>,
_options?: BlockOptions,
): Web.OutgoingMessageBase {
const payload: Web.OutgoingMessageBase = {
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/inbox/components/AttachmentViewer.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
* Copyright © 2025 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/


import DownloadIcon from "@mui/icons-material/Download";
import { Button, Dialog, DialogContent } from "@mui/material";
import { FC } from "react";
Expand All @@ -18,7 +19,6 @@ import {
FileType,
StdIncomingAttachmentMessage,
StdOutgoingAttachmentMessage,
WithUrl,
} from "@/types/message.types";

interface AttachmentInterface {
Expand Down Expand Up @@ -95,7 +95,7 @@ const componentMap: { [key in FileType]: FC<AttachmentInterface> } = {
export const AttachmentViewer = (props: {
message:
| StdIncomingAttachmentMessage
| StdOutgoingAttachmentMessage<WithUrl<AttachmentAttrs>>;
| StdOutgoingAttachmentMessage<AttachmentAttrs>;
}) => {
const message = props.message;

Expand Down
12 changes: 6 additions & 6 deletions frontend/src/types/message.types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
* Copyright © 2025 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/


import { EntityType } from "@/services/types";

import { IAttachment } from "./attachment.types";
Expand Down Expand Up @@ -47,17 +48,16 @@ export interface AttachmentAttrs {
size: number;
location: string;
channel?: Record<string, any>;
url?: string;
}

export type AttachmentForeignKey = {
url?: string;
attachment_id: string | undefined;
};

export type WithUrl<A> = A & { url?: string };

export interface AttachmentPayload<
A extends WithUrl<AttachmentAttrs> | AttachmentForeignKey,
A extends AttachmentAttrs | AttachmentForeignKey,
> {
type: FileType;
payload?: A;
Expand Down Expand Up @@ -172,7 +172,7 @@ export type StdOutgoingListMessage = {
};
};
export type StdOutgoingAttachmentMessage<
A extends WithUrl<AttachmentAttrs> | AttachmentForeignKey,
A extends AttachmentAttrs | AttachmentForeignKey,
> = {
// Stored in DB as `AttachmentPayload`, `Attachment` when populated for channels relaying
attachment: AttachmentPayload<A>;
Expand Down Expand Up @@ -217,7 +217,7 @@ export type StdOutgoingMessage =
| StdOutgoingQuickRepliesMessage
| StdOutgoingButtonsMessage
| StdOutgoingListMessage
| StdOutgoingAttachmentMessage<WithUrl<AttachmentAttrs>>;
| StdOutgoingAttachmentMessage<AttachmentAttrs>;

export interface IMessageAttributes {
mid?: string;
Expand Down

0 comments on commit d48b88f

Please sign in to comment.