@stream-io/node-sdk 0.7.56 → 0.7.58
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/index.cjs.js +263 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.es.mjs +262 -2
- package/dist/index.es.mjs.map +1 -1
- package/dist/src/StreamClient.d.ts +32 -0
- package/dist/src/gen/feeds/FeedApi.d.ts +1 -0
- package/dist/src/gen/feeds/FeedsApi.d.ts +4 -1
- package/dist/src/gen/models/index.d.ts +49 -2
- package/dist/src/utils/webhook.d.ts +98 -0
- package/index.ts +4 -0
- package/package.json +1 -1
- package/src/StreamClient.ts +48 -0
- package/src/gen/feeds/FeedApi.ts +1 -0
- package/src/gen/feeds/FeedsApi.ts +66 -0
- package/src/gen/model-decoders/decoders.ts +14 -0
- package/src/gen/models/index.ts +63 -2
- package/src/utils/webhook.ts +206 -0
|
@@ -103,4 +103,36 @@ export declare class StreamClient extends CommonApi {
|
|
|
103
103
|
role?: string;
|
|
104
104
|
}, call_cids: string[], exp?: number, iat?: number) => string;
|
|
105
105
|
verifyWebhook: (requestBody: string | Buffer, xSignature: string) => boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Verify and parse an HTTP webhook event.
|
|
108
|
+
*
|
|
109
|
+
* Decompresses `rawBody` when gzipped (detected from the body bytes),
|
|
110
|
+
* verifies the `X-Signature` header against the app's API secret, and
|
|
111
|
+
* returns the parsed typed event. Works whether or not Stream is
|
|
112
|
+
* currently compressing payloads for this app, and stays correct behind
|
|
113
|
+
* middleware that auto-decompresses the request.
|
|
114
|
+
*
|
|
115
|
+
* @param rawBody Raw HTTP request body bytes Stream signed
|
|
116
|
+
* @param signature Value of the `X-Signature` header
|
|
117
|
+
* @throws {InvalidWebhookError} When the signature does not match or
|
|
118
|
+
* the gzip / JSON envelope is malformed.
|
|
119
|
+
*/
|
|
120
|
+
verifyAndParseWebhook: (rawBody: string | Buffer, signature: string) => import("./gen/models").WHEvent;
|
|
121
|
+
/**
|
|
122
|
+
* Parse an SQS firehose event: decodes the message `Body` (base64 +
|
|
123
|
+
* optional gzip) and returns the parsed typed event. No HMAC
|
|
124
|
+
* verification (Stream does not sign SQS bodies).
|
|
125
|
+
*
|
|
126
|
+
* @param messageBody SQS message `Body` string
|
|
127
|
+
* @throws {InvalidWebhookError} When the base64 / gzip envelope is malformed.
|
|
128
|
+
*/
|
|
129
|
+
parseSqs: (messageBody: string) => import("./gen/models").WHEvent;
|
|
130
|
+
/**
|
|
131
|
+
* Parse an SNS-delivered event (unwraps envelope JSON when needed, then
|
|
132
|
+
* same decode path as SQS). No HMAC verification.
|
|
133
|
+
*
|
|
134
|
+
* @param notificationBody Raw SNS POST body or pre-extracted `Message` string
|
|
135
|
+
* @throws {InvalidWebhookError} When the envelope cannot be decoded.
|
|
136
|
+
*/
|
|
137
|
+
parseSns: (notificationBody: string) => import("./gen/models").WHEvent;
|
|
106
138
|
}
|
|
@@ -7,6 +7,7 @@ export declare class FeedApi {
|
|
|
7
7
|
constructor(feedsApi: FeedsApi, group: string, id: string);
|
|
8
8
|
delete(request?: {
|
|
9
9
|
hard_delete?: boolean;
|
|
10
|
+
purge_user_activities?: boolean;
|
|
10
11
|
}): Promise<StreamResponse<DeleteFeedResponse>>;
|
|
11
12
|
getOrCreate(request?: GetOrCreateFeedRequest): Promise<StreamResponse<GetOrCreateFeedResponse>>;
|
|
12
13
|
update(request?: UpdateFeedRequest): Promise<StreamResponse<UpdateFeedResponse>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ApiClient, StreamResponse } from '../../gen-imports';
|
|
2
|
-
import { AcceptFeedMemberInviteRequest, AcceptFeedMemberInviteResponse, AcceptFollowRequest, AcceptFollowResponse, ActivityFeedbackRequest, ActivityFeedbackResponse, AddActivityRequest, AddActivityResponse, AddBookmarkRequest, AddBookmarkResponse, AddCommentBookmarkRequest, AddCommentBookmarkResponse, AddCommentReactionRequest, AddCommentReactionResponse, AddCommentRequest, AddCommentResponse, AddCommentsBatchRequest, AddCommentsBatchResponse, AddReactionRequest, AddReactionResponse, CastPollVoteRequest, CreateCollectionsRequest, CreateCollectionsResponse, CreateFeedGroupRequest, CreateFeedGroupResponse, CreateFeedViewRequest, CreateFeedViewResponse, CreateFeedsBatchRequest, CreateFeedsBatchResponse, CreateMembershipLevelRequest, CreateMembershipLevelResponse, DeleteActivitiesRequest, DeleteActivitiesResponse, DeleteActivityReactionResponse, DeleteActivityResponse, DeleteBookmarkFolderResponse, DeleteBookmarkResponse, DeleteCollectionsResponse, DeleteCommentBookmarkResponse, DeleteCommentReactionResponse, DeleteCommentResponse, DeleteFeedGroupResponse, DeleteFeedResponse, DeleteFeedUserDataRequest, DeleteFeedUserDataResponse, DeleteFeedViewResponse, DeleteFeedsBatchRequest, DeleteFeedsBatchResponse, ExportFeedUserDataResponse, FollowBatchRequest, FollowBatchResponse, FollowRequest, GetActivityResponse, GetCommentRepliesResponse, GetCommentResponse, GetCommentsResponse, GetFeedGroupResponse, GetFeedViewResponse, GetFeedVisibilityResponse, GetFeedsRateLimitsResponse, GetFollowSuggestionsResponse, GetOrCreateFeedGroupRequest, GetOrCreateFeedGroupResponse, GetOrCreateFeedRequest, GetOrCreateFeedResponse, GetOrCreateFeedViewRequest, GetOrCreateFeedViewResponse, ListFeedGroupsResponse, ListFeedViewsResponse, ListFeedVisibilitiesResponse, MarkActivityRequest, OwnBatchRequest, OwnBatchResponse, PinActivityRequest, PinActivityResponse, PollVoteResponse, QueryActivitiesRequest, QueryActivitiesResponse, QueryActivityReactionsRequest, QueryActivityReactionsResponse, QueryBookmarkFoldersRequest, QueryBookmarkFoldersResponse, QueryBookmarksRequest, QueryBookmarksResponse, QueryCollectionsRequest, QueryCollectionsResponse, QueryCommentReactionsRequest, QueryCommentReactionsResponse, QueryCommentsRequest, QueryCommentsResponse, QueryFeedMembersRequest, QueryFeedMembersResponse, QueryFeedsRequest, QueryFeedsResponse, QueryFeedsUsageStatsRequest, QueryFeedsUsageStatsResponse, QueryFollowsRequest, QueryFollowsResponse, QueryMembershipLevelsRequest, QueryMembershipLevelsResponse, QueryPinnedActivitiesRequest, QueryPinnedActivitiesResponse, QueryRevisionHistoryRequest, QueryRevisionHistoryResponse, ReadCollectionsResponse, RejectFeedMemberInviteRequest, RejectFeedMemberInviteResponse, RejectFollowRequest, RejectFollowResponse, Response, RestoreActivityRequest, RestoreActivityResponse, RestoreCommentRequest, RestoreCommentResponse, RestoreFeedGroupResponse, SingleFollowResponse, TrackActivityMetricsRequest, TrackActivityMetricsResponse, UnfollowBatchRequest, UnfollowBatchResponse, UnfollowResponse, UnpinActivityResponse, UpdateActivitiesPartialBatchRequest, UpdateActivitiesPartialBatchResponse, UpdateActivityPartialRequest, UpdateActivityPartialResponse, UpdateActivityRequest, UpdateActivityResponse, UpdateBookmarkFolderRequest, UpdateBookmarkFolderResponse, UpdateBookmarkRequest, UpdateBookmarkResponse, UpdateCollectionsRequest, UpdateCollectionsResponse, UpdateCommentBookmarkRequest, UpdateCommentBookmarkResponse, UpdateCommentPartialRequest, UpdateCommentPartialResponse, UpdateCommentRequest, UpdateCommentResponse, UpdateFeedGroupRequest, UpdateFeedGroupResponse, UpdateFeedMembersRequest, UpdateFeedMembersResponse, UpdateFeedRequest, UpdateFeedResponse, UpdateFeedViewRequest, UpdateFeedViewResponse, UpdateFeedVisibilityRequest, UpdateFeedVisibilityResponse, UpdateFollowRequest, UpdateFollowResponse, UpdateMembershipLevelRequest, UpdateMembershipLevelResponse, UpsertActivitiesRequest, UpsertActivitiesResponse, UpsertCollectionsRequest, UpsertCollectionsResponse } from '../models';
|
|
2
|
+
import { AcceptFeedMemberInviteRequest, AcceptFeedMemberInviteResponse, AcceptFollowRequest, AcceptFollowResponse, ActivityFeedbackRequest, ActivityFeedbackResponse, AddActivityRequest, AddActivityResponse, AddBookmarkRequest, AddBookmarkResponse, AddCommentBookmarkRequest, AddCommentBookmarkResponse, AddCommentReactionRequest, AddCommentReactionResponse, AddCommentRequest, AddCommentResponse, AddCommentsBatchRequest, AddCommentsBatchResponse, AddReactionRequest, AddReactionResponse, CastPollVoteRequest, CreateCollectionsRequest, CreateCollectionsResponse, CreateFeedGroupRequest, CreateFeedGroupResponse, CreateFeedViewRequest, CreateFeedViewResponse, CreateFeedsBatchRequest, CreateFeedsBatchResponse, CreateMembershipLevelRequest, CreateMembershipLevelResponse, DeleteActivitiesRequest, DeleteActivitiesResponse, DeleteActivityReactionResponse, DeleteActivityResponse, DeleteBookmarkFolderResponse, DeleteBookmarkResponse, DeleteCollectionsResponse, DeleteCommentBookmarkResponse, DeleteCommentReactionResponse, DeleteCommentResponse, DeleteFeedGroupResponse, DeleteFeedResponse, DeleteFeedUserDataRequest, DeleteFeedUserDataResponse, DeleteFeedViewResponse, DeleteFeedsBatchRequest, DeleteFeedsBatchResponse, ExportFeedUserDataResponse, FollowBatchRequest, FollowBatchResponse, FollowRequest, GetActivityResponse, GetCommentRepliesResponse, GetCommentResponse, GetCommentsResponse, GetFeedGroupResponse, GetFeedViewResponse, GetFeedVisibilityResponse, GetFeedsRateLimitsResponse, GetFollowSuggestionsResponse, GetOrCreateFeedGroupRequest, GetOrCreateFeedGroupResponse, GetOrCreateFeedRequest, GetOrCreateFeedResponse, GetOrCreateFeedViewRequest, GetOrCreateFeedViewResponse, GetOrCreateFollowResponse, GetOrCreateUnfollowRequest, GetOrCreateUnfollowResponse, ListFeedGroupsResponse, ListFeedViewsResponse, ListFeedVisibilitiesResponse, MarkActivityRequest, OwnBatchRequest, OwnBatchResponse, PinActivityRequest, PinActivityResponse, PollVoteResponse, QueryActivitiesRequest, QueryActivitiesResponse, QueryActivityReactionsRequest, QueryActivityReactionsResponse, QueryBookmarkFoldersRequest, QueryBookmarkFoldersResponse, QueryBookmarksRequest, QueryBookmarksResponse, QueryCollectionsRequest, QueryCollectionsResponse, QueryCommentReactionsRequest, QueryCommentReactionsResponse, QueryCommentsRequest, QueryCommentsResponse, QueryFeedMembersRequest, QueryFeedMembersResponse, QueryFeedsRequest, QueryFeedsResponse, QueryFeedsUsageStatsRequest, QueryFeedsUsageStatsResponse, QueryFollowsRequest, QueryFollowsResponse, QueryMembershipLevelsRequest, QueryMembershipLevelsResponse, QueryPinnedActivitiesRequest, QueryPinnedActivitiesResponse, QueryRevisionHistoryRequest, QueryRevisionHistoryResponse, ReadCollectionsResponse, RejectFeedMemberInviteRequest, RejectFeedMemberInviteResponse, RejectFollowRequest, RejectFollowResponse, Response, RestoreActivityRequest, RestoreActivityResponse, RestoreCommentRequest, RestoreCommentResponse, RestoreFeedGroupResponse, SingleFollowResponse, TrackActivityMetricsRequest, TrackActivityMetricsResponse, UnfollowBatchRequest, UnfollowBatchResponse, UnfollowResponse, UnpinActivityResponse, UpdateActivitiesPartialBatchRequest, UpdateActivitiesPartialBatchResponse, UpdateActivityPartialRequest, UpdateActivityPartialResponse, UpdateActivityRequest, UpdateActivityResponse, UpdateBookmarkFolderRequest, UpdateBookmarkFolderResponse, UpdateBookmarkRequest, UpdateBookmarkResponse, UpdateCollectionsRequest, UpdateCollectionsResponse, UpdateCommentBookmarkRequest, UpdateCommentBookmarkResponse, UpdateCommentPartialRequest, UpdateCommentPartialResponse, UpdateCommentRequest, UpdateCommentResponse, UpdateFeedGroupRequest, UpdateFeedGroupResponse, UpdateFeedMembersRequest, UpdateFeedMembersResponse, UpdateFeedRequest, UpdateFeedResponse, UpdateFeedViewRequest, UpdateFeedViewResponse, UpdateFeedVisibilityRequest, UpdateFeedVisibilityResponse, UpdateFollowRequest, UpdateFollowResponse, UpdateMembershipLevelRequest, UpdateMembershipLevelResponse, UpsertActivitiesRequest, UpsertActivitiesResponse, UpsertCollectionsRequest, UpsertCollectionsResponse } from '../models';
|
|
3
3
|
export declare class FeedsApi {
|
|
4
4
|
readonly apiClient: ApiClient;
|
|
5
5
|
constructor(apiClient: ApiClient);
|
|
@@ -160,6 +160,7 @@ export declare class FeedsApi {
|
|
|
160
160
|
feed_group_id: string;
|
|
161
161
|
feed_id: string;
|
|
162
162
|
hard_delete?: boolean;
|
|
163
|
+
purge_user_activities?: boolean;
|
|
163
164
|
}): Promise<StreamResponse<DeleteFeedResponse>>;
|
|
164
165
|
getOrCreateFeed(request: GetOrCreateFeedRequest & {
|
|
165
166
|
feed_group_id: string;
|
|
@@ -266,6 +267,7 @@ export declare class FeedsApi {
|
|
|
266
267
|
getOrCreateFollows(request: FollowBatchRequest): Promise<StreamResponse<FollowBatchResponse>>;
|
|
267
268
|
queryFollows(request?: QueryFollowsRequest): Promise<StreamResponse<QueryFollowsResponse>>;
|
|
268
269
|
rejectFollow(request: RejectFollowRequest): Promise<StreamResponse<RejectFollowResponse>>;
|
|
270
|
+
getOrCreateFollow(request: FollowRequest): Promise<StreamResponse<GetOrCreateFollowResponse>>;
|
|
269
271
|
unfollow(request: {
|
|
270
272
|
source: string;
|
|
271
273
|
target: string;
|
|
@@ -285,6 +287,7 @@ export declare class FeedsApi {
|
|
|
285
287
|
queryFeedsUsageStats(request?: QueryFeedsUsageStatsRequest): Promise<StreamResponse<QueryFeedsUsageStatsResponse>>;
|
|
286
288
|
unfollowBatch(request: UnfollowBatchRequest): Promise<StreamResponse<UnfollowBatchResponse>>;
|
|
287
289
|
getOrCreateUnfollows(request: UnfollowBatchRequest): Promise<StreamResponse<UnfollowBatchResponse>>;
|
|
290
|
+
getOrCreateUnfollow(request: GetOrCreateUnfollowRequest): Promise<StreamResponse<GetOrCreateUnfollowResponse>>;
|
|
288
291
|
deleteFeedUserData(request: DeleteFeedUserDataRequest & {
|
|
289
292
|
user_id: string;
|
|
290
293
|
}): Promise<StreamResponse<DeleteFeedUserDataResponse>>;
|
|
@@ -734,7 +734,7 @@ export interface ActivitySelectorConfig {
|
|
|
734
734
|
*/
|
|
735
735
|
cutoff_window?: string;
|
|
736
736
|
/**
|
|
737
|
-
* Minimum popularity threshold
|
|
737
|
+
* Minimum popularity threshold. For the 'popular' selector, omit to use the default (5); values below 1 are rejected
|
|
738
738
|
*/
|
|
739
739
|
min_popularity?: number;
|
|
740
740
|
/**
|
|
@@ -761,7 +761,7 @@ export interface ActivitySelectorConfigResponse {
|
|
|
761
761
|
*/
|
|
762
762
|
cutoff_window?: string;
|
|
763
763
|
/**
|
|
764
|
-
* Minimum popularity threshold
|
|
764
|
+
* Minimum popularity threshold. For the 'popular' selector, values below 1 are normalized to the default (5) at read time.
|
|
765
765
|
*/
|
|
766
766
|
min_popularity?: number;
|
|
767
767
|
/**
|
|
@@ -1192,6 +1192,7 @@ export interface AppResponseFields {
|
|
|
1192
1192
|
disable_auth_checks: boolean;
|
|
1193
1193
|
disable_permissions_checks: boolean;
|
|
1194
1194
|
enforce_unique_usernames: string;
|
|
1195
|
+
feed_audit_logs_enabled: boolean;
|
|
1195
1196
|
guest_user_creation_disabled: boolean;
|
|
1196
1197
|
id: number;
|
|
1197
1198
|
image_moderation_enabled: boolean;
|
|
@@ -5492,6 +5493,10 @@ export interface DeleteFeedsBatchRequest {
|
|
|
5492
5493
|
* Whether to permanently delete the feeds instead of soft delete
|
|
5493
5494
|
*/
|
|
5494
5495
|
hard_delete?: boolean;
|
|
5496
|
+
/**
|
|
5497
|
+
* When hard-deleting, also fully delete activities authored by each feed's owner from every other feed those activities were fanned out to. Default false preserves existing fan-out. Requires 'hard_delete' to be true; the request is rejected otherwise. Feeds with no recorded owner (created_by_id is empty) are silently skipped for the purge step — owner-matching against an empty string is a safety guard, not a wildcard.
|
|
5498
|
+
*/
|
|
5499
|
+
purge_user_activities?: boolean;
|
|
5495
5500
|
}
|
|
5496
5501
|
export interface DeleteFeedsBatchResponse {
|
|
5497
5502
|
duration: string;
|
|
@@ -7755,6 +7760,48 @@ export interface GetOrCreateFeedViewResponse {
|
|
|
7755
7760
|
was_created: boolean;
|
|
7756
7761
|
feed_view: FeedViewResponse;
|
|
7757
7762
|
}
|
|
7763
|
+
export interface GetOrCreateFollowResponse {
|
|
7764
|
+
/**
|
|
7765
|
+
* True if the follow was newly created by this request; false if it already existed
|
|
7766
|
+
*/
|
|
7767
|
+
created: boolean;
|
|
7768
|
+
duration: string;
|
|
7769
|
+
follow: FollowResponse;
|
|
7770
|
+
/**
|
|
7771
|
+
* Whether a notification activity was successfully created (only set when the follow was newly created)
|
|
7772
|
+
*/
|
|
7773
|
+
notification_created?: boolean;
|
|
7774
|
+
}
|
|
7775
|
+
export interface GetOrCreateUnfollowRequest {
|
|
7776
|
+
/**
|
|
7777
|
+
* Fully qualified ID of the source feed
|
|
7778
|
+
*/
|
|
7779
|
+
source: string;
|
|
7780
|
+
/**
|
|
7781
|
+
* Fully qualified ID of the target feed
|
|
7782
|
+
*/
|
|
7783
|
+
target: string;
|
|
7784
|
+
/**
|
|
7785
|
+
* Whether to delete the corresponding notification activity (default: false)
|
|
7786
|
+
*/
|
|
7787
|
+
delete_notification_activity?: boolean;
|
|
7788
|
+
/**
|
|
7789
|
+
* If true, enriches the follow's source_feed and target_feed with own_* fields (own_follows, own_followings, own_capabilities, own_membership). Defaults to false for performance.
|
|
7790
|
+
*/
|
|
7791
|
+
enrich_own_fields?: boolean;
|
|
7792
|
+
/**
|
|
7793
|
+
* When true, activities from the unfollowed feed will remain in the source feed's timeline (default: false)
|
|
7794
|
+
*/
|
|
7795
|
+
keep_history?: boolean;
|
|
7796
|
+
}
|
|
7797
|
+
export interface GetOrCreateUnfollowResponse {
|
|
7798
|
+
/**
|
|
7799
|
+
* True if a follow was found and removed by this request; false if no follow existed
|
|
7800
|
+
*/
|
|
7801
|
+
deleted: boolean;
|
|
7802
|
+
duration: string;
|
|
7803
|
+
follow?: FollowResponse;
|
|
7804
|
+
}
|
|
7758
7805
|
export interface GetPushTemplatesResponse {
|
|
7759
7806
|
/**
|
|
7760
7807
|
* Duration of the request in milliseconds
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { WHEvent } from '../gen/models';
|
|
2
|
+
/**
|
|
3
|
+
* Canonical failure-mode messages for {@link InvalidWebhookError}.
|
|
4
|
+
*
|
|
5
|
+
* Callers that prefer exact-match filtering (security logging, retry
|
|
6
|
+
* policy) over substring matches can compare `err.message` to these
|
|
7
|
+
* constants instead of pattern-matching free-form text.
|
|
8
|
+
*/
|
|
9
|
+
export declare const InvalidWebhookErrorMessages: {
|
|
10
|
+
readonly signatureMismatch: "signature mismatch";
|
|
11
|
+
readonly invalidBase64: "invalid base64 encoding";
|
|
12
|
+
readonly gzipFailed: "gzip decompression failed";
|
|
13
|
+
readonly invalidJson: "invalid JSON payload";
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Thrown by {@link verifyAndParseWebhook} when the supplied `x-signature`
|
|
17
|
+
* does not match the HMAC of the uncompressed payload, and by all webhook
|
|
18
|
+
* helpers (including {@link parseSqs} / {@link parseSns}) when a
|
|
19
|
+
* gzip / base64 / JSON envelope is malformed.
|
|
20
|
+
*
|
|
21
|
+
* The message identifies which failure mode fired. See
|
|
22
|
+
* {@link InvalidWebhookErrorMessages} for the canonical strings.
|
|
23
|
+
*/
|
|
24
|
+
export declare class InvalidWebhookError extends Error {
|
|
25
|
+
name: string;
|
|
26
|
+
constructor(message?: string);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns `body` as a `Buffer`, gzip-decompressed when its first two
|
|
30
|
+
* bytes match the gzip magic (`1f 8b`, per RFC 1952). When the body is
|
|
31
|
+
* plain JSON (no compression, or middleware already decompressed), the
|
|
32
|
+
* bytes are returned unchanged.
|
|
33
|
+
*
|
|
34
|
+
* Magic-byte detection (rather than relying on a header) keeps the same
|
|
35
|
+
* handler correct when middleware - Express, Next.js, AWS Lambda -
|
|
36
|
+
* auto-decompresses the request before your code sees it.
|
|
37
|
+
*/
|
|
38
|
+
export declare function gunzipPayload(rawBody: string | Buffer): Buffer;
|
|
39
|
+
/**
|
|
40
|
+
* Reverses the SQS firehose envelope: the message `Body` is
|
|
41
|
+
* base64-decoded, then the result is gzip-decompressed when it begins
|
|
42
|
+
* with the gzip magic. Returns the raw JSON `Buffer` Stream signed.
|
|
43
|
+
*
|
|
44
|
+
* SQS bodies are always base64-encoded so they remain valid UTF-8 over
|
|
45
|
+
* the queue. The same call works whether or not Stream is currently
|
|
46
|
+
* compressing payloads for this app.
|
|
47
|
+
*/
|
|
48
|
+
export declare function decodeSqsPayload(body: string): Buffer;
|
|
49
|
+
/**
|
|
50
|
+
* Reverses an SNS HTTP notification envelope. When `notificationBody`
|
|
51
|
+
* is a JSON envelope (`{"Type":"Notification","Message":"..."}`), the
|
|
52
|
+
* inner `Message` field is extracted and run through the SQS pipeline
|
|
53
|
+
* (base64-decode, then gzip-if-magic). When the input is not a JSON
|
|
54
|
+
* envelope it is treated as the already-extracted `Message` string,
|
|
55
|
+
* so call sites that pre-unwrap continue to work.
|
|
56
|
+
*/
|
|
57
|
+
export declare function decodeSnsPayload(notificationBody: string): Buffer;
|
|
58
|
+
/**
|
|
59
|
+
* Constant-time HMAC-SHA256 verification of `signature` against the
|
|
60
|
+
* digest of `body` using `secret` as the key. The signature is always
|
|
61
|
+
* computed over the **uncompressed** JSON bytes, so callers that
|
|
62
|
+
* decoded a gzipped or base64-wrapped payload must pass the inflated
|
|
63
|
+
* bytes here.
|
|
64
|
+
*
|
|
65
|
+
* The legacy `client.verifyWebhook` helper wraps this function, so
|
|
66
|
+
* callers that have already migrated to `verifyAndParseWebhook`,
|
|
67
|
+
* `parseSqs`, or `parseSns` rarely need to invoke this directly.
|
|
68
|
+
*/
|
|
69
|
+
export declare function verifySignature(body: string | Buffer, signature: string, secret: string): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Parse a JSON-encoded webhook event into a typed {@link WHEvent}. New
|
|
72
|
+
* event types Stream introduces still parse successfully — the runtime
|
|
73
|
+
* shape is the JSON Stream sent and the `type` field stays preserved.
|
|
74
|
+
*/
|
|
75
|
+
export declare function parseEvent(payload: Buffer | string): WHEvent;
|
|
76
|
+
/**
|
|
77
|
+
* Decompress (when gzipped), verify the HMAC `signature`, and return
|
|
78
|
+
* the parsed {@link WHEvent}.
|
|
79
|
+
*
|
|
80
|
+
* @param rawBody Raw HTTP request body bytes Stream signed
|
|
81
|
+
* @param signature Value of the `X-Signature` header
|
|
82
|
+
* @param secret Your app's API secret
|
|
83
|
+
* @throws {InvalidWebhookError} When the signature does not match or
|
|
84
|
+
* the gzip / base64 / JSON envelope is malformed.
|
|
85
|
+
*/
|
|
86
|
+
export declare function verifyAndParseWebhook(rawBody: string | Buffer, signature: string, secret: string): WHEvent;
|
|
87
|
+
/**
|
|
88
|
+
* Decode the SQS message `Body` (base64, then gzip-if-magic) and return
|
|
89
|
+
* the parsed {@link WHEvent}. Stream does not attach an application-level
|
|
90
|
+
* HMAC to SQS deliveries — use {@link verifyAndParseWebhook} for HTTP
|
|
91
|
+
* webhooks.
|
|
92
|
+
*/
|
|
93
|
+
export declare function parseSqs(messageBody: string): WHEvent;
|
|
94
|
+
/**
|
|
95
|
+
* Decode an SNS notification (unwrap the JSON envelope when needed; same
|
|
96
|
+
* inner format as SQS). No application-level HMAC verification.
|
|
97
|
+
*/
|
|
98
|
+
export declare function parseSns(notificationBody: string): WHEvent;
|
package/index.ts
CHANGED
package/package.json
CHANGED
package/src/StreamClient.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { JWTServerToken, JWTUserToken } from './utils/create-token';
|
|
2
|
+
import {
|
|
3
|
+
InvalidWebhookError,
|
|
4
|
+
parseSns as parseSnsHelper,
|
|
5
|
+
parseSqs as parseSqsHelper,
|
|
6
|
+
verifyAndParseWebhook as verifyAndParseWebhookHelper,
|
|
7
|
+
} from './utils/webhook';
|
|
2
8
|
import { CommonApi } from './gen/common/CommonApi';
|
|
3
9
|
import { StreamVideoClient } from './StreamVideoClient';
|
|
4
10
|
import crypto from 'crypto';
|
|
@@ -253,4 +259,46 @@ export class StreamClient extends CommonApi {
|
|
|
253
259
|
return false;
|
|
254
260
|
}
|
|
255
261
|
};
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Verify and parse an HTTP webhook event.
|
|
265
|
+
*
|
|
266
|
+
* Decompresses `rawBody` when gzipped (detected from the body bytes),
|
|
267
|
+
* verifies the `X-Signature` header against the app's API secret, and
|
|
268
|
+
* returns the parsed typed event. Works whether or not Stream is
|
|
269
|
+
* currently compressing payloads for this app, and stays correct behind
|
|
270
|
+
* middleware that auto-decompresses the request.
|
|
271
|
+
*
|
|
272
|
+
* @param rawBody Raw HTTP request body bytes Stream signed
|
|
273
|
+
* @param signature Value of the `X-Signature` header
|
|
274
|
+
* @throws {InvalidWebhookError} When the signature does not match or
|
|
275
|
+
* the gzip / JSON envelope is malformed.
|
|
276
|
+
*/
|
|
277
|
+
verifyAndParseWebhook = (rawBody: string | Buffer, signature: string) => {
|
|
278
|
+
if (!this.secret) {
|
|
279
|
+
throw new InvalidWebhookError(
|
|
280
|
+
'cannot verify webhook signature without an API secret on the client',
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
return verifyAndParseWebhookHelper(rawBody, signature, this.secret);
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Parse an SQS firehose event: decodes the message `Body` (base64 +
|
|
288
|
+
* optional gzip) and returns the parsed typed event. No HMAC
|
|
289
|
+
* verification (Stream does not sign SQS bodies).
|
|
290
|
+
*
|
|
291
|
+
* @param messageBody SQS message `Body` string
|
|
292
|
+
* @throws {InvalidWebhookError} When the base64 / gzip envelope is malformed.
|
|
293
|
+
*/
|
|
294
|
+
parseSqs = (messageBody: string) => parseSqsHelper(messageBody);
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Parse an SNS-delivered event (unwraps envelope JSON when needed, then
|
|
298
|
+
* same decode path as SQS). No HMAC verification.
|
|
299
|
+
*
|
|
300
|
+
* @param notificationBody Raw SNS POST body or pre-extracted `Message` string
|
|
301
|
+
* @throws {InvalidWebhookError} When the envelope cannot be decoded.
|
|
302
|
+
*/
|
|
303
|
+
parseSns = (notificationBody: string) => parseSnsHelper(notificationBody);
|
|
256
304
|
}
|
package/src/gen/feeds/FeedApi.ts
CHANGED
|
@@ -67,6 +67,9 @@ import {
|
|
|
67
67
|
GetOrCreateFeedResponse,
|
|
68
68
|
GetOrCreateFeedViewRequest,
|
|
69
69
|
GetOrCreateFeedViewResponse,
|
|
70
|
+
GetOrCreateFollowResponse,
|
|
71
|
+
GetOrCreateUnfollowRequest,
|
|
72
|
+
GetOrCreateUnfollowResponse,
|
|
70
73
|
ListFeedGroupsResponse,
|
|
71
74
|
ListFeedViewsResponse,
|
|
72
75
|
ListFeedVisibilitiesResponse,
|
|
@@ -1545,9 +1548,11 @@ export class FeedsApi {
|
|
|
1545
1548
|
feed_group_id: string;
|
|
1546
1549
|
feed_id: string;
|
|
1547
1550
|
hard_delete?: boolean;
|
|
1551
|
+
purge_user_activities?: boolean;
|
|
1548
1552
|
}): Promise<StreamResponse<DeleteFeedResponse>> {
|
|
1549
1553
|
const queryParams = {
|
|
1550
1554
|
hard_delete: request?.hard_delete,
|
|
1555
|
+
purge_user_activities: request?.purge_user_activities,
|
|
1551
1556
|
};
|
|
1552
1557
|
const pathParams = {
|
|
1553
1558
|
feed_group_id: request?.feed_group_id,
|
|
@@ -2275,6 +2280,7 @@ export class FeedsApi {
|
|
|
2275
2280
|
const body = {
|
|
2276
2281
|
feeds: request?.feeds,
|
|
2277
2282
|
hard_delete: request?.hard_delete,
|
|
2283
|
+
purge_user_activities: request?.purge_user_activities,
|
|
2278
2284
|
};
|
|
2279
2285
|
|
|
2280
2286
|
const response = await this.apiClient.sendRequest<
|
|
@@ -2565,6 +2571,39 @@ export class FeedsApi {
|
|
|
2565
2571
|
return { ...response.body, metadata: response.metadata };
|
|
2566
2572
|
}
|
|
2567
2573
|
|
|
2574
|
+
async getOrCreateFollow(
|
|
2575
|
+
request: FollowRequest,
|
|
2576
|
+
): Promise<StreamResponse<GetOrCreateFollowResponse>> {
|
|
2577
|
+
const body = {
|
|
2578
|
+
source: request?.source,
|
|
2579
|
+
target: request?.target,
|
|
2580
|
+
activity_copy_limit: request?.activity_copy_limit,
|
|
2581
|
+
copy_custom_to_notification: request?.copy_custom_to_notification,
|
|
2582
|
+
create_notification_activity: request?.create_notification_activity,
|
|
2583
|
+
create_users: request?.create_users,
|
|
2584
|
+
enrich_own_fields: request?.enrich_own_fields,
|
|
2585
|
+
push_preference: request?.push_preference,
|
|
2586
|
+
skip_push: request?.skip_push,
|
|
2587
|
+
status: request?.status,
|
|
2588
|
+
custom: request?.custom,
|
|
2589
|
+
};
|
|
2590
|
+
|
|
2591
|
+
const response = await this.apiClient.sendRequest<
|
|
2592
|
+
StreamResponse<GetOrCreateFollowResponse>
|
|
2593
|
+
>(
|
|
2594
|
+
'POST',
|
|
2595
|
+
'/api/v2/feeds/follows/upsert',
|
|
2596
|
+
undefined,
|
|
2597
|
+
undefined,
|
|
2598
|
+
body,
|
|
2599
|
+
'application/json',
|
|
2600
|
+
);
|
|
2601
|
+
|
|
2602
|
+
decoders.GetOrCreateFollowResponse?.(response.body);
|
|
2603
|
+
|
|
2604
|
+
return { ...response.body, metadata: response.metadata };
|
|
2605
|
+
}
|
|
2606
|
+
|
|
2568
2607
|
async unfollow(request: {
|
|
2569
2608
|
source: string;
|
|
2570
2609
|
target: string;
|
|
@@ -2801,6 +2840,33 @@ export class FeedsApi {
|
|
|
2801
2840
|
return { ...response.body, metadata: response.metadata };
|
|
2802
2841
|
}
|
|
2803
2842
|
|
|
2843
|
+
async getOrCreateUnfollow(
|
|
2844
|
+
request: GetOrCreateUnfollowRequest,
|
|
2845
|
+
): Promise<StreamResponse<GetOrCreateUnfollowResponse>> {
|
|
2846
|
+
const body = {
|
|
2847
|
+
source: request?.source,
|
|
2848
|
+
target: request?.target,
|
|
2849
|
+
delete_notification_activity: request?.delete_notification_activity,
|
|
2850
|
+
enrich_own_fields: request?.enrich_own_fields,
|
|
2851
|
+
keep_history: request?.keep_history,
|
|
2852
|
+
};
|
|
2853
|
+
|
|
2854
|
+
const response = await this.apiClient.sendRequest<
|
|
2855
|
+
StreamResponse<GetOrCreateUnfollowResponse>
|
|
2856
|
+
>(
|
|
2857
|
+
'POST',
|
|
2858
|
+
'/api/v2/feeds/unfollow/upsert',
|
|
2859
|
+
undefined,
|
|
2860
|
+
undefined,
|
|
2861
|
+
body,
|
|
2862
|
+
'application/json',
|
|
2863
|
+
);
|
|
2864
|
+
|
|
2865
|
+
decoders.GetOrCreateUnfollowResponse?.(response.body);
|
|
2866
|
+
|
|
2867
|
+
return { ...response.body, metadata: response.metadata };
|
|
2868
|
+
}
|
|
2869
|
+
|
|
2804
2870
|
async deleteFeedUserData(
|
|
2805
2871
|
request: DeleteFeedUserDataRequest & { user_id: string },
|
|
2806
2872
|
): Promise<StreamResponse<DeleteFeedUserDataResponse>> {
|
|
@@ -2767,6 +2767,20 @@ decoders.GetOrCreateFeedViewResponse = (input?: Record<string, any>) => {
|
|
|
2767
2767
|
return decode(typeMappings, input);
|
|
2768
2768
|
};
|
|
2769
2769
|
|
|
2770
|
+
decoders.GetOrCreateFollowResponse = (input?: Record<string, any>) => {
|
|
2771
|
+
const typeMappings: TypeMapping = {
|
|
2772
|
+
follow: { type: 'FollowResponse', isSingle: true },
|
|
2773
|
+
};
|
|
2774
|
+
return decode(typeMappings, input);
|
|
2775
|
+
};
|
|
2776
|
+
|
|
2777
|
+
decoders.GetOrCreateUnfollowResponse = (input?: Record<string, any>) => {
|
|
2778
|
+
const typeMappings: TypeMapping = {
|
|
2779
|
+
follow: { type: 'FollowResponse', isSingle: true },
|
|
2780
|
+
};
|
|
2781
|
+
return decode(typeMappings, input);
|
|
2782
|
+
};
|
|
2783
|
+
|
|
2770
2784
|
decoders.GetPushTemplatesResponse = (input?: Record<string, any>) => {
|
|
2771
2785
|
const typeMappings: TypeMapping = {
|
|
2772
2786
|
templates: { type: 'PushTemplateResponse', isSingle: false },
|
package/src/gen/models/index.ts
CHANGED
|
@@ -1041,7 +1041,7 @@ export interface ActivitySelectorConfig {
|
|
|
1041
1041
|
cutoff_window?: string;
|
|
1042
1042
|
|
|
1043
1043
|
/**
|
|
1044
|
-
* Minimum popularity threshold
|
|
1044
|
+
* Minimum popularity threshold. For the 'popular' selector, omit to use the default (5); values below 1 are rejected
|
|
1045
1045
|
*/
|
|
1046
1046
|
min_popularity?: number;
|
|
1047
1047
|
|
|
@@ -1083,7 +1083,7 @@ export interface ActivitySelectorConfigResponse {
|
|
|
1083
1083
|
cutoff_window?: string;
|
|
1084
1084
|
|
|
1085
1085
|
/**
|
|
1086
|
-
* Minimum popularity threshold
|
|
1086
|
+
* Minimum popularity threshold. For the 'popular' selector, values below 1 are normalized to the default (5) at read time.
|
|
1087
1087
|
*/
|
|
1088
1088
|
min_popularity?: number;
|
|
1089
1089
|
|
|
@@ -1656,6 +1656,8 @@ export interface AppResponseFields {
|
|
|
1656
1656
|
|
|
1657
1657
|
enforce_unique_usernames: string;
|
|
1658
1658
|
|
|
1659
|
+
feed_audit_logs_enabled: boolean;
|
|
1660
|
+
|
|
1659
1661
|
guest_user_creation_disabled: boolean;
|
|
1660
1662
|
|
|
1661
1663
|
id: number;
|
|
@@ -7896,6 +7898,11 @@ export interface DeleteFeedsBatchRequest {
|
|
|
7896
7898
|
* Whether to permanently delete the feeds instead of soft delete
|
|
7897
7899
|
*/
|
|
7898
7900
|
hard_delete?: boolean;
|
|
7901
|
+
|
|
7902
|
+
/**
|
|
7903
|
+
* When hard-deleting, also fully delete activities authored by each feed's owner from every other feed those activities were fanned out to. Default false preserves existing fan-out. Requires 'hard_delete' to be true; the request is rejected otherwise. Feeds with no recorded owner (created_by_id is empty) are silently skipped for the purge step — owner-matching against an empty string is a safety guard, not a wildcard.
|
|
7904
|
+
*/
|
|
7905
|
+
purge_user_activities?: boolean;
|
|
7899
7906
|
}
|
|
7900
7907
|
|
|
7901
7908
|
export interface DeleteFeedsBatchResponse {
|
|
@@ -11158,6 +11165,60 @@ export interface GetOrCreateFeedViewResponse {
|
|
|
11158
11165
|
feed_view: FeedViewResponse;
|
|
11159
11166
|
}
|
|
11160
11167
|
|
|
11168
|
+
export interface GetOrCreateFollowResponse {
|
|
11169
|
+
/**
|
|
11170
|
+
* True if the follow was newly created by this request; false if it already existed
|
|
11171
|
+
*/
|
|
11172
|
+
created: boolean;
|
|
11173
|
+
|
|
11174
|
+
duration: string;
|
|
11175
|
+
|
|
11176
|
+
follow: FollowResponse;
|
|
11177
|
+
|
|
11178
|
+
/**
|
|
11179
|
+
* Whether a notification activity was successfully created (only set when the follow was newly created)
|
|
11180
|
+
*/
|
|
11181
|
+
notification_created?: boolean;
|
|
11182
|
+
}
|
|
11183
|
+
|
|
11184
|
+
export interface GetOrCreateUnfollowRequest {
|
|
11185
|
+
/**
|
|
11186
|
+
* Fully qualified ID of the source feed
|
|
11187
|
+
*/
|
|
11188
|
+
source: string;
|
|
11189
|
+
|
|
11190
|
+
/**
|
|
11191
|
+
* Fully qualified ID of the target feed
|
|
11192
|
+
*/
|
|
11193
|
+
target: string;
|
|
11194
|
+
|
|
11195
|
+
/**
|
|
11196
|
+
* Whether to delete the corresponding notification activity (default: false)
|
|
11197
|
+
*/
|
|
11198
|
+
delete_notification_activity?: boolean;
|
|
11199
|
+
|
|
11200
|
+
/**
|
|
11201
|
+
* If true, enriches the follow's source_feed and target_feed with own_* fields (own_follows, own_followings, own_capabilities, own_membership). Defaults to false for performance.
|
|
11202
|
+
*/
|
|
11203
|
+
enrich_own_fields?: boolean;
|
|
11204
|
+
|
|
11205
|
+
/**
|
|
11206
|
+
* When true, activities from the unfollowed feed will remain in the source feed's timeline (default: false)
|
|
11207
|
+
*/
|
|
11208
|
+
keep_history?: boolean;
|
|
11209
|
+
}
|
|
11210
|
+
|
|
11211
|
+
export interface GetOrCreateUnfollowResponse {
|
|
11212
|
+
/**
|
|
11213
|
+
* True if a follow was found and removed by this request; false if no follow existed
|
|
11214
|
+
*/
|
|
11215
|
+
deleted: boolean;
|
|
11216
|
+
|
|
11217
|
+
duration: string;
|
|
11218
|
+
|
|
11219
|
+
follow?: FollowResponse;
|
|
11220
|
+
}
|
|
11221
|
+
|
|
11161
11222
|
export interface GetPushTemplatesResponse {
|
|
11162
11223
|
/**
|
|
11163
11224
|
* Duration of the request in milliseconds
|