@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.
Files changed (42) hide show
  1. package/CLAUDE.md +339 -0
  2. package/README.md +93 -0
  3. package/dist/core/client.d.ts +8 -0
  4. package/dist/index.d.mts +189 -0
  5. package/dist/index.d.ts +16 -0
  6. package/dist/index.js +194 -0
  7. package/dist/index.mjs +163 -0
  8. package/dist/interfaces/IPaginatedResponse.d.ts +11 -0
  9. package/dist/modules/comments/fetchComment.d.ts +5 -0
  10. package/dist/modules/comments/fetchCommentByForeignId.d.ts +5 -0
  11. package/dist/modules/comments/index.d.ts +3 -0
  12. package/dist/modules/entities/createEntity.d.ts +17 -0
  13. package/dist/modules/entities/deleteEntity.d.ts +5 -0
  14. package/dist/modules/entities/fetchEntity.d.ts +5 -0
  15. package/dist/modules/entities/fetchEntityByForeignId.d.ts +6 -0
  16. package/dist/modules/entities/fetchEntityByShortId.d.ts +5 -0
  17. package/dist/modules/entities/fetchManyEntities.d.ts +50 -0
  18. package/dist/modules/entities/index.d.ts +8 -0
  19. package/dist/modules/entities/updateEntity.d.ts +18 -0
  20. package/dist/modules/users/fetchUserByForeignId.d.ts +11 -0
  21. package/dist/modules/users/fetchUserById.d.ts +5 -0
  22. package/dist/modules/users/index.d.ts +3 -0
  23. package/package.json +33 -0
  24. package/pnpm-workspace.yaml +2 -0
  25. package/src/core/client.ts +15 -0
  26. package/src/index.ts +45 -0
  27. package/src/interfaces/IPaginatedResponse.ts +12 -0
  28. package/src/modules/comments/fetchComment.ts +14 -0
  29. package/src/modules/comments/fetchCommentByForeignId.ts +14 -0
  30. package/src/modules/comments/index.ts +4 -0
  31. package/src/modules/entities/createEntity.ts +27 -0
  32. package/src/modules/entities/deleteEntity.ts +14 -0
  33. package/src/modules/entities/fetchEntity.ts +14 -0
  34. package/src/modules/entities/fetchEntityByForeignId.ts +15 -0
  35. package/src/modules/entities/fetchEntityByShortId.ts +14 -0
  36. package/src/modules/entities/fetchManyEntities.ts +79 -0
  37. package/src/modules/entities/index.ts +17 -0
  38. package/src/modules/entities/updateEntity.ts +28 -0
  39. package/src/modules/users/fetchUserByForeignId.ts +40 -0
  40. package/src/modules/users/fetchUserById.ts +15 -0
  41. package/src/modules/users/index.ts +4 -0
  42. package/tsconfig.json +14 -0
