@stream-io/feeds-client 0.3.14 → 0.3.16

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/index.js +1 -1
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/react-bindings.js +12 -6
  5. package/dist/cjs/react-bindings.js.map +1 -1
  6. package/dist/es/index.mjs +2 -2
  7. package/dist/es/index.mjs.map +1 -1
  8. package/dist/es/react-bindings.mjs +12 -6
  9. package/dist/es/react-bindings.mjs.map +1 -1
  10. package/dist/{feeds-client-YbhVg6cF.js → feeds-client-B6L006tr.js} +42 -9
  11. package/dist/feeds-client-B6L006tr.js.map +1 -0
  12. package/dist/{feeds-client-DoDAKYaV.mjs → feeds-client-Bh01VLai.mjs} +42 -9
  13. package/dist/feeds-client-Bh01VLai.mjs.map +1 -0
  14. package/dist/types/bindings/react/hooks/feed-state-hooks/useOwnCapabilities.d.ts +1 -1
  15. package/dist/types/bindings/react/hooks/feed-state-hooks/useOwnCapabilities.d.ts.map +1 -1
  16. package/dist/types/bindings/react/hooks/useCreateFeedsClient.d.ts +3 -3
  17. package/dist/types/bindings/react/hooks/useCreateFeedsClient.d.ts.map +1 -1
  18. package/dist/types/common/ApiClient.d.ts.map +1 -1
  19. package/dist/types/common/ConnectionIdManager.d.ts +3 -3
  20. package/dist/types/common/ConnectionIdManager.d.ts.map +1 -1
  21. package/dist/types/common/TokenManager.d.ts +3 -3
  22. package/dist/types/common/TokenManager.d.ts.map +1 -1
  23. package/dist/types/feeds-client/feeds-client.d.ts +5 -1
  24. package/dist/types/feeds-client/feeds-client.d.ts.map +1 -1
  25. package/dist/types/gen/models/index.d.ts +2 -0
  26. package/dist/types/gen/models/index.d.ts.map +1 -1
  27. package/package.json +1 -1
  28. package/src/bindings/react/hooks/feed-state-hooks/useOwnCapabilities.ts +2 -2
  29. package/src/bindings/react/hooks/useCreateFeedsClient.ts +23 -12
  30. package/src/common/ApiClient.ts +4 -2
  31. package/src/common/ConnectionIdManager.ts +9 -7
  32. package/src/common/TokenManager.ts +19 -3
  33. package/src/common/real-time/StableWSConnection.ts +1 -1
  34. package/src/feeds-client/feeds-client.ts +22 -1
  35. package/src/gen/models/index.ts +4 -0
  36. package/dist/feeds-client-DoDAKYaV.mjs.map +0 -1
  37. package/dist/feeds-client-YbhVg6cF.js.map +0 -1
@@ -3235,8 +3235,15 @@ const capitalize = (s) => {
3235
3235
  };
