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

fix config from package tag #893

Merged
merged 1 commit into from
Nov 28, 2023
Merged
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
7 changes: 5 additions & 2 deletions packages/restapi/src/lib/chat/addAdmins.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Constants from '../constants';
import { ALPHA_FEATURE_CONFIG } from '../config';
import Constants, { PACKAGE_BUILD } from '../constants';
import { EnvOptionsType, SignerType, GroupInfoDTO } from '../types';
import {
GroupMemberUpdateOptions,
@@ -23,7 +24,9 @@ export const addAdmins = async (
signer = null,
env = Constants.ENV.PROD,
pgpPrivateKey = null,
overrideSecretKeyGeneration = true,
overrideSecretKeyGeneration = !ALPHA_FEATURE_CONFIG[
PACKAGE_BUILD
].feature.includes(Constants.ALPHA_FEATURES.SCALABILITY_V2),
} = options || {};
try {
if (account == null && signer == null) {
7 changes: 5 additions & 2 deletions packages/restapi/src/lib/chat/addMembers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Constants from '../constants';
import { ALPHA_FEATURE_CONFIG } from '../config';
import Constants, { PACKAGE_BUILD } from '../constants';
import { EnvOptionsType, SignerType, GroupInfoDTO } from '../types';
import { updateGroupMembers } from './updateGroupMembers';
import { GroupMemberUpdateOptions } from './updateGroupMembers';
@@ -24,7 +25,9 @@ export const addMembers = async (
signer = null,
env = Constants.ENV.PROD,
pgpPrivateKey = null,
overrideSecretKeyGeneration = true,
overrideSecretKeyGeneration = !ALPHA_FEATURE_CONFIG[
PACKAGE_BUILD
].feature.includes(Constants.ALPHA_FEATURES.SCALABILITY_V2),
} = options || {};
try {
if (account == null && signer == null) {
7 changes: 5 additions & 2 deletions packages/restapi/src/lib/chat/approveRequest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios';
import { getAPIBaseUrls, isValidETHAddress } from '../helpers';
import Constants from '../constants';
import Constants, { PACKAGE_BUILD } from '../constants';
import { EnvOptionsType, SignerType } from '../types';
import {
getAccountAddress,
@@ -14,6 +14,7 @@ import * as CryptoJS from 'crypto-js';
import * as AES from '../chat/helpers/aes';
import { getGroupInfo } from './getGroupInfo';
import { getAllGroupMembersPublicKeys } from './getAllGroupMembersPublicKeys';
import { ALPHA_FEATURE_CONFIG } from '../config';

export interface ApproveRequestOptionsType extends EnvOptionsType {
/**
@@ -52,7 +53,9 @@ export const approveCore = async (
senderAddress,
env = Constants.ENV.PROD,
pgpPrivateKey = null,
overrideSecretKeyGeneration = true,
overrideSecretKeyGeneration = !ALPHA_FEATURE_CONFIG[
PACKAGE_BUILD
].feature.includes(Constants.ALPHA_FEATURES.SCALABILITY_V2),
} = options || {};

/**
7 changes: 5 additions & 2 deletions packages/restapi/src/lib/chat/modifyRole.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Constants from '../constants';
import { ALPHA_FEATURE_CONFIG } from '../config';
import Constants, { PACKAGE_BUILD } from '../constants';
import { EnvOptionsType, SignerType, GroupInfoDTO } from '../types';
import {
GroupMemberUpdateOptions,
@@ -26,7 +27,9 @@ export const modifyRoles = async (
signer = null,
env = Constants.ENV.PROD,
pgpPrivateKey = null,
overrideSecretKeyGeneration = true,
overrideSecretKeyGeneration = !ALPHA_FEATURE_CONFIG[
PACKAGE_BUILD
].feature.includes(Constants.ALPHA_FEATURES.SCALABILITY_V2),
} = options || {};

try {
7 changes: 5 additions & 2 deletions packages/restapi/src/lib/chat/removeAdmins.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Constants from '../constants';
import { ALPHA_FEATURE_CONFIG } from '../config';
import Constants, { PACKAGE_BUILD } from '../constants';
import { EnvOptionsType, SignerType, GroupInfoDTO } from '../types';
import {
GroupMemberUpdateOptions,
@@ -27,7 +28,9 @@ export const removeAdmins = async (
signer = null,
env = Constants.ENV.PROD,
pgpPrivateKey = null,
overrideSecretKeyGeneration = true,
overrideSecretKeyGeneration = !ALPHA_FEATURE_CONFIG[
PACKAGE_BUILD
].feature.includes(Constants.ALPHA_FEATURES.SCALABILITY_V2),
} = options || {};
try {
if (account == null && signer == null) {
7 changes: 5 additions & 2 deletions packages/restapi/src/lib/chat/removeMembers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Constants from '../constants';
import { ALPHA_FEATURE_CONFIG } from '../config';
import Constants, { PACKAGE_BUILD } from '../constants';
import { EnvOptionsType, SignerType, GroupInfoDTO } from '../types';
import {
GroupMemberUpdateOptions,
@@ -23,7 +24,9 @@ export const removeMembers = async (
signer = null,
env = Constants.ENV.PROD,
pgpPrivateKey = null,
overrideSecretKeyGeneration = true,
overrideSecretKeyGeneration = !ALPHA_FEATURE_CONFIG[
PACKAGE_BUILD
].feature.includes(Constants.ALPHA_FEATURES.SCALABILITY_V2),
} = options || {};
try {
if (account == null && signer == null) {
7 changes: 5 additions & 2 deletions packages/restapi/src/lib/chat/updateGroupMembers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios';
import { getAPIBaseUrls } from '../helpers';
import Constants from '../constants';
import Constants, { PACKAGE_BUILD } from '../constants';
import {
getWallet,
PGPHelper,
@@ -15,6 +15,7 @@ import { getGroupInfo } from './getGroupInfo';
import { getGroupMemberStatus } from './getGroupMemberStatus';
import * as AES from '../chat/helpers/aes';
import { getAllGroupMembersPublicKeys } from './getAllGroupMembersPublicKeys';
import { ALPHA_FEATURE_CONFIG } from '../config';

export interface GroupMemberUpdateOptions extends EnvOptionsType {
chatId: string;
@@ -39,7 +40,9 @@ export const updateGroupMembers = async (
signer = null,
env = Constants.ENV.PROD,
pgpPrivateKey = null,
overrideSecretKeyGeneration = true,
overrideSecretKeyGeneration = !ALPHA_FEATURE_CONFIG[
PACKAGE_BUILD
].feature.includes(Constants.ALPHA_FEATURES.SCALABILITY_V2),
} = options;
try {
validateGroupMemberUpdateOptions(options);
30 changes: 21 additions & 9 deletions packages/restapi/src/lib/config.ts
Original file line number Diff line number Diff line change
@@ -40,14 +40,19 @@ const BLOCKCHAIN_NETWORK = {
POLYGON_ZK_EVM_TESTNET: 'eip155:1442',
POLYGON_ZK_EVM_MAINNET: 'eip155:1101',
ARBITRUM_TESTNET: 'eip155:421613',
ARBITRUMONE_MAINNET: "eip155:42161"
ARBITRUMONE_MAINNET: 'eip155:42161',
};

export type ALIAS_CHAIN = 'POLYGON' | 'BSC' | 'OPTIMISM' | 'POLYGONZKEVM' | "ARBITRUMONE";
export type ALIAS_CHAIN =
| 'POLYGON'
| 'BSC'
| 'OPTIMISM'
| 'POLYGONZKEVM'
| 'ARBITRUMONE';

export const ETH_CHAIN_ID = {
[ENV.PROD]: 1,
[ENV.STAGING]:11155111,
[ENV.STAGING]: 11155111,
[ENV.DEV]: 11155111,
[ENV.LOCAL]: 11155111,
};
@@ -81,7 +86,7 @@ export const ALIAS_CHAIN_ID = {
[ENV.STAGING]: 421613,
[ENV.DEV]: 421613,
[ENV.LOCAL]: 421613,
}
},
};

export const CHAIN_ID = {
@@ -106,15 +111,14 @@ export const CHAIN_NAME: { [key: number]: string } = {
1101: 'POLYGONZKEVM',
1442: 'POLYGONZKEVM',
// arbitrun
421613:'ARBITRUN',
42161:'ARBITRUM'
421613: 'ARBITRUN',
42161: 'ARBITRUM',
};
export interface ConfigType {
API_BASE_URL: string;
EPNS_COMMUNICATOR_CONTRACT: string;
}


export const VIEM_CORE_CONFIG = {
[ENV.PROD]: {
NETWORK: mainnet,
@@ -277,7 +281,7 @@ export const TOKEN_VIEM_NETWORK_MAP = {
[ENV.STAGING]: sepolia,
[ENV.DEV]: sepolia,
[ENV.LOCAL]: sepolia,
}
};

export const MIN_TOKEN_BALANCE = {
[ENV.PROD]: 50,
@@ -296,7 +300,6 @@ export const CHANNEL_TYPE = {
GENERAL: 2,
};


export const VIEM_CONFIG = {
[ENV.PROD]: {
[BLOCKCHAIN_NETWORK.ETH_MAINNET]: {
@@ -407,3 +410,12 @@ export const VIEM_CONFIG = {
},
},
};

export const ALPHA_FEATURE_CONFIG = {
STABLE: {
feature: [] as string[],
},
ALPHA: {
feature: [Constants.ALPHA_FEATURES.SCALABILITY_V2],
},
};
9 changes: 8 additions & 1 deletion packages/restapi/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const packageJson = require('../../package.json');

/**
* SUPPORTED ENVIRONEMENTS
*/
@@ -44,9 +47,13 @@ export enum MessageType {
}

export const ALPHA_FEATURES = {
GROUP_SCALABILITY: 'GROUP_SCALABILITY',
SCALABILITY_V2: 'SCALABILITY_V2',
};

export const PACKAGE_BUILD = packageJson.version.includes('alpha')
? 'ALPHA'
: 'STABLE';
console.log(PACKAGE_BUILD);
const Constants = {
ENV,
ENCRYPTION_TYPE,
5 changes: 3 additions & 2 deletions packages/restapi/src/lib/pushapi/PushAPI.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Constants, { ENV } from '../constants';
import Constants, { ENV, PACKAGE_BUILD } from '../constants';
import { SignerType, ProgressHookType } from '../types';
import { PushAPIInitializeProps } from './pushAPITypes';
import * as PUSH_USER from '../user';
@@ -15,6 +15,7 @@ import {
PushStreamInitializeProps,
STREAM,
} from '../pushstream/pushStreamTypes';
import { ALPHA_FEATURE_CONFIG } from '../config';

export class PushAPI {
private signer?: SignerType;
@@ -137,7 +138,7 @@ export class PushAPI {
alpha:
options?.alpha && options.alpha.feature
? options.alpha
: { feature: [] },
: ALPHA_FEATURE_CONFIG[PACKAGE_BUILD],
};

const readMode = !signer;
129 changes: 50 additions & 79 deletions packages/restapi/src/lib/pushapi/chat.ts
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ import { updateGroupConfig } from '../chat/updateGroupConfig';
import { PushAPI } from './PushAPI';
export class Chat {
private userInstance: User;
private groupScalabilityTag: 'ALPHA' | 'STABLE';
private scalabilityV2Feature: boolean;

constructor(
private account: string,
@@ -46,11 +46,9 @@ export class Chat {
private progressHook?: (progress: ProgressHookType) => void
) {
this.userInstance = new User(this.account, this.env);
this.groupScalabilityTag = this.alpha.feature.includes(
ALPHA_FEATURES.GROUP_SCALABILITY
)
? 'ALPHA'
: 'STABLE';
this.scalabilityV2Feature = this.alpha.feature.includes(
ALPHA_FEATURES.SCALABILITY_V2
);
}

async list(
@@ -81,6 +79,7 @@ export class Chat {
throw new Error('Invalid Chat List Type');
}
}

async latest(target: string) {
const { threadHash } = await PUSH_CHAT.conversationHash({
conversationId: target,
@@ -170,7 +169,7 @@ export class Chat {
account: this.account,
signer: this.signer,
pgpPrivateKey: this.decryptedPgpPvtKey,
overrideSecretKeyGeneration: this.groupScalabilityTag !== 'ALPHA',
overrideSecretKeyGeneration: !this.scalabilityV2Feature,
});
}

@@ -304,14 +303,14 @@ export class Chat {
admins: options?.admins ? options.admins : [],
};
const response = await PUSH_CHAT.createGroupV2(groupParams);
switch (this.groupScalabilityTag) {
case 'ALPHA':
return response;
case 'STABLE':
return await PUSH_CHAT.getGroup({
chatId: response.chatId,
env: this.env,
});

if (this.scalabilityV2Feature) {
return response;
} else {
return await PUSH_CHAT.getGroup({
chatId: response.chatId,
env: this.env,
});
}
},

@@ -344,18 +343,15 @@ export class Chat {
},

info: async (chatId: string): Promise<GroupDTO | GroupInfoDTO> => {
switch (this.groupScalabilityTag) {
case 'ALPHA':
return await PUSH_CHAT.getGroupInfo({
return this.scalabilityV2Feature
? await PUSH_CHAT.getGroupInfo({
chatId: chatId,
env: this.env,
});
case 'STABLE':
return await PUSH_CHAT.getGroup({
})
: await PUSH_CHAT.getGroup({
chatId: chatId,
env: this.env,
});
}
},
update: async (
chatId: string,
@@ -400,14 +396,13 @@ export class Chat {
await updateGroupProfile(updateGroupProfileOptions);
const response = await updateGroupConfig(updateGroupConfigOptions);

switch (this.groupScalabilityTag) {
case 'ALPHA':
return response;
case 'STABLE':
return await PUSH_CHAT.getGroup({
chatId: response.chatId,
env: this.env,
});
if (this.scalabilityV2Feature) {
return response;
} else {
return await PUSH_CHAT.getGroup({
chatId: response.chatId,
env: this.env,
});
}
},

@@ -444,7 +439,7 @@ export class Chat {
account: this.account,
signer: this.signer,
pgpPrivateKey: this.decryptedPgpPvtKey,
overrideSecretKeyGeneration: this.groupScalabilityTag !== 'ALPHA',
overrideSecretKeyGeneration: !this.scalabilityV2Feature,
});
} else {
response = await PUSH_CHAT.addMembers({
@@ -454,18 +449,17 @@ export class Chat {
account: this.account,
signer: this.signer,
pgpPrivateKey: this.decryptedPgpPvtKey,
overrideSecretKeyGeneration: this.groupScalabilityTag !== 'ALPHA',
overrideSecretKeyGeneration: !this.scalabilityV2Feature,
});
}

switch (this.groupScalabilityTag) {
case 'ALPHA':
return response;
case 'STABLE':
return await PUSH_CHAT.getGroup({
chatId: response.chatId,
env: this.env,
});
if (this.scalabilityV2Feature) {
return response;
} else {
return await PUSH_CHAT.getGroup({
chatId: response.chatId,
env: this.env,
});
}
},

@@ -513,7 +507,7 @@ export class Chat {
account: this.account,
signer: this.signer,
pgpPrivateKey: this.decryptedPgpPvtKey,
overrideSecretKeyGeneration: this.groupScalabilityTag !== 'ALPHA',
overrideSecretKeyGeneration: !this.scalabilityV2Feature,
});
}

@@ -525,21 +519,10 @@ export class Chat {
account: this.account,
signer: this.signer,
pgpPrivateKey: this.decryptedPgpPvtKey,
overrideSecretKeyGeneration: this.groupScalabilityTag !== 'ALPHA',
overrideSecretKeyGeneration: !this.scalabilityV2Feature,
});
}
switch (this.groupScalabilityTag) {
case 'ALPHA':
return await PUSH_CHAT.getGroupInfo({
chatId: chatId,
env: this.env,
});
case 'STABLE':
return await PUSH_CHAT.getGroup({
chatId: chatId,
env: this.env,
});
}
return await this.group.info(chatId);
},

modify: async (chatId: string, options: ManageGroupOptions) => {
@@ -570,7 +553,7 @@ export class Chat {
account: this.account,
signer: this.signer,
pgpPrivateKey: this.decryptedPgpPvtKey,
overrideSecretKeyGeneration: this.groupScalabilityTag !== 'ALPHA',
overrideSecretKeyGeneration: !this.scalabilityV2Feature,
});
},

@@ -591,7 +574,7 @@ export class Chat {
account: this.account,
signer: this.signer,
pgpPrivateKey: this.decryptedPgpPvtKey,
overrideSecretKeyGeneration: this.groupScalabilityTag !== 'ALPHA',
overrideSecretKeyGeneration: !this.scalabilityV2Feature,
});
} else if (!status.isMember) {
await PUSH_CHAT.addMembers({
@@ -601,21 +584,10 @@ export class Chat {
account: this.account,
signer: this.signer,
pgpPrivateKey: this.decryptedPgpPvtKey,
overrideSecretKeyGeneration: this.groupScalabilityTag !== 'ALPHA',
overrideSecretKeyGeneration: !this.scalabilityV2Feature,
});
}
switch (this.groupScalabilityTag) {
case 'ALPHA':
return await PUSH_CHAT.getGroupInfo({
chatId: target,
env: this.env,
});
case 'STABLE':
return await PUSH_CHAT.getGroup({
chatId: target,
env: this.env,
});
}
return await this.group.info(target);
},

leave: async (target: string): Promise<GroupInfoDTO | GroupDTO> => {
@@ -639,7 +611,7 @@ export class Chat {
account: this.account,
signer: this.signer,
pgpPrivateKey: this.decryptedPgpPvtKey,
overrideSecretKeyGeneration: this.groupScalabilityTag !== 'ALPHA',
overrideSecretKeyGeneration: !this.scalabilityV2Feature,
});
} else {
response = await PUSH_CHAT.removeMembers({
@@ -649,18 +621,17 @@ export class Chat {
account: this.account,
signer: this.signer,
pgpPrivateKey: this.decryptedPgpPvtKey,
overrideSecretKeyGeneration: this.groupScalabilityTag !== 'ALPHA',
overrideSecretKeyGeneration: !this.scalabilityV2Feature,
});
}

switch (this.groupScalabilityTag) {
case 'ALPHA':
return response;
case 'STABLE':
return await PUSH_CHAT.getGroup({
chatId: response.chatId,
env: this.env,
});
if (this.scalabilityV2Feature) {
return response;
} else {
return await PUSH_CHAT.getGroup({
chatId: response.chatId,
env: this.env,
});
}
},

5 changes: 3 additions & 2 deletions packages/restapi/src/lib/pushstream/PushStream.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EventEmitter } from 'events';
import { createSocketConnection, EVENTS } from '@pushprotocol/socket';
import { ENV } from '../constants';
import { ENV, PACKAGE_BUILD } from '../constants';
import {
GroupEventType,
MessageEventType,
@@ -12,6 +12,7 @@ import { DataModifier } from './DataModifier';
import { pCAIP10ToWallet, walletToPCAIP10 } from '../helpers';
import { Chat } from '../pushapi/chat';
import { ProgressHookType, SignerType } from '../types';
import { ALPHA_FEATURE_CONFIG } from '../config';

export class PushStream extends EventEmitter {
private pushChatSocket: any;
@@ -42,7 +43,7 @@ export class PushStream extends EventEmitter {
this.chatInstance = new Chat(
this.account,
this.options.env as ENV,
{ feature: [] },
ALPHA_FEATURE_CONFIG[PACKAGE_BUILD],
this.decryptedPgpPvtKey,
this.signer,
this.progressHook
6 changes: 3 additions & 3 deletions packages/restapi/tests/lib/chat/privateGroup.test.ts
Original file line number Diff line number Diff line change
@@ -40,23 +40,23 @@ describe('Private Groups', () => {
account1 = `eip155:${signer1.address}`;
userAlice = await PushAPI.initialize(signer1, {
env: _env,
alpha: { feature: [Constants.ALPHA_FEATURES.GROUP_SCALABILITY] },
alpha: { feature: [Constants.ALPHA_FEATURES.SCALABILITY_V2] },
});

const WALLET2 = ethers.Wallet.createRandom();
const signer2 = new ethers.Wallet(WALLET2.privateKey);
account2 = `eip155:${signer2.address}`;
userBob = await PushAPI.initialize(signer2, {
env: _env,
alpha: { feature: [Constants.ALPHA_FEATURES.GROUP_SCALABILITY] },
alpha: { feature: [Constants.ALPHA_FEATURES.SCALABILITY_V2] },
});

const WALLET3 = ethers.Wallet.createRandom();
const signer3 = new ethers.Wallet(WALLET3.privateKey);
account3 = `eip155:${signer3.address}`;
userJohn = await PushAPI.initialize(signer3, {
env: _env,
alpha: { feature: [Constants.ALPHA_FEATURES.GROUP_SCALABILITY] },
alpha: { feature: [Constants.ALPHA_FEATURES.SCALABILITY_V2] },
});

group = await userAlice.chat.group.create(groupName, {