@wix/realtime 1.0.34 → 1.0.36

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,41 +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 channel or channel resource.
4
+ * Publishes a message to a channel or resource.
5
5
  *
6
- * All subscribers currently listening to the specified channel receive the
7
- * message. Subscribers to a channel don't receive messages published to a
8
- * resource on that channel, and vice versa.
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.
9
7
  *
10
- * This method is backend-only and requires elevated permissions.
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
11
  *
12
12
  * <!-- TODO: Check whether this API is relevant for headless projects. -->
13
13
  *
14
- * > **Note:** This function requires elevated permissions and runs only on the backend.
15
- * > You can also call this method from the frontend using `elevate()`.
16
- * > Elevated permissions are only available for apps and service accounts.
17
- *
18
- * @example Manual client (self-hosted / explicit auth)
14
+ * @example Publish a message to the specified channel
19
15
  * ```ts
20
16
  * import { publisher } from '@wix/realtime';
21
- * import { createClient, AppStrategy } from '@wix/sdk';
17
+ * import { elevate } from '@wix/sdk/context';
22
18
  *
23
- * const client = createClient({
24
- * modules: { publisher },
25
- * auth: AppStrategy({ appId, appSecret, instanceId }),
26
- * });
27
- * await client.publisher.publish({ name: 'my-channel' }, { message: 'hello' });
19
+ * await elevate(publisher.publish)({ name: 'my-channel' }, { message: 'hello' });
28
20
  * ```
29
21
  *
30
- * @example Contextual client (Wix-hosted)
22
+ * @example Publish a message to the specified channel: Self-hosted
31
23
  * ```ts
32
24
  * import { publisher } from '@wix/realtime';
33
- * import { elevate } from '@wix/sdk/context';
25
+ * import { createClient } from '@wix/sdk';
34
26
  *
35
- * 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' });
36
36
  * ```
37
37
  *
38
- * @param channel - Channel, and optionally resource, to publish to.
38
+ * @param channel - Channel or resource to publish to.
39
39
  * @param payload - Message payload. Max: 10 KB.
40
40
  */
41
41
  export declare const publish: MaybeContext<BuildRESTFunction<typeof publicPublish> & typeof publicPublish>;
@@ -4,41 +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 channel or channel resource.
7
+ * Publishes a message to a channel or resource.
8
8
  *
9
- * All subscribers currently listening to the specified channel receive the
10
- * message. Subscribers to a channel don't receive messages published to a
11
- * resource on that channel, and vice versa.
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.
12
10
  *
13
- * This method is backend-only and requires elevated permissions.
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
14
  *
15
15
  * <!-- TODO: Check whether this API is relevant for headless projects. -->
16
16
  *
17
- * > **Note:** This function requires elevated permissions and runs only on the backend.
18
- * > You can also call this method from the frontend using `elevate()`.
19
- * > Elevated permissions are only available for apps and service accounts.
20
- *
21
- * @example Manual client (self-hosted / explicit auth)
17
+ * @example Publish a message to the specified channel
22
18
  * ```ts
23
19
  * import { publisher } from '@wix/realtime';
24
- * import { createClient, AppStrategy } from '@wix/sdk';
20
+ * import { elevate } from '@wix/sdk/context';
25
21
  *
26
- * const client = createClient({
27
- * modules: { publisher },
28
- * auth: AppStrategy({ appId, appSecret, instanceId }),
29
- * });
30
- * await client.publisher.publish({ name: 'my-channel' }, { message: 'hello' });
22
+ * await elevate(publisher.publish)({ name: 'my-channel' }, { message: 'hello' });
31
23
  * ```
32
24
  *
33
- * @example Contextual client (Wix-hosted)
25
+ * @example Publish a message to the specified channel: Self-hosted
34
26
  * ```ts
35
27
  * import { publisher } from '@wix/realtime';
36
- * import { elevate } from '@wix/sdk/context';
28
+ * import { createClient } from '@wix/sdk';
37
29
  *
38
- * 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' });
39
39
  * ```
40
40
  *
41
- * @param channel - Channel, and optionally resource, to publish to.
41
+ * @param channel - Channel or resource to publish to.
42
42
  * @param payload - Message payload. Max: 10 KB.
43
43
  */
44
44
  exports.publish = (0, rest_modules_1.createRESTModule)(publisher_public_js_1.publish);
@@ -1,48 +1,46 @@
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
- * Subscribes to a channel or channel resource.
4
+ * Subscribes to a channel or resource.
5
5
  *
6
- * The method returns a subscription ID immediately. The connection is
7
- * established asynchronously in the background. Use the `options` parameter
8
- * to register lifecycle handlers that notify you when the subscription
9
- * succeeds or encounters an error.
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.
10
7
  *
