@umbraco-cms/backoffice 14.0.0--preview005-b4989b95 → 14.0.0--preview005-d06b80f2

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.
@@ -9,11 +9,12 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _UmbAuthContext_instances, _UmbAuthContext_isAuthorized, _UmbAuthContext_isBypassed, _UmbAuthContext_backofficePath, _UmbAuthContext_authFlow, _UmbAuthContext_getRedirectUrl;
12
+ var _UmbAuthContext_instances, _UmbAuthContext_isAuthorized, _UmbAuthContext_isBypassed, _UmbAuthContext_serverUrl, _UmbAuthContext_backofficePath, _UmbAuthContext_authFlow, _UmbAuthContext_openApi, _UmbAuthContext_getRedirectUrl;
13
13
  import { UmbAuthFlow } from './auth-flow.js';
14
14
  import { UMB_AUTH_CONTEXT } from './auth.context.token.js';
15
15
  import { UmbBaseController } from '../../libs/class-api/index.js';
16
16
  import { UmbBooleanState } from '../../libs/observable-api/index.js';
17
+ import { OpenAPI } from '../../external/backend-api/index.js';
17
18
  export class UmbAuthContext extends UmbBaseController {
18
19
  constructor(host, serverUrl, backofficePath, isBypassed) {
19
20
  super(host);
@@ -21,9 +22,12 @@ export class UmbAuthContext extends UmbBaseController {
21
22
  _UmbAuthContext_isAuthorized.set(this, new UmbBooleanState(false));
22
23
  this.isAuthorized = __classPrivateFieldGet(this, _UmbAuthContext_isAuthorized, "f").asObservable();
23
24
  _UmbAuthContext_isBypassed.set(this, false);
25
+ _UmbAuthContext_serverUrl.set(this, void 0);
24
26
  _UmbAuthContext_backofficePath.set(this, void 0);
25
27
  _UmbAuthContext_authFlow.set(this, void 0);
28
+ _UmbAuthContext_openApi.set(this, OpenAPI);
26
29
  __classPrivateFieldSet(this, _UmbAuthContext_isBypassed, isBypassed, "f");
30
+ __classPrivateFieldSet(this, _UmbAuthContext_serverUrl, serverUrl, "f");
27
31
  __classPrivateFieldSet(this, _UmbAuthContext_backofficePath, backofficePath, "f");
28
32
  __classPrivateFieldSet(this, _UmbAuthContext_authFlow, new UmbAuthFlow(serverUrl, __classPrivateFieldGet(this, _UmbAuthContext_instances, "m", _UmbAuthContext_getRedirectUrl).call(this)), "f");
29
33
  this.provideContext(UMB_AUTH_CONTEXT, this);
@@ -68,7 +72,7 @@ export class UmbAuthContext extends UmbBaseController {
68
72
  *
69
73
  * NB! The user may experience being redirected to the login screen if the token is expired.
70
74
  *
71
- * @example
75
+ * @example <caption>Using the latest token</caption>
72
76
  * ```js
73
77
  * const token = await authContext.getLatestToken();
74
78
  * const result = await fetch('https://my-api.com', { headers: { Authorization: `Bearer ${token}` } });
@@ -94,7 +98,50 @@ export class UmbAuthContext extends UmbBaseController {
94
98
  signOut() {
95
99
  return __classPrivateFieldGet(this, _UmbAuthContext_authFlow, "f").signOut();
96
100
  }
101
+ /**
102
+ * Get the server url to the Management API.
103
+ * @memberof UmbAuthContext
104
+ * @example <caption>Using the server url</caption>
105
+ * ```js
106
+ * const serverUrl = authContext.getServerUrl();
107
+ * OpenAPI.BASE = serverUrl;
108
+ * ```
109
+ * @example <caption></caption>
110
+ * ```js
111
+ * const serverUrl = authContext.getServerUrl();
112
+ * const token = await authContext.getLatestToken();
113
+ * const result = await fetch(`${serverUrl}/umbraco/management/api/v1/my-resource`, { headers: { Authorization: `Bearer ${token}` } });
114
+ * ```
115
+ * @returns The server url to the Management API
116
+ */
117
+ getServerUrl() {
118
+ return __classPrivateFieldGet(this, _UmbAuthContext_serverUrl, "f");
119
+ }
120
+ /**
121
+ * Get the default OpenAPI configuration, which is set up to communicate with the Management API.
122
+ * @remark This is useful if you want to communicate with your own resources generated by the [openapi-typescript-codegen](https://github.com/ferdikoomen/openapi-typescript-codegen) library.
123
+ * @memberof UmbAuthContext
124
+ *
125
+ * @example <caption>Using the default OpenAPI configuration</caption>
126
+ * ```js
127
+ * const defaultOpenApi = authContext.getOpenApiConfiguration();
128
+ * OpenAPI.BASE = defaultOpenApi.base;
129
+ * OpenAPI.WITH_CREDENTIALS = defaultOpenApi.withCredentials;
130
+ * OpenAPI.CREDENTIALS = defaultOpenApi.credentials;
131
+ * OpenAPI.TOKEN = defaultOpenApi.token;
132
+ * ```
133
+ * @returns The default OpenAPI configuration
134
+ */
135
+ getOpenApiConfiguration() {
136
+ return {
137
+ base: OpenAPI.BASE,
138
+ version: OpenAPI.VERSION,
139
+ withCredentials: OpenAPI.WITH_CREDENTIALS,
140
+ credentials: OpenAPI.CREDENTIALS,
141
+ token: () => this.getLatestToken(),
142
+ };
143
+ }
97
144
  }
98
- _UmbAuthContext_isAuthorized = new WeakMap(), _UmbAuthContext_isBypassed = new WeakMap(), _UmbAuthContext_backofficePath = new WeakMap(), _UmbAuthContext_authFlow = new WeakMap(), _UmbAuthContext_instances = new WeakSet(), _UmbAuthContext_getRedirectUrl = function _UmbAuthContext_getRedirectUrl() {
145
+ _UmbAuthContext_isAuthorized = new WeakMap(), _UmbAuthContext_isBypassed = new WeakMap(), _UmbAuthContext_serverUrl = new WeakMap(), _UmbAuthContext_backofficePath = new WeakMap(), _UmbAuthContext_authFlow = new WeakMap(), _UmbAuthContext_openApi = new WeakMap(), _UmbAuthContext_instances = new WeakSet(), _UmbAuthContext_getRedirectUrl = function _UmbAuthContext_getRedirectUrl() {
99
146
  return `${window.location.origin}${__classPrivateFieldGet(this, _UmbAuthContext_backofficePath, "f")}`;
100
147
  };
@@ -1,2 +1,3 @@
1
1
  export * from './auth.context.js';
2
2
  export * from './auth.context.token.js';
3
+ export * from './models/openApiConfiguration.js';
@@ -1,2 +1,3 @@
1
1
  export * from './auth.context.js';
2
2
  export * from './auth.context.token.js';
3
+ export * from './models/openApiConfiguration.js';
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Configuration for the OpenAPI (Umbraco) server. This is used to communicate with the Management API.
3
+ * This is useful if you want to configure your Fetch, Axios or other HTTP client to communicate with the Management API.
4
+ * If you use the recommended resource generator [openapi-typescript-codegen](https://github.com/ferdikoomen/openapi-typescript-codegen) this can be used to configure the `OpenAPI` object.
5
+ */
6
+ export interface UmbOpenApiConfiguration {
7
+ /**
8
+ * The base URL of the OpenAPI (Umbraco) server.
9
+ */
10
+ readonly base: string;
11
+ /**
12
+ * The configured version of the Management API to use.
13
+ */
14
+ readonly version: string;
15
+ /**
16
+ * The `withCredentials` option for the Fetch API.
17
+ */
18
+ readonly withCredentials: boolean;
19
+ /**
20
+ * The `credentials` option for the Fetch API.
21
+ */
22
+ readonly credentials: 'include' | 'omit' | 'same-origin';
23
+ /**
24
+ * The token to use for the Authorization header.
25
+ * @returns A resolver for the token to use for the Authorization header.
26
+ */
27
+ readonly token: () => Promise<string>;
28
+ }