@rallycry/conveyor-incidents 0.1.0 → 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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @rallycry/conveyor-incidents
2
2
 
3
- Typed TypeScript client for reporting incidents to [Conveyor](https://conveyor.rallycry.gg) via the public REST API.
3
+ Typed TypeScript client for reporting incidents to [Conveyor](https://conveyor.rallycryapp.com) via the public REST API.
4
4
 
5
5
  ## Install
6
6
 
@@ -36,6 +36,43 @@ const { incidentId, attachmentResults } = await incidents.report({
36
36
  });
37
37
  ```
38
38
 
39
+ ### Card types
40
+
41
+ `report()` accepts an optional `type` — `"incident"` (default), `"suggestion"`, or `"task"`:
42
+
43
+ - `"incident"` — fingerprint dedup (see below); repeat reports collapse into one incident.
44
+ - `"suggestion"` — AI duplicate detection; a repeat report upvotes the existing suggestion and returns its id instead of creating a new card. `fingerprintKey` and `severity` are ignored (suggestions are ranked by votes).
45
+ - `"task"` — creates a plain task card. No dedup; `fingerprintKey` is ignored. `severity` maps to the card's priority.
46
+
47
+ ```ts
48
+ // Platform-user suggestion, routed to the team for review
49
+ await incidents.report({
50
+ type: "suggestion",
51
+ title: "Add dark mode toggle",
52
+ assigned: ["logan@rallycry.gg"],
53
+ review: ["dev1@rallycry.gg", "dev2@rallycry.gg"],
54
+ });
55
+ ```
56
+
57
+ ### Assigning members by email
58
+
59
+ `assigned` and `review` are optional arrays of email addresses, matched against the target project's members:
60
+
61
+ - `assigned` — the **first** email that resolves to a project member becomes the card's assignee; remaining entries are ignored.
62
+ - `review` — **every** email that resolves to a project member is added as a reviewer.
63
+ - Emails that don't match a project member are **silently skipped** — safe to pass end-user emails; only teammates who are members of the Conveyor project resolve.
64
+ - Applied **only when a new card is created**. Dedup hits (incident fingerprint match, suggestion AI-merge) leave the existing card untouched.
65
+
66
+ ```ts
67
+ // Incident auto-assigned when reporter is @rallycry.gg
68
+ await incidents.report({
69
+ title: "Checkout service returned 500",
70
+ severity: "high",
71
+ fingerprintKey: "checkout-500-v1.4.2",
72
+ assigned: ["logan@rallycry.gg"],
73
+ });
74
+ ```
75
+
39
76
  ### About `source` and `fingerprintKey`
40
77
 
41
78
  Conveyor deduplicates reports by a fingerprint derived from `(projectId, source, fingerprintKey)` — or by `(projectId, source, title)` if `fingerprintKey` is omitted. **Use stable values** for `source` (e.g. `"prod-web"`, not `"node-pid-1234"`) so that repeat reports collapse into a single incident instead of creating noise.
@@ -49,13 +86,21 @@ Conveyor deduplicates reports by a fingerprint derived from `(projectId, source,
49
86
 
50
87
  Pass a `fetch` polyfill via `opts.fetch` if your runtime lacks a global `fetch`.
51
88
 
89
+ ### `DEP0169 url.parse()` warning
90
+
91
+ The `@rallycry/conveyor-incidents` SDK does not call `url.parse()` — it uses the WHATWG `URL` constructor and the global `fetch` API. If your process emits this warning while using the SDK, the call is coming from another dependency in your project. Run `node --trace-deprecation your-script.js` to locate the source.
92
+
93
+ ### Troubleshooting `403` from `/api/incidents/report`
94
+
95
+ The endpoint requires a project token with `scope: "incident"`. After the 2026-04-22 scope migration, older project tokens default to `scope: "claude_code"` and are rejected. The error body now includes a `reason` field — `"scope_mismatch"` indicates the token exists but is scoped for another surface; generate a new token from **Project Settings → Incidents** in the Conveyor UI.
96
+
52
97
  ## API
53
98
 
54
99
  ```ts
55
100
  new ConveyorIncidents({
56
101
  apiKey: string;
57
102
  projectId: string;
58
- baseUrl?: string; // default: "https://conveyor.rallycry.gg"
103
+ baseUrl?: string; // default: "https://api.conveyor.rallycryapp.com"
59
104
  fetch?: typeof fetch;
60
105
  });
61
106
 
@@ -66,6 +111,9 @@ client.report({
66
111
  source?: string; // default: "client"
67
112
  fingerprintKey?: string;
68
113
  plan?: string;
114
+ type?: "incident" | "suggestion" | "task"; // default: "incident"
115
+ assigned?: string[]; // project-member emails; first match becomes assignee
116
+ review?: string[]; // project-member emails; every match becomes a reviewer
69
117
  attachments?: Array<{
70
118
  fileName: string;
71
119
  mimeType: string;
@@ -73,6 +121,7 @@ client.report({
73
121
  }>;
74
122
  }): Promise<{
75
123
  incidentId: string;
124
+ cardId: string; // alias of incidentId — prefer for suggestion/task types
76
125
  attachmentResults: Array<{
77
126
  fileName: string;
78
127
  ok: boolean;
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ declare class ConveyorIncidentsError extends Error {
5
5
  }
6
6
 
7
7
  type IncidentSeverity = "critical" | "high" | "medium" | "low";
8
+ type ConveyorCardType = "incident" | "suggestion" | "task";
8
9
  interface ConveyorIncidentsOptions {
9
10
  apiKey: string;
10
11
  projectId: string;
@@ -24,6 +25,20 @@ interface ReportIncidentInput {
24
25
  fingerprintKey?: string;
25
26
  plan?: string;
26
27
  attachments?: IncidentAttachment[];
28
+ /** Card type to create. The server defaults to "incident" when omitted. */
29
+ type?: ConveyorCardType;
30
+ /**
31
+ * Project-member emails. The FIRST email that resolves to a member of the
32
+ * target project becomes the card's assignee; the rest are ignored.
33
+ * Non-member emails are silently skipped.
34
+ */
35
+ assigned?: string[];
36
+ /**
37
+ * Project-member emails. EVERY email that resolves to a member of the
38
+ * target project is added as a reviewer. Non-member emails are silently
39
+ * skipped.
40
+ */
41
+ review?: string[];
27
42
  }
28
43
  interface AttachmentResult {
29
44
  fileName: string;
@@ -33,6 +48,8 @@ interface AttachmentResult {
33
48
  }
34
49
  interface ReportIncidentResult {
35
50
  incidentId: string;
51
+ /** Alias of `incidentId` — prefer this when reporting type "suggestion" or "task". */
52
+ cardId: string;
36
53
  attachmentResults: AttachmentResult[];
37
54
  }
38
55
  declare class ConveyorIncidents {
@@ -45,4 +62,4 @@ declare class ConveyorIncidents {
45
62
  private uploadAttachment;
46
63
  }
47
64
 
48
- export { type AttachmentResult, ConveyorIncidents, ConveyorIncidentsError, type ConveyorIncidentsOptions, type IncidentAttachment, type IncidentSeverity, type ReportIncidentInput, type ReportIncidentResult };
65
+ export { type AttachmentResult, type ConveyorCardType, ConveyorIncidents, ConveyorIncidentsError, type ConveyorIncidentsOptions, type IncidentAttachment, type IncidentSeverity, type ReportIncidentInput, type ReportIncidentResult };
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ var ConveyorIncidentsError = class extends Error {
11
11
  };
12
12
 
13
13
  // src/index.ts
14
- var DEFAULT_BASE_URL = "https://conveyor.rallycry.gg";
14
+ var DEFAULT_BASE_URL = "https://api.conveyor.rallycryapp.com";
15
15
  var DEFAULT_SOURCE = "client";
16
16
  var DEFAULT_SEVERITY = "medium";
17
17
  var ConveyorIncidents = class {
@@ -43,7 +43,10 @@ var ConveyorIncidents = class {
43
43
  title: input.title,
44
44
  description: input.description,
45
45
  plan: input.plan,
46
- fingerprintKey: input.fingerprintKey
46
+ fingerprintKey: input.fingerprintKey,
47
+ type: input.type,
48
+ assigned: input.assigned,
49
+ review: input.review
47
50
  };
48
51
  const res = await this.fetchImpl(`${this.baseUrl}/api/incidents/report`, {
49
52
  method: "POST",
@@ -61,7 +64,7 @@ var ConveyorIncidents = class {
61
64
  payload
62
65
  );
63
66
  }
64
- const incidentId = payload && typeof payload === "object" && "incidentId" in payload ? String(payload.incidentId) : void 0;
67
+ const incidentId = extractId(payload, "incidentId") ?? extractId(payload, "cardId");
65
68
  if (!incidentId) {
66
69
  throw new ConveyorIncidentsError(
67
70
  "Invalid response from /api/incidents/report: missing incidentId",
@@ -75,7 +78,7 @@ var ConveyorIncidents = class {
75
78
  attachmentResults.push(await this.uploadAttachment(incidentId, attachment));
76
79
  }
77
80
  }
78
- return { incidentId, attachmentResults };
81
+ return { incidentId, cardId: incidentId, attachmentResults };
79
82
  }
80
83
  async uploadAttachment(incidentId, attachment) {
81
84
  try {
@@ -117,6 +120,13 @@ var ConveyorIncidents = class {
117
120
  function stripTrailingSlash(url) {
118
121
  return url.endsWith("/") ? url.slice(0, -1) : url;
119
122
  }
123
+ function extractId(payload, key) {
124
+ if (payload && typeof payload === "object" && key in payload) {
125
+ const value = payload[key];
126
+ if (value !== void 0 && value !== null) return String(value);
127
+ }
128
+ return void 0;
129
+ }
120
130
  async function readJson(res) {
121
131
  const text = await res.text();
122
132
  if (!text) return void 0;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/errors.ts","../src/index.ts"],"sourcesContent":["export class ConveyorIncidentsError extends Error {\n readonly status: number;\n readonly body: unknown;\n\n constructor(message: string, status: number, body: unknown) {\n super(message);\n this.name = \"ConveyorIncidentsError\";\n this.status = status;\n this.body = body;\n }\n}\n","import { ConveyorIncidentsError } from \"./errors.js\";\n\nexport { ConveyorIncidentsError } from \"./errors.js\";\n\nconst DEFAULT_BASE_URL = \"https://conveyor.rallycry.gg\";\nconst DEFAULT_SOURCE = \"client\";\nconst DEFAULT_SEVERITY: IncidentSeverity = \"medium\";\n\nexport type IncidentSeverity = \"critical\" | \"high\" | \"medium\" | \"low\";\n\nexport interface ConveyorIncidentsOptions {\n apiKey: string;\n projectId: string;\n baseUrl?: string;\n fetch?: typeof fetch;\n}\n\nexport interface IncidentAttachment {\n fileName: string;\n mimeType: string;\n content: Uint8Array | string;\n}\n\nexport interface ReportIncidentInput {\n title: string;\n description?: string;\n severity?: IncidentSeverity;\n source?: string;\n fingerprintKey?: string;\n plan?: string;\n attachments?: IncidentAttachment[];\n}\n\nexport interface AttachmentResult {\n fileName: string;\n ok: boolean;\n fileId?: string;\n error?: string;\n}\n\nexport interface ReportIncidentResult {\n incidentId: string;\n attachmentResults: AttachmentResult[];\n}\n\nexport class ConveyorIncidents {\n private readonly apiKey: string;\n private readonly projectId: string;\n private readonly baseUrl: string;\n private readonly fetchImpl: typeof fetch;\n\n constructor(opts: ConveyorIncidentsOptions) {\n if (!opts.apiKey) {\n throw new Error(\"ConveyorIncidents: apiKey is required\");\n }\n if (!opts.projectId) {\n throw new Error(\"ConveyorIncidents: projectId is required\");\n }\n const resolvedFetch = opts.fetch ?? globalThis.fetch;\n if (typeof resolvedFetch !== \"function\") {\n throw new Error(\"ConveyorIncidents: no global fetch available — pass opts.fetch on Node <18\");\n }\n this.apiKey = opts.apiKey;\n this.projectId = opts.projectId;\n this.baseUrl = stripTrailingSlash(opts.baseUrl ?? DEFAULT_BASE_URL);\n this.fetchImpl = resolvedFetch;\n }\n\n async report(input: ReportIncidentInput): Promise<ReportIncidentResult> {\n const body = {\n projectId: this.projectId,\n source: input.source ?? DEFAULT_SOURCE,\n severity: input.severity ?? DEFAULT_SEVERITY,\n title: input.title,\n description: input.description,\n plan: input.plan,\n fingerprintKey: input.fingerprintKey,\n };\n\n const res = await this.fetchImpl(`${this.baseUrl}/api/incidents/report`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.apiKey}`,\n },\n body: JSON.stringify(body),\n });\n\n const payload = await readJson(res);\n\n if (!res.ok) {\n throw new ConveyorIncidentsError(\n `Failed to report incident: ${res.status} ${res.statusText}`,\n res.status,\n payload,\n );\n }\n\n const incidentId =\n payload && typeof payload === \"object\" && \"incidentId\" in payload\n ? String((payload as { incidentId: unknown }).incidentId)\n : undefined;\n\n if (!incidentId) {\n throw new ConveyorIncidentsError(\n \"Invalid response from /api/incidents/report: missing incidentId\",\n res.status,\n payload,\n );\n }\n\n const attachmentResults: AttachmentResult[] = [];\n if (input.attachments && input.attachments.length > 0) {\n for (const attachment of input.attachments) {\n attachmentResults.push(await this.uploadAttachment(incidentId, attachment));\n }\n }\n\n return { incidentId, attachmentResults };\n }\n\n private async uploadAttachment(\n incidentId: string,\n attachment: IncidentAttachment,\n ): Promise<AttachmentResult> {\n try {\n const contentBase64 = toBase64(attachment.content);\n const res = await this.fetchImpl(\n `${this.baseUrl}/api/incidents/${encodeURIComponent(incidentId)}/files`,\n {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.apiKey}`,\n },\n body: JSON.stringify({\n fileName: attachment.fileName,\n mimeType: attachment.mimeType,\n contentBase64,\n }),\n },\n );\n\n const payload = await readJson(res);\n\n if (!res.ok) {\n return {\n fileName: attachment.fileName,\n ok: false,\n error: formatErrorBody(res.status, res.statusText, payload),\n };\n }\n\n const fileId =\n payload && typeof payload === \"object\" && \"fileId\" in payload\n ? String((payload as { fileId: unknown }).fileId)\n : undefined;\n\n return { fileName: attachment.fileName, ok: true, fileId };\n } catch (err) {\n return {\n fileName: attachment.fileName,\n ok: false,\n error: err instanceof Error ? err.message : String(err),\n };\n }\n }\n}\n\nfunction stripTrailingSlash(url: string): string {\n return url.endsWith(\"/\") ? url.slice(0, -1) : url;\n}\n\nasync function readJson(res: Response): Promise<unknown> {\n const text = await res.text();\n if (!text) return undefined;\n try {\n return JSON.parse(text);\n } catch {\n return text;\n }\n}\n\nfunction formatErrorBody(status: number, statusText: string, body: unknown): string {\n const prefix = `${status} ${statusText}`.trim();\n if (body && typeof body === \"object\" && \"error\" in body) {\n return `${prefix}: ${String((body as { error: unknown }).error)}`;\n }\n if (typeof body === \"string\" && body.length > 0) {\n return `${prefix}: ${body}`;\n }\n return prefix;\n}\n\nfunction toBase64(content: Uint8Array | string): string {\n const bytes = typeof content === \"string\" ? new TextEncoder().encode(content) : content;\n return bytesToBase64(bytes);\n}\n\nfunction bytesToBase64(bytes: Uint8Array): string {\n if (typeof Buffer !== \"undefined\") {\n return Buffer.from(bytes).toString(\"base64\");\n }\n let binary = \"\";\n for (const byte of bytes) {\n binary += String.fromCharCode(byte);\n }\n return btoa(binary);\n}\n"],"mappings":";AAAO,IAAM,yBAAN,cAAqC,MAAM;AAAA,EACvC;AAAA,EACA;AAAA,EAET,YAAY,SAAiB,QAAgB,MAAe;AAC1D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AAAA,EACd;AACF;;;ACNA,IAAM,mBAAmB;AACzB,IAAM,iBAAiB;AACvB,IAAM,mBAAqC;AAuCpC,IAAM,oBAAN,MAAwB;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEjB,YAAY,MAAgC;AAC1C,QAAI,CAAC,KA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AChD;AAEA,eAAe,SAAS,KAAiC;AACvD,QAAM,OAAO,MAAM,IAAI,KAAK;AAC5B,MAAI,CAAC,KAAM,QAAO;AAClB,MAAI;AACF,WAAO,KAAK,MAAM,IAAI;AAAA,EACxB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,gBAAgB,QAAgB,YAAoB,MAAuB;AAClF,QAAM,SAAS,GAAG,MAAM,IAAI,UAAU,GAAG,KAAK;AAC9C,MAAI,QAAQ,OAAO,SAAS,YAAY,WAAW,MAAM;AACvD,WAAO,GAAG,MAAM,KAAK,OAAQ,KAA4B,KAAK,CAAC;AAAA,EACjE;AACA,MAAI,OAAO,SAAS,YAAY,KAAK,SAAS,GAAG;AAC/C,WAAO,GAAG,MAAM,KAAK,IAAI;AAAA,EAC3B;AACA,SAAO;AACT;AAEA,SAAS,SAAS,SAAsC;AACtD,QAAM,QAAQ,OAAO,YAAY,WAAW,IAAI,YAAY,EAAE,OAAO,OAAO,IAAI;AAChF,SAAO,cAAc,KAAK;AAC5B;AAEA,SAAS,cAAc,OAA2B;AAChD,MAAI,OAAO,WAAW,aAAa;AACjC,WAAO,OAAO,KAAK,KAAK,EAAE,SAAS,QAAQ;AAAA,EAC7C;AACA,MAAI,SAAS;AACb,aAAW,QAAQ,OAAO;AACxB,cAAU,OAAO,aAAa,IAAI;AAAA,EACpC;AACA,SAAO,KAAK,MAAM;AACpB;","names":[]}
