@dyne/interfacer-client 0.3.5 → 0.4.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.cjs CHANGED
@@ -259,6 +259,7 @@ __export(index_exports, {
259
259
  CO2_THRESHOLDS_KG: () => CO2_THRESHOLDS_KG,
260
260
  DppClient: () => DppClient,
261
261
  ENERGY_THRESHOLDS_KWH: () => ENERGY_THRESHOLDS_KWH,
262
+ FeedbackClient: () => FeedbackClient,
262
263
  FileClient: () => FileClient,
263
264
  GraphQLClient: () => GraphQLClient,
264
265
  ImportClient: () => ImportClient,
@@ -1167,6 +1168,125 @@ var DppClient = class {
1167
1168
  }
1168
1169
  };
1169
1170
 
1171
+ // src/feedback/FeedbackClient.ts
1172
+ init_sign();
1173
+ var FeedbackClient = class {
1174
+ constructor(config, store) {
1175
+ this.config = config;
1176
+ this.store = store;
1177
+ this.baseUrl = config.feedbackUrl || "";
1178
+ }
1179
+ config;
1180
+ store;
1181
+ baseUrl;
1182
+ get url() {
1183
+ if (!this.baseUrl) throw new Error("feedbackUrl not configured");
1184
+ return this.baseUrl;
1185
+ }
1186
+ get userId() {
1187
+ return this.store.getItem("authId") ?? void 0;
1188
+ }
1189
+ // ─── DID Signing ───────────────────────────────────────────────────
1190
+ async signedHeaders(body) {
1191
+ const headers = {};
1192
+ const uid = this.userId;
1193
+ if (uid) headers["x-user-id"] = uid;
1194
+ if (body) {
1195
+ const did = await signDidRequest(body, this.store);
1196
+ Object.assign(headers, did);
1197
+ headers["Content-Type"] = "application/json";
1198
+ }
1199
+ return headers;
1200
+ }
1201
+ async request(method, path, body) {
1202
+ const json = body != null ? JSON.stringify(body) : void 0;
1203
+ const headers = await this.signedHeaders(json ?? void 0);
1204
+ const res = await fetch(`${this.url}${path}`, { method, headers, body: json });
1205
+ if (!res.ok) {
1206
+ let errMsg = res.statusText;
1207
+ try {
1208
+ const err = await res.json();
1209
+ errMsg = err.error || errMsg;
1210
+ } catch {
1211
+ }
1212
+ throw new Error(`Feedback ${method} ${path} failed: ${errMsg}`);
1213
+ }
1214
+ if (res.status === 204) return void 0;
1215
+ return res.json();
1216
+ }
1217
+ // ─── Reviews ───────────────────────────────────────────────────────
1218
+ /** Create or update a review (1-5 stars + optional text). Auth required. */
1219
+ async createReview(projectUlid, rating, content) {
1220
+ return this.request(
1221
+ "POST",
1222
+ `/api/v1/projects/${encodeURIComponent(projectUlid)}/reviews`,
1223
+ { rating, content: content || null }
1224
+ );
1225
+ }
1226
+ /** Fetch paginated reviews for a project. Public. */
1227
+ async getReviews(projectUlid, params) {
1228
+ const qs = new URLSearchParams();
1229
+ if (params?.limit != null) qs.set("limit", String(params.limit));
1230
+ if (params?.cursor != null) qs.set("cursor", String(params.cursor));
1231
+ const query = qs.toString();
1232
+ const path = `/api/v1/projects/${encodeURIComponent(projectUlid)}/reviews${query ? `?${query}` : ""}`;
1233
+ return this.request("GET", path);
1234
+ }
1235
+ /** Fetch aggregated review stats for a project. Public. */
1236
+ async getReviewSummary(projectUlid) {
1237
+ return this.request(
1238
+ "GET",
1239
+ `/api/v1/projects/${encodeURIComponent(projectUlid)}/reviews/summary`
1240
+ );
1241
+ }
1242
+ /** Fetch the current user's review for a project, or null. */
1243
+ async getUserReview(projectUlid) {
1244
+ return this.request(
1245
+ "GET",
1246
+ `/api/v1/projects/${encodeURIComponent(projectUlid)}/reviews/mine`
1247
+ );
1248
+ }
1249
+ /** Delete a review by ID. Only the author can delete. Auth required. */
1250
+ async deleteReview(reviewId) {
1251
+ return this.request(
1252
+ "DELETE",
1253
+ `/api/v1/reviews/${encodeURIComponent(reviewId)}`,
1254
+ {}
1255
+ );
1256
+ }
1257
+ // ─── Comments ──────────────────────────────────────────────────────
1258
+ /** Post a comment (optionally as a reply to parent_id). Auth required. */
1259
+ async createComment(projectUlid, content, parentId, attachments) {
1260
+ return this.request(
1261
+ "POST",
1262
+ `/api/v1/projects/${encodeURIComponent(projectUlid)}/comments`,
1263
+ {
1264
+ content,
1265
+ parent_id: parentId || null,
1266
+ attachments: attachments || null
1267
+ }
1268
+ );
1269
+ }
1270
+ /** Fetch paginated comments for a project. Public. */
1271
+ async getComments(projectUlid, params) {
1272
+ const qs = new URLSearchParams();
1273
+ if (params?.limit != null) qs.set("limit", String(params.limit));
1274
+ if (params?.cursor != null) qs.set("cursor", String(params.cursor));
1275
+ if (params?.parent_id) qs.set("parent_id", params.parent_id);
1276
+ const query = qs.toString();
1277
+ const path = `/api/v1/projects/${encodeURIComponent(projectUlid)}/comments${query ? `?${query}` : ""}`;
1278
+ return this.request("GET", path);
1279
+ }
1280
+ /** Soft-delete a comment. Only the author can delete. Auth required. */
1281
+ async deleteComment(commentId) {
1282
+ return this.request(
1283
+ "DELETE",
1284
+ `/api/v1/comments/${encodeURIComponent(commentId)}`,
1285
+ {}
1286
+ );
1287
+ }
1288
+ };
1289
+
1170
1290
  // src/files/FileClient.ts
1171
1291
  init_hashing();
1172
1292
  var FileClient = class {
@@ -2221,6 +2341,7 @@ var InterfacerClient = class {
2221
2341
  _resources;
2222
2342
  _files;
2223
2343
  _dpp;
2344
+ _feedback;
2224
2345
  _inbox;
2225
2346
  _wallet;
2226
2347
  _social;
@@ -2246,6 +2367,9 @@ var InterfacerClient = class {
2246
2367
  get dpp() {
2247
2368
  return this._dpp ??= new DppClient(this.config, this.store);
2248
2369
  }
2370
+ get feedback() {
2371
+ return this._feedback ??= new FeedbackClient(this.config, this.store);
2372
+ }
2249
2373
  get inbox() {
2250
2374
  return this._inbox ??= new InboxClient(this.config, this.store);
2251
2375
  }
@@ -2343,6 +2467,7 @@ init_sign();
2343
2467
  CO2_THRESHOLDS_KG,
2344
2468
  DppClient,
2345
2469
  ENERGY_THRESHOLDS_KWH,
2470
+ FeedbackClient,
2346
2471
  FileClient,
2347
2472
  GraphQLClient,
2348
2473
  ImportClient,