@wix/realtime 1.0.17 → 1.0.19

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.
@@ -1,3 +1,7 @@
1
1
  export * as site from '@wix/sdk_realtime_site';
2
2
  export * as publisher from './publisher/publisher.context.js';
3
3
  export * as subscriber from './subscriber/subscriber.context.js';
4
+ import type { Channel, Message, MessageHandler, Publisher, SubscriptionErrorHandler, SubscriptionHandler, SubscriptionOptions, UnsubscribeOptions } from './types.js';
5
+ import { RealtimeError, RealtimeErrorCode } from './types.js';
6
+ export type { Channel, Message, MessageHandler, Publisher, SubscriptionErrorHandler, SubscriptionHandler, SubscriptionOptions, UnsubscribeOptions, };
7
+ export { RealtimeError, RealtimeErrorCode };
@@ -33,7 +33,10 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.subscriber = exports.publisher = exports.site = void 0;
36
+ exports.RealtimeErrorCode = exports.RealtimeError = exports.subscriber = exports.publisher = exports.site = void 0;
37
37
  exports.site = __importStar(require("@wix/sdk_realtime_site"));
38
38
  exports.publisher = __importStar(require("./publisher/publisher.context.js"));
39
39
  exports.subscriber = __importStar(require("./subscriber/subscriber.context.js"));
40
+ const types_js_1 = require("./types.js");
41
+ Object.defineProperty(exports, "RealtimeError", { enumerable: true, get: function () { return types_js_1.RealtimeError; } });
42
+ Object.defineProperty(exports, "RealtimeErrorCode", { enumerable: true, get: function () { return types_js_1.RealtimeErrorCode; } });
@@ -12,6 +12,11 @@ import type { BuildRESTFunction, MaybeContext } from '@wix/sdk-types';
12
12
  * The client's own credentials (instanceId, metaSiteId) are used directly.
13
13
  * This ensures messages are scoped to the correct site.
14
14
  *
15
+ * **Contextual client (Wix-hosted) — elevation needed:**
16
+ * The contextual httpClient may not have sufficient permissions on its own.
17
+ * Wrap the call with `elevate()` to obtain the host's backend credentials.
18
+ *
19
+ * @example Manual client (self-hosted / explicit auth)
15
20
  * ```ts
16
21
  * import { publisher } from '@wix/realtime';
17
22
  * import { createClient, AppStrategy } from '@wix/sdk';
@@ -23,15 +28,15 @@ import type { BuildRESTFunction, MaybeContext } from '@wix/sdk-types';
23
28
  * await client.publisher.publish({ name: 'my-channel' }, { message: 'hello' });
24
29
  * ```
25
30
  *
26
- * **Contextual client (Wix-hosted) — elevation needed:**
27
- * The contextual httpClient may not have sufficient permissions on its own.
28
- * Wrap the call with `elevate()` to obtain the host's backend credentials.
29
- *
31
+ * @example Contextual client (Wix-hosted)
30
32
  * ```ts
31
33
  * import { publisher } from '@wix/realtime';
32
34
  * import { elevate } from '@wix/sdk/context';
33
35
  *
34
36
  * await elevate(publisher.publish)({ name: 'my-channel' }, { message: 'hello' });
35
37
  * ```
38
+ *
39
+ * @param channel - The channel, and optionally the resource, to publish to.
40
+ * @param payload - Message payload. Max: 10kb
36
41
  */
37
42
  export declare const publish: MaybeContext<BuildRESTFunction<typeof publicPublish> & typeof publicPublish>;
@@ -15,6 +15,11 @@ const rest_modules_1 = require("@wix/sdk-runtime/rest-modules");
15
15
  * The client's own credentials (instanceId, metaSiteId) are used directly.
16
16
  * This ensures messages are scoped to the correct site.
17
17
  *
