Skip to content

Commit

Permalink
feat: add users and objects listing (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbell authored Oct 24, 2022
1 parent 55d0cfb commit bd2e1ea
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/resources/objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import {
ChannelType,
} from "../../common/interfaces";
import { Knock } from "../../knock";
import { BulkSetObjectOption, Object, SetObjectProperties } from "./interfaces";
import {
BulkSetObjectOption,
ListObjectOptions,
Object,
SetObjectProperties,
} from "./interfaces";
import { BulkOperation } from "../bulk_operations/interfaces";
import { ListMessagesOptions, Message } from "../messages/interfaces";
import {
Expand Down Expand Up @@ -45,6 +50,17 @@ export class Objects {
return data;
}

async list<T = CommonMetadata>(
collection: string,
filteringOptions: ListObjectOptions = {},
): Promise<PaginatedResponse<Object<T>>> {
const { data } = await this.knock.get(
`/v1/objects/${collection}`,
filteringOptions,
);
return data;
}

async bulkSet(
collection: string,
objects: BulkSetObjectOption[],
Expand Down
7 changes: 6 additions & 1 deletion src/resources/objects/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CommonMetadata } from "../../common/interfaces";
import { CommonMetadata, PaginationOptions } from "../../common/interfaces";

export interface ObjectRef {
collection: string;
Expand All @@ -23,3 +23,8 @@ export interface BulkSetObjectOption {
name?: string;
[key: string]: any;
}

export interface ListObjectOptions extends PaginationOptions {
object_id?: string;
name?: string;
}
8 changes: 8 additions & 0 deletions src/resources/users/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { Knock } from "../../knock";
import {
BulkIdentifyUser,
IdentifyProperties,
ListUserOptions,
User,
UserFeedOptions,
} from "./interfaces";
Expand Down Expand Up @@ -63,6 +64,13 @@ export class Users {
return data;
}

async list(
filteringOptions: ListUserOptions = {},
): Promise<PaginatedResponse<User>> {
const { data } = await this.knock.get(`/v1/users`, filteringOptions);
return data;
}

async delete(userId: string): Promise<null> {
if (!userId) {
throw new Error(`Incomplete arguments. You must provide a 'userId'`);
Expand Down
6 changes: 6 additions & 0 deletions src/resources/users/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ export interface UserFeedOptions extends PaginationOptions {
archived?: "include" | "exclude" | "only";
status?: "unread" | "unseen" | "all";
}

export interface ListUserOptions extends PaginationOptions {
name?: string;
email?: string;
user_id?: string;
}

0 comments on commit bd2e1ea

Please sign in to comment.