Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
9bcb3da
feat: add bank account and supported banks APIs
JustKemForFun Apr 15, 2026
9f91696
refactor: streamline type exports in index.ts and enhance bank accoun…
JustKemForFun Apr 15, 2026
ae85f18
refactor: improve type imports and update sendBankCardFactory
JustKemForFun Apr 15, 2026
f0995ba
feat: add createBankAccount API and related types
JustKemForFun Apr 15, 2026
47e529c
feat: update Bank model with new bank codes and improve documentation
JustKemForFun Apr 15, 2026
5ec26a9
fix: enhance normalizeHolderName function for improved validation
JustKemForFun Apr 15, 2026
c9445e6
feat: add new bank-related APIs and update type exports
JustKemForFun Apr 16, 2026
fd7a82a
feat: add delete and update bank account APIs with corresponding types
JustKemForFun Apr 16, 2026
ff78bcf
feat: add getListDevice API and corresponding types
JustKemForFun Apr 16, 2026
3182c43
feat: add lostFocus API and corresponding types
JustKemForFun Apr 16, 2026
86dde86
feat: add registerCatalog API and corresponding types
JustKemForFun Apr 17, 2026
d925e90
feat: add scanURL API and corresponding types
JustKemForFun Apr 17, 2026
c1bac16
feat: update User model and API response types
JustKemForFun Apr 24, 2026
98c8ae2
feat: update API version and enhance type definitions
JustKemForFun Jun 4, 2026
6635bfa
fix(apis): correct & revert unnecessary changes
RFS-ADRENO Jun 18, 2026
a80bb47
fix(createCatalog): restore to original
RFS-ADRENO Jun 18, 2026
1c3e979
fix(createCatalog): revert format
RFS-ADRENO Jun 18, 2026
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
27 changes: 27 additions & 0 deletions src/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { changeGroupAvatarFactory } from "./apis/changeGroupAvatar.js";
import { changeGroupNameFactory } from "./apis/changeGroupName.js";
import { changeGroupOwnerFactory } from "./apis/changeGroupOwner.js";
import { createAutoReplyFactory } from "./apis/createAutoReply.js";
import { createBankAccountFactory } from "./apis/createBankAccount.js";
import { createCatalogFactory } from "./apis/createCatalog.js";
import { createGroupFactory } from "./apis/createGroup.js";
import { createNoteFactory } from "./apis/createNote.js";
Expand All @@ -24,6 +25,7 @@ import { createProductCatalogFactory } from "./apis/createProductCatalog.js";
import { createReminderFactory } from "./apis/createReminder.js";
import { deleteAutoReplyFactory } from "./apis/deleteAutoReply.js";
import { deleteAvatarFactory } from "./apis/deleteAvatar.js";
import { deleteBankAccountFactory } from "./apis/deleteBankAccount.js";
import { deleteCatalogFactory } from "./apis/deleteCatalog.js";
import { deleteChatFactory } from "./apis/deleteChat.js";
import { deleteGroupInviteBoxFactory } from "./apis/deleteGroupInviteBox.js";
Expand Down Expand Up @@ -66,7 +68,10 @@ import { getGroupLinkInfoFactory } from "./apis/getGroupLinkInfo.js";
import { getGroupMembersInfoFactory } from "./apis/getGroupMembersInfo.js";
import { getHiddenConversationsFactory } from "./apis/getHiddenConversations.js";
import { getLabelsFactory } from "./apis/getLabels.js";
import { getListBankFactory } from "./apis/getListBank.js";
import { getListBankCardFactory } from "./apis/getListBankCard.js";
import { getListBoardFactory } from "./apis/getListBoard.js";
import { getListDeviceFactory } from "./apis/getListDevice.js";
import { getListReminderFactory } from "./apis/getListReminder.js";
import { getMultiUsersByPhonesFactory } from "./apis/getMultiUsersByPhones.js";
import { getMuteFactory } from "./apis/getMute.js";
Expand Down Expand Up @@ -94,7 +99,9 @@ import { keepAliveFactory } from "./apis/keepAlive.js";
import { lastOnlineFactory } from "./apis/lastOnline.js";
import { leaveGroupFactory } from "./apis/leaveGroup.js";
import { lockPollFactory } from "./apis/lockPoll.js";
import { lostFocusFactory } from "./apis/lostFocus.js";
import { parseLinkFactory } from "./apis/parseLink.js";
import { registerCatalogFactory } from "./apis/registerCatalog.js";
import { rejectFriendRequestFactory } from "./apis/rejectFriendRequest.js";
import { removeFriendFactory } from "./apis/removeFriend.js";
import { removeFriendAliasFactory } from "./apis/removeFriendAlias.js";
Expand All @@ -107,6 +114,7 @@ import { removeUserFromGroupFactory } from "./apis/removeUserFromGroup.js";
import { resetHiddenConversPinFactory } from "./apis/resetHiddenConversPin.js";
import { reuseAvatarFactory } from "./apis/reuseAvatar.js";
import { reviewPendingMemberRequestFactory } from "./apis/reviewPendingMemberRequest.js";
import { scanURLFactory } from "./apis/scanURL.js";
import { searchStickerFactory } from "./apis/searchSticker.js";
import { sendBankCardFactory } from "./apis/sendBankCard.js";
import { sendCardFactory } from "./apis/sendCard.js";
Expand All @@ -131,6 +139,7 @@ import { updateActiveStatusFactory } from "./apis/updateActiveStatus.js";
import { updateArchivedChatListFactory } from "./apis/updateArchivedChatList.js";
import { updateAutoDeleteChatFactory } from "./apis/updateAutoDeleteChat.js";
import { updateAutoReplyFactory } from "./apis/updateAutoReply.js";
import { updateBankAccountFactory } from "./apis/updateBankAccount.js";
import { updateCatalogFactory } from "./apis/updateCatalog.js";
import { updateGroupSettingsFactory } from "./apis/updateGroupSettings.js";
import { updateHiddenConversPinFactory } from "./apis/updateHiddenConversPin.js";
Expand Down Expand Up @@ -168,6 +177,7 @@ export class API {
public changeGroupName: ReturnType<typeof changeGroupNameFactory>;
public changeGroupOwner: ReturnType<typeof changeGroupOwnerFactory>;
public createAutoReply: ReturnType<typeof createAutoReplyFactory>;
public createBankAccount: ReturnType<typeof createBankAccountFactory>;
public createCatalog: ReturnType<typeof createCatalogFactory>;
public createGroup: ReturnType<typeof createGroupFactory>;
public createNote: ReturnType<typeof createNoteFactory>;
Expand All @@ -176,6 +186,7 @@ export class API {
public createReminder: ReturnType<typeof createReminderFactory>;
public deleteAutoReply: ReturnType<typeof deleteAutoReplyFactory>;
public deleteAvatar: ReturnType<typeof deleteAvatarFactory>;
public deleteBankAccount: ReturnType<typeof deleteBankAccountFactory>;
public deleteCatalog: ReturnType<typeof deleteCatalogFactory>;
public deleteChat: ReturnType<typeof deleteChatFactory>;
public deleteGroupInviteBox: ReturnType<typeof deleteGroupInviteBoxFactory>;
Expand Down Expand Up @@ -218,7 +229,10 @@ export class API {
public getGroupMembersInfo: ReturnType<typeof getGroupMembersInfoFactory>;
public getHiddenConversations: ReturnType<typeof getHiddenConversationsFactory>;
public getLabels: ReturnType<typeof getLabelsFactory>;
public getListBank: ReturnType<typeof getListBankFactory>;
public getListBankCard: ReturnType<typeof getListBankCardFactory>;
public getListBoard: ReturnType<typeof getListBoardFactory>;
public getListDevice: ReturnType<typeof getListDeviceFactory>;
public getListReminder: ReturnType<typeof getListReminderFactory>;
public getMultiUsersByPhones: ReturnType<typeof getMultiUsersByPhonesFactory>;
public getMute: ReturnType<typeof getMuteFactory>;
Expand Down Expand Up @@ -246,7 +260,9 @@ export class API {
public lastOnline: ReturnType<typeof lastOnlineFactory>;
public leaveGroup: ReturnType<typeof leaveGroupFactory>;
public lockPoll: ReturnType<typeof lockPollFactory>;
public lostFocus: ReturnType<typeof lostFocusFactory>;
public parseLink: ReturnType<typeof parseLinkFactory>;
public registerCatalog: ReturnType<typeof registerCatalogFactory>;
public rejectFriendRequest: ReturnType<typeof rejectFriendRequestFactory>;
public removeFriend: ReturnType<typeof removeFriendFactory>;
public removeFriendAlias: ReturnType<typeof removeFriendAliasFactory>;
Expand All @@ -259,6 +275,7 @@ export class API {
public resetHiddenConversPin: ReturnType<typeof resetHiddenConversPinFactory>;
public reuseAvatar: ReturnType<typeof reuseAvatarFactory>;
public reviewPendingMemberRequest: ReturnType<typeof reviewPendingMemberRequestFactory>;
public scanURL: ReturnType<typeof scanURLFactory>;
public searchSticker: ReturnType<typeof searchStickerFactory>;
public sendBankCard: ReturnType<typeof sendBankCardFactory>;
public sendCard: ReturnType<typeof sendCardFactory>;
Expand All @@ -283,6 +300,7 @@ export class API {
public updateArchivedChatList: ReturnType<typeof updateArchivedChatListFactory>;
public updateAutoDeleteChat: ReturnType<typeof updateAutoDeleteChatFactory>;
public updateAutoReply: ReturnType<typeof updateAutoReplyFactory>;
public updateBankAccount: ReturnType<typeof updateBankAccountFactory>;
public updateCatalog: ReturnType<typeof updateCatalogFactory>;
public updateGroupSettings: ReturnType<typeof updateGroupSettingsFactory>;
public updateHiddenConversPin: ReturnType<typeof updateHiddenConversPinFactory>;
Expand Down Expand Up @@ -320,6 +338,7 @@ export class API {
this.changeGroupName = changeGroupNameFactory(ctx, this);
this.changeGroupOwner = changeGroupOwnerFactory(ctx, this);
this.createAutoReply = createAutoReplyFactory(ctx, this);
this.createBankAccount = createBankAccountFactory(ctx, this);
this.createCatalog = createCatalogFactory(ctx, this);
this.createGroup = createGroupFactory(ctx, this);
this.createNote = createNoteFactory(ctx, this);
Expand All @@ -328,6 +347,7 @@ export class API {
this.createReminder = createReminderFactory(ctx, this);
this.deleteAutoReply = deleteAutoReplyFactory(ctx, this);
this.deleteAvatar = deleteAvatarFactory(ctx, this);
this.deleteBankAccount = deleteBankAccountFactory(ctx, this);
this.deleteCatalog = deleteCatalogFactory(ctx, this);
this.deleteChat = deleteChatFactory(ctx, this);
this.deleteGroupInviteBox = deleteGroupInviteBoxFactory(ctx, this);
Expand Down Expand Up @@ -370,7 +390,10 @@ export class API {
this.getGroupMembersInfo = getGroupMembersInfoFactory(ctx, this);
this.getHiddenConversations = getHiddenConversationsFactory(ctx, this);
this.getLabels = getLabelsFactory(ctx, this);
this.getListBank = getListBankFactory(ctx, this);
this.getListBankCard = getListBankCardFactory(ctx, this);
this.getListBoard = getListBoardFactory(ctx, this);
this.getListDevice = getListDeviceFactory(ctx, this);
this.getListReminder = getListReminderFactory(ctx, this);
this.getMultiUsersByPhones = getMultiUsersByPhonesFactory(ctx, this);
this.getMute = getMuteFactory(ctx, this);
Expand Down Expand Up @@ -398,7 +421,9 @@ export class API {
this.lastOnline = lastOnlineFactory(ctx, this);
this.leaveGroup = leaveGroupFactory(ctx, this);
this.lockPoll = lockPollFactory(ctx, this);
this.lostFocus = lostFocusFactory(ctx, this);
this.parseLink = parseLinkFactory(ctx, this);
this.registerCatalog = registerCatalogFactory(ctx, this);
this.rejectFriendRequest = rejectFriendRequestFactory(ctx, this);
this.removeFriend = removeFriendFactory(ctx, this);
this.removeFriendAlias = removeFriendAliasFactory(ctx, this);
Expand All @@ -411,6 +436,7 @@ export class API {
this.resetHiddenConversPin = resetHiddenConversPinFactory(ctx, this);
this.reuseAvatar = reuseAvatarFactory(ctx, this);
this.reviewPendingMemberRequest = reviewPendingMemberRequestFactory(ctx, this);
this.scanURL = scanURLFactory(ctx, this);
this.searchSticker = searchStickerFactory(ctx, this);
this.sendBankCard = sendBankCardFactory(ctx, this);
this.sendCard = sendCardFactory(ctx, this);
Expand All @@ -435,6 +461,7 @@ export class API {
this.updateArchivedChatList = updateArchivedChatListFactory(ctx, this);
this.updateAutoDeleteChat = updateAutoDeleteChatFactory(ctx, this);
this.updateAutoReply = updateAutoReplyFactory(ctx, this);
this.updateBankAccount = updateBankAccountFactory(ctx, this);
this.updateCatalog = updateCatalogFactory(ctx, this);
this.updateGroupSettings = updateGroupSettingsFactory(ctx, this);
this.updateHiddenConversPin = updateHiddenConversPinFactory(ctx, this);
Expand Down
43 changes: 43 additions & 0 deletions src/apis/createBankAccount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import type { BankAccount, BinBankCard } from "../models/index.js";
import { apiFactory, normalizeHolderName } from "../utils.js";

export type CreateBankAccountPayload = {
binBank: BinBankCard;
numAccBank: string;
nameAccBank: string;
};

export type CreateBankAccountResponse = BankAccount;

export const createBankAccountFactory = apiFactory<CreateBankAccountResponse>()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.zimsg[0]}/api/transfer/create`);

/**
* Create bank account
*
* @param payload The payload containing the bank account information
*
* @throws {ZaloApiError}
*/
return async function createBankAccount(payload: CreateBankAccountPayload) {
const params = {
bin: payload.binBank,
bank_number: payload.numAccBank,
holder_name: normalizeHolderName(payload.nameAccBank),
language: ctx.language,
};

const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams) throw new ZaloApiError("Failed to encrypt params");

const response = await utils.request(serviceURL, {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});

return utils.resolve(response);
};
});
49 changes: 49 additions & 0 deletions src/apis/deleteBankAccount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import type { BankAccount } from "../models/index.js";
import { apiFactory } from "../utils.js";

export type DeleteBankAccountPayload = {
accountId: number;
isDefault: boolean;
};

/**
* I'm really confused that the list of accounts that are not mine is returned by this `api.deleteBankAccount()` T.T
* @TODO check again later
*/
export type DeleteBankAccountResponse = {
hasMore: boolean;
total: number;
myBanks: BankAccount[];
};

export const deleteBankAccountFactory = apiFactory<DeleteBankAccountResponse>()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.zimsg[0]}/api/transfer/delete`);

/**
* Delete bank account
*
* @param payload The payload containing the bank account information to delete
*
* @throws {ZaloApiError}
*/
return async function deleteBankAccount(payload: DeleteBankAccountPayload) {
const params = {
account_id: payload.accountId,
is_default: payload.isDefault,
language: ctx.language,
};

const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams) throw new ZaloApiError("Failed to encrypt params");

const response = await utils.request(serviceURL, {
method: "POST",
body: new URLSearchParams({
params: encryptedParams,
}),
});

return utils.resolve(response);
};
});
4 changes: 2 additions & 2 deletions src/apis/getGroupLinkInfo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import type { GroupSetting } from "../models/index.js";
import type { GroupSetting, GroupType } from "../models/index.js";
import { apiFactory } from "../utils.js";

export type GetGroupLinkInfoPayload = {
Expand All @@ -14,7 +14,7 @@ export type GetGroupLinkInfoResponse = {
groupId: string;
name: string;
desc: string;
type: number;
type: GroupType;
creatorId: string;
avt: string;
fullAvt: string;
Expand Down
29 changes: 29 additions & 0 deletions src/apis/getListBank.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import type { BankInfo } from "../models/index.js";
import { apiFactory } from "../utils.js";

export type GetListBankResponse = {
banks: BankInfo[];
};

export const getListBankFactory = apiFactory<GetListBankResponse>()((api, _ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.zimsg[0]}/api/transfer/conf`);

/**
* Get list bank
*
* @throws {ZaloApiError}
*/
return async function getListBank() {
const params = {};

const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams) throw new ZaloApiError("Failed to encrypt params");

const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
method: "GET",
});

return utils.resolve(response);
};
});
37 changes: 37 additions & 0 deletions src/apis/getListBankCard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import type { BankAccount } from "../models/index.js";
import { apiFactory } from "../utils.js";

export type GetListBankCardResponse = {
hasMore: boolean;
total: number;
myBanks: BankAccount[];
};

export const getListBankCardFactory = apiFactory<GetListBankCardResponse>()((api, _ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.zimsg[0]}/api/transfer/list`);

/**
* Get list bank card
*
* @param page Page number (default: 0)
* @param limit Number of items to retrieve (default: 20)
*
* @throws {ZaloApiError}
*/
return async function getListBankCard(page: number = 0, limit: number = 20) {
const params = {
page: page,
limit: limit,
};

const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams) throw new ZaloApiError("Failed to encrypt params");

const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
method: "GET",
});

return utils.resolve(response);
};
});
36 changes: 36 additions & 0 deletions src/apis/getListDevice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";

export type GetListDeviceResponse = {
devices: {
masterId: string;
encIdentity: string;
lastUpdateTs: number;
encSignature: string;
companions: string[] | unknown[]; // @TODO check type later
};
};

export const getListDeviceFactory = apiFactory<GetListDeviceResponse>()((api, ctx, utils) => {
const serviceURL = utils.makeURL(`${api.zpwServiceMap.aext[0]}/api/devices/linked`);

/**
* Get list device
*
* @throws {ZaloApiError}
*/
return async function getListDevice() {
const params = {
imei: ctx.imei,
};

const encryptedParams = utils.encodeAES(JSON.stringify(params));
if (!encryptedParams) throw new ZaloApiError("Failed to encrypt params");

const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
method: "GET",
});

return utils.resolve(response);
};
});
4 changes: 2 additions & 2 deletions src/apis/getUserInfo.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ZaloApiError } from "../Errors/ZaloApiError.js";
import { apiFactory } from "../utils.js";

import { AvatarSize, type User } from "../models/index.js";
import { AvatarSize, type UnchangedProfileInfo, type User } from "../models/index.js";

export type ProfileInfo = User;

export type UserInfoResponse = {
unchanged_profiles: Record<string, unknown>;
unchanged_profiles: Record<string, Partial<UnchangedProfileInfo>>;
phonebook_version: number;
changed_profiles: Record<string, ProfileInfo>;
};
Expand Down
Loading
Loading