@stream-io/node-sdk 0.8.15 → 0.9.0
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/CHANGELOG.md +11 -0
- package/__tests__/docs-snippets/README.md +4 -4
- package/dist/index.cjs.js +317 -8338
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.es.mjs +310 -8339
- package/dist/index.es.mjs.map +1 -1
- package/dist/src/gen/chat/ChannelApi.d.ts +4 -1
- package/dist/src/gen/chat/ChatApi.d.ts +18 -1
- package/dist/src/gen/common/CommonApi.d.ts +4 -3
- package/dist/src/gen/feeds/FeedApi.d.ts +5 -1
- package/dist/src/gen/feeds/FeedsApi.d.ts +18 -3
- package/dist/src/gen/models/index.d.ts +2530 -1033
- package/dist/src/gen/models/timestamp-guard.d.ts +22 -0
- package/dist/src/gen/moderation/ModerationApi.d.ts +11 -4
- package/dist/src/gen/video/CallApi.d.ts +3 -3
- package/dist/src/gen/video/VideoApi.d.ts +3 -3
- package/dist/src/utils/time.d.ts +67 -0
- package/index.ts +10 -0
- package/package.json +1 -1
- package/src/gen/chat/ChannelApi.ts +54 -0
- package/src/gen/chat/ChatApi.ts +184 -0
- package/src/gen/common/CommonApi.ts +27 -2
- package/src/gen/feeds/FeedApi.ts +12 -0
- package/src/gen/feeds/FeedsApi.ts +106 -2
- package/src/gen/model-decoders/decoders.ts +3 -6472
- package/src/gen/models/index.ts +2682 -1252
- package/src/gen/models/timestamp-guard.ts +27 -0
- package/src/gen/moderation/ModerationApi.ts +89 -12
- package/src/gen/video/CallApi.ts +3 -2
- package/src/gen/video/VideoApi.ts +3 -2
- package/src/utils/time.ts +84 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { TimestampNS } from './index';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Makes `new Date(ns)` a deprecated constructor, and a compile error for a server-sent nanosecond timestamp.
|
|
5
|
+
*
|
|
6
|
+
* Any tsconfig whose `include` covers this directory picks this file up; `exclude` it to defer.
|
|
7
|
+
*
|
|
8
|
+
* The `0 extends 1 & T` guard excludes `any`. Without it this overload would capture
|
|
9
|
+
* every `new Date(<any>)` in the program -- `any` is assignable to the brand, and a
|
|
10
|
+
* merged declaration is tried before lib.es5.d.ts -- breaking each `JSON.parse` path
|
|
11
|
+
* and index-signature read on the next regeneration.
|
|
12
|
+
*/
|
|
13
|
+
declare global {
|
|
14
|
+
interface DateConstructor {
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Unix nanoseconds, not milliseconds. Use SDK's provided nsToDate(t), or nsToMs(t) for arithmetic.
|
|
17
|
+
*/
|
|
18
|
+
new <T extends TimestampNS>(
|
|
19
|
+
t: 0 extends 1 & T ? never : T,
|
|
20
|
+
): {
|
|
21
|
+
readonly ERROR_use_SDKs_nsToDate_helper_instead: never;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Keeps this a module, which `declare global` requires, independent of the import above.
|
|
27
|
+
export {};
|
|
@@ -56,6 +56,8 @@ import {
|
|
|
56
56
|
QueryLabelResultsResponse,
|
|
57
57
|
QueryModerationConfigsRequest,
|
|
58
58
|
QueryModerationConfigsResponse,
|
|
59
|
+
QueryModerationFeedbackRequest,
|
|
60
|
+
QueryModerationFeedbackResponse,
|
|
59
61
|
QueryModerationFlagsRequest,
|
|
60
62
|
QueryModerationFlagsResponse,
|
|
61
63
|
QueryModerationLogsRequest,
|
|
@@ -66,6 +68,8 @@ import {
|
|
|
66
68
|
QueryReviewQueueResponse,
|
|
67
69
|
QueueResponse,
|
|
68
70
|
Response,
|
|
71
|
+
RevealMediaRequest,
|
|
72
|
+
RevealMediaResponse,
|
|
69
73
|
SubmitActionRequest,
|
|
70
74
|
SubmitActionResponse,
|
|
71
75
|
SubmitModerationFeedbackRequest,
|
|
@@ -257,6 +261,7 @@ export class ModerationApi {
|
|
|
257
261
|
entity_id: request?.entity_id,
|
|
258
262
|
entity_type: request?.entity_type,
|
|
259
263
|
user_id: request?.user_id,
|
|
264
|
+
country_codes: request?.country_codes,
|
|
260
265
|
content_ids: request?.content_ids,
|
|
261
266
|
custom: request?.custom,
|
|
262
267
|
texts: request?.texts,
|
|
@@ -460,6 +465,7 @@ export class ModerationApi {
|
|
|
460
465
|
country_code: request?.country_code,
|
|
461
466
|
test_mode: request?.test_mode,
|
|
462
467
|
user_id: request?.user_id,
|
|
468
|
+
country_codes: request?.country_codes,
|
|
463
469
|
config: request?.config,
|
|
464
470
|
moderation_payload: request?.moderation_payload,
|
|
465
471
|
options: request?.options,
|
|
@@ -518,6 +524,7 @@ export class ModerationApi {
|
|
|
518
524
|
aws_rekognition_config: request?.aws_rekognition_config,
|
|
519
525
|
block_list_config: request?.block_list_config,
|
|
520
526
|
bodyguard_config: request?.bodyguard_config,
|
|
527
|
+
engine: request?.engine,
|
|
521
528
|
flood_config: request?.flood_config,
|
|
522
529
|
google_vision_config: request?.google_vision_config,
|
|
523
530
|
intent_config: request?.intent_config,
|
|
@@ -643,15 +650,47 @@ export class ModerationApi {
|
|
|
643
650
|
return response;
|
|
644
651
|
}
|
|
645
652
|
|
|
646
|
-
async
|
|
647
|
-
|
|
648
|
-
|
|
653
|
+
async queryModerationFeedback(
|
|
654
|
+
request?: QueryModerationFeedbackRequest,
|
|
655
|
+
): Promise<StreamResponse<QueryModerationFeedbackResponse>> {
|
|
656
|
+
const body = {
|
|
657
|
+
item_limit: request?.item_limit,
|
|
658
|
+
limit: request?.limit,
|
|
659
|
+
next: request?.next,
|
|
660
|
+
prev: request?.prev,
|
|
661
|
+
user_id: request?.user_id,
|
|
662
|
+
sort: request?.sort,
|
|
663
|
+
filter: request?.filter,
|
|
664
|
+
user: request?.user,
|
|
665
|
+
};
|
|
666
|
+
|
|
667
|
+
const response =
|
|
668
|
+
await this.apiClient.sendRequest<QueryModerationFeedbackResponse>(
|
|
669
|
+
'POST',
|
|
670
|
+
'/api/v2/moderation/feedback_items',
|
|
671
|
+
undefined,
|
|
672
|
+
undefined,
|
|
673
|
+
body,
|
|
674
|
+
);
|
|
675
|
+
|
|
676
|
+
decoders['QueryModerationFeedbackResponse']?.(response);
|
|
677
|
+
|
|
678
|
+
return response;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
async v2DeleteTemplate(request?: {
|
|
682
|
+
name?: string;
|
|
683
|
+
}): Promise<StreamResponse<DeleteModerationTemplateResponse>> {
|
|
684
|
+
const queryParams = {
|
|
685
|
+
name: request?.name,
|
|
686
|
+
};
|
|
687
|
+
|
|
649
688
|
const response =
|
|
650
689
|
await this.apiClient.sendRequest<DeleteModerationTemplateResponse>(
|
|
651
690
|
'DELETE',
|
|
652
691
|
'/api/v2/moderation/feeds_moderation_template',
|
|
653
692
|
undefined,
|
|
654
|
-
|
|
693
|
+
queryParams,
|
|
655
694
|
);
|
|
656
695
|
|
|
657
696
|
decoders['DeleteModerationTemplateResponse']?.(response);
|
|
@@ -993,15 +1032,21 @@ export class ModerationApi {
|
|
|
993
1032
|
return response;
|
|
994
1033
|
}
|
|
995
1034
|
|
|
996
|
-
async listPolicyTestSets(
|
|
997
|
-
|
|
998
|
-
|
|
1035
|
+
async listPolicyTestSets(request?: {
|
|
1036
|
+
limit?: number;
|
|
1037
|
+
offset?: number;
|
|
1038
|
+
}): Promise<StreamResponse<PolicyTestSetListResponse>> {
|
|
1039
|
+
const queryParams = {
|
|
1040
|
+
limit: request?.limit,
|
|
1041
|
+
offset: request?.offset,
|
|
1042
|
+
};
|
|
1043
|
+
|
|
999
1044
|
const response =
|
|
1000
1045
|
await this.apiClient.sendRequest<PolicyTestSetListResponse>(
|
|
1001
1046
|
'GET',
|
|
1002
1047
|
'/api/v2/moderation/policy_tests/sets',
|
|
1003
1048
|
undefined,
|
|
1004
|
-
|
|
1049
|
+
queryParams,
|
|
1005
1050
|
);
|
|
1006
1051
|
|
|
1007
1052
|
decoders['PolicyTestSetListResponse']?.(response);
|
|
@@ -1211,6 +1256,28 @@ export class ModerationApi {
|
|
|
1211
1256
|
return response;
|
|
1212
1257
|
}
|
|
1213
1258
|
|
|
1259
|
+
async revealMedia(
|
|
1260
|
+
request: RevealMediaRequest,
|
|
1261
|
+
): Promise<StreamResponse<RevealMediaResponse>> {
|
|
1262
|
+
const body = {
|
|
1263
|
+
item_id: request?.item_id,
|
|
1264
|
+
user_id: request?.user_id,
|
|
1265
|
+
user: request?.user,
|
|
1266
|
+
};
|
|
1267
|
+
|
|
1268
|
+
const response = await this.apiClient.sendRequest<RevealMediaResponse>(
|
|
1269
|
+
'POST',
|
|
1270
|
+
'/api/v2/moderation/reveal_media',
|
|
1271
|
+
undefined,
|
|
1272
|
+
undefined,
|
|
1273
|
+
body,
|
|
1274
|
+
);
|
|
1275
|
+
|
|
1276
|
+
decoders['RevealMediaResponse']?.(response);
|
|
1277
|
+
|
|
1278
|
+
return response;
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1214
1281
|
async queryReviewQueue(
|
|
1215
1282
|
request?: QueryReviewQueueRequest,
|
|
1216
1283
|
): Promise<StreamResponse<QueryReviewQueueResponse>> {
|
|
@@ -1344,18 +1411,28 @@ export class ModerationApi {
|
|
|
1344
1411
|
}
|
|
1345
1412
|
|
|
1346
1413
|
async submitModerationFeedback(
|
|
1347
|
-
request
|
|
1414
|
+
request?: SubmitModerationFeedbackRequest,
|
|
1348
1415
|
): Promise<StreamResponse<SubmitModerationFeedbackResponse>> {
|
|
1349
1416
|
const body = {
|
|
1350
|
-
message: request?.message,
|
|
1351
|
-
published_at: request?.published_at,
|
|
1352
|
-
reference: request?.reference,
|
|
1353
1417
|
channel_id: request?.channel_id,
|
|
1418
|
+
confidence: request?.confidence,
|
|
1354
1419
|
current_recommended_action: request?.current_recommended_action,
|
|
1355
1420
|
description: request?.description,
|
|
1421
|
+
entity_creator_id: request?.entity_creator_id,
|
|
1422
|
+
entity_id: request?.entity_id,
|
|
1423
|
+
entity_type: request?.entity_type,
|
|
1356
1424
|
expected_recommended_action: request?.expected_recommended_action,
|
|
1425
|
+
false_positive: request?.false_positive,
|
|
1426
|
+
feedback_type: request?.feedback_type,
|
|
1427
|
+
message: request?.message,
|
|
1428
|
+
published_at: request?.published_at,
|
|
1429
|
+
reference: request?.reference,
|
|
1430
|
+
review_queue_item_id: request?.review_queue_item_id,
|
|
1431
|
+
user_id: request?.user_id,
|
|
1357
1432
|
current_labels: request?.current_labels,
|
|
1358
1433
|
expected_labels: request?.expected_labels,
|
|
1434
|
+
items: request?.items,
|
|
1435
|
+
user: request?.user,
|
|
1359
1436
|
};
|
|
1360
1437
|
|
|
1361
1438
|
const response =
|
package/src/gen/video/CallApi.ts
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
QueryCallParticipantSessionsResponse,
|
|
28
28
|
QueryCallParticipantsRequest,
|
|
29
29
|
QueryCallParticipantsResponse,
|
|
30
|
+
RecordingType,
|
|
30
31
|
RingCallRequest,
|
|
31
32
|
RingCallResponse,
|
|
32
33
|
SendCallEventRequest,
|
|
@@ -208,7 +209,7 @@ export class CallApi {
|
|
|
208
209
|
}
|
|
209
210
|
|
|
210
211
|
startRecording(
|
|
211
|
-
request: StartRecordingRequest & { recording_type:
|
|
212
|
+
request: StartRecordingRequest & { recording_type: RecordingType },
|
|
212
213
|
): Promise<StreamResponse<StartRecordingResponse>> {
|
|
213
214
|
return this.videoApi.startRecording({
|
|
214
215
|
id: this.id,
|
|
@@ -218,7 +219,7 @@ export class CallApi {
|
|
|
218
219
|
}
|
|
219
220
|
|
|
220
221
|
stopRecording(
|
|
221
|
-
request: StopRecordingRequest & { recording_type:
|
|
222
|
+
request: StopRecordingRequest & { recording_type: RecordingType },
|
|
222
223
|
): Promise<StreamResponse<StopRecordingResponse>> {
|
|
223
224
|
return this.videoApi.stopRecording({
|
|
224
225
|
id: this.id,
|
|
@@ -58,6 +58,7 @@ import {
|
|
|
58
58
|
QueryCallsResponse,
|
|
59
59
|
QueryUserFeedbackRequest,
|
|
60
60
|
QueryUserFeedbackResponse,
|
|
61
|
+
RecordingType,
|
|
61
62
|
ReportClientEventRequest,
|
|
62
63
|
ReportClientEventResponse,
|
|
63
64
|
ResolveSipAuthRequest,
|
|
@@ -678,7 +679,7 @@ export class VideoApi {
|
|
|
678
679
|
request: StartRecordingRequest & {
|
|
679
680
|
type: string;
|
|
680
681
|
id: string;
|
|
681
|
-
recording_type:
|
|
682
|
+
recording_type: RecordingType;
|
|
682
683
|
},
|
|
683
684
|
): Promise<StreamResponse<StartRecordingResponse>> {
|
|
684
685
|
const pathParams = {
|
|
@@ -707,7 +708,7 @@ export class VideoApi {
|
|
|
707
708
|
request: StopRecordingRequest & {
|
|
708
709
|
type: string;
|
|
709
710
|
id: string;
|
|
710
|
-
recording_type:
|
|
711
|
+
recording_type: RecordingType;
|
|
711
712
|
},
|
|
712
713
|
): Promise<StreamResponse<StopRecordingResponse>> {
|
|
713
714
|
const pathParams = {
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit conversions between the API's timestamps and JavaScript's.
|
|
3
|
+
*
|
|
4
|
+
* **The invariant this module exists to hold:** a timestamp is a unix-**nanosecond** `number` —
|
|
5
|
+
* that is what the API puts on the wire and what every server-sent date field on a generated
|
|
6
|
+
* response or event type carries. A duration, interval or delay stays in **milliseconds**, because
|
|
7
|
+
* that is what `setTimeout` and `ApiConfig.timeout` speak.
|
|
8
|
+
*
|
|
9
|
+
* Two consequences make the helpers below mandatory rather than convenient:
|
|
10
|
+
*
|
|
11
|
+
* - **Every `Date`-based path is out of range.** `Date` tops out around 8.64e15 ms while a current
|
|
12
|
+
* nanosecond timestamp is ~1.79e18, so a bare wire number read as milliseconds lands on an
|
|
13
|
+
* invalid instance: `new Date(ns).toISOString()` throws `RangeError`, and a date library handed
|
|
14
|
+
* the same number formats it as the literal string `'Invalid Date'`. Neither is a type error.
|
|
15
|
+
* - **A unit mix-up between two `number`s is the silent one.** Comparing a wire timestamp against
|
|
16
|
+
* `Date.now()`, or adding a millisecond duration to one, produces a plausible-looking number and
|
|
17
|
+
* no complaint at all.
|
|
18
|
+
*
|
|
19
|
+
* Outgoing **request** date fields are unaffected: they are still typed `Date`, because
|
|
20
|
+
* `JSON.stringify` emits RFC3339 for a `Date` and that is the format the request spec declares.
|
|
21
|
+
* Use {@link nsToDate} when handing a server-sent timestamp back to the API.
|
|
22
|
+
*
|
|
23
|
+
* Precision note: nanosecond epoch values exceed `Number.MAX_SAFE_INTEGER` (~9.01e15), so they are
|
|
24
|
+
* quantised to roughly 256 ns steps. Ordering is unaffected; exact equality against a value that
|
|
25
|
+
* has round-tripped through JSON is not guaranteed.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/** Nanoseconds per millisecond — the only magic number in this module. */
|
|
29
|
+
export const NS_PER_MS = 1e6;
|
|
30
|
+
|
|
31
|
+
/** A wire timestamp as epoch milliseconds, for arithmetic against `Date.now()` or a `Date`. */
|
|
32
|
+
export const nsToMs = (ns: number): number => Math.floor(ns / NS_PER_MS);
|
|
33
|
+
|
|
34
|
+
/** Epoch milliseconds as a wire timestamp. */
|
|
35
|
+
export const msToNs = (ms: number): number => ms * NS_PER_MS;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The local clock as a wire-comparable timestamp, for building API-shaped objects.
|
|
39
|
+
*
|
|
40
|
+
* Millisecond resolution, so two calls within the same millisecond produce equal timestamps.
|
|
41
|
+
* Callers that order by timestamp must tie-break on something else.
|
|
42
|
+
*/
|
|
43
|
+
export const nowNs = (): number => msToNs(Date.now());
|
|
44
|
+
|
|
45
|
+
/** A wire timestamp as a `Date`, for request payloads and date libraries. */
|
|
46
|
+
export const nsToDate = (ns: number): Date => new Date(nsToMs(ns));
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A wire timestamp as a nanosecond-precision RFC3339 string, for an outgoing request date field.
|
|
50
|
+
* {@link nsToDate} is lossy here — `Date` holds only milliseconds.
|
|
51
|
+
*/
|
|
52
|
+
export const nsToRfc3339 = (ns: number): string => {
|
|
53
|
+
const ms = nsToMs(ns);
|
|
54
|
+
const subMs = String(ns - ms * NS_PER_MS).padStart(6, '0');
|
|
55
|
+
return new Date(ms).toISOString().replace(/\.(\d{3})Z$/, `.$1${subMs}Z`);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/** A `Date` as a wire timestamp. */
|
|
59
|
+
export const dateToNs = (date: Date): number => msToNs(date.getTime());
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* A server-sent timestamp as a `Date`, or `undefined` when there is none.
|
|
63
|
+
*
|
|
64
|
+
* The guarded companion to {@link nsToDate}, for the boundary where a wire timestamp becomes
|
|
65
|
+
* something a date library or a caller consumes. Use {@link nsToDate} when the value is known to
|
|
66
|
+
* be present; use this when it comes straight off a response, an event or persisted state.
|
|
67
|
+
*
|
|
68
|
+
* The guard is the whole point, and it covers two cases that are silent rather than loud:
|
|
69
|
+
*
|
|
70
|
+
* - **Absent.** Many timestamps are optional in practice even where the generated type marks them
|
|
71
|
+
* required. `nsToDate(undefined as never)` yields an `Invalid Date`, and `.toISOString()` on one
|
|
72
|
+
* throws `RangeError: Invalid time value`.
|
|
73
|
+
* - **Not finite.** A malformed payload or a hand-built fixture can produce `NaN`, which reaches
|
|
74
|
+
* the same `RangeError` by a different route.
|
|
75
|
+
*
|
|
76
|
+
* Returning `undefined` rather than throwing lets a caller fall back to whatever it already does
|
|
77
|
+
* for a missing timestamp.
|
|
78
|
+
*/
|
|
79
|
+
export const convertTimestampToDate = (
|
|
80
|
+
timestamp?: number | null,
|
|
81
|
+
): Date | undefined => {
|
|
82
|
+
if (timestamp == null || !Number.isFinite(timestamp)) return undefined;
|
|
83
|
+
return nsToDate(timestamp);
|
|
84
|
+
};
|