@elmohq/sdk 0.0.0-stage → 0.1.1
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/LICENSE.md +21 -0
- package/README.md +326 -2
- package/dist/calls/index.d.mts +288 -0
- package/dist/calls/index.d.mts.map +1 -0
- package/dist/calls/index.mjs +390 -0
- package/dist/calls/index.mjs.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +1031 -0
- package/dist/index.mjs.map +1 -0
- package/dist/request-options-B9S9d24M.d.mts +1549 -0
- package/dist/request-options-B9S9d24M.d.mts.map +1 -0
- package/dist/tools-7Hs5J2xb.d.mts +1945 -0
- package/dist/tools-7Hs5J2xb.d.mts.map +1 -0
- package/dist/tools-B1lVtYAr.mjs +2459 -0
- package/dist/tools-B1lVtYAr.mjs.map +1 -0
- package/dist/types/index.d.mts +2 -0
- package/dist/types/index.mjs +1 -0
- package/package.json +68 -4
- package/src/calls/brands-analytics-get.ts +33 -0
- package/src/calls/brands-citations-domains-list.ts +36 -0
- package/src/calls/brands-citations-urls-list.ts +32 -0
- package/src/calls/brands-create.ts +19 -0
- package/src/calls/brands-get.ts +19 -0
- package/src/calls/brands-list.ts +18 -0
- package/src/calls/brands-opportunities-get.ts +42 -0
- package/src/calls/brands-prompt-performance-list.ts +39 -0
- package/src/calls/brands-query-fanout-get.ts +30 -0
- package/src/calls/brands-tags-list.ts +28 -0
- package/src/calls/brands-update.ts +20 -0
- package/src/calls/competitors-create.ts +23 -0
- package/src/calls/competitors-delete.ts +19 -0
- package/src/calls/competitors-get.ts +19 -0
- package/src/calls/competitors-list.ts +23 -0
- package/src/calls/competitors-update.ts +24 -0
- package/src/calls/index.ts +33 -0
- package/src/calls/me-get.ts +18 -0
- package/src/calls/models-list.ts +20 -0
- package/src/calls/organizations-billing-get.ts +37 -0
- package/src/calls/organizations-get.ts +24 -0
- package/src/calls/organizations-list.ts +27 -0
- package/src/calls/prompts-create.ts +27 -0
- package/src/calls/prompts-delete.ts +28 -0
- package/src/calls/prompts-get.ts +23 -0
- package/src/calls/prompts-list.ts +28 -0
- package/src/calls/prompts-runs-get.ts +27 -0
- package/src/calls/prompts-runs-list.ts +30 -0
- package/src/calls/prompts-snapshot-get.ts +28 -0
- package/src/calls/prompts-update.ts +29 -0
- package/src/calls/reports-create.ts +31 -0
- package/src/calls/reports-get.ts +27 -0
- package/src/calls/reports-list.ts +28 -0
- package/src/calls/tools-analyze.ts +26 -0
- package/src/client.ts +649 -0
- package/src/index.ts +21 -0
- package/src/internal/binding/rest/binding.ts +127 -0
- package/src/internal/binding/rest/errors.ts +107 -0
- package/src/internal/binding/rest/path.ts +9 -0
- package/src/internal/binding/rest/url.ts +97 -0
- package/src/internal/codec/json.ts +66 -0
- package/src/internal/codec/registry.ts +55 -0
- package/src/internal/core/backoff.ts +170 -0
- package/src/internal/core/body.ts +54 -0
- package/src/internal/core/browser.ts +11 -0
- package/src/internal/core/call-promise.ts +145 -0
- package/src/internal/core/callable.ts +11 -0
- package/src/internal/core/client.ts +89 -0
- package/src/internal/core/config.ts +84 -0
- package/src/internal/core/credentials.ts +40 -0
- package/src/internal/core/dispatch.ts +225 -0
- package/src/internal/core/env.ts +68 -0
- package/src/internal/core/errors.ts +431 -0
- package/src/internal/core/features.ts +60 -0
- package/src/internal/core/lazy-promise.ts +39 -0
- package/src/internal/core/metadata.ts +79 -0
- package/src/internal/core/page.ts +402 -0
- package/src/internal/core/params.ts +98 -0
- package/src/internal/core/protocol.ts +17 -0
- package/src/internal/core/read-reply.ts +7 -0
- package/src/internal/core/text.ts +7 -0
- package/src/internal/core/types.ts +554 -0
- package/src/internal/feature/auth.ts +201 -0
- package/src/internal/feature/interceptors.ts +36 -0
- package/src/internal/feature/logger.ts +222 -0
- package/src/internal/feature/retry.ts +168 -0
- package/src/internal/feature/rules.ts +54 -0
- package/src/internal/feature/timeout.ts +146 -0
- package/src/internal/feature/validate.ts +82 -0
- package/src/internal/transport/fetch.ts +82 -0
- package/src/resources/analytics.ts +364 -0
- package/src/resources/brands.ts +288 -0
- package/src/resources/competitors.ts +213 -0
- package/src/resources/identity.ts +49 -0
- package/src/resources/models.ts +32 -0
- package/src/resources/opportunities.ts +81 -0
- package/src/resources/organizations.ts +182 -0
- package/src/resources/prompts.ts +293 -0
- package/src/resources/reports.ts +212 -0
- package/src/resources/runs.ts +124 -0
- package/src/resources/shared/auth.ts +13 -0
- package/src/resources/shared/request-options.ts +26 -0
- package/src/resources/shared/resource.ts +23 -0
- package/src/resources/shared/rule.ts +25 -0
- package/src/resources/snapshots.ts +54 -0
- package/src/resources/tags.ts +46 -0
- package/src/resources/tools.ts +69 -0
- package/src/types/analytics.ts +497 -0
- package/src/types/brands.ts +228 -0
- package/src/types/competitors.ts +196 -0
- package/src/types/identity.ts +55 -0
- package/src/types/index.ts +163 -0
- package/src/types/models.ts +40 -0
- package/src/types/opportunities.ts +84 -0
- package/src/types/organizations.ts +157 -0
- package/src/types/prompts.ts +231 -0
- package/src/types/reports.ts +266 -0
- package/src/types/runs.ts +131 -0
- package/src/types/shared/brand-id-path.ts +2 -0
- package/src/types/shared/conflict-error.ts +7 -0
- package/src/types/shared/error.ts +29 -0
- package/src/types/shared/limit.ts +8 -0
- package/src/types/shared/mention-entry.ts +21 -0
- package/src/types/shared/model-filter.ts +15 -0
- package/src/types/shared/not-found-error.ts +4 -0
- package/src/types/shared/page.ts +7 -0
- package/src/types/shared/pagination.ts +7 -0
- package/src/types/shared/validation-error.ts +4 -0
- package/src/types/snapshots.ts +88 -0
- package/src/types/tags.ts +47 -0
- package/src/types/tools.ts +78 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { TIMER_LIMIT } from '../core/backoff';
|
|
2
|
+
import { replyWith } from '../core/body';
|
|
3
|
+
import { calledOffWith, safeAddress, TimeoutError } from '../core/errors';
|
|
4
|
+
import type {
|
|
5
|
+
CallableDescriptor,
|
|
6
|
+
CallTimeout,
|
|
7
|
+
Feature,
|
|
8
|
+
PreparedRequest,
|
|
9
|
+
Result,
|
|
10
|
+
Send,
|
|
11
|
+
} from '../core/types';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Chooses the limit of one call, given the operation as `METHOD /path` and the
|
|
15
|
+
* limit it would otherwise get. `undefined` keeps that limit.
|
|
16
|
+
*/
|
|
17
|
+
export type TimeoutPolicy = (operation: string, timeout: CallTimeout) => CallTimeout | undefined;
|
|
18
|
+
|
|
19
|
+
/** A limit in milliseconds, `false` for none, or a policy choosing one per call. */
|
|
20
|
+
export type TimeoutValue = CallTimeout | TimeoutPolicy;
|
|
21
|
+
|
|
22
|
+
export interface TimeoutOptions {
|
|
23
|
+
ms?: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function describeTarget(request: PreparedRequest): string | undefined {
|
|
27
|
+
const { method } = request.callable;
|
|
28
|
+
if (typeof request.address !== 'string') return undefined;
|
|
29
|
+
const address = safeAddress(request.address);
|
|
30
|
+
return method ? `${method.toUpperCase()} "${address}"` : `"${address}"`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const DEFAULT_TIMEOUT = 60_000;
|
|
34
|
+
|
|
35
|
+
function operationKey({ address, method }: CallableDescriptor): string {
|
|
36
|
+
return method ? `${method.toUpperCase()} ${address}` : address;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function resolveTimeout(base: TimeoutOptions, request: PreparedRequest): number | undefined {
|
|
40
|
+
const own = request.callable.timeout ?? base.ms ?? DEFAULT_TIMEOUT;
|
|
41
|
+
const option = request.options['timeout'] as TimeoutValue | undefined;
|
|
42
|
+
const ms =
|
|
43
|
+
typeof option === 'function'
|
|
44
|
+
? (option(operationKey(request.callable), own) ?? own)
|
|
45
|
+
: (option ?? own);
|
|
46
|
+
if (ms === false) return undefined;
|
|
47
|
+
return ms > 0 && Number.isFinite(ms) ? ms : undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function watchedReply(
|
|
51
|
+
response: Response,
|
|
52
|
+
wait: <T>(pending: Promise<T>) => Promise<T>,
|
|
53
|
+
done: () => void,
|
|
54
|
+
): Response {
|
|
55
|
+
const reader = response.body!.getReader();
|
|
56
|
+
const body = new ReadableStream<Uint8Array>({
|
|
57
|
+
cancel(reason) {
|
|
58
|
+
done();
|
|
59
|
+
return reader.cancel(reason);
|
|
60
|
+
},
|
|
61
|
+
async pull(controller) {
|
|
62
|
+
const step = await wait(reader.read()).catch((error: unknown) => {
|
|
63
|
+
done();
|
|
64
|
+
reader.cancel(error).catch(done);
|
|
65
|
+
throw error;
|
|
66
|
+
});
|
|
67
|
+
if (step.done) {
|
|
68
|
+
done();
|
|
69
|
+
controller.close();
|
|
70
|
+
} else {
|
|
71
|
+
controller.enqueue(step.value);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
return replyWith(body, response);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function timeoutFeature(options: TimeoutOptions = {}): Feature {
|
|
79
|
+
async function bounded(request: PreparedRequest, next: Send, stream: boolean): Promise<Result> {
|
|
80
|
+
const ms = resolveTimeout(options, request);
|
|
81
|
+
if (ms === undefined) return next(request);
|
|
82
|
+
const delay = Math.min(ms, TIMER_LIMIT);
|
|
83
|
+
let left = delay;
|
|
84
|
+
|
|
85
|
+
const caller = request.signal;
|
|
86
|
+
const controller = new AbortController();
|
|
87
|
+
const { signal } = controller;
|
|
88
|
+
|
|
89
|
+
function abortWithCaller(): void {
|
|
90
|
+
controller.abort(caller?.reason);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (caller?.aborted) abortWithCaller();
|
|
94
|
+
caller?.addEventListener('abort', abortWithCaller, { once: true });
|
|
95
|
+
|
|
96
|
+
const abandoned = new Promise<never>((_, reject) => {
|
|
97
|
+
function giveUp(): void {
|
|
98
|
+
reject(calledOffWith(signal.reason));
|
|
99
|
+
}
|
|
100
|
+
if (signal.aborted) giveUp();
|
|
101
|
+
else signal.addEventListener('abort', giveUp, { once: true });
|
|
102
|
+
});
|
|
103
|
+
abandoned.catch(() => {});
|
|
104
|
+
|
|
105
|
+
function expire(): void {
|
|
106
|
+
controller.abort(new TimeoutError(ms, undefined, describeTarget(request)));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function wait<T>(pending: Promise<T>): Promise<T> {
|
|
110
|
+
const started = Date.now();
|
|
111
|
+
const timer = setTimeout(expire, left);
|
|
112
|
+
try {
|
|
113
|
+
return await Promise.race([pending, abandoned]);
|
|
114
|
+
} finally {
|
|
115
|
+
clearTimeout(timer);
|
|
116
|
+
left = stream ? delay : left - (Date.now() - started);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function done(): void {
|
|
121
|
+
caller?.removeEventListener('abort', abortWithCaller);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
request.signal = signal;
|
|
125
|
+
const result = await wait(next(request))
|
|
126
|
+
.catch((error: unknown) => {
|
|
127
|
+
done();
|
|
128
|
+
throw error;
|
|
129
|
+
})
|
|
130
|
+
.finally(() => {
|
|
131
|
+
request.signal = caller;
|
|
132
|
+
});
|
|
133
|
+
const { response } = result;
|
|
134
|
+
if (response?.body && stream) {
|
|
135
|
+
return { ...result, response: watchedReply(response, wait, done) };
|
|
136
|
+
}
|
|
137
|
+
done();
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
name: 'timeout',
|
|
143
|
+
onOpen: (request, next) => bounded(request, next, true),
|
|
144
|
+
onSend: (request, next) => bounded(request, next, !!request.options.unread),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { unreadableValue } from '../core/errors';
|
|
2
|
+
import { readReply } from '../core/read-reply';
|
|
3
|
+
import type { CallableDescriptor, Feature, ResolvedOptions } from '../core/types';
|
|
4
|
+
|
|
5
|
+
export type Validate<TIn = unknown, TOut = TIn> = (value: TIn) => Promise<TOut> | TOut;
|
|
6
|
+
|
|
7
|
+
export async function runValidator<T>(
|
|
8
|
+
validate: Validate<T, T> | undefined,
|
|
9
|
+
value: T,
|
|
10
|
+
options: ResolvedOptions,
|
|
11
|
+
response?: Response,
|
|
12
|
+
): Promise<T> {
|
|
13
|
+
if (!validate || options['validate'] === false) return value;
|
|
14
|
+
return await readReply(validate, value, response);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface CallableValidators {
|
|
18
|
+
error?: Validate;
|
|
19
|
+
request?: Validate<ResolvedOptions, Partial<ResolvedOptions>>;
|
|
20
|
+
response?: Validate;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function validatorsOf(callable: CallableDescriptor): CallableValidators | undefined {
|
|
24
|
+
return callable.validators as CallableValidators | undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function validateFeature(): Feature {
|
|
28
|
+
return {
|
|
29
|
+
name: 'validate',
|
|
30
|
+
async onOptions(options, callable) {
|
|
31
|
+
const validate = validatorsOf(callable)?.request;
|
|
32
|
+
if (!validate || options['validate'] === false) return;
|
|
33
|
+
Object.assign(options, await validate(options));
|
|
34
|
+
},
|
|
35
|
+
async onResult(result, request) {
|
|
36
|
+
const validators = validatorsOf(request.callable);
|
|
37
|
+
if (!validators) return result;
|
|
38
|
+
if (result.error !== undefined && result.error !== null) {
|
|
39
|
+
result.error = await runValidator(
|
|
40
|
+
validators.error,
|
|
41
|
+
result.error,
|
|
42
|
+
request.options,
|
|
43
|
+
result.response,
|
|
44
|
+
);
|
|
45
|
+
} else if (result.data !== undefined) {
|
|
46
|
+
result.data = await runValidator(
|
|
47
|
+
validators.response,
|
|
48
|
+
result.data,
|
|
49
|
+
request.options,
|
|
50
|
+
result.response,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function decoded<TIn, TOut>(at: string, value: TIn, read: (value: TIn) => TOut): TOut {
|
|
59
|
+
let result: TOut;
|
|
60
|
+
try {
|
|
61
|
+
result = read(value);
|
|
62
|
+
} catch (cause) {
|
|
63
|
+
throw unreadableValue(at, value, cause);
|
|
64
|
+
}
|
|
65
|
+
if (result instanceof Date && Number.isNaN(result.getTime())) throw unreadableValue(at, value);
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export type Mutable<T> = T extends (...args: Array<never>) => unknown
|
|
70
|
+
? T
|
|
71
|
+
: T extends object
|
|
72
|
+
? {
|
|
73
|
+
-readonly [K in keyof T]: Mutable<T[K]>;
|
|
74
|
+
}
|
|
75
|
+
: T;
|
|
76
|
+
|
|
77
|
+
export function reviving<T>(revive: (value: T) => void): Validate {
|
|
78
|
+
return (data) => {
|
|
79
|
+
if (data != null) revive(data as T);
|
|
80
|
+
return data;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { isStreamed } from '../core/body';
|
|
2
|
+
import { safeAddress, unsendableAddress } from '../core/errors';
|
|
3
|
+
import { metadataHeaders } from '../core/metadata';
|
|
4
|
+
import type { PreparedRequest, Transport } from '../core/types';
|
|
5
|
+
|
|
6
|
+
/** A `fetch` function, called with the full address and a built `RequestInit`. */
|
|
7
|
+
export type Fetch = (input: string, init: RequestInit) => Promise<Response>;
|
|
8
|
+
|
|
9
|
+
/** What `fetch` takes, less what the client sets itself. */
|
|
10
|
+
export interface FetchOptions extends RequestInit {
|
|
11
|
+
/** Set by the client. */
|
|
12
|
+
body?: never;
|
|
13
|
+
/** Set by the client. Pass `headers` to the call. */
|
|
14
|
+
headers?: never;
|
|
15
|
+
/** Set by the client. */
|
|
16
|
+
method?: never;
|
|
17
|
+
/** Set by the client. Pass `signal` to the call. */
|
|
18
|
+
signal?: never;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function checkAddress(address: string): void {
|
|
22
|
+
let url: URL;
|
|
23
|
+
try {
|
|
24
|
+
url = new URL(address, (globalThis as { location?: { href: string } }).location?.href);
|
|
25
|
+
} catch {
|
|
26
|
+
throw unsendableAddress(
|
|
27
|
+
safeAddress(address),
|
|
28
|
+
'is not a full address',
|
|
29
|
+
'Start the base URL with `https://`.',
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
const shown = `${url.protocol}//${url.host}${url.pathname}`;
|
|
33
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
|
34
|
+
throw unsendableAddress(
|
|
35
|
+
shown,
|
|
36
|
+
`uses \`${url.protocol}\`, which fetch does not send`,
|
|
37
|
+
'Start the base URL with `https://`.',
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
if (url.username || url.password) {
|
|
41
|
+
throw unsendableAddress(
|
|
42
|
+
shown,
|
|
43
|
+
'holds a user name or password, which fetch refuses',
|
|
44
|
+
'Pass the credential as an option instead.',
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const OWNED = ['body', 'headers', 'method', 'signal'] as const;
|
|
50
|
+
|
|
51
|
+
function extraInit(request: PreparedRequest<string>): RequestInit | undefined {
|
|
52
|
+
const extra = request.options['fetchOptions'] as RequestInit | undefined;
|
|
53
|
+
if (!extra) return undefined;
|
|
54
|
+
const rest: RequestInit = { ...extra };
|
|
55
|
+
for (const key of OWNED) delete rest[key];
|
|
56
|
+
return rest;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function toRequestInit(request: PreparedRequest<string>): RequestInit {
|
|
60
|
+
return {
|
|
61
|
+
...extraInit(request),
|
|
62
|
+
...(request.body !== undefined && { body: request.body }),
|
|
63
|
+
...(isStreamed(request.body) && { duplex: 'half' }),
|
|
64
|
+
headers: metadataHeaders(request.meta),
|
|
65
|
+
method: (request.callable.method ?? 'get').toUpperCase(),
|
|
66
|
+
...(request.signal !== undefined && { signal: request.signal }),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function createFetchTransport(fetchFn?: Fetch): Transport<string, 'unary'> {
|
|
71
|
+
function send(request: PreparedRequest<string>): Promise<Response> {
|
|
72
|
+
const configured = request.options['fetch'] as Fetch | undefined;
|
|
73
|
+
const call = configured ?? fetchFn ?? globalThis.fetch;
|
|
74
|
+
if (call === globalThis.fetch) checkAddress(request.address);
|
|
75
|
+
return call(request.address, toRequestInit(request));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
name: 'fetch',
|
|
80
|
+
unary: send,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import { apiKeyRequirements } from './shared/auth';
|
|
2
|
+
import type { RequestOptions } from './shared/request-options';
|
|
3
|
+
import { ElmoResource } from './shared/resource';
|
|
4
|
+
import { callPromise, RestCallPromise } from '../internal/core/call-promise';
|
|
5
|
+
import { callable } from '../internal/core/callable';
|
|
6
|
+
import { mergeParams, placeParams } from '../internal/core/params';
|
|
7
|
+
import type { Mutable } from '../internal/feature/validate';
|
|
8
|
+
import { decoded, reviving } from '../internal/feature/validate';
|
|
9
|
+
import type {
|
|
10
|
+
BrandAnalytics,
|
|
11
|
+
BrandQueryFanout,
|
|
12
|
+
CitationDomain,
|
|
13
|
+
CitationDomainList,
|
|
14
|
+
CitationURL,
|
|
15
|
+
CitationURLList,
|
|
16
|
+
DateRange,
|
|
17
|
+
FanoutQuery,
|
|
18
|
+
GetBrandAnalyticsErrors,
|
|
19
|
+
GetBrandAnalyticsParams,
|
|
20
|
+
GetBrandAnalyticsResponses,
|
|
21
|
+
GetBrandQueryFanoutErrors,
|
|
22
|
+
GetBrandQueryFanoutParams,
|
|
23
|
+
GetBrandQueryFanoutResponses,
|
|
24
|
+
ListBrandCitationDomainsErrors,
|
|
25
|
+
ListBrandCitationDomainsParams,
|
|
26
|
+
ListBrandCitationDomainsResponses,
|
|
27
|
+
ListBrandCitationURLsErrors,
|
|
28
|
+
ListBrandCitationURLsParams,
|
|
29
|
+
ListBrandCitationURLsResponses,
|
|
30
|
+
ListBrandPromptPerformanceErrors,
|
|
31
|
+
ListBrandPromptPerformanceParams,
|
|
32
|
+
ListBrandPromptPerformanceResponses,
|
|
33
|
+
ModelVisibility,
|
|
34
|
+
PromptPerformanceList,
|
|
35
|
+
PromptPerformance as PromptPerformanceSchema,
|
|
36
|
+
ShareOfVoiceEntry,
|
|
37
|
+
ShareOfVoicePoint,
|
|
38
|
+
VisibilityPoint,
|
|
39
|
+
} from '../types/analytics';
|
|
40
|
+
import type { BrandIdPath } from '../types/shared/brand-id-path';
|
|
41
|
+
|
|
42
|
+
export const getBrandAnalyticsFields = { path: ['brandId'] };
|
|
43
|
+
|
|
44
|
+
function reviveDateRange(value: Mutable<DateRange>): void {
|
|
45
|
+
if (value.start != null) {
|
|
46
|
+
value.start = decoded('DateRange.start', value.start, (raw) => new Date(raw));
|
|
47
|
+
}
|
|
48
|
+
if (value.end != null) {
|
|
49
|
+
value.end = decoded('DateRange.end', value.end, (raw) => new Date(raw));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function reviveBrandAnalytics(value: Mutable<BrandAnalytics>): void {
|
|
54
|
+
if (value.range != null) {
|
|
55
|
+
reviveDateRange(value.range);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const getBrandAnalyticsDescriptor = /* @__PURE__ */ callable({
|
|
60
|
+
address: '/brands/{brandId}/analytics',
|
|
61
|
+
auth: apiKeyRequirements,
|
|
62
|
+
method: 'get',
|
|
63
|
+
returns: 'json',
|
|
64
|
+
validators: { response: /* @__PURE__ */ reviving(reviveBrandAnalytics) },
|
|
65
|
+
} as const);
|
|
66
|
+
|
|
67
|
+
export const listBrandCitationDomainsFields = { path: ['brandId'] };
|
|
68
|
+
|
|
69
|
+
function reviveCitationDomainList(value: Mutable<CitationDomainList>): void {
|
|
70
|
+
if (value.range != null) {
|
|
71
|
+
reviveDateRange(value.range);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const listBrandCitationDomainsDescriptor = /* @__PURE__ */ callable({
|
|
76
|
+
address: '/brands/{brandId}/citations/domains',
|
|
77
|
+
auth: apiKeyRequirements,
|
|
78
|
+
method: 'get',
|
|
79
|
+
returns: 'json',
|
|
80
|
+
validators: { response: /* @__PURE__ */ reviving(reviveCitationDomainList) },
|
|
81
|
+
} as const);
|
|
82
|
+
|
|
83
|
+
export const listBrandCitationUrlsFields = { path: ['brandId'] };
|
|
84
|
+
|
|
85
|
+
function reviveCitationUrlList(value: Mutable<CitationURLList>): void {
|
|
86
|
+
if (value.range != null) {
|
|
87
|
+
reviveDateRange(value.range);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export const listBrandCitationURLsDescriptor = /* @__PURE__ */ callable({
|
|
92
|
+
address: '/brands/{brandId}/citations/urls',
|
|
93
|
+
auth: apiKeyRequirements,
|
|
94
|
+
method: 'get',
|
|
95
|
+
returns: 'json',
|
|
96
|
+
validators: { response: /* @__PURE__ */ reviving(reviveCitationUrlList) },
|
|
97
|
+
} as const);
|
|
98
|
+
|
|
99
|
+
export const listBrandPromptPerformanceFields = { path: ['brandId'] };
|
|
100
|
+
|
|
101
|
+
function revivePromptPerformance(value: Mutable<PromptPerformanceSchema>): void {
|
|
102
|
+
if (value.lastRunAt != null) {
|
|
103
|
+
value.lastRunAt = decoded(
|
|
104
|
+
'PromptPerformance.lastRunAt',
|
|
105
|
+
value.lastRunAt,
|
|
106
|
+
(raw) => new Date(raw),
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
if (value.firstEvaluatedAt != null) {
|
|
110
|
+
value.firstEvaluatedAt = decoded(
|
|
111
|
+
'PromptPerformance.firstEvaluatedAt',
|
|
112
|
+
value.firstEvaluatedAt,
|
|
113
|
+
(raw) => new Date(raw),
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function revivePromptPerformanceList(value: Mutable<PromptPerformanceList>): void {
|
|
119
|
+
if (value.range != null) {
|
|
120
|
+
reviveDateRange(value.range);
|
|
121
|
+
}
|
|
122
|
+
if (value.data != null) {
|
|
123
|
+
value.data.forEach((item) => {
|
|
124
|
+
revivePromptPerformance(item);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export const listBrandPromptPerformanceDescriptor = /* @__PURE__ */ callable({
|
|
130
|
+
address: '/brands/{brandId}/prompt-performance',
|
|
131
|
+
auth: apiKeyRequirements,
|
|
132
|
+
method: 'get',
|
|
133
|
+
returns: 'json',
|
|
134
|
+
validators: { response: /* @__PURE__ */ reviving(revivePromptPerformanceList) },
|
|
135
|
+
} as const);
|
|
136
|
+
|
|
137
|
+
export const getBrandQueryFanoutFields = { path: ['brandId'] };
|
|
138
|
+
|
|
139
|
+
function reviveBrandQueryFanout(value: Mutable<BrandQueryFanout>): void {
|
|
140
|
+
if (value.range != null) {
|
|
141
|
+
reviveDateRange(value.range);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export const getBrandQueryFanoutDescriptor = /* @__PURE__ */ callable({
|
|
146
|
+
address: '/brands/{brandId}/query-fanout',
|
|
147
|
+
auth: apiKeyRequirements,
|
|
148
|
+
method: 'get',
|
|
149
|
+
returns: 'json',
|
|
150
|
+
validators: { response: /* @__PURE__ */ reviving(reviveBrandQueryFanout) },
|
|
151
|
+
} as const);
|
|
152
|
+
|
|
153
|
+
/** Aggregated visibility, share of voice, citations, and query fan-out for a brand */
|
|
154
|
+
export class Analytics extends ElmoResource {
|
|
155
|
+
/**
|
|
156
|
+
* Get a brand's analytics
|
|
157
|
+
*
|
|
158
|
+
* Visibility, share of voice, the per-model breakdown and the citation totals for one window, in
|
|
159
|
+
* one request.
|
|
160
|
+
*
|
|
161
|
+
* The long lists — cited domains and URLs, sub-queries, per-prompt results — are endpoints of
|
|
162
|
+
* their own. Everything else is always included.
|
|
163
|
+
*
|
|
164
|
+
* @param brandId Brand identifier.
|
|
165
|
+
*/
|
|
166
|
+
public get(
|
|
167
|
+
brandId: BrandIdPath,
|
|
168
|
+
params: GetBrandAnalyticsParams,
|
|
169
|
+
options?: RequestOptions,
|
|
170
|
+
): RestCallPromise<GetBrandAnalyticsResponses, GetBrandAnalyticsErrors> {
|
|
171
|
+
return callPromise(
|
|
172
|
+
options?.client ?? this.client,
|
|
173
|
+
getBrandAnalyticsDescriptor,
|
|
174
|
+
mergeParams(placeParams({ ...params, brandId }, getBrandAnalyticsFields, 'query'), options),
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Aggregated visibility, share of voice, citations, and query fan-out for a brand */
|
|
180
|
+
export class Domains extends ElmoResource {
|
|
181
|
+
/**
|
|
182
|
+
* List cited domains
|
|
183
|
+
*
|
|
184
|
+
* Domains the engines cited when answering this brand's prompts, categorized and compared against
|
|
185
|
+
* the equal-length window immediately before this one.
|
|
186
|
+
*
|
|
187
|
+
* @param brandId Brand identifier.
|
|
188
|
+
*/
|
|
189
|
+
public list(
|
|
190
|
+
brandId: BrandIdPath,
|
|
191
|
+
params: ListBrandCitationDomainsParams,
|
|
192
|
+
options?: RequestOptions,
|
|
193
|
+
): RestCallPromise<ListBrandCitationDomainsResponses, ListBrandCitationDomainsErrors> {
|
|
194
|
+
return callPromise(
|
|
195
|
+
options?.client ?? this.client,
|
|
196
|
+
listBrandCitationDomainsDescriptor,
|
|
197
|
+
mergeParams(
|
|
198
|
+
placeParams({ ...params, brandId }, listBrandCitationDomainsFields, 'query'),
|
|
199
|
+
options,
|
|
200
|
+
),
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** Aggregated visibility, share of voice, citations, and query fan-out for a brand */
|
|
206
|
+
export class URLs extends ElmoResource {
|
|
207
|
+
/**
|
|
208
|
+
* List cited URLs
|
|
209
|
+
*
|
|
210
|
+
* Individual pages the engines cited, with their category and page type.
|
|
211
|
+
*
|
|
212
|
+
* @param brandId Brand identifier.
|
|
213
|
+
*/
|
|
214
|
+
public list(
|
|
215
|
+
brandId: BrandIdPath,
|
|
216
|
+
params: ListBrandCitationURLsParams,
|
|
217
|
+
options?: RequestOptions,
|
|
218
|
+
): RestCallPromise<ListBrandCitationURLsResponses, ListBrandCitationURLsErrors> {
|
|
219
|
+
return callPromise(
|
|
220
|
+
options?.client ?? this.client,
|
|
221
|
+
listBrandCitationURLsDescriptor,
|
|
222
|
+
mergeParams(
|
|
223
|
+
placeParams({ ...params, brandId }, listBrandCitationUrlsFields, 'query'),
|
|
224
|
+
options,
|
|
225
|
+
),
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export class Citations extends ElmoResource {
|
|
231
|
+
private _domains?: Domains;
|
|
232
|
+
/** Aggregated visibility, share of voice, citations, and query fan-out for a brand */
|
|
233
|
+
get domains(): Domains {
|
|
234
|
+
return (this._domains ??= new Domains(this.client));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
private _urls?: URLs;
|
|
238
|
+
/** Aggregated visibility, share of voice, citations, and query fan-out for a brand */
|
|
239
|
+
get urls(): URLs {
|
|
240
|
+
return (this._urls ??= new URLs(this.client));
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Aggregated visibility, share of voice, citations, and query fan-out for a brand */
|
|
245
|
+
export class PromptPerformance extends ElmoResource {
|
|
246
|
+
/**
|
|
247
|
+
* List prompt performance
|
|
248
|
+
*
|
|
249
|
+
* Per-prompt mention rates over the window. The analytics counterpart to `GET /prompts?brandId=`,
|
|
250
|
+
* which returns prompt configuration rather than results.
|
|
251
|
+
*
|
|
252
|
+
* A prompt the brand stopped tracking is not sampled, so it has no results over the window and
|
|
253
|
+
* does not appear here.
|
|
254
|
+
*
|
|
255
|
+
* @param brandId Brand identifier.
|
|
256
|
+
*/
|
|
257
|
+
public list(
|
|
258
|
+
brandId: BrandIdPath,
|
|
259
|
+
params: ListBrandPromptPerformanceParams,
|
|
260
|
+
options?: RequestOptions,
|
|
261
|
+
): RestCallPromise<ListBrandPromptPerformanceResponses, ListBrandPromptPerformanceErrors> {
|
|
262
|
+
return callPromise(
|
|
263
|
+
options?.client ?? this.client,
|
|
264
|
+
listBrandPromptPerformanceDescriptor,
|
|
265
|
+
mergeParams(
|
|
266
|
+
placeParams({ ...params, brandId }, listBrandPromptPerformanceFields, 'query'),
|
|
267
|
+
options,
|
|
268
|
+
),
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** Aggregated visibility, share of voice, citations, and query fan-out for a brand */
|
|
274
|
+
export class QueryFanout extends ElmoResource {
|
|
275
|
+
/**
|
|
276
|
+
* Get query fan-out
|
|
277
|
+
*
|
|
278
|
+
* The searches engines ran while answering this brand's prompts. Engines that don't expose their
|
|
279
|
+
* searches still contribute runs, so `coverageRate` is the honest denominator.
|
|
280
|
+
*
|
|
281
|
+
* @param brandId Brand identifier.
|
|
282
|
+
*/
|
|
283
|
+
public get(
|
|
284
|
+
brandId: BrandIdPath,
|
|
285
|
+
params: GetBrandQueryFanoutParams,
|
|
286
|
+
options?: RequestOptions,
|
|
287
|
+
): RestCallPromise<GetBrandQueryFanoutResponses, GetBrandQueryFanoutErrors> {
|
|
288
|
+
return callPromise(
|
|
289
|
+
options?.client ?? this.client,
|
|
290
|
+
getBrandQueryFanoutDescriptor,
|
|
291
|
+
mergeParams(placeParams({ ...params, brandId }, getBrandQueryFanoutFields, 'query'), options),
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export declare namespace Analytics {
|
|
297
|
+
export type {
|
|
298
|
+
BrandAnalytics,
|
|
299
|
+
GetBrandAnalyticsErrors,
|
|
300
|
+
GetBrandAnalyticsParams,
|
|
301
|
+
GetBrandAnalyticsResponses,
|
|
302
|
+
ModelVisibility,
|
|
303
|
+
ShareOfVoiceEntry,
|
|
304
|
+
ShareOfVoicePoint,
|
|
305
|
+
VisibilityPoint,
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export declare namespace Domains {
|
|
310
|
+
export type {
|
|
311
|
+
CitationDomain,
|
|
312
|
+
CitationDomainList,
|
|
313
|
+
ListBrandCitationDomainsErrors,
|
|
314
|
+
ListBrandCitationDomainsParams,
|
|
315
|
+
ListBrandCitationDomainsResponses,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export declare namespace URLs {
|
|
320
|
+
export type {
|
|
321
|
+
CitationURL,
|
|
322
|
+
CitationURLList,
|
|
323
|
+
ListBrandCitationURLsErrors,
|
|
324
|
+
ListBrandCitationURLsParams,
|
|
325
|
+
ListBrandCitationURLsResponses,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export declare namespace Citations {
|
|
330
|
+
export type {
|
|
331
|
+
CitationDomain,
|
|
332
|
+
CitationDomainList,
|
|
333
|
+
CitationURL,
|
|
334
|
+
CitationURLList,
|
|
335
|
+
Domains,
|
|
336
|
+
ListBrandCitationDomainsErrors,
|
|
337
|
+
ListBrandCitationDomainsParams,
|
|
338
|
+
ListBrandCitationDomainsResponses,
|
|
339
|
+
ListBrandCitationURLsErrors,
|
|
340
|
+
ListBrandCitationURLsParams,
|
|
341
|
+
ListBrandCitationURLsResponses,
|
|
342
|
+
URLs,
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export declare namespace PromptPerformance {
|
|
347
|
+
export type {
|
|
348
|
+
ListBrandPromptPerformanceErrors,
|
|
349
|
+
ListBrandPromptPerformanceParams,
|
|
350
|
+
ListBrandPromptPerformanceResponses,
|
|
351
|
+
PromptPerformanceSchema as PromptPerformance,
|
|
352
|
+
PromptPerformanceList,
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
export declare namespace QueryFanout {
|
|
357
|
+
export type {
|
|
358
|
+
BrandQueryFanout,
|
|
359
|
+
FanoutQuery,
|
|
360
|
+
GetBrandQueryFanoutErrors,
|
|
361
|
+
GetBrandQueryFanoutParams,
|
|
362
|
+
GetBrandQueryFanoutResponses,
|
|
363
|
+
};
|
|
364
|
+
}
|