@graph8/sdk 0.2.1 → 0.3.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/dist/index.js CHANGED
@@ -638,6 +638,28 @@ var createContactsClient = (apiKey, apiUrl) => {
638
638
  headers: headers()
639
639
  });
640
640
  return resp.json();
641
+ },
642
+ /** List custom contact columns. Pass listId to include list-specific columns. */
643
+ async listColumns(listId) {
644
+ const qs = listId != null ? `?list_id=${listId}` : "";
645
+ const resp = await fetch(`${baseUrl}/api/v1/contacts/columns${qs}`, { headers: headers() });
646
+ return resp.json();
647
+ },
648
+ /** Create a custom contact column. Global if list_id is omitted, list-scoped otherwise. */
649
+ async createColumn(params) {
650
+ const body = {
651
+ title: params.title,
652
+ data_type: params.data_type || "text",
653
+ list_id: params.list_id ?? null,
654
+ created_by: params.created_by
655
+ };
656
+ const resp = await fetch(`${baseUrl}/api/v1/contacts/columns/create`, {
657
+ method: "POST",
658
+ headers: headers(),
659
+ body: JSON.stringify(body)
660
+ });
661
+ const data = await resp.json();
662
+ return data.data || data;
641
663
  }
642
664
  };
643
665
  };
@@ -691,6 +713,28 @@ var createCompaniesClient = (apiKey, apiUrl) => {
691
713
  headers: headers()
692
714
  });
693
715
  return resp.json();
716
+ },
717
+ /** List custom company columns. Pass listId to include list-specific columns. */
718
+ async listColumns(listId) {
719
+ const qs = listId != null ? `?list_id=${listId}` : "";
720
+ const resp = await fetch(`${baseUrl}/api/v1/companies/columns${qs}`, { headers: headers() });
721
+ return resp.json();
722
+ },
723
+ /** Create a custom company column. Global if list_id is omitted, list-scoped otherwise. */
724
+ async createColumn(params) {
725
+ const body = {
726
+ title: params.title,
727
+ data_type: params.data_type || "text",
728
+ list_id: params.list_id ?? null,
729
+ created_by: params.created_by
730
+ };
731
+ const resp = await fetch(`${baseUrl}/api/v1/companies/columns/create`, {
732
+ method: "POST",
733
+ headers: headers(),
734
+ body: JSON.stringify(body)
735
+ });
736
+ const data = await resp.json();
737
+ return data.data || data;
694
738
  }
695
739
  };
696
740
  };
@@ -753,9 +797,247 @@ var createListsClient = (apiKey, apiUrl) => {
753
797
  };
754
798
  };
755
799
 
