@diegoaltoworks/chatter 0.35.0 → 0.36.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.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +36 -0
- package/dist/index.mjs +35 -0
- package/dist/shortener.d.ts +24 -0
- package/dist/shortener.d.ts.map +1 -0
- package/dist/shortener.test.d.ts +2 -0
- package/dist/shortener.test.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -42,5 +42,7 @@ export { privateRoutes } from "./routes/private";
|
|
|
42
42
|
export { publicRoutes } from "./routes/public";
|
|
43
43
|
export type { ChatterApp } from "./server";
|
|
44
44
|
export { createServer } from "./server";
|
|
45
|
+
export type { Shortener, ShortenerConfig } from "./shortener";
|
|
46
|
+
export { createShortener } from "./shortener";
|
|
45
47
|
export type { BotBranding, BotChatConfig, BotIdentity, ChatterConfig, CustomRoutes, EmbeddingChunk, KnowledgeDocument, ServerDependencies, } from "./types";
|
|
46
48
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEzE,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAIvC,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,YAAY,EACV,aAAa,EACb,gBAAgB,EAChB,UAAU,EACV,WAAW,EACX,QAAQ,EACR,eAAe,GAChB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACrD,YAAY,EACV,QAAQ,EACR,aAAa,EACb,cAAc,E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AAM,aAAa,CAAC;AAE9C,YAAY,EACV,WAAW,EACX,aAAa,EACb,WAAW,EACX,aAAa,EACb,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -7550,6 +7550,7 @@ __export(index_exports, {
|
|
|
7550
7550
|
createServer: () => createServer,
|
|
7551
7551
|
createSession: () => createSession,
|
|
7552
7552
|
createSessionMiddleware: () => createSessionMiddleware,
|
|
7553
|
+
createShortener: () => createShortener,
|
|
7553
7554
|
defaultBuckets: () => defaultBuckets,
|
|
7554
7555
|
demoRoutes: () => demoRoutes,
|
|
7555
7556
|
detectLeakage: () => detectLeakage,
|
|
@@ -33396,6 +33397,40 @@ async function createServer(config2) {
|
|
|
33396
33397
|
}
|
|
33397
33398
|
});
|
|
33398
33399
|
}
|
|
33400
|
+
|
|
33401
|
+
// src/shortener.ts
|
|
33402
|
+
var DEFAULT_TIMEOUT_MS = 5e3;
|
|
33403
|
+
function createShortener(config2, fetchImpl = fetch) {
|
|
33404
|
+
const apiUrl = config2.apiUrl.replace(/\/+$/, "");
|
|
33405
|
+
return {
|
|
33406
|
+
async shorten(url2) {
|
|
33407
|
+
const controller = new AbortController();
|
|
33408
|
+
const timeout = setTimeout(() => controller.abort(), config2.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
33409
|
+
try {
|
|
33410
|
+
const response = await fetchImpl(`${apiUrl}/api/v2/links`, {
|
|
33411
|
+
method: "POST",
|
|
33412
|
+
headers: {
|
|
33413
|
+
"Content-Type": "application/json",
|
|
33414
|
+
"X-API-Key": config2.apiKey
|
|
33415
|
+
},
|
|
33416
|
+
body: JSON.stringify({ target: url2, domain: config2.domain }),
|
|
33417
|
+
signal: controller.signal
|
|
33418
|
+
});
|
|
33419
|
+
if (!response.ok) {
|
|
33420
|
+
await response.text().catch(() => "");
|
|
33421
|
+
return url2;
|
|
33422
|
+
}
|
|
33423
|
+
const data = await response.json();
|
|
33424
|
+
if (typeof data.link !== "string") return url2;
|
|
33425
|
+
return data.link.replace(/^http:\/\//, "https://");
|
|
33426
|
+
} catch {
|
|
33427
|
+
return url2;
|
|
33428
|
+
} finally {
|
|
33429
|
+
clearTimeout(timeout);
|
|
33430
|
+
}
|
|
33431
|
+
}
|
|
33432
|
+
};
|
|
33433
|
+
}
|
|
33399
33434
|
// Annotate the CommonJS export names for ESM import in node:
|
|
33400
33435
|
0 && (module.exports = {
|
|
33401
33436
|
ApiKeyManager,
|
|
@@ -33418,6 +33453,7 @@ async function createServer(config2) {
|
|
|
33418
33453
|
createServer,
|
|
33419
33454
|
createSession,
|
|
33420
33455
|
createSessionMiddleware,
|
|
33456
|
+
createShortener,
|
|
33421
33457
|
defaultBuckets,
|
|
33422
33458
|
demoRoutes,
|
|
33423
33459
|
detectLeakage,
|
package/dist/index.mjs
CHANGED
|
@@ -33358,6 +33358,40 @@ async function createServer(config2) {
|
|
|
33358
33358
|
}
|
|
33359
33359
|
});
|
|
33360
33360
|
}
|
|
33361
|
+
|
|
33362
|
+
// src/shortener.ts
|
|
33363
|
+
var DEFAULT_TIMEOUT_MS = 5e3;
|
|
33364
|
+
function createShortener(config2, fetchImpl = fetch) {
|
|
33365
|
+
const apiUrl = config2.apiUrl.replace(/\/+$/, "");
|
|
33366
|
+
return {
|
|
33367
|
+
async shorten(url2) {
|
|
33368
|
+
const controller = new AbortController();
|
|
33369
|
+
const timeout = setTimeout(() => controller.abort(), config2.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
33370
|
+
try {
|
|
33371
|
+
const response = await fetchImpl(`${apiUrl}/api/v2/links`, {
|
|
33372
|
+
method: "POST",
|
|
33373
|
+
headers: {
|
|
33374
|
+
"Content-Type": "application/json",
|
|
33375
|
+
"X-API-Key": config2.apiKey
|
|
33376
|
+
},
|
|
33377
|
+
body: JSON.stringify({ target: url2, domain: config2.domain }),
|
|
33378
|
+
signal: controller.signal
|
|
33379
|
+
});
|
|
33380
|
+
if (!response.ok) {
|
|
33381
|
+
await response.text().catch(() => "");
|
|
33382
|
+
return url2;
|
|
33383
|
+
}
|
|
33384
|
+
const data = await response.json();
|
|
33385
|
+
if (typeof data.link !== "string") return url2;
|
|
33386
|
+
return data.link.replace(/^http:\/\//, "https://");
|
|
33387
|
+
} catch {
|
|
33388
|
+
return url2;
|
|
33389
|
+
} finally {
|
|
33390
|
+
clearTimeout(timeout);
|
|
33391
|
+
}
|
|
33392
|
+
}
|
|
33393
|
+
};
|
|
33394
|
+
}
|
|
33361
33395
|
var export_Chat = import_client3.Chat;
|
|
33362
33396
|
var export_ChatBot = import_client3.ChatBot;
|
|
33363
33397
|
var export_ChatButton = import_client3.ChatButton;
|
|
@@ -33382,6 +33416,7 @@ export {
|
|
|
33382
33416
|
createServer,
|
|
33383
33417
|
createSession,
|
|
33384
33418
|
createSessionMiddleware,
|
|
33419
|
+
createShortener,
|
|
33385
33420
|
defaultBuckets,
|
|
33386
33421
|
demoRoutes,
|
|
33387
33422
|
detectLeakage,
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* URL shortening against a Kutt-compatible API, config-injected (no
|
|
3
|
+
* `process.env` reads) so hosts can wire credentials however they like.
|
|
4
|
+
*
|
|
5
|
+
* The hard invariant: {@link Shortener.shorten} never throws. Any failure —
|
|
6
|
+
* network error, an aborted request past `timeoutMs`, or a non-2xx/malformed
|
|
7
|
+
* response — resolves to the original URL, since a shortener outage must
|
|
8
|
+
* never break something user-facing that only wanted a shorter link.
|
|
9
|
+
*/
|
|
10
|
+
export interface ShortenerConfig {
|
|
11
|
+
/** Base URL of the Kutt (or Kutt-compatible) instance, e.g. "https://kutt.it". */
|
|
12
|
+
apiUrl: string;
|
|
13
|
+
apiKey: string;
|
|
14
|
+
/** Custom short domain configured on the Kutt instance, if any. */
|
|
15
|
+
domain?: string;
|
|
16
|
+
/** Abort the request after this many milliseconds. Defaults to 5000. */
|
|
17
|
+
timeoutMs?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface Shortener {
|
|
20
|
+
/** Resolves to the shortened URL, or the input `url` unchanged on any failure. */
|
|
21
|
+
shorten(url: string): Promise<string>;
|
|
22
|
+
}
|
|
23
|
+
export declare function createShortener(config: ShortenerConfig, fetchImpl?: typeof fetch): Shortener;
|
|
24
|
+
//# sourceMappingURL=shortener.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shortener.d.ts","sourceRoot":"","sources":["../src/shortener.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,WAAW,eAAe;IAC9B,kFAAkF;IAClF,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,mEAAmE;IACnE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wEAAwE;IACxE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,SAAS;IACxB,kFAAkF;IAClF,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACvC;AAQD,wBAAgB,eAAe,CAC7B,MAAM,EAAE,eAAe,EACvB,SAAS,GAAE,OAAO,KAAa,GAC9B,SAAS,CAqCX"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shortener.test.d.ts","sourceRoot":"","sources":["../src/shortener.test.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED