@prefecthq/prefect-ui-library 3.5.9 → 3.5.10

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.
@@ -1,4 +1,5 @@
1
1
  import { AxiosInstance, AxiosRequestConfig, AxiosResponse, RawAxiosRequestHeaders } from 'axios';
2
+ import { MaybeGetter } from '../types';
2
3
  import { MaybeArray } from '../types/utilities';
3
4
  export type AxiosInstanceSetupHook = (instance: AxiosInstance) => void;
4
5
  export type PrefectConfig = {
@@ -12,12 +13,13 @@ export declare const getPrefectBaseUrl: ApiBaseUrl;
12
13
  export declare const getPrefectUIHeaders: RawAxiosRequestHeaders;
13
14
  export declare const getAuthorizationHeaders: ApiHeaders;
14
15
  export declare class Api<T extends PrefectConfig = PrefectConfig> {
15
- protected readonly apiConfig: T;
16
+ protected readonly apiConfig: MaybeGetter<T>;
16
17
  protected apiHeaders: MaybeArray<ApiHeaders>;
17
18
  protected apiBaseUrl: ApiBaseUrl;
18
19
  protected routePrefix: string | undefined;
19
20
  protected instanceSetupHook: AxiosInstanceSetupHook | null;
20
- constructor(apiConfig: T, instanceSetupHook?: AxiosInstanceSetupHook | null);
21
+ constructor(apiConfig: MaybeGetter<T>, instanceSetupHook?: AxiosInstanceSetupHook | null);
22
+ protected getConfig(): T;
21
23
  protected composeBaseUrl(): string;
22
24
  protected composeHeaders(): RawAxiosRequestHeaders;
23
25
  protected combinePath(route: string | undefined): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prefecthq/prefect-ui-library",
3
- "version": "3.5.9",
3
+ "version": "3.5.10",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,5 +1,6 @@
1
1
  import { asArray } from '@prefecthq/prefect-design'
2
2
  import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, RawAxiosRequestHeaders } from 'axios'
3
+ import { MaybeGetter } from '@/types'
3
4
  import { MaybeArray } from '@/types/utilities'
4
5
  import { isDefined } from '@/utilities/variables'
5
6
 
@@ -29,30 +30,38 @@ export const getAuthorizationHeaders: ApiHeaders = (config) => {
29
30
  }
30
31
 
31
32
  export class Api<T extends PrefectConfig = PrefectConfig> {
32
- protected readonly apiConfig: T
33
+ protected readonly apiConfig: MaybeGetter<T>
33
34
  protected apiHeaders: MaybeArray<ApiHeaders> = [getPrefectUIHeaders, getAuthorizationHeaders]
34
35
  protected apiBaseUrl: ApiBaseUrl = getPrefectBaseUrl
35
36
  protected routePrefix: string | undefined
36
37
  protected instanceSetupHook: AxiosInstanceSetupHook | null
37
38
 
38
- public constructor(apiConfig: T, instanceSetupHook: AxiosInstanceSetupHook | null = null) {
39
+ public constructor(apiConfig: MaybeGetter<T>, instanceSetupHook: AxiosInstanceSetupHook | null = null) {
39
40
  this.apiConfig = apiConfig
40
41
  this.instanceSetupHook = instanceSetupHook
41
42
  }
42
43
 
44
+ protected getConfig(): T {
45
+ if (typeof this.apiConfig === 'function') {
46
+ return this.apiConfig()
47
+ }
48
+
49
+ return this.apiConfig
50
+ }
51
+
43
52
  protected composeBaseUrl(): string {
44
53
  if (typeof this.apiBaseUrl === 'string') {
45
54
  return this.apiBaseUrl
46
55
  }
47
56
 
48
- return this.apiBaseUrl(this.apiConfig)
57
+ return this.apiBaseUrl(this.getConfig())
49
58
  }
50
59
 
51
60
  protected composeHeaders(): RawAxiosRequestHeaders {
52
61
  const array = asArray(this.apiHeaders)
53
62
 
54
63
  return array.reduce<RawAxiosRequestHeaders>((headers, header) => {
55
- const value = typeof header === 'function' ? header(this.apiConfig) : header
64
+ const value = typeof header === 'function' ? header(this.getConfig()) : header
56
65
 
57
66
  return {
58
67
  ...headers,