@fonderie/client 0.17.1 → 0.18.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.
@@ -48,6 +48,7 @@ new FonderieClient(opts: IFonderieClientOptions): FonderieClient
48
48
  .audit: AuditClient
49
49
  .webhooks: WebhooksClient
50
50
  .customers: CustomersClient
51
+ .media: MediaClient
51
52
  .setAccessToken(token: string | undefined): void
52
53
  .clearCache(): void
53
54
  .setWorkspaceId(workspaceId: string | undefined): void
@@ -377,6 +378,20 @@ new CustomersClient(http: HttpClient, tokens: TokenStore): CustomersClient
377
378
  .listLabels(type: CustomerLabelType, opts?: IReadOptions | undefined): Promise<IApiResponse<ICustomerLabelListResult>>
378
379
  .removeLabel(labelId: string): Promise<IApiResponse<undefined>>
379
380
 
381
+ interface IUploadMediaInput {
382
+ dataBase64: string;
383
+ purpose?: string;
384
+ ownerType?: string;
385
+ ownerId?: string;
386
+ }
387
+
388
+ new MediaClient(http: HttpClient, tokens: TokenStore): MediaClient
389
+ .setAccessToken(token: string | undefined): void
390
+ .upload(input: IUploadMediaInput): Promise<IApiResponse<IMediaAssetResult>>
391
+ .delete(id: string): Promise<IApiResponse<{ id: string; }>>
392
+ .assetUrl(id: string): string
393
+ .assetIdFromUrl(url: string | null | undefined): string | null
394
+
380
395
  interface ICreateWebhookEndpointInput {
381
396
  url: string;
382
397
  events?: string[];
@@ -800,6 +815,21 @@ interface ILoginResult {
800
815
  requiresVerification?: boolean;
801
816
  }
802
817
 
818
+ interface IMediaAssetDTO {
819
+ id: string;
820
+ url: string;
821
+ contentType: string;
822
+ byteSize: number;
823
+ ownerType: string;
824
+ ownerId: string;
825
+ purpose: string;
826
+ createdAt: string;
827
+ }
828
+
829
+ interface IMediaAssetResult {
830
+ asset: IMediaAssetDTO;
831
+ }
832
+
803
833
  interface IMemberDTO {
804
834
  userId: string;
805
835
  workspaceId: string;
package/dist/index.cjs CHANGED
@@ -28,6 +28,7 @@ __export(index_exports, {
28
28
  CustomersClient: () => CustomersClient,
29
29
  FonderieApiError: () => FonderieApiError,
30
30
  FonderieClient: () => FonderieClient,
31
+ MediaClient: () => MediaClient,
31
32
  WebhooksClient: () => WebhooksClient,
32
33
  WorkspacesClient: () => WorkspacesClient,
33
34
  createMemoryCache: () => createMemoryCache,
@@ -98,6 +99,12 @@ var HttpClient = class {
98
99
  cache;
99
100
  defaultTtlMs;
100
101
  refresh;
102
+ // Absolute URL for a path on this client's origin — for endpoints a browser
103
+ // navigates to or embeds (e.g. a public `<img src>`) rather than fetches
104
+ // through request(). Mirrors the `${baseUrl}${path}` join request() uses.
105
+ absolute(path) {
106
+ return `${this.baseUrl}${path}`;
107
+ }
101
108
  // Drop all cached responses — sign-out must not leave one session's data
102
109
  // servable to the next.
103
110
  clearCache() {
@@ -1020,6 +1027,55 @@ var CustomersClient = class {
1020
1027
  }
1021
1028
  };
1022
1029
 
1030
+ // src/modules/media.ts
1031
+ var MediaClient = class {
1032
+ constructor(http, tokens) {
1033
+ this.http = http;
1034
+ this.tokens = tokens;
1035
+ }
1036
+ http;
1037
+ tokens;
1038
+ setAccessToken(token) {
1039
+ this.tokens.set(token);
1040
+ }
1041
+ // POST /media — store an image; returns the asset with its monomorphic
1042
+ // /media/:id url. requireAuth server-side.
1043
+ upload(input) {
1044
+ return this.http.request({
1045
+ method: "POST",
1046
+ path: "/media",
1047
+ body: input,
1048
+ token: this.tokens.get()
1049
+ });
1050
+ }
1051
+ // DELETE /media/:id — uploader-only (403 for anyone else).
1052
+ delete(id) {
1053
+ return this.http.request({
1054
+ method: "DELETE",
1055
+ path: `/media/${encodeURIComponent(id)}`,
1056
+ token: this.tokens.get()
1057
+ });
1058
+ }
1059
+ // Absolute URL for a stored asset — an `<img src>` target. The GET /media/:id
1060
+ // route is public and cached (it can't carry a Bearer token), so turn an
1061
+ // upload's `asset.id` into a browser-loadable URL with this, and use it as
1062
+ // the avatarUrl handed to auth's updateProfile.
1063
+ assetUrl(id) {
1064
+ return this.http.absolute(`/media/${encodeURIComponent(id)}`);
1065
+ }
1066
+ // Inverse of assetUrl: pull the asset id out of one of THIS brick's
1067
+ // /media/:id URLs (absolute or relative); null for empty/external URLs. Lets
1068
+ // avatar cleanup delete only assets we minted (matched as a UUID), never a
1069
+ // placeholder or third-party avatar URL.
1070
+ assetIdFromUrl(url) {
1071
+ if (!url) return null;
1072
+ const m = url.match(
1073
+ /\/media\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?:[/?#]|$)/i
1074
+ );
1075
+ return m ? m[1] : null;
1076
+ }
1077
+ };
1078
+
1023
1079
  // src/modules/webhooks.ts
1024
1080
  var WebhooksClient = class {
1025
1081
  constructor(http, tokens) {
@@ -1355,6 +1411,7 @@ var FonderieClient = class {
1355
1411
  audit;
1356
1412
  webhooks;
1357
1413
  customers;
1414
+ media;
1358
1415
  http;
1359
1416
  tokens;
1360
1417
  workspaceId;
@@ -1377,6 +1434,7 @@ var FonderieClient = class {
1377
1434
  this.audit = new AuditClient(this.http, this.tokens);
1378
1435
  this.webhooks = new WebhooksClient(this.http, this.tokens);
1379
1436
  this.customers = new CustomersClient(this.http, this.tokens);
1437
+ this.media = new MediaClient(this.http, this.tokens);
1380
1438
  if (opts.workspaceId !== void 0) this.setWorkspaceId(opts.workspaceId);
1381
1439
  }
1382
1440
  // Single-flight refresh: POST /auth/refresh with the app-supplied refresh
@@ -1665,6 +1723,7 @@ function isMfaRequired(result) {
1665
1723
  CustomersClient,
1666
1724
  FonderieApiError,
1667
1725
  FonderieClient,
1726
+ MediaClient,
1668
1727
  WebhooksClient,
1669
1728
  WorkspacesClient,
1670
1729
  createMemoryCache,