@wix/realtime 1.0.33 → 1.0.35

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,32 +1,41 @@
1
1
  import { publish as publicPublish } from './publisher.public.js';
2
2
  import type { BuildRESTFunction, MaybeContext } from '@wix/sdk-types';
3
3
  /**
4
- * Publishes a message to a realtime channel.
4
+ * Publishes a message to a channel or resource.
5
5
  *
6
- * Requires a service identity (server-side only). The caller must have
7
- * app-level permissions to publish messages.
6
+ * The method publishes a message to all subscriptions on the specified channel or resource. Channels and resources are isolated, so subscribers to a channel don't receive messages published to a resource. Similarly, subscribers to a resource don't receive messages published to the parent channel.
8
7
  *
9
- * @example Manual client (self-hosted / explicit auth)
8
+ * > **Authentication**
9
+ * >
10
+ * > This method may require higher-level permissions than the caller has, based on their [identity](https://dev.wix.com/docs/api-reference/articles/authentication/about-identities) and [roles and permissions](https://support.wix.com/en/article/roles-permissions-overview). In these cases, you can ensure the method is called with the required level of authorization by using [elevated permissions](https://dev.wix.com/docs/api-reference/articles/authentication/about-elevated-permissions).
11
+ *
12
+ * <!-- TODO: Check whether this API is relevant for headless projects. -->
13
+ *
14
+ * @example Publish a message to the specified channel
10
15
  * ```ts
11
16
  * import { publisher } from '@wix/realtime';
12
- * import { createClient, AppStrategy } from '@wix/sdk';
17
+ * import { elevate } from '@wix/sdk/context';
13
18
  *
14
- * const client = createClient({
15
- * modules: { publisher },
16
- * auth: AppStrategy({ appId, appSecret, instanceId }),
17
- * });
18
- * await client.publisher.publish({ name: 'my-channel' }, { message: 'hello' });
19
+ * await elevate(publisher.publish)({ name: 'my-channel' }, { message: 'hello' });
19
20
  * ```
20
21
  *
21
- * @example Contextual client (Wix-hosted)
22
+ * @example Publish a message to the specified channel: Self-hosted
22
23
  * ```ts
23
24
  * import { publisher } from '@wix/realtime';
24
- * import { elevate } from '@wix/sdk/context';
25
+ * import { createClient } from '@wix/sdk';
25
26
  *
26
- * await elevate(publisher.publish)({ name: 'my-channel' }, { message: 'hello' });
27
+ * // Import the auth strategy for the relevant access type
28
+ * // Import the relevant host module if needed
29
+ *
30
+ * const client = createClient({
31
+ * modules: { publisher },
32
+ * // Include the auth strategy and host as relevant
33
+ * });
34
+ *
35
+ * await client.publisher.publish({ name: 'my-channel' }, { message: 'hello' });
27
36
  * ```
28
37
  *
29
- * @param channel - The channel, and optionally the resource, to publish to.
30
- * @param payload - Message payload. Max: 10kb
38
+ * @param channel - Channel or resource to publish to.
39
+ * @param payload - Message payload. Max: 10 KB.
31
40
  */
32
41
  export declare const publish: MaybeContext<BuildRESTFunction<typeof publicPublish> & typeof publicPublish>;
@@ -4,32 +4,41 @@ exports.publish = void 0;
4
4
  const publisher_public_js_1 = require("./publisher.public.js");
5
5
  const rest_modules_1 = require("@wix/sdk-runtime/rest-modules");
