@fonderie/client 0.6.0 → 0.8.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.ts CHANGED
@@ -41,6 +41,7 @@ declare class HttpClient {
41
41
  private defaultTtlMs;
42
42
  private refresh;
43
43
  constructor(baseUrl: string, deps?: IHttpDeps);
44
+ clearCache(): void;
44
45
  request<T>(opts: IRequestOptions): Promise<T>;
45
46
  private exec;
46
47
  }
@@ -110,6 +111,10 @@ interface ILoginResult {
110
111
  tokens: ITokens;
111
112
  user: IUserDTO;
112
113
  }
114
+ interface IMfaRequiredResult {
115
+ mfaToken: string;
116
+ }
117
+ declare function isMfaRequired(result: ILoginResult | IMfaRequiredResult): result is IMfaRequiredResult;
113
118
  interface IRefreshResult {
114
119
  tokens: ITokens;
115
120
  }
@@ -593,7 +598,7 @@ declare class AuthClient {
593
598
  constructor(http: HttpClient, tokens: TokenStore);
594
599
  setAccessToken(token: string | undefined): void;
595
600
  register(input: IRegisterInput): Promise<IApiResponse<IRegisterResult>>;
596
- login(input: ILoginInput): Promise<IApiResponse<ILoginResult>>;
601
+ login(input: ILoginInput): Promise<IApiResponse<ILoginResult | IMfaRequiredResult>>;
597
602
  refreshTokens(refreshToken?: string): Promise<IApiResponse<IRefreshResult>>;
598
603
  forgotPassword(email: string): Promise<IApiResponse<undefined>>;
599
604
  resetPassword(input: IResetPasswordInput): Promise<IApiResponse<undefined>>;
@@ -977,4 +982,4 @@ declare class CourierAdminClient {
977
982
  rollback(type: string, input: IRollbackTemplateInput, locale?: string | null): Promise<IApiResponse<ITemplateEntry>>;
978
983
  }
979
984
 
980
- 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 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 IInvitationDTO, type IInvitationListResult, type IInviteEntry, type IInviteResult, type IListAuditEventsInput, type IListCustomersInput, type ILoginInput, type ILoginResult, type IMeResult, type IMemberDTO, type IMemberListResult, type IMemoryCacheOptions, type IMfaEnabledResult, type IMfaSetupResult, type IPlanDTO, type IPlanFeature, type IPlanListResult, type IPlanResult, type IPortalUrlResult, 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 ISetConfigInput, type ISetSecretInput, type ISetTemplateInput, 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 IUserSkill, type IVerifyEmailResult, 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 };
985
+ 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 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 IInvitationDTO, type IInvitationListResult, type IInviteEntry, type IInviteResult, type IListAuditEventsInput, type IListCustomersInput, type ILoginInput, type ILoginResult, type IMeResult, type IMemberDTO, type IMemberListResult, type IMemoryCacheOptions, type IMfaEnabledResult, type IMfaRequiredResult, type IMfaSetupResult, type IPlanDTO, type IPlanFeature, type IPlanListResult, type IPlanResult, type IPortalUrlResult, 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 ISetConfigInput, type ISetSecretInput, type ISetTemplateInput, 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 IUserSkill, type IVerifyEmailResult, 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 };
package/dist/index.js CHANGED
@@ -61,6 +61,11 @@ var HttpClient = class {
61
61
  cache;
62
62
  defaultTtlMs;
63
63
  refresh;
64
+ // Drop all cached responses — sign-out must not leave one session's data
65
+ // servable to the next.
66
+ clearCache() {
67
+ this.cache?.clear();
68
+ }
64
69
  async request(opts) {
65
70
  const method = opts.method.toUpperCase();
66
71
  const cache = this.cache;
@@ -208,6 +213,7 @@ var AuthClient = class {
208
213
  mfa;
209
214
  setAccessToken(token) {
210
215
  this.tokens.set(token);
216
+ if (!token) this.http.clearCache();
211
217
  }
212
218
  // ── Public ─────────────────────────────────────────────────────────────────
213
219
  register(input) {
@@ -1124,6 +1130,7 @@ var FonderieClient = class {
1124
1130
  this.audit = new AuditClient(this.http, this.tokens);
1125
1131
  this.webhooks = new WebhooksClient(this.http, this.tokens);
1126
1132
  this.customers = new CustomersClient(this.http, this.tokens);
1133
+ if (opts.workspaceId !== void 0) this.setWorkspaceId(opts.workspaceId);
1127
1134
  }
1128
1135
  // Single-flight refresh: POST /auth/refresh with the app-supplied refresh
1129
1136
  // token, store the new access token, notify the app, return it for the retry.
@@ -1169,6 +1176,8 @@ var FonderieClient = class {
1169
1176
  this.billing.setWorkspaceId(workspaceId);
1170
1177
  this.workspaces.setWorkspaceId(workspaceId);
1171
1178
  this.customers.setWorkspaceId(workspaceId);
1179
+ this.audit.setWorkspaceId(workspaceId);
1180
+ this.webhooks.setWorkspaceId(workspaceId);
1172
1181
  }
1173
1182
  // ── Generic transport ──────────────────────────────────────────────────────
1174
1183
  // A Fonderie-aware HTTP client for endpoints outside the typed modules (an
@@ -1380,6 +1389,11 @@ var CourierAdminClient = class {
1380
1389
  });
1381
1390
  }
1382
1391
  };
1392
+
1393
+ // src/types.ts
1394
+ function isMfaRequired(result) {
1395
+ return !("tokens" in result);
1396
+ }
1383
1397
  export {
1384
1398
  AuditClient,
1385
1399
  AuthClient,
@@ -1391,6 +1405,7 @@ export {
1391
1405
  FonderieClient,
1392
1406
  WebhooksClient,
1393
1407
  WorkspacesClient,
1394
- createMemoryCache
1408
+ createMemoryCache,
1409
+ isMfaRequired
1395
1410
  };
1396
1411
  //# sourceMappingURL=index.js.map