stream-chat 10.0.1 → 10.0.2
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.
- package/dist/cjs/index.browser.js +53 -7
- package/dist/cjs/index.browser.js.map +4 -4
- package/dist/cjs/index.node.js +54 -7
- package/dist/cjs/index.node.js.map +4 -4
- package/dist/esm/index.mjs +53 -7
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/client.d.ts +6 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/types.d.ts +2 -2
- package/dist/types/version.d.ts +60 -0
- package/package.json +1 -1
- package/src/client.ts +26 -8
- package/src/index.ts +2 -0
- package/src/types.ts +2 -2
- package/src/version.ts +98 -0
package/dist/types/client.d.ts
CHANGED
|
@@ -522,7 +522,12 @@ export declare class StreamChat extends ChatApi {
|
|
|
522
522
|
*/
|
|
523
523
|
_addChannelConfig({ cid, config }: Pick<ChannelResponse, 'cid' | 'config'>): void;
|
|
524
524
|
/**
|
|
525
|
-
* Revokes a global ban.
|
|
525
|
+
* Revokes a global ban, or a channel ban when `options.type` and `options.id` name a channel.
|
|
526
|
+
*
|
|
527
|
+
* Goes through V2 `client.moderation.unban()`. The one exception is
|
|
528
|
+
* `remove_future_channels_ban`, which that endpoint does not accept, so a call with it set still
|
|
529
|
+
* goes to v1 `DELETE /moderation/ban`. `shadow` is accepted for compatibility but ignored: the
|
|
530
|
+
* server lifts whichever ban is in place, shadow or not, on both endpoints.
|
|
526
531
|
*
|
|
527
532
|
* @param targetUserId - The user to unban.
|
|
528
533
|
* @param options - Unban options (optional).
|
package/dist/types/index.d.ts
CHANGED
|
@@ -47,3 +47,4 @@ export { asTimestampNS, convertTimestampToDate, dateToNs, msToNs, nowNs, NS_PER_
|
|
|
47
47
|
export { hasPending, settled, withCancellation, withoutConcurrency, } from './utils/concurrency';
|
|
48
48
|
export * from './ChannelManager';
|
|
49
49
|
export * from './EventHandlerPipeline';
|
|
50
|
+
export { version } from './version';
|
package/dist/types/types.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ export type RequireAtLeastOne<T> = {
|
|
|
9
9
|
[K in keyof T]-?: Required<Pick<T, K>> & Partial<Omit<T, K>>;
|
|
10
10
|
}[keyof T];
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* The return type of `StreamChat.unbanUser`, kept so its signature is unchanged. Its v1 fallback
|
|
13
|
+
* (`remove_future_channels_ban`) is the one hand-written `/moderation/*` call left.
|
|
14
14
|
*/
|
|
15
15
|
export type APIResponse = {
|
|
16
16
|
duration: string;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The parsed version of this `stream-chat` build.
|
|
3
|
+
*
|
|
4
|
+
* - `prerelease` is the prerelease identifier without its trailing `.N` (`'rc'` for
|
|
5
|
+
* `10.0.0-rc.35`; a numeric-only id such as `1.0.0-1` has no `.N` and stays `'1'`), or `null`
|
|
6
|
+
* for a stable release. It is a plain string because this package has
|
|
7
|
+
* shipped prereleases beyond `alpha` / `beta` / `rc` (`dev`, `insights`, `offline-support-beta`).
|
|
8
|
+
* - `prereleaseNumber` is the number of that trailing `.N` (`35`), or `null` when there is none.
|
|
9
|
+
* - `raw` is the version string exactly as it was given.
|
|
10
|
+
*
|
|
11
|
+
* Outside the esbuild bundles (unit tests, code importing `src/` directly) no version is injected,
|
|
12
|
+
* and the value is that of the `package.json` placeholder, `0.0.0-development`.
|
|
13
|
+
*/
|
|
14
|
+
export type StreamChatVersion = Readonly<{
|
|
15
|
+
major: number;
|
|
16
|
+
minor: number;
|
|
17
|
+
patch: number;
|
|
18
|
+
prerelease: string | null;
|
|
19
|
+
prereleaseNumber: number | null;
|
|
20
|
+
raw: string;
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
* Parses a version string into a {@link StreamChatVersion}. Never throws: a missing or empty value
|
|
24
|
+
* parses as the `package.json` placeholder, and an unparseable one gives zeros (the defaults below)
|
|
25
|
+
* with the input kept in `raw`.
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export declare const parseVersion: (raw: string | undefined) => StreamChatVersion;
|
|
30
|
+
/**
|
|
31
|
+
* The version esbuild's `define` injected, or `undefined` outside the bundles.
|
|
32
|
+
*
|
|
33
|
+
* Keep `process.env.PKG_VERSION` spelled out exactly: `define` replaces that expression and no
|
|
34
|
+
* other (a destructure or `globalThis.process` would ship the fallback). A `typeof process` guard
|
|
35
|
+
* would not survive the replacement either: it compiles to `typeof process !== 'undefined' ?
|
|
36
|
+
* "10.0.1" : undefined`, which is the fallback in every browser. A `try` keeps the literal while
|
|
37
|
+
* still letting an unbundled `src/` import in a browser (no `process`) load.
|
|
38
|
+
*
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
export declare const readInjectedVersion: () => string | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* The bundle esbuild's `define` injected (`node-cjs`, `browser-cjs`, `browser-esm`), or `undefined`
|
|
44
|
+
* outside the bundles. Same spelling rule as {@link readInjectedVersion}.
|
|
45
|
+
*
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
export declare const readInjectedClientBundle: () => string | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* The version of this `stream-chat` build, for feature detection between packages (a UI SDK
|
|
51
|
+
* checking which core it runs against). To find out whether one specific API exists, checking for
|
|
52
|
+
* the API itself (`'method' in client`) is more precise.
|
|
53
|
+
*
|
|
54
|
+
* Only the esbuild bundles carry the real version. Imported any other way (`src/` through an alias,
|
|
55
|
+
* a linked checkout) it is `0.0.0-development`, so `major === 0` means **unknown**, not old: a
|
|
56
|
+
* feature check should treat it as "assume the newest behaviour" rather than take a legacy path.
|
|
57
|
+
*
|
|
58
|
+
* Both calls are annotated: `#__PURE__` covers one call, not its arguments.
|
|
59
|
+
*/
|
|
60
|
+
export declare const version: StreamChatVersion;
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/* eslint no-unused-vars: "off" */
|
|
2
|
-
/* global process */
|
|
3
2
|
|
|
4
3
|
import type { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
5
4
|
import axios from 'axios';
|
|
@@ -22,6 +21,7 @@ import {
|
|
|
22
21
|
sanitizeOutgoingAttachments,
|
|
23
22
|
} from './utils';
|
|
24
23
|
import { nowNs } from './utils/time';
|
|
24
|
+
import { readInjectedClientBundle, readInjectedVersion } from './version';
|
|
25
25
|
import { normalizeUploadFile } from './upload-utils';
|
|
26
26
|
|
|
27
27
|
import type {
|
|
@@ -1681,16 +1681,34 @@ export class StreamChat extends ChatApi {
|
|
|
1681
1681
|
}
|
|
1682
1682
|
|
|
1683
1683
|
/**
|
|
1684
|
-
* Revokes a global ban.
|
|
1684
|
+
* Revokes a global ban, or a channel ban when `options.type` and `options.id` name a channel.
|
|
1685
|
+
*
|
|
1686
|
+
* Goes through V2 `client.moderation.unban()`. The one exception is
|
|
1687
|
+
* `remove_future_channels_ban`, which that endpoint does not accept, so a call with it set still
|
|
1688
|
+
* goes to v1 `DELETE /moderation/ban`. `shadow` is accepted for compatibility but ignored: the
|
|
1689
|
+
* server lifts whichever ban is in place, shadow or not, on both endpoints.
|
|
1685
1690
|
*
|
|
1686
1691
|
* @param targetUserId - The user to unban.
|
|
1687
1692
|
* @param options - Unban options (optional).
|
|
1688
1693
|
* @returns The server response.
|
|
1689
1694
|
*/
|
|
1690
|
-
async unbanUser(
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1695
|
+
async unbanUser(
|
|
1696
|
+
targetUserId: string,
|
|
1697
|
+
options?: UnBanUserOptions,
|
|
1698
|
+
): Promise<APIResponse> {
|
|
1699
|
+
const { id, remove_future_channels_ban, type } = options ?? {};
|
|
1700
|
+
const target_user_id = options?.target_user_id ?? targetUserId;
|
|
1701
|
+
|
|
1702
|
+
if (remove_future_channels_ban) {
|
|
1703
|
+
return await this.api.delete<APIResponse>(this.baseURL + '/moderation/ban', {
|
|
1704
|
+
...options,
|
|
1705
|
+
target_user_id,
|
|
1706
|
+
});
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
return await this.moderation.unban({
|
|
1710
|
+
target_user_id,
|
|
1711
|
+
channel_cid: type && id ? `${type}:${id}` : undefined,
|
|
1694
1712
|
});
|
|
1695
1713
|
}
|
|
1696
1714
|
|
|
@@ -1933,7 +1951,7 @@ export class StreamChat extends ChatApi {
|
|
|
1933
1951
|
|
|
1934
1952
|
// Memoized on the first call: later changes to the identifiers are not picked up.
|
|
1935
1953
|
if (!this.cachedUserAgent) {
|
|
1936
|
-
const version =
|
|
1954
|
+
const version = readInjectedVersion();
|
|
1937
1955
|
const { name: sdkName, version: sdkVersion } = this.sdkIdentifier ?? {};
|
|
1938
1956
|
const { name: appName, version: appVersion } = this.appIdentifier ?? {};
|
|
1939
1957
|
const { os, model: deviceModel } = this.deviceIdentifier ?? {};
|
|
@@ -1950,7 +1968,7 @@ export class StreamChat extends ChatApi {
|
|
|
1950
1968
|
app_version: appVersion,
|
|
1951
1969
|
os,
|
|
1952
1970
|
device_model: deviceModel,
|
|
1953
|
-
client_bundle:
|
|
1971
|
+
client_bundle: readInjectedClientBundle(),
|
|
1954
1972
|
})
|
|
1955
1973
|
.filter(([, value]) => value && value.length > 0)
|
|
1956
1974
|
.map(([key, value]) => `${key}=${value}`),
|
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -51,8 +51,8 @@ export type RequireAtLeastOne<T> = {
|
|
|
51
51
|
}[keyof T];
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
54
|
+
* The return type of `StreamChat.unbanUser`, kept so its signature is unchanged. Its v1 fallback
|
|
55
|
+
* (`remove_future_channels_ban`) is the one hand-written `/moderation/*` call left.
|
|
56
56
|
*/
|
|
57
57
|
export type APIResponse = {
|
|
58
58
|
duration: string;
|
package/src/version.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The parsed version of this `stream-chat` build.
|
|
3
|
+
*
|
|
4
|
+
* - `prerelease` is the prerelease identifier without its trailing `.N` (`'rc'` for
|
|
5
|
+
* `10.0.0-rc.35`; a numeric-only id such as `1.0.0-1` has no `.N` and stays `'1'`), or `null`
|
|
6
|
+
* for a stable release. It is a plain string because this package has
|
|
7
|
+
* shipped prereleases beyond `alpha` / `beta` / `rc` (`dev`, `insights`, `offline-support-beta`).
|
|
8
|
+
* - `prereleaseNumber` is the number of that trailing `.N` (`35`), or `null` when there is none.
|
|
9
|
+
* - `raw` is the version string exactly as it was given.
|
|
10
|
+
*
|
|
11
|
+
* Outside the esbuild bundles (unit tests, code importing `src/` directly) no version is injected,
|
|
12
|
+
* and the value is that of the `package.json` placeholder, `0.0.0-development`.
|
|
13
|
+
*/
|
|
14
|
+
export type StreamChatVersion = Readonly<{
|
|
15
|
+
major: number;
|
|
16
|
+
minor: number;
|
|
17
|
+
patch: number;
|
|
18
|
+
prerelease: string | null;
|
|
19
|
+
prereleaseNumber: number | null;
|
|
20
|
+
raw: string;
|
|
21
|
+
}>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* `major.minor.patch`, an optional `-<id>` with its trailing `.N` split off (lazy, so `rc.35` gives
|
|
25
|
+
* `rc` and `35`, and `offline-support-beta.2` keeps its whole id), and an ignored `+<build>`.
|
|
26
|
+
*/
|
|
27
|
+
const SEMVER_PATTERN =
|
|
28
|
+
/^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+?)(?:\.(\d+))?)?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Parses a version string into a {@link StreamChatVersion}. Never throws: a missing or empty value
|
|
32
|
+
* parses as the `package.json` placeholder, and an unparseable one gives zeros (the defaults below)
|
|
33
|
+
* with the input kept in `raw`.
|
|
34
|
+
*
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
export const parseVersion = (raw: string | undefined): StreamChatVersion => {
|
|
38
|
+
const input = raw || '0.0.0-development';
|
|
39
|
+
const [, major = 0, minor = 0, patch = 0, prerelease = null, prereleaseNumber] =
|
|
40
|
+
SEMVER_PATTERN.exec(input) ?? [];
|
|
41
|
+
|
|
42
|
+
return Object.freeze({
|
|
43
|
+
major: Number(major),
|
|
44
|
+
minor: Number(minor),
|
|
45
|
+
patch: Number(patch),
|
|
46
|
+
prerelease,
|
|
47
|
+
prereleaseNumber: prereleaseNumber ? Number(prereleaseNumber) : null,
|
|
48
|
+
raw: input,
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The version esbuild's `define` injected, or `undefined` outside the bundles.
|
|
54
|
+
*
|
|
55
|
+
* Keep `process.env.PKG_VERSION` spelled out exactly: `define` replaces that expression and no
|
|
56
|
+
* other (a destructure or `globalThis.process` would ship the fallback). A `typeof process` guard
|
|
57
|
+
* would not survive the replacement either: it compiles to `typeof process !== 'undefined' ?
|
|
58
|
+
* "10.0.1" : undefined`, which is the fallback in every browser. A `try` keeps the literal while
|
|
59
|
+
* still letting an unbundled `src/` import in a browser (no `process`) load.
|
|
60
|
+
*
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
export const readInjectedVersion = (): string | undefined => {
|
|
64
|
+
try {
|
|
65
|
+
return process.env.PKG_VERSION;
|
|
66
|
+
} catch {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The bundle esbuild's `define` injected (`node-cjs`, `browser-cjs`, `browser-esm`), or `undefined`
|
|
73
|
+
* outside the bundles. Same spelling rule as {@link readInjectedVersion}.
|
|
74
|
+
*
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
export const readInjectedClientBundle = (): string | undefined => {
|
|
78
|
+
try {
|
|
79
|
+
return process.env.CLIENT_BUNDLE;
|
|
80
|
+
} catch {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The version of this `stream-chat` build, for feature detection between packages (a UI SDK
|
|
87
|
+
* checking which core it runs against). To find out whether one specific API exists, checking for
|
|
88
|
+
* the API itself (`'method' in client`) is more precise.
|
|
89
|
+
*
|
|
90
|
+
* Only the esbuild bundles carry the real version. Imported any other way (`src/` through an alias,
|
|
91
|
+
* a linked checkout) it is `0.0.0-development`, so `major === 0` means **unknown**, not old: a
|
|
92
|
+
* feature check should treat it as "assume the newest behaviour" rather than take a legacy path.
|
|
93
|
+
*
|
|
94
|
+
* Both calls are annotated: `#__PURE__` covers one call, not its arguments.
|
|
95
|
+
*/
|
|
96
|
+
export const version: StreamChatVersion = /* #__PURE__ */ parseVersion(
|
|
97
|
+
/* #__PURE__ */ readInjectedVersion(),
|
|
98
|
+
);
|