@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.d.cts CHANGED
@@ -52,6 +52,8 @@ interface InterfacerConfig {
52
52
  };
53
53
  /** Open Source Hardware analysis endpoint */
54
54
  oshUrl?: string;
55
+ /** Feedback service base URL (reviews & comments) */
56
+ feedbackUrl?: string;
55
57
  /** Location services */
56
58
  location?: {
57
59
  autocomplete: string;
@@ -527,6 +529,84 @@ declare class DppClient {
527
529
  getFileUrl(fileId: string): string;
528
530
  }
529
531
 
532
+ /**
533
+ * Feedback client — reviews & comments via interfacer-feedback-service REST API.
534
+ *
535
+ * Auth: DID-signed headers (did-sign + did-pk), same pattern as DppClient.
536
+ * Ported from interfacer-gui lib/feedback.ts
537
+ */
538
+
539
+ interface Review {
540
+ id: string;
541
+ project_ulid: string;
542
+ user_ulid: string;
543
+ rating: number;
544
+ content?: string | null;
545
+ created_at: string;
546
+ updated_at: string;
547
+ }
548
+ interface ReviewSummary {
549
+ average_rating: number;
550
+ total_reviews: number;
551
+ rating_distribution: Record<number, number>;
552
+ }
553
+ interface Comment {
554
+ id: string;
555
+ project_ulid: string;
556
+ user_ulid: string;
557
+ parent_id?: string | null;
558
+ content: string;
559
+ attachments?: string | null;
560
+ status: string;
561
+ created_at: string;
562
+ updated_at: string;
563
+ }
564
+ interface GetReviewsParams {
565
+ limit?: number;
566
+ cursor?: number;
567
+ }
568
+ interface GetCommentsParams {
569
+ limit?: number;
570
+ cursor?: number;
571
+ parent_id?: string;
572
+ }
573
+ declare class FeedbackClient {
574
+ private config;
575
+ private store;
576
+ private baseUrl;
577
+ constructor(config: InterfacerConfig, store: KeyStorage);
578
+ private get url();
579
+ private get userId();
580
+ private signedHeaders;
581
+ private request;
582
+ /** Create or update a review (1-5 stars + optional text). Auth required. */
583
+ createReview(projectUlid: string, rating: number, content?: string): Promise<Review>;
584
+ /** Fetch paginated reviews for a project. Public. */
585
+ getReviews(projectUlid: string, params?: GetReviewsParams): Promise<{
586
+ reviews: Review[];
587
+ }>;
588
+ /** Fetch aggregated review stats for a project. Public. */
589
+ getReviewSummary(projectUlid: string): Promise<ReviewSummary>;
590
+ /** Fetch the current user's review for a project, or null. */
591
+ getUserReview(projectUlid: string): Promise<{
592
+ review: Review | null;
593
+ }>;
594
+ /** Delete a review by ID. Only the author can delete. Auth required. */
595
+ deleteReview(reviewId: string): Promise<{
596
+ status: string;
597
+ }>;
598
+ /** Post a comment (optionally as a reply to parent_id). Auth required. */
599
+ createComment(projectUlid: string, content: string, parentId?: string, attachments?: string): Promise<Comment>;
600
+ /** Fetch paginated comments for a project. Public. */
601
+ getComments(projectUlid: string, params?: GetCommentsParams): Promise<{
602
+ comments: Comment[];
603
+ }>;
604
+ /** Soft-delete a comment. Only the author can delete. Auth required. */
605
+ deleteComment(commentId: string): Promise<{
606
+ status: string;
607
+ }>;
608
+ }
609
+
530
610
  /**
531
611
  * File hashing and preparation for Zenflows and DPP uploads.
532
612
  *
@@ -977,6 +1057,7 @@ declare class InterfacerClient {
977
1057
  private _resources?;
978
1058
  private _files?;
979
1059
  private _dpp?;
1060
+ private _feedback?;
980
1061
  private _inbox?;
981
1062
  private _wallet?;
982
1063
  private _social?;
@@ -988,6 +1069,7 @@ declare class InterfacerClient {
988
1069
  get resources(): ResourceClient;
989
1070
  get files(): FileClient;
990
1071
  get dpp(): DppClient;
1072
+ get feedback(): FeedbackClient;
991
1073
  get inbox(): InboxClient;
992
1074
  get wallet(): WalletClient;
993
1075
  get social(): SocialClient;
@@ -1158,4 +1240,4 @@ declare function signDidRequest(body: string, store: KeyStorage): Promise<{
1158
1240
  */
1159
1241
  declare function signFileUpload(checksumHex: string, store: KeyStorage): Promise<string>;
1160
1242
 
1161
- export { AVAILABILITY_OPTIONS, AuthClient, CO2_THRESHOLDS_KG, type Contributor, type CreateProjectParams, type DerivedEndpoints, type DppAttachment, DppClient, type DppDocument, type DppStatus, ENERGY_THRESHOLDS_KWH, FileClient, type GqlFile, GraphQLClient, type ImageRef, ImportClient, InboxClient, type InstanceVariables, InterfacerClient, type InterfacerConfig, type KeyStorage, type Keyring, type License, type Location, MANUFACTURABLE_TRUE_TAG, type MachineRef, type MaterialRef, type ModelFile, POWER_COMPATIBILITY_OPTIONS, POWER_REQUIREMENT_THRESHOLDS_W, PRODUCT_CATEGORY_OPTIONS, type ProductFilters, type Project, type ProjectFilter, type ProjectModelMetadata, ProjectType, type Proposal, RECYCLABILITY_THRESHOLDS_PCT, REPAIRABILITY_AVAILABLE_TAG, REPLICABILITY_OPTIONS, ResourceClient, SERVICE_TYPE_OPTIONS, SYSTEM_TAG_PREFIXES, type ServiceFilters, SocialClient, TAG_PREFIX, TaggingClient, type UserChallenges, WalletClient, type ZenflowsFile, clearInstanceVariablesCache, createConfig, createMemoryStorage, deriveEndpointsFromProxy, derivedProductFilterTags, extractUserTagValues, formatImageSrc, getInstanceVariables, getResourceImage, isSystemTag, isUserTag, mergeTags, monotonicRangeTags, normalizeUserTagsForSave, prefixedTag, prepFileForZenflows, prepFilesForZenflows, rangeFilterTags, removeTagsWithPrefixes, signDidRequest, signFileUpload, signGraphQLRequest, slugifyTagValue, stripUserTagPrefix, userTag };
1243
+ export { AVAILABILITY_OPTIONS, AuthClient, CO2_THRESHOLDS_KG, type Comment, type Contributor, type CreateProjectParams, type DerivedEndpoints, type DppAttachment, DppClient, type DppDocument, type DppStatus, ENERGY_THRESHOLDS_KWH, FeedbackClient, FileClient, type GetCommentsParams, type GetReviewsParams, type GqlFile, GraphQLClient, type ImageRef, ImportClient, InboxClient, type InstanceVariables, InterfacerClient, type InterfacerConfig, type KeyStorage, type Keyring, type License, type Location, MANUFACTURABLE_TRUE_TAG, type MachineRef, type MaterialRef, type ModelFile, POWER_COMPATIBILITY_OPTIONS, POWER_REQUIREMENT_THRESHOLDS_W, PRODUCT_CATEGORY_OPTIONS, type ProductFilters, type Project, type ProjectFilter, type ProjectModelMetadata, ProjectType, type Proposal, RECYCLABILITY_THRESHOLDS_PCT, REPAIRABILITY_AVAILABLE_TAG, REPLICABILITY_OPTIONS, ResourceClient, type Review, type ReviewSummary, SERVICE_TYPE_OPTIONS, SYSTEM_TAG_PREFIXES, type ServiceFilters, SocialClient, TAG_PREFIX, TaggingClient, type UserChallenges, WalletClient, type ZenflowsFile, clearInstanceVariablesCache, createConfig, createMemoryStorage, deriveEndpointsFromProxy, derivedProductFilterTags, extractUserTagValues, formatImageSrc, getInstanceVariables, getResourceImage, isSystemTag, isUserTag, mergeTags, monotonicRangeTags, normalizeUserTagsForSave, prefixedTag, prepFileForZenflows, prepFilesForZenflows, rangeFilterTags, removeTagsWithPrefixes, signDidRequest, signFileUpload, signGraphQLRequest, slugifyTagValue, stripUserTagPrefix, userTag };
package/dist/index.d.ts CHANGED
@@ -52,6 +52,8 @@ interface InterfacerConfig {
52
52
  };
53
53
  /** Open Source Hardware analysis endpoint */
54
54
  oshUrl?: string;
55
+ /** Feedback service base URL (reviews & comments) */
56
+ feedbackUrl?: string;
55
57
  /** Location services */
56
58
  location?: {
57
59
  autocomplete: string;
@@ -527,6 +529,84 @@ declare class DppClient {
527
529
  getFileUrl(fileId: string): string;
528
530
  }
529
531
 
532
+ /**
533
+ * Feedback client — reviews & comments via interfacer-feedback-service REST API.
534
+ *
535
+ * Auth: DID-signed headers (did-sign + did-pk), same pattern as DppClient.
536
+ * Ported from interfacer-gui lib/feedback.ts
537
+ */
538
+
539
+ interface Review {
540
+ id: string;
541
+ project_ulid: string;
542
+ user_ulid: string;
543
+ rating: number;
544
+ content?: string | null;
545
+ created_at: string;
546
+ updated_at: string;
547
+ }
548
+ interface ReviewSummary {
549
+ average_rating: number;
550
+ total_reviews: number;
551
+ rating_distribution: Record<number, number>;
552
+ }
553
+ interface Comment {
554
+ id: string;
555
+ project_ulid: string;
556
+ user_ulid: string;
557
+ parent_id?: string | null;
558
+ content: string;
559
+ attachments?: string | null;
560
+ status: string;
561
+ created_at: string;
562
+ updated_at: string;
563
+ }
564
+ interface GetReviewsParams {
565
+ limit?: number;
566
+ cursor?: number;
567
+ }
568
+ interface GetCommentsParams {
569
+ limit?: number;
570
+ cursor?: number;
571
+ parent_id?: string;
572
+ }
573
+ declare class FeedbackClient {
574
+ private config;
575
+ private store;
576
+ private baseUrl;
577
+ constructor(config: InterfacerConfig, store: KeyStorage);
578
+ private get url();
579
+ private get userId();
580
+ private signedHeaders;
581
+ private request;
582
+ /** Create or update a review (1-5 stars + optional text). Auth required. */
583
+ createReview(projectUlid: string, rating: number, content?: string): Promise<Review>;
584
+ /** Fetch paginated reviews for a project. Public. */
585
+ getReviews(projectUlid: string, params?: GetReviewsParams): Promise<{
586
+ reviews: Review[];
587
+ }>;
588
+ /** Fetch aggregated review stats for a project. Public. */
589
+ getReviewSummary(projectUlid: string): Promise<ReviewSummary>;
590
+ /** Fetch the current user's review for a project, or null. */
591
+ getUserReview(projectUlid: string): Promise<{
592
+ review: Review | null;
593
+ }>;
594
+ /** Delete a review by ID. Only the author can delete. Auth required. */
595
+ deleteReview(reviewId: string): Promise<{
596
+ status: string;
597
+ }>;
598
+ /** Post a comment (optionally as a reply to parent_id). Auth required. */
599
+ createComment(projectUlid: string, content: string, parentId?: string, attachments?: string): Promise<Comment>;
600
+ /** Fetch paginated comments for a project. Public. */
601
+ getComments(projectUlid: string, params?: GetCommentsParams): Promise<{
602
+ comments: Comment[];
603
+ }>;
604
+ /** Soft-delete a comment. Only the author can delete. Auth required. */
605
+ deleteComment(commentId: string): Promise<{
606
+ status: string;
607
+ }>;
608
+ }
609
+
530
610
  /**
531
611
  * File hashing and preparation for Zenflows and DPP uploads.
532
612
  *
@@ -977,6 +1057,7 @@ declare class InterfacerClient {
977
1057
  private _resources?;
978
1058
  private _files?;
979
1059
  private _dpp?;
1060
+ private _feedback?;
980
1061
  private _inbox?;
981
1062
  private _wallet?;
982
1063
  private _social?;
@@ -988,6 +1069,7 @@ declare class InterfacerClient {
988
1069
  get resources(): ResourceClient;
989
1070
  get files(): FileClient;
990
1071
  get dpp(): DppClient;
1072
+ get feedback(): FeedbackClient;
991
1073
  get inbox(): InboxClient;
992
1074
  get wallet(): WalletClient;
993
1075
  get social(): SocialClient;
@@ -1158,4 +1240,4 @@ declare function signDidRequest(body: string, store: KeyStorage): Promise<{
1158
1240
  */
1159
1241
  declare function signFileUpload(checksumHex: string, store: KeyStorage): Promise<string>;
1160
1242
 
1161
- export { AVAILABILITY_OPTIONS, AuthClient, CO2_THRESHOLDS_KG, type Contributor, type CreateProjectParams, type DerivedEndpoints, type DppAttachment, DppClient, type DppDocument, type DppStatus, ENERGY_THRESHOLDS_KWH, FileClient, type GqlFile, GraphQLClient, type ImageRef, ImportClient, InboxClient, type InstanceVariables, InterfacerClient, type InterfacerConfig, type KeyStorage, type Keyring, type License, type Location, MANUFACTURABLE_TRUE_TAG, type MachineRef, type MaterialRef, type ModelFile, POWER_COMPATIBILITY_OPTIONS, POWER_REQUIREMENT_THRESHOLDS_W, PRODUCT_CATEGORY_OPTIONS, type ProductFilters, type Project, type ProjectFilter, type ProjectModelMetadata, ProjectType, type Proposal, RECYCLABILITY_THRESHOLDS_PCT, REPAIRABILITY_AVAILABLE_TAG, REPLICABILITY_OPTIONS, ResourceClient, SERVICE_TYPE_OPTIONS, SYSTEM_TAG_PREFIXES, type ServiceFilters, SocialClient, TAG_PREFIX, TaggingClient, type UserChallenges, WalletClient, type ZenflowsFile, clearInstanceVariablesCache, createConfig, createMemoryStorage, deriveEndpointsFromProxy, derivedProductFilterTags, extractUserTagValues, formatImageSrc, getInstanceVariables, getResourceImage, isSystemTag, isUserTag, mergeTags, monotonicRangeTags, normalizeUserTagsForSave, prefixedTag, prepFileForZenflows, prepFilesForZenflows, rangeFilterTags, removeTagsWithPrefixes, signDidRequest, signFileUpload, signGraphQLRequest, slugifyTagValue, stripUserTagPrefix, userTag };
1243
+ export { AVAILABILITY_OPTIONS, AuthClient, CO2_THRESHOLDS_KG, type Comment, type Contributor, type CreateProjectParams, type DerivedEndpoints, type DppAttachment, DppClient, type DppDocument, type DppStatus, ENERGY_THRESHOLDS_KWH, FeedbackClient, FileClient, type GetCommentsParams, type GetReviewsParams, type GqlFile, GraphQLClient, type ImageRef, ImportClient, InboxClient, type InstanceVariables, InterfacerClient, type InterfacerConfig, type KeyStorage, type Keyring, type License, type Location, MANUFACTURABLE_TRUE_TAG, type MachineRef, type MaterialRef, type ModelFile, POWER_COMPATIBILITY_OPTIONS, POWER_REQUIREMENT_THRESHOLDS_W, PRODUCT_CATEGORY_OPTIONS, type ProductFilters, type Project, type ProjectFilter, type ProjectModelMetadata, ProjectType, type Proposal, RECYCLABILITY_THRESHOLDS_PCT, REPAIRABILITY_AVAILABLE_TAG, REPLICABILITY_OPTIONS, ResourceClient, type Review, type ReviewSummary, SERVICE_TYPE_OPTIONS, SYSTEM_TAG_PREFIXES, type ServiceFilters, SocialClient, TAG_PREFIX, TaggingClient, type UserChallenges, WalletClient, type ZenflowsFile, clearInstanceVariablesCache, createConfig, createMemoryStorage, deriveEndpointsFromProxy, derivedProductFilterTags, extractUserTagValues, formatImageSrc, getInstanceVariables, getResourceImage, isSystemTag, isUserTag, mergeTags, monotonicRangeTags, normalizeUserTagsForSave, prefixedTag, prepFileForZenflows, prepFilesForZenflows, rangeFilterTags, removeTagsWithPrefixes, signDidRequest, signFileUpload, signGraphQLRequest, slugifyTagValue, stripUserTagPrefix, userTag };
package/dist/index.js CHANGED
@@ -1090,6 +1090,125 @@ var DppClient = class {
1090
1090
  }
1091
1091
  };
1092
1092
 
1093
+ // src/feedback/FeedbackClient.ts
1094
+ init_sign();
1095
+ var FeedbackClient = class {
1096
+ constructor(config, store) {
1097
+ this.config = config;
1098
+ this.store = store;
1099
+ this.baseUrl = config.feedbackUrl || "";
1100
+ }
1101
+ config;
1102
+ store;
1103
+ baseUrl;
1104
+ get url() {
1105
+ if (!this.baseUrl) throw new Error("feedbackUrl not configured");
1106
+ return this.baseUrl;
1107
+ }
1108
+ get userId() {
1109
+ return this.store.getItem("authId") ?? void 0;
1110
+ }
1111
+ // ─── DID Signing ───────────────────────────────────────────────────
1112
+ async signedHeaders(body) {
1113
+ const headers = {};
1114
+ const uid = this.userId;
1115
+ if (uid) headers["x-user-id"] = uid;
1116
+ if (body) {
1117
+ const did = await signDidRequest(body, this.store);
1118
+ Object.assign(headers, did);
1119
+ headers["Content-Type"] = "application/json";
1120
+ }
1121
+ return headers;
1122
+ }
1123
+ async request(method, path, body) {
1124
+ const json = body != null ? JSON.stringify(body) : void 0;
1125
+ const headers = await this.signedHeaders(json ?? void 0);
1126
+ const res = await fetch(`${this.url}${path}`, { method, headers, body: json });
1127
+ if (!res.ok) {
1128
+ let errMsg = res.statusText;
1129
+ try {
1130
+ const err = await res.json();
1131
+ errMsg = err.error || errMsg;
1132
+ } catch {
1133
+ }
1134
+ throw new Error(`Feedback ${method} ${path} failed: ${errMsg}`);
1135
+ }
1136
+ if (res.status === 204) return void 0;
1137
+ return res.json();
1138
+ }
1139
+ // ─── Reviews ───────────────────────────────────────────────────────
1140
+ /** Create or update a review (1-5 stars + optional text). Auth required. */
1141
+ async createReview(projectUlid, rating, content) {
1142
+ return this.request(
1143
+ "POST",
1144
+ `/api/v1/projects/${encodeURIComponent(projectUlid)}/reviews`,
1145
+ { rating, content: content || null }
1146
+ );
1147
+ }
1148
+ /** Fetch paginated reviews for a project. Public. */
1149
+ async getReviews(projectUlid, params) {
1150
+ const qs = new URLSearchParams();
1151
+ if (params?.limit != null) qs.set("limit", String(params.limit));
1152
+ if (params?.cursor != null) qs.set("cursor", String(params.cursor));
1153
+ const query = qs.toString();
1154
+ const path = `/api/v1/projects/${encodeURIComponent(projectUlid)}/reviews${query ? `?${query}` : ""}`;
1155
+ return this.request("GET", path);
1156
+ }
1157
+ /** Fetch aggregated review stats for a project. Public. */
1158
+ async getReviewSummary(projectUlid) {
1159
+ return this.request(
1160
+ "GET",
1161
+ `/api/v1/projects/${encodeURIComponent(projectUlid)}/reviews/summary`
1162
+ );
1163
+ }
1164
+ /** Fetch the current user's review for a project, or null. */
1165
+ async getUserReview(projectUlid) {
1166
+ return this.request(
1167
+ "GET",
1168
+ `/api/v1/projects/${encodeURIComponent(projectUlid)}/reviews/mine`
1169
+ );
1170
+ }
1171
+ /** Delete a review by ID. Only the author can delete. Auth required. */
1172
+ async deleteReview(reviewId) {
1173
+ return this.request(
1174
+ "DELETE",
1175
+ `/api/v1/reviews/${encodeURIComponent(reviewId)}`,
1176
+ {}
1177
+ );
1178
+ }
1179
+ // ─── Comments ──────────────────────────────────────────────────────
1180
+ /** Post a comment (optionally as a reply to parent_id). Auth required. */
1181
+ async createComment(projectUlid, content, parentId, attachments) {
1182
+ return this.request(
1183
+ "POST",
1184
+ `/api/v1/projects/${encodeURIComponent(projectUlid)}/comments`,
1185
+ {
1186
+ content,
1187
+ parent_id: parentId || null,
1188
+ attachments: attachments || null
1189
+ }
1190
+ );
1191
+ }
1192
+ /** Fetch paginated comments for a project. Public. */
1193
+ async getComments(projectUlid, params) {
1194
+ const qs = new URLSearchParams();
1195
+ if (params?.limit != null) qs.set("limit", String(params.limit));
1196
+ if (params?.cursor != null) qs.set("cursor", String(params.cursor));
1197
+ if (params?.parent_id) qs.set("parent_id", params.parent_id);
1198
+ const query = qs.toString();
1199
+ const path = `/api/v1/projects/${encodeURIComponent(projectUlid)}/comments${query ? `?${query}` : ""}`;
1200
+ return this.request("GET", path);
1201
+ }
1202
+ /** Soft-delete a comment. Only the author can delete. Auth required. */
1203
+ async deleteComment(commentId) {
1204
+ return this.request(
1205
+ "DELETE",
1206
+ `/api/v1/comments/${encodeURIComponent(commentId)}`,
1207
+ {}
1208
+ );
1209
+ }
1210
+ };
1211
+
1093
1212
  // src/files/FileClient.ts
1094
1213
  init_hashing();
1095
1214
  var FileClient = class {
@@ -2144,6 +2263,7 @@ var InterfacerClient = class {
2144
2263
  _resources;
2145
2264
  _files;
2146
2265
  _dpp;
2266
+ _feedback;
2147
2267
  _inbox;
2148
2268
  _wallet;
2149
2269
  _social;
@@ -2169,6 +2289,9 @@ var InterfacerClient = class {
2169
2289
  get dpp() {
2170
2290
  return this._dpp ??= new DppClient(this.config, this.store);
2171
2291
  }
2292
+ get feedback() {
2293
+ return this._feedback ??= new FeedbackClient(this.config, this.store);
2294
+ }
2172
2295
  get inbox() {
2173
2296
  return this._inbox ??= new InboxClient(this.config, this.store);
2174
2297
  }
@@ -2265,6 +2388,7 @@ export {
2265
2388
  CO2_THRESHOLDS_KG,
2266
2389
  DppClient,
2267
2390
  ENERGY_THRESHOLDS_KWH,
2391
+ FeedbackClient,
2268
2392
  FileClient,
2269
2393
  GraphQLClient,
2270
2394
  ImportClient,