Skip to content

Commit d0b0b62

Browse files
committed
fix: initialize method change
1 parent 2dd6284 commit d0b0b62

File tree

7 files changed

+48
-38
lines changed

7 files changed

+48
-38
lines changed

packages/restapi/src/lib/constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ export enum MessageType {
4343
PAYMENT = 'Payment',
4444
}
4545

46+
export const ALPHA_FEATURES = {
47+
GROUP_SCALABILITY: 'GROUP_SCALABILITY',
48+
};
49+
4650
const Constants = {
4751
ENV,
4852
ENCRYPTION_TYPE,
@@ -60,6 +64,7 @@ const Constants = {
6064
ENC_TYPE_V2: 'aes256GcmHkdfSha256',
6165
ENC_TYPE_V3: 'eip191-aes256-gcm-hkdf-sha256',
6266
ENC_TYPE_V4: 'pgpv1:nft',
67+
ALPHA_FEATURES,
6368
};
6469

6570
export default Constants;

packages/restapi/src/lib/pushapi/PushAPI.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Constants, { ENV } from '../constants';
22
import { SignerType, ProgressHookType } from '../types';
3-
import { FeatureTag, PushAPIInitializeProps } from './pushAPITypes';
3+
import { PushAPIInitializeProps } from './pushAPITypes';
44
import * as PUSH_USER from '../user';
55
import * as PUSH_CHAT from '../chat';
66
import { getAccountAddress, getWallet } from '../chat/helpers';
@@ -19,7 +19,7 @@ import {
1919
export class PushAPI {
2020
private signer?: SignerType;
2121
private readMode: boolean;
22-
private featureTag: FeatureTag;
22+
private alpha: { feature: string[] };
2323
private account: string;
2424
private decryptedPgpPvtKey?: string;
2525
private pgpPublicKey?: string;
@@ -39,15 +39,15 @@ export class PushAPI {
3939
env: ENV,
4040
account: string,
4141
readMode: boolean,
42-
featureTag: FeatureTag,
42+
alpha: { feature: string[] },
4343
decryptedPgpPvtKey?: string,
4444
pgpPublicKey?: string,
4545
signer?: SignerType,
4646
progressHook?: (progress: ProgressHookType) => void
4747
) {
4848
this.signer = signer;
4949
this.readMode = readMode;
50-
this.featureTag = featureTag;
50+
this.alpha = alpha;
5151
this.env = env;
5252
this.account = account;
5353
this.decryptedPgpPvtKey = decryptedPgpPvtKey;
@@ -60,7 +60,7 @@ export class PushAPI {
6060
this.chat = new Chat(
6161
this.account,
6262
this.env,
63-
this.featureTag,
63+
this.alpha,
6464
this.decryptedPgpPvtKey,
6565
this.signer,
6666
this.progressHook
@@ -134,7 +134,10 @@ export class PushAPI {
134134
options?.autoUpgrade !== undefined
135135
? options?.autoUpgrade
136136
: defaultOptions.autoUpgrade,
137-
featureTag: options?.featureTag || 'STABLE',
137+
alpha:
138+
options?.alpha && options.alpha.feature
139+
? options.alpha
140+
: { feature: [] },
138141
};
139142

140143
const readMode = !signer;
@@ -202,7 +205,7 @@ export class PushAPI {
202205
settings.env as ENV,
203206
derivedAccount,
204207
readMode,
205-
settings.featureTag,
208+
settings.alpha,
206209
decryptedPGPPrivateKey,
207210
pgpPublicKey,
208211
signer,

packages/restapi/src/lib/pushapi/chat.ts

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ENV, MessageType } from '../constants';
1+
import { ENV, MessageType, ALPHA_FEATURES } from '../constants';
22
import {
33
ChatSendOptionsType,
44
GroupAccess,
@@ -21,7 +21,6 @@ import {
2121
ManageGroupOptions,
2222
RemoveFromGroupOptions,
2323
GetGroupParticipantsOptions,
24-
FeatureTag,
2524
} from './pushAPITypes';
2625
import * as PUSH_USER from '../user';
2726
import * as PUSH_CHAT from '../chat';
@@ -36,16 +35,22 @@ import { updateGroupConfig } from '../chat/updateGroupConfig';
3635
import { PushAPI } from './PushAPI';
3736
export class Chat {
3837
private userInstance: User;
38+
private groupScalabilityTag: 'ALPHA' | 'STABLE';
3939

4040
constructor(
4141
private account: string,
4242
private env: ENV,
43-
private featureTag: FeatureTag,
43+
private alpha: { feature: string[] },
4444
private decryptedPgpPvtKey?: string,
4545
private signer?: SignerType,
4646
private progressHook?: (progress: ProgressHookType) => void
4747
) {
4848
this.userInstance = new User(this.account, this.env);
49+
this.groupScalabilityTag = this.alpha.feature.includes(
50+
ALPHA_FEATURES.GROUP_SCALABILITY
51+
)
52+
? 'ALPHA'
53+
: 'STABLE';
4954
}
5055

5156
async list(
@@ -165,7 +170,7 @@ export class Chat {
165170
account: this.account,
166171
signer: this.signer,
167172
pgpPrivateKey: this.decryptedPgpPvtKey,
168-
overrideSecretKeyGeneration: this.featureTag !== 'ALPHA',
173+
overrideSecretKeyGeneration: this.groupScalabilityTag !== 'ALPHA',
169174
});
170175
}
171176

@@ -299,8 +304,7 @@ export class Chat {
299304
admins: options?.admins ? options.admins : [],
300305
};
301306
const response = await PUSH_CHAT.createGroupV2(groupParams);
302-
303-
switch (this.featureTag) {
307+
switch (this.groupScalabilityTag) {
304308
case 'ALPHA':
305309
return response;
306310
case 'STABLE':
@@ -340,7 +344,7 @@ export class Chat {
340344
},
341345

342346
info: async (chatId: string): Promise<GroupDTO | GroupInfoDTO> => {
343-
switch (this.featureTag) {
347+
switch (this.groupScalabilityTag) {
344348
case 'ALPHA':
345349
return await PUSH_CHAT.getGroupInfo({
346350
chatId: chatId,
@@ -396,7 +400,7 @@ export class Chat {
396400
await updateGroupProfile(updateGroupProfileOptions);
397401
const response = await updateGroupConfig(updateGroupConfigOptions);
398402

399-
switch (this.featureTag) {
403+
switch (this.groupScalabilityTag) {
400404
case 'ALPHA':
401405
return response;
402406
case 'STABLE':
@@ -440,7 +444,7 @@ export class Chat {
440444
account: this.account,
441445
signer: this.signer,
442446
pgpPrivateKey: this.decryptedPgpPvtKey,
443-
overrideSecretKeyGeneration: this.featureTag !== 'ALPHA',
447+
overrideSecretKeyGeneration: this.groupScalabilityTag !== 'ALPHA',
444448
});
445449
} else {
446450
response = await PUSH_CHAT.addMembers({
@@ -450,11 +454,11 @@ export class Chat {
450454
account: this.account,
451455
signer: this.signer,
452456
pgpPrivateKey: this.decryptedPgpPvtKey,
453-
overrideSecretKeyGeneration: this.featureTag !== 'ALPHA',
457+
overrideSecretKeyGeneration: this.groupScalabilityTag !== 'ALPHA',
454458
});
455459
}
456460

457-
switch (this.featureTag) {
461+
switch (this.groupScalabilityTag) {
458462
case 'ALPHA':
459463
return response;
460464
case 'STABLE':
@@ -509,7 +513,7 @@ export class Chat {
509513
account: this.account,
510514
signer: this.signer,
511515
pgpPrivateKey: this.decryptedPgpPvtKey,
512-
overrideSecretKeyGeneration: this.featureTag !== 'ALPHA',
516+
overrideSecretKeyGeneration: this.groupScalabilityTag !== 'ALPHA',
513517
});
514518
}
515519

@@ -521,10 +525,10 @@ export class Chat {
521525
account: this.account,
522526
signer: this.signer,
523527
pgpPrivateKey: this.decryptedPgpPvtKey,
524-
overrideSecretKeyGeneration: this.featureTag !== 'ALPHA',
528+
overrideSecretKeyGeneration: this.groupScalabilityTag !== 'ALPHA',
525529
});
526530
}
527-
switch (this.featureTag) {
531+
switch (this.groupScalabilityTag) {
528532
case 'ALPHA':
529533
return await PUSH_CHAT.getGroupInfo({
530534
chatId: chatId,
@@ -566,7 +570,7 @@ export class Chat {
566570
account: this.account,
567571
signer: this.signer,
568572
pgpPrivateKey: this.decryptedPgpPvtKey,
569-
overrideSecretKeyGeneration: this.featureTag !== 'ALPHA',
573+
overrideSecretKeyGeneration: this.groupScalabilityTag !== 'ALPHA',
570574
});
571575
},
572576

@@ -587,7 +591,7 @@ export class Chat {
587591
account: this.account,
588592
signer: this.signer,
589593
pgpPrivateKey: this.decryptedPgpPvtKey,
590-
overrideSecretKeyGeneration: this.featureTag !== 'ALPHA',
594+
overrideSecretKeyGeneration: this.groupScalabilityTag !== 'ALPHA',
591595
});
592596
} else if (!status.isMember) {
593597
await PUSH_CHAT.addMembers({
@@ -597,10 +601,10 @@ export class Chat {
597601
account: this.account,
598602
signer: this.signer,
599603
pgpPrivateKey: this.decryptedPgpPvtKey,
600-
overrideSecretKeyGeneration: this.featureTag !== 'ALPHA',
604+
overrideSecretKeyGeneration: this.groupScalabilityTag !== 'ALPHA',
601605
});
602606
}
603-
switch (this.featureTag) {
607+
switch (this.groupScalabilityTag) {
604608
case 'ALPHA':
605609
return await PUSH_CHAT.getGroupInfo({
606610
chatId: target,
@@ -635,7 +639,7 @@ export class Chat {
635639
account: this.account,
636640
signer: this.signer,
637641
pgpPrivateKey: this.decryptedPgpPvtKey,
638-
overrideSecretKeyGeneration: this.featureTag !== 'ALPHA',
642+
overrideSecretKeyGeneration: this.groupScalabilityTag !== 'ALPHA',
639643
});
640644
} else {
641645
response = await PUSH_CHAT.removeMembers({
@@ -645,11 +649,11 @@ export class Chat {
645649
account: this.account,
646650
signer: this.signer,
647651
pgpPrivateKey: this.decryptedPgpPvtKey,
648-
overrideSecretKeyGeneration: this.featureTag !== 'ALPHA',
652+
overrideSecretKeyGeneration: this.groupScalabilityTag !== 'ALPHA',
649653
});
650654
}
651655

652-
switch (this.featureTag) {
656+
switch (this.groupScalabilityTag) {
653657
case 'ALPHA':
654658
return response;
655659
case 'STABLE':

packages/restapi/src/lib/pushapi/pushAPITypes.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export enum ChatListType {
55
CHATS = 'CHATS',
66
REQUESTS = 'REQUESTS',
77
}
8-
export type FeatureTag = 'ALPHA' | 'STABLE';
98
export interface PushAPIInitializeProps {
109
env?: ENV;
1110
progressHook?: (progress: ProgressHookType) => void;
@@ -14,7 +13,9 @@ export interface PushAPIInitializeProps {
1413
versionMeta?: { NFTPGP_V1?: { password: string } };
1514
autoUpgrade?: boolean;
1615
origin?: string;
17-
featureTag?: FeatureTag;
16+
alpha?: {
17+
feature: string[];
18+
};
1819
}
1920

2021
export interface GroupCreationOptions {

packages/restapi/src/lib/pushstream/PushStream.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class PushStream extends EventEmitter {
4242
this.chatInstance = new Chat(
4343
this.account,
4444
this.options.env as ENV,
45-
this.options.featureTag,
45+
{ feature: [] },
4646
this.decryptedPgpPvtKey,
4747
this.signer,
4848
this.progressHook
@@ -65,7 +65,6 @@ export class PushStream extends EventEmitter {
6565
retries: 3,
6666
},
6767
env: env,
68-
featureTag: 'STABLE',
6968
};
7069

7170
if (!listen || listen.length === 0) {

packages/restapi/src/lib/pushstream/pushStreamTypes.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Rules } from '../types';
2-
import Constants, { ENV } from '../constants';
3-
import { FeatureTag } from '../pushapi/pushAPITypes';
2+
import { ENV } from '../constants';
43

54
export type PushStreamInitializeProps = {
65
filter?: {
@@ -14,7 +13,6 @@ export type PushStreamInitializeProps = {
1413
raw?: boolean;
1514
env?: ENV;
1615
overrideAccount?: string;
17-
featureTag: FeatureTag;
1816
};
1917

2018
export enum STREAM {

packages/restapi/tests/lib/chat/privateGroup.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,23 @@ describe('Private Groups', () => {
4040
account1 = `eip155:${signer1.address}`;
4141
userAlice = await PushAPI.initialize(signer1, {
4242
env: _env,
43-
featureTag: 'ALPHA',
43+
alpha: { feature: [Constants.ALPHA_FEATURES.GROUP_SCALABILITY] },
4444
});
4545

4646
const WALLET2 = ethers.Wallet.createRandom();
4747
const signer2 = new ethers.Wallet(WALLET2.privateKey);
4848
account2 = `eip155:${signer2.address}`;
4949
userBob = await PushAPI.initialize(signer2, {
5050
env: _env,
51-
featureTag: 'ALPHA',
51+
alpha: { feature: [Constants.ALPHA_FEATURES.GROUP_SCALABILITY] },
5252
});
5353

5454
const WALLET3 = ethers.Wallet.createRandom();
5555
const signer3 = new ethers.Wallet(WALLET3.privateKey);
5656
account3 = `eip155:${signer3.address}`;
5757
userJohn = await PushAPI.initialize(signer3, {
5858
env: _env,
59-
featureTag: 'ALPHA',
59+
alpha: { feature: [Constants.ALPHA_FEATURES.GROUP_SCALABILITY] },
6060
});
6161

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

0 commit comments

Comments
 (0)