18
+ * **Contextual client (Wix-hosted) — elevation needed:**
19
+ * The contextual httpClient may not have sufficient permissions on its own.
20
+ * Wrap the call with `elevate()` to obtain the host's backend credentials.
21
+ *
22
+ * @example Manual client (self-hosted / explicit auth)
18
23
  * ```ts
19
24
  * import { publisher } from '@wix/realtime';
20
25
  * import { createClient, AppStrategy } from '@wix/sdk';
@@ -26,15 +31,15 @@ const rest_modules_1 = require("@wix/sdk-runtime/rest-modules");
26
31
  * await client.publisher.publish({ name: 'my-channel' }, { message: 'hello' });
27
32
  * ```
28
33
  *
29
- * **Contextual client (Wix-hosted) — elevation needed:**
30
- * The contextual httpClient may not have sufficient permissions on its own.
31
- * Wrap the call with `elevate()` to obtain the host's backend credentials.
32
- *
34
+ * @example Contextual client (Wix-hosted)
33
35
  * ```ts
34
36
  * import { publisher } from '@wix/realtime';
35
37
  * import { elevate } from '@wix/sdk/context';
36
38
  *
37
39
  * await elevate(publisher.publish)({ name: 'my-channel' }, { message: 'hello' });
38
40
  * ```
41
+ *
42
+ * @param channel - The channel, and optionally the resource, to publish to.
43
+ * @param payload - Message payload. Max: 10kb
39
44
  */
40
45
  exports.publish = (0, rest_modules_1.createRESTModule)(publisher_public_js_1.publish);
@@ -1,4 +1,81 @@
1
1
  import { subscribe as publicSubscribe, unsubscribe as publicUnsubscribe } from './subscriber.public.js';
2
2
  import type { BuildRESTFunction, MaybeContext } from '@wix/sdk-types';
3
+ /**
4
+ * Subscribe to a channel. Returns a subscriptionId immediately; the
5
+ * actual connection is established asynchronously in the background. Use the
6
+ * optional `options` parameter to handle subscription lifecycle events.
7
+ *
8
+ * @example Manual client (self-hosted / explicit auth)
9
+ * ```ts
10
+ * import { subscriber } from '@wix/realtime';
11
+ * import { createClient, AppStrategy } from '@wix/sdk';
12
+ *
13
+ * const client = createClient({
14
+ * modules: { subscriber },
15
+ * auth: AppStrategy({ appId, appSecret, instanceId }),
16
+ * });
17
+ *
18
+ * const subscriptionId = client.subscriber.subscribe(
19
+ * { name: 'my-channel' },
20
+ * (message, channel) => {
21
+ * console.log('Received:', message.payload);
22
+ * },
23
+ * {
24
+ * onSubscribed: (id, isSynced) => console.log('Subscribed', id),
25
+ * onSubscriptionError: (error, id) => console.error('Error', error),
26
+ * },
27
+ * );
28
+ * ```
29
+ *
30
+ * @example Contextual client (Wix-hosted)
31
+ * ```ts
32
+ * import { subscriber } from '@wix/realtime';
33
+ *
34
+ * const subscriptionId = subscriber.subscribe(
35
+ * { name: 'my-channel' },
36
+ * (message, channel) => {
37
+ * console.log('Received:', message.payload);
38
+ * },
39
+ * );
40
+ * ```
41
+ *
42
+ * @param channel - The channel, and optionally the resource, to subscribe to.
43
+ * @param messageHandler - Callback invoked whenever a message is published to the channel.
44
+ * @param options - Optional lifecycle handlers for subscription events.
45
+ */
3
46
  export declare const subscribe: MaybeContext<BuildRESTFunction<typeof publicSubscribe> & typeof publicSubscribe>;