package/dist/index.js ADDED
@@ -0,0 +1,194 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ SublayClient: () => SublayClient
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+
37
+ // src/core/client.ts
38
+ var import_axios = __toESM(require("axios"));
39
+ var SublayHttpClient = class {
40
+ instance;
41
+ constructor({ projectId }) {
42
+ this.instance = import_axios.default.create({
43
+ baseURL: `https://api.sublay.io/api/v5/${projectId}`
44
+ });
45
+ }
46
+ };
47
+
48
+ // src/modules/users/index.ts
49
+ var users_exports = {};
50
+ __export(users_exports, {
51
+ fetchUserByForeignId: () => fetchUserByForeignId,
52
+ fetchUserById: () => fetchUserById
53
+ });
54
+
55
+ // src/modules/users/fetchUserById.ts
56
+ async function fetchUserById(client, data) {
57
+ const path = `/users/${data.userId}`;
58
+ const response = await client.instance.get(path);
59
+ return response.data;
60
+ }
61
+
62
+ // src/modules/users/fetchUserByForeignId.ts
63
+ async function fetchUserByForeignId(client, data) {
64
+ const path = `/users/by-foreign-id`;
65
+ const params = {
66
+ foreignId: data.foreignId,
67
+ name: data.name,
68
+ username: data.username,
69
+ avatar: data.avatar,
70
+ bio: data.bio,
71
+ // birthdate: data.birthdate,
72
+ // location: data.location,
73
+ metadata: data.metadata ? JSON.stringify(data.metadata) : void 0,
74
+ secureMetadata: data.secureMetadata ? JSON.stringify(data.secureMetadata) : void 0
75
+ };
76
+ const response = await client.instance.get(path, {
77
+ params
78
+ });
79
+ return response.data;
80
+ }
81
+
82
+ // src/modules/entities/index.ts
83
+ var entities_exports = {};
84
+ __export(entities_exports, {
85
+ createEntity: () => createEntity,
86
+ deleteEntity: () => deleteEntity,
87
+ fetchEntity: () => fetchEntity,
88
+ fetchEntityByForeignId: () => fetchEntityByForeignId,
89
+ fetchEntityByShortId: () => fetchEntityByShortId,
90
+ fetchManyEntities: () => fetchManyEntities,
91
+ updateEntity: () => updateEntity
92
+ });
93
+
94
+ // src/modules/entities/createEntity.ts
95
+ async function createEntity(client, data) {
96
+ const path = `/entities`;
97
+ const response = await client.instance.post(path, data);
98
+ return response.data;
99
+ }
100
+
101
+ // src/modules/entities/fetchEntity.ts
102
+ async function fetchEntity(client, data) {
103
+ const path = `/entities/${data.entityId}`;
104
+ const response = await client.instance.get(path);
105
+ return response.data;
106
+ }
107
+
108
+ // src/modules/entities/fetchEntityByForeignId.ts
109
+ async function fetchEntityByForeignId(client, data) {
110
+ const path = `/entities/by-foreign-id`;
111
+ const response = await client.instance.get(path, { params: data });
112
+ return response.data;
113
+ }
114
+
115
+ // src/modules/entities/fetchEntityByShortId.ts
116
+ async function fetchEntityByShortId(client, data) {
117
+ const path = `/entities/by-short-id`;
118
+ const response = await client.instance.get(path, { params: data });
119
+ return response.data;
120
+ }
121
+
122
+ // src/modules/entities/fetchManyEntities.ts
123
+ async function fetchManyEntities(client, data) {
124
+ const path = `/entities`;
125
+ const response = await client.instance.get(path, {
126
+ params: data
127
+ });
128
+ return response.data;
129
+ }
130
+
131
+ // src/modules/entities/updateEntity.ts
132
+ async function updateEntity(client, data) {
133
+ const { entityId, ...restOfProps } = data;
134
+ const path = `/entities/${data.entityId}`;
135
+ const response = await client.instance.patch(path, restOfProps);
136
+ return response.data;
137
+ }
138
+
139
+ // src/modules/entities/deleteEntity.ts
140
+ async function deleteEntity(client, data) {
141
+ const path = `/entities/${data.entityId}`;
142
+ const response = await client.instance.delete(path);
143
+ return response.data;
144
+ }
145
+
146
+ // src/modules/comments/index.ts
147
+ var comments_exports = {};
148
+ __export(comments_exports, {
149
+ fetchComment: () => fetchComment,
150
+ fetchCommentByForeignId: () => fetchCommentByForeignId
151
+ });
152
+
153
+ // src/modules/comments/fetchComment.ts
154
+ async function fetchComment(client, data) {
155
+ const path = `/comments/${data.commentId}`;
156
+ const response = await client.instance.get(path);
157
+ return response.data;
158
+ }
159
+
160
+ // src/modules/comments/fetchCommentByForeignId.ts
161
+ async function fetchCommentByForeignId(client, data) {
162
+ const path = `/comments/by-foreign-id`;
163
+ const response = await client.instance.get(path, { params: data });
164
+ return response.data;
165
+ }
166
+
167
+ // src/index.ts
168
+ var SublayClient = class _SublayClient {
169
+ http;
170
+ users;
171
+ entities;
172
+ comments;
173
+ constructor(http) {
174
+ this.http = http;
175
+ this.users = bindModule(users_exports, this.http);
176
+ this.entities = bindModule(entities_exports, this.http);
177
+ this.comments = bindModule(comments_exports, this.http);
178
+ }
179
+ static async init(config) {
180
+ const http = new SublayHttpClient(config);
181
+ return new _SublayClient(http);
182
+ }
183
+ };
184
+ function bindModule(module2, client) {
185
+ const bound = {};
186
+ for (const key in module2) {
187
+ bound[key] = (...args) => module2[key](client, ...args);
188
+ }
189
+ return bound;
190
+ }
191
+ // Annotate the CommonJS export names for ESM import in node:
192
+ 0 && (module.exports = {
193
+ SublayClient
194
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,163 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/core/client.ts
8
+ import axios from "axios";
9
+ var SublayHttpClient = class {
10
+ instance;
11
+ constructor({ projectId }) {
12
+ this.instance = axios.create({
13
+ baseURL: `https://api.sublay.io/api/v5/${projectId}`
14
+ });
15
+ }
16
+ };
17
+
18
+ // src/modules/users/index.ts
19
+ var users_exports = {};
20
+ __export(users_exports, {
21
+ fetchUserByForeignId: () => fetchUserByForeignId,
22
+ fetchUserById: () => fetchUserById
23
+ });
24
+
25
+ // src/modules/users/fetchUserById.ts
26
+ async function fetchUserById(client, data) {
27
+ const path = `/users/${data.userId}`;
28
+ const response = await client.instance.get(path);
29
+ return response.data;
30
+ }
31
+
32
+ // src/modules/users/fetchUserByForeignId.ts
33
+ async function fetchUserByForeignId(client, data) {
34
+ const path = `/users/by-foreign-id`;
35
+ const params = {
36
+ foreignId: data.foreignId,
37
+ name: data.name,
38
+ username: data.username,
39
+ avatar: data.avatar,
40
+ bio: data.bio,
41
+ // birthdate: data.birthdate,
42
+ // location: data.location,
43
+ metadata: data.metadata ? JSON.stringify(data.metadata) : void 0,
44
+ secureMetadata: data.secureMetadata ? JSON.stringify(data.secureMetadata) : void 0
45
+ };
46
+ const response = await client.instance.get(path, {
47
+ params
48
+ });
49
+ return response.data;
50
+ }
51
+
52
+ // src/modules/entities/index.ts
53
+ var entities_exports = {};
54
+ __export(entities_exports, {
55
+ createEntity: () => createEntity,
56
+ deleteEntity: () => deleteEntity,
57
+ fetchEntity: () => fetchEntity,
58
+ fetchEntityByForeignId: () => fetchEntityByForeignId,
59
+ fetchEntityByShortId: () => fetchEntityByShortId,
60
+ fetchManyEntities: () => fetchManyEntities,
61
+ updateEntity: () => updateEntity
62
+ });
63
+
64
+ // src/modules/entities/createEntity.ts
65
+ async function createEntity(client, data) {
66
+ const path = `/entities`;
67
+ const response = await client.instance.post(path, data);
68
+ return response.data;
69
+ }
70
+
71
+ // src/modules/entities/fetchEntity.ts
72
+ async function fetchEntity(client, data) {
73
+ const path = `/entities/${data.entityId}`;
74
+ const response = await client.instance.get(path);
75
+ return response.data;
76
+ }
77
+
78
+ // src/modules/entities/fetchEntityByForeignId.ts
79
+ async function fetchEntityByForeignId(client, data) {
80
+ const path = `/entities/by-foreign-id`;
81
+ const response = await client.instance.get(path, { params: data });
82
+ return response.data;
83
+ }
84
+
85
+ // src/modules/entities/fetchEntityByShortId.ts
86
+ async function fetchEntityByShortId(client, data) {
87
+ const path = `/entities/by-short-id`;
88
+ const response = await client.instance.get(path, { params: data });
89
+ return response.data;
90
+ }
91
+
92
+ // src/modules/entities/fetchManyEntities.ts
93
+ async function fetchManyEntities(client, data) {
94
+ const path = `/entities`;
95
+ const response = await client.instance.get(path, {
96
+ params: data
97
+ });
98
+ return response.data;
99
+ }
100
+
101
+ // src/modules/entities/updateEntity.ts
102
+ async function updateEntity(client, data) {
103
+ const { entityId, ...restOfProps } = data;
104
+ const path = `/entities/${data.entityId}`;
105
+ const response = await client.instance.patch(path, restOfProps);
106
+ return response.data;
107
+ }
108
+
109
+ // src/modules/entities/deleteEntity.ts
110
+ async function deleteEntity(client, data) {
111
+ const path = `/entities/${data.entityId}`;
112
+ const response = await client.instance.delete(path);
113
+ return response.data;
114
+ }
115
+
116
+ // src/modules/comments/index.ts
117
+ var comments_exports = {};
118
+ __export(comments_exports, {
119
+ fetchComment: () => fetchComment,
120
+ fetchCommentByForeignId: () => fetchCommentByForeignId
121
+ });
122
+
123
+ // src/modules/comments/fetchComment.ts
124
+ async function fetchComment(client, data) {
125
+ const path = `/comments/${data.commentId}`;
126
+ const response = await client.instance.get(path);
127
+ return response.data;
128
+ }
129
+
130
+ // src/modules/comments/fetchCommentByForeignId.ts
131
+ async function fetchCommentByForeignId(client, data) {
132
+ const path = `/comments/by-foreign-id`;
133
+ const response = await client.instance.get(path, { params: data });
134
+ return response.data;
135
+ }
136
+
137
+ // src/index.ts
138
+ var SublayClient = class _SublayClient {
139
+ http;
140
+ users;
141
+ entities;
142
+ comments;
143
+ constructor(http) {
144
+ this.http = http;
145
+ this.users = bindModule(users_exports, this.http);
146
+ this.entities = bindModule(entities_exports, this.http);
147
+ this.comments = bindModule(comments_exports, this.http);
148
+ }
149
+ static async init(config) {
150
+ const http = new SublayHttpClient(config);
151
+ return new _SublayClient(http);
152
+ }
153
+ };
154
+ function bindModule(module, client) {
155
+ const bound = {};
156
+ for (const key in module) {
157
+ bound[key] = (...args) => module[key](client, ...args);
158
+ }
159
+ return bound;
160
+ }
161
+ export {
162
+ SublayClient
163
+ };
@@ -0,0 +1,11 @@
1
+ export interface PaginationMetadata {
2
+ page: number;
3
+ pageSize: number;
4
+ totalPages: number;
5
+ totalItems: number;
6
+ hasMore: boolean;
7
+ }
8
+ export interface PaginatedResponse<T> {
9
+ data: T[];
10
+ pagination: PaginationMetadata;
11
+ }
@@ -0,0 +1,5 @@
1
+ import { SublayHttpClient } from "../../core/client";
2
+ export interface FetchCommentProps {
3
+ commentId: string;
4
+ }
5
+ export declare function fetchComment(client: SublayHttpClient, data: FetchCommentProps): Promise<any>;
@@ -0,0 +1,5 @@
1
+ import { SublayHttpClient } from "../../core/client";
2
+ export interface FetchCommentByForeignIdProps {
3
+ foreignId: string;
4
+ }
5
+ export declare function fetchCommentByForeignId(client: SublayHttpClient, data: FetchCommentByForeignIdProps): Promise<any>;
@@ -0,0 +1,3 @@
1
+ import { fetchComment } from "./fetchComment";
2
+ import { fetchCommentByForeignId } from "./fetchCommentByForeignId";
3
+ export { fetchComment, fetchCommentByForeignId };
@@ -0,0 +1,17 @@
1
+ import { SublayHttpClient } from "../../core/client";
2
+ export interface CreateEntityProps {
3
+ foreignId?: string;
4
+ sourceId?: string;
5
+ spaceId?: string;
6
+ title?: string;
7
+ content?: string;
8
+ attachments?: Record<string, any>[];
9
+ keywords?: string[];
10
+ location?: {
11
+ latitude: number;
12
+ longitude: number;
13
+ };
14
+ metadata?: Record<string, any>;
15
+ userId?: string;
16
+ }
17
+ export declare function createEntity(client: SublayHttpClient, data: CreateEntityProps): Promise<any>;
@@ -0,0 +1,5 @@
1
+ import { SublayHttpClient } from "../../core/client";
2
+ export interface DeleteEntityProps {
3
+ entityId: string;
4
+ }
5
+ export declare function deleteEntity(client: SublayHttpClient, data: DeleteEntityProps): Promise<any>;
@@ -0,0 +1,5 @@
1
+ import { SublayHttpClient } from "../../core/client";
2
+ export interface FetchEntityProps {
3
+ entityId: string;
4
+ }
5
+ export declare function fetchEntity(client: SublayHttpClient, data: FetchEntityProps): Promise<any>;
@@ -0,0 +1,6 @@
1
+ import { SublayHttpClient } from "../../core/client";
2
+ export interface FetchEntityByForeignIdProps {
3
+ foreignId: string;
4
+ createIfNotFound?: boolean;
5
+ }
6
+ export declare function fetchEntityByForeignId(client: SublayHttpClient, data: FetchEntityByForeignIdProps): Promise<any>;
@@ -0,0 +1,5 @@
1
+ import { SublayHttpClient } from "../../core/client";
2
+ export interface FetchEntityByShortIdProps {
3
+ shortId: string;
4
+ }
5
+ export declare function fetchEntityByShortId(client: SublayHttpClient, data: FetchEntityByShortIdProps): Promise<any>;
@@ -0,0 +1,50 @@
1
+ import { SublayHttpClient } from "../../core/client";
2
+ import { PaginatedResponse } from "../../interfaces/IPaginatedResponse";
3
+ export interface KeywordsFilters {
4
+ includes?: string[];
5
+ doesNotInclude?: string[];
6
+ }
7
+ export interface MetadataFilters {
8
+ includes?: {
9
+ [key: string]: any;
10
+ };
11
+ doesNotInclude?: {
12
+ [key: string]: any;
13
+ };
14
+ exists?: string[];
15
+ doesNotExist?: string[];
16
+ }
17
+ export interface TextFilters {
18
+ hasTitle?: "true" | "false";
19
+ includes?: string | string[];
20
+ doesNotInclude?: string | string[];
21
+ }
22
+ export interface AttachmentsFilters {
23
+ hasAttachments?: "true" | "false";
24
+ }
25
+ export interface LocationFilters {
26
+ latitude: string;
27
+ longitude: string;
28
+ radius: string;
29
+ }
30
+ export interface FetchManyEntitiesProps {
31
+ sourceId?: string;
32
+ spaceId?: string;
33
+ sortBy?: "hot" | "top" | "controversial";
34
+ page?: number;
35
+ limit?: number;
36
+ timeFrame?: "hour" | "day" | "week" | "month" | "year";
37
+ userId?: string;
38
+ followedOnly?: "true";
39
+ keywordsFilters?: KeywordsFilters;
40
+ metadataFilters?: MetadataFilters;
41
+ titleFilters?: TextFilters;
42
+ contentFilters?: {
43
+ hasContent?: "true" | "false";
44
+ includes?: string | string[];
45
+ doesNotInclude?: string | string[];
46
+ };
47
+ attachmentsFilters?: AttachmentsFilters;
48
+ locationFilters?: LocationFilters;
49
+ }
50
+ export declare function fetchManyEntities(client: SublayHttpClient, data: FetchManyEntitiesProps): Promise<PaginatedResponse<any>>;
@@ -0,0 +1,8 @@
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
+ export { createEntity, fetchEntity, fetchEntityByForeignId, fetchEntityByShortId, fetchManyEntities, updateEntity, deleteEntity, };
@@ -0,0 +1,18 @@
1
+ import { SublayHttpClient } from "../../core/client";
2
+ export interface UpdateEntityProps {
3
+ entityId: string;
4
+ title?: string;
5
+ content?: string;
6
+ attachments?: Record<string, any>[];
7
+ keywords?: string[];
8
+ location?: {
9
+ type: "Point";
10
+ coordinates: [number, number];
11
+ };
12
+ metadata?: Record<string, any>;
13
+ mentions?: {
14
+ id: string;
15
+ username: string;
16
+ }[];
17
+ }
18
+ export declare function updateEntity(client: SublayHttpClient, data: UpdateEntityProps): Promise<any>;
@@ -0,0 +1,11 @@
1
+ import { SublayHttpClient } from "../../core/client";
2
+ export interface FetchUserByForeignIdProps {
3
+ foreignId: string;
4
+ name?: string;
5
+ username?: string;
6
+ avatar?: string;
7
+ bio?: string;
8
+ metadata?: Record<string, any>;
9
+ secureMetadata?: Record<string, any>;
10
+ }
11
+ export declare function fetchUserByForeignId(client: SublayHttpClient, data: FetchUserByForeignIdProps): Promise<any>;
@@ -0,0 +1,5 @@
1
+ import { SublayHttpClient } from "../../core/client";
2
+ export interface FetchUserByIdProps {
3
+ userId: string;
4
+ }
5
+ export declare function fetchUserById(client: SublayHttpClient, data: FetchUserByIdProps): Promise<any>;
@@ -0,0 +1,3 @@
1
+ import { fetchUserById } from "./fetchUserById";
2
+ import { fetchUserByForeignId } from "./fetchUserByForeignId";
3
+ export { fetchUserById, fetchUserByForeignId };
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@sublay/js",
3
+ "version": "5.0.0",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "description": "Official JavaScript SDK for Sublay",
7
+ "author": "Sublay team",
8
+ "license": "ISC",
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "exports": {
13
+ ".": {
14
+ "import": "./dist/index.js",
15
+ "require": "./dist/index.js",
16
+ "types": "./dist/index.d.ts"
17
+ }
18
+ },
19
+ "dependencies": {
20
+ "axios": "^1.8.4"
21
+ },
22
+ "devDependencies": {
23
+ "@types/node": "^22.14.0",
24
+ "tsup": "^8.4.0",
25
+ "typescript": "^5.8.3"
26
+ },
27
+ "scripts": {
28
+ "build": "tsup src/index.ts --dts --format cjs,esm",
29
+ "build:types": "tsc --emitDeclarationOnly",
30
+ "publish-beta": "pnpm publish --tag beta",
31
+ "publish-prod": "pnpm publish"
32
+ }
33
+ }
@@ -0,0 +1,2 @@
1
+ allowBuilds:
2
+ esbuild: true
@@ -0,0 +1,15 @@
1
+ import axios, { AxiosInstance } from "axios";
2
+
3
+ export interface ClientConfig {
4
+ projectId: string;
5
+ }
6
+
7
+ export class SublayHttpClient {
8
+ instance: AxiosInstance;
9
+
10
+ constructor({ projectId }: ClientConfig) {
11
+ this.instance = axios.create({
12
+ baseURL: `https://api.sublay.io/api/v5/${projectId}`,
13
+ });
14
+ }
15
+ }
package/src/index.ts ADDED
@@ -0,0 +1,45 @@
1
+ import { SublayHttpClient, ClientConfig } from "./core/client";
2
+ import * as Users from "./modules/users";
3
+ import * as Entities from "./modules/entities";
4
+ import * as Comments from "./modules/comments";
5
+
6
+ type BoundModule<
7
+ T extends Record<string, (client: SublayHttpClient, ...args: any[]) => any>
8
+ > = {
9
+ [K in keyof T]: (
10
+ ...args: Parameters<T[K]> extends [any, ...infer R] ? R : never
11
+ ) => ReturnType<T[K]>;
12
+ };
13
+
14
+ export class SublayClient {
15
+ private http: SublayHttpClient;
16
+
17
+ public users: BoundModule<typeof Users>;
18
+ public entities: BoundModule<typeof Entities>;
19
+ public comments: BoundModule<typeof Comments>;
20
+
21
+ private constructor(http: SublayHttpClient) {
22
+ this.http = http;
23
+ this.users = bindModule(Users, this.http);
24
+ this.entities = bindModule(Entities, this.http);
25
+ this.comments = bindModule(Comments, this.http);
26
+ }
27
+
28
+ static async init(config: ClientConfig): Promise<SublayClient> {
29
+ const http = new SublayHttpClient(config);
30
+ return new SublayClient(http);
31
+ }
32
+ }
33
+
34
+ function bindModule<
35
+ T extends Record<string, (client: SublayHttpClient, ...args: any[]) => any>
36
+ >(module: T, client: SublayHttpClient): BoundModule<T> {
37
+ const bound: any = {};
38
+ for (const key in module) {
39
+ bound[key] = (...args: any[]) => module[key](client, ...args);
40
+ }
41
+ return bound;
42
+ }
43
+
44
+ // Export pagination types
45
+ export type { PaginatedResponse, PaginationMetadata } from "./interfaces/IPaginatedResponse";
@@ -0,0 +1,12 @@
1
+ export interface PaginationMetadata {
2
+ page: number;
3
+ pageSize: number;
4
+ totalPages: number;
5
+ totalItems: number;
6
+ hasMore: boolean;
7
+ }
8
+
9
+ export interface PaginatedResponse<T> {
10
+ data: T[];
11
+ pagination: PaginationMetadata;
12
+ }
@@ -0,0 +1,14 @@
1
+ import { SublayHttpClient } from "../../core/client";
2
+
3
+ export interface FetchCommentProps {
4
+ commentId: string;
5
+ }
6
+
7
+ export async function fetchComment(
8
+ client: SublayHttpClient,
9
+ data: FetchCommentProps
10
+ ): Promise<any> {
11
+ const path = `/comments/${data.commentId}`;
12
+ const response = await client.instance.get<any>(path);
13
+ return response.data;
14
+ }