11
- * If the connection drops, the client automatically attempts to reconnect
12
- * and re-subscribe. The `onSubscribed` handler fires again on each
13
- * successful re-subscription.
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.
14
9
  *
15
- * @example Manual client (self-hosted / explicit auth)
10
+ * @example Subscribe to a channel
16
11
  * ```ts
17
12
  * import { subscriber } from '@wix/realtime';
18
- * import { createClient, AppStrategy } from '@wix/sdk';
19
13
  *
20
- * const client = createClient({
21
- * modules: { subscriber },
22
- * auth: AppStrategy({ appId, appSecret, instanceId }),
23
- * });
24
- *
25
- * const subscriptionId = client.subscriber.subscribe(
14
+ * const subscriptionId = subscriber.subscribe(
26
15
  * { name: 'my-channel' },
27
16
  * (message, channel) => {
28
17
  * console.log('Received:', message.payload);
29
18
  * },
30
- * {
31
- * onSubscribed: (id, isSynced) => console.log('Subscribed', id),
32
- * onSubscriptionError: (error, id) => console.error('Error', error),
33
- * },
34
19
  * );
35
20
  * ```
36
21
  *
37
- * @example Contextual client (Wix-hosted)
22
+ * @example Subscribe to a channel: Self-hosted
38
23
  * ```ts
24
+ * import { createClient } from '@wix/sdk';
39
25
  * import { subscriber } from '@wix/realtime';
40
26
  *
41
- * 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(
42
36
  * { name: 'my-channel' },
43
37
  * (message, channel) => {
44
38
  * console.log('Received:', message.payload);
45
39
  * },
40
+ * {
41
+ * onSubscribed: (id, isSynced) => console.log('Subscribed', id),
42
+ * onSubscriptionError: (error, id) => console.error('Error', error),
43
+ * },
46
44
  * );
47
45
  * ```
48
46
  *
@@ -52,40 +50,43 @@ import type { BuildRESTFunction, MaybeContext } from '@wix/sdk-types';
52
50
  */
53
51
  export declare const subscribe: MaybeContext<BuildRESTFunction<typeof publicSubscribe> & typeof publicSubscribe>;
54
52
  /**
55
- * Removes one or more subscriptions.
53
+ * Removes 1 or more subscriptions.
56
54
  *
57
- * You can unsubscribe in three ways:
55
+ * You can unsubscribe in 3 ways:
58
56
  * - By `subscriptionId`: removes a single subscription.
59
- * - By `channel`: removes all subscriptions to that channel or channel resource.
57
+ * - By `channel`: removes all subscriptions to that channel or resource.
60
58
  * - By both: removes the specific subscription, verifying it matches the channel.
61
59
  *
62
60
  * When the last subscription on a connection is removed, the connection
63
61
  * closes automatically.
64
62
  *
65
- * @example Manual client (self-hosted / explicit auth)
63
+ * @example Remove the specified subscription.
66
64
  * ```ts
67
65
  * import { subscriber } from '@wix/realtime';
68
- * import { createClient, AppStrategy } from '@wix/sdk';
66
+ *
67
+ * subscriber.unsubscribe({ subscriptionId });
68
+ * ```
69
+ *
70
+ * @example Remove the specified subscription: Self-hosted
71
+ * ```ts
72
+ * import { subscriber } from '@wix/realtime';
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
69
77
  *
70
78
  * const client = createClient({
71
79
  * modules: { subscriber },
72
- * auth: AppStrategy({ appId, appSecret, instanceId }),
80
+ * // Include the auth strategy and host as relevant
73
81
  * });
74
82
  *
75
- * // Unsubscribe by subscription ID
83
+ * // Remove the specified subscription
76
84
  * client.subscriber.unsubscribe({ subscriptionId });
77
85
  *
78
- * // Unsubscribe from all subscriptions to a channel
86
+ * // Remove all subscriptions from the specified channel
79
87
  * client.subscriber.unsubscribe({ channel: { name: 'my-channel' } });
80
88
  * ```
81
89
  *
82
- * @example Contextual client (Wix-hosted)
83
- * ```ts
84
- * import { subscriber } from '@wix/realtime';
85
- *
86
- * subscriber.unsubscribe({ subscriptionId });
87
- * ```
88
- *
89
- * @param options - Specifies what to unsubscribe from. At least one of `channel` or `subscriptionId` is required.
90
+ * @param options - Unsubscribe information. You must specify `channel`, `subscriptionId`, or both.
90
91
  */
91
92
  export declare const unsubscribe: MaybeContext<BuildRESTFunction<typeof publicUnsubscribe> & typeof publicUnsubscribe>;
@@ -4,48 +4,46 @@ 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
- * Subscribes to a channel or channel resource.
7
+ * Subscribes to a channel or resource.
8
8
  *
