attio-ts-sdk 0.0.0 → 1.1.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 +214 -22
- package/dist/index.d.mts +692 -277
- package/dist/index.mjs +1689 -873
- package/dist/index.mjs.map +1 -1
- package/package.json +30 -26
- package/dist/browser.d.ts +0 -14933
- package/dist/browser.js +0 -8
- package/dist/browser.js.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,256 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import process from "node:process";
|
|
2
3
|
|
|
4
|
+
//#region src/attio/batch.ts
|
|
5
|
+
const recordSuccess = (params) => {
|
|
6
|
+
const { state, currentIndex, value, label, isCancelled } = params;
|
|
7
|
+
if (isCancelled?.()) return;
|
|
8
|
+
state.results[currentIndex] = {
|
|
9
|
+
status: "fulfilled",
|
|
10
|
+
value,
|
|
11
|
+
label
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
const recordFailure = (params) => {
|
|
15
|
+
const { state, currentIndex, error, label, options, abortController, isCancelled, reject } = params;
|
|
16
|
+
if (options.stopOnError) {
|
|
17
|
+
if (!state.stopped) {
|
|
18
|
+
state.stopped = true;
|
|
19
|
+
if (abortController && !abortController.signal.aborted) abortController.abort();
|
|
20
|
+
reject(error);
|
|
21
|
+
}
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (isCancelled()) return;
|
|
25
|
+
state.results[currentIndex] = {
|
|
26
|
+
status: "rejected",
|
|
27
|
+
reason: error,
|
|
28
|
+
label
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
const launchNextItem = (params) => {
|
|
32
|
+
const { items, state, abortController, options, isCancelled, reject, launchNext } = params;
|
|
33
|
+
const currentIndex = state.index;
|
|
34
|
+
const item = items[currentIndex];
|
|
35
|
+
state.index += 1;
|
|
36
|
+
state.active += 1;
|
|
37
|
+
item.run(abortController ? { signal: abortController.signal } : void 0).then((value) => {
|
|
38
|
+
recordSuccess({
|
|
39
|
+
state,
|
|
40
|
+
currentIndex,
|
|
41
|
+
value,
|
|
42
|
+
label: item.label,
|
|
43
|
+
isCancelled
|
|
44
|
+
});
|
|
45
|
+
}).catch((error) => {
|
|
46
|
+
recordFailure({
|
|
47
|
+
state,
|
|
48
|
+
currentIndex,
|
|
49
|
+
error,
|
|
50
|
+
label: item.label,
|
|
51
|
+
options,
|
|
52
|
+
abortController,
|
|
53
|
+
isCancelled,
|
|
54
|
+
reject
|
|
55
|
+
});
|
|
56
|
+
}).finally(() => {
|
|
57
|
+
state.active -= 1;
|
|
58
|
+
if (!isCancelled()) launchNext();
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Returns an empty results array when called with no items.
|
|
63
|
+
*/
|
|
64
|
+
const runBatch = (items, options = {}) => {
|
|
65
|
+
if (items.length === 0) return Promise.resolve([]);
|
|
66
|
+
const concurrency = Math.max(1, options.concurrency ?? 4);
|
|
67
|
+
const state = {
|
|
68
|
+
results: new Array(items.length),
|
|
69
|
+
index: 0,
|
|
70
|
+
active: 0,
|
|
71
|
+
stopped: false
|
|
72
|
+
};
|
|
73
|
+
const abortController = options.stopOnError ? new AbortController() : void 0;
|
|
74
|
+
const isCancelled = () => abortController?.signal.aborted ?? state.stopped;
|
|
75
|
+
return new Promise((resolve, reject) => {
|
|
76
|
+
const launchNext = () => {
|
|
77
|
+
if (isCancelled()) return;
|
|
78
|
+
if (state.index >= items.length && state.active === 0) {
|
|
79
|
+
resolve(state.results);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
while (state.active < concurrency && state.index < items.length) launchNextItem({
|
|
83
|
+
items,
|
|
84
|
+
state,
|
|
85
|
+
concurrency,
|
|
86
|
+
abortController,
|
|
87
|
+
options,
|
|
88
|
+
isCancelled,
|
|
89
|
+
resolve,
|
|
90
|
+
reject,
|
|
91
|
+
launchNext
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
launchNext();
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/attio/cache.ts
|
|
100
|
+
const DEFAULT_METADATA_CACHE_TTL_MS = 300 * 1e3;
|
|
101
|
+
const DEFAULT_METADATA_CACHE_MAX_ENTRIES = {
|
|
102
|
+
attributes: 200,
|
|
103
|
+
options: 500,
|
|
104
|
+
statuses: 500
|
|
105
|
+
};
|
|
106
|
+
var TtlCache = class {
|
|
107
|
+
ttlMs;
|
|
108
|
+
maxEntries;
|
|
109
|
+
store = /* @__PURE__ */ new Map();
|
|
110
|
+
constructor(options) {
|
|
111
|
+
this.ttlMs = options.ttlMs;
|
|
112
|
+
this.maxEntries = options.maxEntries;
|
|
113
|
+
}
|
|
114
|
+
get(key) {
|
|
115
|
+
const entry = this.store.get(key);
|
|
116
|
+
if (!entry) return;
|
|
117
|
+
if (Date.now() >= entry.expiresAt) {
|
|
118
|
+
this.store.delete(key);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
return entry.value;
|
|
122
|
+
}
|
|
123
|
+
set(key, value) {
|
|
124
|
+
if (this.maxEntries && this.store.size >= this.maxEntries && !this.store.has(key)) {
|
|
125
|
+
const oldestKey = this.store.keys().next().value;
|
|
126
|
+
if (oldestKey !== void 0) this.store.delete(oldestKey);
|
|
127
|
+
}
|
|
128
|
+
this.store.set(key, {
|
|
129
|
+
value,
|
|
130
|
+
expiresAt: Date.now() + this.ttlMs
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
delete(key) {
|
|
134
|
+
this.store.delete(key);
|
|
135
|
+
}
|
|
136
|
+
clear() {
|
|
137
|
+
this.store.clear();
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
const createTtlCacheAdapter = (params) => {
|
|
141
|
+
const cache = new TtlCache({
|
|
142
|
+
ttlMs: params.ttlMs,
|
|
143
|
+
maxEntries: params.maxEntries
|
|
144
|
+
});
|
|
145
|
+
return {
|
|
146
|
+
get: (key) => cache.get(key),
|
|
147
|
+
set: (key, value) => cache.set(key, value),
|
|
148
|
+
delete: (key) => cache.delete(key),
|
|
149
|
+
clear: () => cache.clear()
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
const clientCache = /* @__PURE__ */ new Map();
|
|
153
|
+
const getCachedClient = (key, validator) => {
|
|
154
|
+
const cached = clientCache.get(key);
|
|
155
|
+
if (cached === void 0) return;
|
|
156
|
+
try {
|
|
157
|
+
const result = validator.safeParse(cached);
|
|
158
|
+
if (!result.success) return;
|
|
159
|
+
return result.data;
|
|
160
|
+
} catch {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
const setCachedClient = (key, client) => {
|
|
165
|
+
clientCache.set(key, client);
|
|
166
|
+
};
|
|
167
|
+
const clearClientCache = () => {
|
|
168
|
+
clientCache.clear();
|
|
169
|
+
};
|
|
170
|
+
const ANONYMOUS_HASH = "anon";
|
|
171
|
+
const hashToken = (value) => {
|
|
172
|
+
if (value === void 0) return ANONYMOUS_HASH;
|
|
173
|
+
let hash = 5381;
|
|
174
|
+
for (let i = 0; i < value.length; i += 1) hash = hash * 33 ^ value.charCodeAt(i);
|
|
175
|
+
return (hash >>> 0).toString(36);
|
|
176
|
+
};
|
|
177
|
+
const createTtlCache = (options) => new TtlCache(options);
|
|
178
|
+
const metadataCacheRegistry = /* @__PURE__ */ new Map();
|
|
179
|
+
const resolveMaxEntries = (maxEntries, scope) => {
|
|
180
|
+
if (typeof maxEntries === "number") return maxEntries;
|
|
181
|
+
if (maxEntries && maxEntries[scope] !== void 0) return maxEntries[scope];
|
|
182
|
+
return DEFAULT_METADATA_CACHE_MAX_ENTRIES[scope];
|
|
183
|
+
};
|
|
184
|
+
const isMetadataCacheDisabled = (config) => config.enabled === false;
|
|
185
|
+
const createMetadataCacheManager = (config = {}) => {
|
|
186
|
+
if (isMetadataCacheDisabled(config)) return {
|
|
187
|
+
get: () => void 0,
|
|
188
|
+
clear: () => void 0
|
|
189
|
+
};
|
|
190
|
+
const ttlMs = config.ttlMs ?? DEFAULT_METADATA_CACHE_TTL_MS;
|
|
191
|
+
const adapterFactory = config.adapter ?? { create: (params) => createTtlCacheAdapter(params) };
|
|
192
|
+
const caches = /* @__PURE__ */ new Map();
|
|
193
|
+
const get = (scope) => {
|
|
194
|
+
const existing = caches.get(scope);
|
|
195
|
+
if (existing) return existing;
|
|
196
|
+
const adapter = adapterFactory.create({
|
|
197
|
+
scope,
|
|
198
|
+
ttlMs,
|
|
199
|
+
maxEntries: resolveMaxEntries(config.maxEntries, scope)
|
|
200
|
+
});
|
|
201
|
+
caches.set(scope, adapter);
|
|
202
|
+
return adapter;
|
|
203
|
+
};
|
|
204
|
+
const clear = () => {
|
|
205
|
+
for (const adapter of caches.values()) adapter.clear();
|
|
206
|
+
caches.clear();
|
|
207
|
+
};
|
|
208
|
+
return {
|
|
209
|
+
get,
|
|
210
|
+
clear
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
const buildMetadataCacheFingerprint = (config) => {
|
|
214
|
+
return `ttl:${config.ttlMs ?? "default"}|max:${typeof config.maxEntries === "number" ? config.maxEntries : JSON.stringify(config.maxEntries ?? "default")}`;
|
|
215
|
+
};
|
|
216
|
+
const getMetadataCacheManager = (key, config) => {
|
|
217
|
+
if (config?.enabled === false) return createMetadataCacheManager(config);
|
|
218
|
+
if (config?.adapter) return createMetadataCacheManager(config);
|
|
219
|
+
const registryKey = `${key}|${config ? buildMetadataCacheFingerprint(config) : "default"}`;
|
|
220
|
+
const existing = metadataCacheRegistry.get(registryKey);
|
|
221
|
+
if (existing) return existing;
|
|
222
|
+
const manager = createMetadataCacheManager(config);
|
|
223
|
+
metadataCacheRegistry.set(registryKey, manager);
|
|
224
|
+
return manager;
|
|
225
|
+
};
|
|
226
|
+
const clearMetadataCacheRegistry = () => {
|
|
227
|
+
for (const manager of metadataCacheRegistry.values()) manager.clear();
|
|
228
|
+
metadataCacheRegistry.clear();
|
|
229
|
+
};
|
|
230
|
+
const isAttioCacheDisabled = (config) => config?.enabled === false;
|
|
231
|
+
const resolveMetadataCacheConfig = (config) => {
|
|
232
|
+
if (isAttioCacheDisabled(config)) return { enabled: false };
|
|
233
|
+
const metadataBase = config?.metadata;
|
|
234
|
+
if (metadataBase?.enabled === false) return { enabled: false };
|
|
235
|
+
return {
|
|
236
|
+
enabled: true,
|
|
237
|
+
ttlMs: metadataBase?.ttlMs,
|
|
238
|
+
maxEntries: metadataBase?.maxEntries,
|
|
239
|
+
adapter: metadataBase?.adapter
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
const createAttioCacheManager = (key, config) => {
|
|
243
|
+
const metadata = getMetadataCacheManager(key, resolveMetadataCacheConfig(config));
|
|
244
|
+
const clear = () => {
|
|
245
|
+
metadata.clear();
|
|
246
|
+
};
|
|
247
|
+
return {
|
|
248
|
+
metadata,
|
|
249
|
+
clear
|
|
250
|
+
};
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
//#endregion
|
|
3
254
|
//#region src/generated/core/bodySerializer.gen.ts
|
|
4
255
|
const jsonBodySerializer = { bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value) };
|
|
5
256
|
|
|
@@ -610,74 +861,600 @@ const createClient = (config = {}) => {
|
|
|
610
861
|
};
|
|
611
862
|
|
|
612
863
|
//#endregion
|
|
613
|
-
//#region src/
|
|
614
|
-
const
|
|
864
|
+
//#region src/attio/config.ts
|
|
865
|
+
const TRAILING_SLASHES_REGEX = /\/+$/;
|
|
866
|
+
const DEFAULT_BASE_URL = "https://api.attio.com";
|
|
867
|
+
const getEnvValue = (key) => {
|
|
868
|
+
if (typeof process === "undefined") return;
|
|
869
|
+
return process.env?.[key];
|
|
870
|
+
};
|
|
871
|
+
const normalizeBaseUrl = (baseUrl) => baseUrl.replace(TRAILING_SLASHES_REGEX, "");
|
|
872
|
+
const resolveBaseUrl = (config) => {
|
|
873
|
+
return normalizeBaseUrl(config?.baseUrl ?? getEnvValue("ATTIO_BASE_URL") ?? DEFAULT_BASE_URL);
|
|
874
|
+
};
|
|
875
|
+
const resolveAuthToken = (config) => config?.apiKey ?? config?.accessToken ?? config?.authToken ?? getEnvValue("ATTIO_API_KEY") ?? getEnvValue("ATTIO_ACCESS_TOKEN");
|
|
876
|
+
const resolveResponseStyle = (config) => config?.responseStyle ?? "fields";
|
|
877
|
+
const resolveThrowOnError = (config) => config?.throwOnError ?? true;
|
|
615
878
|
|
|
616
879
|
//#endregion
|
|
617
|
-
//#region src/
|
|
618
|
-
const
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
}
|
|
630
|
-
const
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
880
|
+
//#region src/attio/error-enhancer.ts
|
|
881
|
+
const knownFieldValues = /* @__PURE__ */ new Map();
|
|
882
|
+
const VALUE_PATTERNS = [
|
|
883
|
+
/constraint:\s*([^,]+)/i,
|
|
884
|
+
/option name\s+'([^']+)'/i,
|
|
885
|
+
/option name\s+"([^"]+)"/i
|
|
886
|
+
];
|
|
887
|
+
const getKnownFieldValues = (field) => knownFieldValues.get(field);
|
|
888
|
+
const updateKnownFieldValues = (field, values) => {
|
|
889
|
+
const unique = Array.from(new Set(values.map((value) => value.trim()))).filter(Boolean);
|
|
890
|
+
if (unique.length > 0) knownFieldValues.set(field, unique);
|
|
891
|
+
else knownFieldValues.delete(field);
|
|
892
|
+
};
|
|
893
|
+
const extractMismatchContext = (error) => {
|
|
894
|
+
const { message, data: rawData } = error;
|
|
895
|
+
const data = rawData;
|
|
896
|
+
const path = (Array.isArray(data?.path) ? data?.path[0] : data?.path) ?? data?.field ?? data?.attribute ?? void 0;
|
|
897
|
+
if (typeof message !== "string" || typeof path !== "string") return;
|
|
898
|
+
let value;
|
|
899
|
+
for (const pattern of VALUE_PATTERNS) {
|
|
900
|
+
const match = message.match(pattern);
|
|
901
|
+
if (match?.[1]) {
|
|
902
|
+
value = match[1].trim();
|
|
903
|
+
break;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
return {
|
|
907
|
+
field: path,
|
|
908
|
+
value
|
|
909
|
+
};
|
|
910
|
+
};
|
|
911
|
+
const levenshtein = (a, b) => {
|
|
912
|
+
const matrix = [];
|
|
913
|
+
const aLen = a.length;
|
|
914
|
+
const bLen = b.length;
|
|
915
|
+
for (let i = 0; i <= bLen; i += 1) matrix[i] = [i];
|
|
916
|
+
for (let j = 0; j <= aLen; j += 1) matrix[0][j] = j;
|
|
917
|
+
for (let i = 1; i <= bLen; i += 1) for (let j = 1; j <= aLen; j += 1) if (b.charAt(i - 1) === a.charAt(j - 1)) matrix[i][j] = matrix[i - 1][j - 1];
|
|
918
|
+
else matrix[i][j] = Math.min(matrix[i - 1][j - 1] + 1, matrix[i][j - 1] + 1, matrix[i - 1][j] + 1);
|
|
919
|
+
return matrix[bLen][aLen];
|
|
920
|
+
};
|
|
921
|
+
const scoreCandidates = (value, candidates) => {
|
|
922
|
+
const normalized = value.toLowerCase();
|
|
923
|
+
return candidates.map((candidate) => ({
|
|
924
|
+
candidate,
|
|
925
|
+
score: levenshtein(normalized, candidate.toLowerCase())
|
|
926
|
+
})).sort((a, b) => a.score - b.score).map((entry) => entry.candidate);
|
|
927
|
+
};
|
|
928
|
+
const enhanceAttioError = (error) => {
|
|
929
|
+
if (!error?.isApiError) return error;
|
|
930
|
+
const context = extractMismatchContext(error);
|
|
931
|
+
if (!(context?.field && context?.value)) return error;
|
|
932
|
+
const candidates = knownFieldValues.get(context.field);
|
|
933
|
+
if (candidates === void 0 || candidates.length === 0) return error;
|
|
934
|
+
const matches = scoreCandidates(context.value, candidates).slice(0, 3);
|
|
935
|
+
error.suggestions = {
|
|
936
|
+
field: context.field,
|
|
937
|
+
attempted: context.value,
|
|
938
|
+
bestMatch: matches[0],
|
|
939
|
+
matches
|
|
940
|
+
};
|
|
941
|
+
return error;
|
|
942
|
+
};
|
|
943
|
+
|
|
944
|
+
//#endregion
|
|
945
|
+
//#region src/attio/errors.ts
|
|
946
|
+
var AttioError = class extends Error {
|
|
947
|
+
status;
|
|
948
|
+
code;
|
|
949
|
+
type;
|
|
950
|
+
requestId;
|
|
951
|
+
data;
|
|
952
|
+
response;
|
|
953
|
+
request;
|
|
954
|
+
retryAfterMs;
|
|
955
|
+
isNetworkError;
|
|
956
|
+
isApiError;
|
|
957
|
+
suggestions;
|
|
958
|
+
constructor(message, details = {}) {
|
|
959
|
+
super(message, details.cause ? { cause: details.cause } : void 0);
|
|
960
|
+
this.name = "AttioError";
|
|
961
|
+
this.status = details.status;
|
|
962
|
+
this.code = details.code;
|
|
963
|
+
this.type = details.type;
|
|
964
|
+
this.data = details.data;
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
const applyDefaultCode = (details, code) => ({
|
|
968
|
+
...details,
|
|
969
|
+
code: details.code ?? code
|
|
639
970
|
});
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
})
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
"
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
971
|
+
var AttioBatchError = class extends AttioError {
|
|
972
|
+
constructor(message, details = {}) {
|
|
973
|
+
super(message, applyDefaultCode(details, "BATCH_ERROR"));
|
|
974
|
+
this.name = "AttioBatchError";
|
|
975
|
+
}
|
|
976
|
+
};
|
|
977
|
+
var AttioConfigError = class extends AttioError {
|
|
978
|
+
constructor(message, details = {}) {
|
|
979
|
+
super(message, applyDefaultCode(details, "CONFIG_ERROR"));
|
|
980
|
+
this.name = "AttioConfigError";
|
|
981
|
+
}
|
|
982
|
+
};
|
|
983
|
+
var AttioEnvironmentError = class extends AttioError {
|
|
984
|
+
constructor(message, details = {}) {
|
|
985
|
+
super(message, applyDefaultCode(details, "ENVIRONMENT_ERROR"));
|
|
986
|
+
this.name = "AttioEnvironmentError";
|
|
987
|
+
}
|
|
988
|
+
};
|
|
989
|
+
var AttioResponseError = class extends AttioError {
|
|
990
|
+
constructor(message, details = {}) {
|
|
991
|
+
super(message, applyDefaultCode(details, "RESPONSE_ERROR"));
|
|
992
|
+
this.name = "AttioResponseError";
|
|
993
|
+
}
|
|
994
|
+
};
|
|
995
|
+
var AttioRetryError = class extends AttioError {
|
|
996
|
+
constructor(message, details = {}) {
|
|
997
|
+
super(message, applyDefaultCode(details, "RETRY_ERROR"));
|
|
998
|
+
this.name = "AttioRetryError";
|
|
999
|
+
}
|
|
1000
|
+
};
|
|
1001
|
+
var AttioApiError = class extends AttioError {
|
|
1002
|
+
constructor(message, details = {}) {
|
|
1003
|
+
super(message, details);
|
|
1004
|
+
this.name = "AttioApiError";
|
|
1005
|
+
this.isApiError = true;
|
|
1006
|
+
}
|
|
1007
|
+
};
|
|
1008
|
+
var AttioNetworkError = class extends AttioError {
|
|
1009
|
+
constructor(message, details = {}) {
|
|
1010
|
+
super(message, details);
|
|
1011
|
+
this.name = "AttioNetworkError";
|
|
1012
|
+
this.isNetworkError = true;
|
|
1013
|
+
}
|
|
1014
|
+
};
|
|
1015
|
+
const getHeaderValue = (response, key) => {
|
|
1016
|
+
if (!response) return;
|
|
1017
|
+
return response.headers.get(key) ?? void 0;
|
|
1018
|
+
};
|
|
1019
|
+
const parseRetryAfter = (response) => {
|
|
1020
|
+
if (!response) return;
|
|
1021
|
+
const raw = response.headers.get("Retry-After");
|
|
1022
|
+
if (!raw) return;
|
|
1023
|
+
const seconds = Number(raw);
|
|
1024
|
+
if (Number.isFinite(seconds)) return Math.max(0, seconds * 1e3);
|
|
1025
|
+
const dateMs = Date.parse(raw);
|
|
1026
|
+
if (!Number.isNaN(dateMs)) return Math.max(0, dateMs - Date.now());
|
|
1027
|
+
};
|
|
1028
|
+
const extractMessage = (error, fallback) => {
|
|
1029
|
+
if (typeof error === "string") return error;
|
|
1030
|
+
if (error && typeof error === "object") {
|
|
1031
|
+
const maybe = error;
|
|
1032
|
+
if (typeof maybe.message === "string") return maybe.message;
|
|
1033
|
+
}
|
|
1034
|
+
return fallback ?? "Request failed.";
|
|
1035
|
+
};
|
|
1036
|
+
const extractStatusCode = (payload) => {
|
|
1037
|
+
if (typeof payload.status_code === "number") return payload.status_code;
|
|
1038
|
+
if (typeof payload.status === "number") return payload.status;
|
|
1039
|
+
};
|
|
1040
|
+
const extractDetails = (error) => {
|
|
1041
|
+
if (!error || typeof error !== "object") return {};
|
|
1042
|
+
const payload = error;
|
|
1043
|
+
return {
|
|
1044
|
+
code: typeof payload.code === "string" ? payload.code : void 0,
|
|
1045
|
+
type: typeof payload.type === "string" ? payload.type : void 0,
|
|
1046
|
+
status: extractStatusCode(payload),
|
|
1047
|
+
message: typeof payload.message === "string" ? payload.message : void 0,
|
|
1048
|
+
data: payload
|
|
1049
|
+
};
|
|
1050
|
+
};
|
|
1051
|
+
const normalizeAttioError = (error, context = {}) => {
|
|
1052
|
+
const { response, request } = context;
|
|
1053
|
+
const details = extractDetails(error);
|
|
1054
|
+
const status = response?.status ?? details.status;
|
|
1055
|
+
const message = extractMessage(error, response?.statusText ?? details.message);
|
|
1056
|
+
const requestId = getHeaderValue(response, "x-request-id") ?? getHeaderValue(response, "x-attio-request-id");
|
|
1057
|
+
if (response) {
|
|
1058
|
+
const apiError = new AttioApiError(message, {
|
|
1059
|
+
...details,
|
|
1060
|
+
status
|
|
1061
|
+
});
|
|
1062
|
+
apiError.requestId = requestId;
|
|
1063
|
+
apiError.response = response;
|
|
1064
|
+
apiError.request = request;
|
|
1065
|
+
apiError.data = details.data ?? error;
|
|
1066
|
+
apiError.retryAfterMs = parseRetryAfter(response);
|
|
1067
|
+
return enhanceAttioError(apiError);
|
|
1068
|
+
}
|
|
1069
|
+
const networkError = new AttioNetworkError(message, details);
|
|
1070
|
+
networkError.request = request;
|
|
1071
|
+
return networkError;
|
|
1072
|
+
};
|
|
1073
|
+
|
|
1074
|
+
//#endregion
|
|
1075
|
+
//#region src/attio/retry.ts
|
|
1076
|
+
const DEFAULT_RETRY_CONFIG = {
|
|
1077
|
+
maxRetries: 3,
|
|
1078
|
+
initialDelayMs: 500,
|
|
1079
|
+
maxDelayMs: 5e3,
|
|
1080
|
+
retryableStatusCodes: [
|
|
1081
|
+
408,
|
|
1082
|
+
429,
|
|
1083
|
+
500,
|
|
1084
|
+
502,
|
|
1085
|
+
503,
|
|
1086
|
+
504
|
|
1087
|
+
],
|
|
1088
|
+
respectRetryAfter: true
|
|
1089
|
+
};
|
|
1090
|
+
const RetryErrorSchema = z.object({
|
|
1091
|
+
status: z.number().optional(),
|
|
1092
|
+
isNetworkError: z.boolean().optional(),
|
|
1093
|
+
retryAfterMs: z.number().optional()
|
|
1094
|
+
});
|
|
1095
|
+
const extractRetryErrorInfo = (error) => {
|
|
1096
|
+
if (error instanceof AttioError) return {
|
|
1097
|
+
status: error.status,
|
|
1098
|
+
isNetworkError: error.isNetworkError,
|
|
1099
|
+
retryAfterMs: error.retryAfterMs
|
|
1100
|
+
};
|
|
1101
|
+
const result = RetryErrorSchema.safeParse(error);
|
|
1102
|
+
if (!result.success) return;
|
|
1103
|
+
return result.data;
|
|
1104
|
+
};
|
|
1105
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
1106
|
+
const calculateRetryDelay = (attempt, config, retryAfterMs) => {
|
|
1107
|
+
if (config.respectRetryAfter && retryAfterMs && retryAfterMs > 0) return Math.min(retryAfterMs, config.maxDelayMs);
|
|
1108
|
+
const base = config.initialDelayMs * 2 ** attempt;
|
|
1109
|
+
const jitter = .75 + Math.random() * .5;
|
|
1110
|
+
return Math.min(base * jitter, config.maxDelayMs);
|
|
1111
|
+
};
|
|
1112
|
+
const isRetryableStatus = (status, config) => {
|
|
1113
|
+
if (status === void 0) return true;
|
|
1114
|
+
return config.retryableStatusCodes.includes(status);
|
|
1115
|
+
};
|
|
1116
|
+
const isRetryableError = (error, config) => {
|
|
1117
|
+
const info = extractRetryErrorInfo(error);
|
|
1118
|
+
if (info?.isNetworkError) return true;
|
|
1119
|
+
return isRetryableStatus(info?.status, config);
|
|
1120
|
+
};
|
|
1121
|
+
const getRetryAfterMs = (error) => extractRetryErrorInfo(error)?.retryAfterMs;
|
|
1122
|
+
async function callWithRetry(fn, config) {
|
|
1123
|
+
const retryConfig = {
|
|
1124
|
+
...DEFAULT_RETRY_CONFIG,
|
|
1125
|
+
...config
|
|
1126
|
+
};
|
|
1127
|
+
let attempt = 0;
|
|
1128
|
+
while (attempt <= retryConfig.maxRetries) try {
|
|
1129
|
+
return await fn();
|
|
1130
|
+
} catch (error) {
|
|
1131
|
+
if (!isRetryableError(error, retryConfig)) throw error;
|
|
1132
|
+
if (attempt >= retryConfig.maxRetries) throw new AttioRetryError("Retry attempts exhausted.", {
|
|
1133
|
+
code: "RETRY_EXHAUSTED",
|
|
1134
|
+
cause: error
|
|
1135
|
+
});
|
|
1136
|
+
await sleep(calculateRetryDelay(attempt, retryConfig, getRetryAfterMs(error)));
|
|
1137
|
+
attempt += 1;
|
|
1138
|
+
}
|
|
1139
|
+
throw new AttioRetryError("Retry attempts exhausted.", { code: "RETRY_EXHAUSTED" });
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
//#endregion
|
|
1143
|
+
//#region src/attio/client.ts
|
|
1144
|
+
const interceptorUseSchema = z.object({ use: z.function() }).passthrough();
|
|
1145
|
+
const attioClientShapeSchema = z.object({
|
|
1146
|
+
request: z.function(),
|
|
1147
|
+
cache: z.object({
|
|
1148
|
+
metadata: z.object({
|
|
1149
|
+
get: z.function(),
|
|
1150
|
+
clear: z.function()
|
|
1151
|
+
}).passthrough(),
|
|
1152
|
+
clear: z.function()
|
|
1153
|
+
}).passthrough(),
|
|
1154
|
+
interceptors: z.object({
|
|
1155
|
+
error: interceptorUseSchema,
|
|
1156
|
+
request: interceptorUseSchema,
|
|
1157
|
+
response: interceptorUseSchema
|
|
1158
|
+
}).passthrough()
|
|
1159
|
+
}).passthrough();
|
|
1160
|
+
const AttioClientSchema = z.any().refine((value) => attioClientShapeSchema.safeParse(value).success, { message: "Invalid cached Attio client." });
|
|
1161
|
+
const combineSignalsWithAny = ({ requestSignal, timeoutSignal }) => AbortSignal.any([requestSignal, timeoutSignal]);
|
|
1162
|
+
const combineSignalsWithFallback = ({ requestSignal, timeoutSignal }) => {
|
|
1163
|
+
const combinedController = new AbortController();
|
|
1164
|
+
if (requestSignal.aborted) {
|
|
1165
|
+
combinedController.abort();
|
|
1166
|
+
return { combinedSignal: combinedController.signal };
|
|
1167
|
+
}
|
|
1168
|
+
const abortCombined = () => combinedController.abort();
|
|
1169
|
+
requestSignal.addEventListener("abort", abortCombined, { once: true });
|
|
1170
|
+
timeoutSignal.addEventListener("abort", abortCombined, { once: true });
|
|
1171
|
+
return {
|
|
1172
|
+
combinedSignal: combinedController.signal,
|
|
1173
|
+
abortCombined
|
|
1174
|
+
};
|
|
1175
|
+
};
|
|
1176
|
+
const resolveFetch = (config) => {
|
|
1177
|
+
const baseFetch = config?.fetch ?? globalThis.fetch;
|
|
1178
|
+
if (!baseFetch) throw new AttioEnvironmentError("Fetch is not available in this environment.", { code: "FETCH_UNAVAILABLE" });
|
|
1179
|
+
if (!config?.timeoutMs) return baseFetch;
|
|
1180
|
+
return async (input, init) => {
|
|
1181
|
+
const controller = new AbortController();
|
|
1182
|
+
const timeoutId = setTimeout(() => controller.abort(), config.timeoutMs);
|
|
1183
|
+
let combinedSignal = controller.signal;
|
|
1184
|
+
let abortCombined;
|
|
1185
|
+
if (init?.signal) {
|
|
1186
|
+
const signals = {
|
|
1187
|
+
requestSignal: init.signal,
|
|
1188
|
+
timeoutSignal: controller.signal
|
|
1189
|
+
};
|
|
1190
|
+
if (typeof AbortSignal !== "undefined" && "any" in AbortSignal) combinedSignal = combineSignalsWithAny(signals);
|
|
1191
|
+
else ({combinedSignal, abortCombined} = combineSignalsWithFallback(signals));
|
|
1192
|
+
}
|
|
1193
|
+
try {
|
|
1194
|
+
return await baseFetch(input, {
|
|
1195
|
+
...init,
|
|
1196
|
+
signal: combinedSignal
|
|
1197
|
+
});
|
|
1198
|
+
} finally {
|
|
1199
|
+
if (abortCombined) {
|
|
1200
|
+
init?.signal?.removeEventListener("abort", abortCombined);
|
|
1201
|
+
controller.signal.removeEventListener("abort", abortCombined);
|
|
1202
|
+
}
|
|
1203
|
+
clearTimeout(timeoutId);
|
|
1204
|
+
}
|
|
1205
|
+
};
|
|
1206
|
+
};
|
|
1207
|
+
const buildClientCacheKey = ({ config, authToken }) => {
|
|
1208
|
+
if (config.cache?.key) return `${config.cache.key}:${hashToken(authToken)}`;
|
|
1209
|
+
};
|
|
1210
|
+
const buildMetadataCacheKey = ({ config, authToken, baseUrl }) => `${config.cache?.key ?? "attio"}:${hashToken(authToken)}:${baseUrl}`;
|
|
1211
|
+
const composeHook = (first, second) => {
|
|
1212
|
+
if (!first) return second;
|
|
1213
|
+
if (!second) return first;
|
|
1214
|
+
return (payload) => {
|
|
1215
|
+
first(payload);
|
|
1216
|
+
second(payload);
|
|
1217
|
+
};
|
|
1218
|
+
};
|
|
1219
|
+
const createLoggerHooks = (logger) => {
|
|
1220
|
+
if (!logger) return {};
|
|
1221
|
+
const { debug, error: logError } = logger;
|
|
1222
|
+
return {
|
|
1223
|
+
onRequest: debug ? ({ request }) => debug("attio.request", {
|
|
1224
|
+
method: request.method,
|
|
1225
|
+
url: request.url
|
|
1226
|
+
}) : void 0,
|
|
1227
|
+
onResponse: debug ? ({ response, request }) => debug("attio.response", {
|
|
1228
|
+
method: request.method,
|
|
1229
|
+
url: request.url,
|
|
1230
|
+
status: response.status
|
|
1231
|
+
}) : void 0,
|
|
1232
|
+
onError: logError ? ({ error, request, response }) => logError("attio.error", {
|
|
1233
|
+
message: error.message,
|
|
1234
|
+
code: error.code,
|
|
1235
|
+
status: error.status,
|
|
1236
|
+
requestId: error.requestId,
|
|
1237
|
+
url: request?.url,
|
|
1238
|
+
responseStatus: response?.status
|
|
1239
|
+
}) : void 0
|
|
1240
|
+
};
|
|
1241
|
+
};
|
|
1242
|
+
const resolveClientHooks = (config) => {
|
|
1243
|
+
const loggerHooks = createLoggerHooks(config?.logger);
|
|
1244
|
+
const customHooks = config?.hooks ?? {};
|
|
1245
|
+
return {
|
|
1246
|
+
onRequest: composeHook(loggerHooks.onRequest, customHooks.onRequest),
|
|
1247
|
+
onResponse: composeHook(loggerHooks.onResponse, customHooks.onResponse),
|
|
1248
|
+
onError: composeHook(loggerHooks.onError, customHooks.onError)
|
|
1249
|
+
};
|
|
1250
|
+
};
|
|
1251
|
+
const applyInterceptors = (client, hooks) => {
|
|
1252
|
+
if (hooks.onRequest) client.interceptors.request.use((request, options) => {
|
|
1253
|
+
hooks.onRequest?.({
|
|
1254
|
+
request,
|
|
1255
|
+
options
|
|
1256
|
+
});
|
|
1257
|
+
return request;
|
|
1258
|
+
});
|
|
1259
|
+
if (hooks.onResponse) client.interceptors.response.use((response, request, options) => {
|
|
1260
|
+
hooks.onResponse?.({
|
|
1261
|
+
response,
|
|
1262
|
+
request,
|
|
1263
|
+
options
|
|
1264
|
+
});
|
|
1265
|
+
return response;
|
|
1266
|
+
});
|
|
1267
|
+
client.interceptors.error.use((error, response, request, options) => {
|
|
1268
|
+
const normalized = normalizeAttioError(error, {
|
|
1269
|
+
response,
|
|
1270
|
+
request,
|
|
1271
|
+
options
|
|
1272
|
+
});
|
|
1273
|
+
hooks.onError?.({
|
|
1274
|
+
error: normalized,
|
|
1275
|
+
response,
|
|
1276
|
+
request,
|
|
1277
|
+
options
|
|
1278
|
+
});
|
|
1279
|
+
return normalized;
|
|
1280
|
+
});
|
|
1281
|
+
};
|
|
1282
|
+
const wrapClient = (base, retry) => {
|
|
1283
|
+
const requestWithRetry = (options) => {
|
|
1284
|
+
const { retry: retryOverride, ...rest } = options;
|
|
1285
|
+
return callWithRetry(() => base.request(rest), {
|
|
1286
|
+
...retry,
|
|
1287
|
+
...retryOverride
|
|
1288
|
+
});
|
|
1289
|
+
};
|
|
1290
|
+
const makeMethod = (method) => (options) => requestWithRetry({
|
|
1291
|
+
...options,
|
|
1292
|
+
method
|
|
1293
|
+
});
|
|
1294
|
+
return {
|
|
1295
|
+
...base,
|
|
1296
|
+
request: requestWithRetry,
|
|
1297
|
+
connect: makeMethod("CONNECT"),
|
|
1298
|
+
delete: makeMethod("DELETE"),
|
|
1299
|
+
get: makeMethod("GET"),
|
|
1300
|
+
head: makeMethod("HEAD"),
|
|
1301
|
+
options: makeMethod("OPTIONS"),
|
|
1302
|
+
patch: makeMethod("PATCH"),
|
|
1303
|
+
post: makeMethod("POST"),
|
|
1304
|
+
put: makeMethod("PUT"),
|
|
1305
|
+
trace: makeMethod("TRACE")
|
|
1306
|
+
};
|
|
1307
|
+
};
|
|
1308
|
+
const extractAndCleanConfig = (config) => {
|
|
1309
|
+
const { apiKey: _apiKey, accessToken: _accessToken, authToken: _authToken, cache: _cache, retry, timeoutMs, headers, ...cleanConfig } = config;
|
|
1310
|
+
return {
|
|
1311
|
+
cleanConfig,
|
|
1312
|
+
headers,
|
|
1313
|
+
retry,
|
|
1314
|
+
timeoutMs
|
|
1315
|
+
};
|
|
1316
|
+
};
|
|
1317
|
+
const createAttioClientWithAuthToken = ({ config = {}, authToken }) => {
|
|
1318
|
+
const baseUrl = resolveBaseUrl(config);
|
|
1319
|
+
const responseStyle = resolveResponseStyle(config);
|
|
1320
|
+
const throwOnError = resolveThrowOnError(config);
|
|
1321
|
+
const hooks = resolveClientHooks(config);
|
|
1322
|
+
const { cleanConfig, headers, retry, timeoutMs } = extractAndCleanConfig(config);
|
|
1323
|
+
const mergedHeaders = mergeHeaders({ Accept: "application/json" }, headers);
|
|
1324
|
+
const base = createClient({
|
|
1325
|
+
...cleanConfig,
|
|
1326
|
+
baseUrl,
|
|
1327
|
+
auth: authToken,
|
|
1328
|
+
headers: mergedHeaders,
|
|
1329
|
+
fetch: resolveFetch({
|
|
1330
|
+
...config,
|
|
1331
|
+
timeoutMs
|
|
1332
|
+
}),
|
|
1333
|
+
responseStyle,
|
|
1334
|
+
throwOnError
|
|
1335
|
+
});
|
|
1336
|
+
applyInterceptors(base, hooks);
|
|
1337
|
+
const wrapped = wrapClient(base, retry);
|
|
1338
|
+
const cache = createAttioCacheManager(buildMetadataCacheKey({
|
|
1339
|
+
config,
|
|
1340
|
+
authToken,
|
|
1341
|
+
baseUrl
|
|
1342
|
+
}), config.cache);
|
|
1343
|
+
return Object.assign(wrapped, { cache });
|
|
1344
|
+
};
|
|
1345
|
+
const createAttioClient = (config = {}) => {
|
|
1346
|
+
return createAttioClientWithAuthToken({
|
|
1347
|
+
config,
|
|
1348
|
+
authToken: resolveAuthToken(config)
|
|
1349
|
+
});
|
|
1350
|
+
};
|
|
1351
|
+
const getAttioClient = (config = {}) => {
|
|
1352
|
+
const cacheEnabled = config.cache?.enabled ?? true;
|
|
1353
|
+
const authToken = resolveAuthToken(config);
|
|
1354
|
+
const cacheKey = authToken ? buildClientCacheKey({
|
|
1355
|
+
config,
|
|
1356
|
+
authToken
|
|
1357
|
+
}) : void 0;
|
|
1358
|
+
if (cacheEnabled && cacheKey) {
|
|
1359
|
+
const cached = getCachedClient(cacheKey, AttioClientSchema);
|
|
1360
|
+
if (cached) return cached;
|
|
1361
|
+
const client = createAttioClientWithAuthToken({
|
|
1362
|
+
config,
|
|
1363
|
+
authToken
|
|
1364
|
+
});
|
|
1365
|
+
setCachedClient(cacheKey, client);
|
|
1366
|
+
return client;
|
|
1367
|
+
}
|
|
1368
|
+
return createAttioClientWithAuthToken({
|
|
1369
|
+
config,
|
|
1370
|
+
authToken
|
|
1371
|
+
});
|
|
1372
|
+
};
|
|
1373
|
+
const resolveAttioClient = (input = {}) => input.client ?? getAttioClient(input.config ?? {});
|
|
1374
|
+
|
|
1375
|
+
//#endregion
|
|
1376
|
+
//#region src/attio/filters.ts
|
|
1377
|
+
const operator = (field, op, value) => ({ [field]: { [op]: value } });
|
|
1378
|
+
const filters = {
|
|
1379
|
+
eq: (field, value) => operator(field, "$eq", value),
|
|
1380
|
+
contains: (field, value) => operator(field, "$contains", value),
|
|
1381
|
+
startsWith: (field, value) => operator(field, "$starts_with", value),
|
|
1382
|
+
endsWith: (field, value) => operator(field, "$ends_with", value),
|
|
1383
|
+
notEmpty: (field) => operator(field, "$not_empty", true),
|
|
1384
|
+
and: (...conditions) => ({ $and: conditions }),
|
|
1385
|
+
or: (...conditions) => ({ $or: conditions }),
|
|
1386
|
+
not: (condition) => ({ $not: condition })
|
|
1387
|
+
};
|
|
1388
|
+
|
|
1389
|
+
//#endregion
|
|
1390
|
+
//#region src/generated/client.gen.ts
|
|
1391
|
+
const client = createClient(createConfig({ baseUrl: "https://api.attio.com" }));
|
|
1392
|
+
|
|
1393
|
+
//#endregion
|
|
1394
|
+
//#region src/generated/zod.gen.ts
|
|
1395
|
+
const zStatus = z.object({
|
|
1396
|
+
id: z.object({
|
|
1397
|
+
workspace_id: z.uuid(),
|
|
1398
|
+
object_id: z.uuid(),
|
|
1399
|
+
attribute_id: z.uuid(),
|
|
1400
|
+
status_id: z.uuid()
|
|
1401
|
+
}),
|
|
1402
|
+
title: z.string(),
|
|
1403
|
+
is_archived: z.boolean(),
|
|
1404
|
+
celebration_enabled: z.boolean(),
|
|
1405
|
+
target_time_in_status: z.union([z.string(), z.null()])
|
|
1406
|
+
});
|
|
1407
|
+
const zSelectOption = z.object({
|
|
1408
|
+
id: z.object({
|
|
1409
|
+
workspace_id: z.uuid(),
|
|
1410
|
+
object_id: z.uuid(),
|
|
1411
|
+
attribute_id: z.uuid(),
|
|
1412
|
+
option_id: z.uuid()
|
|
1413
|
+
}),
|
|
1414
|
+
title: z.string(),
|
|
1415
|
+
is_archived: z.boolean()
|
|
1416
|
+
});
|
|
1417
|
+
/**
|
|
1418
|
+
* A union of possible value types, as required in request bodies.
|
|
1419
|
+
*/
|
|
1420
|
+
const zInputValue = z.union([
|
|
1421
|
+
z.object({
|
|
1422
|
+
referenced_actor_type: z.enum(["workspace-member"]),
|
|
1423
|
+
referenced_actor_id: z.uuid()
|
|
1424
|
+
}),
|
|
1425
|
+
z.object({ workspace_member_email_address: z.string() }),
|
|
1426
|
+
z.object({ value: z.boolean() }),
|
|
1427
|
+
z.object({ currency_value: z.number() }),
|
|
1428
|
+
z.object({ value: z.string() }),
|
|
1429
|
+
z.object({ domain: z.optional(z.string()) }),
|
|
1430
|
+
z.object({ email_address: z.optional(z.string()) }),
|
|
1431
|
+
z.object({
|
|
1432
|
+
target_object: z.string(),
|
|
1433
|
+
target_record_id: z.uuid()
|
|
1434
|
+
}),
|
|
1435
|
+
z.object({
|
|
1436
|
+
target_object: z.string(),
|
|
1437
|
+
"[slug_or_id_of_matching_attribute]": z.array(z.union([
|
|
1438
|
+
z.object({ domain: z.optional(z.string()) }),
|
|
1439
|
+
z.object({ email_address: z.optional(z.string()) }),
|
|
1440
|
+
z.object({ value: z.optional(z.number()) }),
|
|
1441
|
+
z.object({
|
|
1442
|
+
original_phone_number: z.optional(z.string()),
|
|
1443
|
+
country_code: z.optional(z.enum([
|
|
1444
|
+
"AF",
|
|
1445
|
+
"AX",
|
|
1446
|
+
"AL",
|
|
1447
|
+
"DZ",
|
|
1448
|
+
"AS",
|
|
1449
|
+
"AD",
|
|
1450
|
+
"AO",
|
|
1451
|
+
"AI",
|
|
1452
|
+
"AQ",
|
|
1453
|
+
"AG",
|
|
1454
|
+
"AR",
|
|
1455
|
+
"AM",
|
|
1456
|
+
"AW",
|
|
1457
|
+
"AU",
|
|
681
1458
|
"AT",
|
|
682
1459
|
"AZ",
|
|
683
1460
|
"BS",
|
|
@@ -1508,6 +2285,7 @@ const zOutputValue = z.union([
|
|
|
1508
2285
|
"DKK",
|
|
1509
2286
|
"EUR",
|
|
1510
2287
|
"HKD",
|
|
2288
|
+
"HUF",
|
|
1511
2289
|
"ISK",
|
|
1512
2290
|
"INR",
|
|
1513
2291
|
"ILS",
|
|
@@ -2218,6 +2996,7 @@ const zAttribute = z.object({
|
|
|
2218
2996
|
"DKK",
|
|
2219
2997
|
"EUR",
|
|
2220
2998
|
"HKD",
|
|
2999
|
+
"HUF",
|
|
2221
3000
|
"ISK",
|
|
2222
3001
|
"INR",
|
|
2223
3002
|
"ILS",
|
|
@@ -2579,6 +3358,7 @@ const zPostV2ByTargetByIdentifierAttributesData = z.object({
|
|
|
2579
3358
|
"DKK",
|
|
2580
3359
|
"EUR",
|
|
2581
3360
|
"HKD",
|
|
3361
|
+
"HUF",
|
|
2582
3362
|
"ISK",
|
|
2583
3363
|
"INR",
|
|
2584
3364
|
"ILS",
|
|
@@ -2673,6 +3453,7 @@ const zPatchV2ByTargetByIdentifierAttributesByAttributeData = z.object({
|
|
|
2673
3453
|
"DKK",
|
|
2674
3454
|
"EUR",
|
|
2675
3455
|
"HKD",
|
|
3456
|
+
"HUF",
|
|
2676
3457
|
"ISK",
|
|
2677
3458
|
"INR",
|
|
2678
3459
|
"ILS",
|
|
@@ -2907,6 +3688,7 @@ const zPostV2ObjectsByObjectRecordsQueryResponse = z.object({ data: z.array(z.ob
|
|
|
2907
3688
|
"DKK",
|
|
2908
3689
|
"EUR",
|
|
2909
3690
|
"HKD",
|
|
3691
|
+
"HUF",
|
|
2910
3692
|
"ISK",
|
|
2911
3693
|
"INR",
|
|
2912
3694
|
"ILS",
|
|
@@ -3770,6 +4552,7 @@ const zPostV2ObjectsByObjectRecordsResponse = z.object({ data: z.object({
|
|
|
3770
4552
|
"DKK",
|
|
3771
4553
|
"EUR",
|
|
3772
4554
|
"HKD",
|
|
4555
|
+
"HUF",
|
|
3773
4556
|
"ISK",
|
|
3774
4557
|
"INR",
|
|
3775
4558
|
"ILS",
|
|
@@ -4633,6 +5416,7 @@ const zPutV2ObjectsByObjectRecordsResponse = z.object({ data: z.object({
|
|
|
4633
5416
|
"DKK",
|
|
4634
5417
|
"EUR",
|
|
4635
5418
|
"HKD",
|
|
5419
|
+
"HUF",
|
|
4636
5420
|
"ISK",
|
|
4637
5421
|
"INR",
|
|
4638
5422
|
"ILS",
|
|
@@ -5511,6 +6295,7 @@ const zGetV2ObjectsByObjectRecordsByRecordIdResponse = z.object({ data: z.object
|
|
|
5511
6295
|
"DKK",
|
|
5512
6296
|
"EUR",
|
|
5513
6297
|
"HKD",
|
|
6298
|
+
"HUF",
|
|
5514
6299
|
"ISK",
|
|
5515
6300
|
"INR",
|
|
5516
6301
|
"ILS",
|
|
@@ -6377,6 +7162,7 @@ const zPatchV2ObjectsByObjectRecordsByRecordIdResponse = z.object({ data: z.obje
|
|
|
6377
7162
|
"DKK",
|
|
6378
7163
|
"EUR",
|
|
6379
7164
|
"HKD",
|
|
7165
|
+
"HUF",
|
|
6380
7166
|
"ISK",
|
|
6381
7167
|
"INR",
|
|
6382
7168
|
"ILS",
|
|
@@ -7243,6 +8029,7 @@ const zPutV2ObjectsByObjectRecordsByRecordIdResponse = z.object({ data: z.object
|
|
|
7243
8029
|
"DKK",
|
|
7244
8030
|
"EUR",
|
|
7245
8031
|
"HKD",
|
|
8032
|
+
"HUF",
|
|
7246
8033
|
"ISK",
|
|
7247
8034
|
"INR",
|
|
7248
8035
|
"ILS",
|
|
@@ -8106,6 +8893,7 @@ const zGetV2ObjectsByObjectRecordsByRecordIdAttributesByAttributeValuesResponse
|
|
|
8106
8893
|
"DKK",
|
|
8107
8894
|
"EUR",
|
|
8108
8895
|
"HKD",
|
|
8896
|
+
"HUF",
|
|
8109
8897
|
"ISK",
|
|
8110
8898
|
"INR",
|
|
8111
8899
|
"ILS",
|
|
@@ -9129,6 +9917,7 @@ const zPostV2ListsByListEntriesQueryResponse = z.object({ data: z.array(z.object
|
|
|
9129
9917
|
"DKK",
|
|
9130
9918
|
"EUR",
|
|
9131
9919
|
"HKD",
|
|
9920
|
+
"HUF",
|
|
9132
9921
|
"ISK",
|
|
9133
9922
|
"INR",
|
|
9134
9923
|
"ILS",
|
|
@@ -9997,6 +10786,7 @@ const zPostV2ListsByListEntriesResponse = z.object({ data: z.object({
|
|
|
9997
10786
|
"DKK",
|
|
9998
10787
|
"EUR",
|
|
9999
10788
|
"HKD",
|
|
10789
|
+
"HUF",
|
|
10000
10790
|
"ISK",
|
|
10001
10791
|
"INR",
|
|
10002
10792
|
"ILS",
|
|
@@ -10865,6 +11655,7 @@ const zPutV2ListsByListEntriesResponse = z.object({ data: z.object({
|
|
|
10865
11655
|
"DKK",
|
|
10866
11656
|
"EUR",
|
|
10867
11657
|
"HKD",
|
|
11658
|
+
"HUF",
|
|
10868
11659
|
"ISK",
|
|
10869
11660
|
"INR",
|
|
10870
11661
|
"ILS",
|
|
@@ -11744,6 +12535,7 @@ const zGetV2ListsByListEntriesByEntryIdResponse = z.object({ data: z.object({
|
|
|
11744
12535
|
"DKK",
|
|
11745
12536
|
"EUR",
|
|
11746
12537
|
"HKD",
|
|
12538
|
+
"HUF",
|
|
11747
12539
|
"ISK",
|
|
11748
12540
|
"INR",
|
|
11749
12541
|
"ILS",
|
|
@@ -12611,6 +13403,7 @@ const zPatchV2ListsByListEntriesByEntryIdResponse = z.object({ data: z.object({
|
|
|
12611
13403
|
"DKK",
|
|
12612
13404
|
"EUR",
|
|
12613
13405
|
"HKD",
|
|
13406
|
+
"HUF",
|
|
12614
13407
|
"ISK",
|
|
12615
13408
|
"INR",
|
|
12616
13409
|
"ILS",
|
|
@@ -13478,6 +14271,7 @@ const zPutV2ListsByListEntriesByEntryIdResponse = z.object({ data: z.object({
|
|
|
13478
14271
|
"DKK",
|
|
13479
14272
|
"EUR",
|
|
13480
14273
|
"HKD",
|
|
14274
|
+
"HUF",
|
|
13481
14275
|
"ISK",
|
|
13482
14276
|
"INR",
|
|
13483
14277
|
"ILS",
|
|
@@ -14341,6 +15135,7 @@ const zGetV2ListsByListEntriesByEntryIdAttributesByAttributeValuesResponse = z.o
|
|
|
14341
15135
|
"DKK",
|
|
14342
15136
|
"EUR",
|
|
14343
15137
|
"HKD",
|
|
15138
|
+
"HUF",
|
|
14344
15139
|
"ISK",
|
|
14345
15140
|
"INR",
|
|
14346
15141
|
"ILS",
|
|
@@ -17633,732 +18428,338 @@ const getV2MeetingsByMeetingId = (options) => (options.client ?? client).get({
|
|
|
17633
18428
|
* This endpoint is in beta. We will aim to avoid breaking changes, but small updates may be made as we roll out to more users.
|
|
17634
18429
|
*
|
|
17635
18430
|
* Required scopes: `meeting:read`, `call_recording:read`.
|
|
17636
|
-
*/
|
|
17637
|
-
const getV2MeetingsByMeetingIdCallRecordings = (options) => (options.client ?? client).get({
|
|
17638
|
-
requestValidator: async (data) => await zGetV2MeetingsByMeetingIdCallRecordingsData.parseAsync(data),
|
|
17639
|
-
responseValidator: async (data) => await zGetV2MeetingsByMeetingIdCallRecordingsResponse.parseAsync(data),
|
|
17640
|
-
security: [{
|
|
17641
|
-
scheme: "bearer",
|
|
17642
|
-
type: "http"
|
|
17643
|
-
}],
|
|
17644
|
-
url: "/v2/meetings/{meeting_id}/call_recordings",
|
|
17645
|
-
...options
|
|
17646
|
-
});
|
|
17647
|
-
/**
|
|
17648
|
-
* Create call recording
|
|
17649
|
-
*
|
|
17650
|
-
* Create a call recording for a meeting. This endpoint is rate limited to 1 request per second.
|
|
17651
|
-
*
|
|
17652
|
-
* This endpoint is in alpha and may be subject to breaking changes as we gather feedback.
|
|
17653
|
-
*
|
|
17654
|
-
* Required scopes: `meeting:read`, `call_recording:read-write`.
|
|
17655
|
-
*/
|
|
17656
|
-
const postV2MeetingsByMeetingIdCallRecordings = (options) => (options.client ?? client).post({
|
|
17657
|
-
requestValidator: async (data) => await zPostV2MeetingsByMeetingIdCallRecordingsData.parseAsync(data),
|
|
17658
|
-
responseValidator: async (data) => await zPostV2MeetingsByMeetingIdCallRecordingsResponse.parseAsync(data),
|
|
17659
|
-
security: [{
|
|
17660
|
-
scheme: "bearer",
|
|
17661
|
-
type: "http"
|
|
17662
|
-
}],
|
|
17663
|
-
url: "/v2/meetings/{meeting_id}/call_recordings",
|
|
17664
|
-
...options,
|
|
17665
|
-
headers: {
|
|
17666
|
-
"Content-Type": "application/json",
|
|
17667
|
-
...options.headers
|
|
17668
|
-
}
|
|
17669
|
-
});
|
|
17670
|
-
/**
|
|
17671
|
-
* Delete call recording
|
|
17672
|
-
*
|
|
17673
|
-
* Deletes the specified call recording. This will remove the call recording and all associated data.
|
|
17674
|
-
*
|
|
17675
|
-
* This endpoint is in alpha and may be subject to breaking changes as we gather feedback.
|
|
17676
|
-
*
|
|
17677
|
-
* Required scopes: `meeting:read`, `call_recording:read-write`.
|
|
17678
|
-
*/
|
|
17679
|
-
const deleteV2MeetingsByMeetingIdCallRecordingsByCallRecordingId = (options) => (options.client ?? client).delete({
|
|
17680
|
-
requestValidator: async (data) => await zDeleteV2MeetingsByMeetingIdCallRecordingsByCallRecordingIdData.parseAsync(data),
|
|
17681
|
-
responseValidator: async (data) => await zDeleteV2MeetingsByMeetingIdCallRecordingsByCallRecordingIdResponse.parseAsync(data),
|
|
17682
|
-
security: [{
|
|
17683
|
-
scheme: "bearer",
|
|
17684
|
-
type: "http"
|
|
17685
|
-
}],
|
|
17686
|
-
url: "/v2/meetings/{meeting_id}/call_recordings/{call_recording_id}",
|
|
17687
|
-
...options
|
|
17688
|
-
});
|
|
17689
|
-
/**
|
|
17690
|
-
* Get call recording
|
|
17691
|
-
*
|
|
17692
|
-
* Get a single call recording by ID.
|
|
17693
|
-
*
|
|
17694
|
-
* This endpoint is in beta. We will aim to avoid breaking changes, but small updates may be made as we roll out to more users.
|
|
17695
|
-
*
|
|
17696
|
-
* Required scopes: `meeting:read`, `call_recording:read`.
|
|
17697
|
-
*/
|
|
17698
|
-
const getV2MeetingsByMeetingIdCallRecordingsByCallRecordingId = (options) => (options.client ?? client).get({
|
|
17699
|
-
requestValidator: async (data) => await zGetV2MeetingsByMeetingIdCallRecordingsByCallRecordingIdData.parseAsync(data),
|
|
17700
|
-
responseValidator: async (data) => await zGetV2MeetingsByMeetingIdCallRecordingsByCallRecordingIdResponse.parseAsync(data),
|
|
17701
|
-
security: [{
|
|
17702
|
-
scheme: "bearer",
|
|
17703
|
-
type: "http"
|
|
17704
|
-
}],
|
|
17705
|
-
url: "/v2/meetings/{meeting_id}/call_recordings/{call_recording_id}",
|
|
17706
|
-
...options
|
|
17707
|
-
});
|
|
17708
|
-
/**
|
|
17709
|
-
* Get call transcript
|
|
17710
|
-
*
|
|
17711
|
-
* Get the transcript for a call recording.
|
|
17712
|
-
*
|
|
17713
|
-
* This endpoint is in beta. We will aim to avoid breaking changes, but small updates may be made as we roll out to more users.
|
|
17714
|
-
*
|
|
17715
|
-
* Required scopes: `meeting:read`, `call_recording:read`.
|
|
17716
|
-
*/
|
|
17717
|
-
const getV2MeetingsByMeetingIdCallRecordingsByCallRecordingIdTranscript = (options) => (options.client ?? client).get({
|
|
17718
|
-
requestValidator: async (data) => await zGetV2MeetingsByMeetingIdCallRecordingsByCallRecordingIdTranscriptData.parseAsync(data),
|
|
17719
|
-
responseValidator: async (data) => await zGetV2MeetingsByMeetingIdCallRecordingsByCallRecordingIdTranscriptResponse.parseAsync(data),
|
|
17720
|
-
security: [{
|
|
17721
|
-
scheme: "bearer",
|
|
17722
|
-
type: "http"
|
|
17723
|
-
}],
|
|
17724
|
-
url: "/v2/meetings/{meeting_id}/call_recordings/{call_recording_id}/transcript",
|
|
17725
|
-
...options
|
|
17726
|
-
});
|
|
17727
|
-
/**
|
|
17728
|
-
* List webhooks
|
|
17729
|
-
*
|
|
17730
|
-
* Get all of the webhooks in your workspace.
|
|
17731
|
-
*
|
|
17732
|
-
* Required scopes: `webhook:read`.
|
|
17733
|
-
*/
|
|
17734
|
-
const getV2Webhooks = (options) => (options?.client ?? client).get({
|
|
17735
|
-
requestValidator: async (data) => await zGetV2WebhooksData.parseAsync(data),
|
|
17736
|
-
responseValidator: async (data) => await zGetV2WebhooksResponse.parseAsync(data),
|
|
17737
|
-
security: [{
|
|
17738
|
-
scheme: "bearer",
|
|
17739
|
-
type: "http"
|
|
17740
|
-
}],
|
|
17741
|
-
url: "/v2/webhooks",
|
|
17742
|
-
...options
|
|
17743
|
-
});
|
|
17744
|
-
/**
|
|
17745
|
-
* Create a webhook
|
|
17746
|
-
*
|
|
17747
|
-
* Create a webhook and associated subscriptions.
|
|
17748
|
-
*
|
|
17749
|
-
* Required scopes: `webhook:read-write`.
|
|
17750
|
-
*/
|
|
17751
|
-
const postV2Webhooks = (options) => (options.client ?? client).post({
|
|
17752
|
-
requestValidator: async (data) => await zPostV2WebhooksData.parseAsync(data),
|
|
17753
|
-
responseValidator: async (data) => await zPostV2WebhooksResponse.parseAsync(data),
|
|
17754
|
-
security: [{
|
|
17755
|
-
scheme: "bearer",
|
|
17756
|
-
type: "http"
|
|
17757
|
-
}],
|
|
17758
|
-
url: "/v2/webhooks",
|
|
17759
|
-
...options,
|
|
17760
|
-
headers: {
|
|
17761
|
-
"Content-Type": "application/json",
|
|
17762
|
-
...options.headers
|
|
17763
|
-
}
|
|
17764
|
-
});
|
|
17765
|
-
/**
|
|
17766
|
-
* Delete a webhook
|
|
17767
|
-
*
|
|
17768
|
-
* Delete a webhook by ID.
|
|
17769
|
-
*
|
|
17770
|
-
* Required scopes: `webhook:read-write`.
|
|
17771
|
-
*/
|
|
17772
|
-
const deleteV2WebhooksByWebhookId = (options) => (options.client ?? client).delete({
|
|
17773
|
-
requestValidator: async (data) => await zDeleteV2WebhooksByWebhookIdData.parseAsync(data),
|
|
17774
|
-
responseValidator: async (data) => await zDeleteV2WebhooksByWebhookIdResponse.parseAsync(data),
|
|
17775
|
-
security: [{
|
|
17776
|
-
scheme: "bearer",
|
|
17777
|
-
type: "http"
|
|
17778
|
-
}],
|
|
17779
|
-
url: "/v2/webhooks/{webhook_id}",
|
|
17780
|
-
...options
|
|
17781
|
-
});
|
|
17782
|
-
/**
|
|
17783
|
-
* Get a webhook
|
|
17784
|
-
*
|
|
17785
|
-
* Get a single webhook.
|
|
17786
|
-
*
|
|
17787
|
-
* Required scopes: `webhook:read`.
|
|
17788
|
-
*/
|
|
17789
|
-
const getV2WebhooksByWebhookId = (options) => (options.client ?? client).get({
|
|
17790
|
-
requestValidator: async (data) => await zGetV2WebhooksByWebhookIdData.parseAsync(data),
|
|
17791
|
-
responseValidator: async (data) => await zGetV2WebhooksByWebhookIdResponse.parseAsync(data),
|
|
17792
|
-
security: [{
|
|
17793
|
-
scheme: "bearer",
|
|
17794
|
-
type: "http"
|
|
17795
|
-
}],
|
|
17796
|
-
url: "/v2/webhooks/{webhook_id}",
|
|
17797
|
-
...options
|
|
17798
|
-
});
|
|
17799
|
-
/**
|
|
17800
|
-
* Update a webhook
|
|
17801
|
-
*
|
|
17802
|
-
* Update a webhook and associated subscriptions.
|
|
17803
|
-
*
|
|
17804
|
-
* Required scopes: `webhook:read-write`.
|
|
17805
|
-
*/
|
|
17806
|
-
const patchV2WebhooksByWebhookId = (options) => (options.client ?? client).patch({
|
|
17807
|
-
requestValidator: async (data) => await zPatchV2WebhooksByWebhookIdData.parseAsync(data),
|
|
17808
|
-
responseValidator: async (data) => await zPatchV2WebhooksByWebhookIdResponse.parseAsync(data),
|
|
17809
|
-
security: [{
|
|
17810
|
-
scheme: "bearer",
|
|
17811
|
-
type: "http"
|
|
17812
|
-
}],
|
|
17813
|
-
url: "/v2/webhooks/{webhook_id}",
|
|
17814
|
-
...options,
|
|
17815
|
-
headers: {
|
|
17816
|
-
"Content-Type": "application/json",
|
|
17817
|
-
...options.headers
|
|
17818
|
-
}
|
|
17819
|
-
});
|
|
17820
|
-
/**
|
|
17821
|
-
* Identify
|
|
17822
|
-
*
|
|
17823
|
-
* Identify the current access token, the workspace it is linked to, and any permissions it has.
|
|
17824
|
-
*/
|
|
17825
|
-
const getV2Self = (options) => (options?.client ?? client).get({
|
|
17826
|
-
requestValidator: async (data) => await zGetV2SelfData.parseAsync(data),
|
|
17827
|
-
responseValidator: async (data) => await zGetV2SelfResponse.parseAsync(data),
|
|
18431
|
+
*/
|
|
18432
|
+
const getV2MeetingsByMeetingIdCallRecordings = (options) => (options.client ?? client).get({
|
|
18433
|
+
requestValidator: async (data) => await zGetV2MeetingsByMeetingIdCallRecordingsData.parseAsync(data),
|
|
18434
|
+
responseValidator: async (data) => await zGetV2MeetingsByMeetingIdCallRecordingsResponse.parseAsync(data),
|
|
17828
18435
|
security: [{
|
|
17829
18436
|
scheme: "bearer",
|
|
17830
18437
|
type: "http"
|
|
17831
18438
|
}],
|
|
17832
|
-
url: "/v2/
|
|
18439
|
+
url: "/v2/meetings/{meeting_id}/call_recordings",
|
|
17833
18440
|
...options
|
|
17834
18441
|
});
|
|
17835
|
-
|
|
17836
|
-
//#endregion
|
|
17837
|
-
//#region src/attio/batch.ts
|
|
17838
18442
|
/**
|
|
17839
|
-
*
|
|
18443
|
+
* Create call recording
|
|
18444
|
+
*
|
|
18445
|
+
* Create a call recording for a meeting. This endpoint is rate limited to 1 request per second.
|
|
18446
|
+
*
|
|
18447
|
+
* This endpoint is in alpha and may be subject to breaking changes as we gather feedback.
|
|
18448
|
+
*
|
|
18449
|
+
* Required scopes: `meeting:read`, `call_recording:read-write`.
|
|
17840
18450
|
*/
|
|
17841
|
-
const
|
|
17842
|
-
|
|
17843
|
-
|
|
17844
|
-
|
|
17845
|
-
|
|
17846
|
-
|
|
17847
|
-
|
|
17848
|
-
|
|
17849
|
-
|
|
17850
|
-
|
|
17851
|
-
|
|
17852
|
-
|
|
17853
|
-
if (index >= items.length && active === 0) {
|
|
17854
|
-
resolve(results);
|
|
17855
|
-
return;
|
|
17856
|
-
}
|
|
17857
|
-
while (active < concurrency && index < items.length) {
|
|
17858
|
-
const currentIndex = index;
|
|
17859
|
-
const item = items[currentIndex];
|
|
17860
|
-
index += 1;
|
|
17861
|
-
active += 1;
|
|
17862
|
-
item.run(abortController ? { signal: abortController.signal } : void 0).then((value) => {
|
|
17863
|
-
if (isCancelled()) return;
|
|
17864
|
-
results[currentIndex] = {
|
|
17865
|
-
status: "fulfilled",
|
|
17866
|
-
value,
|
|
17867
|
-
label: item.label
|
|
17868
|
-
};
|
|
17869
|
-
}).catch((reason) => {
|
|
17870
|
-
if (options.stopOnError) {
|
|
17871
|
-
if (!stopped) {
|
|
17872
|
-
stopped = true;
|
|
17873
|
-
if (abortController && !abortController.signal.aborted) abortController.abort();
|
|
17874
|
-
reject(reason);
|
|
17875
|
-
}
|
|
17876
|
-
return;
|
|
17877
|
-
}
|
|
17878
|
-
if (isCancelled()) return;
|
|
17879
|
-
results[currentIndex] = {
|
|
17880
|
-
status: "rejected",
|
|
17881
|
-
reason,
|
|
17882
|
-
label: item.label
|
|
17883
|
-
};
|
|
17884
|
-
}).finally(() => {
|
|
17885
|
-
active -= 1;
|
|
17886
|
-
if (isCancelled()) return;
|
|
17887
|
-
launchNext();
|
|
17888
|
-
});
|
|
17889
|
-
}
|
|
17890
|
-
};
|
|
17891
|
-
launchNext();
|
|
17892
|
-
});
|
|
17893
|
-
};
|
|
17894
|
-
|
|
17895
|
-
//#endregion
|
|
17896
|
-
//#region src/attio/cache.ts
|
|
17897
|
-
var TtlCache = class {
|
|
17898
|
-
ttlMs;
|
|
17899
|
-
maxEntries;
|
|
17900
|
-
store = /* @__PURE__ */ new Map();
|
|
17901
|
-
constructor(options) {
|
|
17902
|
-
this.ttlMs = options.ttlMs;
|
|
17903
|
-
this.maxEntries = options.maxEntries;
|
|
17904
|
-
}
|
|
17905
|
-
get(key) {
|
|
17906
|
-
const entry = this.store.get(key);
|
|
17907
|
-
if (!entry) return;
|
|
17908
|
-
if (Date.now() >= entry.expiresAt) {
|
|
17909
|
-
this.store.delete(key);
|
|
17910
|
-
return;
|
|
17911
|
-
}
|
|
17912
|
-
return entry.value;
|
|
17913
|
-
}
|
|
17914
|
-
set(key, value) {
|
|
17915
|
-
if (this.maxEntries && this.store.size >= this.maxEntries && !this.store.has(key)) {
|
|
17916
|
-
const oldestKey = this.store.keys().next().value;
|
|
17917
|
-
if (oldestKey !== void 0) this.store.delete(oldestKey);
|
|
17918
|
-
}
|
|
17919
|
-
this.store.set(key, {
|
|
17920
|
-
value,
|
|
17921
|
-
expiresAt: Date.now() + this.ttlMs
|
|
17922
|
-
});
|
|
17923
|
-
}
|
|
17924
|
-
delete(key) {
|
|
17925
|
-
this.store.delete(key);
|
|
17926
|
-
}
|
|
17927
|
-
clear() {
|
|
17928
|
-
this.store.clear();
|
|
17929
|
-
}
|
|
17930
|
-
};
|
|
17931
|
-
const createTtlCache = (options) => new TtlCache(options);
|
|
17932
|
-
const clientCache = /* @__PURE__ */ new Map();
|
|
17933
|
-
const getCachedClient = (key) => {
|
|
17934
|
-
return clientCache.get(key);
|
|
17935
|
-
};
|
|
17936
|
-
const setCachedClient = (key, client) => {
|
|
17937
|
-
clientCache.set(key, client);
|
|
17938
|
-
};
|
|
17939
|
-
const clearClientCache = () => {
|
|
17940
|
-
clientCache.clear();
|
|
17941
|
-
};
|
|
17942
|
-
const hashToken = (value) => {
|
|
17943
|
-
let hash = 5381;
|
|
17944
|
-
for (let i = 0; i < value.length; i += 1) hash = hash * 33 ^ value.charCodeAt(i);
|
|
17945
|
-
return (hash >>> 0).toString(36);
|
|
17946
|
-
};
|
|
17947
|
-
|
|
17948
|
-
//#endregion
|
|
17949
|
-
//#region src/attio/config.ts
|
|
17950
|
-
const DEFAULT_BASE_URL = "https://api.attio.com";
|
|
17951
|
-
const getEnvValue = (key) => {
|
|
17952
|
-
if (typeof process === "undefined") return void 0;
|
|
17953
|
-
return process.env?.[key];
|
|
17954
|
-
};
|
|
17955
|
-
const normalizeBaseUrl = (baseUrl) => {
|
|
17956
|
-
return baseUrl.replace(/\/+$/, "");
|
|
17957
|
-
};
|
|
17958
|
-
const resolveBaseUrl = (config) => {
|
|
17959
|
-
return normalizeBaseUrl(config?.baseUrl ?? getEnvValue("ATTIO_BASE_URL") ?? DEFAULT_BASE_URL);
|
|
17960
|
-
};
|
|
17961
|
-
const resolveAuthToken = (config) => {
|
|
17962
|
-
return config?.apiKey ?? config?.accessToken ?? config?.authToken ?? getEnvValue("ATTIO_API_KEY") ?? getEnvValue("ATTIO_ACCESS_TOKEN");
|
|
17963
|
-
};
|
|
17964
|
-
const validateAuthToken = (token) => {
|
|
17965
|
-
if (!token || typeof token !== "string") throw new Error("Missing Attio API key. Set ATTIO_API_KEY or pass apiKey.");
|
|
17966
|
-
if (/\s/.test(token)) throw new Error("Invalid Attio API key: contains whitespace.");
|
|
17967
|
-
if (token.length < 10) throw new Error("Invalid Attio API key: too short.");
|
|
17968
|
-
return token;
|
|
17969
|
-
};
|
|
17970
|
-
const resolveResponseStyle = (config) => config?.responseStyle ?? "fields";
|
|
17971
|
-
const resolveThrowOnError = (config) => config?.throwOnError ?? true;
|
|
17972
|
-
|
|
17973
|
-
//#endregion
|
|
17974
|
-
//#region src/attio/retry.ts
|
|
17975
|
-
const DEFAULT_RETRY_CONFIG = {
|
|
17976
|
-
maxRetries: 3,
|
|
17977
|
-
initialDelayMs: 500,
|
|
17978
|
-
maxDelayMs: 5e3,
|
|
17979
|
-
retryableStatusCodes: [
|
|
17980
|
-
408,
|
|
17981
|
-
429,
|
|
17982
|
-
500,
|
|
17983
|
-
502,
|
|
17984
|
-
503,
|
|
17985
|
-
504
|
|
17986
|
-
],
|
|
17987
|
-
respectRetryAfter: true
|
|
17988
|
-
};
|
|
17989
|
-
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
17990
|
-
const calculateRetryDelay = (attempt, config, retryAfterMs) => {
|
|
17991
|
-
if (config.respectRetryAfter && retryAfterMs && retryAfterMs > 0) return Math.min(retryAfterMs, config.maxDelayMs);
|
|
17992
|
-
const base = config.initialDelayMs * 2 ** attempt;
|
|
17993
|
-
const jitter = .75 + Math.random() * .5;
|
|
17994
|
-
return Math.min(base * jitter, config.maxDelayMs);
|
|
17995
|
-
};
|
|
17996
|
-
const isRetryableStatus = (status, config) => {
|
|
17997
|
-
if (status === void 0) return true;
|
|
17998
|
-
return config.retryableStatusCodes.includes(status);
|
|
17999
|
-
};
|
|
18000
|
-
const isRetryableError = (error, config) => {
|
|
18001
|
-
const typed = error;
|
|
18002
|
-
if (typed?.isNetworkError) return true;
|
|
18003
|
-
return isRetryableStatus(typed?.status, config);
|
|
18004
|
-
};
|
|
18005
|
-
const getRetryAfterMs = (error) => {
|
|
18006
|
-
const typed = error;
|
|
18007
|
-
if (typed?.retryAfterMs) return typed.retryAfterMs;
|
|
18008
|
-
};
|
|
18009
|
-
const callWithRetry = async (fn, config) => {
|
|
18010
|
-
const retryConfig = {
|
|
18011
|
-
...DEFAULT_RETRY_CONFIG,
|
|
18012
|
-
...config
|
|
18013
|
-
};
|
|
18014
|
-
let attempt = 0;
|
|
18015
|
-
while (attempt <= retryConfig.maxRetries) try {
|
|
18016
|
-
return await fn();
|
|
18017
|
-
} catch (error) {
|
|
18018
|
-
if (!isRetryableError(error, retryConfig) || attempt >= retryConfig.maxRetries) throw error;
|
|
18019
|
-
await sleep(calculateRetryDelay(attempt, retryConfig, getRetryAfterMs(error)));
|
|
18020
|
-
attempt += 1;
|
|
18021
|
-
}
|
|
18022
|
-
throw new Error("Retry attempts exhausted.");
|
|
18023
|
-
};
|
|
18024
|
-
|
|
18025
|
-
//#endregion
|
|
18026
|
-
//#region src/attio/error-enhancer.ts
|
|
18027
|
-
const knownFieldValues = /* @__PURE__ */ new Map();
|
|
18028
|
-
const getKnownFieldValues = (field) => knownFieldValues.get(field);
|
|
18029
|
-
const updateKnownFieldValues = (field, values) => {
|
|
18030
|
-
const unique = Array.from(new Set(values.map((value) => value.trim()))).filter(Boolean);
|
|
18031
|
-
if (unique.length > 0) knownFieldValues.set(field, unique);
|
|
18032
|
-
else knownFieldValues.delete(field);
|
|
18033
|
-
};
|
|
18034
|
-
const extractMismatchContext = (error) => {
|
|
18035
|
-
const data = error.data;
|
|
18036
|
-
const message = error.message;
|
|
18037
|
-
const path = (Array.isArray(data?.path) ? data?.path[0] : data?.path) ?? data?.field ?? data?.attribute ?? void 0;
|
|
18038
|
-
if (typeof message !== "string" || typeof path !== "string") return;
|
|
18039
|
-
const patterns = [
|
|
18040
|
-
/constraint:\s*([^,]+)/i,
|
|
18041
|
-
/option name\s+'([^']+)'/i,
|
|
18042
|
-
/option name\s+"([^"]+)"/i
|
|
18043
|
-
];
|
|
18044
|
-
let value;
|
|
18045
|
-
for (const pattern of patterns) {
|
|
18046
|
-
const match = message.match(pattern);
|
|
18047
|
-
if (match?.[1]) {
|
|
18048
|
-
value = match[1].trim();
|
|
18049
|
-
break;
|
|
18050
|
-
}
|
|
18051
|
-
}
|
|
18052
|
-
return {
|
|
18053
|
-
field: path,
|
|
18054
|
-
value
|
|
18055
|
-
};
|
|
18056
|
-
};
|
|
18057
|
-
const levenshtein = (a, b) => {
|
|
18058
|
-
const matrix = [];
|
|
18059
|
-
const aLen = a.length;
|
|
18060
|
-
const bLen = b.length;
|
|
18061
|
-
for (let i = 0; i <= bLen; i += 1) matrix[i] = [i];
|
|
18062
|
-
for (let j = 0; j <= aLen; j += 1) matrix[0][j] = j;
|
|
18063
|
-
for (let i = 1; i <= bLen; i += 1) for (let j = 1; j <= aLen; j += 1) if (b.charAt(i - 1) === a.charAt(j - 1)) matrix[i][j] = matrix[i - 1][j - 1];
|
|
18064
|
-
else matrix[i][j] = Math.min(matrix[i - 1][j - 1] + 1, matrix[i][j - 1] + 1, matrix[i - 1][j] + 1);
|
|
18065
|
-
return matrix[bLen][aLen];
|
|
18066
|
-
};
|
|
18067
|
-
const scoreCandidates = (value, candidates) => {
|
|
18068
|
-
const normalized = value.toLowerCase();
|
|
18069
|
-
return candidates.map((candidate) => ({
|
|
18070
|
-
candidate,
|
|
18071
|
-
score: levenshtein(normalized, candidate.toLowerCase())
|
|
18072
|
-
})).sort((a, b) => a.score - b.score).map((entry) => entry.candidate);
|
|
18073
|
-
};
|
|
18074
|
-
const enhanceAttioError = (error) => {
|
|
18075
|
-
if (!error?.isApiError) return error;
|
|
18076
|
-
const context = extractMismatchContext(error);
|
|
18077
|
-
if (!context?.field || !context?.value) return error;
|
|
18078
|
-
const candidates = knownFieldValues.get(context.field);
|
|
18079
|
-
if (!candidates?.length) return error;
|
|
18080
|
-
const matches = scoreCandidates(context.value, candidates).slice(0, 3);
|
|
18081
|
-
error.suggestions = {
|
|
18082
|
-
field: context.field,
|
|
18083
|
-
attempted: context.value,
|
|
18084
|
-
bestMatch: matches[0],
|
|
18085
|
-
matches
|
|
18086
|
-
};
|
|
18087
|
-
return error;
|
|
18088
|
-
};
|
|
18089
|
-
|
|
18090
|
-
//#endregion
|
|
18091
|
-
//#region src/attio/errors.ts
|
|
18092
|
-
var AttioError = class extends Error {
|
|
18093
|
-
status;
|
|
18094
|
-
code;
|
|
18095
|
-
type;
|
|
18096
|
-
requestId;
|
|
18097
|
-
data;
|
|
18098
|
-
response;
|
|
18099
|
-
request;
|
|
18100
|
-
retryAfterMs;
|
|
18101
|
-
isNetworkError;
|
|
18102
|
-
isApiError;
|
|
18103
|
-
suggestions;
|
|
18104
|
-
constructor(message, details = {}) {
|
|
18105
|
-
super(message);
|
|
18106
|
-
this.name = "AttioError";
|
|
18107
|
-
this.status = details.status;
|
|
18108
|
-
this.code = details.code;
|
|
18109
|
-
this.type = details.type;
|
|
18110
|
-
this.data = details.data;
|
|
18111
|
-
}
|
|
18112
|
-
};
|
|
18113
|
-
var AttioApiError = class extends AttioError {
|
|
18114
|
-
constructor(message, details = {}) {
|
|
18115
|
-
super(message, details);
|
|
18116
|
-
this.name = "AttioApiError";
|
|
18117
|
-
this.isApiError = true;
|
|
18118
|
-
}
|
|
18119
|
-
};
|
|
18120
|
-
var AttioNetworkError = class extends AttioError {
|
|
18121
|
-
constructor(message, details = {}) {
|
|
18122
|
-
super(message, details);
|
|
18123
|
-
this.name = "AttioNetworkError";
|
|
18124
|
-
this.isNetworkError = true;
|
|
18125
|
-
}
|
|
18126
|
-
};
|
|
18127
|
-
const getHeaderValue = (response, key) => {
|
|
18128
|
-
if (!response) return;
|
|
18129
|
-
return response.headers.get(key) ?? void 0;
|
|
18130
|
-
};
|
|
18131
|
-
const parseRetryAfter = (response) => {
|
|
18132
|
-
if (!response) return;
|
|
18133
|
-
const raw = response.headers.get("Retry-After");
|
|
18134
|
-
if (!raw) return;
|
|
18135
|
-
const seconds = Number(raw);
|
|
18136
|
-
if (Number.isFinite(seconds)) return Math.max(0, seconds * 1e3);
|
|
18137
|
-
const dateMs = Date.parse(raw);
|
|
18138
|
-
if (!Number.isNaN(dateMs)) return Math.max(0, dateMs - Date.now());
|
|
18139
|
-
};
|
|
18140
|
-
const extractMessage = (error, fallback) => {
|
|
18141
|
-
if (typeof error === "string") return error;
|
|
18142
|
-
if (error && typeof error === "object") {
|
|
18143
|
-
const maybe = error;
|
|
18144
|
-
if (typeof maybe.message === "string") return maybe.message;
|
|
18451
|
+
const postV2MeetingsByMeetingIdCallRecordings = (options) => (options.client ?? client).post({
|
|
18452
|
+
requestValidator: async (data) => await zPostV2MeetingsByMeetingIdCallRecordingsData.parseAsync(data),
|
|
18453
|
+
responseValidator: async (data) => await zPostV2MeetingsByMeetingIdCallRecordingsResponse.parseAsync(data),
|
|
18454
|
+
security: [{
|
|
18455
|
+
scheme: "bearer",
|
|
18456
|
+
type: "http"
|
|
18457
|
+
}],
|
|
18458
|
+
url: "/v2/meetings/{meeting_id}/call_recordings",
|
|
18459
|
+
...options,
|
|
18460
|
+
headers: {
|
|
18461
|
+
"Content-Type": "application/json",
|
|
18462
|
+
...options.headers
|
|
18145
18463
|
}
|
|
18146
|
-
|
|
18147
|
-
|
|
18148
|
-
|
|
18149
|
-
|
|
18150
|
-
|
|
18151
|
-
|
|
18152
|
-
|
|
18153
|
-
|
|
18154
|
-
|
|
18155
|
-
|
|
18156
|
-
|
|
18157
|
-
|
|
18158
|
-
|
|
18159
|
-
|
|
18160
|
-
|
|
18161
|
-
|
|
18162
|
-
|
|
18163
|
-
|
|
18164
|
-
|
|
18165
|
-
|
|
18166
|
-
|
|
18167
|
-
|
|
18168
|
-
|
|
18169
|
-
|
|
18170
|
-
|
|
18171
|
-
|
|
18172
|
-
|
|
18173
|
-
|
|
18174
|
-
|
|
18175
|
-
|
|
18464
|
+
});
|
|
18465
|
+
/**
|
|
18466
|
+
* Delete call recording
|
|
18467
|
+
*
|
|
18468
|
+
* Deletes the specified call recording. This will remove the call recording and all associated data.
|
|
18469
|
+
*
|
|
18470
|
+
* This endpoint is in alpha and may be subject to breaking changes as we gather feedback.
|
|
18471
|
+
*
|
|
18472
|
+
* Required scopes: `meeting:read`, `call_recording:read-write`.
|
|
18473
|
+
*/
|
|
18474
|
+
const deleteV2MeetingsByMeetingIdCallRecordingsByCallRecordingId = (options) => (options.client ?? client).delete({
|
|
18475
|
+
requestValidator: async (data) => await zDeleteV2MeetingsByMeetingIdCallRecordingsByCallRecordingIdData.parseAsync(data),
|
|
18476
|
+
responseValidator: async (data) => await zDeleteV2MeetingsByMeetingIdCallRecordingsByCallRecordingIdResponse.parseAsync(data),
|
|
18477
|
+
security: [{
|
|
18478
|
+
scheme: "bearer",
|
|
18479
|
+
type: "http"
|
|
18480
|
+
}],
|
|
18481
|
+
url: "/v2/meetings/{meeting_id}/call_recordings/{call_recording_id}",
|
|
18482
|
+
...options
|
|
18483
|
+
});
|
|
18484
|
+
/**
|
|
18485
|
+
* Get call recording
|
|
18486
|
+
*
|
|
18487
|
+
* Get a single call recording by ID.
|
|
18488
|
+
*
|
|
18489
|
+
* This endpoint is in beta. We will aim to avoid breaking changes, but small updates may be made as we roll out to more users.
|
|
18490
|
+
*
|
|
18491
|
+
* Required scopes: `meeting:read`, `call_recording:read`.
|
|
18492
|
+
*/
|
|
18493
|
+
const getV2MeetingsByMeetingIdCallRecordingsByCallRecordingId = (options) => (options.client ?? client).get({
|
|
18494
|
+
requestValidator: async (data) => await zGetV2MeetingsByMeetingIdCallRecordingsByCallRecordingIdData.parseAsync(data),
|
|
18495
|
+
responseValidator: async (data) => await zGetV2MeetingsByMeetingIdCallRecordingsByCallRecordingIdResponse.parseAsync(data),
|
|
18496
|
+
security: [{
|
|
18497
|
+
scheme: "bearer",
|
|
18498
|
+
type: "http"
|
|
18499
|
+
}],
|
|
18500
|
+
url: "/v2/meetings/{meeting_id}/call_recordings/{call_recording_id}",
|
|
18501
|
+
...options
|
|
18502
|
+
});
|
|
18503
|
+
/**
|
|
18504
|
+
* Get call transcript
|
|
18505
|
+
*
|
|
18506
|
+
* Get the transcript for a call recording.
|
|
18507
|
+
*
|
|
18508
|
+
* This endpoint is in beta. We will aim to avoid breaking changes, but small updates may be made as we roll out to more users.
|
|
18509
|
+
*
|
|
18510
|
+
* Required scopes: `meeting:read`, `call_recording:read`.
|
|
18511
|
+
*/
|
|
18512
|
+
const getV2MeetingsByMeetingIdCallRecordingsByCallRecordingIdTranscript = (options) => (options.client ?? client).get({
|
|
18513
|
+
requestValidator: async (data) => await zGetV2MeetingsByMeetingIdCallRecordingsByCallRecordingIdTranscriptData.parseAsync(data),
|
|
18514
|
+
responseValidator: async (data) => await zGetV2MeetingsByMeetingIdCallRecordingsByCallRecordingIdTranscriptResponse.parseAsync(data),
|
|
18515
|
+
security: [{
|
|
18516
|
+
scheme: "bearer",
|
|
18517
|
+
type: "http"
|
|
18518
|
+
}],
|
|
18519
|
+
url: "/v2/meetings/{meeting_id}/call_recordings/{call_recording_id}/transcript",
|
|
18520
|
+
...options
|
|
18521
|
+
});
|
|
18522
|
+
/**
|
|
18523
|
+
* List webhooks
|
|
18524
|
+
*
|
|
18525
|
+
* Get all of the webhooks in your workspace.
|
|
18526
|
+
*
|
|
18527
|
+
* Required scopes: `webhook:read`.
|
|
18528
|
+
*/
|
|
18529
|
+
const getV2Webhooks = (options) => (options?.client ?? client).get({
|
|
18530
|
+
requestValidator: async (data) => await zGetV2WebhooksData.parseAsync(data),
|
|
18531
|
+
responseValidator: async (data) => await zGetV2WebhooksResponse.parseAsync(data),
|
|
18532
|
+
security: [{
|
|
18533
|
+
scheme: "bearer",
|
|
18534
|
+
type: "http"
|
|
18535
|
+
}],
|
|
18536
|
+
url: "/v2/webhooks",
|
|
18537
|
+
...options
|
|
18538
|
+
});
|
|
18539
|
+
/**
|
|
18540
|
+
* Create a webhook
|
|
18541
|
+
*
|
|
18542
|
+
* Create a webhook and associated subscriptions.
|
|
18543
|
+
*
|
|
18544
|
+
* Required scopes: `webhook:read-write`.
|
|
18545
|
+
*/
|
|
18546
|
+
const postV2Webhooks = (options) => (options.client ?? client).post({
|
|
18547
|
+
requestValidator: async (data) => await zPostV2WebhooksData.parseAsync(data),
|
|
18548
|
+
responseValidator: async (data) => await zPostV2WebhooksResponse.parseAsync(data),
|
|
18549
|
+
security: [{
|
|
18550
|
+
scheme: "bearer",
|
|
18551
|
+
type: "http"
|
|
18552
|
+
}],
|
|
18553
|
+
url: "/v2/webhooks",
|
|
18554
|
+
...options,
|
|
18555
|
+
headers: {
|
|
18556
|
+
"Content-Type": "application/json",
|
|
18557
|
+
...options.headers
|
|
18176
18558
|
}
|
|
18177
|
-
|
|
18178
|
-
|
|
18179
|
-
|
|
18180
|
-
|
|
18181
|
-
|
|
18182
|
-
|
|
18183
|
-
|
|
18184
|
-
|
|
18185
|
-
|
|
18186
|
-
|
|
18187
|
-
|
|
18188
|
-
|
|
18189
|
-
|
|
18190
|
-
|
|
18191
|
-
|
|
18192
|
-
|
|
18193
|
-
|
|
18194
|
-
|
|
18195
|
-
|
|
18196
|
-
|
|
18197
|
-
|
|
18198
|
-
|
|
18199
|
-
|
|
18200
|
-
|
|
18201
|
-
|
|
18202
|
-
|
|
18203
|
-
|
|
18204
|
-
|
|
18205
|
-
|
|
18206
|
-
|
|
18207
|
-
|
|
18208
|
-
|
|
18209
|
-
|
|
18210
|
-
|
|
18211
|
-
|
|
18212
|
-
|
|
18213
|
-
|
|
18214
|
-
|
|
18215
|
-
|
|
18216
|
-
|
|
18217
|
-
|
|
18218
|
-
|
|
18219
|
-
|
|
18220
|
-
|
|
18221
|
-
|
|
18222
|
-
|
|
18223
|
-
|
|
18224
|
-
|
|
18225
|
-
|
|
18226
|
-
}
|
|
18227
|
-
|
|
18228
|
-
|
|
18229
|
-
|
|
18230
|
-
|
|
18231
|
-
return callWithRetry(() => base.request(rest), {
|
|
18232
|
-
...retry,
|
|
18233
|
-
...retryOverride
|
|
18234
|
-
});
|
|
18235
|
-
};
|
|
18236
|
-
const makeMethod = (method) => (options) => requestWithRetry({
|
|
18237
|
-
...options,
|
|
18238
|
-
method
|
|
18239
|
-
});
|
|
18240
|
-
return {
|
|
18241
|
-
...base,
|
|
18242
|
-
request: requestWithRetry,
|
|
18243
|
-
connect: makeMethod("CONNECT"),
|
|
18244
|
-
delete: makeMethod("DELETE"),
|
|
18245
|
-
get: makeMethod("GET"),
|
|
18246
|
-
head: makeMethod("HEAD"),
|
|
18247
|
-
options: makeMethod("OPTIONS"),
|
|
18248
|
-
patch: makeMethod("PATCH"),
|
|
18249
|
-
post: makeMethod("POST"),
|
|
18250
|
-
put: makeMethod("PUT"),
|
|
18251
|
-
trace: makeMethod("TRACE")
|
|
18252
|
-
};
|
|
18253
|
-
};
|
|
18254
|
-
const createAttioClientWithAuthToken = ({ config = {}, authToken }) => {
|
|
18255
|
-
const baseUrl = resolveBaseUrl(config);
|
|
18256
|
-
const responseStyle = resolveResponseStyle(config);
|
|
18257
|
-
const throwOnError = resolveThrowOnError(config);
|
|
18258
|
-
const headers = config.headers;
|
|
18259
|
-
const retry = config.retry;
|
|
18260
|
-
const timeoutMs = config.timeoutMs;
|
|
18261
|
-
const cleanConfig = { ...config };
|
|
18262
|
-
delete cleanConfig.apiKey;
|
|
18263
|
-
delete cleanConfig.accessToken;
|
|
18264
|
-
delete cleanConfig.authToken;
|
|
18265
|
-
delete cleanConfig.cache;
|
|
18266
|
-
delete cleanConfig.retry;
|
|
18267
|
-
delete cleanConfig.timeoutMs;
|
|
18268
|
-
delete cleanConfig.headers;
|
|
18269
|
-
const mergedHeaders = mergeHeaders({ Accept: "application/json" }, headers);
|
|
18270
|
-
const base = createClient({
|
|
18271
|
-
...cleanConfig,
|
|
18272
|
-
baseUrl,
|
|
18273
|
-
auth: authToken,
|
|
18274
|
-
headers: mergedHeaders,
|
|
18275
|
-
fetch: resolveFetch({
|
|
18276
|
-
...config,
|
|
18277
|
-
timeoutMs
|
|
18278
|
-
}),
|
|
18279
|
-
responseStyle,
|
|
18280
|
-
throwOnError
|
|
18281
|
-
});
|
|
18282
|
-
applyInterceptors(base);
|
|
18283
|
-
return wrapClient(base, retry);
|
|
18284
|
-
};
|
|
18285
|
-
const createAttioClient = (config = {}) => {
|
|
18286
|
-
return createAttioClientWithAuthToken({
|
|
18287
|
-
config,
|
|
18288
|
-
authToken: validateAuthToken(resolveAuthToken(config))
|
|
18289
|
-
});
|
|
18290
|
-
};
|
|
18291
|
-
const getAttioClient = (config = {}) => {
|
|
18292
|
-
const cacheEnabled = config.cache?.enabled ?? true;
|
|
18293
|
-
const authToken = validateAuthToken(resolveAuthToken(config));
|
|
18294
|
-
const cacheKey = buildClientCacheKey({
|
|
18295
|
-
config,
|
|
18296
|
-
authToken
|
|
18297
|
-
});
|
|
18298
|
-
if (cacheEnabled && cacheKey) {
|
|
18299
|
-
const cached = getCachedClient(cacheKey);
|
|
18300
|
-
if (cached) return cached;
|
|
18301
|
-
const client = createAttioClientWithAuthToken({
|
|
18302
|
-
config,
|
|
18303
|
-
authToken
|
|
18304
|
-
});
|
|
18305
|
-
setCachedClient(cacheKey, client);
|
|
18306
|
-
return client;
|
|
18559
|
+
});
|
|
18560
|
+
/**
|
|
18561
|
+
* Delete a webhook
|
|
18562
|
+
*
|
|
18563
|
+
* Delete a webhook by ID.
|
|
18564
|
+
*
|
|
18565
|
+
* Required scopes: `webhook:read-write`.
|
|
18566
|
+
*/
|
|
18567
|
+
const deleteV2WebhooksByWebhookId = (options) => (options.client ?? client).delete({
|
|
18568
|
+
requestValidator: async (data) => await zDeleteV2WebhooksByWebhookIdData.parseAsync(data),
|
|
18569
|
+
responseValidator: async (data) => await zDeleteV2WebhooksByWebhookIdResponse.parseAsync(data),
|
|
18570
|
+
security: [{
|
|
18571
|
+
scheme: "bearer",
|
|
18572
|
+
type: "http"
|
|
18573
|
+
}],
|
|
18574
|
+
url: "/v2/webhooks/{webhook_id}",
|
|
18575
|
+
...options
|
|
18576
|
+
});
|
|
18577
|
+
/**
|
|
18578
|
+
* Get a webhook
|
|
18579
|
+
*
|
|
18580
|
+
* Get a single webhook.
|
|
18581
|
+
*
|
|
18582
|
+
* Required scopes: `webhook:read`.
|
|
18583
|
+
*/
|
|
18584
|
+
const getV2WebhooksByWebhookId = (options) => (options.client ?? client).get({
|
|
18585
|
+
requestValidator: async (data) => await zGetV2WebhooksByWebhookIdData.parseAsync(data),
|
|
18586
|
+
responseValidator: async (data) => await zGetV2WebhooksByWebhookIdResponse.parseAsync(data),
|
|
18587
|
+
security: [{
|
|
18588
|
+
scheme: "bearer",
|
|
18589
|
+
type: "http"
|
|
18590
|
+
}],
|
|
18591
|
+
url: "/v2/webhooks/{webhook_id}",
|
|
18592
|
+
...options
|
|
18593
|
+
});
|
|
18594
|
+
/**
|
|
18595
|
+
* Update a webhook
|
|
18596
|
+
*
|
|
18597
|
+
* Update a webhook and associated subscriptions.
|
|
18598
|
+
*
|
|
18599
|
+
* Required scopes: `webhook:read-write`.
|
|
18600
|
+
*/
|
|
18601
|
+
const patchV2WebhooksByWebhookId = (options) => (options.client ?? client).patch({
|
|
18602
|
+
requestValidator: async (data) => await zPatchV2WebhooksByWebhookIdData.parseAsync(data),
|
|
18603
|
+
responseValidator: async (data) => await zPatchV2WebhooksByWebhookIdResponse.parseAsync(data),
|
|
18604
|
+
security: [{
|
|
18605
|
+
scheme: "bearer",
|
|
18606
|
+
type: "http"
|
|
18607
|
+
}],
|
|
18608
|
+
url: "/v2/webhooks/{webhook_id}",
|
|
18609
|
+
...options,
|
|
18610
|
+
headers: {
|
|
18611
|
+
"Content-Type": "application/json",
|
|
18612
|
+
...options.headers
|
|
18307
18613
|
}
|
|
18308
|
-
|
|
18309
|
-
|
|
18310
|
-
|
|
18311
|
-
|
|
18312
|
-
|
|
18313
|
-
|
|
18314
|
-
|
|
18315
|
-
|
|
18316
|
-
|
|
18317
|
-
|
|
18318
|
-
|
|
18319
|
-
|
|
18320
|
-
|
|
18321
|
-
|
|
18322
|
-
|
|
18323
|
-
|
|
18324
|
-
endsWith: (field, value) => operator(field, "$ends_with", value),
|
|
18325
|
-
notEmpty: (field) => operator(field, "$not_empty", true),
|
|
18326
|
-
and: (...conditions) => ({ $and: conditions }),
|
|
18327
|
-
or: (...conditions) => ({ $or: conditions }),
|
|
18328
|
-
not: (condition) => ({ $not: condition })
|
|
18329
|
-
};
|
|
18614
|
+
});
|
|
18615
|
+
/**
|
|
18616
|
+
* Identify
|
|
18617
|
+
*
|
|
18618
|
+
* Identify the current access token, the workspace it is linked to, and any permissions it has.
|
|
18619
|
+
*/
|
|
18620
|
+
const getV2Self = (options) => (options?.client ?? client).get({
|
|
18621
|
+
requestValidator: async (data) => await zGetV2SelfData.parseAsync(data),
|
|
18622
|
+
responseValidator: async (data) => await zGetV2SelfResponse.parseAsync(data),
|
|
18623
|
+
security: [{
|
|
18624
|
+
scheme: "bearer",
|
|
18625
|
+
type: "http"
|
|
18626
|
+
}],
|
|
18627
|
+
url: "/v2/self",
|
|
18628
|
+
...options
|
|
18629
|
+
});
|
|
18330
18630
|
|
|
18331
18631
|
//#endregion
|
|
18332
18632
|
//#region src/attio/response.ts
|
|
18333
|
-
const
|
|
18334
|
-
|
|
18335
|
-
|
|
18336
|
-
|
|
18337
|
-
|
|
18338
|
-
|
|
18339
|
-
|
|
18340
|
-
|
|
18341
|
-
|
|
18633
|
+
const DEFAULT_UNWRAP_DEPTH = 3;
|
|
18634
|
+
const responseEnvelopeSchema = z.object({
|
|
18635
|
+
data: z.unknown().optional(),
|
|
18636
|
+
error: z.unknown().optional(),
|
|
18637
|
+
request: z.instanceof(Request).optional(),
|
|
18638
|
+
response: z.instanceof(Response).optional()
|
|
18639
|
+
}).passthrough();
|
|
18640
|
+
function unwrapData(result, options = {}) {
|
|
18641
|
+
const maxDepth = options.maxDepth ?? DEFAULT_UNWRAP_DEPTH;
|
|
18642
|
+
let current = result;
|
|
18643
|
+
for (let depth = 0; depth < maxDepth; depth += 1) {
|
|
18644
|
+
if (!current || typeof current !== "object") break;
|
|
18645
|
+
if (!("data" in current)) break;
|
|
18646
|
+
current = current.data;
|
|
18647
|
+
}
|
|
18648
|
+
if (options.schema) {
|
|
18649
|
+
const parsed = options.schema.safeParse(current);
|
|
18650
|
+
if (!parsed.success) throw createSchemaError(parsed.error);
|
|
18651
|
+
return parsed.data;
|
|
18652
|
+
}
|
|
18653
|
+
return current;
|
|
18654
|
+
}
|
|
18655
|
+
/**
|
|
18656
|
+
* Searches nested data structures for an array, checking `data`, `items`,
|
|
18657
|
+
* and `records` keys at each level up to DEFAULT_UNWRAP_DEPTH.
|
|
18658
|
+
*/
|
|
18659
|
+
const findArrayInData = (initialData) => {
|
|
18660
|
+
let data = initialData;
|
|
18661
|
+
for (let depth = 0; depth < DEFAULT_UNWRAP_DEPTH; depth += 1) {
|
|
18662
|
+
if (Array.isArray(data)) return data;
|
|
18663
|
+
if (!data || typeof data !== "object") return;
|
|
18342
18664
|
const record = data;
|
|
18343
18665
|
const nested = record.data ?? record.items ?? record.records;
|
|
18344
|
-
if (
|
|
18666
|
+
if (nested === void 0) return;
|
|
18667
|
+
data = nested;
|
|
18345
18668
|
}
|
|
18346
|
-
|
|
18669
|
+
};
|
|
18670
|
+
const validateItemsArray = (items, schema) => {
|
|
18671
|
+
const parsed = z.array(schema).safeParse(items);
|
|
18672
|
+
if (!parsed.success) throw createSchemaError(parsed.error);
|
|
18673
|
+
return parsed.data;
|
|
18674
|
+
};
|
|
18675
|
+
function unwrapItems(result, options = {}) {
|
|
18676
|
+
const items = findArrayInData(unwrapData(result));
|
|
18677
|
+
if (!items) return [];
|
|
18678
|
+
if (options.schema) return validateItemsArray(items, options.schema);
|
|
18679
|
+
return items;
|
|
18680
|
+
}
|
|
18681
|
+
const readPaginationCursor = (pagination) => {
|
|
18682
|
+
if (!pagination || typeof pagination !== "object") return null;
|
|
18683
|
+
const cursor = pagination.next_cursor ?? pagination.nextCursor;
|
|
18684
|
+
return typeof cursor === "string" ? cursor : null;
|
|
18347
18685
|
};
|
|
18348
18686
|
const unwrapPaginationCursor = (result) => {
|
|
18349
|
-
const readCursor = (pagination) => {
|
|
18350
|
-
if (!pagination || typeof pagination !== "object") return null;
|
|
18351
|
-
const cursor = pagination.next_cursor ?? pagination.nextCursor;
|
|
18352
|
-
return typeof cursor === "string" ? cursor : null;
|
|
18353
|
-
};
|
|
18354
18687
|
if (result && typeof result === "object") {
|
|
18355
|
-
const rootCursor =
|
|
18688
|
+
const rootCursor = readPaginationCursor(result.pagination);
|
|
18356
18689
|
if (rootCursor) return rootCursor;
|
|
18357
18690
|
}
|
|
18358
18691
|
const data = unwrapData(result);
|
|
18359
18692
|
if (!data || typeof data !== "object") return null;
|
|
18360
|
-
return
|
|
18693
|
+
return readPaginationCursor(data.pagination);
|
|
18694
|
+
};
|
|
18695
|
+
const readPaginationOffset = (pagination) => {
|
|
18696
|
+
if (!pagination || typeof pagination !== "object") return null;
|
|
18697
|
+
const record = pagination;
|
|
18698
|
+
const nextOffset = record.next_offset ?? record.nextOffset;
|
|
18699
|
+
return typeof nextOffset === "number" ? nextOffset : null;
|
|
18700
|
+
};
|
|
18701
|
+
const unwrapPaginationOffset = (result) => {
|
|
18702
|
+
if (result && typeof result === "object") {
|
|
18703
|
+
const rootOffset = readPaginationOffset(result.pagination);
|
|
18704
|
+
if (rootOffset !== null) return rootOffset;
|
|
18705
|
+
}
|
|
18706
|
+
const data = unwrapData(result);
|
|
18707
|
+
if (!data || typeof data !== "object") return null;
|
|
18708
|
+
return readPaginationOffset(data.pagination);
|
|
18361
18709
|
};
|
|
18710
|
+
const parseResponseEnvelope = (result) => {
|
|
18711
|
+
const parsed = responseEnvelopeSchema.safeParse(result);
|
|
18712
|
+
if (!parsed.success) return;
|
|
18713
|
+
return parsed.data;
|
|
18714
|
+
};
|
|
18715
|
+
const createSchemaError = (details) => new AttioResponseError("Invalid API response: schema mismatch", {
|
|
18716
|
+
code: "INVALID_RESPONSE",
|
|
18717
|
+
data: details
|
|
18718
|
+
});
|
|
18719
|
+
function assertOk(result, options) {
|
|
18720
|
+
const envelope = parseResponseEnvelope(result);
|
|
18721
|
+
if (envelope?.error !== void 0) throw normalizeAttioError(envelope.error, {
|
|
18722
|
+
response: envelope.response,
|
|
18723
|
+
request: envelope.request
|
|
18724
|
+
});
|
|
18725
|
+
const unwrapped = unwrapData(envelope?.data ?? result, { maxDepth: options?.maxDepth });
|
|
18726
|
+
if (!options?.schema) return unwrapped;
|
|
18727
|
+
const parsed = options.schema.safeParse(unwrapped);
|
|
18728
|
+
if (!parsed.success) throw createSchemaError(parsed.error);
|
|
18729
|
+
return parsed.data;
|
|
18730
|
+
}
|
|
18731
|
+
function toResult(result, options) {
|
|
18732
|
+
const envelope = parseResponseEnvelope(result);
|
|
18733
|
+
if (envelope?.error !== void 0) return {
|
|
18734
|
+
ok: false,
|
|
18735
|
+
error: normalizeAttioError(envelope.error, {
|
|
18736
|
+
response: envelope.response,
|
|
18737
|
+
request: envelope.request
|
|
18738
|
+
}),
|
|
18739
|
+
request: envelope.request,
|
|
18740
|
+
response: envelope.response
|
|
18741
|
+
};
|
|
18742
|
+
const unwrapped = unwrapData(envelope?.data ?? result, { maxDepth: options?.maxDepth });
|
|
18743
|
+
if (!options?.schema) return {
|
|
18744
|
+
ok: true,
|
|
18745
|
+
value: unwrapped,
|
|
18746
|
+
request: envelope?.request,
|
|
18747
|
+
response: envelope?.response
|
|
18748
|
+
};
|
|
18749
|
+
const parsed = options.schema.safeParse(unwrapped);
|
|
18750
|
+
if (!parsed.success) return {
|
|
18751
|
+
ok: false,
|
|
18752
|
+
error: createSchemaError(parsed.error),
|
|
18753
|
+
request: envelope?.request,
|
|
18754
|
+
response: envelope?.response
|
|
18755
|
+
};
|
|
18756
|
+
return {
|
|
18757
|
+
ok: true,
|
|
18758
|
+
value: parsed.data,
|
|
18759
|
+
request: envelope?.request,
|
|
18760
|
+
response: envelope?.response
|
|
18761
|
+
};
|
|
18762
|
+
}
|
|
18362
18763
|
|
|
18363
18764
|
//#endregion
|
|
18364
18765
|
//#region src/attio/lists.ts
|
|
@@ -18368,7 +18769,8 @@ const listLists = async (input = {}) => {
|
|
|
18368
18769
|
const getList = async (input) => {
|
|
18369
18770
|
return unwrapData(await getV2ListsByList({
|
|
18370
18771
|
client: resolveAttioClient(input),
|
|
18371
|
-
path: { list: input.list }
|
|
18772
|
+
path: { list: input.list },
|
|
18773
|
+
...input.options
|
|
18372
18774
|
}));
|
|
18373
18775
|
};
|
|
18374
18776
|
const queryListEntries = async (input) => {
|
|
@@ -18388,6 +18790,7 @@ const addListEntry = async (input) => {
|
|
|
18388
18790
|
client: resolveAttioClient(input),
|
|
18389
18791
|
path: { list: input.list },
|
|
18390
18792
|
body: { data: {
|
|
18793
|
+
parent_object: input.parentObject,
|
|
18391
18794
|
parent_record_id: input.parentRecordId,
|
|
18392
18795
|
entry_values: input.entryValues ?? {}
|
|
18393
18796
|
} },
|
|
@@ -18420,19 +18823,7 @@ const removeListEntry = async (input) => {
|
|
|
18420
18823
|
|
|
18421
18824
|
//#endregion
|
|
18422
18825
|
//#region src/attio/metadata.ts
|
|
18423
|
-
const
|
|
18424
|
-
const attributesCache = createTtlCache({
|
|
18425
|
-
ttlMs: DEFAULT_TTL_MS,
|
|
18426
|
-
maxEntries: 200
|
|
18427
|
-
});
|
|
18428
|
-
const optionsCache = createTtlCache({
|
|
18429
|
-
ttlMs: DEFAULT_TTL_MS,
|
|
18430
|
-
maxEntries: 500
|
|
18431
|
-
});
|
|
18432
|
-
const statusesCache = createTtlCache({
|
|
18433
|
-
ttlMs: DEFAULT_TTL_MS,
|
|
18434
|
-
maxEntries: 500
|
|
18435
|
-
});
|
|
18826
|
+
const getMetadataCache = (client, scope) => client.cache.metadata.get(scope);
|
|
18436
18827
|
const buildKey = (target, identifier, attribute) => [
|
|
18437
18828
|
target,
|
|
18438
18829
|
identifier,
|
|
@@ -18444,41 +18835,56 @@ const extractTitles = (items) => items.reduce((titles, item) => {
|
|
|
18444
18835
|
if (parsed.success) titles.push(parsed.data.title);
|
|
18445
18836
|
return titles;
|
|
18446
18837
|
}, []);
|
|
18447
|
-
|
|
18448
|
-
|
|
18449
|
-
|
|
18450
|
-
|
|
18451
|
-
|
|
18452
|
-
|
|
18453
|
-
|
|
18454
|
-
|
|
18455
|
-
|
|
18838
|
+
const buildAttributeMetadataPath = (input) => ({
|
|
18839
|
+
target: input.target,
|
|
18840
|
+
identifier: input.identifier,
|
|
18841
|
+
attribute: input.attribute
|
|
18842
|
+
});
|
|
18843
|
+
const listAttributeMetadata = async ({ input, cache, fetcher, itemSchema }) => {
|
|
18844
|
+
const cacheKey = buildKey(input.target, input.identifier, input.attribute);
|
|
18845
|
+
const arraySchema = z.array(itemSchema);
|
|
18846
|
+
if (cache) {
|
|
18456
18847
|
const cached = cache.get(cacheKey);
|
|
18457
|
-
if (cached)
|
|
18458
|
-
|
|
18459
|
-
|
|
18460
|
-
|
|
18461
|
-
|
|
18462
|
-
|
|
18463
|
-
|
|
18464
|
-
|
|
18465
|
-
|
|
18466
|
-
|
|
18467
|
-
|
|
18468
|
-
|
|
18848
|
+
if (cached) {
|
|
18849
|
+
const parsed = arraySchema.safeParse(cached);
|
|
18850
|
+
if (parsed.success) return parsed.data;
|
|
18851
|
+
cache.delete(cacheKey);
|
|
18852
|
+
}
|
|
18853
|
+
}
|
|
18854
|
+
const client = resolveAttioClient(input);
|
|
18855
|
+
const options = input.options ?? {};
|
|
18856
|
+
const items = unwrapItems(await fetcher({
|
|
18857
|
+
client,
|
|
18858
|
+
path: buildAttributeMetadataPath(input),
|
|
18859
|
+
...options
|
|
18860
|
+
}), { schema: itemSchema });
|
|
18861
|
+
const titles = extractTitles(items);
|
|
18862
|
+
updateKnownFieldValues(input.attribute, titles);
|
|
18863
|
+
cache?.set(cacheKey, items);
|
|
18864
|
+
return items;
|
|
18865
|
+
};
|
|
18469
18866
|
const listAttributes = async (input) => {
|
|
18867
|
+
const client = resolveAttioClient(input);
|
|
18868
|
+
const cache = getMetadataCache(client, "attributes");
|
|
18470
18869
|
const cacheKey = buildKey(input.target, input.identifier);
|
|
18471
|
-
const
|
|
18472
|
-
if (
|
|
18870
|
+
const arraySchema = z.array(zAttribute);
|
|
18871
|
+
if (cache) {
|
|
18872
|
+
const cached = cache.get(cacheKey);
|
|
18873
|
+
if (cached) {
|
|
18874
|
+
const parsed = arraySchema.safeParse(cached);
|
|
18875
|
+
if (!parsed.success) throw createSchemaError(parsed.error);
|
|
18876
|
+
return parsed.data;
|
|
18877
|
+
}
|
|
18878
|
+
}
|
|
18473
18879
|
const items = unwrapItems(await getV2ByTargetByIdentifierAttributes({
|
|
18474
|
-
client
|
|
18880
|
+
client,
|
|
18475
18881
|
path: {
|
|
18476
18882
|
target: input.target,
|
|
18477
18883
|
identifier: input.identifier
|
|
18478
18884
|
},
|
|
18479
18885
|
...input.options
|
|
18480
|
-
}));
|
|
18481
|
-
|
|
18886
|
+
}), { schema: zAttribute });
|
|
18887
|
+
cache?.set(cacheKey, items);
|
|
18482
18888
|
return items;
|
|
18483
18889
|
};
|
|
18484
18890
|
const getAttribute = async (input) => {
|
|
@@ -18490,20 +18896,30 @@ const getAttribute = async (input) => {
|
|
|
18490
18896
|
attribute: input.attribute
|
|
18491
18897
|
},
|
|
18492
18898
|
...input.options
|
|
18493
|
-
}));
|
|
18899
|
+
}), { schema: zAttribute });
|
|
18494
18900
|
};
|
|
18495
|
-
const getAttributeOptions =
|
|
18496
|
-
|
|
18497
|
-
|
|
18498
|
-
|
|
18499
|
-
|
|
18901
|
+
const getAttributeOptions = (input) => {
|
|
18902
|
+
const client = resolveAttioClient(input);
|
|
18903
|
+
return listAttributeMetadata({
|
|
18904
|
+
input: {
|
|
18905
|
+
...input,
|
|
18906
|
+
client
|
|
18907
|
+
},
|
|
18908
|
+
cache: getMetadataCache(client, "options"),
|
|
18909
|
+
fetcher: getV2ByTargetByIdentifierAttributesByAttributeOptions,
|
|
18910
|
+
itemSchema: zSelectOption
|
|
18500
18911
|
});
|
|
18501
18912
|
};
|
|
18502
|
-
const getAttributeStatuses =
|
|
18503
|
-
|
|
18504
|
-
|
|
18505
|
-
|
|
18506
|
-
|
|
18913
|
+
const getAttributeStatuses = (input) => {
|
|
18914
|
+
const client = resolveAttioClient(input);
|
|
18915
|
+
return listAttributeMetadata({
|
|
18916
|
+
input: {
|
|
18917
|
+
...input,
|
|
18918
|
+
client
|
|
18919
|
+
},
|
|
18920
|
+
cache: getMetadataCache(client, "statuses"),
|
|
18921
|
+
fetcher: getV2ByTargetByIdentifierAttributesByAttributeStatuses,
|
|
18922
|
+
itemSchema: zStatus
|
|
18507
18923
|
});
|
|
18508
18924
|
};
|
|
18509
18925
|
|
|
@@ -18515,7 +18931,8 @@ const listNotes = async (input = {}) => {
|
|
|
18515
18931
|
const getNote = async (input) => {
|
|
18516
18932
|
return unwrapData(await getV2NotesByNoteId({
|
|
18517
18933
|
client: resolveAttioClient(input),
|
|
18518
|
-
path: { note_id: input.noteId }
|
|
18934
|
+
path: { note_id: input.noteId },
|
|
18935
|
+
...input.options
|
|
18519
18936
|
}));
|
|
18520
18937
|
};
|
|
18521
18938
|
const createNote = async (input) => {
|
|
@@ -18525,7 +18942,10 @@ const createNote = async (input) => {
|
|
|
18525
18942
|
parent_object: input.parentObject,
|
|
18526
18943
|
parent_record_id: input.parentRecordId,
|
|
18527
18944
|
title: input.title,
|
|
18528
|
-
|
|
18945
|
+
format: input.format,
|
|
18946
|
+
content: input.content,
|
|
18947
|
+
created_at: input.createdAt,
|
|
18948
|
+
meeting_id: input.meetingId
|
|
18529
18949
|
} },
|
|
18530
18950
|
...input.options
|
|
18531
18951
|
}));
|
|
@@ -18533,19 +18953,104 @@ const createNote = async (input) => {
|
|
|
18533
18953
|
const deleteNote = async (input) => {
|
|
18534
18954
|
await deleteV2NotesByNoteId({
|
|
18535
18955
|
client: resolveAttioClient(input),
|
|
18536
|
-
path: { note_id: input.noteId }
|
|
18956
|
+
path: { note_id: input.noteId },
|
|
18957
|
+
...input.options
|
|
18537
18958
|
});
|
|
18538
18959
|
return true;
|
|
18539
18960
|
};
|
|
18540
18961
|
|
|
18962
|
+
//#endregion
|
|
18963
|
+
//#region src/attio/objects.ts
|
|
18964
|
+
const AttioObjectSchema = z.object({
|
|
18965
|
+
id: z.object({
|
|
18966
|
+
workspace_id: z.string(),
|
|
18967
|
+
object_id: z.string()
|
|
18968
|
+
}),
|
|
18969
|
+
api_slug: z.string(),
|
|
18970
|
+
singular_noun: z.string(),
|
|
18971
|
+
plural_noun: z.string(),
|
|
18972
|
+
created_at: z.string()
|
|
18973
|
+
}).passthrough();
|
|
18974
|
+
const listObjects = async (input = {}) => {
|
|
18975
|
+
return unwrapItems(await getV2Objects({
|
|
18976
|
+
client: resolveAttioClient(input),
|
|
18977
|
+
...input.options
|
|
18978
|
+
}), { schema: AttioObjectSchema });
|
|
18979
|
+
};
|
|
18980
|
+
const getObject = async (input) => {
|
|
18981
|
+
return unwrapData(await getV2ObjectsByObject({
|
|
18982
|
+
client: resolveAttioClient(input),
|
|
18983
|
+
path: { object: input.object },
|
|
18984
|
+
...input.options
|
|
18985
|
+
}), { schema: AttioObjectSchema });
|
|
18986
|
+
};
|
|
18987
|
+
const createObject = async (input) => {
|
|
18988
|
+
return unwrapData(await postV2Objects({
|
|
18989
|
+
client: resolveAttioClient(input),
|
|
18990
|
+
body: { data: {
|
|
18991
|
+
api_slug: input.apiSlug,
|
|
18992
|
+
singular_noun: input.singularNoun,
|
|
18993
|
+
plural_noun: input.pluralNoun
|
|
18994
|
+
} },
|
|
18995
|
+
...input.options
|
|
18996
|
+
}), { schema: AttioObjectSchema });
|
|
18997
|
+
};
|
|
18998
|
+
const buildUpdateObjectData = (input) => ({
|
|
18999
|
+
...input.apiSlug !== void 0 && { api_slug: input.apiSlug },
|
|
19000
|
+
...input.singularNoun !== void 0 && { singular_noun: input.singularNoun },
|
|
19001
|
+
...input.pluralNoun !== void 0 && { plural_noun: input.pluralNoun }
|
|
19002
|
+
});
|
|
19003
|
+
const updateObject = async (input) => {
|
|
19004
|
+
return unwrapData(await patchV2ObjectsByObject({
|
|
19005
|
+
client: resolveAttioClient(input),
|
|
19006
|
+
path: { object: input.object },
|
|
19007
|
+
body: { data: buildUpdateObjectData(input) },
|
|
19008
|
+
...input.options
|
|
19009
|
+
}), { schema: AttioObjectSchema });
|
|
19010
|
+
};
|
|
19011
|
+
|
|
18541
19012
|
//#endregion
|
|
18542
19013
|
//#region src/attio/pagination.ts
|
|
19014
|
+
const createPageResultSchema = (itemSchema) => z.object({
|
|
19015
|
+
items: z.array(itemSchema),
|
|
19016
|
+
nextCursor: z.string().nullish()
|
|
19017
|
+
});
|
|
19018
|
+
const basePageResultSchema = z.object({
|
|
19019
|
+
items: z.array(z.unknown()),
|
|
19020
|
+
nextCursor: z.string().nullish()
|
|
19021
|
+
});
|
|
19022
|
+
const createOffsetPageResultSchema = (itemSchema) => z.object({
|
|
19023
|
+
items: z.array(itemSchema),
|
|
19024
|
+
nextOffset: z.number().nullish(),
|
|
19025
|
+
total: z.number().optional()
|
|
19026
|
+
});
|
|
19027
|
+
const baseOffsetPageResultSchema = z.object({
|
|
19028
|
+
items: z.array(z.unknown()),
|
|
19029
|
+
nextOffset: z.number().nullish(),
|
|
19030
|
+
total: z.number().optional()
|
|
19031
|
+
});
|
|
18543
19032
|
const toPageResult = (result) => {
|
|
18544
19033
|
return {
|
|
18545
19034
|
items: unwrapItems(result),
|
|
18546
19035
|
nextCursor: unwrapPaginationCursor(result)
|
|
18547
19036
|
};
|
|
18548
19037
|
};
|
|
19038
|
+
const toOffsetPageResult = (result) => {
|
|
19039
|
+
return {
|
|
19040
|
+
items: unwrapItems(result),
|
|
19041
|
+
nextOffset: unwrapPaginationOffset(result)
|
|
19042
|
+
};
|
|
19043
|
+
};
|
|
19044
|
+
const parsePageResult = (page, itemSchema) => {
|
|
19045
|
+
const result = (itemSchema ? createPageResultSchema(itemSchema) : basePageResultSchema).safeParse(page);
|
|
19046
|
+
if (!result.success) return;
|
|
19047
|
+
return result.data;
|
|
19048
|
+
};
|
|
19049
|
+
const parseOffsetPageResult = (page, itemSchema) => {
|
|
19050
|
+
const result = (itemSchema ? createOffsetPageResultSchema(itemSchema) : baseOffsetPageResultSchema).safeParse(page);
|
|
19051
|
+
if (!result.success) return;
|
|
19052
|
+
return result.data;
|
|
19053
|
+
};
|
|
18549
19054
|
const paginate = async (fetchPage, options = {}) => {
|
|
18550
19055
|
const items = [];
|
|
18551
19056
|
let cursor = options.cursor ?? null;
|
|
@@ -18554,7 +19059,7 @@ const paginate = async (fetchPage, options = {}) => {
|
|
|
18554
19059
|
const maxItems = options.maxItems ?? Number.POSITIVE_INFINITY;
|
|
18555
19060
|
while (pages < maxPages && items.length < maxItems) {
|
|
18556
19061
|
const page = await fetchPage(cursor);
|
|
18557
|
-
const { items: pageItems, nextCursor } = page
|
|
19062
|
+
const { items: pageItems, nextCursor } = parsePageResult(page, options.itemSchema) ?? toPageResult(page);
|
|
18558
19063
|
items.push(...pageItems);
|
|
18559
19064
|
pages += 1;
|
|
18560
19065
|
if (!nextCursor) break;
|
|
@@ -18562,60 +19067,176 @@ const paginate = async (fetchPage, options = {}) => {
|
|
|
18562
19067
|
}
|
|
18563
19068
|
return items.slice(0, maxItems);
|
|
18564
19069
|
};
|
|
19070
|
+
const DEFAULT_OFFSET_PAGE_SIZE = 50;
|
|
19071
|
+
const resolveNextOffset = ({ nextOffset, pageItemsLength, limit, currentOffset }) => {
|
|
19072
|
+
if (typeof nextOffset === "number") return nextOffset;
|
|
19073
|
+
if (pageItemsLength < limit) return null;
|
|
19074
|
+
return currentOffset + limit;
|
|
19075
|
+
};
|
|
19076
|
+
const paginateOffset = async (fetchPage, options = {}) => {
|
|
19077
|
+
const items = [];
|
|
19078
|
+
const maxPages = options.maxPages ?? Number.POSITIVE_INFINITY;
|
|
19079
|
+
const maxItems = options.maxItems ?? Number.POSITIVE_INFINITY;
|
|
19080
|
+
const limit = Math.max(1, options.limit ?? options.pageSize ?? DEFAULT_OFFSET_PAGE_SIZE);
|
|
19081
|
+
let offset = Math.max(0, options.offset ?? 0);
|
|
19082
|
+
let pages = 0;
|
|
19083
|
+
while (pages < maxPages && items.length < maxItems) {
|
|
19084
|
+
const page = await fetchPage(offset, limit);
|
|
19085
|
+
const { items: pageItems, nextOffset } = parseOffsetPageResult(page, options.itemSchema) ?? toOffsetPageResult(page);
|
|
19086
|
+
items.push(...pageItems);
|
|
19087
|
+
pages += 1;
|
|
19088
|
+
if (items.length >= maxItems) break;
|
|
19089
|
+
const resolvedOffset = resolveNextOffset({
|
|
19090
|
+
nextOffset,
|
|
19091
|
+
pageItemsLength: pageItems.length,
|
|
19092
|
+
limit,
|
|
19093
|
+
currentOffset: offset
|
|
19094
|
+
});
|
|
19095
|
+
if (resolvedOffset === null || resolvedOffset <= offset) break;
|
|
19096
|
+
offset = resolvedOffset;
|
|
19097
|
+
}
|
|
19098
|
+
return items.slice(0, maxItems);
|
|
19099
|
+
};
|
|
18565
19100
|
|
|
18566
19101
|
//#endregion
|
|
18567
19102
|
//#region src/attio/record-utils.ts
|
|
18568
|
-
const
|
|
18569
|
-
|
|
18570
|
-
|
|
18571
|
-
|
|
18572
|
-
|
|
19103
|
+
const attioRecordIdSchema = z.string().brand();
|
|
19104
|
+
const defaultNormalizeRecordOptions = { emptyBehavior: "reject" };
|
|
19105
|
+
const emptyObjectIssueCode = "EMPTY_OBJECT";
|
|
19106
|
+
const unknownObjectSchema = z.object({}).passthrough();
|
|
19107
|
+
const nonEmptyObjectSchema = unknownObjectSchema.superRefine((value, ctx) => {
|
|
19108
|
+
if (Object.keys(value).length === 0) ctx.addIssue({
|
|
19109
|
+
code: z.ZodIssueCode.custom,
|
|
19110
|
+
message: "Expected non-empty object",
|
|
19111
|
+
params: { code: emptyObjectIssueCode }
|
|
19112
|
+
});
|
|
19113
|
+
});
|
|
19114
|
+
const recordIdFieldsSchema = z.object({
|
|
19115
|
+
record_id: attioRecordIdSchema.optional(),
|
|
19116
|
+
company_id: attioRecordIdSchema.optional(),
|
|
19117
|
+
person_id: attioRecordIdSchema.optional(),
|
|
19118
|
+
list_id: attioRecordIdSchema.optional(),
|
|
19119
|
+
task_id: attioRecordIdSchema.optional()
|
|
19120
|
+
});
|
|
19121
|
+
const unknownArraySchema = z.array(z.unknown());
|
|
19122
|
+
const extractIdFromFields = (fields) => fields.record_id ?? fields.company_id ?? fields.person_id ?? fields.list_id ?? fields.task_id;
|
|
19123
|
+
function parseObject(value, options) {
|
|
19124
|
+
const parsed = ((options?.emptyBehavior ?? "allow") === "allow" ? unknownObjectSchema : nonEmptyObjectSchema).safeParse(value);
|
|
19125
|
+
if (parsed.success) return parsed.data;
|
|
19126
|
+
if (options) throw parsed.error;
|
|
19127
|
+
}
|
|
19128
|
+
const parseId = (value) => {
|
|
19129
|
+
const parsed = attioRecordIdSchema.safeParse(value);
|
|
19130
|
+
return parsed.success ? parsed.data : void 0;
|
|
18573
19131
|
};
|
|
18574
|
-
const
|
|
18575
|
-
|
|
18576
|
-
|
|
18577
|
-
|
|
18578
|
-
|
|
19132
|
+
const parseIdFields = (value) => {
|
|
19133
|
+
const parsed = recordIdFieldsSchema.safeParse(value);
|
|
19134
|
+
return parsed.success ? parsed.data : void 0;
|
|
19135
|
+
};
|
|
19136
|
+
const parseArray = (value) => {
|
|
19137
|
+
const parsed = unknownArraySchema.safeParse(value);
|
|
19138
|
+
return parsed.success ? parsed.data : void 0;
|
|
19139
|
+
};
|
|
19140
|
+
const extractIdFromRecord = (record) => {
|
|
19141
|
+
const idFields = parseIdFields(record.id);
|
|
19142
|
+
return (idFields ? extractIdFromFields(idFields) : void 0) ?? parseId(record.id) ?? parseId(record.record_id) ?? parseId(record.company_id) ?? parseId(record.person_id) ?? parseId(record.list_id) ?? parseId(record.task_id);
|
|
19143
|
+
};
|
|
19144
|
+
const extractValuesObject = (record) => parseObject(record.values);
|
|
19145
|
+
const extractIdFromUnknown = (value) => {
|
|
19146
|
+
const record = parseObject(value);
|
|
19147
|
+
if (!record) return;
|
|
19148
|
+
return extractIdFromRecord(record);
|
|
19149
|
+
};
|
|
19150
|
+
const extractValues$1 = (obj) => {
|
|
19151
|
+
const record = parseObject(obj);
|
|
19152
|
+
if (!record) return;
|
|
19153
|
+
return extractValuesObject(record);
|
|
19154
|
+
};
|
|
19155
|
+
const collectNestedCandidates = (record) => {
|
|
19156
|
+
const candidates = [];
|
|
19157
|
+
if (record.data !== void 0) candidates.push(record.data);
|
|
19158
|
+
const dataRecord = parseObject(record.data);
|
|
19159
|
+
if (!dataRecord) return candidates;
|
|
19160
|
+
if (dataRecord.data !== void 0) candidates.push(dataRecord.data);
|
|
19161
|
+
if (dataRecord.record !== void 0) candidates.push(dataRecord.record);
|
|
19162
|
+
const items = parseArray(dataRecord.items);
|
|
19163
|
+
if (items && items.length > 0) candidates.push(items[0]);
|
|
19164
|
+
return candidates;
|
|
19165
|
+
};
|
|
19166
|
+
const findFirstId = (candidates) => {
|
|
19167
|
+
for (const candidate of candidates) {
|
|
19168
|
+
const nested = extractIdFromUnknown(candidate);
|
|
19169
|
+
if (nested) return nested;
|
|
19170
|
+
}
|
|
18579
19171
|
};
|
|
18580
19172
|
const extractRecordId = (obj) => {
|
|
18581
|
-
|
|
18582
|
-
|
|
18583
|
-
|
|
19173
|
+
const record = parseObject(obj);
|
|
19174
|
+
if (!record) return;
|
|
19175
|
+
const direct = extractIdFromRecord(record);
|
|
19176
|
+
if (direct) return direct;
|
|
19177
|
+
return findFirstId(collectNestedCandidates(record));
|
|
19178
|
+
};
|
|
19179
|
+
const hasValidRecordId = (raw) => {
|
|
19180
|
+
const idFields = parseIdFields(raw.id);
|
|
19181
|
+
return Boolean(idFields?.record_id);
|
|
18584
19182
|
};
|
|
18585
|
-
const
|
|
18586
|
-
|
|
18587
|
-
|
|
18588
|
-
|
|
18589
|
-
|
|
18590
|
-
|
|
19183
|
+
const extractNestedValues = (result) => {
|
|
19184
|
+
const candidates = collectNestedCandidates(result);
|
|
19185
|
+
for (const candidate of candidates) {
|
|
19186
|
+
const values = extractValues$1(candidate);
|
|
19187
|
+
if (values) return values;
|
|
19188
|
+
}
|
|
19189
|
+
};
|
|
19190
|
+
const parseRecordInput = (raw, options) => {
|
|
19191
|
+
try {
|
|
19192
|
+
return parseObject(raw, { emptyBehavior: options.emptyBehavior ?? "reject" });
|
|
19193
|
+
} catch (error) {
|
|
19194
|
+
if (error instanceof z.ZodError) {
|
|
19195
|
+
if (error.issues.some((issue) => issue.code === z.ZodIssueCode.custom && issue.params?.code === emptyObjectIssueCode)) throw new AttioResponseError("Invalid API response: empty data object", { code: "EMPTY_RESPONSE" });
|
|
19196
|
+
throw new AttioResponseError("Invalid API response: no data found", { code: "INVALID_RESPONSE" });
|
|
19197
|
+
}
|
|
19198
|
+
throw error;
|
|
19199
|
+
}
|
|
19200
|
+
};
|
|
19201
|
+
function normalizeRecord(raw, options = defaultNormalizeRecordOptions) {
|
|
19202
|
+
const parsedRaw = parseRecordInput(raw, options);
|
|
19203
|
+
if (hasValidRecordId(parsedRaw) && extractValuesObject(parsedRaw)) return parsedRaw;
|
|
19204
|
+
const result = { ...parsedRaw };
|
|
19205
|
+
if (!hasValidRecordId(result)) {
|
|
18591
19206
|
const extractedId = extractRecordId(result);
|
|
18592
19207
|
if (extractedId) result.id = {
|
|
18593
|
-
...result.id,
|
|
19208
|
+
...parseObject(result.id) ?? {},
|
|
18594
19209
|
record_id: extractedId
|
|
18595
19210
|
};
|
|
18596
19211
|
}
|
|
18597
|
-
if (!result.values) {
|
|
18598
|
-
const dataRecord = result.data;
|
|
18599
|
-
result.values = extractValues(result.data) ?? extractValues(dataRecord?.data) ?? extractValues(dataRecord?.record) ?? extractValues(dataRecord?.items?.[0]) ?? {};
|
|
18600
|
-
}
|
|
19212
|
+
if (!extractValuesObject(result)) result.values = extractNestedValues(result) ?? {};
|
|
18601
19213
|
return result;
|
|
18602
|
-
}
|
|
18603
|
-
|
|
18604
|
-
|
|
18605
|
-
|
|
19214
|
+
}
|
|
19215
|
+
function normalizeRecords(items, options = defaultNormalizeRecordOptions) {
|
|
19216
|
+
const normalized = [];
|
|
19217
|
+
for (const item of items) {
|
|
19218
|
+
const record = parseObject(item);
|
|
19219
|
+
if (record) normalized.push(normalizeRecord(record, options));
|
|
19220
|
+
}
|
|
19221
|
+
return normalized;
|
|
19222
|
+
}
|
|
19223
|
+
|
|
19224
|
+
//#endregion
|
|
19225
|
+
//#region src/attio/schemas.ts
|
|
19226
|
+
const rawRecordSchema = z.record(z.string(), z.unknown());
|
|
18606
19227
|
|
|
18607
19228
|
//#endregion
|
|
18608
19229
|
//#region src/attio/records.ts
|
|
18609
19230
|
const createRecord = async (input) => {
|
|
18610
|
-
return normalizeRecord(
|
|
19231
|
+
return normalizeRecord(assertOk(await postV2ObjectsByObjectRecords({
|
|
18611
19232
|
client: resolveAttioClient(input),
|
|
18612
19233
|
path: { object: input.object },
|
|
18613
19234
|
body: { data: { values: input.values } },
|
|
18614
19235
|
...input.options
|
|
18615
|
-
})));
|
|
19236
|
+
}), { schema: rawRecordSchema }));
|
|
18616
19237
|
};
|
|
18617
19238
|
const updateRecord = async (input) => {
|
|
18618
|
-
return normalizeRecord(
|
|
19239
|
+
return normalizeRecord(assertOk(await patchV2ObjectsByObjectRecordsByRecordId({
|
|
18619
19240
|
client: resolveAttioClient(input),
|
|
18620
19241
|
path: {
|
|
18621
19242
|
object: input.object,
|
|
@@ -18623,28 +19244,26 @@ const updateRecord = async (input) => {
|
|
|
18623
19244
|
},
|
|
18624
19245
|
body: { data: { values: input.values } },
|
|
18625
19246
|
...input.options
|
|
18626
|
-
})));
|
|
19247
|
+
}), { schema: rawRecordSchema }));
|
|
18627
19248
|
};
|
|
18628
19249
|
const upsertRecord = async (input) => {
|
|
18629
|
-
return normalizeRecord(
|
|
19250
|
+
return normalizeRecord(assertOk(await putV2ObjectsByObjectRecords({
|
|
18630
19251
|
client: resolveAttioClient(input),
|
|
18631
19252
|
path: { object: input.object },
|
|
18632
|
-
body: {
|
|
18633
|
-
|
|
18634
|
-
matching_attribute: input.matchingAttribute
|
|
18635
|
-
},
|
|
19253
|
+
body: { data: { values: input.values } },
|
|
19254
|
+
query: { matching_attribute: input.matchingAttribute },
|
|
18636
19255
|
...input.options
|
|
18637
|
-
})));
|
|
19256
|
+
}), { schema: rawRecordSchema }));
|
|
18638
19257
|
};
|
|
18639
19258
|
const getRecord = async (input) => {
|
|
18640
|
-
return normalizeRecord(
|
|
19259
|
+
return normalizeRecord(assertOk(await getV2ObjectsByObjectRecordsByRecordId({
|
|
18641
19260
|
client: resolveAttioClient(input),
|
|
18642
19261
|
path: {
|
|
18643
19262
|
object: input.object,
|
|
18644
19263
|
record_id: input.recordId
|
|
18645
19264
|
},
|
|
18646
19265
|
...input.options
|
|
18647
|
-
})));
|
|
19266
|
+
}), { schema: rawRecordSchema }));
|
|
18648
19267
|
};
|
|
18649
19268
|
const deleteRecord = async (input) => {
|
|
18650
19269
|
await deleteV2ObjectsByObjectRecordsByRecordId({
|
|
@@ -18669,7 +19288,203 @@ const queryRecords = async (input) => {
|
|
|
18669
19288
|
offset: input.offset
|
|
18670
19289
|
},
|
|
18671
19290
|
...input.options
|
|
18672
|
-
})));
|
|
19291
|
+
}), { schema: rawRecordSchema }));
|
|
19292
|
+
};
|
|
19293
|
+
|
|
19294
|
+
//#endregion
|
|
19295
|
+
//#region src/attio/values.ts
|
|
19296
|
+
const nonEmptyStringSchema = z.string().min(1, "Expected a non-empty string.");
|
|
19297
|
+
const emailSchema = z.string().email("Expected a valid email address.");
|
|
19298
|
+
const currencyCodeSchema = z.string().regex(/^[A-Z]{3}$/, "Expected ISO 4217 currency code.");
|
|
19299
|
+
const finiteNumberSchema = z.number().finite("Expected a finite number.");
|
|
19300
|
+
const wrapSingle = (input) => [input];
|
|
19301
|
+
const value = {
|
|
19302
|
+
string: (input) => wrapSingle({ value: nonEmptyStringSchema.parse(input) }),
|
|
19303
|
+
number: (input) => wrapSingle({ value: finiteNumberSchema.parse(input) }),
|
|
19304
|
+
boolean: (input) => wrapSingle({ value: z.boolean().parse(input) }),
|
|
19305
|
+
domain: (input) => wrapSingle({ domain: nonEmptyStringSchema.parse(input) }),
|
|
19306
|
+
email: (input) => wrapSingle({ email_address: emailSchema.parse(input) }),
|
|
19307
|
+
currency: (input, currencyCode) => {
|
|
19308
|
+
const currency_value = finiteNumberSchema.parse(input);
|
|
19309
|
+
if (currencyCode === void 0) return wrapSingle({ currency_value });
|
|
19310
|
+
return wrapSingle({
|
|
19311
|
+
currency_value,
|
|
19312
|
+
currency_code: currencyCodeSchema.parse(currencyCode)
|
|
19313
|
+
});
|
|
19314
|
+
}
|
|
19315
|
+
};
|
|
19316
|
+
const recordValuesSchema = z.object({ values: z.record(z.string(), z.array(z.unknown())).optional() }).passthrough();
|
|
19317
|
+
const extractValues = (record) => {
|
|
19318
|
+
const parsed = recordValuesSchema.safeParse(record);
|
|
19319
|
+
if (!parsed.success) return;
|
|
19320
|
+
return parsed.data.values;
|
|
19321
|
+
};
|
|
19322
|
+
const parseValuesOrThrow = (raw, schema, attribute) => {
|
|
19323
|
+
const parsed = [];
|
|
19324
|
+
for (const entry of raw) {
|
|
19325
|
+
const result = schema.safeParse(entry);
|
|
19326
|
+
if (!result.success) throw new AttioResponseError(`Invalid API response: attribute "${attribute}" value mismatch`, {
|
|
19327
|
+
code: "INVALID_VALUE",
|
|
19328
|
+
data: result.error
|
|
19329
|
+
});
|
|
19330
|
+
parsed.push(result.data);
|
|
19331
|
+
}
|
|
19332
|
+
return parsed;
|
|
19333
|
+
};
|
|
19334
|
+
function getValue(record, attribute, options) {
|
|
19335
|
+
const raw = extractValues(record)?.[attribute];
|
|
19336
|
+
if (!raw) return;
|
|
19337
|
+
if (!options?.schema) return raw;
|
|
19338
|
+
return parseValuesOrThrow(raw, options.schema, attribute);
|
|
19339
|
+
}
|
|
19340
|
+
function getFirstValue(record, attribute, options) {
|
|
19341
|
+
const values = getValue(record, attribute, options);
|
|
19342
|
+
return values ? values[0] : void 0;
|
|
19343
|
+
}
|
|
19344
|
+
|
|
19345
|
+
//#endregion
|
|
19346
|
+
//#region src/attio/schema.ts
|
|
19347
|
+
const createAccessor = (attribute) => ({
|
|
19348
|
+
attribute,
|
|
19349
|
+
getValue: (record) => getValue(record, attribute.api_slug),
|
|
19350
|
+
getFirstValue: (record) => getFirstValue(record, attribute.api_slug),
|
|
19351
|
+
getValueAs: (record, options) => getValue(record, attribute.api_slug, options),
|
|
19352
|
+
getFirstValueAs: (record, options) => getFirstValue(record, attribute.api_slug, options)
|
|
19353
|
+
});
|
|
19354
|
+
const createSchema = async (input) => {
|
|
19355
|
+
const attributes = await listAttributes({
|
|
19356
|
+
...input,
|
|
19357
|
+
options: input.options
|
|
19358
|
+
});
|
|
19359
|
+
const attributeMap = /* @__PURE__ */ new Map();
|
|
19360
|
+
const attributeSlugs = [];
|
|
19361
|
+
for (const attribute of attributes) {
|
|
19362
|
+
attributeMap.set(attribute.api_slug, attribute);
|
|
19363
|
+
attributeSlugs.push(attribute.api_slug);
|
|
19364
|
+
}
|
|
19365
|
+
const getAttribute = (slug) => attributeMap.get(slug);
|
|
19366
|
+
const getAttributeOrThrow = (slug) => {
|
|
19367
|
+
const attribute = getAttribute(slug);
|
|
19368
|
+
if (!attribute) throw new AttioResponseError(`Unknown attribute slug "${slug}" for ${input.target}:${input.identifier}`, { code: "UNKNOWN_ATTRIBUTE" });
|
|
19369
|
+
return attribute;
|
|
19370
|
+
};
|
|
19371
|
+
const getAccessor = (slug) => {
|
|
19372
|
+
const attribute = getAttribute(slug);
|
|
19373
|
+
if (!attribute) return;
|
|
19374
|
+
return createAccessor(attribute);
|
|
19375
|
+
};
|
|
19376
|
+
const getAccessorOrThrow = (slug) => createAccessor(getAttributeOrThrow(slug));
|
|
19377
|
+
return {
|
|
19378
|
+
target: input.target,
|
|
19379
|
+
identifier: input.identifier,
|
|
19380
|
+
attributes,
|
|
19381
|
+
attributeSlugs,
|
|
19382
|
+
getAttribute,
|
|
19383
|
+
getAttributeOrThrow,
|
|
19384
|
+
getAccessor,
|
|
19385
|
+
getAccessorOrThrow
|
|
19386
|
+
};
|
|
19387
|
+
};
|
|
19388
|
+
|
|
19389
|
+
//#endregion
|
|
19390
|
+
//#region src/attio/sdk.ts
|
|
19391
|
+
const createAttioSdk = (input = {}) => {
|
|
19392
|
+
const client = resolveAttioClient(input);
|
|
19393
|
+
return {
|
|
19394
|
+
client,
|
|
19395
|
+
objects: {
|
|
19396
|
+
list: (params = {}) => listObjects({
|
|
19397
|
+
...params,
|
|
19398
|
+
client
|
|
19399
|
+
}),
|
|
19400
|
+
get: (params) => getObject({
|
|
19401
|
+
...params,
|
|
19402
|
+
client
|
|
19403
|
+
}),
|
|
19404
|
+
create: (params) => createObject({
|
|
19405
|
+
...params,
|
|
19406
|
+
client
|
|
19407
|
+
}),
|
|
19408
|
+
update: (params) => updateObject({
|
|
19409
|
+
...params,
|
|
19410
|
+
client
|
|
19411
|
+
})
|
|
19412
|
+
},
|
|
19413
|
+
records: {
|
|
19414
|
+
create: (params) => createRecord({
|
|
19415
|
+
...params,
|
|
19416
|
+
client
|
|
19417
|
+
}),
|
|
19418
|
+
update: (params) => updateRecord({
|
|
19419
|
+
...params,
|
|
19420
|
+
client
|
|
19421
|
+
}),
|
|
19422
|
+
upsert: (params) => upsertRecord({
|
|
19423
|
+
...params,
|
|
19424
|
+
client
|
|
19425
|
+
}),
|
|
19426
|
+
get: (params) => getRecord({
|
|
19427
|
+
...params,
|
|
19428
|
+
client
|
|
19429
|
+
}),
|
|
19430
|
+
delete: (params) => deleteRecord({
|
|
19431
|
+
...params,
|
|
19432
|
+
client
|
|
19433
|
+
}),
|
|
19434
|
+
query: (params) => queryRecords({
|
|
19435
|
+
...params,
|
|
19436
|
+
client
|
|
19437
|
+
})
|
|
19438
|
+
},
|
|
19439
|
+
lists: {
|
|
19440
|
+
list: (params = {}) => listLists({
|
|
19441
|
+
...params,
|
|
19442
|
+
client
|
|
19443
|
+
}),
|
|
19444
|
+
get: (params) => getList({
|
|
19445
|
+
...params,
|
|
19446
|
+
client
|
|
19447
|
+
}),
|
|
19448
|
+
queryEntries: (params) => queryListEntries({
|
|
19449
|
+
...params,
|
|
19450
|
+
client
|
|
19451
|
+
}),
|
|
19452
|
+
addEntry: (params) => addListEntry({
|
|
19453
|
+
...params,
|
|
19454
|
+
client
|
|
19455
|
+
}),
|
|
19456
|
+
updateEntry: (params) => updateListEntry({
|
|
19457
|
+
...params,
|
|
19458
|
+
client
|
|
19459
|
+
}),
|
|
19460
|
+
removeEntry: (params) => removeListEntry({
|
|
19461
|
+
...params,
|
|
19462
|
+
client
|
|
19463
|
+
})
|
|
19464
|
+
},
|
|
19465
|
+
metadata: {
|
|
19466
|
+
listAttributes: (params) => listAttributes({
|
|
19467
|
+
...params,
|
|
19468
|
+
client
|
|
19469
|
+
}),
|
|
19470
|
+
getAttribute: (params) => getAttribute({
|
|
19471
|
+
...params,
|
|
19472
|
+
client
|
|
19473
|
+
}),
|
|
19474
|
+
getAttributeOptions: (params) => getAttributeOptions({
|
|
19475
|
+
...params,
|
|
19476
|
+
client
|
|
19477
|
+
}),
|
|
19478
|
+
getAttributeStatuses: (params) => getAttributeStatuses({
|
|
19479
|
+
...params,
|
|
19480
|
+
client
|
|
19481
|
+
}),
|
|
19482
|
+
schema: (params) => createSchema({
|
|
19483
|
+
...params,
|
|
19484
|
+
client
|
|
19485
|
+
})
|
|
19486
|
+
}
|
|
19487
|
+
};
|
|
18673
19488
|
};
|
|
18674
19489
|
|
|
18675
19490
|
//#endregion
|
|
@@ -18684,26 +19499,27 @@ const searchRecords = async (input) => {
|
|
|
18684
19499
|
limit: input.limit
|
|
18685
19500
|
},
|
|
18686
19501
|
...input.options
|
|
18687
|
-
})));
|
|
19502
|
+
}), { schema: rawRecordSchema }));
|
|
18688
19503
|
};
|
|
18689
19504
|
|
|
18690
19505
|
//#endregion
|
|
18691
19506
|
//#region src/attio/tasks.ts
|
|
18692
19507
|
const listTasks = async (input = {}) => {
|
|
18693
|
-
return unwrapItems(await getV2Tasks({ client: resolveAttioClient(input) }));
|
|
19508
|
+
return unwrapItems(await getV2Tasks({ client: resolveAttioClient(input) }), { schema: zTask });
|
|
18694
19509
|
};
|
|
18695
19510
|
const getTask = async (input) => {
|
|
18696
19511
|
return unwrapData(await getV2TasksByTaskId({
|
|
18697
19512
|
client: resolveAttioClient(input),
|
|
18698
|
-
path: { task_id: input.taskId }
|
|
18699
|
-
|
|
19513
|
+
path: { task_id: input.taskId },
|
|
19514
|
+
...input.options
|
|
19515
|
+
}), { schema: zTask });
|
|
18700
19516
|
};
|
|
18701
19517
|
const createTask = async (input) => {
|
|
18702
19518
|
return unwrapData(await postV2Tasks({
|
|
18703
19519
|
client: resolveAttioClient(input),
|
|
18704
19520
|
body: { data: input.data },
|
|
18705
19521
|
...input.options
|
|
18706
|
-
}));
|
|
19522
|
+
}), { schema: zTask });
|
|
18707
19523
|
};
|
|
18708
19524
|
const updateTask = async (input) => {
|
|
18709
19525
|
return unwrapData(await patchV2TasksByTaskId({
|
|
@@ -18711,14 +19527,14 @@ const updateTask = async (input) => {
|
|
|
18711
19527
|
path: { task_id: input.taskId },
|
|
18712
19528
|
body: { data: input.data },
|
|
18713
19529
|
...input.options
|
|
18714
|
-
}));
|
|
19530
|
+
}), { schema: zTask });
|
|
18715
19531
|
};
|
|
18716
19532
|
const deleteTask = async (input) => {
|
|
18717
|
-
await deleteV2TasksByTaskId({
|
|
19533
|
+
return (await deleteV2TasksByTaskId({
|
|
18718
19534
|
client: resolveAttioClient(input),
|
|
18719
|
-
path: { task_id: input.taskId }
|
|
18720
|
-
|
|
18721
|
-
|
|
19535
|
+
path: { task_id: input.taskId },
|
|
19536
|
+
...input.options
|
|
19537
|
+
})).data ?? {};
|
|
18722
19538
|
};
|
|
18723
19539
|
|
|
18724
19540
|
//#endregion
|
|
@@ -18734,5 +19550,5 @@ const getWorkspaceMember = async (input) => {
|
|
|
18734
19550
|
};
|
|
18735
19551
|
|
|
18736
19552
|
//#endregion
|
|
18737
|
-
export { AttioApiError, AttioError, AttioNetworkError, DEFAULT_BASE_URL, DEFAULT_RETRY_CONFIG, TtlCache, addListEntry, calculateRetryDelay, callWithRetry, clearClientCache, createAttioClient, createNote, createRecord, createTask, createTtlCache, deleteNote, deleteRecord, deleteTask, deleteV2CommentsByCommentId, deleteV2ListsByListEntriesByEntryId, deleteV2MeetingsByMeetingIdCallRecordingsByCallRecordingId, deleteV2NotesByNoteId, deleteV2ObjectsByObjectRecordsByRecordId, deleteV2TasksByTaskId, deleteV2WebhooksByWebhookId, enhanceAttioError, extractRecordId, filters, getAttioClient, getAttribute, getAttributeOptions, getAttributeStatuses, getCachedClient, getEnvValue, getKnownFieldValues, getList, getNote, getRecord, getTask, getV2ByTargetByIdentifierAttributes, getV2ByTargetByIdentifierAttributesByAttribute, getV2ByTargetByIdentifierAttributesByAttributeOptions, getV2ByTargetByIdentifierAttributesByAttributeStatuses, getV2CommentsByCommentId, getV2Lists, getV2ListsByList, getV2ListsByListEntriesByEntryId, getV2ListsByListEntriesByEntryIdAttributesByAttributeValues, getV2Meetings, getV2MeetingsByMeetingId, getV2MeetingsByMeetingIdCallRecordings, getV2MeetingsByMeetingIdCallRecordingsByCallRecordingId, getV2MeetingsByMeetingIdCallRecordingsByCallRecordingIdTranscript, getV2Notes, getV2NotesByNoteId, getV2Objects, getV2ObjectsByObject, getV2ObjectsByObjectRecordsByRecordId, getV2ObjectsByObjectRecordsByRecordIdAttributesByAttributeValues, getV2ObjectsByObjectRecordsByRecordIdEntries, getV2Self, getV2Tasks, getV2TasksByTaskId, getV2Threads, getV2ThreadsByThreadId, getV2Webhooks, getV2WebhooksByWebhookId, getV2WorkspaceMembers, getV2WorkspaceMembersByWorkspaceMemberId, getWorkspaceMember, hashToken, isRetryableError, isRetryableStatus, listAttributes, listLists, listNotes, listTasks, listWorkspaceMembers, normalizeAttioError, normalizeBaseUrl, normalizeRecord, normalizeRecords, paginate, patchV2ByTargetByIdentifierAttributesByAttribute, patchV2ByTargetByIdentifierAttributesByAttributeOptionsByOption, patchV2ByTargetByIdentifierAttributesByAttributeStatusesByStatus, patchV2ListsByList, patchV2ListsByListEntriesByEntryId, patchV2ObjectsByObject, patchV2ObjectsByObjectRecordsByRecordId, patchV2TasksByTaskId, patchV2WebhooksByWebhookId, postV2ByTargetByIdentifierAttributes, postV2ByTargetByIdentifierAttributesByAttributeOptions, postV2ByTargetByIdentifierAttributesByAttributeStatuses, postV2Comments, postV2Lists, postV2ListsByListEntries, postV2ListsByListEntriesQuery, postV2Meetings, postV2MeetingsByMeetingIdCallRecordings, postV2Notes, postV2Objects, postV2ObjectsByObjectRecords, postV2ObjectsByObjectRecordsQuery, postV2ObjectsRecordsSearch, postV2Tasks, postV2Webhooks, putV2ListsByListEntries, putV2ListsByListEntriesByEntryId, putV2ObjectsByObjectRecords, putV2ObjectsByObjectRecordsByRecordId, queryListEntries, queryRecords, removeListEntry, resolveAttioClient, resolveAuthToken, resolveBaseUrl, resolveResponseStyle, resolveThrowOnError, runBatch, searchRecords, setCachedClient, sleep, toPageResult, unwrapData, unwrapItems, unwrapPaginationCursor, updateKnownFieldValues, updateListEntry, updateRecord, updateTask, upsertRecord,
|
|
19553
|
+
export { AttioApiError, AttioBatchError, AttioConfigError, AttioEnvironmentError, AttioError, AttioNetworkError, AttioResponseError, AttioRetryError, DEFAULT_BASE_URL, DEFAULT_METADATA_CACHE_MAX_ENTRIES, DEFAULT_METADATA_CACHE_TTL_MS, DEFAULT_RETRY_CONFIG, TtlCache, addListEntry, assertOk, buildAttributeMetadataPath, buildKey, calculateRetryDelay, callWithRetry, clearClientCache, clearMetadataCacheRegistry, createAttioCacheManager, createAttioClient, createAttioSdk, createNote, createObject, createOffsetPageResultSchema, createPageResultSchema, createRecord, createSchema, createSchemaError, createTask, createTtlCache, createTtlCacheAdapter, deleteNote, deleteRecord, deleteTask, deleteV2CommentsByCommentId, deleteV2ListsByListEntriesByEntryId, deleteV2MeetingsByMeetingIdCallRecordingsByCallRecordingId, deleteV2NotesByNoteId, deleteV2ObjectsByObjectRecordsByRecordId, deleteV2TasksByTaskId, deleteV2WebhooksByWebhookId, enhanceAttioError, extractRecordId, extractTitles, filters, getAttioClient, getAttribute, getAttributeOptions, getAttributeStatuses, getCachedClient, getEnvValue, getFirstValue, getKnownFieldValues, getList, getNote, getObject, getRecord, getTask, getV2ByTargetByIdentifierAttributes, getV2ByTargetByIdentifierAttributesByAttribute, getV2ByTargetByIdentifierAttributesByAttributeOptions, getV2ByTargetByIdentifierAttributesByAttributeStatuses, getV2CommentsByCommentId, getV2Lists, getV2ListsByList, getV2ListsByListEntriesByEntryId, getV2ListsByListEntriesByEntryIdAttributesByAttributeValues, getV2Meetings, getV2MeetingsByMeetingId, getV2MeetingsByMeetingIdCallRecordings, getV2MeetingsByMeetingIdCallRecordingsByCallRecordingId, getV2MeetingsByMeetingIdCallRecordingsByCallRecordingIdTranscript, getV2Notes, getV2NotesByNoteId, getV2Objects, getV2ObjectsByObject, getV2ObjectsByObjectRecordsByRecordId, getV2ObjectsByObjectRecordsByRecordIdAttributesByAttributeValues, getV2ObjectsByObjectRecordsByRecordIdEntries, getV2Self, getV2Tasks, getV2TasksByTaskId, getV2Threads, getV2ThreadsByThreadId, getV2Webhooks, getV2WebhooksByWebhookId, getV2WorkspaceMembers, getV2WorkspaceMembersByWorkspaceMemberId, getValue, getWorkspaceMember, hashToken, isRetryableError, isRetryableStatus, listAttributeMetadata, listAttributes, listLists, listNotes, listObjects, listTasks, listWorkspaceMembers, normalizeAttioError, normalizeBaseUrl, normalizeRecord, normalizeRecords, paginate, paginateOffset, parseOffsetPageResult, parsePageResult, patchV2ByTargetByIdentifierAttributesByAttribute, patchV2ByTargetByIdentifierAttributesByAttributeOptionsByOption, patchV2ByTargetByIdentifierAttributesByAttributeStatusesByStatus, patchV2ListsByList, patchV2ListsByListEntriesByEntryId, patchV2ObjectsByObject, patchV2ObjectsByObjectRecordsByRecordId, patchV2TasksByTaskId, patchV2WebhooksByWebhookId, postV2ByTargetByIdentifierAttributes, postV2ByTargetByIdentifierAttributesByAttributeOptions, postV2ByTargetByIdentifierAttributesByAttributeStatuses, postV2Comments, postV2Lists, postV2ListsByListEntries, postV2ListsByListEntriesQuery, postV2Meetings, postV2MeetingsByMeetingIdCallRecordings, postV2Notes, postV2Objects, postV2ObjectsByObjectRecords, postV2ObjectsByObjectRecordsQuery, postV2ObjectsRecordsSearch, postV2Tasks, postV2Webhooks, putV2ListsByListEntries, putV2ListsByListEntriesByEntryId, putV2ObjectsByObjectRecords, putV2ObjectsByObjectRecordsByRecordId, queryListEntries, queryRecords, removeListEntry, resolveAttioClient, resolveAuthToken, resolveBaseUrl, resolveResponseStyle, resolveThrowOnError, runBatch, searchRecords, setCachedClient, sleep, toOffsetPageResult, toPageResult, toResult, unwrapData, unwrapItems, unwrapPaginationCursor, unwrapPaginationOffset, updateKnownFieldValues, updateListEntry, updateObject, updateRecord, updateTask, upsertRecord, value };
|
|
18738
19554
|
//# sourceMappingURL=index.mjs.map
|