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

Change TS types to use type declarations from PN JS SDK #155

Merged
merged 3 commits into from
Jan 16, 2025
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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SONATYPE_HOST=DEFAULT
SONATYPE_AUTOMATIC_RELEASE=false
GROUP=com.pubnub
POM_PACKAGING=jar
VERSION_NAME=0.10.1
VERSION_NAME=0.11.0

POM_NAME=PubNub Chat SDK
POM_DESCRIPTION=This SDK offers a set of handy methods to create your own feature-rich chat or add a chat to your existing application.
Expand Down
7 changes: 6 additions & 1 deletion js-chat/.pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
name: pubnub-js-chat
version: 0.10.0
version: 0.11.0
scm: github.com/pubnub/js-chat
schema: 1
files:
- lib/dist/index.js
changelog:
- date: 2025-01-16
version: 0.11.0
changes:
- type: improvement
text: "The JS Chat SDK now uses TS types from recent versions of PubNub JS SDK instead of the ones in the `@types/pubnub` community resource. Changes to customer code might be required to accommodate this change."
- date: 2025-01-08
version: 0.10.0
changes:
Expand Down
3 changes: 1 addition & 2 deletions js-chat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"@rollup/plugin-terser": "^0.4.3",
"@rollup/plugin-commonjs": "28.0.1",
"@types/jest": "29.5.0",
"@types/pubnub": "7.4.2",
"babel-jest": "29.5.0",
"dotenv": "16.0.3",
"jest": "29.5.0",
Expand All @@ -41,7 +40,7 @@
"module": "dist/index.es.js",
"types": "dist/index.d.ts",
"react-native": "dist/index.es.js",
"version": "0.10.0",
"version": "0.11.0",
"name": "@pubnub/chat",
"dependencies": {
"pubnub": "8.4.1",
Expand Down
1 change: 0 additions & 1 deletion js-chat/package_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"@rollup/plugin-terser": "^0.4.3",
"@rollup/plugin-commonjs": "28.0.1",
"@types/jest": "29.5.0",
"@types/pubnub": "7.4.2",
"babel-jest": "29.5.0",
"dotenv": "16.0.3",
"jest": "29.5.0",
Expand Down
12 changes: 12 additions & 0 deletions js-chat/tests/channel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,11 @@ describe("Channel test", () => {
channelTypeField: true,
statusField: true,
channelStatusField: true,
typeField: true,
},
limit: null,
page: null,
sort: {},
uuid: chat.currentUser.id,
}

Expand Down Expand Up @@ -1261,4 +1265,12 @@ describe("Channel test", () => {
})
)
})

test("use PubNub SDK types from Chat SDK", async () => {
let channelMetadata = await chat.sdk.objects.getChannelMetadata({
channel: channel.id,
include: { customFields: true }
})
expect(channelMetadata).toBeDefined()
})
})
4 changes: 4 additions & 0 deletions js-chat/tests/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ describe("User test", () => {
channelTypeField: true,
statusField: true,
channelStatusField: true,
typeField: true,
},
limit: null,
page: null,
sort: {},
uuid: chat.currentUser.id,
}

