@uveysservetoglu/kobil-chat 1.0.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 ADDED
@@ -0,0 +1,57 @@
1
+ # @uveysservetoglu/kobil-chat
2
+
3
+ KOBIL Chat (Mercury) client for Node.js / TypeScript, with automatic OAuth token management.
4
+
5
+ ```bash
6
+ npm install @uveysservetoglu/kobil-chat
7
+ ```
8
+
9
+ ```ts
10
+ import { ChatClient } from "@uveysservetoglu/kobil-chat";
11
+
12
+ const chat = new ChatClient({
13
+ // credentials (or KOBIL_* env vars):
14
+ tokenEndpoint: process.env.KOBIL_TOKEN_ENDPOINT!,
15
+ clientId: process.env.KOBIL_CLIENT_ID!,
16
+ clientSecret: process.env.KOBIL_CLIENT_SECRET!,
17
+ tokenAuthMode: "basic", // the chat token endpoint may require Basic auth
18
+ // chat-specific:
19
+ chatBaseUrl: "https://idp.cloud.kobil.com/auth/realms/{TENANT}/mpower/v1/users/{USER_ID}",
20
+ tenantName: "acme",
21
+ mediaDownloadUrl: "https://idp.cloud.kobil.com/v1/mpower/tenants/{TENANT}/media/{MEDIA_ID}/download",
22
+ });
23
+ ```
24
+
25
+ `{TENANT}` is filled from `tenantName`, `{USER_ID}` from the call, `{MEDIA_ID}` from
26
+ `getAttachmentFile`. `/message` or `/media` is appended to `chatBaseUrl` per operation.
27
+ Message text supports styling: `*bold*`, `_italic_`, `~strike~`, `\n`.
28
+
29
+ ## The five operations
30
+
31
+ ```ts
32
+ // 1. Plain text
33
+ await chat.sendText({ userId, text: "Hi, how are you?", title: "Update" });
34
+
35
+ // 2. Multi-choice
36
+ await chat.sendChoice({ userId, text: "Continue?", choices: ["Yes", "No"] });
37
+
38
+ // 3. SmartScreen
39
+ await chat.sendSmartScreen({ userId, text: "Opening…", smartScreenServiceUuid: "service_client_id" });
40
+
41
+ // 4. Attachment (content type inferred from the file name)
42
+ await chat.sendAttachment({ userId, file: pdfBytes, fileName: "agreement.pdf", text: "Please review" });
43
+
44
+ // 5. Download media
45
+ const bytes = await chat.getAttachmentFile(mediaId);
46
+ ```
47
+
48
+ All send operations return `{ messageId, instanceId }`. JavaScript usage is identical
49
+ (`const { ChatClient } = require("@uveysservetoglu/kobil-chat")`).
50
+
51
+ ## Errors
52
+
53
+ Failures throw `KobilChatError` (extends `KobilError`) with `statusCode` / `responseBody`.
54
+
55
+ ## License
56
+
57
+ MIT
@@ -0,0 +1,39 @@
1
+ import { KobilCredentials, KobilError, KobilServiceClient, TokenProvider } from "@uveysservetoglu/kobil-core";
2
+ import { ChatMessageResult, SendAttachmentInput, SendChoiceInput, SendSmartScreenInput, SendTextInput } from "./types";
3
+ export interface ChatClientOptions extends Partial<KobilCredentials> {
4
+ /** Message endpoint template up to the user segment, with {TENANT} and {USER_ID}. */
5
+ chatBaseUrl: string;
6
+ /** Media download template with {TENANT} and {MEDIA_ID}. Required for getAttachmentFile. */
7
+ mediaDownloadUrl?: string;
8
+ /** Tenant/realm name substituted for {TENANT}. */
9
+ tenantName?: string;
10
+ /** serviceUuid sent with messages. Optional: defaults to clientId. */
11
+ serviceUuid?: string;
12
+ /** Wire protocol version. Default: 3. */
13
+ version?: number;
14
+ /** Escape non-ASCII in the attachment message part (backend compatibility). Default: true. */
15
+ escapeAttachmentUnicode?: boolean;
16
+ tokenProvider?: TokenProvider;
17
+ }
18
+ /** Client for the KOBIL Chat (Mercury) API. */
19
+ export declare class ChatClient extends KobilServiceClient {
20
+ private readonly chatBaseUrl;
21
+ private readonly mediaDownloadUrl?;
22
+ private readonly tenantName?;
23
+ private readonly clientId;
24
+ private readonly serviceUuidOption?;
25
+ private readonly version;
26
+ private readonly escapeUnicode;
27
+ constructor(options: ChatClientOptions);
28
+ protected makeError(message: string, statusCode?: number, responseBody?: string, cause?: unknown): KobilError;
29
+ sendText(input: SendTextInput, signal?: AbortSignal): Promise<ChatMessageResult>;
30
+ sendChoice(input: SendChoiceInput, signal?: AbortSignal): Promise<ChatMessageResult>;
31
+ sendSmartScreen(input: SendSmartScreenInput, signal?: AbortSignal): Promise<ChatMessageResult>;
32
+ sendAttachment(input: SendAttachmentInput, signal?: AbortSignal): Promise<ChatMessageResult>;
33
+ getAttachmentFile(mediaId: string, signal?: AbortSignal): Promise<Uint8Array>;
34
+ private messageUrl;
35
+ private mediaUrl;
36
+ private userBaseUrl;
37
+ private serviceUuid;
38
+ }
39
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,gBAAgB,EAChB,UAAU,EACV,kBAAkB,EAClB,aAAa,EAEd,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,oBAAoB,EACpB,aAAa,EACd,MAAM,SAAS,CAAC;AAEjB,MAAM,WAAW,iBAAkB,SAAQ,OAAO,CAAC,gBAAgB,CAAC;IAClE,qFAAqF;IACrF,WAAW,EAAE,MAAM,CAAC;IACpB,4FAA4F;IAC5F,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,kDAAkD;IAClD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,sEAAsE;IACtE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yCAAyC;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8FAA8F;IAC9F,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AAED,+CAA+C;AAC/C,qBAAa,UAAW,SAAQ,kBAAkB;IAChD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAS;IAC5C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAU;gBAE5B,OAAO,EAAE,iBAAiB;cAsBnB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,UAAU;IAItH,QAAQ,CAAC,KAAK,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAUhF,UAAU,CAAC,KAAK,EAAE,eAAe,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAcpF,eAAe,CAAC,KAAK,EAAE,oBAAoB,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAc9F,cAAc,CAAC,KAAK,EAAE,mBAAmB,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAqBtF,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;IAOnF,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,WAAW;CAGpB"}
package/dist/client.js ADDED
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChatClient = void 0;
4
+ const kobil_core_1 = require("@uveysservetoglu/kobil-core");
5
+ const error_1 = require("./error");
6
+ const mime_1 = require("./mime");
7
+ /** Client for the KOBIL Chat (Mercury) API. */
8
+ class ChatClient extends kobil_core_1.KobilServiceClient {
9
+ chatBaseUrl;
10
+ mediaDownloadUrl;
11
+ tenantName;
12
+ clientId;
13
+ serviceUuidOption;
14
+ version;
15
+ escapeUnicode;
16
+ constructor(options) {
17
+ const credentials = (0, kobil_core_1.credentialsFromEnv)({
18
+ tokenEndpoint: options.tokenEndpoint,
19
+ clientId: options.clientId,
20
+ clientSecret: options.clientSecret,
21
+ tokenAuthMode: options.tokenAuthMode,
22
+ defaultTokenTtlSeconds: options.defaultTokenTtlSeconds,
23
+ tokenExpirySkewSeconds: options.tokenExpirySkewSeconds,
24
+ });
25
+ super(options.tokenProvider ?? new kobil_core_1.DefaultTokenProvider(credentials));
26
+ if (!options.chatBaseUrl)
27
+ throw new kobil_core_1.KobilError("chatBaseUrl is required.");
28
+ this.chatBaseUrl = options.chatBaseUrl;
29
+ this.mediaDownloadUrl = options.mediaDownloadUrl;
30
+ this.tenantName = options.tenantName;
31
+ this.clientId = credentials.clientId;
32
+ this.serviceUuidOption = options.serviceUuid;
33
+ this.version = options.version ?? 3;
34
+ this.escapeUnicode = options.escapeAttachmentUnicode ?? true;
35
+ }
36
+ makeError(message, statusCode, responseBody, cause) {
37
+ return new error_1.KobilChatError(message, { statusCode, responseBody, cause });
38
+ }
39
+ sendText(input, signal) {
40
+ if (!input.userId)
41
+ throw new error_1.KobilChatError("userId cannot be empty.");
42
+ return this.sendJson("POST", this.messageUrl(input.userId), {
43
+ serviceUuid: this.serviceUuid(),
44
+ messageType: "processChatMessage",
45
+ version: this.version,
46
+ messageContent: { messageText: composeText(input.title, input.text) },
47
+ }, signal);
48
+ }
49
+ sendChoice(input, signal) {
50
+ if (!input.userId)
51
+ throw new error_1.KobilChatError("userId cannot be empty.");
52
+ if (!input.choices || input.choices.length === 0)
53
+ throw new error_1.KobilChatError("At least one choice is required.");
54
+ return this.sendJson("POST", this.messageUrl(input.userId), {
55
+ serviceUuid: this.serviceUuid(),
56
+ messageType: "choiceRequest",
57
+ version: this.version,
58
+ messageContent: {
59
+ messageText: input.text ?? "",
60
+ choices: input.choices.map((text) => ({ text })),
61
+ },
62
+ }, signal);
63
+ }
64
+ sendSmartScreen(input, signal) {
65
+ if (!input.userId)
66
+ throw new error_1.KobilChatError("userId cannot be empty.");
67
+ if (!input.smartScreenServiceUuid)
68
+ throw new error_1.KobilChatError("smartScreenServiceUuid cannot be empty.");
69
+ return this.sendJson("POST", this.messageUrl(input.userId), {
70
+ serviceUuid: this.serviceUuid(),
71
+ messageType: "smartScreenService",
72
+ version: this.version,
73
+ messageContent: {
74
+ messageText: input.text ?? "",
75
+ smartScreenServiceUuid: input.smartScreenServiceUuid,
76
+ },
77
+ }, signal);
78
+ }
79
+ sendAttachment(input, signal) {
80
+ if (!input.userId)
81
+ throw new error_1.KobilChatError("userId cannot be empty.");
82
+ if (!input.file || input.file.length === 0)
83
+ throw new error_1.KobilChatError("file cannot be empty.");
84
+ const message = {
85
+ serviceUuid: this.serviceUuid(),
86
+ messageType: "attachmentMessage",
87
+ version: this.version,
88
+ messageContent: { messageText: composeAttachmentText(input.title, input.text) },
89
+ };
90
+ let messageJson = JSON.stringify(message);
91
+ if (this.escapeUnicode)
92
+ messageJson = (0, mime_1.escapeNonAscii)(messageJson);
93
+ const form = new FormData();
94
+ const blob = new Blob([input.file], { type: (0, mime_1.resolveContentType)(input) });
95
+ form.append("attachment", blob, (0, mime_1.resolveFileName)(input));
96
+ form.append("message", messageJson);
97
+ return this.send("POST", this.mediaUrl(input.userId), form, signal);
98
+ }
99
+ async getAttachmentFile(mediaId, signal) {
100
+ if (!mediaId)
101
+ throw new error_1.KobilChatError("mediaId cannot be empty.");
102
+ if (!this.mediaDownloadUrl)
103
+ throw new kobil_core_1.KobilError("mediaDownloadUrl is required to download attachments.");
104
+ const url = replaceTokens(this.mediaDownloadUrl, { "{TENANT}": this.tenantName, "{MEDIA_ID}": mediaId });
105
+ return this.sendForBytes("POST", url, signal);
106
+ }
107
+ messageUrl(userId) {
108
+ return `${this.userBaseUrl(userId)}/message`;
109
+ }
110
+ mediaUrl(userId) {
111
+ return `${this.userBaseUrl(userId)}/media`;
112
+ }
113
+ userBaseUrl(userId) {
114
+ return replaceTokens(this.chatBaseUrl, { "{TENANT}": this.tenantName, "{USER_ID}": userId }).replace(/\/+$/, "");
115
+ }
116
+ serviceUuid() {
117
+ return this.serviceUuidOption && this.serviceUuidOption.length > 0 ? this.serviceUuidOption : this.clientId;
118
+ }
119
+ }
120
+ exports.ChatClient = ChatClient;
121
+ function composeText(title, text) {
122
+ return title ? `${title}\n\n${text}` : text ?? "";
123
+ }
124
+ function composeAttachmentText(title, text) {
125
+ let out = "";
126
+ if (title)
127
+ out += `*${title}*`;
128
+ if (title && text)
129
+ out += `\n\n${text}`;
130
+ else if (!title && text)
131
+ out += text;
132
+ return out;
133
+ }
134
+ function replaceTokens(template, tokens) {
135
+ let result = template;
136
+ for (const [token, value] of Object.entries(tokens)) {
137
+ result = result.split(token).join(encodeURIComponent(value ?? ""));
138
+ }
139
+ return result;
140
+ }
141
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAAA,4DAOqC;AACrC,mCAAyC;AACzC,iCAA6E;AAyB7E,+CAA+C;AAC/C,MAAa,UAAW,SAAQ,+BAAkB;IAC/B,WAAW,CAAS;IACpB,gBAAgB,CAAU;IAC1B,UAAU,CAAU;IACpB,QAAQ,CAAS;IACjB,iBAAiB,CAAU;IAC3B,OAAO,CAAS;IAChB,aAAa,CAAU;IAExC,YAAY,OAA0B;QACpC,MAAM,WAAW,GAAG,IAAA,+BAAkB,EAAC;YACrC,aAAa,EAAE,OAAO,CAAC,aAAa;YACpC,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,aAAa,EAAE,OAAO,CAAC,aAAa;YACpC,sBAAsB,EAAE,OAAO,CAAC,sBAAsB;YACtD,sBAAsB,EAAE,OAAO,CAAC,sBAAsB;SACvD,CAAC,CAAC;QACH,KAAK,CAAC,OAAO,CAAC,aAAa,IAAI,IAAI,iCAAoB,CAAC,WAAW,CAAC,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1D,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,KAAK;QAAE,GAAG,IAAI,IAAI,KAAK,GAAG,CAAC;IAC/B,IAAI,KAAK,IAAI,IAAI;QAAE,GAAG,IAAI,OAAO,IAAI,EAAE,CAAC;SACnC,IAAI,CAAC,KAAK,IAAI,IAAI;QAAE,GAAG,IAAI,IAAI,CAAC;IACrC,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,aAAa,CAAC,QAAgB,EAAE,MAA0C;IACjF,IAAI,MAAM,GAAG,QAAQ,CAAC;IACtB,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACpD,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC;IACrE,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { KobilError } from "@uveysservetoglu/kobil-core";
2
+ /** Thrown when a chat operation fails. */
3
+ export declare class KobilChatError extends KobilError {
4
+ }
5
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEzD,0CAA0C;AAC1C,qBAAa,cAAe,SAAQ,UAAU;CAAG"}
package/dist/error.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KobilChatError = void 0;
4
+ const kobil_core_1 = require("@uveysservetoglu/kobil-core");
5
+ /** Thrown when a chat operation fails. */
6
+ class KobilChatError extends kobil_core_1.KobilError {
7
+ }
8
+ exports.KobilChatError = KobilChatError;
9
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":";;;AAAA,4DAAyD;AAEzD,0CAA0C;AAC1C,MAAa,cAAe,SAAQ,uBAAU;CAAG;AAAjD,wCAAiD"}
@@ -0,0 +1,5 @@
1
+ export { ChatClient } from "./client";
2
+ export type { ChatClientOptions } from "./client";
3
+ export { KobilChatError } from "./error";
4
+ export type { SendTextInput, SendChoiceInput, SendSmartScreenInput, SendAttachmentInput, ChatMessageResult, } from "./types";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,YAAY,EACV,aAAa,EACb,eAAe,EACf,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KobilChatError = exports.ChatClient = void 0;
4
+ var client_1 = require("./client");
5
+ Object.defineProperty(exports, "ChatClient", { enumerable: true, get: function () { return client_1.ChatClient; } });
6
+ var error_1 = require("./error");
7
+ Object.defineProperty(exports, "KobilChatError", { enumerable: true, get: function () { return error_1.KobilChatError; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAsC;AAA7B,oGAAA,UAAU,OAAA;AAEnB,iCAAyC;AAAhC,uGAAA,cAAc,OAAA"}
package/dist/mime.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { SendAttachmentInput } from "./types";
2
+ export declare function resolveContentType(input: SendAttachmentInput): string;
3
+ export declare function resolveFileName(input: SendAttachmentInput): string;
4
+ /** Escapes non-ASCII characters to \uXXXX sequences (backend compatibility). */
5
+ export declare function escapeNonAscii(text: string): string;
6
+ //# sourceMappingURL=mime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mime.d.ts","sourceRoot":"","sources":["../src/mime.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AA8B9C,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,mBAAmB,GAAG,MAAM,CAQrE;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,mBAAmB,GAAG,MAAM,CAKlE;AAED,gFAAgF;AAChF,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOnD"}
package/dist/mime.js ADDED
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveContentType = resolveContentType;
4
+ exports.resolveFileName = resolveFileName;
5
+ exports.escapeNonAscii = escapeNonAscii;
6
+ const crypto_1 = require("crypto");
7
+ const MIME_BY_EXT = {
8
+ ".png": "image/png",
9
+ ".jpg": "image/jpeg",
10
+ ".jpeg": "image/jpeg",
11
+ ".gif": "image/gif",
12
+ ".bmp": "image/bmp",
13
+ ".webp": "image/webp",
14
+ ".svg": "image/svg+xml",
15
+ ".pdf": "application/pdf",
16
+ ".doc": "application/msword",
17
+ ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
18
+ ".xls": "application/vnd.ms-excel",
19
+ ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
20
+ ".ppt": "application/vnd.ms-powerpoint",
21
+ ".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
22
+ ".txt": "text/plain",
23
+ ".csv": "text/csv",
24
+ ".json": "application/json",
25
+ ".xml": "application/xml",
26
+ ".zip": "application/zip",
27
+ ".rar": "application/vnd.rar",
28
+ ".7z": "application/x-7z-compressed",
29
+ ".mp3": "audio/mpeg",
30
+ ".mp4": "video/mp4",
31
+ ".avi": "video/x-msvideo",
32
+ ".mov": "video/quicktime",
33
+ };
34
+ function resolveContentType(input) {
35
+ if (input.contentType)
36
+ return input.contentType;
37
+ let ext = input.fileExtension?.toLowerCase();
38
+ if (!ext && input.fileName) {
39
+ const idx = input.fileName.lastIndexOf(".");
40
+ ext = idx >= 0 ? input.fileName.slice(idx).toLowerCase() : undefined;
41
+ }
42
+ return (ext && MIME_BY_EXT[ext]) || "application/octet-stream";
43
+ }
44
+ function resolveFileName(input) {
45
+ if (input.fileName)
46
+ return input.fileName;
47
+ let ext = input.fileExtension?.toLowerCase() ?? ".bin";
48
+ if (!ext.startsWith("."))
49
+ ext = "." + ext;
50
+ return `${(0, crypto_1.randomUUID)()}${ext}`;
51
+ }
52
+ /** Escapes non-ASCII characters to \uXXXX sequences (backend compatibility). */
53
+ function escapeNonAscii(text) {
54
+ let out = "";
55
+ for (const ch of text) {
56
+ const code = ch.codePointAt(0);
57
+ out += code > 127 ? "\\u" + code.toString(16).padStart(4, "0") : ch;
58
+ }
59
+ return out;
60
+ }
61
+ //# sourceMappingURL=mime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mime.js","sourceRoot":"","sources":["../src/mime.ts"],"names":[],"mappings":";;AA+BA,gDAQC;AAED,0CAKC;AAGD,wCAOC;AAxDD,mCAAoC;AAGpC,MAAM,WAAW,GAA2B;IAC1C,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,YAAY;IACpB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,WAAW;IACnB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,eAAe;IACvB,MAAM,EAAE,iBAAiB;IACzB,MAAM,EAAE,oBAAoB;IAC5B,OAAO,EAAE,yEAAyE;IAClF,MAAM,EAAE,0BAA0B;IAClC,OAAO,EAAE,mEAAmE;IAC5E,MAAM,EAAE,+BA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C;AACjC,CAAC;AAED,gFAAgF;AAChF,SAAgB,cAAc,CAAC,IAAY;IACzC,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,KAAK,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC;QACtB,MAAM,IAAI,GAAG,EAAE,CAAC,WAAW,CAAC,CAAC,CAAE,CAAC;QAChC,GAAG,IAAI,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACtE,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,35 @@
1
+ export interface SendTextInput {
2
+ userId: string;
3
+ /** Message body. Supports styling: *bold*, _italic_, ~strike~, \n. */
4
+ text: string;
5
+ title?: string;
6
+ }
7
+ export interface SendChoiceInput {
8
+ userId: string;
9
+ text: string;
10
+ choices: string[];
11
+ }
12
+ export interface SendSmartScreenInput {
13
+ userId: string;
14
+ text: string;
15
+ smartScreenServiceUuid: string;
16
+ }
17
+ export interface SendAttachmentInput {
18
+ userId: string;
19
+ /** Raw file bytes. */
20
+ file: Uint8Array;
21
+ /** File name. If omitted, one is generated from the extension. */
22
+ fileName?: string;
23
+ /** MIME type. If omitted, inferred from the file name/extension. */
24
+ contentType?: string;
25
+ /** Extension (e.g. ".png") used to infer content type / file name when not given. */
26
+ fileExtension?: string;
27
+ title?: string;
28
+ text?: string;
29
+ }
30
+ export interface ChatMessageResult {
31
+ messageId?: string;
32
+ instanceId?: string;
33
+ [key: string]: unknown;
34
+ }
35
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,sEAAsE;IACtE,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,sBAAsB,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,sBAAsB;IACtB,IAAI,EAAE,UAAU,CAAC;IACjB,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oEAAoE;IACpE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qFAAqF;IACrF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB"}
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@uveysservetoglu/kobil-chat",
3
+ "version": "1.0.0",
4
+ "description": "KOBIL Chat (Mercury) client for Node.js: send text, multi-choice and SmartScreen messages, send attachments and download media, with automatic OAuth token management.",
5
+ "license": "MIT",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "keywords": [
12
+ "kobil",
13
+ "chat",
14
+ "mercury",
15
+ "messaging"
16
+ ],
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/uveysservetoglu/kobil-sdks"
20
+ },
21
+ "dependencies": {
22
+ "@uveysservetoglu/kobil-core": "^1.0.0"
23
+ },
24
+ "scripts": {
25
+ "build": "tsc -b"
26
+ }
27
+ }