@sublay/js 5.0.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/CLAUDE.md +339 -0
- package/README.md +93 -0
- package/dist/core/client.d.ts +8 -0
- package/dist/index.d.mts +189 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +194 -0
- package/dist/index.mjs +163 -0
- package/dist/interfaces/IPaginatedResponse.d.ts +11 -0
- package/dist/modules/comments/fetchComment.d.ts +5 -0
- package/dist/modules/comments/fetchCommentByForeignId.d.ts +5 -0
- package/dist/modules/comments/index.d.ts +3 -0
- package/dist/modules/entities/createEntity.d.ts +17 -0
- package/dist/modules/entities/deleteEntity.d.ts +5 -0
- package/dist/modules/entities/fetchEntity.d.ts +5 -0
- package/dist/modules/entities/fetchEntityByForeignId.d.ts +6 -0
- package/dist/modules/entities/fetchEntityByShortId.d.ts +5 -0
- package/dist/modules/entities/fetchManyEntities.d.ts +50 -0
- package/dist/modules/entities/index.d.ts +8 -0
- package/dist/modules/entities/updateEntity.d.ts +18 -0
- package/dist/modules/users/fetchUserByForeignId.d.ts +11 -0
- package/dist/modules/users/fetchUserById.d.ts +5 -0
- package/dist/modules/users/index.d.ts +3 -0
- package/package.json +33 -0
- package/pnpm-workspace.yaml +2 -0
- package/src/core/client.ts +15 -0
- package/src/index.ts +45 -0
- package/src/interfaces/IPaginatedResponse.ts +12 -0
- package/src/modules/comments/fetchComment.ts +14 -0
- package/src/modules/comments/fetchCommentByForeignId.ts +14 -0
- package/src/modules/comments/index.ts +4 -0
- package/src/modules/entities/createEntity.ts +27 -0
- package/src/modules/entities/deleteEntity.ts +14 -0
- package/src/modules/entities/fetchEntity.ts +14 -0
- package/src/modules/entities/fetchEntityByForeignId.ts +15 -0
- package/src/modules/entities/fetchEntityByShortId.ts +14 -0
- package/src/modules/entities/fetchManyEntities.ts +79 -0
- package/src/modules/entities/index.ts +17 -0
- package/src/modules/entities/updateEntity.ts +28 -0
- package/src/modules/users/fetchUserByForeignId.ts +40 -0
- package/src/modules/users/fetchUserById.ts +15 -0
- package/src/modules/users/index.ts +4 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SublayHttpClient } from "../../core/client";
|
|
2
|
+
|
|
3
|
+
export interface FetchCommentByForeignIdProps {
|
|
4
|
+
foreignId: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export async function fetchCommentByForeignId(
|
|
8
|
+
client: SublayHttpClient,
|
|
9
|
+
data: FetchCommentByForeignIdProps
|
|
10
|
+
): Promise<any> {
|
|
11
|
+
const path = `/comments/by-foreign-id`;
|
|
12
|
+
const response = await client.instance.get<any>(path, { params: data });
|
|
13
|
+
return response.data;
|
|
14
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SublayHttpClient } from "../../core/client";
|
|
2
|
+
|
|
3
|
+
export interface CreateEntityProps {
|
|
4
|
+
foreignId?: string;
|
|
5
|
+
sourceId?: string;
|
|
6
|
+
spaceId?: string;
|
|
7
|
+
title?: string;
|
|
8
|
+
content?: string;
|
|
9
|
+
attachments?: Record<string, any>[];
|
|
10
|
+
keywords?: string[];
|
|
11
|
+
location?: {
|
|
12
|
+
latitude: number;
|
|
13
|
+
longitude: number;
|
|
14
|
+
};
|
|
15
|
+
metadata?: Record<string, any>;
|
|
16
|
+
userId?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// TODO: Replace "any" with Entity once we have types here too
|
|
20
|
+
export async function createEntity(
|
|
21
|
+
client: SublayHttpClient,
|
|
22
|
+
data: CreateEntityProps
|
|
23
|
+
): Promise<any> {
|
|
24
|
+
const path = `/entities`; // assuming client handles prefix like /{projectId}
|
|
25
|
+
const response = await client.instance.post<any>(path, data);
|
|
26
|
+
return response.data;
|
|
27
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SublayHttpClient } from "../../core/client";
|
|
2
|
+
|
|
3
|
+
export interface DeleteEntityProps {
|
|
4
|
+
entityId: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export async function deleteEntity(
|
|
8
|
+
client: SublayHttpClient,
|
|
9
|
+
data: DeleteEntityProps
|
|
10
|
+
): Promise<any> {
|
|
11
|
+
const path = `/entities/${data.entityId}`;
|
|
12
|
+
const response = await client.instance.delete<any>(path);
|
|
13
|
+
return response.data;
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SublayHttpClient } from "../../core/client";
|
|
2
|
+
|
|
3
|
+
export interface FetchEntityProps {
|
|
4
|
+
entityId: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export async function fetchEntity(
|
|
8
|
+
client: SublayHttpClient,
|
|
9
|
+
data: FetchEntityProps
|
|
10
|
+
): Promise<any> {
|
|
11
|
+
const path = `/entities/${data.entityId}`;
|
|
12
|
+
const response = await client.instance.get<any>(path);
|
|
13
|
+
return response.data;
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SublayHttpClient } from "../../core/client";
|
|
2
|
+
|
|
3
|
+
export interface FetchEntityByForeignIdProps {
|
|
4
|
+
foreignId: string;
|
|
5
|
+
createIfNotFound?: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export async function fetchEntityByForeignId(
|
|
9
|
+
client: SublayHttpClient,
|
|
10
|
+
data: FetchEntityByForeignIdProps
|
|
11
|
+
): Promise<any> {
|
|
12
|
+
const path = `/entities/by-foreign-id`;
|
|
13
|
+
const response = await client.instance.get<any>(path, { params: data });
|
|
14
|
+
return response.data;
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SublayHttpClient } from "../../core/client";
|
|
2
|
+
|
|
3
|
+
export interface FetchEntityByShortIdProps {
|
|
4
|
+
shortId: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export async function fetchEntityByShortId(
|
|
8
|
+
client: SublayHttpClient,
|
|
9
|
+
data: FetchEntityByShortIdProps
|
|
10
|
+
): Promise<any> {
|
|
11
|
+
const path = `/entities/by-short-id`;
|
|
12
|
+
const response = await client.instance.get<any>(path, { params: data });
|
|
13
|
+
return response.data;
|
|
14
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { SublayHttpClient } from "../../core/client";
|
|
2
|
+
import { PaginatedResponse } from "../../interfaces/IPaginatedResponse";
|
|
3
|
+
|
|
4
|
+
export interface KeywordsFilters {
|
|
5
|
+
includes?: string[];
|
|
6
|
+
doesNotInclude?: string[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface MetadataFilters {
|
|
10
|
+
includes?: { [key: string]: any };
|
|
11
|
+
doesNotInclude?: { [key: string]: any };
|
|
12
|
+
exists?: string[];
|
|
13
|
+
doesNotExist?: string[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface TextFilters {
|
|
17
|
+
hasTitle?: "true" | "false";
|
|
18
|
+
includes?: string | string[];
|
|
19
|
+
doesNotInclude?: string | string[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface AttachmentsFilters {
|
|
23
|
+
hasAttachments?: "true" | "false";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface LocationFilters {
|
|
27
|
+
latitude: string;
|
|
28
|
+
longitude: string;
|
|
29
|
+
radius: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface FetchManyEntitiesProps {
|
|
33
|
+
sourceId?: string;
|
|
34
|
+
spaceId?: string;
|
|
35
|
+
|
|
36
|
+
// Sorting & Pagination
|
|
37
|
+
sortBy?: "hot" | "top" | "controversial";
|
|
38
|
+
page?: number;
|
|
39
|
+
limit?: number;
|
|
40
|
+
|
|
41
|
+
// Time-based filtering
|
|
42
|
+
timeFrame?: "hour" | "day" | "week" | "month" | "year";
|
|
43
|
+
|
|
44
|
+
userId?: string;
|
|
45
|
+
followedOnly?: "true";
|
|
46
|
+
|
|
47
|
+
// Keyword filters
|
|
48
|
+
keywordsFilters?: KeywordsFilters;
|
|
49
|
+
|
|
50
|
+
// Metadata filters
|
|
51
|
+
metadataFilters?: MetadataFilters;
|
|
52
|
+
|
|
53
|
+
// Title filtering
|
|
54
|
+
titleFilters?: TextFilters;
|
|
55
|
+
|
|
56
|
+
// Content filtering
|
|
57
|
+
contentFilters?: {
|
|
58
|
+
hasContent?: "true" | "false";
|
|
59
|
+
includes?: string | string[];
|
|
60
|
+
doesNotInclude?: string | string[];
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// Media filtering
|
|
64
|
+
attachmentsFilters?: AttachmentsFilters;
|
|
65
|
+
|
|
66
|
+
// Location filtering
|
|
67
|
+
locationFilters?: LocationFilters;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function fetchManyEntities(
|
|
71
|
+
client: SublayHttpClient,
|
|
72
|
+
data: FetchManyEntitiesProps
|
|
73
|
+
): Promise<PaginatedResponse<any>> {
|
|
74
|
+
const path = `/entities`;
|
|
75
|
+
const response = await client.instance.get<PaginatedResponse<any>>(path, {
|
|
76
|
+
params: data,
|
|
77
|
+
});
|
|
78
|
+
return response.data;
|
|
79
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createEntity } from "./createEntity";
|
|
2
|
+
import { fetchEntity } from "./fetchEntity";
|
|
3
|
+
import { fetchEntityByForeignId } from "./fetchEntityByForeignId";
|
|
4
|
+
import { fetchEntityByShortId } from "./fetchEntityByShortId";
|
|
5
|
+
import { fetchManyEntities } from "./fetchManyEntities";
|
|
6
|
+
import { updateEntity } from "./updateEntity";
|
|
7
|
+
import { deleteEntity } from "./deleteEntity";
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
createEntity,
|
|
11
|
+
fetchEntity,
|
|
12
|
+
fetchEntityByForeignId,
|
|
13
|
+
fetchEntityByShortId,
|
|
14
|
+
fetchManyEntities,
|
|
15
|
+
updateEntity,
|
|
16
|
+
deleteEntity,
|
|
17
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SublayHttpClient } from "../../core/client";
|
|
2
|
+
|
|
3
|
+
export interface UpdateEntityProps {
|
|
4
|
+
entityId: string;
|
|
5
|
+
title?: string;
|
|
6
|
+
content?: string;
|
|
7
|
+
attachments?: Record<string, any>[];
|
|
8
|
+
keywords?: string[];
|
|
9
|
+
location?: {
|
|
10
|
+
type: "Point";
|
|
11
|
+
coordinates: [number, number]; // [longitude, latitude]
|
|
12
|
+
};
|
|
13
|
+
metadata?: Record<string, any>;
|
|
14
|
+
mentions?: {
|
|
15
|
+
id: string;
|
|
16
|
+
username: string;
|
|
17
|
+
}[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function updateEntity(
|
|
21
|
+
client: SublayHttpClient,
|
|
22
|
+
data: UpdateEntityProps
|
|
23
|
+
): Promise<any> {
|
|
24
|
+
const { entityId, ...restOfProps } = data;
|
|
25
|
+
const path = `/entities/${data.entityId}`;
|
|
26
|
+
const response = await client.instance.patch<any>(path, restOfProps);
|
|
27
|
+
return response.data;
|
|
28
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { SublayHttpClient } from "../../core/client";
|
|
2
|
+
|
|
3
|
+
export interface FetchUserByForeignIdProps {
|
|
4
|
+
foreignId: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
username?: string;
|
|
7
|
+
avatar?: string;
|
|
8
|
+
bio?: string;
|
|
9
|
+
// birthdate?: string; // ISO format string
|
|
10
|
+
// location?: string; // "lat,lng" string format (e.g. "32.0853,34.7818")
|
|
11
|
+
metadata?: Record<string, any>;
|
|
12
|
+
secureMetadata?: Record<string, any>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function fetchUserByForeignId(
|
|
16
|
+
client: SublayHttpClient,
|
|
17
|
+
data: FetchUserByForeignIdProps
|
|
18
|
+
): Promise<any> {
|
|
19
|
+
const path = `/users/by-foreign-id`;
|
|
20
|
+
|
|
21
|
+
const params: Record<string, any> = {
|
|
22
|
+
foreignId: data.foreignId,
|
|
23
|
+
name: data.name,
|
|
24
|
+
username: data.username,
|
|
25
|
+
avatar: data.avatar,
|
|
26
|
+
bio: data.bio,
|
|
27
|
+
// birthdate: data.birthdate,
|
|
28
|
+
// location: data.location,
|
|
29
|
+
metadata: data.metadata ? JSON.stringify(data.metadata) : undefined,
|
|
30
|
+
secureMetadata: data.secureMetadata
|
|
31
|
+
? JSON.stringify(data.secureMetadata)
|
|
32
|
+
: undefined,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const response = await client.instance.get<any>(path, {
|
|
36
|
+
params,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return response.data;
|
|
40
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SublayHttpClient } from "../../core/client";
|
|
2
|
+
|
|
3
|
+
export interface FetchUserByIdProps {
|
|
4
|
+
userId: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// TODO: Replace "any" with Entity once we have types here too
|
|
8
|
+
export async function fetchUserById(
|
|
9
|
+
client: SublayHttpClient,
|
|
10
|
+
data: FetchUserByIdProps
|
|
11
|
+
): Promise<any> {
|
|
12
|
+
const path = `/users/${data.userId}`; // assuming client handles prefix like /{projectId}
|
|
13
|
+
const response = await client.instance.get<any>(path);
|
|
14
|
+
return response.data;
|
|
15
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "esnext",
|
|
4
|
+
"module": "esnext",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"outDir": "dist",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"moduleResolution": "node",
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"skipLibCheck": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["src"]
|
|
14
|
+
}
|