@01.software/sdk 0.5.9 → 0.6.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/README.md CHANGED
@@ -134,6 +134,18 @@ const { docs, totalDocs, hasNextPage } = await client.from('products').find({
134
134
  select: { title: true, slug: true },
135
135
  })
136
136
 
137
+ // Query with populate/joins control
138
+ const { docs } = await client.from('products').find({
139
+ select: { title: true, slug: true, price: true, thumbnail: true },
140
+ joins: false, // disable joins for lightweight list
141
+ })
142
+
143
+ // Override relationship populate
144
+ const product = await client.from('products').findById(id, {
145
+ populate: { brands: { name: true, logo: true } },
146
+ joins: { variants: { limit: 50 } },
147
+ })
148
+
137
149
  // Single item query - returns document directly
138
150
  const product = await client.from('products').findById('id')
139
151
 
package/dist/auth.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import './payload-types-D70l0uF9.cjs';
1
+ import './payload-types-DCVm1syH.cjs';
2
2
 
3
3
  interface JwtPayload {
4
4
  clientKey: string;
package/dist/auth.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import './payload-types-D70l0uF9.js';
1
+ import './payload-types-DCVm1syH.js';
2
2
 
3
3
  interface JwtPayload {
4
4
  clientKey: string;
@@ -1,4 +1,4 @@
1
- import { C as Config } from './payload-types-D70l0uF9.js';
1
+ import { C as Config } from './payload-types-DCVm1syH.js';
2
2
 
3
3
  /**
4
4
  * Collection type derived from Payload Config.
@@ -9,7 +9,7 @@ type Collection = keyof Config['collections'];
9
9
  * Array of all public collection names for runtime use (e.g., Zod enum validation).
10
10
  * This is the single source of truth for which collections are publicly accessible via SDK.
11
11
  */
12
- declare const COLLECTIONS: readonly ["tenants", "tenant-metadata", "tenant-logos", "products", "product-variants", "product-options", "product-categories", "product-tags", "product-collections", "brands", "brand-logos", "orders", "order-products", "returns", "return-products", "exchanges", "exchange-products", "fulfillments", "fulfillment-items", "transactions", "customers", "customer-addresses", "customer-groups", "carts", "cart-items", "discounts", "shipping-policies", "documents", "document-categories", "document-types", "posts", "post-authors", "post-categories", "post-tags", "playlists", "playlist-categories", "playlist-tags", "musics", "music-categories", "music-tags", "galleries", "gallery-categories", "gallery-tags", "gallery-items", "links", "link-categories", "link-tags", "flows", "flow-node-types", "flow-edge-types", "flow-categories", "flow-tags", "videos", "video-categories", "video-tags", "live-streams", "images", "forms", "form-submissions"];
12
+ declare const COLLECTIONS: readonly ["tenants", "tenant-metadata", "tenant-logos", "products", "product-variants", "product-options", "product-categories", "product-tags", "product-collections", "brands", "brand-logos", "orders", "order-products", "returns", "return-products", "exchanges", "exchange-products", "fulfillments", "fulfillment-items", "transactions", "customers", "customer-addresses", "customer-groups", "carts", "cart-items", "discounts", "shipping-policies", "documents", "document-categories", "document-types", "posts", "post-authors", "post-categories", "post-tags", "playlists", "playlist-categories", "playlist-tags", "musics", "music-categories", "music-tags", "galleries", "gallery-categories", "gallery-tags", "gallery-items", "links", "link-categories", "link-tags", "flows", "flow-node-types", "flow-edge-types", "flow-categories", "flow-tags", "videos", "video-categories", "video-tags", "live-streams", "images", "forms", "form-submissions", "threads", "comments", "reactions", "reaction-types", "bookmarks", "thread-categories", "reports", "community-bans"];
13
13
  /**
14
14
  * Public collections available for SDK access.
15
15
  * Derived from the COLLECTIONS array (single source of truth).
@@ -1,4 +1,4 @@
1
- import { C as Config } from './payload-types-D70l0uF9.cjs';
1
+ import { C as Config } from './payload-types-DCVm1syH.cjs';
2
2
 
3
3
  /**
4
4
  * Collection type derived from Payload Config.
@@ -9,7 +9,7 @@ type Collection = keyof Config['collections'];
9
9
  * Array of all public collection names for runtime use (e.g., Zod enum validation).
10
10
  * This is the single source of truth for which collections are publicly accessible via SDK.
11
11
  */
12
- declare const COLLECTIONS: readonly ["tenants", "tenant-metadata", "tenant-logos", "products", "product-variants", "product-options", "product-categories", "product-tags", "product-collections", "brands", "brand-logos", "orders", "order-products", "returns", "return-products", "exchanges", "exchange-products", "fulfillments", "fulfillment-items", "transactions", "customers", "customer-addresses", "customer-groups", "carts", "cart-items", "discounts", "shipping-policies", "documents", "document-categories", "document-types", "posts", "post-authors", "post-categories", "post-tags", "playlists", "playlist-categories", "playlist-tags", "musics", "music-categories", "music-tags", "galleries", "gallery-categories", "gallery-tags", "gallery-items", "links", "link-categories", "link-tags", "flows", "flow-node-types", "flow-edge-types", "flow-categories", "flow-tags", "videos", "video-categories", "video-tags", "live-streams", "images", "forms", "form-submissions"];
12
+ declare const COLLECTIONS: readonly ["tenants", "tenant-metadata", "tenant-logos", "products", "product-variants", "product-options", "product-categories", "product-tags", "product-collections", "brands", "brand-logos", "orders", "order-products", "returns", "return-products", "exchanges", "exchange-products", "fulfillments", "fulfillment-items", "transactions", "customers", "customer-addresses", "customer-groups", "carts", "cart-items", "discounts", "shipping-policies", "documents", "document-categories", "document-types", "posts", "post-authors", "post-categories", "post-tags", "playlists", "playlist-categories", "playlist-tags", "musics", "music-categories", "music-tags", "galleries", "gallery-categories", "gallery-tags", "gallery-items", "links", "link-categories", "link-tags", "flows", "flow-node-types", "flow-edge-types", "flow-categories", "flow-tags", "videos", "video-categories", "video-tags", "live-streams", "images", "forms", "form-submissions", "threads", "comments", "reactions", "reaction-types", "bookmarks", "thread-categories", "reports", "community-bans"];
13
13
  /**
14
14
  * Public collections available for SDK access.
15
15
  * Derived from the COLLECTIONS array (single source of truth).
package/dist/index.cjs CHANGED
@@ -28,6 +28,7 @@ __export(src_exports, {
28
28
  CollectionClient: () => CollectionClient,
29
29
  CollectionHooks: () => CollectionHooks,
30
30
  CollectionQueryBuilder: () => CollectionQueryBuilder,
31
+ CommunityClient: () => CommunityClient,
31
32
  ConfigError: () => ConfigError,
32
33
  CustomerAuth: () => CustomerAuth,
33
34
  CustomerHooks: () => CustomerHooks,
@@ -824,7 +825,7 @@ var CollectionQueryBuilder = class {
824
825
  async find(options) {
825
826
  return this.api.requestFind(
826
827
  `/api/${String(this.collection)}`,
827
- options
828
+ { depth: 1, ...options }
828
829
  );
829
830
  }
830
831
  /**
@@ -835,7 +836,7 @@ var CollectionQueryBuilder = class {
835
836
  async findById(id, options) {
836
837
  return this.api.requestFindById(
837
838
  `/api/${String(this.collection)}/${String(id)}`,
838
- options
839
+ { depth: 1, ...options }
839
840
  );
840
841
  }
841
842
  /**
@@ -1265,9 +1266,204 @@ var COLLECTIONS = [
1265
1266
  "live-streams",
1266
1267
  "images",
1267
1268
  "forms",
1268
- "form-submissions"
1269
+ "form-submissions",
1270
+ // Community
1271
+ "threads",
1272
+ "comments",
1273
+ "reactions",
1274
+ "reaction-types",
1275
+ "bookmarks",
1276
+ "thread-categories",
1277
+ "reports",
1278
+ "community-bans"
1269
1279
  ];
1270
1280
 
1281
+ // src/core/community/community-client.ts
1282
+ var CommunityClient = class {
1283
+ constructor(options) {
1284
+ if (!options.clientKey) {
1285
+ throw createConfigError("clientKey is required for CommunityClient.");
1286
+ }
1287
+ this.clientKey = options.clientKey;
1288
+ this.secretKey = options.secretKey;
1289
+ this.customerToken = options.customerToken;
1290
+ this.baseUrl = options.baseUrl;
1291
+ this.onUnauthorized = options.onUnauthorized;
1292
+ }
1293
+ async execute(endpoint, method, body) {
1294
+ const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
1295
+ const response = await httpFetch(endpoint, {
1296
+ method,
1297
+ clientKey: this.clientKey,
1298
+ secretKey: this.secretKey,
1299
+ customerToken: token ?? void 0,
1300
+ baseUrl: this.baseUrl,
1301
+ ...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
1302
+ ...body !== void 0 && { body: JSON.stringify(body) }
1303
+ });
1304
+ return parseApiResponse(response, endpoint);
1305
+ }
1306
+ // Threads
1307
+ createThread(params) {
1308
+ return this.execute("/api/threads", "POST", params);
1309
+ }
1310
+ getMyThreads(params) {
1311
+ const query = params ? `?${new URLSearchParams(
1312
+ Object.fromEntries(
1313
+ Object.entries(params).map(([k, v]) => [k, String(v)])
1314
+ )
1315
+ ).toString()}` : "";
1316
+ return this.execute(
1317
+ `/api/threads/my${query}`,
1318
+ "GET"
1319
+ );
1320
+ }
1321
+ getTrending(params) {
1322
+ const query = params ? `?${new URLSearchParams(
1323
+ Object.fromEntries(
1324
+ Object.entries(params).map(([k, v]) => [k, String(v)])
1325
+ )
1326
+ ).toString()}` : "";
1327
+ return this.execute(
1328
+ `/api/threads/trending${query}`,
1329
+ "GET"
1330
+ );
1331
+ }
1332
+ incrementView(params) {
1333
+ return this.execute(
1334
+ `/api/threads/${params.threadId}/view`,
1335
+ "POST"
1336
+ );
1337
+ }
1338
+ reportThread(params) {
1339
+ const { threadId, ...body } = params;
1340
+ return this.execute(
1341
+ `/api/threads/${threadId}/report`,
1342
+ "POST",
1343
+ body
1344
+ );
1345
+ }
1346
+ // Comments
1347
+ createComment(params) {
1348
+ const { threadId, parentId, content } = params;
1349
+ const body = { thread: threadId, content };
1350
+ if (parentId !== void 0) {
1351
+ body.parent = parentId;
1352
+ }
1353
+ return this.execute("/api/comments", "POST", body);
1354
+ }
1355
+ listComments(params) {
1356
+ const { threadId, page, limit, rootId } = params;
1357
+ const urlParams = new URLSearchParams();
1358
+ urlParams.set("where[thread][equals]", threadId);
1359
+ urlParams.set("sort", "-createdAt");
1360
+ if (limit !== void 0) urlParams.set("limit", String(limit));
1361
+ if (page !== void 0) urlParams.set("page", String(page));
1362
+ if (rootId !== void 0) urlParams.set("where[rootId][equals]", rootId);
1363
+ return this.execute(
1364
+ `/api/comments?${urlParams.toString()}`,
1365
+ "GET"
1366
+ );
1367
+ }
1368
+ updateComment(params) {
1369
+ const { commentId, content } = params;
1370
+ return this.execute(
1371
+ `/api/comments/${commentId}`,
1372
+ "PATCH",
1373
+ { content }
1374
+ );
1375
+ }
1376
+ deleteComment(params) {
1377
+ return this.execute(
1378
+ `/api/comments/${params.commentId}`,
1379
+ "DELETE"
1380
+ );
1381
+ }
1382
+ reportComment(params) {
1383
+ const { commentId, ...body } = params;
1384
+ return this.execute(
1385
+ `/api/comments/${commentId}/report`,
1386
+ "POST",
1387
+ body
1388
+ );
1389
+ }
1390
+ // Reactions
1391
+ addReaction(params) {
1392
+ const { threadId, type } = params;
1393
+ return this.execute("/api/reactions", "POST", {
1394
+ thread: threadId,
1395
+ type
1396
+ });
1397
+ }
1398
+ removeReaction(params) {
1399
+ const { threadId, type } = params;
1400
+ return this.execute(
1401
+ `/api/threads/${threadId}/react?type=${encodeURIComponent(type)}`,
1402
+ "DELETE"
1403
+ );
1404
+ }
1405
+ addCommentReaction(params) {
1406
+ const { commentId, type } = params;
1407
+ return this.execute("/api/reactions", "POST", {
1408
+ comment: commentId,
1409
+ type
1410
+ });
1411
+ }
1412
+ removeCommentReaction(params) {
1413
+ const { commentId, type } = params;
1414
+ return this.execute(
1415
+ `/api/comments/${commentId}/react?type=${encodeURIComponent(type)}`,
1416
+ "DELETE"
1417
+ );
1418
+ }
1419
+ getReactionSummary(params) {
1420
+ return this.execute(
1421
+ `/api/threads/${params.threadId}/reactions`,
1422
+ "GET"
1423
+ );
1424
+ }
1425
+ getReactionTypes() {
1426
+ return this.execute(
1427
+ "/api/reaction-types?limit=100",
1428
+ "GET"
1429
+ );
1430
+ }
1431
+ // Bookmarks
1432
+ addBookmark(params) {
1433
+ return this.execute("/api/bookmarks", "POST", {
1434
+ thread: params.threadId
1435
+ });
1436
+ }
1437
+ removeBookmark(params) {
1438
+ return this.execute(
1439
+ `/api/threads/${params.threadId}/bookmark`,
1440
+ "DELETE"
1441
+ );
1442
+ }
1443
+ getMyBookmarks(params) {
1444
+ const query = params ? `?${new URLSearchParams(
1445
+ Object.fromEntries(
1446
+ Object.entries(params).map(([k, v]) => [k, String(v)])
1447
+ )
1448
+ ).toString()}` : "";
1449
+ return this.execute(
1450
+ `/api/bookmarks/my${query}`,
1451
+ "GET"
1452
+ );
1453
+ }
1454
+ // Moderation
1455
+ banCustomer(params) {
1456
+ return this.execute("/api/community-bans/ban", "POST", params);
1457
+ }
1458
+ unbanCustomer(params) {
1459
+ return this.execute(
1460
+ "/api/community-bans/unban",
1461
+ "DELETE",
1462
+ params
1463
+ );
1464
+ }
1465
+ };
1466
+
1271
1467
  // src/core/customer/customer-auth.ts
1272
1468
  var DEFAULT_TIMEOUT2 = 15e3;
1273
1469
  function safeGetItem(key) {
@@ -1977,6 +2173,12 @@ var Client = class {
1977
2173
  baseUrl: this.baseUrl,
1978
2174
  onUnauthorized
1979
2175
  });
2176
+ this.community = new CommunityClient({
2177
+ clientKey: this.config.clientKey,
2178
+ customerToken: () => this.customer.getToken(),
2179
+ baseUrl: this.baseUrl,
2180
+ onUnauthorized
2181
+ });
1980
2182
  this.collections = new CollectionClient(
1981
2183
  this.config.clientKey,
1982
2184
  void 0,
@@ -2035,6 +2237,11 @@ var ServerClient = class {
2035
2237
  secretKey: this.config.secretKey,
2036
2238
  baseUrl: this.baseUrl
2037
2239
  });
2240
+ this.community = new CommunityClient({
2241
+ clientKey: this.config.clientKey,
2242
+ secretKey: this.config.secretKey,
2243
+ baseUrl: this.baseUrl
2244
+ });
2038
2245
  this.product = new ProductApi({
2039
2246
  clientKey: this.config.clientKey,
2040
2247
  secretKey: this.config.secretKey,