Expand Down
92 changes: 44 additions & 48 deletions src/jsMain/resources/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/// <reference types="pubnub" />
import PubNub from "pubnub";
import { GetMembershipsParametersv2, GetChannelMembersParameters, ObjectCustom, SetMembershipsParameters, ChannelMetadataObject, PublishParameters, SendFileParameters } from "pubnub";
import { AppContext, Publish, FileSharing, Signal, Subscription, History } from "pubnub";
type MembershipFields = Pick<Membership, "channel" | "user" | "custom" | "updated" | "eTag" | "status" | "type">;
declare class Membership {
private chat;
readonly channel: Channel;
readonly user: User;
readonly custom: ObjectCustom | null | undefined;
readonly custom?: AppContext.CustomData | null;
readonly updated: string;
readonly eTag: string;
readonly status?: string;
readonly type?: string;
update({ custom }: {
custom: ObjectCustom;
custom: AppContext.CustomData;
}): Promise<Membership>;
/*
* Updates
Expand All @@ -35,7 +35,7 @@ declare class User {
readonly externalId?: string;
readonly profileUrl?: string;
readonly email?: string;
readonly custom?: ObjectCustom;
readonly custom?: AppContext.CustomData;
readonly status?: string;
readonly type?: string;
readonly updated?: string;
Expand All @@ -59,7 +59,7 @@ declare class User {
/*
* Memberships
*/
getMemberships(params?: Omit<GetMembershipsParametersv2, "include" | "uuid">): Promise<{
getMemberships(params?: Omit<AppContext.GetMembershipsParameters, "include" | "uuid">): Promise<{
page: {
next: string | undefined;
prev: string | undefined;
Expand All @@ -81,7 +81,7 @@ declare class User {
mute: boolean;
reason: string | number | boolean | undefined;
}>;
getChannelsRestrictions(params?: Pick<PubNub.GetChannelMembersParameters, "limit" | "page" | "sort">): Promise<{
getChannelsRestrictions(params?: Pick<AppContext.GetMembersParameters, "limit" | "page" | "sort">): Promise<{
page: {
next: string | undefined;
prev: string | undefined;
Expand All @@ -99,7 +99,7 @@ declare class User {
* Other
*/
/** @deprecated */
DEPRECATED_report(reason: string): Promise<PubNub.SignalResponse>;
DEPRECATED_report(reason: string): Promise<Signal.SignalResponse>;
}
type EventFields<T extends EventType> = Pick<Event<T>, "timetoken" | "type" | "payload" | "channelId" | "userId">;
declare class Event<T extends EventType> {
Expand Down Expand Up @@ -243,26 +243,22 @@ type MessageReferencedChannels = {
name: string;
};
};
type MessageDraftOptions = Omit<PublishParameters, "message" | "channel">;
type SendTextOptionParams = Omit<PublishParameters, "message" | "channel"> & {
type MessageDraftOptions = Omit<Publish.PublishParameters, "message" | "channel">;
type SendTextOptionParams = Omit<Publish.PublishParameters, "message" | "channel"> & {
mentionedUsers?: MessageMentionedUsers;
referencedChannels?: MessageReferencedChannels;
textLinks?: TextLink[];
quotedMessage?: Message;
files?: FileList | File[] | SendFileParameters["file"][];
files?: FileList | File[] | FileSharing.SendFileParameters<PubNub.PubNubFileParameters>["file"][];
};
type EnhancedMessageEvent = PubNub.MessageEvent & {
userMetadata?: {
[key: string]: any;
};
};
type MessageDTOParams = PubNub.FetchMessagesResponse["channels"]["channel"][0] | EnhancedMessageEvent;
type EnhancedMessageEvent = Subscription.Message;
type MessageDTOParams = History.FetchMessagesForChannelsResponse['channels'][string][number] | History.FetchMessagesWithActionsResponse['channels'][string][number] | EnhancedMessageEvent;
type ThreadMessageDTOParams = MessageDTOParams & {
parentChannelId: string;
};
type MembershipResponse = Awaited<ReturnType<User["getMemberships"]>>;
type OptionalAllBut<T, K extends keyof T> = Partial<T> & Pick<T, K>;
type ChannelDTOParams = OptionalAllBut<ChannelMetadataObject<ObjectCustom>, "id"> & {
type ChannelDTOParams = OptionalAllBut<AppContext.ChannelMetadataObject<AppContext.CustomData>, "id"> & {
status?: string | null;
type?: ChannelType | null | string;
};
Expand Down Expand Up @@ -396,11 +392,11 @@ declare class Message {
/*
* Other
*/
forward(channelId: string): Promise<PubNub.PublishResponse>;
forward(channelId: string): Promise<Publish.PublishResponse>;
pin(): Promise<void>;
/** @deprecated */
DEPRECATED_report(reason: string): Promise<PubNub.SignalResponse>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it mean that we are changing type in Deprecated method? If so it means that client should modify the code after upgrade? If so wouldn't be better to just remove this deprecated code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

only the type name changes, the content is the same

we could remove this method in the future I guess, we can do a sweep before 1.0.0 and remove any deprecated patterns

report(reason: string): Promise<PubNub.SignalResponse>;
DEPRECATED_report(reason: string): Promise<Signal.SignalResponse>;
report(reason: string): Promise<Signal.SignalResponse>;
/**
* Threads
*/
Expand Down Expand Up @@ -429,13 +425,13 @@ export declare class MessageDraftV2 {
get value(): string;
quotedMessage: Message | undefined;
readonly config: MessageDraftConfig;
files?: FileList | File[] | SendFileParameters["file"][];
files?: FileList | File[] | FileSharing.SendFileParameters<PubNub.PubNubFileParameters>["file"][];
addQuote(message: Message): void;
removeQuote(): void;
addLinkedText(params: AddLinkedTextParams): void;
removeLinkedText(positionInInput: number): void;
getMessagePreview(): MixedTextTypedElement[];
send(params?: MessageDraftOptions): Promise<PubNub.PublishResponse>;
send(params?: MessageDraftOptions): Promise<Publish.PublishResponse>;
addChangeListener(listener: (p0: MessageDraftState) => void): void;
removeChangeListener(listener: (p0: MessageDraftState) => void): void;
insertText(offset: number, text: string): void;
Expand Down Expand Up @@ -465,7 +461,7 @@ declare class MessageDraft {
value: string;
quotedMessage: Message | undefined;
readonly config: MessageDraftConfig;
files?: FileList | File[] | SendFileParameters["file"][];
files?: FileList | File[] | FileSharing.SendFileParameters<PubNub.PubNubFileParameters>["file"][];
onChange(text: string): Promise<{
users: {
nameOccurrenceIndex: number;
Expand Down Expand Up @@ -499,7 +495,7 @@ declare class Channel {
protected chat: Chat;
readonly id: string;
readonly name?: string;
readonly custom?: ObjectCustom;
readonly custom?: AppContext.CustomData;
readonly description?: string;
readonly updated?: string;
readonly status?: string;
Expand All @@ -515,9 +511,9 @@ declare class Channel {
static streamUpdatesOn(channels: Channel[], callback: (channels: Channel[]) => unknown): () => void;
streamUpdates(callback: (channel: Channel) => unknown): () => void;
sendText(text: string, options?: SendTextOptionParams): Promise<unknown>;
forwardMessage(message: Message): Promise<PubNub.PublishResponse>;
startTyping(): Promise<PubNub.SignalResponse | undefined>;
stopTyping(): Promise<PubNub.SignalResponse | undefined>;
forwardMessage(message: Message): Promise<Publish.PublishResponse>;
startTyping(): Promise<Signal.SignalResponse | undefined>;
stopTyping(): Promise<Signal.SignalResponse | undefined>;
getTyping(callback: (typingUserIds: string[]) => unknown): () => void;
/*
* Streaming messages
Expand All @@ -541,14 +537,14 @@ declare class Channel {
isMore: boolean;
}>;
getMessage(timetoken: string): Promise<Message>;
join(callback: (message: Message) => void, params?: Omit<SetMembershipsParameters<ObjectCustom>, "channels" | "include" | "filter"> & {
custom?: ObjectCustom;
join(callback: (message: Message) => void, params?: Omit<AppContext.SetMembershipsParameters<AppContext.CustomData>, "channels" | "include" | "filter"> & {
custom?: AppContext.CustomData;
}): Promise<{
membership: Membership;
disconnect: () => void;
}>;
leave(): Promise<boolean>;
getMembers(params?: Omit<GetChannelMembersParameters, "channel" | "include">): Promise<{
getMembers(params?: Omit<AppContext.GetMembersParameters, "channel" | "include">): Promise<{
page: {
next: string | undefined;
prev: string | undefined;
Expand All @@ -572,7 +568,7 @@ declare class Channel {
streamReadReceipts(callback: (receipts: {
[key: string]: string[];
}) => unknown): Promise<() => void>;
getFiles(params?: Omit<PubNub.ListFilesParameters, "channel">): Promise<{
getFiles(params?: Omit<FileSharing.ListFilesParameters, "channel">): Promise<{
files: {
name: string;
id: string;
Expand All @@ -584,7 +580,7 @@ declare class Channel {
deleteFile(params: {
id: string;
name: string;
}): Promise<PubNub.DeleteFileResponse>;
}): Promise<FileSharing.DeleteFileResponse>;
/**
* Moderation restrictions
*/
Expand All @@ -598,7 +594,7 @@ declare class Channel {
mute: boolean;
reason: string | number | boolean | undefined;
}>;
getUsersRestrictions(params?: Pick<PubNub.GetChannelMembersParameters, "limit" | "page" | "sort">): Promise<{
getUsersRestrictions(params?: Pick<AppContext.GetMembersParameters, "limit" | "page" | "sort">): Promise<{
page: {
next: string | undefined;
prev: string | undefined;
Expand Down Expand Up @@ -652,13 +648,13 @@ type ChatConfig = {
authKey?: string;
syncMutedUsers?: boolean;
};
type ChatConstructor = Partial<ChatConfig> & PubNub.PubnubConfig;
type ChatConstructor = Partial<ChatConfig> & PubNub.PubNubConfiguration;
declare class Chat {
readonly sdk: PubNub;
readonly config: ChatConfig;
private user;
static init(params: ChatConstructor): Promise<Chat>;
emitEvent(event: EmitEventParams): Promise<PubNub.SignalResponse>;
emitEvent(event: EmitEventParams): Promise<Signal.SignalResponse>;
listenForEvents<T extends EventType>(event: GenericEventParams<T> & {
callback: (event: Event<T>) => unknown;
}): () => void;
Expand All @@ -683,7 +679,7 @@ declare class Chat {
createUser(id: string, data: Omit<UserFields, "id">): Promise<User>;
updateUser(id: string, data: Omit<UserFields, "id">): Promise<User>;
deleteUser(id: string, params?: DeleteParameters): Promise<true | User>;
getUsers(params?: Omit<PubNub.GetAllMetadataParameters, "include">): Promise<{
getUsers(params?: Omit<AppContext.GetAllMetadataParameters<AppContext.UUIDMetadataObject<AppContext.CustomData>>, "include">): Promise<{
users: User[];
page: {
next: string | undefined;
Expand All @@ -696,7 +692,7 @@ declare class Chat {
*/
getChannel(id: string): Promise<Channel | null>;
updateChannel(id: string, data: Omit<ChannelFields, "id">): Promise<Channel>;
getChannels(params?: Omit<PubNub.GetAllMetadataParameters, "include">): Promise<{
getChannels(params?: Omit<AppContext.GetAllMetadataParameters<AppContext.ChannelMetadataObject<AppContext.CustomData>>, "include">): Promise<{
channels: Channel[];
page: {
next: string | undefined;
Expand All @@ -710,7 +706,7 @@ declare class Chat {
*/
createPublicConversation({ channelId, channelData }?: {
channelId?: string;
channelData?: PubNub.ChannelMetadata<PubNub.ObjectCustom>;
channelData?: AppContext.SetChannelMetadataParameters<AppContext.CustomData>;
}): Promise<Channel>;
/**
* Presence
Expand All @@ -721,9 +717,9 @@ declare class Chat {
createDirectConversation({ user, channelId, channelData, membershipData }: {
user: User;
channelId?: string;
channelData?: PubNub.ChannelMetadata<PubNub.ObjectCustom>;
membershipData?: Omit<PubNub.SetMembershipsParameters<PubNub.ObjectCustom>, "channels" | "include" | "filter"> & {
custom?: PubNub.ObjectCustom;
channelData?: AppContext.SetChannelMetadataParameters<AppContext.CustomData>;
membershipData?: Omit<AppContext.SetMembershipsParameters<AppContext.CustomData>, "channels" | "include" | "filter"> & {
custom?: AppContext.CustomData;
};
}): Promise<{
channel: Channel;
Expand All @@ -733,9 +729,9 @@ declare class Chat {
createGroupConversation({ users, channelId, channelData, membershipData }: {
users: User[];
channelId?: string;
channelData?: PubNub.ChannelMetadata<PubNub.ObjectCustom>;
membershipData?: Omit<PubNub.SetMembershipsParameters<PubNub.ObjectCustom>, "channels" | "include" | "filter"> & {
custom?: PubNub.ObjectCustom;
channelData?: AppContext.SetChannelMetadataParameters<AppContext.CustomData>;
membershipData?: Omit<AppContext.SetMembershipsParameters<AppContext.CustomData>, "channels" | "include" | "filter"> & {
custom?: AppContext.CustomData;
};
}): Promise<{
channel: Channel;
Expand All @@ -761,12 +757,12 @@ declare class Chat {
enhancedMentionsData: UserMentionData[];
isMore: boolean;
}>;
getUnreadMessagesCounts(params?: Omit<GetMembershipsParametersv2, "include">): Promise<{
getUnreadMessagesCounts(params?: Omit<AppContext.GetMembershipsParameters, "include">): Promise<{
channel: Channel;
membership: Membership;
count: number;
}[]>;
markAllMessagesAsRead(params?: Omit<GetMembershipsParametersv2, "include">): Promise<{
markAllMessagesAsRead(params?: Omit<AppContext.GetMembershipsParameters, "include">): Promise<{
page: {
next: string | undefined;
prev: string | undefined;
Expand Down Expand Up @@ -829,8 +825,8 @@ declare class QuotedMessage {

declare class MutedUsersManager {
get mutedUsers(): string[];
async muteUser(userId: string);
async unmuteUser(userId: string);
muteUser(userId: string): Promise<any>;
unmuteUser(userId: string): Promise<any>;
}

declare const MESSAGE_THREAD_ID_PREFIX = "PUBNUB_INTERNAL_THREAD";
Expand Down