1
+ {"version":3,"sources":["../src/errors.ts","../src/index.ts"],"sourcesContent":["export class ConveyorIncidentsError extends Error {\n readonly status: number;\n readonly body: unknown;\n\n constructor(message: string, status: number, body: unknown) {\n super(message);\n this.name = \"ConveyorIncidentsError\";\n this.status = status;\n this.body = body;\n }\n}\n","import { ConveyorIncidentsError } from \"./errors.js\";\n\nexport { ConveyorIncidentsError } from \"./errors.js\";\n\nconst DEFAULT_BASE_URL = \"https://api.conveyor.rallycryapp.com\";\nconst DEFAULT_SOURCE = \"client\";\nconst DEFAULT_SEVERITY: IncidentSeverity = \"medium\";\n\nexport type IncidentSeverity = \"critical\" | \"high\" | \"medium\" | \"low\";\n\nexport type ConveyorCardType = \"incident\" | \"suggestion\" | \"task\";\n\nexport interface ConveyorIncidentsOptions {\n apiKey: string;\n projectId: string;\n baseUrl?: string;\n fetch?: typeof fetch;\n}\n\nexport interface IncidentAttachment {\n fileName: string;\n mimeType: string;\n content: Uint8Array | string;\n}\n\nexport interface ReportIncidentInput {\n title: string;\n description?: string;\n severity?: IncidentSeverity;\n source?: string;\n fingerprintKey?: string;\n plan?: string;\n attachments?: IncidentAttachment[];\n /** Card type to create. The server defaults to \"incident\" when omitted. */\n type?: ConveyorCardType;\n /**\n * Project-member emails. The FIRST email that resolves to a member of the\n * target project becomes the card's assignee; the rest are ignored.\n * Non-member emails are silently skipped.\n */\n assigned?: string[];\n /**\n * Project-member emails. EVERY email that resolves to a member of the\n * target project is added as a reviewer. Non-member emails are silently\n * skipped.\n */\n review?: string[];\n}\n\nexport interface AttachmentResult {\n fileName: string;\n ok: boolean;\n fileId?: string;\n error?: string;\n}\n\nexport interface ReportIncidentResult {\n incidentId: string;\n /** Alias of `incidentId` — prefer this when reporting type \"suggestion\" or \"task\". */\n cardId: string;\n attachmentResults: AttachmentResult[];\n}\n\nexport class ConveyorIncidents {\n private readonly apiKey: string;\n private readonly projectId: string;\n private readonly baseUrl: string;\n private readonly fetchImpl: typeof fetch;\n\n constructor(opts: ConveyorIncidentsOptions) {\n if (!opts.apiKey) {\n throw new Error(\"ConveyorIncidents: apiKey is required\");\n }\n if (!opts.projectId) {\n throw new Error(\"ConveyorIncidents: projectId is required\");\n }\n const resolvedFetch = opts.fetch ?? globalThis.fetch;\n if (typeof resolvedFetch !== \"function\") {\n throw new Error(\"ConveyorIncidents: no global fetch available — pass opts.fetch on Node <18\");\n }\n this.apiKey = opts.apiKey;\n this.projectId = opts.projectId;\n this.baseUrl = stripTrailingSlash(opts.baseUrl ?? DEFAULT_BASE_URL);\n this.fetchImpl = resolvedFetch;\n }\n\n async report(input: ReportIncidentInput): Promise<ReportIncidentResult> {\n const body = {\n projectId: this.projectId,\n source: input.source ?? DEFAULT_SOURCE,\n severity: input.severity ?? DEFAULT_SEVERITY,\n title: input.title,\n description: input.description,\n plan: input.plan,\n fingerprintKey: input.fingerprintKey,\n type: input.type,\n assigned: input.assigned,\n review: input.review,\n };\n\n const res = await this.fetchImpl(`${this.baseUrl}/api/incidents/report`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.apiKey}`,\n },\n body: JSON.stringify(body),\n });\n\n const payload = await readJson(res);\n\n if (!res.ok) {\n throw new ConveyorIncidentsError(\n `Failed to report incident: ${res.status} ${res.statusText}`,\n res.status,\n payload,\n );\n }\n\n const incidentId = extractId(payload, \"incidentId\") ?? extractId(payload, \"cardId\");\n\n if (!incidentId) {\n throw new ConveyorIncidentsError(\n \"Invalid response from /api/incidents/report: missing incidentId\",\n res.status,\n payload,\n );\n }\n\n const attachmentResults: AttachmentResult[] = [];\n if (input.attachments && input.attachments.length > 0) {\n for (const attachment of input.attachments) {\n attachmentResults.push(await this.uploadAttachment(incidentId, attachment));\n }\n }\n\n return { incidentId, cardId: incidentId, attachmentResults };\n }\n\n private async uploadAttachment(\n incidentId: string,\n attachment: IncidentAttachment,\n ): Promise<AttachmentResult> {\n try {\n const contentBase64 = toBase64(attachment.content);\n const res = await this.fetchImpl(\n `${this.baseUrl}/api/incidents/${encodeURIComponent(incidentId)}/files`,\n {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${this.apiKey}`,\n },\n body: JSON.stringify({\n fileName: attachment.fileName,\n mimeType: attachment.mimeType,\n contentBase64,\n }),\n },\n );\n\n const payload = await readJson(res);\n\n if (!res.ok) {\n return {\n fileName: attachment.fileName,\n ok: false,\n error: formatErrorBody(res.status, res.statusText, payload),\n };\n }\n\n const fileId =\n payload && typeof payload === \"object\" && \"fileId\" in payload\n ? String((payload as { fileId: unknown }).fileId)\n : undefined;\n\n return { fileName: attachment.fileName, ok: true, fileId };\n } catch (err) {\n return {\n fileName: attachment.fileName,\n ok: false,\n error: err instanceof Error ? err.message : String(err),\n };\n }\n }\n}\n\nfunction stripTrailingSlash(url: string): string {\n return url.endsWith(\"/\") ? url.slice(0, -1) : url;\n}\n\nfunction extractId(payload: unknown, key: \"incidentId\" | \"cardId\"): string | undefined {\n if (payload && typeof payload === \"object\" && key in payload) {\n const value = (payload as Record<string, unknown>)[key];\n if (value !== undefined && value !== null) return String(value);\n }\n return undefined;\n}\n\nasync function readJson(res: Response): Promise<unknown> {\n const text = await res.text();\n if (!text) return undefined;\n try {\n return JSON.parse(text);\n } catch {\n return text;\n }\n}\n\nfunction formatErrorBody(status: number, statusText: string, body: unknown): string {\n const prefix = `${status} ${statusText}`.trim();\n if (body && typeof body === \"object\" && \"error\" in body) {\n return `${prefix}: ${String((body as { error: unknown }).error)}`;\n }\n if (typeof body === \"string\" && body.length > 0) {\n return `${prefix}: ${body}`;\n }\n return prefix;\n}\n\nfunction toBase64(content: Uint8Array | string): string {\n const bytes = typeof content === \"string\" ? new TextEncoder().encode(content) : content;\n return bytesToBase64(bytes);\n}\n\nfunction bytesToBase64(bytes: Uint8Array): string {\n if (typeof Buffer !== \"undefined\") {\n return Buffer.from(bytes).toString(\"base64\");\n }\n let binary = \"\";\n for (const byte of bytes) {\n binary += String.fromCharCode(byte);\n }\n return btoa(binary);\n}\n"],"mappings":";AAAO,IAAM,yBAAN,cAAqC,MAAM;AAAA,EACvC;AAAA,EACA;AAAA,EAET,YAAY,SAAiB,QAAgB,MAAe;AAC1D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AAAA,EACd;AACF;;;ACNA,IAAM,mBAAmB;AACzB,IAAM,iBAAiB;AACvB,IAAM,mBAAqC;AAyDpC,IAAM,oBAAN,MAAwB;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEjB,Y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ry/conveyor-incidents",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Typed TypeScript client for Conveyor's public incidents REST API",
5
5
  "keywords": [
6
6
  "client",
@@ -10,7 +10,8 @@
10
10
  ],
11
11
  "license": "MIT",
12
12
  "files": [
13
- "dist"
13
+ "dist",
14
+ "README.md"
14
15
  ],
15
16
  "type": "module",
16
17
  "main": "./dist/index.js",