@wireapp/core 24.4.5 → 25.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,68 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [25.0.0](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@24.4.7...@wireapp/core@25.0.0) (2022-05-02)
7
+
8
+
9
+ ### Code Refactoring
10
+
11
+ * Cleanup storage initialization ([#4257](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/issues/4257)) ([cf952c5](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/commit/cf952c5522ccebe2c4e97d7dbb27de447a532032))
12
+
13
+
14
+ ### BREAKING CHANGES
15
+
16
+ * The way custom database are given to the `Account` has changed.
17
+ - The constructor signature now changes.
18
+ If you were doing
19
+
20
+ ```js
21
+ const account = new Account(apiClient, createStoreEngine);
22
+ ```
23
+
24
+ Now you need to do
25
+
26
+ ```js
27
+ const account = new Account(apiClient, {createStore: createStoreEngine});
28
+ ```
29
+
30
+ - The `login` and `init` function do not take a storage engine parameter anymore. You now need to give a `createStore` function to the constructor in order to give a custom storage engine to the core.
31
+
32
+ BEFORE
33
+
34
+ ```js
35
+ const account = new Accoun(apiClient);
36
+
37
+ account.login(data, initClient, clientInfo, database);
38
+ ```
39
+
40
+ AFTER
41
+
42
+ ```js
43
+ const account = new Accoun(apiClient, {createStore: () => database});
44
+
45
+ account.login(data, initClient, clientInfo);
46
+ ```
47
+
48
+
49
+
50
+
51
+
52
+ ## [24.4.7](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@24.4.6...@wireapp/core@24.4.7) (2022-04-21)
53
+
54
+ **Note:** Version bump only for package @wireapp/core
55
+
56
+
57
+
58
+
59
+
60
+ ## [24.4.6](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@24.4.5...@wireapp/core@24.4.6) (2022-04-20)
61
+
62
+ **Note:** Version bump only for package @wireapp/core
63
+
64
+
65
+
66
+
67
+
6
68
  ## [24.4.5](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@24.4.4...@wireapp/core@24.4.5) (2022-04-06)
7
69
 
8
70
  **Note:** Version bump only for package @wireapp/core
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "dependencies": {
6
6
  "@types/long": "4.0.1",
7
7
  "@types/node": "~14",
8
- "@wireapp/api-client": "18.8.2",
8
+ "@wireapp/api-client": "19.0.0",
9
9
  "@wireapp/cryptobox": "12.8.0",
10
10
  "bazinga64": "5.10.0",
11
11
  "hash.js": "1.1.7",
@@ -69,6 +69,6 @@
69
69
  "test:project": "yarn dist && yarn test",
70
70
  "test:node": "nyc jasmine --config=jasmine.json"
71
71
  },
72
- "version": "24.4.5",
73
- "gitHead": "db7082ca9eca742678c4ee8f3e03d94f0704ec42"
72
+ "version": "25.0.0",
73
+ "gitHead": "1312d666c6dbae992b9811bf672e3fed303c1e90"
74
74
  }
@@ -52,11 +52,11 @@ export interface Account {
52
52
  on(event: PayloadBundleType.UNKNOWN, listener: (payload: any) => void): this;
53
53
  on(event: TOPIC.ERROR, listener: (payload: CoreError) => void): this;
54
54
  }
55
- export declare type StoreEngineProvider = (storeName: string) => Promise<CRUDEngine>;
55
+ export declare type CreateStoreFn = (storeName: string, context: Context) => undefined | Promise<CRUDEngine | undefined>;
56
56
  export declare class Account extends EventEmitter {
57
57
  private readonly apiClient;
58
58
  private readonly logger;
59
- private readonly storeEngineProvider;
59
+ private readonly createStore;
60
60
  private storeEngine?;
61
61
  static readonly TOPIC: typeof TOPIC;
62
62
  service?: {
@@ -77,16 +77,18 @@ export declare class Account extends EventEmitter {
77
77
  backendFeatures: BackendFeatures;
78
78
  /**
79
79
  * @param apiClient The apiClient instance to use in the core (will create a new new one if undefined)
80
- * @param storeEngineProvider Used to store info in the database (will create a inMemory engine if undefined)
80
+ * @param storeEngineProvider Used to store info in the database (will create a inMemory engine if returns undefined)
81
81
  */
82
- constructor(apiClient?: APIClient, storeEngineProvider?: StoreEngineProvider);
82
+ constructor(apiClient?: APIClient, { createStore }?: {
83
+ createStore?: CreateStoreFn;
84
+ });
83
85
  private persistCookie;
84
86
  get clientId(): string;
85
87
  get userId(): string;
86
88
  register(registration: RegisterData, clientType: ClientType): Promise<Context>;
87
- init(clientType: ClientType, cookie?: Cookie, initializedStoreEngine?: CRUDEngine): Promise<Context>;
88
- initServices(storeEngine: CRUDEngine): Promise<void>;
89
- login(loginData: LoginData, initClient?: boolean, clientInfo?: ClientInfo, initializedStoreEngine?: CRUDEngine): Promise<Context>;
89
+ init(clientType: ClientType, cookie?: Cookie, initClient?: boolean): Promise<Context>;
90
+ initServices(context: Context): Promise<void>;
91
+ login(loginData: LoginData, initClient?: boolean, clientInfo?: ClientInfo): Promise<Context>;
90
92
  initClient(loginData: LoginData, clientInfo?: ClientInfo, entropyData?: Uint8Array): Promise<{
91
93
  isNewClient: boolean;
92
94
  localClient: RegisteredClient;
@@ -70,9 +70,9 @@ var TOPIC;
70
70
  class Account extends events_1.EventEmitter {
71
71
  /**
72
72
  * @param apiClient The apiClient instance to use in the core (will create a new new one if undefined)
73
- * @param storeEngineProvider Used to store info in the database (will create a inMemory engine if undefined)
73
+ * @param storeEngineProvider Used to store info in the database (will create a inMemory engine if returns undefined)
74
74
  */
75
- constructor(apiClient = new api_client_1.APIClient(), storeEngineProvider) {
75
+ constructor(apiClient = new api_client_1.APIClient(), { createStore = () => undefined } = {}) {
76
76
  super();
77
77
  this.handlePayload = async (payload) => {
78
78
  switch (payload.type) {
@@ -90,16 +90,7 @@ class Account extends events_1.EventEmitter {
90
90
  };
91
91
  this.apiClient = apiClient;
92
92
  this.backendFeatures = this.apiClient.backendFeatures;
93
- if (storeEngineProvider) {
94
- this.storeEngineProvider = storeEngineProvider;
95
- }
96
- else {
97
- this.storeEngineProvider = async (storeName) => {
98
- const engine = new store_engine_1.MemoryEngine();
99
- await engine.init(storeName);
100
- return engine;
101
- };
102
- }
93
+ this.createStore = createStore;
103
94
  apiClient.on(api_client_1.APIClient.TOPIC.COOKIE_REFRESH, async (cookie) => {
104
95
  if (cookie && this.storeEngine) {
105
96
  try {
@@ -127,35 +118,26 @@ class Account extends events_1.EventEmitter {
127
118
  }
128
119
  async register(registration, clientType) {
129
120
  const context = await this.apiClient.register(registration, clientType);
130
- const storeEngine = await this.initEngine(context);
131
- await this.initServices(storeEngine);
121
+ await this.initServices(context);
132
122
  return context;
133
123
  }
134
- async init(clientType, cookie, initializedStoreEngine) {
124
+ async init(clientType, cookie, initClient = true) {
135
125
  const context = await this.apiClient.init(clientType, cookie);
136
- if (initializedStoreEngine) {
137
- this.storeEngine = initializedStoreEngine;
138
- this.logger.log(`Initialized store with existing engine "${this.storeEngine.storeName}".`);
139
- }
140
- else {
141
- this.storeEngine = await this.initEngine(context);
142
- }
143
- await this.initServices(this.storeEngine);
144
- if (initializedStoreEngine) {
145
- await this.initClient({
146
- clientType,
147
- });
126
+ await this.initServices(context);
127
+ if (initClient) {
128
+ await this.initClient({ clientType });
148
129
  }
149
130
  return context;
150
131
  }
151
- async initServices(storeEngine) {
132
+ async initServices(context) {
133
+ this.storeEngine = await this.initEngine(context);
152
134
  const accountService = new account_1.AccountService(this.apiClient);
153
135
  const assetService = new conversation_1.AssetService(this.apiClient);
154
- const cryptographyService = new cryptography_1.CryptographyService(this.apiClient, storeEngine, {
136
+ const cryptographyService = new cryptography_1.CryptographyService(this.apiClient, this.storeEngine, {
155
137
  // We want to encrypt with fully qualified session ids, only if the backend is federated with other backends
156
138
  useQualifiedIds: this.backendFeatures.isFederated,
157
139
  });
158
- const clientService = new client_2.ClientService(this.apiClient, storeEngine, cryptographyService);
140
+ const clientService = new client_2.ClientService(this.apiClient, this.storeEngine, cryptographyService);
159
141
  const connectionService = new connection_1.ConnectionService(this.apiClient);
160
142
  const giphyService = new giphy_1.GiphyService(this.apiClient);
161
143
  const linkPreviewService = new linkPreview_1.LinkPreviewService(assetService);
@@ -163,7 +145,7 @@ class Account extends events_1.EventEmitter {
163
145
  // We can use qualified ids to send messages as long as the backend supports federated endpoints
164
146
  useQualifiedIds: this.backendFeatures.federationEndpoints,
165
147
  });
166
- const notificationService = new notification_1.NotificationService(this.apiClient, cryptographyService, storeEngine);
148
+ const notificationService = new notification_1.NotificationService(this.apiClient, cryptographyService, this.storeEngine);
167
149
  const selfService = new self_1.SelfService(this.apiClient);
168
150
  const teamService = new team_1.TeamService(this.apiClient);
169
151
  const broadcastService = new broadcast_1.BroadcastService(this.apiClient, cryptographyService);
@@ -184,18 +166,11 @@ class Account extends events_1.EventEmitter {
184
166
  user: userService,
185
167
  };
186
168
  }
187
- async login(loginData, initClient = true, clientInfo, initializedStoreEngine) {
169
+ async login(loginData, initClient = true, clientInfo) {
188
170
  this.resetContext();
189
171
  auth_2.LoginSanitizer.removeNonPrintableCharacters(loginData);
190
172
  const context = await this.apiClient.login(loginData);
191
- if (initializedStoreEngine) {
192
- this.storeEngine = initializedStoreEngine;
193
- this.logger.log(`Initialized store with existing engine "${this.storeEngine.storeName}".`);
194
- }
195
- else {
196
- this.storeEngine = await this.initEngine(context);
197
- }
198
- await this.initServices(this.storeEngine);
173
+ await this.initServices(context);
199
174
  if (initClient) {
200
175
  await this.initClient(loginData, clientInfo);
201
176
  }
@@ -291,12 +266,23 @@ class Account extends events_1.EventEmitter {
291
266
  const clientType = context.clientType === client_1.ClientType.NONE ? '' : `@${context.clientType}`;
292
267
  const dbName = `wire@${this.apiClient.config.urls.name}@${context.userId}${clientType}`;
293
268
  this.logger.log(`Initialising store with name "${dbName}"...`);
294
- this.storeEngine = await this.storeEngineProvider(dbName);
269
+ const openDb = async () => {
270
+ const initializedDb = await this.createStore(dbName, context);
271
+ if (initializedDb) {
272
+ this.logger.log(`Initialized store with existing engine "${dbName}".`);
273
+ return initializedDb;
274
+ }
275
+ this.logger.log(`Initialized store with new memory engine "${dbName}".`);
276
+ const memoryEngine = new store_engine_1.MemoryEngine();
277
+ await memoryEngine.init(dbName);
278
+ return memoryEngine;
279
+ };
280
+ const storeEngine = await openDb();
295
281
  const cookie = auth_1.CookieStore.getCookie();
296
282
  if (cookie) {
297
- await this.persistCookie(this.storeEngine, cookie);
283
+ await this.persistCookie(storeEngine, cookie);
298
284
  }
299
- return this.storeEngine;
285
+ return storeEngine;
300
286
  }
301
287
  }
302
288
  exports.Account = Account;