@xh/hoist 64.0.1 → 64.0.4

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +23 -1
  2. package/appcontainer/AppContainerModel.ts +2 -2
  3. package/build/types/core/HoistComponent.d.ts +4 -8
  4. package/build/types/core/HoistProps.d.ts +3 -1
  5. package/build/types/core/elem.d.ts +1 -3
  6. package/build/types/core/types/Types.d.ts +1 -0
  7. package/build/types/desktop/cmp/appOption/AutoRefreshAppOption.d.ts +1 -0
  8. package/build/types/desktop/cmp/appOption/ThemeAppOption.d.ts +1 -0
  9. package/build/types/icon/Icon.d.ts +7 -4
  10. package/build/types/security/BaseOAuthClient.d.ts +63 -46
  11. package/build/types/security/{TokenInfo.d.ts → Token.d.ts} +5 -4
  12. package/build/types/security/authzero/AuthZeroClient.d.ts +12 -7
  13. package/build/types/security/authzero/index.d.ts +1 -0
  14. package/build/types/security/msal/MsalClient.d.ts +63 -10
  15. package/build/types/security/msal/index.d.ts +1 -0
  16. package/build/types/svc/FetchService.d.ts +5 -5
  17. package/build/types/utils/react/LayoutPropUtils.d.ts +4 -4
  18. package/core/HoistComponent.ts +4 -8
  19. package/core/HoistProps.ts +4 -1
  20. package/core/elem.ts +0 -4
  21. package/core/types/Types.ts +1 -0
  22. package/desktop/cmp/input/ButtonGroupInput.ts +4 -3
  23. package/icon/Icon.ts +7 -4
  24. package/kit/blueprint/styles.scss +31 -18
  25. package/mobile/appcontainer/ToastSource.ts +2 -1
  26. package/package.json +1 -1
  27. package/security/BaseOAuthClient.ts +148 -165
  28. package/security/{TokenInfo.ts → Token.ts} +12 -9
  29. package/security/authzero/AuthZeroClient.ts +92 -80
  30. package/security/authzero/index.ts +7 -0
  31. package/security/msal/MsalClient.ts +204 -94
  32. package/security/msal/index.ts +7 -0
  33. package/svc/FetchService.ts +14 -11
  34. package/svc/IdentityService.ts +1 -1
  35. package/svc/LocalStorageService.ts +1 -1
  36. package/tsconfig.tsbuildinfo +1 -1
  37. package/utils/react/LayoutPropUtils.ts +4 -4
@@ -46,7 +46,7 @@ export class FetchService extends HoistService {
46
46
  NO_JSON_RESPONSES = [StatusCodes.NO_CONTENT, StatusCodes.RESET_CONTENT];
47
47
 
48
48
  private autoAborters = {};
49
- defaultHeaders: (PlainObject | ((arg: FetchOptions) => PlainObject))[] = [];
49
+ defaultHeaders: (PlainObject | ((arg: FetchOptions) => Awaitable<PlainObject>))[] = [];
50
50
  defaultTimeout = (30 * SECONDS) as any;
51
51
 
52
52
  /**
@@ -54,7 +54,7 @@ export class FetchService extends HoistService {
54
54
  * @param headers - to be sent with all fetch requests, or a function to generate.
55
55
  * @deprecated use addDefaultHeaders instead.
56
56
  */
57
- setDefaultHeaders(headers: PlainObject | ((arg: FetchOptions) => PlainObject)) {
57
+ setDefaultHeaders(headers: PlainObject | ((arg: FetchOptions) => Awaitable<PlainObject>)) {
58
58
  apiDeprecated('setDefaultHeaders', {v: '66', msg: 'Use addDefaultHeaders instead'});
59
59
  this.addDefaultHeaders(headers);
60
60
  }
@@ -63,7 +63,7 @@ export class FetchService extends HoistService {
63
63
  * Add default headers to be sent with all subsequent requests.
64
64
  * @param headers - to be sent with all fetch requests, or a function to generate.
65
65
  */
66
- addDefaultHeaders(headers: PlainObject | ((arg: FetchOptions) => PlainObject)) {
66
+ addDefaultHeaders(headers: PlainObject | ((arg: FetchOptions) => Awaitable<PlainObject>)) {
67
67
  this.defaultHeaders.push(headers);
68
68
  }
69
69
 
@@ -79,8 +79,8 @@ export class FetchService extends HoistService {
79
79
  * Send a request via the underlying fetch API.
80
80
  * @returns Promise which resolves to a Fetch Response.
81
81
  */
82
- fetch(opts: FetchOptions): Promise<FetchResponse> {
83
- opts = this.withDefaults(opts);
82
+ async fetch(opts: FetchOptions): Promise<FetchResponse> {
83
+ opts = await this.withDefaultsAsync(opts);
84
84
  return this.managedFetchAsync(opts);
85
85
  }
86
86
 
@@ -88,8 +88,8 @@ export class FetchService extends HoistService {
88
88
  * Send an HTTP request and decode the response as JSON.
89
89
  * @returns the decoded JSON object, or null if the response has status in {@link NO_JSON_RESPONSES}.
90
90
  */
91
- fetchJson(opts: FetchOptions): Promise<any> {
92
- opts = this.withDefaults(opts, {Accept: 'application/json'});
91
+ async fetchJson(opts: FetchOptions): Promise<any> {
92
+ opts = await this.withDefaultsAsync(opts, {Accept: 'application/json'});
93
93
  return this.managedFetchAsync(opts, async r => {
94
94
  if (this.NO_JSON_RESPONSES.includes(r.status)) return null;
95
95
 
@@ -157,14 +157,17 @@ export class FetchService extends HoistService {
157
157
  //-----------------------
158
158
  // Implementation
159
159
  //-----------------------
160
- private withDefaults(opts: FetchOptions, extraHeaders: PlainObject = null): FetchOptions {
160
+ private async withDefaultsAsync(
161
+ opts: FetchOptions,
162
+ extraHeaders: PlainObject = null
163
+ ): Promise<FetchOptions> {
161
164
  const method = opts.method ?? (opts.params ? 'POST' : 'GET'),
162
165
  isPost = method === 'POST';
163
166
 
164
167
  const defaultHeaders = {};
165
- this.defaultHeaders.forEach(h => {
166
- Object.assign(defaultHeaders, isFunction(h) ? h(opts) : h);
167
- });
168
+ for (const h of this.defaultHeaders) {
169
+ Object.assign(defaultHeaders, isFunction(h) ? await h(opts) : h);
170
+ }
168
171
 
169
172
  return {
170
173
  ...opts,
@@ -59,7 +59,7 @@ export class IdentityService extends HoistService {
59
59
  */
60
60
  async logoutAsync() {
61
61
  await XH.fetchJson({url: 'xh/logout'});
62
- await XH.appModel.logoutAsync();
62
+ await XH.appModel?.logoutAsync(); // can be called by LockoutPanel prior to appModel init
63
63
  XH.reloadApp();
64
64
  }
65
65
 
@@ -82,6 +82,6 @@ export class LocalStorageService extends HoistService {
82
82
  }
83
83
 
84
84
  private getNamespace() {
85
- return `${XH.appCode}.${XH.getUsername() ?? 'ANON'}`;
85
+ return `${XH.appCode}.${XH.getUsername()}`;
86
86
  }
87
87
  }