@machhub-dev/sdk-ts 0.0.10 → 0.0.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@machhub-dev/sdk-ts",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "MACHHUB TYPESCRIPT SDK",
5
5
  "keywords": [
6
6
  "machhub",
@@ -48,8 +48,32 @@ export class Collection {
48
48
  return this;
49
49
  }
50
50
 
51
- async getAll(): Promise<any[]> {
51
+ expand(fields: string | string[]): Collection {
52
+ this.queryParams.expand = Array.isArray(fields) ? fields.join(",") : fields;
53
+ return this;
54
+ }
55
+
56
+ private applyOptions(options?: Record<string, any>) {
57
+ if (!options) return;
58
+
59
+ for (const [key, value] of Object.entries(options)) {
60
+ if (value !== undefined && value !== null) {
61
+ this.queryParams[key] = value;
62
+ }
63
+ }
64
+ }
65
+
66
+ async first(): Promise<any> {
67
+ const results = await this.limit(1).getAll();
68
+ return results[0] ?? null
69
+ }
70
+
71
+ async getAll(options?: { expand?: string | string[] }): Promise<any[]> {
52
72
  try {
73
+ this.applyOptions(options)
74
+ if (options?.expand) {
75
+ this.queryParams.expand = Array.isArray(options.expand) ? options.expand.join() : options.expand
76
+ }
53
77
  return await this.httpService.request.get(this.collectionName + "/all", this.queryParams);
54
78
  } catch (error) {
55
79
  throw new CollectionError('getAll', this.collectionName, error as Error);