6
6
  /**
7
- * Publishes a message to a realtime channel.
7
+ * Publishes a message to a channel or resource.
8
8
  *
9
- * Requires a service identity (server-side only). The caller must have
10
- * app-level permissions to publish messages.
9
+ * The method publishes a message to all subscriptions on the specified channel or resource. Channels and resources are isolated, so subscribers to a channel don't receive messages published to a resource. Similarly, subscribers to a resource don't receive messages published to the parent channel.
11
10
  *
12
- * @example Manual client (self-hosted / explicit auth)
11
+ * > **Authentication**
12
+ * >
13
+ * > This method may require higher-level permissions than the caller has, based on their [identity](https://dev.wix.com/docs/api-reference/articles/authentication/about-identities) and [roles and permissions](https://support.wix.com/en/article/roles-permissions-overview). In these cases, you can ensure the method is called with the required level of authorization by using [elevated permissions](https://dev.wix.com/docs/api-reference/articles/authentication/about-elevated-permissions).
14
+ *
15
+ * <!-- TODO: Check whether this API is relevant for headless projects. -->
16
+ *
17
+ * @example Publish a message to the specified channel
13
18
  * ```ts
14
19
  * import { publisher } from '@wix/realtime';
15
- * import { createClient, AppStrategy } from '@wix/sdk';
20
+ * import { elevate } from '@wix/sdk/context';
16
21
  *
17
- * const client = createClient({
18
- * modules: { publisher },
19
- * auth: AppStrategy({ appId, appSecret, instanceId }),
20
- * });
21
- * await client.publisher.publish({ name: 'my-channel' }, { message: 'hello' });
22
+ * await elevate(publisher.publish)({ name: 'my-channel' }, { message: 'hello' });
22
23
  * ```
23
24
  *
24
- * @example Contextual client (Wix-hosted)
25
+ * @example Publish a message to the specified channel: Self-hosted
25
26
  * ```ts
26
27
  * import { publisher } from '@wix/realtime';
27
- * import { elevate } from '@wix/sdk/context';
28
+ * import { createClient } from '@wix/sdk';
28
29
  *
29
- * await elevate(publisher.publish)({ name: 'my-channel' }, { message: 'hello' });
30
+ * // Import the auth strategy for the relevant access type
31
+ * // Import the relevant host module if needed
32
+ *
33
+ * const client = createClient({
34
+ * modules: { publisher },
35
+ * // Include the auth strategy and host as relevant
36
+ * });
37
+ *
38
+ * await client.publisher.publish({ name: 'my-channel' }, { message: 'hello' });
30
39
  * ```
31
40
  *
32
- * @param channel - The channel, and optionally the resource, to publish to.
33
- * @param payload - Message payload. Max: 10kb
41
+ * @param channel - Channel or resource to publish to.
42
+ * @param payload - Message payload. Max: 10 KB.
34
43
  */
35
44
  exports.publish = (0, rest_modules_1.createRESTModule)(publisher_public_js_1.publish);
@@ -1,81 +1,92 @@
1
1
  import { subscribe as publicSubscribe, unsubscribe as publicUnsubscribe } from './subscriber.public.js';
2
2
  import type { BuildRESTFunction, MaybeContext } from '@wix/sdk-types';
3
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.
4
+ * Subscribes to a channel or resource.
7
5
  *
8
- * @example Manual client (self-hosted / explicit auth)
6
+ * The method attempts to establish a subscription to the specified channel or resource. While the subscription is attempted asynchronously, the method returns the subscription ID immediately.
7
+ *
8
+ * Use the `options` parameter to register handlers that run whenever the subscription succeeds or generates an error. For some errors, the subscription is re-attempted automatically. The `onSubscribed()` handler runs on every successful re-subscription.
9
+ *
10
+ * @example Subscribe to a channel
9
11
  * ```ts
10
12
  * 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
13
  *
18
- * const subscriptionId = client.subscriber.subscribe(
14
+ * const subscriptionId = subscriber.subscribe(
19
15
  * { name: 'my-channel' },
20
16
  * (message, channel) => {
21
17
  * console.log('Received:', message.payload);
22
18
  * },
23
- * {
24
- * onSubscribed: (id, isSynced) => console.log('Subscribed', id),
25
- * onSubscriptionError: (error, id) => console.error('Error', error),
26
- * },
27
19
  * );
28
20
  * ```
29
21
  *