800
+ // src/notes.ts
801
+ var DEFAULT_API18 = "https://be.graph8.com";
802
+ var createNotesClient = (apiKey, apiUrl) => {
803
+ const baseUrl = apiUrl || DEFAULT_API18;
804
+ const headers = () => ({ "Content-Type": "application/json", Authorization: `Bearer ${apiKey}` });
805
+ return {
806
+ /** List all notes on a contact. */
807
+ async list(contactId) {
808
+ const resp = await fetch(`${baseUrl}/api/v1/contacts/${contactId}/notes`, { headers: headers() });
809
+ return resp.json();
810
+ },
811
+ /** Create a note on a contact. */
812
+ async create(contactId, content) {
813
+ const resp = await fetch(`${baseUrl}/api/v1/contacts/${contactId}/notes`, {
814
+ method: "POST",
815
+ headers: headers(),
816
+ body: JSON.stringify({ content })
817
+ });
818
+ const data = await resp.json();
819
+ return data.data || data;
820
+ },
821
+ /** Update a note's content. */
822
+ async update(noteId, content) {
823
+ const resp = await fetch(`${baseUrl}/api/v1/notes/${noteId}`, {
824
+ method: "PATCH",
825
+ headers: headers(),
826
+ body: JSON.stringify({ content })
827
+ });
828
+ const data = await resp.json();
829
+ return data.data || data;
830
+ },
831
+ /** Delete a note. */
832
+ async delete(noteId) {
833
+ const resp = await fetch(`${baseUrl}/api/v1/notes/${noteId}`, {
834
+ method: "DELETE",
835
+ headers: headers()
836
+ });
837
+ return resp.json();
838
+ }
839
+ };
840
+ };
841
+
842
+ // src/tasks.ts
843
+ var DEFAULT_API19 = "https://be.graph8.com";
844
+ var createTasksClient = (apiKey, apiUrl) => {
845
+ const baseUrl = apiUrl || DEFAULT_API19;
846
+ const headers = () => ({ "Content-Type": "application/json", Authorization: `Bearer ${apiKey}` });
847
+ const toQuery = (params) => {
848
+ const qs = new URLSearchParams();
849
+ for (const [k, v] of Object.entries(params)) {
850
+ if (v != null) qs.set(k, String(v));
851
+ }
852
+ const s = qs.toString();
853
+ return s ? `?${s}` : "";
854
+ };
855
+ return {
856
+ /** List tasks on a single contact. Optional status filter ("open" | "completed"). */
857
+ async listForContact(contactId, status) {
858
+ const qs = status ? `?status=${encodeURIComponent(status)}` : "";
859
+ const resp = await fetch(`${baseUrl}/api/v1/contacts/${contactId}/tasks${qs}`, { headers: headers() });
860
+ return resp.json();
861
+ },
862
+ /** List all tasks org-wide with optional filters. */
863
+ async list(params = {}) {
864
+ const resp = await fetch(`${baseUrl}/api/v1/tasks${toQuery(params)}`, { headers: headers() });
865
+ return resp.json();
866
+ },
867
+ /** Create a task on a contact. */
868
+ async create(contactId, task) {
869
+ const resp = await fetch(`${baseUrl}/api/v1/contacts/${contactId}/tasks`, {
870
+ method: "POST",
871
+ headers: headers(),
872
+ body: JSON.stringify(task)
873
+ });
874
+ const data = await resp.json();
875
+ return data.data || data;
876
+ },
877
+ /** Update a task (partial). */
878
+ async update(taskId, fields) {
879
+ const resp = await fetch(`${baseUrl}/api/v1/tasks/${taskId}`, {
880
+ method: "PATCH",
881
+ headers: headers(),
882
+ body: JSON.stringify(fields)
883
+ });
884
+ const data = await resp.json();
885
+ return data.data || data;
886
+ },
887
+ /** Delete a task. */
888
+ async delete(taskId) {
889
+ const resp = await fetch(`${baseUrl}/api/v1/tasks/${taskId}`, {
890
+ method: "DELETE",
891
+ headers: headers()
892
+ });
893
+ return resp.json();
894
+ }
895
+ };
896
+ };
897
+
898
+ // src/fields.ts
899
+ var DEFAULT_API20 = "https://be.graph8.com";
900
+ var createFieldsClient = (apiKey, apiUrl) => {
901
+ const baseUrl = apiUrl || DEFAULT_API20;
902
+ const headers = () => ({ "Content-Type": "application/json", Authorization: `Bearer ${apiKey}` });
903
+ const toQuery = (params) => {
904
+ const qs = new URLSearchParams();
905
+ for (const [k, v] of Object.entries(params)) {
906
+ if (v != null) qs.set(k, String(v));
907
+ }
908
+ const s = qs.toString();
909
+ return s ? `?${s}` : "";
910
+ };
911
+ return {
912
+ /** List contact fields (base + custom). Pass listId to include list-specific custom fields. */
913
+ async listContactFields(listId) {
914
+ const qs = listId != null ? `?list_id=${listId}` : "";
915
+ const resp = await fetch(`${baseUrl}/api/v1/fields${qs}`, { headers: headers() });
916
+ return resp.json();
917
+ },
918
+ /** List company fields (base + custom). Pass listId to include list-specific custom fields. */
919
+ async listCompanyFields(listId) {
920
+ const qs = listId != null ? `?list_id=${listId}` : "";
921
+ const resp = await fetch(`${baseUrl}/api/v1/fields/companies${qs}`, { headers: headers() });
922
+ return resp.json();
923
+ },
924
+ /** Create a custom field on contacts (default) or companies. */
925
+ async create(params) {
926
+ const body = {
927
+ title: params.title,
928
+ data_type: params.data_type || "text",
929
+ list_id: params.list_id ?? null,
930
+ entity: params.entity || "contacts"
931
+ };
932
+ const resp = await fetch(`${baseUrl}/api/v1/fields`, {
933
+ method: "POST",
934
+ headers: headers(),
935
+ body: JSON.stringify(body)
936
+ });
937
+ const data = await resp.json();
938
+ return data.data || data;
939
+ },
940
+ /** Delete a custom field (soft-delete). Pass list_id to scope-guard against cross-list deletion. */
941
+ async delete(columnId, params = {}) {
942
+ const queryParams = { entity: params.entity || "contacts" };
943
+ if (params.list_id != null) queryParams.list_id = params.list_id;
944
+ const resp = await fetch(`${baseUrl}/api/v1/fields/${columnId}${toQuery(queryParams)}`, {
945
+ method: "DELETE",
946
+ headers: headers()
947
+ });
948
+ return resp.json();
949
+ },
950
+ /** Set a custom field value on a single contact or company row. Pass value=null to clear. */
951
+ async setValue(columnId, params) {
952
+ const body = {
953
+ record_id: params.record_id,
954
+ value: params.value ?? null,
955
+ entity: params.entity || "contacts"
956
+ };
957
+ const resp = await fetch(`${baseUrl}/api/v1/fields/${columnId}/values`, {
958
+ method: "PATCH",
959
+ headers: headers(),
960
+ body: JSON.stringify(body)
961
+ });
962
+ return resp.json();
963
+ }
964
+ };
965
+ };
966
+
967
+ // src/deals.ts
968
+ var DEFAULT_API21 = "https://be.graph8.com";
969
+ var createDealsClient = (apiKey, apiUrl) => {
970
+ const baseUrl = apiUrl || DEFAULT_API21;
971
+ const headers = () => ({ "Content-Type": "application/json", Authorization: `Bearer ${apiKey}` });
972
+ const toQuery = (params) => {
973
+ const qs = new URLSearchParams();
974
+ for (const [k, v] of Object.entries(params)) {
975
+ if (v != null) qs.set(k, String(v));
976
+ }
977
+ const s = qs.toString();
978
+ return s ? `?${s}` : "";
979
+ };
980
+ return {
981
+ /** List all deal pipelines and their stages. */
982
+ async pipelines() {
983
+ const resp = await fetch(`${baseUrl}/api/v1/deals/pipelines`, { headers: headers() });
984
+ return resp.json();
985
+ },
986
+ /** List deals org-wide with optional filters and pagination. */
987
+ async list(params = {}) {
988
+ const resp = await fetch(`${baseUrl}/api/v1/deals${toQuery(params)}`, { headers: headers() });
989
+ return resp.json();
990
+ },
991
+ /** Create a new deal. */
992
+ async create(deal) {
993
+ const resp = await fetch(`${baseUrl}/api/v1/deals`, {
994
+ method: "POST",
995
+ headers: headers(),
996
+ body: JSON.stringify(deal)
997
+ });
998
+ const data = await resp.json();
999
+ return data.data || data;
1000
+ },
1001
+ /** Get a single deal by ID. */
1002
+ async get(dealId) {
1003
+ const resp = await fetch(`${baseUrl}/api/v1/deals/${dealId}`, { headers: headers() });
1004
+ const data = await resp.json();
1005
+ return data.data || data;
1006
+ },
1007
+ /** Update a deal (partial). */
1008
+ async update(dealId, fields) {
1009
+ const resp = await fetch(`${baseUrl}/api/v1/deals/${dealId}`, {
1010
+ method: "PATCH",
1011
+ headers: headers(),
1012
+ body: JSON.stringify(fields)
1013
+ });
1014
+ const data = await resp.json();
1015
+ return data.data || data;
1016
+ },
1017
+ /** Delete a deal. */
1018
+ async delete(dealId) {
1019
+ const resp = await fetch(`${baseUrl}/api/v1/deals/${dealId}`, {
1020
+ method: "DELETE",
1021
+ headers: headers()
1022
+ });
1023
+ return resp.json();
1024
+ },
1025
+ /** Get all deals associated with a contact. */
1026
+ async forContact(contactId) {
1027
+ const resp = await fetch(`${baseUrl}/api/v1/contacts/${contactId}/deals`, { headers: headers() });
1028
+ return resp.json();
1029
+ },
1030
+ /** Get all deals associated with a company. */
1031
+ async forCompany(companyId) {
1032
+ const resp = await fetch(`${baseUrl}/api/v1/companies/${companyId}/deals`, { headers: headers() });
1033
+ return resp.json();
1034
+ }
1035
+ };
1036
+ };
1037
+
756
1038
  // src/core.ts
