@wix/realtime 1.0.21 → 1.0.23

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.
@@ -0,0 +1 @@
1
+ export { resolveDuplexerChannelName } from '@wix/realtime-common';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveDuplexerChannelName = void 0;
4
+ var realtime_common_1 = require("@wix/realtime-common");
5
+ Object.defineProperty(exports, "resolveDuplexerChannelName", { enumerable: true, get: function () { return realtime_common_1.resolveDuplexerChannelName; } });
@@ -1,42 +1,9 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
3
  exports.publish = publish;
37
4
  const auto_sdk_duplexer_publisher_1 = require("@wix/auto_sdk_duplexer_publisher");
38
5
  const realtime_common_1 = require("@wix/realtime-common");
39
- const site = __importStar(require("@wix/sdk_realtime_site"));
6
+ const channel_utils_js_1 = require("../channel-utils.js");
40
7
  const errors_js_1 = require("../subscriber/errors.js");
41
8
  /**
42
9
  * Publish a message to a channel.
@@ -61,13 +28,12 @@ function publish(httpClient) {
61
28
  // For contextual usage (no explicit auth), the caller should wrap this
62
29
  // function with elevate() to obtain the host's backend credentials:
63
30
  // elevate(realtimePublisher.publish)(channel, payload)
64
- const boundPublish = auto_sdk_duplexer_publisher_1.publish(httpClient);
31
+ const boundPublish = (0, auto_sdk_duplexer_publisher_1.publish)(httpClient);
65
32
  return (channel, payload) => {
66
33
  (0, errors_js_1.validateChannel)(channel);
67
- if ((0, realtime_common_1.isVeloEnvironment)()) {
68
- return Promise.resolve(site.publish(channel, payload));
69
- }
70
- return boundPublish({ eventName: realtime_common_1.MESSAGE_EVENT_NAME, payload }, { channels: [channel.name], resourceId: channel.resourceId }).catch((error) => {
34
+ return (0, channel_utils_js_1.resolveDuplexerChannelName)(channel)
35
+ .then((channelName) => boundPublish({ eventName: realtime_common_1.MESSAGE_EVENT_NAME, payload }, { channels: [channelName], resourceId: channel.resourceId }))
36
+ .catch((error) => {
71
37
  throw new Error(`Failed to publish: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
72
38
  });
73
39
  };
@@ -6,6 +6,7 @@ exports._resetForTesting = _resetForTesting;
6
6
  const duplexer_js_1 = require("@wix/duplexer-js");
7
7
  const realtime_common_1 = require("@wix/realtime-common");
8
8
  const uuid_1 = require("uuid");
9
+ const channel_utils_js_1 = require("../channel-utils.js");
9
10
  const constants_js_1 = require("../constants.js");
10
11
  const errors_js_1 = require("./errors.js");
11
12
  const subscription_manager_js_1 = require("./subscription-manager.js");
@@ -135,7 +136,10 @@ function getOrCreateConnection(httpClient, appId, instanceId) {
135
136
  }
136
137
  async function setupSubscription(httpClient, subscriptionId, channel, messageHandler) {
137
138
  try {
138
- const { appId, instanceId } = await (0, realtime_common_1.getAppInfoFromAuthToken)(httpClient);
139
+ const [{ appId, instanceId }, duplexerChannelName] = await Promise.all([
140
+ (0, realtime_common_1.getAppInfoFromAuthToken)(httpClient),
141
+ (0, channel_utils_js_1.resolveDuplexerChannelName)(channel),
142
+ ]);
139
143
  const subscriptionEntry = subscriptionManager.get(subscriptionId);
140
144
  // Entry was already deleted (e.g., unsubscribe called during the await)
141
145
  // or explicitly cancelled — bail out.
@@ -163,7 +167,7 @@ async function setupSubscription(httpClient, subscriptionId, channel, messageHan
163
167
  // the duplexer to confirm, clean up the duplexer channel to avoid a
164
168
  // server-side subscription leak.
165
169
  if (!subscriptionManager.get(subscriptionId)) {
166
- socket.unsubscribe(channel.name, channel.resourceId);
170
+ socket.unsubscribe(duplexerChannelName, channel.resourceId);
167
171
  cleanupConnectionIfIdle(instanceId);
168
172
  return;
169
173
  }
@@ -212,7 +216,7 @@ async function setupSubscription(httpClient, subscriptionId, channel, messageHan
212
216
  }
213
217
  // Subscribe to the duplexer channel and register lifecycle listeners
214
218
  // in the same synchronous block so no events can be missed.
215
- const subscribedChannel = socket.subscribe(channel.name, {
219
+ const subscribedChannel = socket.subscribe(duplexerChannelName, {
216
220
  resourceId: channel.resourceId,
217
221
  });
218
222
  subscribedChannel.once(realtime_common_1.DUPLEXER_EVENTS.subscriptionSucceeded, onSubscribeSucceeded);
@@ -797,6 +797,33 @@
797
797
  "kind": "text",
798
798
  "text": "."
799
799
  }
800
+ ],
801
+ "blockTags": [
802
+ {
803
+ "tag": "@deprecated",
804
+ "content": [
805
+ {
806
+ "kind": "text",
807
+ "text": "Use "
808
+ },
809
+ {
810
+ "kind": "code",
811
+ "text": "`publisher.publish`"
812
+ },
813
+ {
814
+ "kind": "text",
815
+ "text": " from "
816
+ },
817
+ {
818
+ "kind": "code",
819
+ "text": "`@wix/realtime`"
820
+ },
821
+ {
822
+ "kind": "text",
823
+ "text": " instead."
824
+ }
825
+ ]
826
+ }
800
827
  ]
801
828
  },
802
829
  "parameters": [
@@ -859,37 +886,28 @@
859
886
  "type": {
860
887
  "type": "reference",
861
888
  "target": {
862
- "sourceFileName": "../realtime-common/cjs/build/types.d.ts",
889
+ "sourceFileName": "../site/cjs/build/publisher.d.ts",
863
890
  "qualifiedName": "PublishOptions"
864
891
  },
865
892
  "name": "PublishOptions",
866
- "package": "@wix/realtime-common"
893
+ "package": "@wix/sdk_realtime_site"
867
894
  }
868
895
  }
869
896
  ],
870
897
  "type": {
871
- "type": "union",
872
- "types": [
898
+ "type": "reference",
899
+ "target": {
900
+ "sourceFileName": "../../node_modules/typescript/lib/lib.es5.d.ts",
901
+ "qualifiedName": "Promise"
902
+ },
903
+ "typeArguments": [
873
904
  {
874
905
  "type": "intrinsic",
875
906
  "name": "void"
876
- },
877
- {
878
- "type": "reference",
879
- "target": {
880
- "sourceFileName": "../../node_modules/typescript/lib/lib.es5.d.ts",
881
- "qualifiedName": "Promise"
882
- },
883
- "typeArguments": [
884
- {
885
- "type": "intrinsic",
886
- "name": "void"
887
- }
888
- ],
889
- "name": "Promise",
890
- "package": "typescript"
891
907
  }
892
- ]
908
+ ],
909
+ "name": "Promise",
910
+ "package": "typescript"
893
911
  }
894
912
  }
895
913
  ]
@@ -0,0 +1 @@
1
+ export { resolveDuplexerChannelName } from '@wix/realtime-common';
@@ -0,0 +1 @@
1
+ export { resolveDuplexerChannelName } from '@wix/realtime-common';
@@ -1,6 +1,6 @@
1
- import { publish as autoSdkPublish } from '@wix/auto_sdk_duplexer_publisher';
2
- import { isVeloEnvironment, MESSAGE_EVENT_NAME } from '@wix/realtime-common';
3
- import * as site from '@wix/sdk_realtime_site';
1
+ import { publish as autoSdkPublish, } from '@wix/auto_sdk_duplexer_publisher';
2
+ import { MESSAGE_EVENT_NAME } from '@wix/realtime-common';
3
+ import { resolveDuplexerChannelName } from '../channel-utils.js';
4
4
  import { validateChannel } from '../subscriber/errors.js';
5
5
  /**
6
6
  * Publish a message to a channel.
@@ -28,10 +28,9 @@ export function publish(httpClient) {
28
28
  const boundPublish = autoSdkPublish(httpClient);
29
29
  return (channel, payload) => {
30
30
  validateChannel(channel);
31
- if (isVeloEnvironment()) {
32
- return Promise.resolve(site.publish(channel, payload));
33
- }
34
- return boundPublish({ eventName: MESSAGE_EVENT_NAME, payload }, { channels: [channel.name], resourceId: channel.resourceId }).catch((error) => {
31
+ return resolveDuplexerChannelName(channel)
32
+ .then((channelName) => boundPublish({ eventName: MESSAGE_EVENT_NAME, payload }, { channels: [channelName], resourceId: channel.resourceId }))
33
+ .catch((error) => {
35
34
  throw new Error(`Failed to publish: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
36
35
  });
37
36
  };
@@ -1,6 +1,7 @@
1
1
  import { Duplexer } from '@wix/duplexer-js';
2
2
  import { DUPLEXER_EVENTS, MESSAGE_EVENT_NAME, getAppInfoFromAuthToken, tokenToAppInfoCache, getAuthToken, } from '@wix/realtime-common';
3
3
  import { v4 as uuidv4 } from 'uuid';
4
+ import { resolveDuplexerChannelName } from '../channel-utils.js';
4
5
  import { DUPLEXER_HOST_URL } from '../constants.js';
5
6
  import { missingChannelOrSubscriptionId, channelMismatch, disconnectedError, connectError, subscribeFailed, resubscribeFailed, subscribeError, validateChannel, } from './errors.js';
6
7
  import { SubscriptionManager } from './subscription-manager.js';
@@ -130,7 +131,10 @@ function getOrCreateConnection(httpClient, appId, instanceId) {
130
131
  }
131
132
  async function setupSubscription(httpClient, subscriptionId, channel, messageHandler) {
132
133
  try {
133
- const { appId, instanceId } = await getAppInfoFromAuthToken(httpClient);
134
+ const [{ appId, instanceId }, duplexerChannelName] = await Promise.all([
135
+ getAppInfoFromAuthToken(httpClient),
136
+ resolveDuplexerChannelName(channel),
137
+ ]);
134
138
  const subscriptionEntry = subscriptionManager.get(subscriptionId);
135
139
  // Entry was already deleted (e.g., unsubscribe called during the await)
136
140
  // or explicitly cancelled — bail out.
@@ -158,7 +162,7 @@ async function setupSubscription(httpClient, subscriptionId, channel, messageHan
158
162
  // the duplexer to confirm, clean up the duplexer channel to avoid a
159
163
  // server-side subscription leak.
160
164
  if (!subscriptionManager.get(subscriptionId)) {
161
- socket.unsubscribe(channel.name, channel.resourceId);
165
+ socket.unsubscribe(duplexerChannelName, channel.resourceId);
162
166
  cleanupConnectionIfIdle(instanceId);
163
167
  return;
164
168
  }
@@ -207,7 +211,7 @@ async function setupSubscription(httpClient, subscriptionId, channel, messageHan
207
211
  }
208
212
  // Subscribe to the duplexer channel and register lifecycle listeners
209
213
  // in the same synchronous block so no events can be missed.
210
- const subscribedChannel = socket.subscribe(channel.name, {
214
+ const subscribedChannel = socket.subscribe(duplexerChannelName, {
211
215
  resourceId: channel.resourceId,
212
216
  });
213
217
  subscribedChannel.once(DUPLEXER_EVENTS.subscriptionSucceeded, onSubscribeSucceeded);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/realtime",
3
- "version": "1.0.21",
3
+ "version": "1.0.23",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"
@@ -37,11 +37,11 @@
37
37
  "dependencies": {
38
38
  "@wix/auto_sdk_duplexer_publisher": "^1.0.10",
39
39
  "@wix/duplexer-js": "^2.0.6",
40
- "@wix/realtime-common": "1.0.2",
40
+ "@wix/realtime-common": "1.0.4",
41
41
  "@wix/sdk": "^1.21.4",
42
42
  "@wix/sdk-runtime": "^1.0.9",
43
43
  "@wix/sdk-types": "^1.17.5",
44
- "@wix/sdk_realtime_site": "1.0.18",
44
+ "@wix/sdk_realtime_site": "1.0.20",
45
45
  "uuid": "^11.1.0"
46
46
  },
47
47
  "devDependencies": {
@@ -65,5 +65,5 @@
65
65
  "isRootPublicSdk": true
66
66
  }
67
67
  },
68
- "falconPackageHash": "facecfa825a0ea1d9f981570bd0d3d99ca6fd995f5e5ec3f635260eb"
68
+ "falconPackageHash": "b0703d550c42219421881692c225661586900d2ab35c82a9b2cbd0bf"
69
69
  }