这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
343 changes: 212 additions & 131 deletions clients/ts-sdk/openapi.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion clients/ts-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"files": [
"dist"
],
"version": "0.0.33",
"version": "0.0.34",
"license": "MIT",
"scripts": {
"lint": "eslint 'src/**/*.ts'",
Expand Down
2 changes: 2 additions & 0 deletions clients/ts-sdk/src/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as fileMethods from "./file/index";
import * as eventsMethods from "./events/index";
import * as datasetsMethods from "./datasets/index";
import * as userMethods from "./user/index";
import * as organizationMethods from "./organization/index";

export default {
...chunkMethods,
Expand All @@ -18,4 +19,5 @@ export default {
...eventsMethods,
...datasetsMethods,
...userMethods,
...organizationMethods,
};
53 changes: 53 additions & 0 deletions clients/ts-sdk/src/functions/organization/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* This includes all the functions you can use to communicate with our organization endpoint
*
* @module Organization Methods
*/

import { TrieveSDK } from "../../sdk";
import { CreateApiKeyReqPayload, CreateApiKeyResponse } from "../../types.gen";

export async function createOrganizationApiKey(
/** @hidden */
this: TrieveSDK,
props: CreateApiKeyReqPayload,
signal?: AbortSignal,
): Promise<CreateApiKeyResponse> {
if (!this.organizationId) {
throw new Error(
"Organization ID is required to create Organization API key",
);
}

return this.trieve.fetch(
"/api/organization/api_key",
"post",
{
data: props,
organizationId: this.organizationId,
},
signal,
);
}

export async function deleteOrganizationApiKey(
/** @hidden */
this: TrieveSDK,
apiKeyId: string,
signal?: AbortSignal,
): Promise<void> {
if (!this.organizationId) {
throw new Error(
"Organization ID is required to delete Organization API key",
);
}
return this.trieve.fetch(
"/api/organization/api_key/{api_key_id}",
"delete",
{
apiKeyId,
organizationId: this.organizationId,
},
signal,
);
}
134 changes: 134 additions & 0 deletions clients/ts-sdk/src/functions/organization/organization.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import { describe, beforeAll, test, expectTypeOf, expect } from "vitest";
import { TRIEVE } from "../../__tests__/constants";
import { TrieveSDK } from "../../sdk";
import { CreateApiKeyResponse, ReturnQueuedChunk } from "../../types.gen";

describe("Organization Tests", async () => {
let trieve: TrieveSDK;
beforeAll(() => {
trieve = TRIEVE;
});

test("create an api key and verify it works", async () => {
const apiKeyResponse = await trieve.createOrganizationApiKey({
role: 1,
name: "test suite key",
});

expectTypeOf(apiKeyResponse).toEqualTypeOf<CreateApiKeyResponse>();

const newTrieve = new TrieveSDK({
apiKey: apiKeyResponse.api_key,
datasetId: trieve.datasetId,
});

const queuedChunk = await newTrieve.createChunk({
chunk_html: "testing hello world",
tracking_id: "1234",
tag_set: ["test"],
});

expectTypeOf(queuedChunk).toEqualTypeOf<ReturnQueuedChunk>();

newTrieve.deleteChunkByTrackingId({
trackingId: "1234",
});
});

test("create an expired api key and verify it does not work", async () => {
const apiKeyResponse = await trieve.createOrganizationApiKey({
expires_at: new Date(new Date().setDate(new Date().getDate() - 1))
.toISOString()
.slice(0, 19)
.replace("T", " "),
role: 1,
name: "test suite key",
});

expectTypeOf(apiKeyResponse).toEqualTypeOf<CreateApiKeyResponse>();

let errorOccurred = false;

const newTrieve = new TrieveSDK({
apiKey: apiKeyResponse.api_key,
datasetId: trieve.datasetId,
});

try {
await newTrieve.createChunk({
chunk_html: "testing hello world",
tracking_id: "should_never_work",
tag_set: ["test"],
});

newTrieve.deleteChunkByTrackingId({
trackingId: "should_never_work",
});
} catch (e) {
errorOccurred = true;
}

expect(errorOccurred).toBe(true);
});

test("create an api key with a filter for test and verify it excludes chunks without the tag", async () => {
const apiKeyResponse = await trieve.createOrganizationApiKey({
role: 1,
name: "test suite key",
default_params: {
filters: {
must: [
{
field: "tag_set",
match_all: ["test"],
},
],
},
},
});

expectTypeOf(apiKeyResponse).toEqualTypeOf<CreateApiKeyResponse>();

const newTrieve = new TrieveSDK({
apiKey: apiKeyResponse.api_key,
datasetId: trieve.datasetId,
});

const queuedChunks = await newTrieve.createChunk([
{
chunk_html: "testing hello world",
tracking_id: "not_test",
tag_set: ["not_test"],
},
{
chunk_html: "testing hello world",
tracking_id: "test",
tag_set: ["test"],
},
]);

expectTypeOf(queuedChunks).toEqualTypeOf<ReturnQueuedChunk>();

await new Promise((r) => setTimeout(r, 10000));

const chunksResp = await newTrieve.scroll({
page_size: 100,
filters: {
must: [
{
field: "tag_set",
match_all: ["not_test"],
},
],
},
});

for (const chunk of chunksResp.chunks) {
expect(chunk.tag_set).toContain("test");
}

newTrieve.deleteChunkByTrackingId({
trackingId: "1234",
});
});
});
37 changes: 0 additions & 37 deletions clients/ts-sdk/src/functions/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

import { TrieveSDK } from "../../sdk";
import {
CreateApiKeyReqPayload,
CreateApiKeyResponse,
UpdateUserOrgRoleReqPayload,
} from "../../types.gen";

Expand All @@ -32,38 +30,3 @@ export async function updateUserRole(
);
}

export async function createUserApiKey(
/** @hidden */
this: TrieveSDK,
props: CreateApiKeyReqPayload,
signal?: AbortSignal
): Promise<CreateApiKeyResponse> {
if (!this.organizationId) {
throw new Error("Organization ID is required to create user API key");
}

return this.trieve.fetch(
"/api/user/api_key",
"post",
{
data: props,
},
signal
);
}

export async function deleteUserApiKey(
/** @hidden */
this: TrieveSDK,
apiKeyId: string,
signal?: AbortSignal
): Promise<void> {
return this.trieve.fetch(
"/api/user/api_key/{api_key_id}",
"delete",
{
apiKeyId,
},
signal
);
}
125 changes: 4 additions & 121 deletions clients/ts-sdk/src/functions/user/user.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { beforeAll, describe, expect, expectTypeOf } from "vitest";
import { beforeAll, describe, expectTypeOf } from "vitest";
import { TrieveSDK } from "../../sdk";
import { CreateApiKeyResponse, ReturnQueuedChunk } from "../../types.gen";
import { TRIEVE } from "../../__tests__/constants";
import { test } from "../../__tests__/utils";

Expand All @@ -9,127 +8,11 @@ describe("User Tests", async () => {
beforeAll(() => {
trieve = TRIEVE;
});

test("create an api key and verify it works", async () => {
const apiKeyResponse = await trieve.createUserApiKey({
role: 1,
name: "test suite key",
});

expectTypeOf(apiKeyResponse).toEqualTypeOf<CreateApiKeyResponse>();

const newTrieve = new TrieveSDK({
apiKey: apiKeyResponse.api_key,
datasetId: trieve.datasetId,
});

const queuedChunk = await newTrieve.createChunk({
chunk_html: "testing hello world",
tracking_id: "1234",
tag_set: ["test"],
});

expectTypeOf(queuedChunk).toEqualTypeOf<ReturnQueuedChunk>();

newTrieve.deleteChunkByTrackingId({
trackingId: "1234",
});
});

test("create an expired api key and verify it does not work", async () => {
const apiKeyResponse = await trieve.createUserApiKey({
expires_at: new Date(new Date().setDate(new Date().getDate() - 1))
.toISOString()
.slice(0, 19)
.replace("T", " "),
role: 1,
name: "test suite key",
});

expectTypeOf(apiKeyResponse).toEqualTypeOf<CreateApiKeyResponse>();

let errorOccurred = false;

const newTrieve = new TrieveSDK({
apiKey: apiKeyResponse.api_key,
datasetId: trieve.datasetId,
});

try {
await newTrieve.createChunk({
chunk_html: "testing hello world",
tracking_id: "should_never_work",
tag_set: ["test"],
});

newTrieve.deleteChunkByTrackingId({
trackingId: "should_never_work",
});
} catch (e) {
errorOccurred = true;
}

expect(errorOccurred).toBe(true);
});

test("create an api key with a filter for test and verify it excludes chunks without the tag", async () => {
const apiKeyResponse = await trieve.createUserApiKey({
test("updateUserRole", async () => {
const data = await trieve.updateUserRole({
role: 1,
name: "test suite key",
default_params: {
filters: {
must: [
{
field: "tag_set",
match_all: ["test"],
},
],
},
},
});

expectTypeOf(apiKeyResponse).toEqualTypeOf<CreateApiKeyResponse>();

const newTrieve = new TrieveSDK({
apiKey: apiKeyResponse.api_key,
datasetId: trieve.datasetId,
});

const queuedChunks = await newTrieve.createChunk([
{
chunk_html: "testing hello world",
tracking_id: "not_test",
tag_set: ["not_test"],
},
{
chunk_html: "testing hello world",
tracking_id: "test",
tag_set: ["test"],
},
]);

expectTypeOf(queuedChunks).toEqualTypeOf<ReturnQueuedChunk>();

await new Promise((r) => setTimeout(r, 10000));

const chunksResp = await newTrieve.scroll({
page_size: 100,
filters: {
must: [
{
field: "tag_set",
match_all: ["not_test"],
},
],
},
});

for (const chunk of chunksResp.chunks) {
expect(chunk.tag_set).toContain("test");
}

newTrieve.deleteChunkByTrackingId({
trackingId: "1234",
});
expectTypeOf(data).toBeVoid();
});
});
Loading
Loading