47
+ /**
48
+ * Unsubscribe from a subscription by its ID, by channel, or both.
49
+ *
50
+ * You can unsubscribe in three ways:
51
+ * - By `subscriptionId` — removes a single subscription.
52
+ * - By `channel` — removes all subscriptions to that channel.
53
+ * - By both — removes the specific subscription, verifying it matches the channel.
54
+ *
55
+ * @example Manual client (self-hosted / explicit auth)
56
+ * ```ts
57
+ * import { subscriber } from '@wix/realtime';
58
+ * import { createClient, AppStrategy } from '@wix/sdk';
59
+ *
60
+ * const client = createClient({
61
+ * modules: { subscriber },
62
+ * auth: AppStrategy({ appId, appSecret, instanceId }),
63
+ * });
64
+ *
65
+ * // Unsubscribe by subscription ID
66
+ * client.subscriber.unsubscribe({ subscriptionId });
67
+ *
68
+ * // Unsubscribe from all subscriptions to a channel
69
+ * client.subscriber.unsubscribe({ channel: { name: 'my-channel' } });
70
+ * ```
71
+ *
72
+ * @example Contextual client (Wix-hosted)
73
+ * ```ts
74
+ * import { subscriber } from '@wix/realtime';
75
+ *
76
+ * subscriber.unsubscribe({ subscriptionId });
77
+ * ```
78
+ *
79
+ * @param options - Identifies what to unsubscribe from — by subscription ID, channel, or both.
80
+ */
4
81
  export declare const unsubscribe: MaybeContext<BuildRESTFunction<typeof publicUnsubscribe> & typeof publicUnsubscribe>;
@@ -3,5 +3,82 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.unsubscribe = exports.subscribe = void 0;
4
4
  const subscriber_public_js_1 = require("./subscriber.public.js");
5
5
  const rest_modules_1 = require("@wix/sdk-runtime/rest-modules");
6
+ /**
7
+ * Subscribe to a channel. Returns a subscriptionId immediately; the
8
+ * actual connection is established asynchronously in the background. Use the
9
+ * optional `options` parameter to handle subscription lifecycle events.
10
+ *
11
+ * @example Manual client (self-hosted / explicit auth)
12
+ * ```ts
13
+ * import { subscriber } from '@wix/realtime';
14
+ * import { createClient, AppStrategy } from '@wix/sdk';
15
+ *
16
+ * const client = createClient({
17
+ * modules: { subscriber },
18
+ * auth: AppStrategy({ appId, appSecret, instanceId }),
19
+ * });
20
+ *
21
+ * const subscriptionId = client.subscriber.subscribe(
22
+ * { name: 'my-channel' },
23
+ * (message, channel) => {
24
+ * console.log('Received:', message.payload);
25
+ * },
26
+ * {
27
+ * onSubscribed: (id, isSynced) => console.log('Subscribed', id),
28
+ * onSubscriptionError: (error, id) => console.error('Error', error),
29
+ * },
30
+ * );
31
+ * ```
32
+ *
33
+ * @example Contextual client (Wix-hosted)
34
+ * ```ts
35
+ * import { subscriber } from '@wix/realtime';
36
+ *
37
+ * const subscriptionId = subscriber.subscribe(
38
+ * { name: 'my-channel' },
39
+ * (message, channel) => {
40
+ * console.log('Received:', message.payload);
41
+ * },
42
+ * );
43
+ * ```
44
+ *
45
+ * @param channel - The channel, and optionally the resource, to subscribe to.
46
+ * @param messageHandler - Callback invoked whenever a message is published to the channel.
47
+ * @param options - Optional lifecycle handlers for subscription events.
48
+ */
6
49
  exports.subscribe = (0, rest_modules_1.createRESTModule)(subscriber_public_js_1.subscribe);
