@msssystems/mss-link-sdk 0.2.5 → 0.2.6

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.
@@ -13,7 +13,7 @@ export class BrowserMssLinkClient extends MssLinkClient {
13
13
  this.cryptoEngine = new WasmCryptoEngine({
14
14
  userId: options.userId,
15
15
  apiBaseUrl: options.baseUrl,
16
- accessToken: typeof options.token === 'string' ? options.token : undefined,
16
+ accessToken: options.token,
17
17
  deviceId: options.deviceId,
18
18
  registrationId: options.registrationId,
19
19
  signedPrekeyId: options.signedPrekeyId,
@@ -3,7 +3,7 @@ import type { MssCryptoWasmModule, WasmMssClientInstance } from '../client/wasm-
3
3
  export interface WasmCryptoEngineOptions {
4
4
  userId: string;
5
5
  apiBaseUrl: string;
6
- accessToken?: string | undefined;
6
+ accessToken?: string | (() => string | Promise<string>) | undefined;
7
7
  deviceId?: number | undefined;
8
8
  registrationId?: number | undefined;
9
9
  signedPrekeyId?: number | undefined;
@@ -25,7 +25,7 @@ export declare class WasmCryptoEngine {
25
25
  private wasmModulePromise;
26
26
  private accessToken;
27
27
  constructor(options: WasmCryptoEngineOptions);
28
- setAccessToken(accessToken: string | null): void;
28
+ setAccessToken(accessToken: string | (() => string | Promise<string>) | null): void;
29
29
  getLocalCryptoHealth(): Promise<import("./local-crypto-health.contracts").LocalCryptoHealth>;
30
30
  ensureReady(): Promise<void>;
31
31
  reset(): void;
@@ -36,7 +36,14 @@ export class WasmCryptoEngine {
36
36
  }
37
37
  setAccessToken(accessToken) {
38
38
  this.accessToken = accessToken;
39
- this.wasmClient?.setAccessToken(accessToken);
39
+ if (typeof accessToken === 'string' || accessToken === null) {
40
+ this.wasmClient?.setAccessToken(accessToken);
41
+ }
42
+ else if (this.wasmClient) {
43
+ Promise.resolve(accessToken()).then((tokenStr) => {
44
+ this.wasmClient?.setAccessToken(tokenStr);
45
+ }).catch(() => { });
46
+ }
40
47
  }
41
48
  async getLocalCryptoHealth() {
42
49
  const { checkLocalCryptoHealth } = await import('./local-crypto-health');
@@ -68,8 +75,9 @@ export class WasmCryptoEngine {
68
75
  if (!this.wasmClient) {
69
76
  const sdkModule = await this.loadWasmModule();
70
77
  this.wasmClient = new sdkModule.WasmMssClient(this.userId, this.deviceId, this.apiBaseUrl);
71
- this.wasmClient.setAccessToken(this.accessToken);
72
78
  }
79
+ const tokenStr = typeof this.accessToken === 'function' ? await this.accessToken() : this.accessToken;
80
+ this.wasmClient.setAccessToken(tokenStr);
73
81
  return this.wasmClient;
74
82
  }
75
83
  loadWasmModule() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@msssystems/mss-link-sdk",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "Official managed application SDK for MSS ecosystem",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",