@graph8/sdk 0.7.2 → 0.12.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 +67 -39
- package/dist/index.d.mts +416 -164
- package/dist/index.d.ts +416 -164
- package/dist/index.js +291 -178
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +284 -178
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +186 -156
- package/dist/react.d.ts +186 -156
- package/dist/react.js +115 -178
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +115 -178
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -32,6 +32,21 @@ var createFormsClient = (writeKey, apiUrl) => {
|
|
|
32
32
|
|
|
33
33
|
// src/utils.ts
|
|
34
34
|
var isServer = typeof window === "undefined";
|
|
35
|
+
var resolveAppBaseUrl = (apiBaseUrl) => {
|
|
36
|
+
try {
|
|
37
|
+
const url = new URL(apiBaseUrl);
|
|
38
|
+
if (url.hostname === "localhost" || url.hostname === "127.0.0.1") {
|
|
39
|
+
url.port = "3000";
|
|
40
|
+
return url.origin;
|
|
41
|
+
}
|
|
42
|
+
if (url.hostname.endsWith("graph8.com")) {
|
|
43
|
+
url.hostname = url.hostname.replace(/^be\./, "app.");
|
|
44
|
+
return url.origin;
|
|
45
|
+
}
|
|
46
|
+
} catch {
|
|
47
|
+
}
|
|
48
|
+
return apiBaseUrl;
|
|
49
|
+
};
|
|
35
50
|
|
|
36
51
|
// src/visitors.ts
|
|
37
52
|
var DEFAULT_API2 = "https://be.graph8.com";
|
|
@@ -144,6 +159,7 @@ var createCopilotClient = (writeKey, apiUrl) => {
|
|
|
144
159
|
var DEFAULT_API4 = "https://be.graph8.com";
|
|
145
160
|
var createChatClient = (writeKey, apiUrl) => {
|
|
146
161
|
const baseUrl = apiUrl || DEFAULT_API4;
|
|
162
|
+
const appUrl = resolveAppBaseUrl(baseUrl);
|
|
147
163
|
const listeners = /* @__PURE__ */ new Map();
|
|
148
164
|
let widgetEl = null;
|
|
149
165
|
let ws = null;
|
|
@@ -158,7 +174,7 @@ var createChatClient = (writeKey, apiUrl) => {
|
|
|
158
174
|
const position = config?.position || "bottom-right";
|
|
159
175
|
const posStyle = position === "bottom-left" ? "left:16px;" : "right:16px;";
|
|
160
176
|
const iframe = document.createElement("iframe");
|
|
161
|
-
iframe.src = `${
|
|
177
|
+
iframe.src = `${appUrl}/webchat/embed?write_key=${writeKey}&theme=${config?.theme || "auto"}`;
|
|
162
178
|
iframe.style.cssText = `position:fixed;bottom:16px;${posStyle}width:380px;height:560px;border:none;border-radius:12px;box-shadow:0 8px 32px rgba(0,0,0,0.15);z-index:99997;`;
|
|
163
179
|
iframe.id = "g8-chat-widget";
|
|
164
180
|
document.body.appendChild(iframe);
|
|
@@ -283,6 +299,19 @@ var G8Error = class _G8Error extends Error {
|
|
|
283
299
|
function isRetryableStatus(status) {
|
|
284
300
|
return status === 429 || status >= 500 && status <= 599;
|
|
285
301
|
}
|
|
302
|
+
function isNonIdempotentMethod(method) {
|
|
303
|
+
const m = method.toUpperCase();
|
|
304
|
+
return m === "POST" || m === "PATCH";
|
|
305
|
+
}
|
|
306
|
+
function newIdempotencyKey() {
|
|
307
|
+
const c = globalThis.crypto;
|
|
308
|
+
if (c?.randomUUID) return c.randomUUID();
|
|
309
|
+
if (c?.getRandomValues) {
|
|
310
|
+
const bytes = c.getRandomValues(new Uint8Array(16));
|
|
311
|
+
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
312
|
+
}
|
|
313
|
+
return `g8-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 12)}`;
|
|
314
|
+
}
|
|
286
315
|
function parseRetryAfter(header, nowMs = Date.now()) {
|
|
287
316
|
if (!header) return null;
|
|
288
317
|
const secs = Number(header);
|
|
@@ -349,7 +378,8 @@ async function request(baseUrl, path, apiKey, opts = {}) {
|
|
|
349
378
|
Authorization: `Bearer ${apiKey}`,
|
|
350
379
|
...headers
|
|
351
380
|
};
|
|
352
|
-
|
|
381
|
+
const effectiveIdempotencyKey = idempotencyKey ?? (maxRetries > 0 && isNonIdempotentMethod(method) ? newIdempotencyKey() : void 0);
|
|
382
|
+
if (effectiveIdempotencyKey) finalHeaders["Idempotency-Key"] = effectiveIdempotencyKey;
|
|
353
383
|
let attempt = 0;
|
|
354
384
|
for (; ; ) {
|
|
355
385
|
let resp;
|
|
@@ -427,7 +457,7 @@ var createEnrichClient = (apiKey, apiUrl) => {
|
|
|
427
457
|
});
|
|
428
458
|
return resp.data ?? resp;
|
|
429
459
|
},
|
|
430
|
-
/** Search
|
|
460
|
+
/** Search 700M+ contacts with filters. Credits charged per result. */
|
|
431
461
|
async search(filters, page = 1, limit = 25) {
|
|
432
462
|
const resp = await request(baseUrl, "/api/v1/search/contacts", apiKey, {
|
|
433
463
|
method: "POST",
|
|
@@ -600,45 +630,23 @@ var createCampaignsClient = (apiKey, apiUrl) => {
|
|
|
600
630
|
return resp.data ?? resp;
|
|
601
631
|
},
|
|
602
632
|
async launch(campaignId) {
|
|
603
|
-
await request(
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
633
|
+
const resp = await request(
|
|
634
|
+
baseUrl,
|
|
635
|
+
`/api/v1/campaigns/${campaignId}/launch`,
|
|
636
|
+
apiKey,
|
|
637
|
+
{ method: "POST" }
|
|
638
|
+
);
|
|
607
639
|
return resp.data ?? resp;
|
|
608
640
|
}
|
|
609
641
|
};
|
|
610
642
|
};
|
|
611
643
|
|
|
612
|
-
// src/integrations.ts
|
|
613
|
-
var DEFAULT_API9 = "https://be.graph8.com";
|
|
614
|
-
var createIntegrationsClient = (apiKey, apiUrl) => {
|
|
615
|
-
const baseUrl = apiUrl || DEFAULT_API9;
|
|
616
|
-
return {
|
|
617
|
-
async list() {
|
|
618
|
-
const resp = await request(baseUrl, "/api/v1/integrations", apiKey);
|
|
619
|
-
return resp.data ?? resp;
|
|
620
|
-
},
|
|
621
|
-
async connect(provider, config) {
|
|
622
|
-
await request(baseUrl, "/api/v1/integrations/connect", apiKey, {
|
|
623
|
-
method: "POST",
|
|
624
|
-
body: { provider, ...config }
|
|
625
|
-
});
|
|
626
|
-
},
|
|
627
|
-
async sync(provider, config) {
|
|
628
|
-
await request(baseUrl, "/api/v1/integrations/sync", apiKey, {
|
|
629
|
-
method: "POST",
|
|
630
|
-
body: { provider, ...config }
|
|
631
|
-
});
|
|
632
|
-
}
|
|
633
|
-
};
|
|
634
|
-
};
|
|
635
|
-
|
|
636
644
|
// src/signals.ts
|
|
637
|
-
var
|
|
645
|
+
var DEFAULT_API9 = "https://be.graph8.com";
|
|
638
646
|
var createSignalsClient = (key, isApiKey, apiUrl) => {
|
|
639
|
-
const baseUrl = apiUrl ||
|
|
647
|
+
const baseUrl = apiUrl || DEFAULT_API9;
|
|
640
648
|
const headers = () => isApiKey ? { "Content-Type": "application/json", "Authorization": `Bearer ${key}` } : { "Content-Type": "application/json", "X-Write-Key": key };
|
|
641
|
-
const endpoint =
|
|
649
|
+
const endpoint = "/api/v1/public/signals/company";
|
|
642
650
|
return {
|
|
643
651
|
/** Get intent signals for a specific company domain. */
|
|
644
652
|
async company(domain) {
|
|
@@ -663,24 +671,10 @@ var createSignalsClient = (key, isApiKey, apiUrl) => {
|
|
|
663
671
|
};
|
|
664
672
|
};
|
|
665
673
|
|
|
666
|
-
// src/analytics.ts
|
|
667
|
-
var DEFAULT_API11 = "https://be.graph8.com";
|
|
668
|
-
var createAnalyticsClient = (apiKey, apiUrl) => {
|
|
669
|
-
const baseUrl = apiUrl || DEFAULT_API11;
|
|
670
|
-
return {
|
|
671
|
-
async overview(config) {
|
|
672
|
-
const resp = await request(baseUrl, "/api/v1/analytics/overview", apiKey, {
|
|
673
|
-
query: { period: config?.period }
|
|
674
|
-
});
|
|
675
|
-
return resp.data ?? resp;
|
|
676
|
-
}
|
|
677
|
-
};
|
|
678
|
-
};
|
|
679
|
-
|
|
680
674
|
// src/voice.ts
|
|
681
|
-
var
|
|
675
|
+
var DEFAULT_API10 = "https://be.graph8.com";
|
|
682
676
|
var createVoiceClient = (apiKey, apiUrl) => {
|
|
683
|
-
const baseUrl = apiUrl ||
|
|
677
|
+
const baseUrl = apiUrl || DEFAULT_API10;
|
|
684
678
|
const listeners = /* @__PURE__ */ new Map();
|
|
685
679
|
const dialer = {
|
|
686
680
|
/** List parallel-dialer sessions with filters + pagination. */
|
|
@@ -813,31 +807,6 @@ var createVoiceClient = (apiKey, apiUrl) => {
|
|
|
813
807
|
}
|
|
814
808
|
};
|
|
815
809
|
return {
|
|
816
|
-
/**
|
|
817
|
-
* Start an AI voice session.
|
|
818
|
-
* @deprecated Preview surface — for parallel-dialer flows use `voice.dialer.createSession()`.
|
|
819
|
-
*/
|
|
820
|
-
async start(config) {
|
|
821
|
-
const resp = await request(
|
|
822
|
-
baseUrl,
|
|
823
|
-
"/api/v1/voice/sessions",
|
|
824
|
-
apiKey,
|
|
825
|
-
{ method: "POST", body: config }
|
|
826
|
-
);
|
|
827
|
-
return resp.data ?? resp;
|
|
828
|
-
},
|
|
829
|
-
/**
|
|
830
|
-
* Get call analysis for a completed session.
|
|
831
|
-
* @deprecated Preview surface — for dialer-call grading use `voice.dialer.callGrading(roomName)`.
|
|
832
|
-
*/
|
|
833
|
-
async analysis(sessionId) {
|
|
834
|
-
const resp = await request(
|
|
835
|
-
baseUrl,
|
|
836
|
-
`/api/v1/voice/sessions/${sessionId}/analysis`,
|
|
837
|
-
apiKey
|
|
838
|
-
);
|
|
839
|
-
return resp.data ?? resp;
|
|
840
|
-
},
|
|
841
810
|
/** Listen for voice events. */
|
|
842
811
|
on(event, callback) {
|
|
843
812
|
if (!listeners.has(event)) listeners.set(event, []);
|
|
@@ -848,43 +817,9 @@ var createVoiceClient = (apiKey, apiUrl) => {
|
|
|
848
817
|
};
|
|
849
818
|
};
|
|
850
819
|
|
|
851
|
-
// src/pages.ts
|
|
852
|
-
var DEFAULT_API13 = "https://be.graph8.com";
|
|
853
|
-
var createPagesClient = (apiKey, apiUrl) => {
|
|
854
|
-
const baseUrl = apiUrl || DEFAULT_API13;
|
|
855
|
-
return {
|
|
856
|
-
/** Clone a landing page from any URL. */
|
|
857
|
-
async clone(url) {
|
|
858
|
-
const resp = await request(baseUrl, "/api/v1/landing-pages/clone-url", apiKey, {
|
|
859
|
-
method: "POST",
|
|
860
|
-
body: { url }
|
|
861
|
-
});
|
|
862
|
-
return resp.data ?? resp;
|
|
863
|
-
},
|
|
864
|
-
/** Create a landing page from a template. */
|
|
865
|
-
async create(config) {
|
|
866
|
-
const resp = await request(baseUrl, "/api/v1/landing-pages", apiKey, {
|
|
867
|
-
method: "POST",
|
|
868
|
-
body: config
|
|
869
|
-
});
|
|
870
|
-
return resp.data ?? resp;
|
|
871
|
-
},
|
|
872
|
-
/** Publish a landing page to CDN. */
|
|
873
|
-
async publish(pageId) {
|
|
874
|
-
const data = await request(
|
|
875
|
-
baseUrl,
|
|
876
|
-
`/api/v1/landing-pages/${pageId}/publish`,
|
|
877
|
-
apiKey,
|
|
878
|
-
{ method: "POST" }
|
|
879
|
-
);
|
|
880
|
-
return { url: data.published_url || data.data?.published_url || "" };
|
|
881
|
-
}
|
|
882
|
-
};
|
|
883
|
-
};
|
|
884
|
-
|
|
885
820
|
// src/webhooks.ts
|
|
886
821
|
import { createHmac, timingSafeEqual } from "crypto";
|
|
887
|
-
var
|
|
822
|
+
var DEFAULT_API11 = "https://be.graph8.com";
|
|
888
823
|
var KNOWN_WEBHOOK_EVENTS = [
|
|
889
824
|
"campaign.created",
|
|
890
825
|
"campaign.updated",
|
|
@@ -902,7 +837,7 @@ var KNOWN_WEBHOOK_EVENTS = [
|
|
|
902
837
|
"company_intelligence.completed",
|
|
903
838
|
"audience.ready",
|
|
904
839
|
"audience.failed",
|
|
905
|
-
"sequence.
|
|
840
|
+
"sequence.draft_created",
|
|
906
841
|
"sequence.started",
|
|
907
842
|
"sequence.paused",
|
|
908
843
|
"sequence.completed",
|
|
@@ -965,7 +900,7 @@ function constructEvent(payload, signature, timestamp, secret, opts = {}) {
|
|
|
965
900
|
}
|
|
966
901
|
}
|
|
967
902
|
var createWebhooksClient = (_apiKey, apiUrl) => {
|
|
968
|
-
const baseUrl = apiUrl ||
|
|
903
|
+
const baseUrl = apiUrl || DEFAULT_API11;
|
|
969
904
|
return {
|
|
970
905
|
/** Base URL the webhook subscription API lives under. */
|
|
971
906
|
baseUrl,
|
|
@@ -979,9 +914,9 @@ var createWebhooksClient = (_apiKey, apiUrl) => {
|
|
|
979
914
|
};
|
|
980
915
|
|
|
981
916
|
// src/contacts.ts
|
|
982
|
-
var
|
|
917
|
+
var DEFAULT_API12 = "https://be.graph8.com";
|
|
983
918
|
var createContactsClient = (apiKey, apiUrl) => {
|
|
984
|
-
const baseUrl = apiUrl ||
|
|
919
|
+
const baseUrl = apiUrl || DEFAULT_API12;
|
|
985
920
|
return {
|
|
986
921
|
/** List contacts with optional filters. */
|
|
987
922
|
async list(params = {}) {
|
|
@@ -1040,9 +975,9 @@ var createContactsClient = (apiKey, apiUrl) => {
|
|
|
1040
975
|
};
|
|
1041
976
|
|
|
1042
977
|
// src/companies.ts
|
|
1043
|
-
var
|
|
978
|
+
var DEFAULT_API13 = "https://be.graph8.com";
|
|
1044
979
|
var createCompaniesClient = (apiKey, apiUrl) => {
|
|
1045
|
-
const baseUrl = apiUrl ||
|
|
980
|
+
const baseUrl = apiUrl || DEFAULT_API13;
|
|
1046
981
|
return {
|
|
1047
982
|
/** List companies with optional filters. */
|
|
1048
983
|
async list(params = {}) {
|
|
@@ -1088,9 +1023,9 @@ var createCompaniesClient = (apiKey, apiUrl) => {
|
|
|
1088
1023
|
};
|
|
1089
1024
|
|
|
1090
1025
|
// src/lists.ts
|
|
1091
|
-
var
|
|
1026
|
+
var DEFAULT_API14 = "https://be.graph8.com";
|
|
1092
1027
|
var createListsClient = (apiKey, apiUrl) => {
|
|
1093
|
-
const baseUrl = apiUrl ||
|
|
1028
|
+
const baseUrl = apiUrl || DEFAULT_API14;
|
|
1094
1029
|
return {
|
|
1095
1030
|
/** List all lists. */
|
|
1096
1031
|
async list(page = 1, limit = 50) {
|
|
@@ -1130,9 +1065,9 @@ var createListsClient = (apiKey, apiUrl) => {
|
|
|
1130
1065
|
};
|
|
1131
1066
|
|
|
1132
1067
|
// src/notes.ts
|
|
1133
|
-
var
|
|
1068
|
+
var DEFAULT_API15 = "https://be.graph8.com";
|
|
1134
1069
|
var createNotesClient = (apiKey, apiUrl) => {
|
|
1135
|
-
const baseUrl = apiUrl ||
|
|
1070
|
+
const baseUrl = apiUrl || DEFAULT_API15;
|
|
1136
1071
|
return {
|
|
1137
1072
|
/** List all notes on a contact. */
|
|
1138
1073
|
async list(contactId) {
|
|
@@ -1162,9 +1097,9 @@ var createNotesClient = (apiKey, apiUrl) => {
|
|
|
1162
1097
|
};
|
|
1163
1098
|
|
|
1164
1099
|
// src/tasks.ts
|
|
1165
|
-
var
|
|
1100
|
+
var DEFAULT_API16 = "https://be.graph8.com";
|
|
1166
1101
|
var createTasksClient = (apiKey, apiUrl) => {
|
|
1167
|
-
const baseUrl = apiUrl ||
|
|
1102
|
+
const baseUrl = apiUrl || DEFAULT_API16;
|
|
1168
1103
|
return {
|
|
1169
1104
|
/** List tasks on a single contact. Optional status filter ("open" | "completed"). */
|
|
1170
1105
|
async listForContact(contactId, status) {
|
|
@@ -1200,9 +1135,9 @@ var createTasksClient = (apiKey, apiUrl) => {
|
|
|
1200
1135
|
};
|
|
1201
1136
|
|
|
1202
1137
|
// src/fields.ts
|
|
1203
|
-
var
|
|
1138
|
+
var DEFAULT_API17 = "https://be.graph8.com";
|
|
1204
1139
|
var createFieldsClient = (apiKey, apiUrl) => {
|
|
1205
|
-
const baseUrl = apiUrl ||
|
|
1140
|
+
const baseUrl = apiUrl || DEFAULT_API17;
|
|
1206
1141
|
return {
|
|
1207
1142
|
/** List contact fields (base + custom). Pass listId to include list-specific custom fields. */
|
|
1208
1143
|
async listContactFields(listId) {
|
|
@@ -1244,9 +1179,9 @@ var createFieldsClient = (apiKey, apiUrl) => {
|
|
|
1244
1179
|
};
|
|
1245
1180
|
|
|
1246
1181
|
// src/deals.ts
|
|
1247
|
-
var
|
|
1182
|
+
var DEFAULT_API18 = "https://be.graph8.com";
|
|
1248
1183
|
var createDealsClient = (apiKey, apiUrl) => {
|
|
1249
|
-
const baseUrl = apiUrl ||
|
|
1184
|
+
const baseUrl = apiUrl || DEFAULT_API18;
|
|
1250
1185
|
return {
|
|
1251
1186
|
/** List all deal pipelines and their stages. */
|
|
1252
1187
|
async pipelines() {
|
|
@@ -1290,9 +1225,9 @@ var createDealsClient = (apiKey, apiUrl) => {
|
|
|
1290
1225
|
};
|
|
1291
1226
|
|
|
1292
1227
|
// src/inbox.ts
|
|
1293
|
-
var
|
|
1228
|
+
var DEFAULT_API19 = "https://be.graph8.com";
|
|
1294
1229
|
var createInboxClient = (apiKey, apiUrl) => {
|
|
1295
|
-
const baseUrl = apiUrl ||
|
|
1230
|
+
const baseUrl = apiUrl || DEFAULT_API19;
|
|
1296
1231
|
return {
|
|
1297
1232
|
/** List inbox threads across email, SMS, and LinkedIn. */
|
|
1298
1233
|
async list(params = {}) {
|
|
@@ -1345,9 +1280,9 @@ var createInboxClient = (apiKey, apiUrl) => {
|
|
|
1345
1280
|
};
|
|
1346
1281
|
|
|
1347
1282
|
// src/quotes.ts
|
|
1348
|
-
var
|
|
1283
|
+
var DEFAULT_API20 = "https://be.graph8.com";
|
|
1349
1284
|
var createQuotesClient = (apiKey, apiUrl) => {
|
|
1350
|
-
const baseUrl = apiUrl ||
|
|
1285
|
+
const baseUrl = apiUrl || DEFAULT_API20;
|
|
1351
1286
|
return {
|
|
1352
1287
|
/** List quotes org-wide with optional filters and pagination. */
|
|
1353
1288
|
async list(params = {}) {
|
|
@@ -1419,9 +1354,9 @@ var createQuotesClient = (apiKey, apiUrl) => {
|
|
|
1419
1354
|
};
|
|
1420
1355
|
|
|
1421
1356
|
// src/pipelines.ts
|
|
1422
|
-
var
|
|
1357
|
+
var DEFAULT_API21 = "https://be.graph8.com";
|
|
1423
1358
|
var createPipelinesClient = (apiKey, apiUrl) => {
|
|
1424
|
-
const baseUrl = apiUrl ||
|
|
1359
|
+
const baseUrl = apiUrl || DEFAULT_API21;
|
|
1425
1360
|
return {
|
|
1426
1361
|
/** List all stage-checklist pipelines with stages, evidence, scripts. */
|
|
1427
1362
|
async list() {
|
|
@@ -1503,9 +1438,9 @@ var createPipelinesClient = (apiKey, apiUrl) => {
|
|
|
1503
1438
|
};
|
|
1504
1439
|
|
|
1505
1440
|
// src/workflows.ts
|
|
1506
|
-
var
|
|
1441
|
+
var DEFAULT_API22 = "https://be.graph8.com";
|
|
1507
1442
|
var createWorkflowsClient = (apiKey, apiUrl) => {
|
|
1508
|
-
const baseUrl = apiUrl ||
|
|
1443
|
+
const baseUrl = apiUrl || DEFAULT_API22;
|
|
1509
1444
|
return {
|
|
1510
1445
|
/** List workflows org-wide. */
|
|
1511
1446
|
async list(params = {}) {
|
|
@@ -1621,9 +1556,9 @@ var createWorkflowsClient = (apiKey, apiUrl) => {
|
|
|
1621
1556
|
};
|
|
1622
1557
|
|
|
1623
1558
|
// src/skills.ts
|
|
1624
|
-
var
|
|
1559
|
+
var DEFAULT_API23 = "https://be.graph8.com";
|
|
1625
1560
|
var createSkillsClient = (apiKey, apiUrl) => {
|
|
1626
|
-
const baseUrl = apiUrl ||
|
|
1561
|
+
const baseUrl = apiUrl || DEFAULT_API23;
|
|
1627
1562
|
return {
|
|
1628
1563
|
/** List skills. */
|
|
1629
1564
|
async list(params = {}) {
|
|
@@ -1710,9 +1645,9 @@ var createSkillsClient = (apiKey, apiUrl) => {
|
|
|
1710
1645
|
};
|
|
1711
1646
|
|
|
1712
1647
|
// src/intent.ts
|
|
1713
|
-
var
|
|
1648
|
+
var DEFAULT_API24 = "https://be.graph8.com";
|
|
1714
1649
|
var createIntentClient = (apiKey, apiUrl) => {
|
|
1715
|
-
const baseUrl = apiUrl ||
|
|
1650
|
+
const baseUrl = apiUrl || DEFAULT_API24;
|
|
1716
1651
|
const get = (path) => request(baseUrl, `/api/v1${path}`, apiKey);
|
|
1717
1652
|
const post = (path, body = {}) => request(baseUrl, `/api/v1${path}`, apiKey, { method: "POST", body });
|
|
1718
1653
|
const del = (path) => request(baseUrl, `/api/v1${path}`, apiKey, { method: "DELETE" });
|
|
@@ -1781,10 +1716,12 @@ var createIntentClient = (apiKey, apiUrl) => {
|
|
|
1781
1716
|
};
|
|
1782
1717
|
|
|
1783
1718
|
// src/studio.ts
|
|
1784
|
-
var
|
|
1719
|
+
var DEFAULT_API25 = "https://be.graph8.com";
|
|
1785
1720
|
var createStudioClient = (apiKey, apiUrl) => {
|
|
1786
|
-
const baseUrl = apiUrl ||
|
|
1721
|
+
const baseUrl = apiUrl || DEFAULT_API25;
|
|
1787
1722
|
const get = (path, params = {}) => request(baseUrl, `/api/v1${path}`, apiKey, { query: params });
|
|
1723
|
+
const post = (path, body = {}) => request(baseUrl, `/api/v1${path}`, apiKey, { method: "POST", body });
|
|
1724
|
+
const patch = (path, body = {}) => request(baseUrl, `/api/v1${path}`, apiKey, { method: "PATCH", body });
|
|
1788
1725
|
return {
|
|
1789
1726
|
/** Org-level Studio documents (brand_brief, value_props, messaging_house, etc.).
|
|
1790
1727
|
* `include_content` defaults to true server-side, so each document includes
|
|
@@ -1807,14 +1744,38 @@ var createStudioClient = (apiKey, apiUrl) => {
|
|
|
1807
1744
|
/** AI research reports (buyer psychology, competitive teardown, GTM channel, etc.). */
|
|
1808
1745
|
async researchReports(params = {}) {
|
|
1809
1746
|
return get("/research-reports", params);
|
|
1747
|
+
},
|
|
1748
|
+
/** Create an ICP manually (no AI scoring). Requires name + website_url. */
|
|
1749
|
+
async createIcp(body) {
|
|
1750
|
+
return post("/icps", body);
|
|
1751
|
+
},
|
|
1752
|
+
/** Update an ICP (partial - send only fields to change). */
|
|
1753
|
+
async updateIcp(icpId, body) {
|
|
1754
|
+
return patch(`/icps/${icpId}`, body);
|
|
1755
|
+
},
|
|
1756
|
+
/** Archive an ICP (soft delete - sets status to "archived"). */
|
|
1757
|
+
async archiveIcp(icpId) {
|
|
1758
|
+
return post(`/icps/${icpId}/archive`);
|
|
1759
|
+
},
|
|
1760
|
+
/** Create a buyer persona manually (no AI generation). Requires title + website_url. */
|
|
1761
|
+
async createPersona(body) {
|
|
1762
|
+
return post("/personas", body);
|
|
1763
|
+
},
|
|
1764
|
+
/** Update a persona (partial). Passing status "archived" is equivalent to archivePersona. */
|
|
1765
|
+
async updatePersona(personaId, body) {
|
|
1766
|
+
return patch(`/personas/${personaId}`, body);
|
|
1767
|
+
},
|
|
1768
|
+
/** Archive a persona (soft delete - sets status to "archived"). */
|
|
1769
|
+
async archivePersona(personaId) {
|
|
1770
|
+
return post(`/personas/${personaId}/archive`);
|
|
1810
1771
|
}
|
|
1811
1772
|
};
|
|
1812
1773
|
};
|
|
1813
1774
|
|
|
1814
1775
|
// src/meetings.ts
|
|
1815
|
-
var
|
|
1776
|
+
var DEFAULT_API26 = "https://be.graph8.com";
|
|
1816
1777
|
var createMeetingsClient = (apiKey, apiUrl) => {
|
|
1817
|
-
const baseUrl = apiUrl ||
|
|
1778
|
+
const baseUrl = apiUrl || DEFAULT_API26;
|
|
1818
1779
|
return {
|
|
1819
1780
|
/** List meetings with optional filters. Returns summary rows without transcript / analysis. */
|
|
1820
1781
|
async list(params = {}) {
|
|
@@ -1829,9 +1790,9 @@ var createMeetingsClient = (apiKey, apiUrl) => {
|
|
|
1829
1790
|
};
|
|
1830
1791
|
|
|
1831
1792
|
// src/audiences.ts
|
|
1832
|
-
var
|
|
1793
|
+
var DEFAULT_API27 = "https://be.graph8.com";
|
|
1833
1794
|
var createAudiencesClient = (apiKey, apiUrl) => {
|
|
1834
|
-
const baseUrl = apiUrl ||
|
|
1795
|
+
const baseUrl = apiUrl || DEFAULT_API27;
|
|
1835
1796
|
const base = "/api/v1/audience-syncs";
|
|
1836
1797
|
return {
|
|
1837
1798
|
/** List all audience syncs for the organization. */
|
|
@@ -1879,9 +1840,9 @@ var createAudiencesClient = (apiKey, apiUrl) => {
|
|
|
1879
1840
|
};
|
|
1880
1841
|
|
|
1881
1842
|
// src/search.ts
|
|
1882
|
-
var
|
|
1843
|
+
var DEFAULT_API28 = "https://be.graph8.com";
|
|
1883
1844
|
var createSearchClient = (apiKey, apiUrl) => {
|
|
1884
|
-
const baseUrl = apiUrl ||
|
|
1845
|
+
const baseUrl = apiUrl || DEFAULT_API28;
|
|
1885
1846
|
const body = (p) => ({ filters: [], page: 1, limit: 25, ...p });
|
|
1886
1847
|
return {
|
|
1887
1848
|
/** Search open-data contacts by filter. */
|
|
@@ -1912,9 +1873,9 @@ var createSearchClient = (apiKey, apiUrl) => {
|
|
|
1912
1873
|
};
|
|
1913
1874
|
|
|
1914
1875
|
// src/agency.ts
|
|
1915
|
-
var
|
|
1876
|
+
var DEFAULT_API29 = "https://be.graph8.com";
|
|
1916
1877
|
var createAgencyClient = (apiKey, apiUrl) => {
|
|
1917
|
-
const baseUrl = apiUrl ||
|
|
1878
|
+
const baseUrl = apiUrl || DEFAULT_API29;
|
|
1918
1879
|
return {
|
|
1919
1880
|
/** Describe the agency credential: agency org + authorized client count. */
|
|
1920
1881
|
async me() {
|
|
@@ -1929,9 +1890,9 @@ var createAgencyClient = (apiKey, apiUrl) => {
|
|
|
1929
1890
|
};
|
|
1930
1891
|
|
|
1931
1892
|
// src/marketplace.ts
|
|
1932
|
-
var
|
|
1893
|
+
var DEFAULT_API30 = "https://be.graph8.com";
|
|
1933
1894
|
var createMarketplaceClient = (apiKey, apiUrl) => {
|
|
1934
|
-
const baseUrl = apiUrl ||
|
|
1895
|
+
const baseUrl = apiUrl || DEFAULT_API30;
|
|
1935
1896
|
const base = "/api/v1/marketplace";
|
|
1936
1897
|
return {
|
|
1937
1898
|
/** Your own marketplace SDR profile. */
|
|
@@ -1981,9 +1942,9 @@ var createMarketplaceClient = (apiKey, apiUrl) => {
|
|
|
1981
1942
|
};
|
|
1982
1943
|
|
|
1983
1944
|
// src/snippet.ts
|
|
1984
|
-
var
|
|
1945
|
+
var DEFAULT_API31 = "https://be.graph8.com";
|
|
1985
1946
|
var createSnippetClient = (apiKey, apiUrl) => {
|
|
1986
|
-
const baseUrl = apiUrl ||
|
|
1947
|
+
const baseUrl = apiUrl || DEFAULT_API31;
|
|
1987
1948
|
return {
|
|
1988
1949
|
/** Get your org's tracking snippet (write key + React/script-tag embeds + config). */
|
|
1989
1950
|
async get() {
|
|
@@ -1995,7 +1956,7 @@ var createSnippetClient = (apiKey, apiUrl) => {
|
|
|
1995
1956
|
|
|
1996
1957
|
// src/core.ts
|
|
1997
1958
|
var DEFAULT_HOST = "https://t.graph8.com";
|
|
1998
|
-
var
|
|
1959
|
+
var DEFAULT_API32 = "https://be.graph8.com";
|
|
1999
1960
|
var G8 = class {
|
|
2000
1961
|
constructor() {
|
|
2001
1962
|
/** @internal */
|
|
@@ -2019,16 +1980,10 @@ var G8 = class {
|
|
|
2019
1980
|
/** @internal */
|
|
2020
1981
|
this._campaigns = null;
|
|
2021
1982
|
/** @internal */
|
|
2022
|
-
this._integrations = null;
|
|
2023
|
-
/** @internal */
|
|
2024
1983
|
this._signals = null;
|
|
2025
1984
|
/** @internal */
|
|
2026
|
-
this._analytics = null;
|
|
2027
|
-
/** @internal */
|
|
2028
1985
|
this._voice = null;
|
|
2029
1986
|
/** @internal */
|
|
2030
|
-
this._pages = null;
|
|
2031
|
-
/** @internal */
|
|
2032
1987
|
this._webhooks = null;
|
|
2033
1988
|
/** @internal */
|
|
2034
1989
|
this._contacts = null;
|
|
@@ -2084,7 +2039,7 @@ var G8 = class {
|
|
|
2084
2039
|
debug: config.debug
|
|
2085
2040
|
});
|
|
2086
2041
|
}
|
|
2087
|
-
const apiUrl = config.apiUrl ||
|
|
2042
|
+
const apiUrl = config.apiUrl || DEFAULT_API32;
|
|
2088
2043
|
const writeKey = config.writeKey || "";
|
|
2089
2044
|
const apiKey = config.apiKey || "";
|
|
2090
2045
|
if (writeKey) {
|
|
@@ -2099,10 +2054,7 @@ var G8 = class {
|
|
|
2099
2054
|
this._enrich = createEnrichClient(apiKey, apiUrl);
|
|
2100
2055
|
this._sequences = createSequencesClient(apiKey, apiUrl);
|
|
2101
2056
|
this._campaigns = createCampaignsClient(apiKey, apiUrl);
|
|
2102
|
-
this._integrations = createIntegrationsClient(apiKey, apiUrl);
|
|
2103
|
-
this._analytics = createAnalyticsClient(apiKey, apiUrl);
|
|
2104
2057
|
this._voice = createVoiceClient(apiKey, apiUrl);
|
|
2105
|
-
this._pages = createPagesClient(apiKey, apiUrl);
|
|
2106
2058
|
this._webhooks = createWebhooksClient(apiKey, apiUrl);
|
|
2107
2059
|
this._contacts = createContactsClient(apiKey, apiUrl);
|
|
2108
2060
|
this._companies = createCompaniesClient(apiKey, apiUrl);
|
|
@@ -2185,31 +2137,16 @@ var G8 = class {
|
|
|
2185
2137
|
this._assertKey("campaigns");
|
|
2186
2138
|
return this._campaigns;
|
|
2187
2139
|
}
|
|
2188
|
-
/** CRM integrations (requires API key). */
|
|
2189
|
-
get integrations() {
|
|
2190
|
-
this._assertKey("integrations");
|
|
2191
|
-
return this._integrations;
|
|
2192
|
-
}
|
|
2193
2140
|
/** Intent signals. */
|
|
2194
2141
|
get signals() {
|
|
2195
2142
|
this._assertInit();
|
|
2196
2143
|
return this._signals;
|
|
2197
2144
|
}
|
|
2198
|
-
/** Analytics (requires API key). */
|
|
2199
|
-
get analytics() {
|
|
2200
|
-
this._assertKey("analytics");
|
|
2201
|
-
return this._analytics;
|
|
2202
|
-
}
|
|
2203
2145
|
/** Voice AI (requires API key). */
|
|
2204
2146
|
get voice() {
|
|
2205
2147
|
this._assertKey("voice");
|
|
2206
2148
|
return this._voice;
|
|
2207
2149
|
}
|
|
2208
|
-
/** Landing pages (requires API key). */
|
|
2209
|
-
get pages() {
|
|
2210
|
-
this._assertKey("pages");
|
|
2211
|
-
return this._pages;
|
|
2212
|
-
}
|
|
2213
2150
|
/** Webhook event listeners (requires API key). */
|
|
2214
2151
|
get webhooks() {
|
|
2215
2152
|
this._assertKey("webhooks");
|
|
@@ -2330,12 +2267,181 @@ var G8 = class {
|
|
|
2330
2267
|
}
|
|
2331
2268
|
};
|
|
2332
2269
|
var g8 = new G8();
|
|
2270
|
+
|
|
2271
|
+
// src/appTokens.ts
|
|
2272
|
+
var DEFAULT_APP_API = "https://be.graph8.com";
|
|
2273
|
+
function createTokenManager(args) {
|
|
2274
|
+
const now = args.now ?? (() => Date.now());
|
|
2275
|
+
const skewMs = args.refreshSkewMs ?? 6e4;
|
|
2276
|
+
let token = null;
|
|
2277
|
+
let expiresAtMs = 0;
|
|
2278
|
+
let inflight = null;
|
|
2279
|
+
const doRefresh = async () => {
|
|
2280
|
+
const resp = await args.refresh();
|
|
2281
|
+
token = resp.access_token;
|
|
2282
|
+
expiresAtMs = now() + Math.max(0, resp.expires_in) * 1e3;
|
|
2283
|
+
return token;
|
|
2284
|
+
};
|
|
2285
|
+
return {
|
|
2286
|
+
async getToken(force = false) {
|
|
2287
|
+
const stillFresh = !force && token !== null && now() < expiresAtMs - skewMs;
|
|
2288
|
+
if (stillFresh) return token;
|
|
2289
|
+
if (!inflight) {
|
|
2290
|
+
inflight = doRefresh().finally(() => {
|
|
2291
|
+
inflight = null;
|
|
2292
|
+
});
|
|
2293
|
+
}
|
|
2294
|
+
return inflight;
|
|
2295
|
+
},
|
|
2296
|
+
expiresAt() {
|
|
2297
|
+
return expiresAtMs;
|
|
2298
|
+
}
|
|
2299
|
+
};
|
|
2300
|
+
}
|
|
2301
|
+
function createAppRequester(args) {
|
|
2302
|
+
const { baseUrl, tokens, extraHeaders, fetchImpl, sleepImpl } = args;
|
|
2303
|
+
const appRequest = async (path, opts = {}) => {
|
|
2304
|
+
const headers = { ...extraHeaders ?? {}, ...opts.headers ?? {} };
|
|
2305
|
+
const reqOpts = { ...opts, headers, fetchImpl, sleepImpl };
|
|
2306
|
+
const token = await tokens.getToken();
|
|
2307
|
+
try {
|
|
2308
|
+
return await request(baseUrl, path, token, reqOpts);
|
|
2309
|
+
} catch (err) {
|
|
2310
|
+
if (err instanceof G8Error && err.status === 401) {
|
|
2311
|
+
const fresh = await tokens.getToken(true);
|
|
2312
|
+
return await request(baseUrl, path, fresh, reqOpts);
|
|
2313
|
+
}
|
|
2314
|
+
throw err;
|
|
2315
|
+
}
|
|
2316
|
+
};
|
|
2317
|
+
return appRequest;
|
|
2318
|
+
}
|
|
2319
|
+
async function exchangeBrowserToken(args) {
|
|
2320
|
+
const propelToken = await Promise.resolve(args.getPropelAuthToken());
|
|
2321
|
+
if (!propelToken) {
|
|
2322
|
+
throw new G8Error({
|
|
2323
|
+
message: "getPropelAuthToken() returned no token \u2014 cannot exchange a browser app session",
|
|
2324
|
+
status: 401,
|
|
2325
|
+
type: "app_token_invalid",
|
|
2326
|
+
code: "app_token_invalid"
|
|
2327
|
+
});
|
|
2328
|
+
}
|
|
2329
|
+
const resp = await request(
|
|
2330
|
+
args.baseUrl,
|
|
2331
|
+
"/api/v1/app-sessions/exchange",
|
|
2332
|
+
propelToken,
|
|
2333
|
+
{
|
|
2334
|
+
method: "POST",
|
|
2335
|
+
body: { app_id: args.appId, scopes: args.scopes ?? [] },
|
|
2336
|
+
fetchImpl: args.fetchImpl,
|
|
2337
|
+
sleepImpl: args.sleepImpl
|
|
2338
|
+
}
|
|
2339
|
+
);
|
|
2340
|
+
return resp.data ?? resp;
|
|
2341
|
+
}
|
|
2342
|
+
async function exchangeServiceToken(args) {
|
|
2343
|
+
const resp = await request(
|
|
2344
|
+
args.baseUrl,
|
|
2345
|
+
"/api/v1/service-token",
|
|
2346
|
+
"",
|
|
2347
|
+
{
|
|
2348
|
+
method: "POST",
|
|
2349
|
+
body: {
|
|
2350
|
+
client_id: args.clientId,
|
|
2351
|
+
client_secret: args.clientSecret,
|
|
2352
|
+
scopes: args.scopes ?? [],
|
|
2353
|
+
ttl_seconds: args.ttlSeconds ?? null
|
|
2354
|
+
},
|
|
2355
|
+
fetchImpl: args.fetchImpl,
|
|
2356
|
+
sleepImpl: args.sleepImpl
|
|
2357
|
+
}
|
|
2358
|
+
);
|
|
2359
|
+
return resp.data ?? resp;
|
|
2360
|
+
}
|
|
2361
|
+
|
|
2362
|
+
// src/appClient.ts
|
|
2363
|
+
function createGraph8AppClient(config) {
|
|
2364
|
+
if (typeof config?.getPropelAuthToken !== "function") {
|
|
2365
|
+
throw new Error(
|
|
2366
|
+
"createGraph8AppClient requires getPropelAuthToken() \u2014 a function returning the caller's PropelAuth token"
|
|
2367
|
+
);
|
|
2368
|
+
}
|
|
2369
|
+
const asRecord = config;
|
|
2370
|
+
if ("apiKey" in asRecord || "writeKey" in asRecord) {
|
|
2371
|
+
throw new Error(
|
|
2372
|
+
"createGraph8AppClient does not accept an org API key or write key in the browser \u2014 pass getPropelAuthToken() instead"
|
|
2373
|
+
);
|
|
2374
|
+
}
|
|
2375
|
+
const baseUrl = config.apiUrl || DEFAULT_APP_API;
|
|
2376
|
+
const tokens = createTokenManager({
|
|
2377
|
+
now: config.now,
|
|
2378
|
+
refreshSkewMs: config.refreshSkewMs,
|
|
2379
|
+
refresh: () => exchangeBrowserToken({
|
|
2380
|
+
baseUrl,
|
|
2381
|
+
appId: config.appId,
|
|
2382
|
+
scopes: config.scopes,
|
|
2383
|
+
getPropelAuthToken: config.getPropelAuthToken,
|
|
2384
|
+
fetchImpl: config.fetchImpl,
|
|
2385
|
+
sleepImpl: config.sleepImpl
|
|
2386
|
+
})
|
|
2387
|
+
});
|
|
2388
|
+
const req = createAppRequester({ baseUrl, tokens, fetchImpl: config.fetchImpl, sleepImpl: config.sleepImpl });
|
|
2389
|
+
return {
|
|
2390
|
+
appId: config.appId,
|
|
2391
|
+
tenantOrgId: config.tenantOrgId,
|
|
2392
|
+
request: req,
|
|
2393
|
+
getAppToken: (force = false) => tokens.getToken(force)
|
|
2394
|
+
};
|
|
2395
|
+
}
|
|
2396
|
+
function createGraph8ServiceClient(config) {
|
|
2397
|
+
if (!config?.clientId || !config?.clientSecret) {
|
|
2398
|
+
throw new Error("createGraph8ServiceClient requires clientId and clientSecret");
|
|
2399
|
+
}
|
|
2400
|
+
if (!config?.tenantOrgId) {
|
|
2401
|
+
throw new Error(
|
|
2402
|
+
"createGraph8ServiceClient requires tenantOrgId \u2014 the single consented client org this backend acts for"
|
|
2403
|
+
);
|
|
2404
|
+
}
|
|
2405
|
+
const baseUrl = config.apiUrl || DEFAULT_APP_API;
|
|
2406
|
+
const tokens = createTokenManager({
|
|
2407
|
+
now: config.now,
|
|
2408
|
+
refreshSkewMs: config.refreshSkewMs,
|
|
2409
|
+
refresh: () => exchangeServiceToken({
|
|
2410
|
+
baseUrl,
|
|
2411
|
+
clientId: config.clientId,
|
|
2412
|
+
clientSecret: config.clientSecret,
|
|
2413
|
+
scopes: config.scopes,
|
|
2414
|
+
ttlSeconds: config.ttlSeconds,
|
|
2415
|
+
fetchImpl: config.fetchImpl,
|
|
2416
|
+
sleepImpl: config.sleepImpl
|
|
2417
|
+
})
|
|
2418
|
+
});
|
|
2419
|
+
const req = createAppRequester({
|
|
2420
|
+
baseUrl,
|
|
2421
|
+
tokens,
|
|
2422
|
+
extraHeaders: { "X-Target-Org-Id": config.tenantOrgId },
|
|
2423
|
+
fetchImpl: config.fetchImpl,
|
|
2424
|
+
sleepImpl: config.sleepImpl
|
|
2425
|
+
});
|
|
2426
|
+
return {
|
|
2427
|
+
tenantOrgId: config.tenantOrgId,
|
|
2428
|
+
request: req,
|
|
2429
|
+
getServiceToken: (force = false) => tokens.getToken(force)
|
|
2430
|
+
};
|
|
2431
|
+
}
|
|
2333
2432
|
export {
|
|
2433
|
+
DEFAULT_APP_API,
|
|
2334
2434
|
G8Error,
|
|
2335
2435
|
KNOWN_WEBHOOK_EVENTS,
|
|
2336
2436
|
WebhookSignatureError,
|
|
2337
2437
|
backoffDelayMs,
|
|
2338
2438
|
constructEvent,
|
|
2439
|
+
createAppRequester,
|
|
2440
|
+
createGraph8AppClient,
|
|
2441
|
+
createGraph8ServiceClient,
|
|
2442
|
+
createTokenManager,
|
|
2443
|
+
exchangeBrowserToken,
|
|
2444
|
+
exchangeServiceToken,
|
|
2339
2445
|
g8,
|
|
2340
2446
|
isRetryableStatus,
|
|
2341
2447
|
paginate,
|