50
+ /**
51
+ * Unsubscribe from a subscription by its ID, by channel, or both.
52
+ *
53
+ * You can unsubscribe in three ways:
54
+ * - By `subscriptionId` — removes a single subscription.
55
+ * - By `channel` — removes all subscriptions to that channel.
56
+ * - By both — removes the specific subscription, verifying it matches the channel.
57
+ *
58
+ * @example Manual client (self-hosted / explicit auth)
59
+ * ```ts
60
+ * import { subscriber } from '@wix/realtime';
61
+ * import { createClient, AppStrategy } from '@wix/sdk';
62
+ *
63
+ * const client = createClient({
64
+ * modules: { subscriber },
65
+ * auth: AppStrategy({ appId, appSecret, instanceId }),
66
+ * });
67
+ *
68
+ * // Unsubscribe by subscription ID
69
+ * client.subscriber.unsubscribe({ subscriptionId });
70
+ *
71
+ * // Unsubscribe from all subscriptions to a channel
72
+ * client.subscriber.unsubscribe({ channel: { name: 'my-channel' } });
73
+ * ```
74
+ *
75
+ * @example Contextual client (Wix-hosted)
76
+ * ```ts
77
+ * import { subscriber } from '@wix/realtime';
78
+ *
79
+ * subscriber.unsubscribe({ subscriptionId });
80
+ * ```
81
+ *
82
+ * @param options - Identifies what to unsubscribe from — by subscription ID, channel, or both.
83
+ */
7
84
  exports.unsubscribe = (0, rest_modules_1.createRESTModule)(subscriber_public_js_1.unsubscribe);
@@ -3,18 +3,10 @@ import type { HttpClient } from '@wix/sdk-types';
3
3
  interface SubscribeSignature {
4
4
  (channel: Channel, messageHandler: MessageHandler, options?: SubscriptionOptions): string;
5
5
  }
6
- /**
7
- * Subscribe to a channel. Returns a subscriptionId immediately; the
8
- * actual connection is established asynchronously in the background. Use the
9
- * optional `options` parameter to handle subscription lifecycle events.
10
- */
11
6
  export declare function subscribe(httpClient: HttpClient): SubscribeSignature;
12
7
  interface UnsubscribeSignature {
13
8
  (options: UnsubscribeOptions): void;
14
9
  }
15
- /**
16
- * Unsubscribe from a subscription by its ID, by channel, or both.
17
- */
18
10
  export declare function unsubscribe(_: HttpClient): UnsubscribeSignature;
19
11
  /** @internal Resets all module-level state. Only for use in tests. */
20
12
  export declare function _resetForTesting(): void;
@@ -11,11 +11,6 @@ const errors_js_1 = require("./errors.js");
11
11
  const subscription_manager_js_1 = require("./subscription-manager.js");
12
12
  const instanceConnections = new Map();
13
13
  const subscriptionManager = new subscription_manager_js_1.SubscriptionManager();
14
- /**
15
- * Subscribe to a channel. Returns a subscriptionId immediately; the
16
- * actual connection is established asynchronously in the background. Use the
17
- * optional `options` parameter to handle subscription lifecycle events.
18
- */
19
14
  function subscribe(httpClient) {
20
15
  return (channel, messageHandler, options) => {
21
16
  (0, errors_js_1.validateChannel)(channel);
@@ -31,9 +26,6 @@ function subscribe(httpClient) {
31
26
  return subscriptionId;
32
27
  };
33
28
  }
34
- /**
35
- * Unsubscribe from a subscription by its ID, by channel, or both.
36
- */
37
29
  function unsubscribe(_) {
38
30
  return ({ channel, subscriptionId }) => {
39
31
  if (!channel && !subscriptionId) {
@@ -1 +1 @@
1
- export { RealtimeErrorCode, RealtimeError, type Channel, type Publisher, type Message, type MessageHandler, type SubscriptionHandler, type SubscriptionErrorHandler, type SubscriptionOptions, } from '@wix/realtime-common/types';
1
+ export { RealtimeErrorCode, RealtimeError, type Channel, type Publisher, type Message, type MessageHandler, type SubscriptionHandler, type SubscriptionErrorHandler, type SubscriptionOptions, type UnsubscribeOptions, } from '@wix/realtime-common/types';