@fonderie/client 0.17.1 → 0.19.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
@@ -17,7 +17,8 @@ declare class FonderieApiError extends Error {
17
17
  readonly explanation: string;
18
18
  readonly status: number;
19
19
  readonly details?: unknown | undefined;
20
- constructor(reason: string, explanation: string, status: number, details?: unknown | undefined);
20
+ readonly requestId?: string | undefined;
21
+ constructor(reason: string, explanation: string, status: number, details?: unknown | undefined, requestId?: string | undefined);
21
22
  }
22
23
  interface IRequestOptions {
23
24
  method: string;
@@ -42,6 +43,7 @@ declare class HttpClient {
42
43
  private defaultTtlMs;
43
44
  private refresh;
44
45
  constructor(baseUrl: string, deps?: IHttpDeps);
46
+ absolute(path: string): string;
45
47
  clearCache(): void;
46
48
  request<T>(opts: IRequestOptions): Promise<T>;
47
49
  private exec;
@@ -466,6 +468,19 @@ interface ISessionDTO {
466
468
  interface ISessionsResult {
467
469
  sessions: ISessionDTO[];
468
470
  }
471
+ interface IMediaAssetDTO {
472
+ id: string;
473
+ url: string;
474
+ contentType: string;
475
+ byteSize: number;
476
+ ownerType: string;
477
+ ownerId: string;
478
+ purpose: string;
479
+ createdAt: string;
480
+ }
481
+ interface IMediaAssetResult {
482
+ asset: IMediaAssetDTO;
483
+ }
469
484
  interface IWebhookEndpointDTO {
470
485
  id: string;
471
486
  url: string;
@@ -907,6 +922,25 @@ declare class CustomersClient {
907
922
  removeLabel(labelId: string): Promise<IApiResponse<undefined>>;
908
923
  }
909
924
 
925
+ interface IUploadMediaInput {
926
+ dataBase64: string;
927
+ purpose?: string;
928
+ ownerType?: string;
929
+ ownerId?: string;
930
+ }
931
+ declare class MediaClient {
932
+ private http;
933
+ private tokens;
934
+ constructor(http: HttpClient, tokens: TokenStore);
935
+ setAccessToken(token: string | undefined): void;
936
+ upload(input: IUploadMediaInput): Promise<IApiResponse<IMediaAssetResult>>;
937
+ delete(id: string): Promise<IApiResponse<{
938
+ id: string;
939
+ }>>;
940
+ assetUrl(id: string): string;
941
+ assetIdFromUrl(url: string | null | undefined): string | null;
942
+ }
943
+
910
944
  interface ICreateWebhookEndpointInput {
911
945
  url: string;
912
946
  events?: string[];
@@ -1048,6 +1082,7 @@ declare class FonderieClient {
1048
1082
  readonly audit: AuditClient;
1049
1083
  readonly webhooks: WebhooksClient;
1050
1084
  readonly customers: CustomersClient;
1085
+ readonly media: MediaClient;
1051
1086
  private http;
1052
1087
  private tokens;
1053
1088
  private workspaceId;
@@ -1144,4 +1179,4 @@ declare class CourierAdminClient {
1144
1179
  rollback(type: string, input: IRollbackTemplateInput, locale?: string | null): Promise<IApiResponse<ITemplateEntry>>;
1145
1180
  }
1146
1181
 
1147
- export { AuditClient, AuthClient, BillingClient, ConfigAdminClient, CourierAdminClient, type CustomerLabelType, type CustomerSex, type CustomerType, CustomersClient, FonderieApiError, FonderieClient, type IAcceptInvitationResult, type IAddAddressInput, type IAddEmailInput, type IAddPhoneInput, type IAddRelationshipInput, type IAddressDTO, type IApiError, type IApiResponse, type IAuditEventDTO, type IAuditPageResult, type IBlacklistCustomerInput, type ICache, type ICancelSubscriptionInput, type IChangePasswordInput, type ICheckoutInput, type ICheckoutUrlResult, type IClientAuthConfig, type IConfigAdminClientOptions, type IConfigEntry, type IConfigRevision, type ICourierAdminClientOptions, type ICreateCustomerInput, type ICreatePlanInput, type ICreateRoleInput, type ICreateWebhookEndpointInput, type ICreateWorkspaceInput, type ICustomerAddressDTO, type ICustomerAddressListResult, type ICustomerAddressResult, type ICustomerDTO, type ICustomerDetailD2DTO, type ICustomerDetailDTO, type ICustomerEmailDTO, type ICustomerEmailListResult, type ICustomerEmailResult, type ICustomerLabelDTO, type ICustomerLabelListResult, type ICustomerListResult, type ICustomerNoteDTO, type ICustomerNoteListResult, type ICustomerNoteResult, type ICustomerPhoneDTO, type ICustomerPhoneListResult, type ICustomerPhoneResult, type ICustomerRelationshipDTO, type ICustomerRelationshipExpandedD2DTO, type ICustomerRelationshipExpandedDTO, type ICustomerRelationshipListResult, type ICustomerRelationshipResult, type ICustomerResult, type ICustomerShallowDTO, type ICustomerTagListResult, type IFonderieClientOptions, type IGetCustomerInput, type IGetLoginHistoryInput, type IInvitationDTO, type IInvitationListResult, type IInviteEntry, type IInviteResult, type IInvoiceDTO, type IInvoicesResult, type IListAuditEventsInput, type IListCustomersInput, type ILoginEventDTO, type ILoginHistoryPageResult, type ILoginInput, type ILoginResult, type IMeResult, type IMemberDTO, type IMemberListResult, type IMemoryCacheOptions, type IMfaEnabledResult, type IMfaRequiredResult, type IMfaSetupResult, type IPaymentMethodDTO, type IPaymentMethodResult, type IPlanDTO, type IPlanFeature, type IPlanListResult, type IPlanResult, type IPortalUrlResult, type IReadOptions, type IRecordUsageInput, type IRefreshResult, type IRegisterInput, type IRegisterResult, type IRequestConfig, type IResendVerificationResult, type IResetPasswordInput, type IRevealSecretResult, type IRoleDTO, type IRoleListResult, type IRolePermission, type IRolePermissionInput, type IRolePermissionsResult, type IRoleResult, type IRollbackInput, type IRollbackTemplateInput, type ISecretEntry, type ISecretRevision, type ISessionDTO, type ISessionsResult, type ISetConfigInput, type ISetSecretInput, type ISetTemplateInput, type ISubscriptionChangeResult, type ISubscriptionDTO, type ISubscriptionResult, type ITemplateEntry, type ITemplateRevision, type ITestWebhookResult, type ITokens, type IUpdateCustomerInput, type IUpdatePlanInput, type IUpdatePreferencesInput, type IUpdateProfileInput, type IUpdateRoleInput, type IUpdateSettingsInput, type IUpdateWebhookEndpointInput, type IUpdateWorkspaceInput, type IUsageResult, type IUserDTO, type IUserPreferences, type IVerifyEmailResult, type IWalletCheckoutInput, type IWalletDTO, type IWalletPreferencesInput, type IWalletPurchaseInput, type IWalletPurchaseResult, type IWalletResult, type IWalletTransactionDTO, type IWalletTransactionsResult, type IWebhookDeliveryDTO, type IWebhookDeliveryListResult, type IWebhookEndpointCreatedDTO, type IWebhookEndpointDTO, type IWebhookEndpointListResult, type IWorkspaceAddressDTO, type IWorkspaceDTO, type IWorkspaceListResult, type IWorkspaceResult, type IWorkspaceSettingsDTO, type IWorkspaceSettingsResult, type SubscriberType, WebhooksClient, WorkspacesClient, createMemoryCache, isMfaRequired };
1182
+ export { AuditClient, AuthClient, BillingClient, ConfigAdminClient, CourierAdminClient, type CustomerLabelType, type CustomerSex, type CustomerType, CustomersClient, FonderieApiError, FonderieClient, type IAcceptInvitationResult, type IAddAddressInput, type IAddEmailInput, type IAddPhoneInput, type IAddRelationshipInput, type IAddressDTO, type IApiError, type IApiResponse, type IAuditEventDTO, type IAuditPageResult, type IBlacklistCustomerInput, type ICache, type ICancelSubscriptionInput, type IChangePasswordInput, type ICheckoutInput, type ICheckoutUrlResult, type IClientAuthConfig, type IConfigAdminClientOptions, type IConfigEntry, type IConfigRevision, type ICourierAdminClientOptions, type ICreateCustomerInput, type ICreatePlanInput, type ICreateRoleInput, type ICreateWebhookEndpointInput, type ICreateWorkspaceInput, type ICustomerAddressDTO, type ICustomerAddressListResult, type ICustomerAddressResult, type ICustomerDTO, type ICustomerDetailD2DTO, type ICustomerDetailDTO, type ICustomerEmailDTO, type ICustomerEmailListResult, type ICustomerEmailResult, type ICustomerLabelDTO, type ICustomerLabelListResult, type ICustomerListResult, type ICustomerNoteDTO, type ICustomerNoteListResult, type ICustomerNoteResult, type ICustomerPhoneDTO, type ICustomerPhoneListResult, type ICustomerPhoneResult, type ICustomerRelationshipDTO, type ICustomerRelationshipExpandedD2DTO, type ICustomerRelationshipExpandedDTO, type ICustomerRelationshipListResult, type ICustomerRelationshipResult, type ICustomerResult, type ICustomerShallowDTO, type ICustomerTagListResult, type IFonderieClientOptions, type IGetCustomerInput, type IGetLoginHistoryInput, type IInvitationDTO, type IInvitationListResult, type IInviteEntry, type IInviteResult, type IInvoiceDTO, type IInvoicesResult, type IListAuditEventsInput, type IListCustomersInput, type ILoginEventDTO, type ILoginHistoryPageResult, type ILoginInput, type ILoginResult, type IMeResult, type IMediaAssetDTO, type IMediaAssetResult, type IMemberDTO, type IMemberListResult, type IMemoryCacheOptions, type IMfaEnabledResult, type IMfaRequiredResult, type IMfaSetupResult, type IPaymentMethodDTO, type IPaymentMethodResult, type IPlanDTO, type IPlanFeature, type IPlanListResult, type IPlanResult, type IPortalUrlResult, type IReadOptions, type IRecordUsageInput, type IRefreshResult, type IRegisterInput, type IRegisterResult, type IRequestConfig, type IResendVerificationResult, type IResetPasswordInput, type IRevealSecretResult, type IRoleDTO, type IRoleListResult, type IRolePermission, type IRolePermissionInput, type IRolePermissionsResult, type IRoleResult, type IRollbackInput, type IRollbackTemplateInput, type ISecretEntry, type ISecretRevision, type ISessionDTO, type ISessionsResult, type ISetConfigInput, type ISetSecretInput, type ISetTemplateInput, type ISubscriptionChangeResult, type ISubscriptionDTO, type ISubscriptionResult, type ITemplateEntry, type ITemplateRevision, type ITestWebhookResult, type ITokens, type IUpdateCustomerInput, type IUpdatePlanInput, type IUpdatePreferencesInput, type IUpdateProfileInput, type IUpdateRoleInput, type IUpdateSettingsInput, type IUpdateWebhookEndpointInput, type IUpdateWorkspaceInput, type IUploadMediaInput, type IUsageResult, type IUserDTO, type IUserPreferences, type IVerifyEmailResult, type IWalletCheckoutInput, type IWalletDTO, type IWalletPreferencesInput, type IWalletPurchaseInput, type IWalletPurchaseResult, type IWalletResult, type IWalletTransactionDTO, type IWalletTransactionsResult, type IWebhookDeliveryDTO, type IWebhookDeliveryListResult, type IWebhookEndpointCreatedDTO, type IWebhookEndpointDTO, type IWebhookEndpointListResult, type IWorkspaceAddressDTO, type IWorkspaceDTO, type IWorkspaceListResult, type IWorkspaceResult, type IWorkspaceSettingsDTO, type IWorkspaceSettingsResult, MediaClient, type SubscriberType, WebhooksClient, WorkspacesClient, createMemoryCache, isMfaRequired };
package/dist/index.d.ts CHANGED
@@ -17,7 +17,8 @@ declare class FonderieApiError extends Error {
17
17
  readonly explanation: string;
18
18
  readonly status: number;
19
19
  readonly details?: unknown | undefined;
20
- constructor(reason: string, explanation: string, status: number, details?: unknown | undefined);
20
+ readonly requestId?: string | undefined;
21
+ constructor(reason: string, explanation: string, status: number, details?: unknown | undefined, requestId?: string | undefined);
21
22
  }
22
23
  interface IRequestOptions {
23
24
  method: string;
@@ -42,6 +43,7 @@ declare class HttpClient {
42
43
  private defaultTtlMs;
43
44
  private refresh;
44
45
  constructor(baseUrl: string, deps?: IHttpDeps);
46
+ absolute(path: string): string;
45
47
  clearCache(): void;
46
48
  request<T>(opts: IRequestOptions): Promise<T>;
47
49
  private exec;
@@ -466,6 +468,19 @@ interface ISessionDTO {
466
468
  interface ISessionsResult {
467
469
  sessions: ISessionDTO[];
468
470
  }
471
+ interface IMediaAssetDTO {
472
+ id: string;
473
+ url: string;
474
+ contentType: string;
475
+ byteSize: number;
476
+ ownerType: string;
477
+ ownerId: string;
478
+ purpose: string;
479
+ createdAt: string;
480
+ }
481
+ interface IMediaAssetResult {
482
+ asset: IMediaAssetDTO;
483
+ }
469
484
  interface IWebhookEndpointDTO {
470
485
  id: string;
471
486
  url: string;
@@ -907,6 +922,25 @@ declare class CustomersClient {
907
922
  removeLabel(labelId: string): Promise<IApiResponse<undefined>>;
908
923
  }
909
924
 
925
+ interface IUploadMediaInput {
926
+ dataBase64: string;
927
+ purpose?: string;
928
+ ownerType?: string;
929
+ ownerId?: string;
930
+ }
931
+ declare class MediaClient {
932
+ private http;
933
+ private tokens;
934
+ constructor(http: HttpClient, tokens: TokenStore);
935
+ setAccessToken(token: string | undefined): void;
936
+ upload(input: IUploadMediaInput): Promise<IApiResponse<IMediaAssetResult>>;
937
+ delete(id: string): Promise<IApiResponse<{
938
+ id: string;
939
+ }>>;
940
+ assetUrl(id: string): string;
941
+ assetIdFromUrl(url: string | null | undefined): string | null;
942
+ }
943
+
910
944
  interface ICreateWebhookEndpointInput {
911
945
  url: string;
912
946
  events?: string[];
@@ -1048,6 +1082,7 @@ declare class FonderieClient {
1048
1082
  readonly audit: AuditClient;
1049
1083
  readonly webhooks: WebhooksClient;
1050
1084
  readonly customers: CustomersClient;
1085
+ readonly media: MediaClient;
1051
1086
  private http;
1052
1087
  private tokens;
1053
1088
  private workspaceId;
@@ -1144,4 +1179,4 @@ declare class CourierAdminClient {
1144
1179
  rollback(type: string, input: IRollbackTemplateInput, locale?: string | null): Promise<IApiResponse<ITemplateEntry>>;
1145
1180
  }
1146
1181
 
1147
- export { AuditClient, AuthClient, BillingClient, ConfigAdminClient, CourierAdminClient, type CustomerLabelType, type CustomerSex, type CustomerType, CustomersClient, FonderieApiError, FonderieClient, type IAcceptInvitationResult, type IAddAddressInput, type IAddEmailInput, type IAddPhoneInput, type IAddRelationshipInput, type IAddressDTO, type IApiError, type IApiResponse, type IAuditEventDTO, type IAuditPageResult, type IBlacklistCustomerInput, type ICache, type ICancelSubscriptionInput, type IChangePasswordInput, type ICheckoutInput, type ICheckoutUrlResult, type IClientAuthConfig, type IConfigAdminClientOptions, type IConfigEntry, type IConfigRevision, type ICourierAdminClientOptions, type ICreateCustomerInput, type ICreatePlanInput, type ICreateRoleInput, type ICreateWebhookEndpointInput, type ICreateWorkspaceInput, type ICustomerAddressDTO, type ICustomerAddressListResult, type ICustomerAddressResult, type ICustomerDTO, type ICustomerDetailD2DTO, type ICustomerDetailDTO, type ICustomerEmailDTO, type ICustomerEmailListResult, type ICustomerEmailResult, type ICustomerLabelDTO, type ICustomerLabelListResult, type ICustomerListResult, type ICustomerNoteDTO, type ICustomerNoteListResult, type ICustomerNoteResult, type ICustomerPhoneDTO, type ICustomerPhoneListResult, type ICustomerPhoneResult, type ICustomerRelationshipDTO, type ICustomerRelationshipExpandedD2DTO, type ICustomerRelationshipExpandedDTO, type ICustomerRelationshipListResult, type ICustomerRelationshipResult, type ICustomerResult, type ICustomerShallowDTO, type ICustomerTagListResult, type IFonderieClientOptions, type IGetCustomerInput, type IGetLoginHistoryInput, type IInvitationDTO, type IInvitationListResult, type IInviteEntry, type IInviteResult, type IInvoiceDTO, type IInvoicesResult, type IListAuditEventsInput, type IListCustomersInput, type ILoginEventDTO, type ILoginHistoryPageResult, type ILoginInput, type ILoginResult, type IMeResult, type IMemberDTO, type IMemberListResult, type IMemoryCacheOptions, type IMfaEnabledResult, type IMfaRequiredResult, type IMfaSetupResult, type IPaymentMethodDTO, type IPaymentMethodResult, type IPlanDTO, type IPlanFeature, type IPlanListResult, type IPlanResult, type IPortalUrlResult, type IReadOptions, type IRecordUsageInput, type IRefreshResult, type IRegisterInput, type IRegisterResult, type IRequestConfig, type IResendVerificationResult, type IResetPasswordInput, type IRevealSecretResult, type IRoleDTO, type IRoleListResult, type IRolePermission, type IRolePermissionInput, type IRolePermissionsResult, type IRoleResult, type IRollbackInput, type IRollbackTemplateInput, type ISecretEntry, type ISecretRevision, type ISessionDTO, type ISessionsResult, type ISetConfigInput, type ISetSecretInput, type ISetTemplateInput, type ISubscriptionChangeResult, type ISubscriptionDTO, type ISubscriptionResult, type ITemplateEntry, type ITemplateRevision, type ITestWebhookResult, type ITokens, type IUpdateCustomerInput, type IUpdatePlanInput, type IUpdatePreferencesInput, type IUpdateProfileInput, type IUpdateRoleInput, type IUpdateSettingsInput, type IUpdateWebhookEndpointInput, type IUpdateWorkspaceInput, type IUsageResult, type IUserDTO, type IUserPreferences, type IVerifyEmailResult, type IWalletCheckoutInput, type IWalletDTO, type IWalletPreferencesInput, type IWalletPurchaseInput, type IWalletPurchaseResult, type IWalletResult, type IWalletTransactionDTO, type IWalletTransactionsResult, type IWebhookDeliveryDTO, type IWebhookDeliveryListResult, type IWebhookEndpointCreatedDTO, type IWebhookEndpointDTO, type IWebhookEndpointListResult, type IWorkspaceAddressDTO, type IWorkspaceDTO, type IWorkspaceListResult, type IWorkspaceResult, type IWorkspaceSettingsDTO, type IWorkspaceSettingsResult, type SubscriberType, WebhooksClient, WorkspacesClient, createMemoryCache, isMfaRequired };
1182
+ export { AuditClient, AuthClient, BillingClient, ConfigAdminClient, CourierAdminClient, type CustomerLabelType, type CustomerSex, type CustomerType, CustomersClient, FonderieApiError, FonderieClient, type IAcceptInvitationResult, type IAddAddressInput, type IAddEmailInput, type IAddPhoneInput, type IAddRelationshipInput, type IAddressDTO, type IApiError, type IApiResponse, type IAuditEventDTO, type IAuditPageResult, type IBlacklistCustomerInput, type ICache, type ICancelSubscriptionInput, type IChangePasswordInput, type ICheckoutInput, type ICheckoutUrlResult, type IClientAuthConfig, type IConfigAdminClientOptions, type IConfigEntry, type IConfigRevision, type ICourierAdminClientOptions, type ICreateCustomerInput, type ICreatePlanInput, type ICreateRoleInput, type ICreateWebhookEndpointInput, type ICreateWorkspaceInput, type ICustomerAddressDTO, type ICustomerAddressListResult, type ICustomerAddressResult, type ICustomerDTO, type ICustomerDetailD2DTO, type ICustomerDetailDTO, type ICustomerEmailDTO, type ICustomerEmailListResult, type ICustomerEmailResult, type ICustomerLabelDTO, type ICustomerLabelListResult, type ICustomerListResult, type ICustomerNoteDTO, type ICustomerNoteListResult, type ICustomerNoteResult, type ICustomerPhoneDTO, type ICustomerPhoneListResult, type ICustomerPhoneResult, type ICustomerRelationshipDTO, type ICustomerRelationshipExpandedD2DTO, type ICustomerRelationshipExpandedDTO, type ICustomerRelationshipListResult, type ICustomerRelationshipResult, type ICustomerResult, type ICustomerShallowDTO, type ICustomerTagListResult, type IFonderieClientOptions, type IGetCustomerInput, type IGetLoginHistoryInput, type IInvitationDTO, type IInvitationListResult, type IInviteEntry, type IInviteResult, type IInvoiceDTO, type IInvoicesResult, type IListAuditEventsInput, type IListCustomersInput, type ILoginEventDTO, type ILoginHistoryPageResult, type ILoginInput, type ILoginResult, type IMeResult, type IMediaAssetDTO, type IMediaAssetResult, type IMemberDTO, type IMemberListResult, type IMemoryCacheOptions, type IMfaEnabledResult, type IMfaRequiredResult, type IMfaSetupResult, type IPaymentMethodDTO, type IPaymentMethodResult, type IPlanDTO, type IPlanFeature, type IPlanListResult, type IPlanResult, type IPortalUrlResult, type IReadOptions, type IRecordUsageInput, type IRefreshResult, type IRegisterInput, type IRegisterResult, type IRequestConfig, type IResendVerificationResult, type IResetPasswordInput, type IRevealSecretResult, type IRoleDTO, type IRoleListResult, type IRolePermission, type IRolePermissionInput, type IRolePermissionsResult, type IRoleResult, type IRollbackInput, type IRollbackTemplateInput, type ISecretEntry, type ISecretRevision, type ISessionDTO, type ISessionsResult, type ISetConfigInput, type ISetSecretInput, type ISetTemplateInput, type ISubscriptionChangeResult, type ISubscriptionDTO, type ISubscriptionResult, type ITemplateEntry, type ITemplateRevision, type ITestWebhookResult, type ITokens, type IUpdateCustomerInput, type IUpdatePlanInput, type IUpdatePreferencesInput, type IUpdateProfileInput, type IUpdateRoleInput, type IUpdateSettingsInput, type IUpdateWebhookEndpointInput, type IUpdateWorkspaceInput, type IUploadMediaInput, type IUsageResult, type IUserDTO, type IUserPreferences, type IVerifyEmailResult, type IWalletCheckoutInput, type IWalletDTO, type IWalletPreferencesInput, type IWalletPurchaseInput, type IWalletPurchaseResult, type IWalletResult, type IWalletTransactionDTO, type IWalletTransactionsResult, type IWebhookDeliveryDTO, type IWebhookDeliveryListResult, type IWebhookEndpointCreatedDTO, type IWebhookEndpointDTO, type IWebhookEndpointListResult, type IWorkspaceAddressDTO, type IWorkspaceDTO, type IWorkspaceListResult, type IWorkspaceResult, type IWorkspaceSettingsDTO, type IWorkspaceSettingsResult, MediaClient, type SubscriberType, WebhooksClient, WorkspacesClient, createMemoryCache, isMfaRequired };
package/dist/index.js CHANGED
@@ -37,19 +37,26 @@ function createMemoryCache(opts = {}) {
37
37
 
38
38
  // src/http.ts
39
39
  var FonderieApiError = class extends Error {
40
- constructor(reason, explanation, status, details) {
40
+ constructor(reason, explanation, status, details, requestId) {
41
41
  super(explanation);
42
42
  this.reason = reason;
43
43
  this.explanation = explanation;
44
44
  this.status = status;
45
45
  this.details = details;
46
+ this.requestId = requestId;
46
47
  this.name = "FonderieApiError";
47
48
  }
48
49
  reason;
49
50
  explanation;
50
51
  status;
51
52
  details;
53
+ requestId;
52
54
  };
55
+ function newRequestId() {
56
+ const c = globalThis.crypto;
57
+ if (c?.randomUUID) return c.randomUUID();
58
+ return `r-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
59
+ }
53
60
  var HttpClient = class {
54
61
  constructor(baseUrl, deps = {}) {
55
62
  this.baseUrl = baseUrl;
@@ -61,6 +68,12 @@ var HttpClient = class {
61
68
  cache;
62
69
  defaultTtlMs;
63
70
  refresh;
71
+ // Absolute URL for a path on this client's origin — for endpoints a browser
72
+ // navigates to or embeds (e.g. a public `<img src>`) rather than fetches
73
+ // through request(). Mirrors the `${baseUrl}${path}` join request() uses.
74
+ absolute(path) {
75
+ return `${this.baseUrl}${path}`;
76
+ }
64
77
  // Drop all cached responses — sign-out must not leave one session's data
65
78
  // servable to the next.
66
79
  clearCache() {
@@ -91,7 +104,11 @@ var HttpClient = class {
91
104
  return data;
92
105
  }
93
106
  async exec(opts, retried = false) {
94
- const headers = { "Content-Type": "application/json" };
107
+ const requestId = newRequestId();
108
+ const headers = {
109
+ "Content-Type": "application/json",
110
+ "X-Request-ID": requestId
111
+ };
95
112
  if (opts.token) headers["Authorization"] = `Bearer ${opts.token}`;
96
113
  if (opts.cookie) headers["Cookie"] = opts.cookie;
97
114
  if (opts.workspaceId) headers["X-Workspace-ID"] = opts.workspaceId;
@@ -99,18 +116,19 @@ var HttpClient = class {
99
116
  const fetchInit = { method: opts.method, headers, credentials: "include" };
100
117
  if (opts.body !== void 0) fetchInit.body = JSON.stringify(opts.body);
101
118
  const res = await fetch(`${this.baseUrl}${opts.path}`, fetchInit);
119
+ const rid = res.headers.get("x-request-id") ?? requestId;
102
120
  if (res.status === 401 && this.refresh && !retried && !opts.path.startsWith("/auth/")) {
103
121
  const newToken = await this.refresh();
104
122
  if (newToken) return this.exec({ ...opts, token: newToken }, true);
105
123
  }
106
124
  if (res.status === 204) {
107
- if (!res.ok) throw new FonderieApiError("unknown", res.statusText, res.status);
125
+ if (!res.ok) throw new FonderieApiError("unknown", res.statusText, res.status, void 0, rid);
108
126
  return void 0;
109
127
  }
110
128
  const data = await res.json();
111
129
  if (!res.ok || res.status === 202) {
112
130
  const err = data;
113
- throw new FonderieApiError(err.reason, err.explanation, res.status, err.details);
131
+ throw new FonderieApiError(err.reason, err.explanation, res.status, err.details, rid);
114
132
  }
115
133
  return data;
116
134
  }
@@ -983,6 +1001,55 @@ var CustomersClient = class {
983
1001
  }
984
1002
  };
985
1003
 
1004
+ // src/modules/media.ts
1005
+ var MediaClient = class {
1006
+ constructor(http, tokens) {
1007
+ this.http = http;
1008
+ this.tokens = tokens;
1009
+ }
1010
+ http;
1011
+ tokens;
1012
+ setAccessToken(token) {
1013
+ this.tokens.set(token);
1014
+ }
1015
+ // POST /media — store an image; returns the asset with its monomorphic
1016
+ // /media/:id url. requireAuth server-side.
1017
+ upload(input) {
1018
+ return this.http.request({
1019
+ method: "POST",
1020
+ path: "/media",
1021
+ body: input,
1022
+ token: this.tokens.get()
1023
+ });
1024
+ }
1025
+ // DELETE /media/:id — uploader-only (403 for anyone else).
1026
+ delete(id) {
1027
+ return this.http.request({
1028
+ method: "DELETE",
1029
+ path: `/media/${encodeURIComponent(id)}`,
1030
+ token: this.tokens.get()
1031
+ });
1032
+ }
1033
+ // Absolute URL for a stored asset — an `<img src>` target. The GET /media/:id
1034
+ // route is public and cached (it can't carry a Bearer token), so turn an
1035
+ // upload's `asset.id` into a browser-loadable URL with this, and use it as
1036
+ // the avatarUrl handed to auth's updateProfile.
1037
+ assetUrl(id) {
1038
+ return this.http.absolute(`/media/${encodeURIComponent(id)}`);
1039
+ }
1040
+ // Inverse of assetUrl: pull the asset id out of one of THIS brick's
1041
+ // /media/:id URLs (absolute or relative); null for empty/external URLs. Lets
1042
+ // avatar cleanup delete only assets we minted (matched as a UUID), never a
1043
+ // placeholder or third-party avatar URL.
1044
+ assetIdFromUrl(url) {
1045
+ if (!url) return null;
1046
+ const m = url.match(
1047
+ /\/media\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?:[/?#]|$)/i
1048
+ );
1049
+ return m ? m[1] : null;
1050
+ }
1051
+ };
1052
+
986
1053
  // src/modules/webhooks.ts
987
1054
  var WebhooksClient = class {
988
1055
  constructor(http, tokens) {
@@ -1318,6 +1385,7 @@ var FonderieClient = class {
1318
1385
  audit;
1319
1386
  webhooks;
1320
1387
  customers;
1388
+ media;
1321
1389
  http;
1322
1390
  tokens;
1323
1391
  workspaceId;
@@ -1340,6 +1408,7 @@ var FonderieClient = class {
1340
1408
  this.audit = new AuditClient(this.http, this.tokens);
1341
1409
  this.webhooks = new WebhooksClient(this.http, this.tokens);
1342
1410
  this.customers = new CustomersClient(this.http, this.tokens);
1411
+ this.media = new MediaClient(this.http, this.tokens);
1343
1412
  if (opts.workspaceId !== void 0) this.setWorkspaceId(opts.workspaceId);
1344
1413
  }
1345
1414
  // Single-flight refresh: POST /auth/refresh with the app-supplied refresh
@@ -1627,6 +1696,7 @@ export {
1627
1696
  CustomersClient,
1628
1697
  FonderieApiError,
1629
1698
  FonderieClient,
1699
+ MediaClient,
1630
1700
  WebhooksClient,
1631
1701
  WorkspacesClient,
1632
1702
  createMemoryCache,