@ecodrix/erix-api 3.1.1 → 3.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.
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Website chat (webchat) shapes shared by the visitor client
3
+ * (`@ecodrix/erix-api/visitor`) and the workspace client. Types only: this
4
+ * file must never import runtime code, so the visitor bundle stays small.
5
+ */
6
+ /**
7
+ * A message as a website visitor sees it (`messages()`, the live
8
+ * `webchat.message` event). Nothing else from the stored row is exposed.
9
+ */
10
+ interface VisitorMessage {
11
+ id: string;
12
+ direction: "inbound" | "outbound";
13
+ text: string;
14
+ /** ISO timestamp. */
15
+ createdAt: string;
16
+ /** Who wrote it: the visitor, the AI assistant, a team member, or a system notice. */
17
+ from: "visitor" | "ai" | "team" | "system";
18
+ /** Team replies only, and only when the workspace shows staff names. */
19
+ senderFirstName?: string;
20
+ }
21
+ /**
22
+ * The live `webchat.typing` event. `waiting: true` (with `on: false`) means
23
+ * the AI left the reply to the team: show "The team will reply here".
24
+ */
25
+ interface VisitorTyping {
26
+ on: boolean;
27
+ waiting?: boolean;
28
+ }
29
+ /** The website chat widget's settings (`service_config.webchat`). */
30
+ interface WebchatSettings {
31
+ /**
32
+ * Sites the widget may run on. Read-only here: add one with `domain`,
33
+ * remove one with `connections.removeWebchatDomain`.
34
+ */
35
+ allowedDomains: string[];
36
+ /** Up to 60 characters. */
37
+ name?: string;
38
+ /** Up to 200 characters. */
39
+ greeting?: string;
40
+ /** `#rrggbb`. */
41
+ color?: string;
42
+ /** Default `right`. */
43
+ position?: "left" | "right";
44
+ /** `https://` only. */
45
+ logoUrl?: string;
46
+ /** When the widget asks for name and phone/email. Default `when_needed`. */
47
+ detailsMode?: "before" | "when_needed" | "off";
48
+ /** Up to 80 characters, e.g. "We reply 10 am to 7 pm". */
49
+ hoursText?: string;
50
+ /** Show a team member's first name on their replies. Default true. */
51
+ showStaffNames?: boolean;
52
+ }
53
+ /**
54
+ * The website chat as its owner edits it (`connections.webchatSettings()`):
55
+ * the sites it may run on in plain text, the plan's cap on them, and the
56
+ * saved settings (a setting left at its default is absent).
57
+ */
58
+ interface WebchatOwnerSettings {
59
+ allowedDomains: string[];
60
+ /** How many sites the plan allows. */
61
+ maxDomains: number;
62
+ settings: Omit<WebchatSettings, "allowedDomains">;
63
+ }
64
+ /**
65
+ * A settings save: send only what changes; `null` clears a setting back to
66
+ * its default. `domain` adds a site to the allowed domains (plan-capped).
67
+ */
68
+ type WebchatSettingsPatch = {
69
+ [K in Exclude<keyof WebchatSettings, "allowedDomains">]?: WebchatSettings[K] | null;
70
+ } & {
71
+ /** A site to add to the allowed domains, e.g. `example.com`. */
72
+ domain?: string;
73
+ };
74
+
75
+ /**
76
+ * Typed error hierarchy for the @ecodrix/erix-api SDK.
77
+ *
78
+ * All errors thrown by the SDK extend `EcodrixError`, so a single
79
+ * `catch` block can handle them all, while still allowing granular
80
+ * differentiation between auth failures, rate limits, and generic API errors.
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * import { APIError, AuthenticationError, RateLimitError } from "@ecodrix/erix-api";
85
+ *
86
+ * try {
87
+ * await ecod.product.erix.leads.retrieve("invalid_id");
88
+ * } catch (err) {
89
+ * if (err instanceof AuthenticationError) {
90
+ * console.error("Invalid API key or client code.");
91
+ * } else if (err instanceof RateLimitError) {
92
+ * console.warn("Slow down — rate limit hit.");
93
+ * } else if (err instanceof APIError) {
94
+ * console.error(`API error ${err.status}: ${err.message}`);
95
+ * }
96
+ * }
97
+ * ```
98
+ */
99
+ /** Base class for all ECODrIx SDK errors. */
100
+ declare class EcodrixError extends Error {
101
+ constructor(message: string);
102
+ }
103
+ /** One value the server refused, from a `VALIDATION_ERROR`'s `issues`. */
104
+ interface APIErrorIssue {
105
+ /** Where in the request body, e.g. `["color"]`. */
106
+ path: (string | number)[];
107
+ message: string;
108
+ /** The check that failed, e.g. `"too_big"`. */
109
+ code?: string;
110
+ }
111
+ /**
112
+ * Represents an error returned by the ECODrIx API.
113
+ * Carries the HTTP `status` code and an optional `code` string.
114
+ */
115
+ declare class APIError extends EcodrixError {
116
+ /** HTTP status code returned by the API (e.g. 400, 404, 500). */
117
+ status?: number;
118
+ /** Machine-readable error code (e.g. `"NOT_FOUND"`, `"VALIDATION_ERROR"`). */
119
+ code?: string;
120
+ /** Each refused value, when the server lists them (`VALIDATION_ERROR`). */
121
+ issues?: APIErrorIssue[];
122
+ /** The one field the server names, when it sends `field`. */
123
+ field?: string;
124
+ constructor(message: string, status?: number, code?: string);
125
+ }
126
+ /**
127
+ * Thrown when the API key or client code is missing, invalid, or expired.
128
+ * HTTP 401. `code` is the server's (e.g. `INVALID_KEY`) when it sends one.
129
+ */
130
+ declare class AuthenticationError extends APIError {
131
+ constructor(message?: string, code?: string, status?: number);
132
+ }
133
+ /**
134
+ * Thrown when the caller is signed in but not allowed: role, plan, or no
135
+ * longer a member (`code` `FORBIDDEN`, `NOT_A_MEMBER`, …). HTTP 403. Extends
136
+ * AuthenticationError so existing 401/403 handling keeps working; check
137
+ * `status` or `code` to tell a dead key from a missing permission.
138
+ */
139
+ declare class PermissionError extends AuthenticationError {
140
+ constructor(message?: string, code?: string);
141
+ }
142
+ /**
143
+ * Thrown when the rate limit for the API key has been exceeded.
144
+ * HTTP 429. Implement exponential backoff before retrying.
145
+ */
146
+ declare class RateLimitError extends APIError {
147
+ constructor(message?: string);
148
+ }
149
+ /**
150
+ * Turn an HTTP client error into the typed SDK error: 401 → AuthenticationError,
151
+ * 403 → PermissionError, 429 → RateLimitError, else APIError. Keeps the
152
+ * server's status and code (sent in `code`, or in `error` as UPPER_SNAKE),
153
+ * and an APIError keeps the body's `issues` and `field` so a form can show
154
+ * each refused value under its own field.
155
+ */
156
+ declare function toAPIError(error: any): APIError;
157
+
158
+ export { APIError as A, EcodrixError as E, PermissionError as P, RateLimitError as R, type VisitorMessage as V, type WebchatSettingsPatch as W, type WebchatOwnerSettings as a, AuthenticationError as b, type APIErrorIssue as c, type VisitorTyping as d, type WebchatSettings as e, toAPIError as t };