@graph8/sdk 0.11.0 → 0.12.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 +51 -0
- package/dist/index.d.mts +304 -17
- package/dist/index.d.ts +304 -17
- package/dist/index.js +188 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +181 -6
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +77 -15
- package/dist/react.d.ts +77 -15
- package/dist/react.js +12 -6
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +12 -6
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -578,6 +578,29 @@ interface IntentCompany {
|
|
|
578
578
|
visit_count: number;
|
|
579
579
|
last_seen: string | null;
|
|
580
580
|
}
|
|
581
|
+
/** One company row from `intent.urlCompanies()`. Richer than {@link IntentCompany},
|
|
582
|
+
* which describes the keyword-companies surface. */
|
|
583
|
+
interface IntentUrlCompany {
|
|
584
|
+
company_id: number | null;
|
|
585
|
+
name: string | null;
|
|
586
|
+
domain: string | null;
|
|
587
|
+
industry: string | null;
|
|
588
|
+
employee_count: number | null;
|
|
589
|
+
logo_url: string | null;
|
|
590
|
+
audience: string;
|
|
591
|
+
visit_count: number;
|
|
592
|
+
contacts_seen: number;
|
|
593
|
+
last_seen: string | null;
|
|
594
|
+
}
|
|
595
|
+
/** Response of `intent.urlCompanies()`. This endpoint returns a bare aggregate,
|
|
596
|
+
* not the `{ data }` envelope the rest of the Developer API uses. */
|
|
597
|
+
interface IntentUrlCompaniesResponse {
|
|
598
|
+
url: string;
|
|
599
|
+
total_companies: number;
|
|
600
|
+
b2b_count: number;
|
|
601
|
+
b2c_count: number;
|
|
602
|
+
companies: IntentUrlCompany[];
|
|
603
|
+
}
|
|
581
604
|
interface IntentContact {
|
|
582
605
|
contact_id: number | null;
|
|
583
606
|
email: string | null;
|
|
@@ -612,7 +635,7 @@ interface IntentStats {
|
|
|
612
635
|
* POST /api/v1/intent/pages/visitors
|
|
613
636
|
* POST /api/v1/intent/pages/contacts
|
|
614
637
|
* POST /api/v1/intent/pages/visitor-counts
|
|
615
|
-
* POST /intent
|
|
638
|
+
* POST /api/v1/intent/url-companies
|
|
616
639
|
*/
|
|
617
640
|
declare const createIntentClient: (apiKey: string, apiUrl?: string) => {
|
|
618
641
|
/** Org-level intent stats (totals over the last 30 days). */
|
|
@@ -695,16 +718,24 @@ declare const createIntentClient: (apiKey: string, apiUrl?: string) => {
|
|
|
695
718
|
/**
|
|
696
719
|
* Find companies whose users visited a specific URL (intent search).
|
|
697
720
|
*
|
|
698
|
-
*
|
|
699
|
-
*
|
|
721
|
+
* Previously posted to the bare-host `/intent-search/url-companies`, bypassing
|
|
722
|
+
* the shared `post()` helper. That route is JWT-only, so this method could
|
|
723
|
+
* never actually work with an API key. It now goes through
|
|
724
|
+
* `/api/v1/intent/url-companies` like the rest of the intent surface (g8 issue
|
|
725
|
+
* #16536).
|
|
726
|
+
*
|
|
727
|
+
* Returns a bare aggregate, NOT the `{ data }` envelope — the previous
|
|
728
|
+
* `{ data: IntentCompany[] }` signature never matched what the API sends.
|
|
729
|
+
*
|
|
730
|
+
* `date_from` / `date_to` are accepted for backwards compatibility but have
|
|
731
|
+
* never been read by this endpoint; use `days` to set the lookback window.
|
|
700
732
|
*/
|
|
701
733
|
urlCompanies(url: string, params?: {
|
|
702
734
|
limit?: number;
|
|
735
|
+
days?: number;
|
|
703
736
|
date_from?: string;
|
|
704
737
|
date_to?: string;
|
|
705
|
-
}): Promise<
|
|
706
|
-
data: IntentCompany[];
|
|
707
|
-
}>;
|
|
738
|
+
}): Promise<IntentUrlCompaniesResponse>;
|
|
708
739
|
};
|
|
709
740
|
|
|
710
741
|
type SkillType = "llm" | "api";
|
|
@@ -1553,14 +1584,28 @@ interface DealCreateParams {
|
|
|
1553
1584
|
*/
|
|
1554
1585
|
company_id?: number;
|
|
1555
1586
|
description?: string;
|
|
1587
|
+
/**
|
|
1588
|
+
* Monetary value. Required (HTTP 400, marker `amount_required_for_won_stage`)
|
|
1589
|
+
* when creating directly in a Closed Won stage; 0 is a valid amount.
|
|
1590
|
+
*/
|
|
1556
1591
|
amount?: number;
|
|
1557
1592
|
/** Default: "USD". */
|
|
1558
1593
|
currency?: string;
|
|
1559
|
-
/**
|
|
1594
|
+
/**
|
|
1595
|
+
* Stage ID from the org's pipelines. Must exist and belong to `pipeline_id`
|
|
1596
|
+
* when both are sent (HTTP 422 otherwise). Defaults to the default
|
|
1597
|
+
* pipeline's first non-closed stage if omitted. Creating directly in a
|
|
1598
|
+
* closed stage triggers the closed-stage rules (HTTP 400 with marker
|
|
1599
|
+
* `close_date_required_for_won_stage` / `close_date_required_for_lost_stage`
|
|
1600
|
+
* / `amount_required_for_won_stage` / `owner_required_for_closed_stage`).
|
|
1601
|
+
*/
|
|
1560
1602
|
stage_id?: string;
|
|
1561
|
-
/** Pipeline ID. Defaults to org's default pipeline if omitted. */
|
|
1603
|
+
/** Pipeline ID. Must exist (HTTP 422 otherwise). Defaults to org's default pipeline if omitted. */
|
|
1562
1604
|
pipeline_id?: string;
|
|
1563
|
-
/**
|
|
1605
|
+
/**
|
|
1606
|
+
* ISO 8601 close date. Required when creating directly in a Closed Won or
|
|
1607
|
+
* Closed Lost stage; past dates are allowed (backdating is supported).
|
|
1608
|
+
*/
|
|
1564
1609
|
close_date?: string;
|
|
1565
1610
|
/**
|
|
1566
1611
|
* Set true to create a deal even if one already exists for the company.
|
|
@@ -1573,10 +1618,28 @@ interface DealUpdateParams {
|
|
|
1573
1618
|
description?: string;
|
|
1574
1619
|
amount?: number;
|
|
1575
1620
|
currency?: string;
|
|
1621
|
+
/**
|
|
1622
|
+
* New stage ID. Must be an existing stage in the deal's pipeline (HTTP 422
|
|
1623
|
+
* otherwise). Moving a deal INTO a Closed Won stage requires an effective
|
|
1624
|
+
* close_date AND amount; Closed Lost requires an effective close_date;
|
|
1625
|
+
* either requires an owner ("effective" = the value in this call, else the
|
|
1626
|
+
* deal's existing value). Violations return HTTP 400 with a marker-prefixed
|
|
1627
|
+
* detail: `close_date_required_for_won_stage`,
|
|
1628
|
+
* `close_date_required_for_lost_stage`, `amount_required_for_won_stage`,
|
|
1629
|
+
* `owner_required_for_closed_stage`. Re-submitting the deal's current stage
|
|
1630
|
+
* is never gated.
|
|
1631
|
+
*/
|
|
1576
1632
|
stage_id?: string;
|
|
1577
|
-
/**
|
|
1578
|
-
|
|
1579
|
-
|
|
1633
|
+
/**
|
|
1634
|
+
* ISO 8601 close date. Explicit null clears it, except on a deal sitting in
|
|
1635
|
+
* a closed stage (HTTP 400, closed-stage markers above).
|
|
1636
|
+
*/
|
|
1637
|
+
close_date?: string | null;
|
|
1638
|
+
/**
|
|
1639
|
+
* Reassign the deal owner (user id or email). Pass null to clear, except on
|
|
1640
|
+
* a deal sitting in a closed stage (HTTP 400, marker
|
|
1641
|
+
* `owner_required_for_closed_stage`).
|
|
1642
|
+
*/
|
|
1580
1643
|
owner_id?: string | null;
|
|
1581
1644
|
/**
|
|
1582
1645
|
* mashup_contact_ids to link. Must belong to the deal's company (if the deal
|
|
@@ -3717,7 +3780,7 @@ declare class G8 {
|
|
|
3717
3780
|
data: IntentCompany[];
|
|
3718
3781
|
}>;
|
|
3719
3782
|
keywordContacts(keywordId: string, params?: {
|
|
3720
|
-
limit
|
|
3783
|
+
limit?: number;
|
|
3721
3784
|
date_from?: string;
|
|
3722
3785
|
date_to?: string;
|
|
3723
3786
|
}): Promise<{
|
|
@@ -3758,11 +3821,10 @@ declare class G8 {
|
|
|
3758
3821
|
}>;
|
|
3759
3822
|
urlCompanies(url: string, params?: {
|
|
3760
3823
|
limit?: number;
|
|
3824
|
+
days?: number;
|
|
3761
3825
|
date_from?: string;
|
|
3762
3826
|
date_to?: string;
|
|
3763
|
-
}): Promise<
|
|
3764
|
-
data: IntentCompany[];
|
|
3765
|
-
}>;
|
|
3827
|
+
}): Promise<IntentUrlCompaniesResponse>;
|
|
3766
3828
|
};
|
|
3767
3829
|
/** Studio context — ICPs, personas, brand briefs, intelligence, AI research reports (requires API key). */
|
|
3768
3830
|
get studio(): {
|
|
@@ -4016,4 +4078,229 @@ interface PaginatedResponse<T> {
|
|
|
4016
4078
|
*/
|
|
4017
4079
|
declare function paginate<T>(fetchPage: (cursor?: string) => Promise<PaginatedResponse<T>>): AsyncGenerator<T, void, unknown>;
|
|
4018
4080
|
|
|
4019
|
-
|
|
4081
|
+
/**
|
|
4082
|
+
* App-platform token exchange + refresh core (M6-9).
|
|
4083
|
+
*
|
|
4084
|
+
* The hosted-app clients never carry a permanent org API key. Instead they mint
|
|
4085
|
+
* SHORT-LIVED app tokens by EXCHANGING a longer-lived credential, and refresh
|
|
4086
|
+
* them on/near expiry:
|
|
4087
|
+
*
|
|
4088
|
+
* - browser apps exchange the caller's PropelAuth login at
|
|
4089
|
+
* `POST /api/v1/app-sessions/exchange` (identity is derived server-side from
|
|
4090
|
+
* the validated principal — the body only names the target app + scopes);
|
|
4091
|
+
* - hosted backends exchange service client-credentials at
|
|
4092
|
+
* `POST /api/v1/service-token`.
|
|
4093
|
+
*
|
|
4094
|
+
* Both endpoints answer with the reused `ApiResponse` envelope wrapping a
|
|
4095
|
+
* `TokenResponse` (see developer_api/app_platform/app_tokens/dtos.py). This
|
|
4096
|
+
* module owns:
|
|
4097
|
+
*
|
|
4098
|
+
* - `AppTokenResponse` — the minted-token payload shape (frozen wire contract);
|
|
4099
|
+
* - `createTokenManager` — caches a token, refreshes it on/near expiry, and
|
|
4100
|
+
* de-dupes concurrent refreshes into one in-flight exchange;
|
|
4101
|
+
* - `createAppRequester` — binds the managed token onto the hardened
|
|
4102
|
+
* `request()` core (typed `G8Error`, retries, idempotency, pagination),
|
|
4103
|
+
* attaching `Authorization: Bearer <app-token>` (plus any static header such
|
|
4104
|
+
* as a service client's `X-Target-Org-Id`) and refreshing once on a 401.
|
|
4105
|
+
*
|
|
4106
|
+
* The backend app-token API is INERT/unmounted today (behind a deny-by-default
|
|
4107
|
+
* flag), so these paths are exercised against mocked HTTP, never a live server.
|
|
4108
|
+
*/
|
|
4109
|
+
declare const DEFAULT_APP_API = "https://be.graph8.com";
|
|
4110
|
+
/** The minted app token + the non-secret metadata a client reads back.
|
|
4111
|
+
* Mirrors `TokenResponse` in developer_api/app_platform/app_tokens/dtos.py. */
|
|
4112
|
+
interface AppTokenResponse {
|
|
4113
|
+
/** The signed app JWT (attach as `Authorization: Bearer <access_token>`). */
|
|
4114
|
+
access_token: string;
|
|
4115
|
+
/** Always "Bearer". */
|
|
4116
|
+
token_type: string;
|
|
4117
|
+
/** Lifetime in seconds from issuance. */
|
|
4118
|
+
expires_in: number;
|
|
4119
|
+
/** The distinct-per-app, per-environment audience. */
|
|
4120
|
+
audience: string;
|
|
4121
|
+
/** App the token is bound to (dapp_-prefixed). */
|
|
4122
|
+
app_id: string;
|
|
4123
|
+
/** Signing key id (matches a JWKS entry). */
|
|
4124
|
+
kid: string;
|
|
4125
|
+
}
|
|
4126
|
+
/** Per-request options accepted by an {@link AppRequest}. A subset of the
|
|
4127
|
+
* hardened core's `RequestOptions` — auth (the app token) and the injected
|
|
4128
|
+
* fetch/sleep seams are bound by the requester, not passed per call. */
|
|
4129
|
+
interface AppRequestOptions {
|
|
4130
|
+
method?: string;
|
|
4131
|
+
body?: unknown;
|
|
4132
|
+
headers?: Record<string, string>;
|
|
4133
|
+
query?: Record<string, unknown>;
|
|
4134
|
+
/** Sent as `Idempotency-Key` for safe POST/PATCH retries. */
|
|
4135
|
+
idempotencyKey?: string;
|
|
4136
|
+
/** Max retry attempts on 429/5xx/network (default 2). */
|
|
4137
|
+
maxRetries?: number;
|
|
4138
|
+
/** Base backoff in ms (default 200). */
|
|
4139
|
+
retryBaseMs?: number;
|
|
4140
|
+
signal?: AbortSignal;
|
|
4141
|
+
}
|
|
4142
|
+
/** A token-bound request function: same ergonomics as the raw `request()` core
|
|
4143
|
+
* minus the credential, which the token manager supplies. */
|
|
4144
|
+
type AppRequest = <T = unknown>(path: string, opts?: AppRequestOptions) => Promise<T>;
|
|
4145
|
+
/** Caches + refreshes one app token. */
|
|
4146
|
+
interface TokenManager {
|
|
4147
|
+
/** Return a valid token, refreshing on/near expiry. `force` refreshes now. */
|
|
4148
|
+
getToken(force?: boolean): Promise<string>;
|
|
4149
|
+
/** Current token expiry as an epoch-ms timestamp (0 before the first mint). */
|
|
4150
|
+
expiresAt(): number;
|
|
4151
|
+
}
|
|
4152
|
+
/**
|
|
4153
|
+
* Build a token manager over a `refresh` exchange.
|
|
4154
|
+
*
|
|
4155
|
+
* Freshness rule: a cached token is reused until it is within `refreshSkewMs`
|
|
4156
|
+
* of expiry, then a refresh is triggered. Concurrent callers during a refresh
|
|
4157
|
+
* share ONE in-flight exchange (no stampede). `now` is injectable for tests.
|
|
4158
|
+
*/
|
|
4159
|
+
declare function createTokenManager(args: {
|
|
4160
|
+
refresh: () => Promise<AppTokenResponse>;
|
|
4161
|
+
now?: () => number;
|
|
4162
|
+
refreshSkewMs?: number;
|
|
4163
|
+
}): TokenManager;
|
|
4164
|
+
/**
|
|
4165
|
+
* Bind a {@link TokenManager} onto the hardened `request()` core.
|
|
4166
|
+
*
|
|
4167
|
+
* Every call fetches the current token, attaches `Authorization: Bearer …`
|
|
4168
|
+
* (plus any `extraHeaders`, e.g. a service client's `X-Target-Org-Id`), and
|
|
4169
|
+
* reuses all of the core's typed errors / retries / idempotency. On a 401 —
|
|
4170
|
+
* a token revoked or gone stale mid-window — it force-refreshes ONCE and retries.
|
|
4171
|
+
*/
|
|
4172
|
+
declare function createAppRequester(args: {
|
|
4173
|
+
baseUrl: string;
|
|
4174
|
+
tokens: TokenManager;
|
|
4175
|
+
extraHeaders?: Record<string, string>;
|
|
4176
|
+
fetchImpl?: typeof fetch;
|
|
4177
|
+
sleepImpl?: (ms: number) => Promise<void>;
|
|
4178
|
+
}): AppRequest;
|
|
4179
|
+
/**
|
|
4180
|
+
* Exchange the caller's PropelAuth token for a short-lived BROWSER app token.
|
|
4181
|
+
* `POST /api/v1/app-sessions/exchange` (body = target app + scopes only;
|
|
4182
|
+
* identity/role/tenant are derived server-side from the validated principal).
|
|
4183
|
+
*/
|
|
4184
|
+
declare function exchangeBrowserToken(args: {
|
|
4185
|
+
baseUrl: string;
|
|
4186
|
+
appId: string;
|
|
4187
|
+
scopes?: string[];
|
|
4188
|
+
getPropelAuthToken: () => string | Promise<string>;
|
|
4189
|
+
fetchImpl?: typeof fetch;
|
|
4190
|
+
sleepImpl?: (ms: number) => Promise<void>;
|
|
4191
|
+
}): Promise<AppTokenResponse>;
|
|
4192
|
+
/**
|
|
4193
|
+
* Exchange service client-credentials for a SERVICE app token.
|
|
4194
|
+
* `POST /api/v1/service-token` — credentials travel in the body; this endpoint
|
|
4195
|
+
* has no bearer auth, so no `Authorization` is sent on the exchange itself.
|
|
4196
|
+
*/
|
|
4197
|
+
declare function exchangeServiceToken(args: {
|
|
4198
|
+
baseUrl: string;
|
|
4199
|
+
clientId: string;
|
|
4200
|
+
clientSecret: string;
|
|
4201
|
+
scopes?: string[];
|
|
4202
|
+
ttlSeconds?: number;
|
|
4203
|
+
fetchImpl?: typeof fetch;
|
|
4204
|
+
sleepImpl?: (ms: number) => Promise<void>;
|
|
4205
|
+
}): Promise<AppTokenResponse>;
|
|
4206
|
+
|
|
4207
|
+
/**
|
|
4208
|
+
* Hosted app-platform clients (M6-9).
|
|
4209
|
+
*
|
|
4210
|
+
* Two entry points, both additive to `@graph8/sdk` and independent of the
|
|
4211
|
+
* `g8` tracking/API-key singleton:
|
|
4212
|
+
*
|
|
4213
|
+
* - `createGraph8AppClient` — BROWSER client. Exchanges the caller's
|
|
4214
|
+
* PropelAuth token for a short-lived app token, refreshes it on/near expiry,
|
|
4215
|
+
* and attaches `Authorization: Bearer <app-token>` to every call. It NEVER
|
|
4216
|
+
* accepts a permanent org API key for browser init (the whole reason the
|
|
4217
|
+
* token-exchange exists).
|
|
4218
|
+
* - `createGraph8ServiceClient` — BACKEND client. Exchanges service
|
|
4219
|
+
* client-credentials for a service app token and sends `X-Target-Org-Id`
|
|
4220
|
+
* for the single configured tenant on every call.
|
|
4221
|
+
*
|
|
4222
|
+
* Both expose a token-bound `request()` — the hardened `request()` core with the
|
|
4223
|
+
* minted app token attached — so callers reach Developer API routes with the
|
|
4224
|
+
* app token and reuse the core's typed `G8Error`, retries, idempotency, and
|
|
4225
|
+
* cursor pagination. The typed `apps` (control-plane) and `objects`
|
|
4226
|
+
* (custom-object CRUD) resource modules are DEFERRED until their backend routes
|
|
4227
|
+
* ship and freeze (M6-3 / M6-5); only the auth clients ship here.
|
|
4228
|
+
*/
|
|
4229
|
+
|
|
4230
|
+
/** Config for {@link createGraph8AppClient} (browser). No API key is accepted. */
|
|
4231
|
+
interface Graph8AppClientConfig {
|
|
4232
|
+
/** Target app id (dapp_-prefixed). */
|
|
4233
|
+
appId: string;
|
|
4234
|
+
/** The client org this browser session acts in (informational; the server
|
|
4235
|
+
* derives the authoritative tenant from the validated PropelAuth principal). */
|
|
4236
|
+
tenantOrgId: string;
|
|
4237
|
+
/** Returns the caller's current PropelAuth token (sync or async). */
|
|
4238
|
+
getPropelAuthToken: () => string | Promise<string>;
|
|
4239
|
+
/** Scopes to embed in the minted app token. */
|
|
4240
|
+
scopes?: string[];
|
|
4241
|
+
/** Backend API URL (default https://be.graph8.com). */
|
|
4242
|
+
apiUrl?: string;
|
|
4243
|
+
/** Refresh this many ms before expiry (default 60_000). */
|
|
4244
|
+
refreshSkewMs?: number;
|
|
4245
|
+
/** Injected for tests; defaults to global fetch. */
|
|
4246
|
+
fetchImpl?: typeof fetch;
|
|
4247
|
+
/** Injected for tests; defaults to a real setTimeout sleep. */
|
|
4248
|
+
sleepImpl?: (ms: number) => Promise<void>;
|
|
4249
|
+
/** Injected for tests; defaults to Date.now. */
|
|
4250
|
+
now?: () => number;
|
|
4251
|
+
}
|
|
4252
|
+
/** A browser app-platform client. */
|
|
4253
|
+
interface Graph8AppClient {
|
|
4254
|
+
readonly appId: string;
|
|
4255
|
+
readonly tenantOrgId: string;
|
|
4256
|
+
/** Token-bound requester: mints/refreshes the app token and attaches
|
|
4257
|
+
* `Authorization: Bearer <app-token>` to every Developer API call. */
|
|
4258
|
+
readonly request: AppRequest;
|
|
4259
|
+
/** Return the current app token, refreshing on/near expiry (`force` refreshes now). */
|
|
4260
|
+
getAppToken(force?: boolean): Promise<string>;
|
|
4261
|
+
}
|
|
4262
|
+
/**
|
|
4263
|
+
* Create a BROWSER app-platform client backed by PropelAuth->app-token exchange.
|
|
4264
|
+
* Refuses an org API key / write key — those must never reach a browser.
|
|
4265
|
+
*/
|
|
4266
|
+
declare function createGraph8AppClient(config: Graph8AppClientConfig): Graph8AppClient;
|
|
4267
|
+
/** Config for {@link createGraph8ServiceClient} (backend / server-to-server). */
|
|
4268
|
+
interface Graph8ServiceClientConfig {
|
|
4269
|
+
/** Service credential client id. */
|
|
4270
|
+
clientId: string;
|
|
4271
|
+
/** Service credential client secret (checked against the stored hash). */
|
|
4272
|
+
clientSecret: string;
|
|
4273
|
+
/** The single consented client org this backend acts for (sent as X-Target-Org-Id). */
|
|
4274
|
+
tenantOrgId: string;
|
|
4275
|
+
/** Scopes to embed in the minted service token. */
|
|
4276
|
+
scopes?: string[];
|
|
4277
|
+
/** Requested token TTL; the server clamps it into its service band. */
|
|
4278
|
+
ttlSeconds?: number;
|
|
4279
|
+
/** Backend API URL (default https://be.graph8.com). */
|
|
4280
|
+
apiUrl?: string;
|
|
4281
|
+
/** Refresh this many ms before expiry (default 60_000). */
|
|
4282
|
+
refreshSkewMs?: number;
|
|
4283
|
+
/** Injected for tests; defaults to global fetch. */
|
|
4284
|
+
fetchImpl?: typeof fetch;
|
|
4285
|
+
/** Injected for tests; defaults to a real setTimeout sleep. */
|
|
4286
|
+
sleepImpl?: (ms: number) => Promise<void>;
|
|
4287
|
+
/** Injected for tests; defaults to Date.now. */
|
|
4288
|
+
now?: () => number;
|
|
4289
|
+
}
|
|
4290
|
+
/** A backend service app-platform client. */
|
|
4291
|
+
interface Graph8ServiceClient {
|
|
4292
|
+
readonly tenantOrgId: string;
|
|
4293
|
+
/** Token-bound requester: mints/refreshes the service token, attaches it, and
|
|
4294
|
+
* sends `X-Target-Org-Id` for the one consented tenant on every call. */
|
|
4295
|
+
readonly request: AppRequest;
|
|
4296
|
+
/** Return the current service token, refreshing on/near expiry (`force` refreshes now). */
|
|
4297
|
+
getServiceToken(force?: boolean): Promise<string>;
|
|
4298
|
+
}
|
|
4299
|
+
/**
|
|
4300
|
+
* Create a BACKEND service client backed by client-credentials->service-token
|
|
4301
|
+
* exchange. Every request carries `X-Target-Org-Id: <tenantOrgId>` for the one
|
|
4302
|
+
* configured consented tenant.
|
|
4303
|
+
*/
|
|
4304
|
+
declare function createGraph8ServiceClient(config: Graph8ServiceClientConfig): Graph8ServiceClient;
|
|
4305
|
+
|
|
4306
|
+
export { type AddToSequenceConfig, type AgencyClient, type AgencyInfo, type AppRequest, type AppRequestOptions, type AppTokenResponse, type AudienceSync, type AudienceSyncCreateParams, type AudienceSyncError, type AudienceSyncMode, type AudienceSyncPlatform, type AudienceSyncRun, type AudienceSyncUpdateParams, type Booking, type BookingRequest, type CalendarConfig, type CallGradingResult, type Campaign, type CampaignCreateConfig, type CampaignLaunchExecution, type CampaignLaunchResult, type ChatConfig, type Company, type CompanyColumn, type CompanyColumnCreateParams, type CompanyContact, type CompanyEnrichment, type CompanyListParams, type CompanyUpdateParams, type ConstructEventOptions, type Contact, type ContactColumn, type ContactColumnCreateParams, type ContactCreateParams, type ContactDeal, type ContactList, type ContactListParams, type ContactUpdateParams, type CopilotConfig, type CreatedField, DEFAULT_APP_API, type Deal, type DealCreateParams, type DealListParams, type DealUpdateParams, type DialerAgentSummary, type DialerAgentsListParams, type DialerAgentsListResult, type DialerNumberInfo, type DialerNumbersListResult, type DialerReportFilters, type DialerReportMetric, type DialerSessionCreateParams, type DialerSessionCreateResult, type DialerSessionResumeResult, type DialerSessionStatus, type DialerSessionStatusUpdateResult, type DialerSessionSummary, type DialerSessionsListParams, type DialerSessionsListResult, type DialerStatsParams, type DialerStatsResult, type EmailVerification, type EnrichLookupResult, type EvidenceKey, type Field, type FieldCreateParams, type FieldDeleteParams, type G8Config, G8Error, type G8PrivacyConfig, type GlobalContextDocument, type Graph8AppClient, type Graph8AppClientConfig, type Graph8ServiceClient, type Graph8ServiceClientConfig, type ICP, type IdentifyProperties, type InboxAssignResult, type InboxAssignee, type InboxChannel, type InboxContact, type InboxDraft, type InboxListParams, type InboxMessage, type InboxSendParams, type InboxSendResult, type InboxTag, type InboxTagResult, type InboxThread, type IntelligenceData, type IntentCompany, type IntentContact, type IntentKeyword, type IntentPage, type IntentSignals, type IntentStats, type IntentVisitor, KNOWN_WEBHOOK_EVENTS, type ListContact, type MarketplaceHiring, type MarketplaceOffer, type MarketplaceProfile, type MeetingAnalysis, type MeetingAttendee, type MeetingDetail, type MeetingListParams, type MeetingSummary, type MeetingTranscriptLine, type MissedCallback, type MissedCallbacksResult, type NodeTypeSchema, type Note, type PaginatedResponse, type PaginationMeta$1 as PaginationMeta, type PersonEnrichment, type Persona, type Pipeline, type PipelineStage, type PipelineSuggestion, type QuotableProduct, type QuoteCreateParams, type QuoteDetail, type QuoteLineItem, type QuoteListParams, type QuoteSendParams, type QuoteSettings, type QuoteStatus, type QuoteSummary, type QuoteUpdateParams, type RequestOptions, type ResearchReport, type SearchCompanyItem, type SearchCondition, type SearchContactItem, type SearchFilter, type SearchOperator, type SearchParams, type SearchResults, type SearchSaveParams, type SearchSaveResult, type Sequence, type SequenceActionResult, type SequenceAnalytics, type SequenceChannelConfig, type SequenceContactItem, type SequenceContactsParams, type SequenceCreateParams, type SequenceCreateResult, type SequenceDetail, type SequenceKind, type SequenceListItem, type SequenceListParams, type SequencePreview, type SequencePreviewChannel, type SequencePreviewStep, type SequenceStepConfig, type SequenceStepInputType, type SequenceStepType, type SequenceStepUpdateParams, type SequenceUpdateParams, type SetFieldValueParams, type Skill, type SkillCreateAPIParams, type SkillCreateLLMParams, type SkillInputField, type SkillListParams, type SkillTemplate, type SkillType, type SkillUpdateAPIParams, type SkillUpdateLLMParams, type Snippet, type StageCreateParams, type StagePipeline, type StagePipelineCreateParams, type StagePipelineStage, type StagePipelineUpdateParams, type StageUpdateParams, type Task, type TaskCreateParams, type TaskListParams, type TaskUpdateParams, type TimeSlot, type TokenManager, type TrackProperties, type VisitorCompany, type VisitorScore, type VoicePagination, type WebhookEvent, type WebhookEventPayload, WebhookSignatureError, type Workflow, type WorkflowConfig, type WorkflowConnection, type WorkflowCreateParams, type WorkflowExecution, type WorkflowListParams, type WorkflowNode, type WorkflowUpdateParams, backoffDelayMs, constructEvent, createAppRequester, createGraph8AppClient, createGraph8ServiceClient, createTokenManager, exchangeBrowserToken, exchangeServiceToken, g8, isRetryableStatus, paginate, parseRetryAfter, request };
|
package/dist/index.js
CHANGED
|
@@ -20,11 +20,18 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
DEFAULT_APP_API: () => DEFAULT_APP_API,
|
|
23
24
|
G8Error: () => G8Error,
|
|
24
25
|
KNOWN_WEBHOOK_EVENTS: () => KNOWN_WEBHOOK_EVENTS,
|
|
25
26
|
WebhookSignatureError: () => WebhookSignatureError,
|
|
26
27
|
backoffDelayMs: () => backoffDelayMs,
|
|
27
28
|
constructEvent: () => constructEvent,
|
|
29
|
+
createAppRequester: () => createAppRequester,
|
|
30
|
+
createGraph8AppClient: () => createGraph8AppClient,
|
|
31
|
+
createGraph8ServiceClient: () => createGraph8ServiceClient,
|
|
32
|
+
createTokenManager: () => createTokenManager,
|
|
33
|
+
exchangeBrowserToken: () => exchangeBrowserToken,
|
|
34
|
+
exchangeServiceToken: () => exchangeServiceToken,
|
|
28
35
|
g8: () => g8,
|
|
29
36
|
isRetryableStatus: () => isRetryableStatus,
|
|
30
37
|
paginate: () => paginate,
|
|
@@ -1738,14 +1745,20 @@ var createIntentClient = (apiKey, apiUrl) => {
|
|
|
1738
1745
|
/**
|
|
1739
1746
|
* Find companies whose users visited a specific URL (intent search).
|
|
1740
1747
|
*
|
|
1741
|
-
*
|
|
1742
|
-
*
|
|
1748
|
+
* Previously posted to the bare-host `/intent-search/url-companies`, bypassing
|
|
1749
|
+
* the shared `post()` helper. That route is JWT-only, so this method could
|
|
1750
|
+
* never actually work with an API key. It now goes through
|
|
1751
|
+
* `/api/v1/intent/url-companies` like the rest of the intent surface (g8 issue
|
|
1752
|
+
* #16536).
|
|
1753
|
+
*
|
|
1754
|
+
* Returns a bare aggregate, NOT the `{ data }` envelope — the previous
|
|
1755
|
+
* `{ data: IntentCompany[] }` signature never matched what the API sends.
|
|
1756
|
+
*
|
|
1757
|
+
* `date_from` / `date_to` are accepted for backwards compatibility but have
|
|
1758
|
+
* never been read by this endpoint; use `days` to set the lookback window.
|
|
1743
1759
|
*/
|
|
1744
1760
|
async urlCompanies(url, params = {}) {
|
|
1745
|
-
return
|
|
1746
|
-
method: "POST",
|
|
1747
|
-
body: { url, ...params }
|
|
1748
|
-
});
|
|
1761
|
+
return post("/intent/url-companies", { url, ...params });
|
|
1749
1762
|
}
|
|
1750
1763
|
};
|
|
1751
1764
|
};
|
|
@@ -2302,13 +2315,182 @@ var G8 = class {
|
|
|
2302
2315
|
}
|
|
2303
2316
|
};
|
|
2304
2317
|
var g8 = new G8();
|
|
2318
|
+
|
|
2319
|
+
// src/appTokens.ts
|
|
2320
|
+
var DEFAULT_APP_API = "https://be.graph8.com";
|
|
2321
|
+
function createTokenManager(args) {
|
|
2322
|
+
const now = args.now ?? (() => Date.now());
|
|
2323
|
+
const skewMs = args.refreshSkewMs ?? 6e4;
|
|
2324
|
+
let token = null;
|
|
2325
|
+
let expiresAtMs = 0;
|
|
2326
|
+
let inflight = null;
|
|
2327
|
+
const doRefresh = async () => {
|
|
2328
|
+
const resp = await args.refresh();
|
|
2329
|
+
token = resp.access_token;
|
|
2330
|
+
expiresAtMs = now() + Math.max(0, resp.expires_in) * 1e3;
|
|
2331
|
+
return token;
|
|
2332
|
+
};
|
|
2333
|
+
return {
|
|
2334
|
+
async getToken(force = false) {
|
|
2335
|
+
const stillFresh = !force && token !== null && now() < expiresAtMs - skewMs;
|
|
2336
|
+
if (stillFresh) return token;
|
|
2337
|
+
if (!inflight) {
|
|
2338
|
+
inflight = doRefresh().finally(() => {
|
|
2339
|
+
inflight = null;
|
|
2340
|
+
});
|
|
2341
|
+
}
|
|
2342
|
+
return inflight;
|
|
2343
|
+
},
|
|
2344
|
+
expiresAt() {
|
|
2345
|
+
return expiresAtMs;
|
|
2346
|
+
}
|
|
2347
|
+
};
|
|
2348
|
+
}
|
|
2349
|
+
function createAppRequester(args) {
|
|
2350
|
+
const { baseUrl, tokens, extraHeaders, fetchImpl, sleepImpl } = args;
|
|
2351
|
+
const appRequest = async (path, opts = {}) => {
|
|
2352
|
+
const headers = { ...extraHeaders ?? {}, ...opts.headers ?? {} };
|
|
2353
|
+
const reqOpts = { ...opts, headers, fetchImpl, sleepImpl };
|
|
2354
|
+
const token = await tokens.getToken();
|
|
2355
|
+
try {
|
|
2356
|
+
return await request(baseUrl, path, token, reqOpts);
|
|
2357
|
+
} catch (err) {
|
|
2358
|
+
if (err instanceof G8Error && err.status === 401) {
|
|
2359
|
+
const fresh = await tokens.getToken(true);
|
|
2360
|
+
return await request(baseUrl, path, fresh, reqOpts);
|
|
2361
|
+
}
|
|
2362
|
+
throw err;
|
|
2363
|
+
}
|
|
2364
|
+
};
|
|
2365
|
+
return appRequest;
|
|
2366
|
+
}
|
|
2367
|
+
async function exchangeBrowserToken(args) {
|
|
2368
|
+
const propelToken = await Promise.resolve(args.getPropelAuthToken());
|
|
2369
|
+
if (!propelToken) {
|
|
2370
|
+
throw new G8Error({
|
|
2371
|
+
message: "getPropelAuthToken() returned no token \u2014 cannot exchange a browser app session",
|
|
2372
|
+
status: 401,
|
|
2373
|
+
type: "app_token_invalid",
|
|
2374
|
+
code: "app_token_invalid"
|
|
2375
|
+
});
|
|
2376
|
+
}
|
|
2377
|
+
const resp = await request(
|
|
2378
|
+
args.baseUrl,
|
|
2379
|
+
"/api/v1/app-sessions/exchange",
|
|
2380
|
+
propelToken,
|
|
2381
|
+
{
|
|
2382
|
+
method: "POST",
|
|
2383
|
+
body: { app_id: args.appId, scopes: args.scopes ?? [] },
|
|
2384
|
+
fetchImpl: args.fetchImpl,
|
|
2385
|
+
sleepImpl: args.sleepImpl
|
|
2386
|
+
}
|
|
2387
|
+
);
|
|
2388
|
+
return resp.data ?? resp;
|
|
2389
|
+
}
|
|
2390
|
+
async function exchangeServiceToken(args) {
|
|
2391
|
+
const resp = await request(
|
|
2392
|
+
args.baseUrl,
|
|
2393
|
+
"/api/v1/service-token",
|
|
2394
|
+
"",
|
|
2395
|
+
{
|
|
2396
|
+
method: "POST",
|
|
2397
|
+
body: {
|
|
2398
|
+
client_id: args.clientId,
|
|
2399
|
+
client_secret: args.clientSecret,
|
|
2400
|
+
scopes: args.scopes ?? [],
|
|
2401
|
+
ttl_seconds: args.ttlSeconds ?? null
|
|
2402
|
+
},
|
|
2403
|
+
fetchImpl: args.fetchImpl,
|
|
2404
|
+
sleepImpl: args.sleepImpl
|
|
2405
|
+
}
|
|
2406
|
+
);
|
|
2407
|
+
return resp.data ?? resp;
|
|
2408
|
+
}
|
|
2409
|
+
|
|
2410
|
+
// src/appClient.ts
|
|
2411
|
+
function createGraph8AppClient(config) {
|
|
2412
|
+
if (typeof config?.getPropelAuthToken !== "function") {
|
|
2413
|
+
throw new Error(
|
|
2414
|
+
"createGraph8AppClient requires getPropelAuthToken() \u2014 a function returning the caller's PropelAuth token"
|
|
2415
|
+
);
|
|
2416
|
+
}
|
|
2417
|
+
const asRecord = config;
|
|
2418
|
+
if ("apiKey" in asRecord || "writeKey" in asRecord) {
|
|
2419
|
+
throw new Error(
|
|
2420
|
+
"createGraph8AppClient does not accept an org API key or write key in the browser \u2014 pass getPropelAuthToken() instead"
|
|
2421
|
+
);
|
|
2422
|
+
}
|
|
2423
|
+
const baseUrl = config.apiUrl || DEFAULT_APP_API;
|
|
2424
|
+
const tokens = createTokenManager({
|
|
2425
|
+
now: config.now,
|
|
2426
|
+
refreshSkewMs: config.refreshSkewMs,
|
|
2427
|
+
refresh: () => exchangeBrowserToken({
|
|
2428
|
+
baseUrl,
|
|
2429
|
+
appId: config.appId,
|
|
2430
|
+
scopes: config.scopes,
|
|
2431
|
+
getPropelAuthToken: config.getPropelAuthToken,
|
|
2432
|
+
fetchImpl: config.fetchImpl,
|
|
2433
|
+
sleepImpl: config.sleepImpl
|
|
2434
|
+
})
|
|
2435
|
+
});
|
|
2436
|
+
const req = createAppRequester({ baseUrl, tokens, fetchImpl: config.fetchImpl, sleepImpl: config.sleepImpl });
|
|
2437
|
+
return {
|
|
2438
|
+
appId: config.appId,
|
|
2439
|
+
tenantOrgId: config.tenantOrgId,
|
|
2440
|
+
request: req,
|
|
2441
|
+
getAppToken: (force = false) => tokens.getToken(force)
|
|
2442
|
+
};
|
|
2443
|
+
}
|
|
2444
|
+
function createGraph8ServiceClient(config) {
|
|
2445
|
+
if (!config?.clientId || !config?.clientSecret) {
|
|
2446
|
+
throw new Error("createGraph8ServiceClient requires clientId and clientSecret");
|
|
2447
|
+
}
|
|
2448
|
+
if (!config?.tenantOrgId) {
|
|
2449
|
+
throw new Error(
|
|
2450
|
+
"createGraph8ServiceClient requires tenantOrgId \u2014 the single consented client org this backend acts for"
|
|
2451
|
+
);
|
|
2452
|
+
}
|
|
2453
|
+
const baseUrl = config.apiUrl || DEFAULT_APP_API;
|
|
2454
|
+
const tokens = createTokenManager({
|
|
2455
|
+
now: config.now,
|
|
2456
|
+
refreshSkewMs: config.refreshSkewMs,
|
|
2457
|
+
refresh: () => exchangeServiceToken({
|
|
2458
|
+
baseUrl,
|
|
2459
|
+
clientId: config.clientId,
|
|
2460
|
+
clientSecret: config.clientSecret,
|
|
2461
|
+
scopes: config.scopes,
|
|
2462
|
+
ttlSeconds: config.ttlSeconds,
|
|
2463
|
+
fetchImpl: config.fetchImpl,
|
|
2464
|
+
sleepImpl: config.sleepImpl
|
|
2465
|
+
})
|
|
2466
|
+
});
|
|
2467
|
+
const req = createAppRequester({
|
|
2468
|
+
baseUrl,
|
|
2469
|
+
tokens,
|
|
2470
|
+
extraHeaders: { "X-Target-Org-Id": config.tenantOrgId },
|
|
2471
|
+
fetchImpl: config.fetchImpl,
|
|
2472
|
+
sleepImpl: config.sleepImpl
|
|
2473
|
+
});
|
|
2474
|
+
return {
|
|
2475
|
+
tenantOrgId: config.tenantOrgId,
|
|
2476
|
+
request: req,
|
|
2477
|
+
getServiceToken: (force = false) => tokens.getToken(force)
|
|
2478
|
+
};
|
|
2479
|
+
}
|
|
2305
2480
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2306
2481
|
0 && (module.exports = {
|
|
2482
|
+
DEFAULT_APP_API,
|
|
2307
2483
|
G8Error,
|
|
2308
2484
|
KNOWN_WEBHOOK_EVENTS,
|
|
2309
2485
|
WebhookSignatureError,
|
|
2310
2486
|
backoffDelayMs,
|
|
2311
2487
|
constructEvent,
|
|
2488
|
+
createAppRequester,
|
|
2489
|
+
createGraph8AppClient,
|
|
2490
|
+
createGraph8ServiceClient,
|
|
2491
|
+
createTokenManager,
|
|
2492
|
+
exchangeBrowserToken,
|
|
2493
|
+
exchangeServiceToken,
|
|
2312
2494
|
g8,
|
|
2313
2495
|
isRetryableStatus,
|
|
2314
2496
|
paginate,
|