lazo-sdk 0.1.0 → 0.1.2

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
@@ -1,6 +1,6 @@
1
1
  # lazo-sdk
2
2
 
3
- TypeScript SDK for the [Lazo](../lazo-3) CRM API.
3
+ TypeScript SDK for the [Lazo Digital](https://lazo.digital) API.
4
4
 
5
5
  ```ts
6
6
  import { LazoClient } from "lazo-sdk";
package/dist/index.d.ts CHANGED
@@ -1,21 +1,48 @@
1
- /** Lazo CRM SDK — phase 1: create records via the Lazo API. */
1
+ /** Lazo CRM SDK — create and list records via the Lazo API. */
2
2
  export interface LazoClientOptions {
3
3
  /** API token from Lazo (starts with `lazo_`). */
4
4
  apiToken: string;
5
- /** Base URL of the Lazo instance, e.g. https://app.lazo.com */
5
+ /** Base URL of the Lazo instance, e.g. https://app.lazo.digital */
6
6
  baseUrl: string;
7
7
  }
8
8
  export declare class LazoError extends Error {
9
9
  status: number;
10
10
  constructor(status: number, message: string);
11
11
  }
12
+ /**
13
+ * Search records by custom field (exact-match).
14
+ */
15
+ export type SearchRecordsOptions = Record<string, string | number | boolean>;
16
+ /** Options for listing records. */
17
+ export interface ListRecordsOptions {
18
+ page?: number;
19
+ limit?: number;
20
+ sort?: "createdAt" | "updatedAt";
21
+ order?: "asc" | "desc";
22
+ deleted?: boolean;
23
+ }
24
+ /** Paginated list response from GET /api/{resource}. */
25
+ export interface ListRecordsResponse<T = Record<string, unknown>> {
26
+ data: T[];
27
+ total: number;
28
+ page: number;
29
+ limit: number;
30
+ }
12
31
  export declare class LazoClient {
13
32
  private readonly apiToken;
14
33
  private readonly baseUrl;
15
34
  constructor(options: LazoClientOptions);
16
35
  /**
17
36
  * Create a record for the given resource (e.g. "contacts", "deals").
18
- * Maps to POST /api/{resource} on the Lazo API.
19
37
  */
20
38
  createRecord<T = Record<string, unknown>>(resource: string, data: Record<string, unknown>): Promise<T>;
39
+ /**
40
+ * List records for the given resource, paginated with `options` and filtered by `search`.
41
+ */
42
+ listRecords<T = Record<string, unknown>>(resource: string, search?: SearchRecordsOptions, options?: ListRecordsOptions): Promise<ListRecordsResponse<T>>;
43
+ /**
44
+ * Fetch a single record by id.
45
+ */
46
+ getRecord<T = Record<string, unknown>>(resource: string, id: string): Promise<T>;
47
+ private request;
21
48
  }
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** Lazo CRM SDK — phase 1: create records via the Lazo API. */
1
+ /** Lazo CRM SDK — create and list records via the Lazo API. */
2
2
  export class LazoError extends Error {
3
3
  status;
4
4
  constructor(status, message) {
@@ -20,16 +20,44 @@ export class LazoClient {
20
20
  }
21
21
  /**
22
22
  * Create a record for the given resource (e.g. "contacts", "deals").
23
- * Maps to POST /api/{resource} on the Lazo API.
24
23
  */
25
24
  async createRecord(resource, data) {
26
- const res = await fetch(`${this.baseUrl}/api/${resource}`, {
25
+ return this.request(`/api/${resource}`, {
27
26
  method: "POST",
27
+ body: JSON.stringify(data),
28
+ });
29
+ }
30
+ /**
31
+ * List records for the given resource, paginated with `options` and filtered by `search`.
32
+ */
33
+ async listRecords(resource, search = {}, options = {}) {
34
+ const params = new URLSearchParams();
35
+ for (const [k, v] of Object.entries(options)) {
36
+ if (v !== undefined)
37
+ params.set(k, String(v));
38
+ }
39
+ for (const [k, v] of Object.entries(search)) {
40
+ if (v !== undefined)
41
+ params.set(k, String(v));
42
+ }
43
+ const query = params.toString();
44
+ const suffix = query ? `?${query}` : "";
45
+ return this.request(`/api/resources/${resource}${suffix}`);
46
+ }
47
+ /**
48
+ * Fetch a single record by id.
49
+ */
50
+ async getRecord(resource, id) {
51
+ return this.request(`/api/${resource}/${encodeURIComponent(id)}`);
52
+ }
53
+ async request(path, init = {}) {
54
+ const res = await fetch(`${this.baseUrl}${path}`, {
55
+ ...init,
28
56
  headers: {
29
57
  Authorization: `Bearer ${this.apiToken}`,
30
58
  "Content-Type": "application/json",
59
+ ...init.headers,
31
60
  },
32
- body: JSON.stringify(data),
33
61
  });
34
62
  if (!res.ok) {
35
63
  const body = await res.json().catch(() => ({}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lazo-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "TypeScript SDK for the Lazo CRM API",
5
5
  "author": "Juan Daniel <juan.sanchez@stallionstudios.net>",
6
6
  "repository": {
@@ -13,7 +13,9 @@
13
13
  "type": "module",
14
14
  "main": "dist/index.js",
15
15
  "types": "dist/index.d.ts",
16
- "files": ["dist"],
16
+ "files": [
17
+ "dist"
18
+ ],
17
19
  "scripts": {
18
20
  "build": "tsc",
19
21
  "test": "node --import tsx --test test/*.test.ts"