9
- * The method returns a subscription ID immediately. The connection is
10
- * established asynchronously in the background. Use the `options` parameter
11
- * to register lifecycle handlers that notify you when the subscription
12
- * succeeds or encounters an error.
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.
13
10
  *
14
- * If the connection drops, the client automatically attempts to reconnect
15
- * and re-subscribe. The `onSubscribed` handler fires again on each
16
- * successful re-subscription.
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.
17
12
  *
18
- * @example Manual client (self-hosted / explicit auth)
13
+ * @example Subscribe to a channel
19
14
  * ```ts
20
15
  * import { subscriber } from '@wix/realtime';
21
- * import { createClient, AppStrategy } from '@wix/sdk';
22
16
  *
23
- * const client = createClient({
24
- * modules: { subscriber },
25
- * auth: AppStrategy({ appId, appSecret, instanceId }),
26
- * });
27
- *
28
- * const subscriptionId = client.subscriber.subscribe(
17
+ * const subscriptionId = subscriber.subscribe(
29
18
  * { name: 'my-channel' },
30
19
  * (message, channel) => {
31
20
  * console.log('Received:', message.payload);
32
21
  * },
33
- * {
34
- * onSubscribed: (id, isSynced) => console.log('Subscribed', id),
35
- * onSubscriptionError: (error, id) => console.error('Error', error),
36
- * },
37
22
  * );
38
23
  * ```
39
24
  *
40
- * @example Contextual client (Wix-hosted)
25
+ * @example Subscribe to a channel: Self-hosted
41
26
  * ```ts
27
+ * import { createClient } from '@wix/sdk';
42
28
  * import { subscriber } from '@wix/realtime';
43
29
  *
44
- * 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(
45
39
  * { name: 'my-channel' },
46
40
  * (message, channel) => {
47
41
  * console.log('Received:', message.payload);
48
42
  * },
43
+ * {
44
+ * onSubscribed: (id, isSynced) => console.log('Subscribed', id),
45
+ * onSubscriptionError: (error, id) => console.error('Error', error),
46
+ * },
49
47
  * );
50
48
  * ```
51
49
  *
@@ -55,40 +53,43 @@ const rest_modules_1 = require("@wix/sdk-runtime/rest-modules");
55
53
  */
56
54
  exports.subscribe = (0, rest_modules_1.createRESTModule)(subscriber_public_js_1.subscribe);
57
55
  /**
58
- * Removes one or more subscriptions.
56
+ * Removes 1 or more subscriptions.
59
57
  *
60
- * You can unsubscribe in three ways:
58
+ * You can unsubscribe in 3 ways:
61
59
  * - By `subscriptionId`: removes a single subscription.
62
- * - By `channel`: removes all subscriptions to that channel or channel resource.
60
+ * - By `channel`: removes all subscriptions to that channel or resource.
63
61
  * - By both: removes the specific subscription, verifying it matches the channel.
64
62
  *
65
63
  * When the last subscription on a connection is removed, the connection
66
64
  * closes automatically.
67
65
  *
68
- * @example Manual client (self-hosted / explicit auth)
66
+ * @example Remove the specified subscription.
69
67
  * ```ts
70
68
  * import { subscriber } from '@wix/realtime';
71
- * import { createClient, AppStrategy } from '@wix/sdk';
69
+ *
70
+ * subscriber.unsubscribe({ subscriptionId });
71
+ * ```
72
+ *
73
+ * @example Remove the specified subscription: Self-hosted
74
+ * ```ts
75
+ * import { subscriber } from '@wix/realtime';
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
72
80
  *
73
81
  * const client = createClient({
74
82
  * modules: { subscriber },
75
- * auth: AppStrategy({ appId, appSecret, instanceId }),
83
+ * // Include the auth strategy and host as relevant
76
84
  * });
77
85
  *
78
- * // Unsubscribe by subscription ID
86
+ * // Remove the specified subscription
79
87
  * client.subscriber.unsubscribe({ subscriptionId });
80
88
  *
81
- * // Unsubscribe from all subscriptions to a channel
89
+ * // Remove all subscriptions from the specified channel
82
90
  * client.subscriber.unsubscribe({ channel: { name: 'my-channel' } });
83
91
  * ```
84
92
  *
85
- * @example Contextual client (Wix-hosted)
86
- * ```ts
87
- * import { subscriber } from '@wix/realtime';
88
- *
89
- * subscriber.unsubscribe({ subscriptionId });
90
- * ```
91
- *
92
- * @param options - Specifies what to unsubscribe from. At least one of `channel` or `subscriptionId` is required.
93
+ * @param options - Unsubscribe information. You must specify `channel`, `subscriptionId`, or both.
93
94
  */
94
95
  exports.unsubscribe = (0, rest_modules_1.createRESTModule)(subscriber_public_js_1.unsubscribe);