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