30
- * @example Contextual client (Wix-hosted)
22
+ * @example Subscribe to a channel: Self-hosted
31
23
  * ```ts
24
+ * import { createClient } from '@wix/sdk';
32
25
  * import { subscriber } from '@wix/realtime';
33
26
  *
34
- * const subscriptionId = subscriber.subscribe(
27
+ * // Import the auth strategy for the relevant access type
28
+ * // Import the relevant host module if needed
29
+ *
30
+ * const client = createClient({
31
+ * modules: { subscriber },
32
+ * // Include the auth strategy and host as relevant
33
+ * });
34
+ *
35
+ * const subscriptionId = client.subscriber.subscribe(
35
36
  * { name: 'my-channel' },
36
37
  * (message, channel) => {
37
38
  * console.log('Received:', message.payload);
38
39
  * },
40
+ * {
41
+ * onSubscribed: (id, isSynced) => console.log('Subscribed', id),
42
+ * onSubscriptionError: (error, id) => console.error('Error', error),
43
+ * },
39
44
  * );
40
45
  * ```
41
46
  *
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.
47
+ * @param channel - Channel, and optionally resource, to subscribe to.
48
+ * @param messageHandler - Callback that runs whenever a message is published to the channel.
49
+ * @param options - Lifecycle handlers for subscription events.
45
50
  */
46
51
  export declare const subscribe: MaybeContext<BuildRESTFunction<typeof publicSubscribe> & typeof publicSubscribe>;
47
52
  /**
48
- * Unsubscribe from a subscription by its ID, by channel, or both.
53
+ * Removes 1 or more subscriptions.
54
+ *
55
+ * You can unsubscribe in 3 ways:
56
+ * - By `subscriptionId`: removes a single subscription.
57
+ * - By `channel`: removes all subscriptions to that channel or resource.
58
+ * - By both: removes the specific subscription, verifying it matches the channel.
59
+ *
60
+ * When the last subscription on a connection is removed, the connection
61
+ * closes automatically.
62
+ *
63
+ * @example Remove the specified subscription.
64
+ * ```ts
65
+ * import { subscriber } from '@wix/realtime';
49
66
  *
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.
67
+ * subscriber.unsubscribe({ subscriptionId });
68
+ * ```
54
69
  *
55
- * @example Manual client (self-hosted / explicit auth)
70
+ * @example Remove the specified subscription: Self-hosted
56
71
  * ```ts
57
72
  * import { subscriber } from '@wix/realtime';
58
- * import { createClient, AppStrategy } from '@wix/sdk';
73
+ * import { createClient } from '@wix/sdk';
74
+ *
75
+ * // Import the auth strategy for the relevant access type
76
+ * // Import the relevant host module if needed
59
77
  *
60
78
  * const client = createClient({
61
79
  * modules: { subscriber },
62
- * auth: AppStrategy({ appId, appSecret, instanceId }),
80
+ * // Include the auth strategy and host as relevant
63
81
  * });
64
82
  *
65
- * // Unsubscribe by subscription ID
83
+ * // Remove the specified subscription
66
84
  * client.subscriber.unsubscribe({ subscriptionId });
67
85
  *
68
- * // Unsubscribe from all subscriptions to a channel
86
+ * // Remove all subscriptions from the specified channel
69
87
  * client.subscriber.unsubscribe({ channel: { name: 'my-channel' } });
70
88
  * ```
71
89
  *
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.
90
+ * @param options - Unsubscribe information. You must specify `channel`, `subscriptionId`, or both.
80
91
  */
81
92
  export declare const unsubscribe: MaybeContext<BuildRESTFunction<typeof publicUnsubscribe> & typeof publicUnsubscribe>;
@@ -4,81 +4,92 @@ 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
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.
7
+ * Subscribes to a channel or resource.
10
8
  *
11
- * @example Manual client (self-hosted / explicit auth)
9
+ * The method attempts to establish a subscription to the specified channel or resource. While the subscription is attempted asynchronously, the method returns the subscription ID immediately.
10
+ *
11
+ * Use the `options` parameter to register handlers that run whenever the subscription succeeds or generates an error. For some errors, the subscription is re-attempted automatically. The `onSubscribed()` handler runs on every successful re-subscription.
12
+ *
13
+ * @example Subscribe to a channel
12
14
  * ```ts
13
15
  * 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
16
  *
21
- * const subscriptionId = client.subscriber.subscribe(
17
+ * const subscriptionId = subscriber.subscribe(
22
18
  * { name: 'my-channel' },
23
19
  * (message, channel) => {
24
20
  * console.log('Received:', message.payload);
25
21
  * },
26
- * {
27
- * onSubscribed: (id, isSynced) => console.log('Subscribed', id),
28
- * onSubscriptionError: (error, id) => console.error('Error', error),
29
- * },
30
22
  * );
31
23
  * ```