3236
3236
  class TokenManager {
3237
3237
  constructor() {
3238
+ this._isAnonymous = false;
3238
3239
  this.logger = feedsLoggerSystem.getLogger("token-manager");
3239
3240
  this.setTokenOrProvider = (tokenOrProvider) => {
3241
+ if (tokenOrProvider === void 0) {
3242
+ this._isAnonymous = true;
3243
+ tokenOrProvider = "";
3244
+ } else {
3245
+ this._isAnonymous = false;
3246
+ }
3240
3247
  if (isFunction(tokenOrProvider)) {
3241
3248
  this.tokenProvider = tokenOrProvider;
3242
3249
  this.type = "provider";
@@ -3247,7 +3254,9 @@ class TokenManager {
3247
3254
  }
3248
3255
  };
3249
3256
  this.reset = () => {
3257
+ this._isAnonymous = false;
3250
3258
  this.token = void 0;
3259
+ this.tokenProvider = void 0;
3251
3260
  this.loadTokenPromise = null;
3252
3261
  };
3253
3262
  this.loadToken = () => {
@@ -3290,6 +3299,9 @@ class TokenManager {
3290
3299
  return this.loadTokenPromise;
3291
3300
  };
3292
3301
  this.getToken = () => {
3302
+ if (this._isAnonymous) {
3303
+ return "";
3304
+ }
3293
3305
  if (this.token) {
3294
3306
  return this.token;
3295
3307
  }
@@ -3306,6 +3318,9 @@ class TokenManager {
3306
3318
  this.loadTokenPromise = null;
3307
3319
  this.type = "static";
3308
3320
  }
3321
+ get isAnonymous() {
3322
+ return this._isAnonymous;
3323
+ }
3309
3324
  }
3310
3325
  class ConnectionIdManager {
3311
3326
  constructor() {
@@ -3317,10 +3332,12 @@ class ConnectionIdManager {
3317
3332
  };
3318
3333
  this.resetConnectionIdPromise = () => {
3319
3334
  this.connectionId = void 0;
3320
- this.loadConnectionIdPromise = new Promise((resolve, reject) => {
3321
- this.resolve = resolve;
3322
- this.reject = reject;
3323
- });
3335
+ this.loadConnectionIdPromise = new Promise(
3336
+ (resolve, reject) => {
3337
+ this.resolve = resolve;
3338
+ this.reject = reject;
3339
+ }
3340
+ );
3324
3341
  };
3325
3342
  this.resolveConnectionidPromise = (connectionId) => {
3326
3343
  this.connectionId = connectionId;
@@ -3422,7 +3439,7 @@ class StableWSConnection {
3422
3439
  return;
3423
3440
  }
3424
3441
  const token = await this.tokenManager.getToken();
3425
- if (!token) {
3442
+ if (!token && !this.tokenManager.isAnonymous) {
3426
3443
  logger.warn(`Token not set, can't connect authenticate`);
3427
3444
  return;
3428
3445
  }
@@ -3905,7 +3922,7 @@ const getRateLimitFromResponseHeader = (response_headers) => {
3905
3922
  };
3906
3923
  return result;
3907
3924
  };
3908
- const version = "0.3.14";
3925
+ const version = "0.3.16";
3909
3926
  class ApiClient {
3910
3927
  constructor(apiKey, tokenManager, connectionIdManager, options) {
3911
3928
  this.apiKey = apiKey;
@@ -3919,7 +3936,9 @@ class ApiClient {
3919
3936
  if (queryParams?.watch || queryParams?.presence || queryParams?.payload?.watch || queryParams?.payload?.presence || body?.watch || body?.presence) {
3920
3937
  this.logger.info("Getting connection_id for watch or presence request");
3921
3938
  const connectionId = await this.connectionIdManager.getConnectionId();
3922
- queryParams.connection_id = connectionId;
3939
+ if (connectionId) {
3940
+ queryParams.connection_id = connectionId;
3941
+ }
3923
3942
  }
3924
3943
  let requestUrl = url;
3925
3944
  if (pathParams) {
@@ -4067,7 +4086,7 @@ class ApiClient {
4067
4086
  }
4068
4087
  get commonHeaders() {
4069
4088
  return {
4070
- "stream-auth-type": "jwt",
4089
+ "stream-auth-type": this.tokenManager.isAnonymous ? "anonymous" : "jwt",
4071
4090
  "X-Stream-Client": this.generateStreamClientHeader()
4072
4091
  };
4073
4092
  }
@@ -7161,6 +7180,19 @@ class FeedsClient extends FeedsApi {
7161
7180
  }
7162
7181
  };
7163
7182
  this.pollFromState = (id) => this.polls_by_id.get(id);
7183
+ this.connectAnonymous = () => {
7184
+ this.connectionIdManager.resolveConnectionidPromise();
7185
+ this.tokenManager.setTokenOrProvider(void 0);
7186
+ this.setGetBatchOwnCapabilitiesThrottlingInterval(
7187
+ this.query_batch_own_capabilties_throttling_interval
7188
+ );
7189
+ this.state.partialNext({
7190
+ connected_user: void 0,
7191
+ is_anonymous: true,
7192
+ is_ws_connection_healthy: false
7193
+ });
7194
+ return Promise.resolve();
7195
+ };
7164
7196
  this.connectUser = async (user, tokenProvider) => {
7165
7197
  if (this.state.getLatestValue().connected_user !== void 0 || this.wsConnection) {
7166
7198
  throw new Error(`Can't connect a new user, call "disconnectUser" first`);
@@ -7395,6 +7427,7 @@ class FeedsClient extends FeedsApi {
7395
7427
  };
7396
7428
  this.state = new stateStore.StateStore({
7397
7429
  connected_user: void 0,
7430
+ is_anonymous: false,
7398
7431
  is_ws_connection_healthy: false,
7399
7432
  own_capabilities_by_fid: {}
7400
7433
  });
@@ -7716,4 +7749,4 @@ exports.replaceUniqueArrayMerge = replaceUniqueArrayMerge;
7716
7749
  exports.shouldUpdateState = shouldUpdateState;
7717
7750
  exports.uniqueArrayMerge = uniqueArrayMerge;
7718
7751
  exports.updateEntityInArray = updateEntityInArray;
7719
- //# sourceMappingURL=feeds-client-YbhVg6cF.js.map
7752
+ //# sourceMappingURL=feeds-client-B6L006tr.js.map