@myapihq/sdk 2.19.2 → 2.20.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.
@@ -154,3 +154,16 @@ export interface WidgetUpdate {
154
154
  export declare function updateWidget(apiKey: string, orgId: string, id: string, patch: WidgetUpdate): Promise<Widget>;
155
155
  export declare function listWidgets(apiKey: string, orgId: string): Promise<Widget[]>;
156
156
  export declare function revokeWidget(apiKey: string, orgId: string, id: string): Promise<void>;
157
+ /**
158
+ * Render a feedback item as a Playwright spec.
159
+ *
160
+ * Returns the spec SOURCE, not JSON: the endpoint answers `text/plain`, so this
161
+ * cannot go through `request()`, which parses every body as JSON and would
162
+ * throw `invalid_json_response` on a perfectly good test file.
163
+ *
164
+ * `base` overrides where the test runs. The report's own `page_url` is used by
165
+ * default; an item filed without one answers 422 `BASE_URL_REQUIRED`, because
166
+ * the generator has nowhere to point the browser and guessing would produce a
167
+ * spec that silently tests nothing.
168
+ */
169
+ export declare function getItemTest(apiKey: string, orgId: string, id: string, base?: string): Promise<string>;
package/dist/feedback.js CHANGED
@@ -9,6 +9,7 @@ exports.createWidget = createWidget;
9
9
  exports.updateWidget = updateWidget;
10
10
  exports.listWidgets = listWidgets;
11
11
  exports.revokeWidget = revokeWidget;
12
+ exports.getItemTest = getItemTest;
12
13
  const client_1 = require("./client");
13
14
  const config_1 = require("./config");
14
15
  // End-user feedback collected from a page, and the widget keys that let a
@@ -22,6 +23,8 @@ exports.EXPOSES = [
22
23
  'POST /feedback/orgs/{org_id}/items',
23
24
  'POST /feedback/orgs/{org_id}/items/{id}/resolve',
24
25
  'DELETE /feedback/orgs/{org_id}/items/{id}',
26
+ // Answers text/plain — a Playwright spec, not the JSON envelope.
27
+ 'GET /feedback/orgs/{org_id}/items/{id}/test',
25
28
  ];
26
29
  function orgBase(orgId) {
27
30
  return `${config_1.FEEDBACK_BASE}/feedback/orgs/${encodeURIComponent(orgId)}`;
@@ -92,3 +95,33 @@ async function listWidgets(apiKey, orgId) {
92
95
  async function revokeWidget(apiKey, orgId, id) {
93
96
  return (0, client_1.request)('DELETE', `${orgBase(orgId)}/widgets/${encodeURIComponent(id)}`, apiKey);
94
97
  }
98
+ /**
99
+ * Render a feedback item as a Playwright spec.
100
+ *
101
+ * Returns the spec SOURCE, not JSON: the endpoint answers `text/plain`, so this
102
+ * cannot go through `request()`, which parses every body as JSON and would
103
+ * throw `invalid_json_response` on a perfectly good test file.
104
+ *
105
+ * `base` overrides where the test runs. The report's own `page_url` is used by
106
+ * default; an item filed without one answers 422 `BASE_URL_REQUIRED`, because
107
+ * the generator has nowhere to point the browser and guessing would produce a
108
+ * spec that silently tests nothing.
109
+ */
110
+ async function getItemTest(apiKey, orgId, id, base) {
111
+ const qs = base ? `?base=${encodeURIComponent(base)}` : '';
112
+ const url = `${orgBase(orgId)}/items/${encodeURIComponent(id)}/test${qs}`;
113
+ const response = await fetch(url, { headers: { Authorization: `Bearer ${apiKey}` } });
114
+ const raw = await response.text();
115
+ if (!response.ok) {
116
+ // Errors still come back as the JSON envelope, so parse only on failure.
117
+ let err;
118
+ try {
119
+ err = JSON.parse(raw)?.error;
120
+ }
121
+ catch { /* fall through to the code below */ }
122
+ const code = typeof err === 'object' ? (err?.code ?? 'unknown_error') : (err ?? 'unknown_error');
123
+ const detail = typeof err === 'object' ? err?.message : undefined;
124
+ throw new client_1.MyApiError(code, response.status, detail, typeof err === 'object' ? err : undefined);
125
+ }
126
+ return raw;
127
+ }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "2.19.2";
1
+ export declare const SDK_VERSION = "2.20.0";
package/dist/version.js CHANGED
@@ -8,4 +8,4 @@ exports.SDK_VERSION = void 0;
8
8
  // Why a constant and not a package.json read: the SDK runs inside edge
9
9
  // functions (Cloudflare Workers), so it must not import node:fs. A literal
10
10
  // is the only version source that works in every runtime we ship to.
11
- exports.SDK_VERSION = '2.19.2';
11
+ exports.SDK_VERSION = '2.20.0';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@myapihq/sdk",
3
3
  "license": "Apache-2.0",
4
- "version": "2.19.2",
4
+ "version": "2.20.0",
5
5
  "description": "TypeScript SDK for the MyAPI ecosystem",
6
6
  "repository": {
7
7
  "type": "git",