@autolink/sdk 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +466 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +304 -0
- package/dist/index.d.ts +304 -0
- package/dist/index.js +426 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
AutolinkAuthError: () => AutolinkAuthError,
|
|
24
|
+
AutolinkClient: () => AutolinkClient,
|
|
25
|
+
AutolinkError: () => AutolinkError,
|
|
26
|
+
AutolinkForbiddenError: () => AutolinkForbiddenError,
|
|
27
|
+
AutolinkNetworkError: () => AutolinkNetworkError,
|
|
28
|
+
AutolinkNotFoundError: () => AutolinkNotFoundError,
|
|
29
|
+
AutolinkRateLimitError: () => AutolinkRateLimitError,
|
|
30
|
+
AutolinkValidationError: () => AutolinkValidationError,
|
|
31
|
+
GATEWAY_BASE_URL: () => GATEWAY_BASE_URL,
|
|
32
|
+
GATEWAY_URL: () => GATEWAY_URL,
|
|
33
|
+
MemoryCache: () => MemoryCache,
|
|
34
|
+
SDK_VERSION: () => SDK_VERSION,
|
|
35
|
+
getFieldErrors: () => getFieldErrors,
|
|
36
|
+
unwrap: () => unwrap
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(index_exports);
|
|
39
|
+
|
|
40
|
+
// src/transport/constants.ts
|
|
41
|
+
var GATEWAY_BASE_URL = "https://gateway.autolink.ke";
|
|
42
|
+
var GATEWAY_API_VERSION = "v1";
|
|
43
|
+
var GATEWAY_URL = `${GATEWAY_BASE_URL}/sdk/${GATEWAY_API_VERSION}`;
|
|
44
|
+
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
45
|
+
var DEFAULT_RETRY_ATTEMPTS = 3;
|
|
46
|
+
var SDK_VERSION = "0.1.0";
|
|
47
|
+
|
|
48
|
+
// src/errors.ts
|
|
49
|
+
var AutolinkError = class extends Error {
|
|
50
|
+
requestId;
|
|
51
|
+
code;
|
|
52
|
+
constructor(message, code, requestId) {
|
|
53
|
+
super(message);
|
|
54
|
+
this.name = "AutolinkError";
|
|
55
|
+
this.code = code;
|
|
56
|
+
this.requestId = requestId;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var AutolinkAuthError = class extends AutolinkError {
|
|
60
|
+
constructor(message, requestId) {
|
|
61
|
+
super(message, "AUTHENTICATION_ERROR", requestId);
|
|
62
|
+
this.name = "AutolinkAuthError";
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var AutolinkForbiddenError = class extends AutolinkError {
|
|
66
|
+
constructor(message, requestId) {
|
|
67
|
+
super(message, "FORBIDDEN", requestId);
|
|
68
|
+
this.name = "AutolinkForbiddenError";
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var AutolinkNotFoundError = class extends AutolinkError {
|
|
72
|
+
constructor(message, requestId) {
|
|
73
|
+
super(message, "NOT_FOUND", requestId);
|
|
74
|
+
this.name = "AutolinkNotFoundError";
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
var AutolinkValidationError = class extends AutolinkError {
|
|
78
|
+
fields;
|
|
79
|
+
constructor(message, requestId, fields = {}) {
|
|
80
|
+
super(message, "VALIDATION_ERROR", requestId);
|
|
81
|
+
this.name = "AutolinkValidationError";
|
|
82
|
+
this.fields = fields;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
var AutolinkRateLimitError = class extends AutolinkError {
|
|
86
|
+
retryAfter;
|
|
87
|
+
constructor(message, requestId, retryAfter) {
|
|
88
|
+
super(message, "RATE_LIMITED", requestId);
|
|
89
|
+
this.name = "AutolinkRateLimitError";
|
|
90
|
+
this.retryAfter = retryAfter;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
var AutolinkNetworkError = class extends AutolinkError {
|
|
94
|
+
cause;
|
|
95
|
+
constructor(message, cause) {
|
|
96
|
+
super(message, "NETWORK_ERROR", "");
|
|
97
|
+
this.name = "AutolinkNetworkError";
|
|
98
|
+
this.cause = cause;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// src/transport/retry.ts
|
|
103
|
+
var RETRYABLE_STATUS = /* @__PURE__ */ new Set([500, 502, 503, 504]);
|
|
104
|
+
function isRetryableStatus(status) {
|
|
105
|
+
return RETRYABLE_STATUS.has(status);
|
|
106
|
+
}
|
|
107
|
+
function backoffMs(attempt) {
|
|
108
|
+
const base = 100 * Math.pow(2, attempt);
|
|
109
|
+
const jitter = Math.random() * 100;
|
|
110
|
+
return Math.min(base + jitter, 1e4);
|
|
111
|
+
}
|
|
112
|
+
async function sleep(ms) {
|
|
113
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/transport/fetcher.ts
|
|
117
|
+
function resolveGatewayUrl() {
|
|
118
|
+
if (process.env["NODE_ENV"] !== "production" && process.env["AUTOLINK_GATEWAY_URL"]) {
|
|
119
|
+
return `${process.env["AUTOLINK_GATEWAY_URL"]}/sdk/v1`;
|
|
120
|
+
}
|
|
121
|
+
return GATEWAY_URL;
|
|
122
|
+
}
|
|
123
|
+
function throwFromResponse(status, body, headers) {
|
|
124
|
+
const { code, message, fields, request_id } = body.error;
|
|
125
|
+
const rid = request_id ?? "";
|
|
126
|
+
if (status === 401) throw new AutolinkAuthError(message, rid);
|
|
127
|
+
if (status === 403) throw new AutolinkForbiddenError(message, rid);
|
|
128
|
+
if (status === 404) throw new AutolinkNotFoundError(message, rid);
|
|
129
|
+
if (status === 400 || status === 422)
|
|
130
|
+
throw new AutolinkValidationError(message, rid, fields ?? {});
|
|
131
|
+
if (status === 429) {
|
|
132
|
+
const retryAfter = parseInt(headers.get("Retry-After") ?? "60", 10);
|
|
133
|
+
throw new AutolinkRateLimitError(message, rid, retryAfter);
|
|
134
|
+
}
|
|
135
|
+
throw new AutolinkError(message, code ?? "GATEWAY_ERROR", rid);
|
|
136
|
+
}
|
|
137
|
+
async function gatewayFetch(config, method, path, options = {}) {
|
|
138
|
+
const base = resolveGatewayUrl();
|
|
139
|
+
const url = new URL(`${base}${path}`);
|
|
140
|
+
if (options.params) {
|
|
141
|
+
for (const [k, v] of Object.entries(options.params)) {
|
|
142
|
+
if (v !== void 0) url.searchParams.set(k, String(v));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const headers = {
|
|
146
|
+
"Content-Type": "application/json",
|
|
147
|
+
"X-API-Key": config.apiKey,
|
|
148
|
+
"X-Autolink-SDK-Version": SDK_VERSION
|
|
149
|
+
};
|
|
150
|
+
if (options.idempotencyKey) {
|
|
151
|
+
headers["Idempotency-Key"] = options.idempotencyKey;
|
|
152
|
+
}
|
|
153
|
+
const isWrite = method === "POST" || method === "PUT" || method === "PATCH";
|
|
154
|
+
const maxAttempts = isWrite && !options.idempotencyKey ? 1 : config.retry.attempts;
|
|
155
|
+
let lastError = null;
|
|
156
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
157
|
+
if (attempt > 0) await sleep(backoffMs(attempt - 1));
|
|
158
|
+
const controller = new AbortController();
|
|
159
|
+
const timeoutId = setTimeout(
|
|
160
|
+
() => controller.abort(),
|
|
161
|
+
config.timeout ?? DEFAULT_TIMEOUT_MS
|
|
162
|
+
);
|
|
163
|
+
const signal = options.signal ?? controller.signal;
|
|
164
|
+
try {
|
|
165
|
+
const res = await fetch(url.toString(), {
|
|
166
|
+
method,
|
|
167
|
+
headers,
|
|
168
|
+
...options.body ? { body: JSON.stringify(options.body) } : {},
|
|
169
|
+
signal
|
|
170
|
+
});
|
|
171
|
+
clearTimeout(timeoutId);
|
|
172
|
+
if (config.debug) {
|
|
173
|
+
const rid = res.headers.get("X-Request-ID") ?? "";
|
|
174
|
+
console.debug(`[autolink] ${method} ${path} \u2192 ${res.status} (${rid})`);
|
|
175
|
+
}
|
|
176
|
+
if (!res.ok) {
|
|
177
|
+
const errorBody = await res.json();
|
|
178
|
+
if (isRetryableStatus(res.status) && attempt < maxAttempts - 1) {
|
|
179
|
+
lastError = new AutolinkError(
|
|
180
|
+
errorBody.error?.message ?? "Gateway error",
|
|
181
|
+
errorBody.error?.code ?? "GATEWAY_ERROR",
|
|
182
|
+
errorBody.error?.request_id ?? ""
|
|
183
|
+
);
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
throwFromResponse(res.status, errorBody, res.headers);
|
|
187
|
+
}
|
|
188
|
+
return await res.json();
|
|
189
|
+
} catch (err) {
|
|
190
|
+
clearTimeout(timeoutId);
|
|
191
|
+
if (err instanceof AutolinkError) throw err;
|
|
192
|
+
const networkErr = err instanceof Error ? err : new Error(String(err));
|
|
193
|
+
lastError = new AutolinkNetworkError(
|
|
194
|
+
`Request to Autolink gateway failed: ${networkErr.message}`,
|
|
195
|
+
networkErr
|
|
196
|
+
);
|
|
197
|
+
if (attempt < maxAttempts - 1) continue;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
throw lastError ?? new AutolinkNetworkError("Request failed", new Error("Unknown error"));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// src/resources/inventory.ts
|
|
204
|
+
var TTL_LIST = 300;
|
|
205
|
+
var TTL_SINGLE = 600;
|
|
206
|
+
var TTL_FILTER_OPTIONS = 300;
|
|
207
|
+
var InventoryResource = class {
|
|
208
|
+
constructor(config, cache) {
|
|
209
|
+
this.config = config;
|
|
210
|
+
this.cache = cache;
|
|
211
|
+
}
|
|
212
|
+
config;
|
|
213
|
+
cache;
|
|
214
|
+
async list(filters = {}, options) {
|
|
215
|
+
const ttl = options?.ttl ?? TTL_LIST;
|
|
216
|
+
const key = `autolink:inventory:list:${JSON.stringify(filters)}`;
|
|
217
|
+
if (this.cache && ttl > 0) {
|
|
218
|
+
const cached = await this.cache.get(key);
|
|
219
|
+
if (cached !== void 0)
|
|
220
|
+
return cached;
|
|
221
|
+
}
|
|
222
|
+
const result = await gatewayFetch(
|
|
223
|
+
this.config,
|
|
224
|
+
"GET",
|
|
225
|
+
"/inventory",
|
|
226
|
+
{
|
|
227
|
+
params: filters
|
|
228
|
+
}
|
|
229
|
+
);
|
|
230
|
+
if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);
|
|
231
|
+
return result;
|
|
232
|
+
}
|
|
233
|
+
async get(slug, options) {
|
|
234
|
+
const ttl = options?.ttl ?? TTL_SINGLE;
|
|
235
|
+
const key = `autolink:inventory:${slug}`;
|
|
236
|
+
if (this.cache && ttl > 0) {
|
|
237
|
+
const cached = await this.cache.get(key);
|
|
238
|
+
if (cached !== void 0)
|
|
239
|
+
return cached;
|
|
240
|
+
}
|
|
241
|
+
const result = await gatewayFetch(
|
|
242
|
+
this.config,
|
|
243
|
+
"GET",
|
|
244
|
+
`/inventory/${slug}`
|
|
245
|
+
);
|
|
246
|
+
if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);
|
|
247
|
+
return result;
|
|
248
|
+
}
|
|
249
|
+
async filterOptions(options) {
|
|
250
|
+
const ttl = options?.ttl ?? TTL_FILTER_OPTIONS;
|
|
251
|
+
const key = "autolink:inventory:filter-options";
|
|
252
|
+
if (this.cache && ttl > 0) {
|
|
253
|
+
const cached = await this.cache.get(key);
|
|
254
|
+
if (cached !== void 0) return cached;
|
|
255
|
+
}
|
|
256
|
+
const result = await gatewayFetch(
|
|
257
|
+
this.config,
|
|
258
|
+
"GET",
|
|
259
|
+
"/inventory/filter-options"
|
|
260
|
+
);
|
|
261
|
+
if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);
|
|
262
|
+
return result;
|
|
263
|
+
}
|
|
264
|
+
async *pages(filters = {}) {
|
|
265
|
+
let page = 1;
|
|
266
|
+
while (true) {
|
|
267
|
+
const result = await this.list({ ...filters, page });
|
|
268
|
+
yield result;
|
|
269
|
+
const { pagination } = result.meta;
|
|
270
|
+
if (!pagination || page >= pagination.pages) break;
|
|
271
|
+
page++;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
// src/resources/inquiries.ts
|
|
277
|
+
var import_crypto = require("crypto");
|
|
278
|
+
var InquiriesResource = class {
|
|
279
|
+
constructor(config) {
|
|
280
|
+
this.config = config;
|
|
281
|
+
}
|
|
282
|
+
config;
|
|
283
|
+
async create(payload, options = {}) {
|
|
284
|
+
const idempotencyKey = options.idempotencyKey ?? (0, import_crypto.randomUUID)();
|
|
285
|
+
return gatewayFetch(
|
|
286
|
+
this.config,
|
|
287
|
+
"POST",
|
|
288
|
+
"/inquiries",
|
|
289
|
+
{ body: payload, idempotencyKey }
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
// src/resources/profile.ts
|
|
295
|
+
var ProfileResource = class {
|
|
296
|
+
constructor(config) {
|
|
297
|
+
this.config = config;
|
|
298
|
+
}
|
|
299
|
+
config;
|
|
300
|
+
async get() {
|
|
301
|
+
return gatewayFetch(
|
|
302
|
+
this.config,
|
|
303
|
+
"GET",
|
|
304
|
+
"/profile"
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
// src/resources/articles.ts
|
|
310
|
+
var TTL_ARTICLES = 600;
|
|
311
|
+
var ArticlesResource = class {
|
|
312
|
+
constructor(config, cache) {
|
|
313
|
+
this.config = config;
|
|
314
|
+
this.cache = cache;
|
|
315
|
+
}
|
|
316
|
+
config;
|
|
317
|
+
cache;
|
|
318
|
+
async list(filters = {}, options) {
|
|
319
|
+
const ttl = options?.ttl ?? TTL_ARTICLES;
|
|
320
|
+
const key = `autolink:articles:list:${JSON.stringify(filters)}`;
|
|
321
|
+
if (this.cache && ttl > 0) {
|
|
322
|
+
const cached = await this.cache.get(key);
|
|
323
|
+
if (cached !== void 0)
|
|
324
|
+
return cached;
|
|
325
|
+
}
|
|
326
|
+
const result = await gatewayFetch(
|
|
327
|
+
this.config,
|
|
328
|
+
"GET",
|
|
329
|
+
"/articles",
|
|
330
|
+
{
|
|
331
|
+
params: filters
|
|
332
|
+
}
|
|
333
|
+
);
|
|
334
|
+
if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);
|
|
335
|
+
return result;
|
|
336
|
+
}
|
|
337
|
+
async get(slug, options) {
|
|
338
|
+
const ttl = options?.ttl ?? TTL_ARTICLES;
|
|
339
|
+
const key = `autolink:articles:${slug}`;
|
|
340
|
+
if (this.cache && ttl > 0) {
|
|
341
|
+
const cached = await this.cache.get(key);
|
|
342
|
+
if (cached !== void 0)
|
|
343
|
+
return cached;
|
|
344
|
+
}
|
|
345
|
+
const result = await gatewayFetch(
|
|
346
|
+
this.config,
|
|
347
|
+
"GET",
|
|
348
|
+
`/articles/${slug}`
|
|
349
|
+
);
|
|
350
|
+
if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);
|
|
351
|
+
return result;
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
// src/resources/integration.ts
|
|
356
|
+
var IntegrationResource = class {
|
|
357
|
+
constructor(config) {
|
|
358
|
+
this.config = config;
|
|
359
|
+
}
|
|
360
|
+
config;
|
|
361
|
+
async check() {
|
|
362
|
+
return gatewayFetch(
|
|
363
|
+
this.config,
|
|
364
|
+
"GET",
|
|
365
|
+
"/integration"
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
// src/client.ts
|
|
371
|
+
var AutolinkClient = class {
|
|
372
|
+
inventory;
|
|
373
|
+
inquiries;
|
|
374
|
+
profile;
|
|
375
|
+
articles;
|
|
376
|
+
integration;
|
|
377
|
+
constructor(config) {
|
|
378
|
+
if (!config.apiKey) {
|
|
379
|
+
throw new Error("AutolinkClient: apiKey is required");
|
|
380
|
+
}
|
|
381
|
+
if (!config.apiKey.startsWith("gw_live_") && !config.apiKey.startsWith("gw_test_")) {
|
|
382
|
+
throw new Error(
|
|
383
|
+
'AutolinkClient: apiKey must start with "gw_live_" or "gw_test_"'
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
const fetcherConfig = {
|
|
387
|
+
apiKey: config.apiKey,
|
|
388
|
+
timeout: config.timeout ?? DEFAULT_TIMEOUT_MS,
|
|
389
|
+
retry: {
|
|
390
|
+
attempts: config.retry?.attempts ?? DEFAULT_RETRY_ATTEMPTS,
|
|
391
|
+
backoff: config.retry?.backoff ?? "exponential"
|
|
392
|
+
},
|
|
393
|
+
debug: config.debug ?? false
|
|
394
|
+
};
|
|
395
|
+
this.inventory = new InventoryResource(fetcherConfig, config.cache);
|
|
396
|
+
this.inquiries = new InquiriesResource(fetcherConfig);
|
|
397
|
+
this.profile = new ProfileResource(fetcherConfig);
|
|
398
|
+
this.articles = new ArticlesResource(fetcherConfig, config.cache);
|
|
399
|
+
this.integration = new IntegrationResource(fetcherConfig);
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
// src/cache/index.ts
|
|
404
|
+
var MAX_ENTRIES = 200;
|
|
405
|
+
var MemoryCache = class {
|
|
406
|
+
store = /* @__PURE__ */ new Map();
|
|
407
|
+
get(key) {
|
|
408
|
+
const entry = this.store.get(key);
|
|
409
|
+
if (!entry) return void 0;
|
|
410
|
+
if (entry.expiresAt !== null && Date.now() > entry.expiresAt) {
|
|
411
|
+
this.store.delete(key);
|
|
412
|
+
return void 0;
|
|
413
|
+
}
|
|
414
|
+
return entry.value;
|
|
415
|
+
}
|
|
416
|
+
set(key, value, ttlSeconds) {
|
|
417
|
+
if (this.store.size >= MAX_ENTRIES && !this.store.has(key)) {
|
|
418
|
+
const oldestKey = this.store.keys().next().value;
|
|
419
|
+
if (oldestKey !== void 0) {
|
|
420
|
+
this.store.delete(oldestKey);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
this.store.set(key, {
|
|
424
|
+
value,
|
|
425
|
+
expiresAt: ttlSeconds != null ? Date.now() + ttlSeconds * 1e3 : null
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
delete(key) {
|
|
429
|
+
this.store.delete(key);
|
|
430
|
+
}
|
|
431
|
+
/** Remove all expired entries. Optional maintenance call. */
|
|
432
|
+
purgeExpired() {
|
|
433
|
+
const now = Date.now();
|
|
434
|
+
for (const [key, entry] of this.store) {
|
|
435
|
+
if (entry.expiresAt !== null && now > entry.expiresAt) {
|
|
436
|
+
this.store.delete(key);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
// src/index.ts
|
|
443
|
+
function unwrap(envelope) {
|
|
444
|
+
return envelope.data;
|
|
445
|
+
}
|
|
446
|
+
function getFieldErrors(error, field) {
|
|
447
|
+
return error.fields[field] ?? [];
|
|
448
|
+
}
|
|
449
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
450
|
+
0 && (module.exports = {
|
|
451
|
+
AutolinkAuthError,
|
|
452
|
+
AutolinkClient,
|
|
453
|
+
AutolinkError,
|
|
454
|
+
AutolinkForbiddenError,
|
|
455
|
+
AutolinkNetworkError,
|
|
456
|
+
AutolinkNotFoundError,
|
|
457
|
+
AutolinkRateLimitError,
|
|
458
|
+
AutolinkValidationError,
|
|
459
|
+
GATEWAY_BASE_URL,
|
|
460
|
+
GATEWAY_URL,
|
|
461
|
+
MemoryCache,
|
|
462
|
+
SDK_VERSION,
|
|
463
|
+
getFieldErrors,
|
|
464
|
+
unwrap
|
|
465
|
+
});
|
|
466
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/transport/constants.ts","../src/errors.ts","../src/transport/retry.ts","../src/transport/fetcher.ts","../src/resources/inventory.ts","../src/resources/inquiries.ts","../src/resources/profile.ts","../src/resources/articles.ts","../src/resources/integration.ts","../src/client.ts","../src/cache/index.ts"],"sourcesContent":["export { AutolinkClient } from \"./client.js\";\nexport type { AutolinkClientConfig } from \"./client.js\";\n\nexport {\n AutolinkError,\n AutolinkAuthError,\n AutolinkForbiddenError,\n AutolinkNotFoundError,\n AutolinkValidationError,\n AutolinkRateLimitError,\n AutolinkNetworkError,\n} from \"./errors.js\";\n\nexport type {\n GatewayEnvelope,\n GatewayMeta,\n GatewayPagination,\n AutolinkVehicle,\n VehiclePhoto,\n VehicleDealer,\n CoverImageVariants,\n InventoryListFilters,\n FilterOptions,\n AutolinkInquiryPayload,\n AutolinkInquiry,\n AutolinkProfile,\n AutolinkArticle,\n ArticleListFilters,\n IntegrationStatus,\n StockStatus,\n VehicleCondition,\n} from \"./types/index.js\";\n\n// ---------------------------------------------------------------------------\n// DX helpers\n// ---------------------------------------------------------------------------\n\nimport type { GatewayEnvelope } from \"./types/index.js\";\nimport type { AutolinkValidationError } from \"./errors.js\";\n\n/** Unwraps a GatewayEnvelope and returns the data directly */\nexport function unwrap<T>(envelope: GatewayEnvelope<T>): T {\n return envelope.data;\n}\n\n/** Returns field-level validation errors for a given field name */\nexport function getFieldErrors(\n error: AutolinkValidationError,\n field: string,\n): string[] {\n return error.fields[field] ?? [];\n}\n\nexport {\n GATEWAY_BASE_URL,\n GATEWAY_URL,\n SDK_VERSION,\n} from \"./transport/constants.js\";\n\nexport type { AutolinkCache } from \"./cache/index.js\";\nexport { MemoryCache } from \"./cache/index.js\";\n","export const GATEWAY_BASE_URL = \"https://gateway.autolink.ke\";\nexport const GATEWAY_API_VERSION = \"v1\";\nexport const GATEWAY_URL = `${GATEWAY_BASE_URL}/sdk/${GATEWAY_API_VERSION}`;\n\nexport const DEFAULT_TIMEOUT_MS = 10_000;\nexport const DEFAULT_RETRY_ATTEMPTS = 3;\nexport const SDK_VERSION = \"0.1.0\";\n","export class AutolinkError extends Error {\n readonly requestId: string;\n readonly code: string;\n\n constructor(message: string, code: string, requestId: string) {\n super(message);\n this.name = \"AutolinkError\";\n this.code = code;\n this.requestId = requestId;\n }\n}\n\nexport class AutolinkAuthError extends AutolinkError {\n constructor(message: string, requestId: string) {\n super(message, \"AUTHENTICATION_ERROR\", requestId);\n this.name = \"AutolinkAuthError\";\n }\n}\n\nexport class AutolinkForbiddenError extends AutolinkError {\n constructor(message: string, requestId: string) {\n super(message, \"FORBIDDEN\", requestId);\n this.name = \"AutolinkForbiddenError\";\n }\n}\n\nexport class AutolinkNotFoundError extends AutolinkError {\n constructor(message: string, requestId: string) {\n super(message, \"NOT_FOUND\", requestId);\n this.name = \"AutolinkNotFoundError\";\n }\n}\n\nexport class AutolinkValidationError extends AutolinkError {\n readonly fields: Record<string, string[]>;\n\n constructor(\n message: string,\n requestId: string,\n fields: Record<string, string[]> = {},\n ) {\n super(message, \"VALIDATION_ERROR\", requestId);\n this.name = \"AutolinkValidationError\";\n this.fields = fields;\n }\n}\n\nexport class AutolinkRateLimitError extends AutolinkError {\n readonly retryAfter: number;\n\n constructor(message: string, requestId: string, retryAfter: number) {\n super(message, \"RATE_LIMITED\", requestId);\n this.name = \"AutolinkRateLimitError\";\n this.retryAfter = retryAfter;\n }\n}\n\nexport class AutolinkNetworkError extends AutolinkError {\n readonly cause: Error;\n\n constructor(message: string, cause: Error) {\n super(message, \"NETWORK_ERROR\", \"\");\n this.name = \"AutolinkNetworkError\";\n this.cause = cause;\n }\n}\n","export interface RetryConfig {\n attempts: number;\n backoff: \"exponential\" | \"linear\";\n}\n\nconst RETRYABLE_STATUS = new Set([500, 502, 503, 504]);\n\nexport function isRetryableStatus(status: number): boolean {\n return RETRYABLE_STATUS.has(status);\n}\n\nexport function backoffMs(attempt: number): number {\n const base = 100 * Math.pow(2, attempt);\n const jitter = Math.random() * 100;\n return Math.min(base + jitter, 10_000);\n}\n\nexport async function sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n","import { GATEWAY_URL, DEFAULT_TIMEOUT_MS, SDK_VERSION } from \"./constants.js\";\nimport {\n AutolinkAuthError,\n AutolinkForbiddenError,\n AutolinkNotFoundError,\n AutolinkValidationError,\n AutolinkRateLimitError,\n AutolinkNetworkError,\n AutolinkError,\n} from \"../errors.js\";\nimport { RetryConfig, isRetryableStatus, backoffMs, sleep } from \"./retry.js\";\n\n// Internal escape hatch for Autolink engineering only — not documented publicly.\n// Silently ignored when NODE_ENV is \"production\".\nfunction resolveGatewayUrl(): string {\n if (\n process.env[\"NODE_ENV\"] !== \"production\" &&\n process.env[\"AUTOLINK_GATEWAY_URL\"]\n ) {\n return `${process.env[\"AUTOLINK_GATEWAY_URL\"]}/sdk/v1`;\n }\n return GATEWAY_URL;\n}\n\nexport interface FetcherConfig {\n apiKey: string;\n timeout: number;\n retry: RetryConfig;\n debug: boolean;\n}\n\ninterface GatewayErrorBody {\n error: {\n code: string;\n message: string;\n fields?: Record<string, string[]>;\n request_id: string;\n };\n}\n\nfunction throwFromResponse(\n status: number,\n body: GatewayErrorBody,\n headers: Headers,\n): never {\n const { code, message, fields, request_id } = body.error;\n const rid = request_id ?? \"\";\n\n if (status === 401) throw new AutolinkAuthError(message, rid);\n if (status === 403) throw new AutolinkForbiddenError(message, rid);\n if (status === 404) throw new AutolinkNotFoundError(message, rid);\n if (status === 400 || status === 422)\n throw new AutolinkValidationError(message, rid, fields ?? {});\n if (status === 429) {\n const retryAfter = parseInt(headers.get(\"Retry-After\") ?? \"60\", 10);\n throw new AutolinkRateLimitError(message, rid, retryAfter);\n }\n throw new AutolinkError(message, code ?? \"GATEWAY_ERROR\", rid);\n}\n\nexport async function gatewayFetch<T>(\n config: FetcherConfig,\n method: string,\n path: string,\n options: {\n params?: Record<string, string | number | boolean | undefined>;\n body?: unknown;\n idempotencyKey?: string;\n signal?: AbortSignal;\n } = {},\n): Promise<T> {\n const base = resolveGatewayUrl();\n const url = new URL(`${base}${path}`);\n\n if (options.params) {\n for (const [k, v] of Object.entries(options.params)) {\n if (v !== undefined) url.searchParams.set(k, String(v));\n }\n }\n\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n \"X-API-Key\": config.apiKey,\n \"X-Autolink-SDK-Version\": SDK_VERSION,\n };\n if (options.idempotencyKey) {\n headers[\"Idempotency-Key\"] = options.idempotencyKey;\n }\n\n const isWrite = method === \"POST\" || method === \"PUT\" || method === \"PATCH\";\n const maxAttempts =\n isWrite && !options.idempotencyKey ? 1 : config.retry.attempts;\n\n let lastError: Error | null = null;\n\n for (let attempt = 0; attempt < maxAttempts; attempt++) {\n if (attempt > 0) await sleep(backoffMs(attempt - 1));\n\n const controller = new AbortController();\n const timeoutId = setTimeout(\n () => controller.abort(),\n config.timeout ?? DEFAULT_TIMEOUT_MS,\n );\n const signal = options.signal ?? controller.signal;\n\n try {\n const res = await fetch(url.toString(), {\n method,\n headers,\n ...(options.body ? { body: JSON.stringify(options.body) } : {}),\n signal,\n });\n clearTimeout(timeoutId);\n\n if (config.debug) {\n const rid = res.headers.get(\"X-Request-ID\") ?? \"\";\n console.debug(`[autolink] ${method} ${path} → ${res.status} (${rid})`);\n }\n\n if (!res.ok) {\n const errorBody = (await res.json()) as GatewayErrorBody;\n\n // Retry on 5xx but not on 4xx\n if (isRetryableStatus(res.status) && attempt < maxAttempts - 1) {\n lastError = new AutolinkError(\n errorBody.error?.message ?? \"Gateway error\",\n errorBody.error?.code ?? \"GATEWAY_ERROR\",\n errorBody.error?.request_id ?? \"\",\n );\n continue;\n }\n\n throwFromResponse(res.status, errorBody, res.headers);\n }\n\n return (await res.json()) as T;\n } catch (err) {\n clearTimeout(timeoutId);\n\n if (err instanceof AutolinkError) throw err;\n\n const networkErr = err instanceof Error ? err : new Error(String(err));\n lastError = new AutolinkNetworkError(\n `Request to Autolink gateway failed: ${networkErr.message}`,\n networkErr,\n );\n\n if (attempt < maxAttempts - 1) continue;\n }\n }\n\n throw (\n lastError ??\n new AutolinkNetworkError(\"Request failed\", new Error(\"Unknown error\"))\n );\n}\n","import { gatewayFetch, FetcherConfig } from \"../transport/fetcher.js\";\nimport type {\n GatewayEnvelope,\n AutolinkVehicle,\n FilterOptions,\n InventoryListFilters,\n} from \"../types/index.js\";\nimport type { AutolinkCache } from \"../cache/index.js\";\n\nconst TTL_LIST = 300; // 5 minutes\nconst TTL_SINGLE = 600; // 10 minutes\nconst TTL_FILTER_OPTIONS = 300;\n\nexport class InventoryResource {\n constructor(\n private config: FetcherConfig,\n private cache?: AutolinkCache,\n ) {}\n\n async list(\n filters: InventoryListFilters = {},\n options?: { ttl?: number },\n ): Promise<GatewayEnvelope<AutolinkVehicle[]>> {\n const ttl = options?.ttl ?? TTL_LIST;\n const key = `autolink:inventory:list:${JSON.stringify(filters)}`;\n if (this.cache && ttl > 0) {\n const cached = await this.cache.get(key);\n if (cached !== undefined)\n return cached as GatewayEnvelope<AutolinkVehicle[]>;\n }\n const result = await gatewayFetch<GatewayEnvelope<AutolinkVehicle[]>>(\n this.config,\n \"GET\",\n \"/inventory\",\n {\n params: filters as Record<\n string,\n string | number | boolean | undefined\n >,\n },\n );\n if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);\n return result;\n }\n\n async get(\n slug: string,\n options?: { ttl?: number },\n ): Promise<GatewayEnvelope<AutolinkVehicle>> {\n const ttl = options?.ttl ?? TTL_SINGLE;\n const key = `autolink:inventory:${slug}`;\n if (this.cache && ttl > 0) {\n const cached = await this.cache.get(key);\n if (cached !== undefined)\n return cached as GatewayEnvelope<AutolinkVehicle>;\n }\n const result = await gatewayFetch<GatewayEnvelope<AutolinkVehicle>>(\n this.config,\n \"GET\",\n `/inventory/${slug}`,\n );\n if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);\n return result;\n }\n\n async filterOptions(options?: {\n ttl?: number;\n }): Promise<GatewayEnvelope<FilterOptions>> {\n const ttl = options?.ttl ?? TTL_FILTER_OPTIONS;\n const key = \"autolink:inventory:filter-options\";\n if (this.cache && ttl > 0) {\n const cached = await this.cache.get(key);\n if (cached !== undefined) return cached as GatewayEnvelope<FilterOptions>;\n }\n const result = await gatewayFetch<GatewayEnvelope<FilterOptions>>(\n this.config,\n \"GET\",\n \"/inventory/filter-options\",\n );\n if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);\n return result;\n }\n\n async *pages(\n filters: Omit<InventoryListFilters, \"page\"> = {},\n ): AsyncGenerator<GatewayEnvelope<AutolinkVehicle[]>> {\n let page = 1;\n while (true) {\n const result = await this.list({ ...filters, page });\n yield result;\n const { pagination } = result.meta;\n if (!pagination || page >= pagination.pages) break;\n page++;\n }\n }\n}\n","import { gatewayFetch, FetcherConfig } from \"../transport/fetcher.js\";\nimport type {\n GatewayEnvelope,\n AutolinkInquiry,\n AutolinkInquiryPayload,\n} from \"../types/index.js\";\nimport { randomUUID } from \"crypto\";\n\nexport interface InquiryCreateOptions {\n idempotencyKey?: string;\n}\n\nexport class InquiriesResource {\n constructor(private config: FetcherConfig) {}\n\n async create(\n payload: AutolinkInquiryPayload,\n options: InquiryCreateOptions = {},\n ): Promise<GatewayEnvelope<AutolinkInquiry>> {\n const idempotencyKey = options.idempotencyKey ?? randomUUID();\n return gatewayFetch<GatewayEnvelope<AutolinkInquiry>>(\n this.config,\n \"POST\",\n \"/inquiries\",\n { body: payload, idempotencyKey },\n );\n }\n}\n","import { gatewayFetch, FetcherConfig } from \"../transport/fetcher.js\";\nimport type { GatewayEnvelope, AutolinkProfile } from \"../types/index.js\";\n\nexport class ProfileResource {\n constructor(private config: FetcherConfig) {}\n\n async get(): Promise<GatewayEnvelope<AutolinkProfile>> {\n return gatewayFetch<GatewayEnvelope<AutolinkProfile>>(\n this.config,\n \"GET\",\n \"/profile\",\n );\n }\n}\n","import { gatewayFetch, FetcherConfig } from \"../transport/fetcher.js\";\nimport type {\n GatewayEnvelope,\n AutolinkArticle,\n ArticleListFilters,\n} from \"../types/index.js\";\nimport type { AutolinkCache } from \"../cache/index.js\";\n\nconst TTL_ARTICLES = 600; // 10 minutes\n\nexport class ArticlesResource {\n constructor(\n private config: FetcherConfig,\n private cache?: AutolinkCache,\n ) {}\n\n async list(\n filters: ArticleListFilters = {},\n options?: { ttl?: number },\n ): Promise<GatewayEnvelope<AutolinkArticle[]>> {\n const ttl = options?.ttl ?? TTL_ARTICLES;\n const key = `autolink:articles:list:${JSON.stringify(filters)}`;\n if (this.cache && ttl > 0) {\n const cached = await this.cache.get(key);\n if (cached !== undefined)\n return cached as GatewayEnvelope<AutolinkArticle[]>;\n }\n const result = await gatewayFetch<GatewayEnvelope<AutolinkArticle[]>>(\n this.config,\n \"GET\",\n \"/articles\",\n {\n params: filters as Record<\n string,\n string | number | boolean | undefined\n >,\n },\n );\n if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);\n return result;\n }\n\n async get(\n slug: string,\n options?: { ttl?: number },\n ): Promise<GatewayEnvelope<AutolinkArticle>> {\n const ttl = options?.ttl ?? TTL_ARTICLES;\n const key = `autolink:articles:${slug}`;\n if (this.cache && ttl > 0) {\n const cached = await this.cache.get(key);\n if (cached !== undefined)\n return cached as GatewayEnvelope<AutolinkArticle>;\n }\n const result = await gatewayFetch<GatewayEnvelope<AutolinkArticle>>(\n this.config,\n \"GET\",\n `/articles/${slug}`,\n );\n if (this.cache && ttl > 0) await this.cache.set(key, result, ttl);\n return result;\n }\n}\n","import { gatewayFetch, FetcherConfig } from \"../transport/fetcher.js\";\nimport type { GatewayEnvelope, IntegrationStatus } from \"../types/index.js\";\n\nexport class IntegrationResource {\n constructor(private config: FetcherConfig) {}\n\n async check(): Promise<GatewayEnvelope<IntegrationStatus>> {\n return gatewayFetch<GatewayEnvelope<IntegrationStatus>>(\n this.config,\n \"GET\",\n \"/integration\",\n );\n }\n}\n","import {\n DEFAULT_TIMEOUT_MS,\n DEFAULT_RETRY_ATTEMPTS,\n} from \"./transport/constants.js\";\nimport type { RetryConfig } from \"./transport/retry.js\";\nimport type { FetcherConfig } from \"./transport/fetcher.js\";\nimport { InventoryResource } from \"./resources/inventory.js\";\nimport { InquiriesResource } from \"./resources/inquiries.js\";\nimport { ProfileResource } from \"./resources/profile.js\";\nimport { ArticlesResource } from \"./resources/articles.js\";\nimport { IntegrationResource } from \"./resources/integration.js\";\nimport type { AutolinkCache } from \"./cache/index.js\";\n\nexport interface AutolinkClientConfig {\n apiKey: string;\n timeout?: number;\n retry?: Partial<RetryConfig>;\n debug?: boolean;\n cache?: AutolinkCache;\n}\n\nexport class AutolinkClient {\n readonly inventory: InventoryResource;\n readonly inquiries: InquiriesResource;\n readonly profile: ProfileResource;\n readonly articles: ArticlesResource;\n readonly integration: IntegrationResource;\n\n constructor(config: AutolinkClientConfig) {\n if (!config.apiKey) {\n throw new Error(\"AutolinkClient: apiKey is required\");\n }\n if (\n !config.apiKey.startsWith(\"gw_live_\") &&\n !config.apiKey.startsWith(\"gw_test_\")\n ) {\n throw new Error(\n 'AutolinkClient: apiKey must start with \"gw_live_\" or \"gw_test_\"',\n );\n }\n\n const fetcherConfig: FetcherConfig = {\n apiKey: config.apiKey,\n timeout: config.timeout ?? DEFAULT_TIMEOUT_MS,\n retry: {\n attempts: config.retry?.attempts ?? DEFAULT_RETRY_ATTEMPTS,\n backoff: config.retry?.backoff ?? \"exponential\",\n },\n debug: config.debug ?? false,\n };\n\n this.inventory = new InventoryResource(fetcherConfig, config.cache);\n this.inquiries = new InquiriesResource(fetcherConfig);\n this.profile = new ProfileResource(fetcherConfig);\n this.articles = new ArticlesResource(fetcherConfig, config.cache);\n this.integration = new IntegrationResource(fetcherConfig);\n }\n}\n","export interface AutolinkCache {\n get(key: string): Promise<unknown> | unknown;\n set(key: string, value: unknown, ttlSeconds?: number): Promise<void> | void;\n delete(key: string): Promise<void> | void;\n}\n\ninterface CacheEntry {\n value: unknown;\n expiresAt: number | null; // null = no expiry\n}\n\nconst MAX_ENTRIES = 200;\n\nexport class MemoryCache implements AutolinkCache {\n private store = new Map<string, CacheEntry>();\n\n get(key: string): unknown {\n const entry = this.store.get(key);\n if (!entry) return undefined;\n if (entry.expiresAt !== null && Date.now() > entry.expiresAt) {\n this.store.delete(key);\n return undefined;\n }\n return entry.value;\n }\n\n set(key: string, value: unknown, ttlSeconds?: number): void {\n // Evict oldest entry if at capacity and key is new\n if (this.store.size >= MAX_ENTRIES && !this.store.has(key)) {\n const oldestKey = this.store.keys().next().value;\n if (oldestKey !== undefined) {\n this.store.delete(oldestKey);\n }\n }\n this.store.set(key, {\n value,\n expiresAt: ttlSeconds != null ? Date.now() + ttlSeconds * 1000 : null,\n });\n }\n\n delete(key: string): void {\n this.store.delete(key);\n }\n\n /** Remove all expired entries. Optional maintenance call. */\n purgeExpired(): void {\n const now = Date.now();\n for (const [key, entry] of this.store) {\n if (entry.expiresAt !== null && now > entry.expiresAt) {\n this.store.delete(key);\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,mBAAmB;AACzB,IAAM,sBAAsB;AAC5B,IAAM,cAAc,GAAG,gBAAgB,QAAQ,mBAAmB;AAElE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