32
24
  *
33
- * @example Contextual client (Wix-hosted)
25
+ * @example Subscribe to a channel: Self-hosted
34
26
  * ```ts
27
+ * import { createClient } from '@wix/sdk';
35
28
  * import { subscriber } from '@wix/realtime';
36
29
  *
37
- * const subscriptionId = subscriber.subscribe(
30
+ * // Import the auth strategy for the relevant access type
31
+ * // Import the relevant host module if needed
32
+ *
33
+ * const client = createClient({
34
+ * modules: { subscriber },
35
+ * // Include the auth strategy and host as relevant
36
+ * });
37
+ *
38
+ * const subscriptionId = client.subscriber.subscribe(
38
39
  * { name: 'my-channel' },
39
40
  * (message, channel) => {
40
41
  * console.log('Received:', message.payload);
41
42
  * },
43
+ * {
44
+ * onSubscribed: (id, isSynced) => console.log('Subscribed', id),
45
+ * onSubscriptionError: (error, id) => console.error('Error', error),
46
+ * },
42
47
  * );
43
48
  * ```
44
49
  *
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.
50
+ * @param channel - Channel, and optionally resource, to subscribe to.
51
+ * @param messageHandler - Callback that runs whenever a message is published to the channel.
52
+ * @param options - Lifecycle handlers for subscription events.
48
53
  */
49
54
  exports.subscribe = (0, rest_modules_1.createRESTModule)(subscriber_public_js_1.subscribe);
50
55
  /**
51
- * Unsubscribe from a subscription by its ID, by channel, or both.
56
+ * Removes 1 or more subscriptions.
57
+ *
58
+ * You can unsubscribe in 3 ways:
59
+ * - By `subscriptionId`: removes a single subscription.
60
+ * - By `channel`: removes all subscriptions to that channel or resource.
61
+ * - By both: removes the specific subscription, verifying it matches the channel.
62
+ *
63
+ * When the last subscription on a connection is removed, the connection
64
+ * closes automatically.
65
+ *
66
+ * @example Remove the specified subscription.
67
+ * ```ts
68
+ * import { subscriber } from '@wix/realtime';
52
69
  *
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.
70
+ * subscriber.unsubscribe({ subscriptionId });
71
+ * ```
57
72
  *
58
- * @example Manual client (self-hosted / explicit auth)
73
+ * @example Remove the specified subscription: Self-hosted
59
74
  * ```ts
60
75
  * import { subscriber } from '@wix/realtime';
61
- * import { createClient, AppStrategy } from '@wix/sdk';
76
+ * import { createClient } from '@wix/sdk';
77
+ *
78
+ * // Import the auth strategy for the relevant access type
79
+ * // Import the relevant host module if needed
62
80
  *
63
81
  * const client = createClient({
64
82
  * modules: { subscriber },
65
- * auth: AppStrategy({ appId, appSecret, instanceId }),
83
+ * // Include the auth strategy and host as relevant
66
84
  * });
67
85
  *
68
- * // Unsubscribe by subscription ID
86
+ * // Remove the specified subscription
69
87
  * client.subscriber.unsubscribe({ subscriptionId });
70
88
  *
71
- * // Unsubscribe from all subscriptions to a channel
89
+ * // Remove all subscriptions from the specified channel
72
90
  * client.subscriber.unsubscribe({ channel: { name: 'my-channel' } });
73
91
  * ```
74
92
  *
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.
93
+ * @param options - Unsubscribe information. You must specify `channel`, `subscriptionId`, or both.
83
94
  */
84
95
  exports.unsubscribe = (0, rest_modules_1.createRESTModule)(subscriber_public_js_1.unsubscribe);