Skip to content
4 changes: 2 additions & 2 deletions __tests__/agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe.skip('AI agent integration', () => {
const [, agent] = await createTestStreamAndRealtimeClients();
let errorEvent: any = null;

agent.on('realtime.event', ({ event }) => {
agent.on('realtime.event', ({ event }: { event: any }) => {
if (event.type === 'error') {
errorEvent = event;
}
Expand Down Expand Up @@ -147,7 +147,7 @@ describe.skip('AI agent integration', () => {
required: ['lat', 'lng', 'location'],
},
},
async ({ lat, lng }) => {
async ({ lat, lng }: { lat: number; lng: number }) => {
const result = await fetch(
`https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lng}&current=temperature_2m,wind_speed_10m`,
);
Expand Down
27 changes: 13 additions & 14 deletions __tests__/date-transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { randomUUID } from 'crypto';
import { createTestClient } from './create-test-client';
import { StreamClient } from '../src/StreamClient';
import { UserRequest } from '../src/gen/models';
import { nsToDate, nsToMs } from '../src/utils/time';

describe('Date conversion', () => {
describe('dates on responses', () => {
let client: StreamClient;
const user = {
id: 'stream-node-test-user',
Expand Down Expand Up @@ -36,18 +37,18 @@ describe('Date conversion', () => {

const createdAt = response.call.created_at;

expect(createdAt instanceof Date).toBe(true);
expect(now - createdAt.getTime()).toBeLessThan(oneMin);
expect(typeof createdAt).toBe('number');
expect(now - nsToMs(createdAt)).toBeLessThan(oneMin);

expect(response.call.starts_at instanceof Date).toBe(true);
expect(startsAt.getTime()).toEqual(response.call.starts_at?.getTime());
expect(typeof response.call.starts_at).toBe('number');
expect(startsAt.getTime()).toEqual(nsToMs(response.call.starts_at!));

expect(response.call.ended_at).toBeNull();

expect(response.members.length).toBeGreaterThan(0);

response.members.forEach((m) => {
expect(m.created_at instanceof Date).toBe(true);
expect(typeof m.created_at).toBe('number');
});

const queryResult = await client.video.queryCalls({
Expand Down Expand Up @@ -75,28 +76,26 @@ describe('Date conversion', () => {

const createdAt = response.channel!.created_at;

expect(createdAt instanceof Date).toBe(true);
expect(now - createdAt.getTime()).toBeLessThan(oneMin);
expect(typeof createdAt).toBe('number');
expect(now - nsToMs(createdAt)).toBeLessThan(oneMin);

expect(response.channel!.deleted_at).toBeUndefined();

expect(response.members.length).toBeGreaterThan(0);

response.members.forEach((m) => {
expect(m.created_at instanceof Date).toBe(true);
expect(typeof m.created_at).toBe('number');
});

const queryResult = await client.chat.queryChannels({
filter_conditions: {
created_at: { $lte: createdAt.toISOString() },
created_at: { $lte: nsToDate(createdAt).toISOString() },
},
limit: 10,
});

queryResult.channels.forEach((c) => {
expect(c.channel!.created_at.getTime()).toBeLessThanOrEqual(
createdAt.getTime(),
);
expect(c.channel!.created_at).toBeLessThanOrEqual(createdAt);
});

await channel.delete();
Expand All @@ -113,7 +112,7 @@ describe('Date conversion', () => {

const response = await client.upsertUsers([newUser]);

expect(response.users[newUser.id].created_at instanceof Date).toBe(true);
expect(typeof response.users[newUser.id].created_at).toBe('number');

expect(
typeof response.users[newUser.id].custom.created_at === 'string',
Expand Down
4 changes: 2 additions & 2 deletions __tests__/devices-push.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { beforeAll, describe, expect, it } from 'vitest';
import { randomUUID } from 'crypto';
import { createTestClient } from './create-test-client';
import { StreamClient } from '../src/StreamClient';
import { CreateDeviceRequest, PushProvider } from '../src/gen/models';
import { CreateDeviceRequest, PushProviderRequest } from '../src/gen/models';

describe('devices and push', () => {
let client: StreamClient;
Expand All @@ -16,7 +16,7 @@ describe('devices and push', () => {
push_provider_name: 'firebase',
user_id: user.id,
};
const pushProvider: PushProvider = {
const pushProvider: PushProviderRequest = {
name: 'test-push-provider',
type: 'xiaomi',
xiaomi_app_secret: '',
Expand Down
2 changes: 0 additions & 2 deletions __tests__/messages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ describe('messages API', () => {
});

it('thread replies', async () => {
const now = new Date();
const response = await channel.sendMessage({
message: {
text: 'Hello from Stream Node SDK',
Expand All @@ -77,7 +76,6 @@ describe('messages API', () => {

const getResponse = await client.chat.getReplies({
parent_id: response.message.id,
created_at_after: now,
});

expect(
Expand Down
7 changes: 5 additions & 2 deletions __tests__/rate-limit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { beforeAll, describe, expect, it } from 'vitest';
import { createTestClient } from './create-test-client';
import { StreamClient } from '../src/StreamClient';
import { StreamError } from '../src/types';

describe('rate limit', () => {
let client: StreamClient;
Expand Down Expand Up @@ -61,12 +62,14 @@ describe('rate limit', () => {
try {
await call.startTranscription();
throw new Error(`Method didn't throw`);
} catch (error) {
} catch (err) {
const error = err as StreamError;

expect(error.code).toBeDefined();
expect(error.metadata).toBeDefined();
expect(error.metadata.responseCode).toBe(404);

const rateLimit = error.metadata.rateLimit;
const rateLimit = error.metadata.rateLimit!;

expect(rateLimit.rateLimit).toBeDefined();
}
Expand Down
2 changes: 1 addition & 1 deletion generate-openapi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ CHAT_DIR="../chat"

rm -rf $OUTPUT_DIR

( cd $CHAT_DIR ; make openapi ; make -C tools/openapi build ; ./build/openapi generate-client --language ts --spec ./releases/v2/serverside-api.yaml --output $OUTPUT_DIR )
( cd $CHAT_DIR ; make openapi ; make -C tools/openapi build ; ./build/openapi generate-client --language ts --spec ./releases/v2/serverside-api.yaml --opt response_dates_as_number=true --output $OUTPUT_DIR )

yarn lint:gen
10 changes: 10 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,13 @@ export {
InvalidWebhookError,
InvalidWebhookErrorMessages,
} from './src/utils/webhook';
export {
convertTimestampToDate,
dateToNs,
msToNs,
nowNs,
NS_PER_MS,
nsToDate,
nsToMs,
nsToRfc3339,
} from './src/utils/time';
18 changes: 18 additions & 0 deletions src/gen/chat/ChannelApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
MarkReadRequest,
MarkReadResponse,
MarkUnreadRequest,
QueryChannelBansRequest,
QueryChannelBansResponse,
Response,
SendEventRequest,
SendMessageRequest,
Expand Down Expand Up @@ -114,6 +116,22 @@ export class ChannelApi {
});
}

queryChannelBans(
request?: QueryChannelBansRequest,
): Promise<StreamResponse<QueryChannelBansResponse>> {
if (!this.id) {
throw new Error(
`Channel isn't yet created, call getOrCreateDistinctChannel() before this operation`,
);
}

return this.chatApi.queryChannelBans({
id: this.id,
type: this.type,
...request,
});
}

deleteDraft(request?: {
parent_id?: string;
user_id?: string;
Expand Down
36 changes: 36 additions & 0 deletions src/gen/chat/ChatApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ import {
QueryBannedUsersResponse,
QueryCampaignsRequest,
QueryCampaignsResponse,
QueryChannelBansRequest,
QueryChannelBansResponse,
QueryChannelsRequest,
QueryChannelsResponse,
QueryDraftsRequest,
Expand Down Expand Up @@ -452,6 +454,7 @@ export class ChatApi {
const body = {
limit: request?.limit,
user_id: request?.user_id,
sort: request?.sort,
groups: request?.groups,
user: request?.user,
};
Expand Down Expand Up @@ -661,6 +664,37 @@ export class ChatApi {
return response;
}

async queryChannelBans(
request: QueryChannelBansRequest & { type: string; id: string },
): Promise<StreamResponse<QueryChannelBansResponse>> {
const pathParams = {
type: request?.type,
id: request?.id,
};
const body = {
exclude_expired_bans: request?.exclude_expired_bans,
include_total: request?.include_total,
limit: request?.limit,
next: request?.next,
prev: request?.prev,
user_id: request?.user_id,
filter_conditions: request?.filter_conditions,
user: request?.user,
};

const response = await this.apiClient.sendRequest<QueryChannelBansResponse>(
'POST',
'/api/v2/chat/channels/{type}/{id}/bans/query',
pathParams,
undefined,
body,
);

decoders['QueryChannelBansResponse']?.(response);

return response;
}

async deleteDraft(request: {
type: string;
id: string;
Expand Down Expand Up @@ -1854,6 +1888,8 @@ export class ChatApi {
poll_id: request?.poll_id,
};
const body = {
config_key: request?.config_key,
config_team: request?.config_team,
user_id: request?.user_id,
user: request?.user,
vote: request?.vote,
Expand Down
10 changes: 10 additions & 0 deletions src/gen/common/CommonApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,8 @@ export class CommonApi {
name: request?.name,
allow_answers: request?.allow_answers,
allow_user_suggested_options: request?.allow_user_suggested_options,
config_key: request?.config_key,
config_team: request?.config_team,
description: request?.description,
enforce_unique_vote: request?.enforce_unique_vote,
id: request?.id,
Expand Down Expand Up @@ -1105,6 +1107,8 @@ export class CommonApi {
name: request?.name,
allow_answers: request?.allow_answers,
allow_user_suggested_options: request?.allow_user_suggested_options,
config_key: request?.config_key,
config_team: request?.config_team,
description: request?.description,
enforce_unique_vote: request?.enforce_unique_vote,
is_closed: request?.is_closed,
Expand Down Expand Up @@ -1209,6 +1213,8 @@ export class CommonApi {
poll_id: request?.poll_id,
};
const body = {
config_key: request?.config_key,
config_team: request?.config_team,
user_id: request?.user_id,
unset: request?.unset,
set: request?.set,
Expand Down Expand Up @@ -1236,6 +1242,8 @@ export class CommonApi {
};
const body = {
text: request?.text,
config_key: request?.config_key,
config_team: request?.config_team,
user_id: request?.user_id,
custom: request?.custom,
user: request?.user,
Expand Down Expand Up @@ -1263,6 +1271,8 @@ export class CommonApi {
const body = {
id: request?.id,
text: request?.text,
config_key: request?.config_key,
config_team: request?.config_team,
user_id: request?.user_id,
custom: request?.custom,
user: request?.user,
Expand Down
10 changes: 10 additions & 0 deletions src/gen/feeds/FeedsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export class FeedsApi {
poll_id: request?.poll_id,
restrict_replies: request?.restrict_replies,
skip_enrich_url: request?.skip_enrich_url,
skip_existing: request?.skip_existing,
skip_push: request?.skip_push,
text: request?.text,
user_id: request?.user_id,
Expand Down Expand Up @@ -246,6 +247,7 @@ export class FeedsApi {
create_users: request?.create_users,
enrich_own_fields: request?.enrich_own_fields,
force_moderation: request?.force_moderation,
skip_existing: request?.skip_existing,
};

const response = await this.apiClient.sendRequest<UpsertActivitiesResponse>(
Expand Down Expand Up @@ -511,6 +513,8 @@ export class FeedsApi {
poll_id: request?.poll_id,
};
const body = {
config_key: request?.config_key,
config_team: request?.config_team,
user_id: request?.user_id,
user: request?.user,
vote: request?.vote,
Expand Down Expand Up @@ -975,9 +979,11 @@ export class FeedsApi {

async deleteCollections(request: {
collection_refs: Array<string>;
hard_delete?: boolean;
}): Promise<StreamResponse<DeleteCollectionsResponse>> {
const queryParams = {
collection_refs: request?.collection_refs,
hard_delete: request?.hard_delete,
};

const response =
Expand Down Expand Up @@ -2697,6 +2703,7 @@ export class FeedsApi {
): Promise<StreamResponse<FollowBatchResponse>> {
const body = {
follows: request?.follows,
async: request?.async,
create_users: request?.create_users,
enrich_own_fields: request?.enrich_own_fields,
};
Expand All @@ -2719,6 +2726,7 @@ export class FeedsApi {
): Promise<StreamResponse<FollowBatchResponse>> {
const body = {
follows: request?.follows,
async: request?.async,
create_users: request?.create_users,
enrich_own_fields: request?.enrich_own_fields,
};
Expand Down Expand Up @@ -3077,6 +3085,7 @@ export class FeedsApi {
): Promise<StreamResponse<UnfollowBatchResponse>> {
const body = {
follows: request?.follows,
async: request?.async,
delete_notification_activity: request?.delete_notification_activity,
enrich_own_fields: request?.enrich_own_fields,
};
Expand All @@ -3099,6 +3108,7 @@ export class FeedsApi {
): Promise<StreamResponse<UnfollowBatchResponse>> {
const body = {
follows: request?.follows,
async: request?.async,
delete_notification_activity: request?.delete_notification_activity,
enrich_own_fields: request?.enrich_own_fields,
};
Expand Down
Loading
Loading