757
1039
  var DEFAULT_HOST = "https://t.graph8.com";
758
- var DEFAULT_API18 = "https://be.graph8.com";
1040
+ var DEFAULT_API22 = "https://be.graph8.com";
759
1041
  var G8 = class {
760
1042
  constructor() {
761
1043
  /** @internal */
@@ -796,6 +1078,14 @@ var G8 = class {
796
1078
  this._companies = null;
797
1079
  /** @internal */
798
1080
  this._lists = null;
1081
+ /** @internal */
1082
+ this._notes = null;
1083
+ /** @internal */
1084
+ this._tasks = null;
1085
+ /** @internal */
1086
+ this._fields = null;
1087
+ /** @internal */
1088
+ this._deals = null;
799
1089
  }
800
1090
  /**
801
1091
  * Initialize the graph8 SDK. Must be called before any other method.
@@ -810,7 +1100,7 @@ var G8 = class {
810
1100
  debug: config.debug
811
1101
  });
812
1102
  }
813
- const apiUrl = config.apiUrl || DEFAULT_API18;
1103
+ const apiUrl = config.apiUrl || DEFAULT_API22;
814
1104
  const writeKey = config.writeKey || "";
815
1105
  const apiKey = config.apiKey || "";
816
1106
  if (writeKey) {
@@ -833,6 +1123,10 @@ var G8 = class {
833
1123
  this._contacts = createContactsClient(apiKey, apiUrl);
834
1124
  this._companies = createCompaniesClient(apiKey, apiUrl);
835
1125
  this._lists = createListsClient(apiKey, apiUrl);
1126
+ this._notes = createNotesClient(apiKey, apiUrl);
1127
+ this._tasks = createTasksClient(apiKey, apiUrl);
1128
+ this._fields = createFieldsClient(apiKey, apiUrl);
1129
+ this._deals = createDealsClient(apiKey, apiUrl);
836
1130
  this._signals = createSignalsClient(apiKey, true, apiUrl);
837
1131
  }
838
1132
  }
@@ -939,6 +1233,26 @@ var G8 = class {
939
1233
  this._assertKey("lists");
940
1234
  return this._lists;
941
1235
  }
1236
+ /** Notes on contacts (requires API key). */
1237
+ get notes() {
1238
+ this._assertKey("notes");
1239
+ return this._notes;
1240
+ }
1241
+ /** Tasks on contacts (requires API key). */
1242
+ get tasks() {
1243
+ this._assertKey("tasks");
1244
+ return this._tasks;
1245
+ }
1246
+ /** Custom fields management (requires API key). */
1247
+ get fields() {
1248
+ this._assertKey("fields");
1249
+ return this._fields;
1250
+ }
1251
+ /** Deals and pipelines (requires API key). */
1252
+ get deals() {
1253
+ this._assertKey("deals");
1254
+ return this._deals;
1255
+ }
942
1256
  /** Whether the SDK has been initialized. */
943
1257
  get initialized() {
944
1258
  return this.config !== null;