@functionalcms/svelte-components 3.4.0 → 3.5.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/auth/getMachineAccessToken.d.ts +1 -0
- package/dist/auth/getMachineAccessToken.js +22 -0
- package/dist/auth/types.d.ts +12 -1
- package/dist/server-side/getServices.d.ts +6 -6
- package/dist/server-side/getServices.js +12 -12
- package/dist/server-side/types.d.ts +5 -0
- package/dist/server-side/types.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getMachineAccessToken: (scope?: string) => Promise<string>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AUTH_KEYCLOAK_ID, AUTH_KEYCLOAK_SECRET, AUTH_KEYCLOAK_ISSUER } from '$env/static/private';
|
|
2
|
+
export const getMachineAccessToken = async (scope = '') => {
|
|
3
|
+
const response = await fetch(`${AUTH_KEYCLOAK_ISSUER}/protocol/openid-connect/token`, {
|
|
4
|
+
method: "POST",
|
|
5
|
+
body: new URLSearchParams({
|
|
6
|
+
grant_type: "client_credentials",
|
|
7
|
+
client_id: AUTH_KEYCLOAK_ID,
|
|
8
|
+
client_secret: AUTH_KEYCLOAK_SECRET,
|
|
9
|
+
scope,
|
|
10
|
+
}),
|
|
11
|
+
headers: {
|
|
12
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
13
|
+
Accept: "application/json"
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
if (!response.ok) {
|
|
17
|
+
console.log('Response was NOT okay');
|
|
18
|
+
throw new Error('Token not validated.');
|
|
19
|
+
}
|
|
20
|
+
const token = await response.json();
|
|
21
|
+
return token.access_token;
|
|
22
|
+
};
|
package/dist/auth/types.d.ts
CHANGED
|
@@ -8,8 +8,19 @@ export declare class Token {
|
|
|
8
8
|
session_state?: string;
|
|
9
9
|
token_type?: string;
|
|
10
10
|
}
|
|
11
|
+
export interface Session {
|
|
12
|
+
client_id: string;
|
|
13
|
+
email_verified: string;
|
|
14
|
+
preferred_username: string;
|
|
15
|
+
sub: string;
|
|
16
|
+
userId: string;
|
|
17
|
+
}
|
|
18
|
+
export interface Locals {
|
|
19
|
+
session: Session;
|
|
20
|
+
auth_token: string;
|
|
21
|
+
}
|
|
11
22
|
export type ISession = {
|
|
12
|
-
session:
|
|
23
|
+
session: Session;
|
|
13
24
|
token: Token;
|
|
14
25
|
};
|
|
15
26
|
export type SessionInfoCache = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CommunicationService, DataService, TemplateService, WebsitesService, BlobService, AiService } from "@functionalcms/services";
|
|
2
|
-
export declare const getDataService: (locals: any) => DataService;
|
|
3
|
-
export declare const getCommunicationService: (locals: any) => CommunicationService;
|
|
4
|
-
export declare const getWebsiteService: (locals: any) => WebsitesService;
|
|
5
|
-
export declare const getTemplateService: (locals: any) => TemplateService;
|
|
6
|
-
export declare const getBlobService: (locals: any) => BlobService;
|
|
7
|
-
export declare const getAIService: (locals: any) => AiService;
|
|
2
|
+
export declare const getDataService: (locals: any, getToken?: (locals: any) => string) => DataService;
|
|
3
|
+
export declare const getCommunicationService: (locals: any, getToken?: (locals: any) => string) => CommunicationService;
|
|
4
|
+
export declare const getWebsiteService: (locals: any, getToken?: (locals: any) => string) => WebsitesService;
|
|
5
|
+
export declare const getTemplateService: (locals: any, getToken?: (locals: any) => string) => TemplateService;
|
|
6
|
+
export declare const getBlobService: (locals: any, getToken?: (locals: any) => string) => BlobService;
|
|
7
|
+
export declare const getAIService: (locals: any, getToken?: (locals: any) => string) => AiService;
|
|
@@ -3,33 +3,33 @@ import { CommunicationService, DataService, TemplateService, WebsitesService, Bl
|
|
|
3
3
|
const getAccessToken = (locals) => {
|
|
4
4
|
return locals.token.access_token;
|
|
5
5
|
};
|
|
6
|
-
export const getDataService = (locals) => {
|
|
7
|
-
const accessToken =
|
|
6
|
+
export const getDataService = (locals, getToken = getAccessToken) => {
|
|
7
|
+
const accessToken = getToken(locals);
|
|
8
8
|
const service = new DataService(accessToken, DOMAIN, ENDPOINT);
|
|
9
9
|
return service;
|
|
10
10
|
};
|
|
11
|
-
export const getCommunicationService = (locals) => {
|
|
12
|
-
const accessToken =
|
|
11
|
+
export const getCommunicationService = (locals, getToken = getAccessToken) => {
|
|
12
|
+
const accessToken = getToken(locals);
|
|
13
13
|
const service = new CommunicationService(accessToken, DOMAIN, ENDPOINT);
|
|
14
14
|
return service;
|
|
15
15
|
};
|
|
16
|
-
export const getWebsiteService = (locals) => {
|
|
17
|
-
const accessToken =
|
|
16
|
+
export const getWebsiteService = (locals, getToken = getAccessToken) => {
|
|
17
|
+
const accessToken = getToken(locals);
|
|
18
18
|
const service = new WebsitesService(accessToken, DOMAIN, ENDPOINT);
|
|
19
19
|
return service;
|
|
20
20
|
};
|
|
21
|
-
export const getTemplateService = (locals) => {
|
|
22
|
-
const accessToken =
|
|
21
|
+
export const getTemplateService = (locals, getToken = getAccessToken) => {
|
|
22
|
+
const accessToken = getToken(locals);
|
|
23
23
|
const service = new TemplateService(accessToken, DOMAIN, ENDPOINT);
|
|
24
24
|
return service;
|
|
25
25
|
};
|
|
26
|
-
export const getBlobService = (locals) => {
|
|
27
|
-
const accessToken =
|
|
26
|
+
export const getBlobService = (locals, getToken = getAccessToken) => {
|
|
27
|
+
const accessToken = getToken(locals);
|
|
28
28
|
const service = new BlobService(accessToken, DOMAIN, ENDPOINT);
|
|
29
29
|
return service;
|
|
30
30
|
};
|
|
31
|
-
export const getAIService = (locals) => {
|
|
32
|
-
const accessToken =
|
|
31
|
+
export const getAIService = (locals, getToken = getAccessToken) => {
|
|
32
|
+
const accessToken = getToken(locals);
|
|
33
33
|
const service = new AiService(accessToken, DOMAIN, ENDPOINT);
|
|
34
34
|
return service;
|
|
35
35
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|