@jskit-ai/connectors-web 0.2.5 → 0.2.7
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/connectors-web",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "Shared Vue fields for portable application integration configuration.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
"./locales/en.json": "./locales/en.json"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@jskit-ai/connectors-core": "0.2.
|
|
15
|
+
"@jskit-ai/connectors-core": "0.2.7"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"@jskit-ai/kernel": "0.2.
|
|
18
|
+
"@jskit-ai/kernel": "0.2.6",
|
|
19
19
|
"vue": "^3.5.13",
|
|
20
20
|
"vuetify": "^4.0.0"
|
|
21
21
|
},
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { computed, ref } from "vue";
|
|
3
|
-
import {
|
|
3
|
+
import { getProviderAccountModes, getProviderAuthenticationMethods, getProviderScopes, providerGrantTypes } from "@jskit-ai/connectors-core/shared/configuration";
|
|
4
4
|
import { useJskitText } from "./i18n.js";
|
|
5
|
+
import { environmentPrefix, useIntegrationConfiguration } from "./useIntegrationConfiguration.js";
|
|
5
6
|
|
|
6
7
|
const props = defineProps({
|
|
7
8
|
modelValue: { type: Object, required: true },
|
|
@@ -15,16 +16,25 @@ const props = defineProps({
|
|
|
15
16
|
});
|
|
16
17
|
const emit = defineEmits(["update:modelValue"]);
|
|
17
18
|
// Provider texts may be message keys (the JSKIT catalog) or plain text (other catalogs); text() renders both.
|
|
18
|
-
// The catalog's public definitions are English; each keeps its keyed original under MESSAGE_KEY_SOURCE.
|
|
19
19
|
const jskitText = useJskitText();
|
|
20
20
|
const { t, text, formatDate, fieldErrorMessages } = jskitText;
|
|
21
|
-
const definition = computed(() => props.provider[MESSAGE_KEY_SOURCE] || props.provider);
|
|
22
21
|
const errors = computed(() => fieldErrorMessages({ fieldErrors: props.fieldErrors, fieldErrorCodes: props.fieldErrorCodes }));
|
|
23
22
|
const panels = ref(["details", "credentials"]);
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
const {
|
|
24
|
+
definition,
|
|
25
|
+
integration,
|
|
26
|
+
registrationId,
|
|
27
|
+
registration,
|
|
28
|
+
grantType,
|
|
29
|
+
settingProperties,
|
|
30
|
+
editAssistantPolicy,
|
|
31
|
+
editIntegration,
|
|
32
|
+
editSetting,
|
|
33
|
+
editAuthentication,
|
|
34
|
+
editSecretReference,
|
|
35
|
+
editRegistration,
|
|
36
|
+
editGrantType
|
|
37
|
+
} = useIntegrationConfiguration({ props, emit });
|
|
28
38
|
const grantTitles = { authorization_code: "jskit.connectors.configurationFields.grantTypes.authorizationCode", client_credentials: "jskit.connectors.configurationFields.grantTypes.clientCredentials" };
|
|
29
39
|
const grantOptions = computed(() => providerGrantTypes(definition.value).map((value) => ({
|
|
30
40
|
value, title: grantTitles[value] ? t(grantTitles[value]) : value
|
|
@@ -39,7 +49,6 @@ const modes = computed(() => getProviderAccountModes(definition.value, integrati
|
|
|
39
49
|
const registrationOptions = computed(() => Object.keys(props.modelValue.registrations));
|
|
40
50
|
const integrationPath = computed(() => `integrations.${props.integrationId}`);
|
|
41
51
|
const registrationPath = computed(() => `registrations.${registrationId.value}`);
|
|
42
|
-
const settingProperties = computed(() => getProviderSettingsSchema(definition.value, integration.value?.settings)?.getFieldDefinitions() || {});
|
|
43
52
|
const methodTitles = { "api-key": "jskit.connectors.configurationFields.authenticationMethods.apiKey", "service-account": "jskit.connectors.configurationFields.authenticationMethods.serviceAccount",
|
|
44
53
|
oauth2: "jskit.connectors.configurationFields.authenticationMethods.oauth2", none: "jskit.connectors.configurationFields.authenticationMethods.none" };
|
|
45
54
|
const authenticationOptions = computed(() => getProviderAuthenticationMethods(definition.value, integration.value.settings).map((value) => ({
|
|
@@ -63,22 +72,12 @@ const credentialReference = computed(() => integration.value?.authentication.met
|
|
|
63
72
|
: { label: text(definition.value.apiKeyReferenceLabel) || t("jskit.connectors.configurationFields.apiKeyReference.label"),
|
|
64
73
|
hint: text(definition.value.apiKeyReferenceHint) || t("jskit.connectors.configurationFields.apiKeyReference.hint") });
|
|
65
74
|
|
|
66
|
-
// The environment-variable prefix editAuthentication uses for a new registration's references.
|
|
67
|
-
function environmentPrefix(id) {
|
|
68
|
-
return id.toUpperCase().replaceAll("-", "_");
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// A service account cannot connect as each app user; fall back to a mode these settings allow.
|
|
72
|
-
function accountModeForGrant(grant, settings, accountMode) {
|
|
73
|
-
return grant === "client_credentials" && accountMode === "per-user"
|
|
74
|
-
? getProviderAccountModes(definition.value, settings || {}).find((mode) => mode !== "per-user") : accountMode;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
75
|
function settingValue(field) {
|
|
78
76
|
return integration.value.settings?.[field.name] ?? settingProperties.value[field.name]?.defaultTo;
|
|
79
77
|
}
|
|
80
78
|
|
|
81
79
|
// A hint function receives formatDate so dates it shows follow the app's language (none: its own English).
|
|
80
|
+
// readable-check: allow method-probe - input validation: a field's hint is text, or a function of the settings
|
|
82
81
|
function settingHint(field) {
|
|
83
82
|
return text(typeof field.hint === "function" ? field.hint(integration.value.settings, jskitText.locale ? { formatDate } : {}) : field.hint);
|
|
84
83
|
}
|
|
@@ -95,117 +94,6 @@ function settingErrors(field) {
|
|
|
95
94
|
return errors.value[`${integrationPath.value}.settings.${field.name}`];
|
|
96
95
|
}
|
|
97
96
|
|
|
98
|
-
function editAssistantPolicy(changes) {
|
|
99
|
-
editIntegration({ assistantPolicy: { enabled: true, defaultPermission: "ask", actions: {}, ...integration.value.assistantPolicy, ...changes } });
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function editIntegration(changes) {
|
|
103
|
-
const next = { ...integration.value, ...changes };
|
|
104
|
-
for (const key of Object.keys(changes)) if (changes[key] === undefined) delete next[key];
|
|
105
|
-
const registrations = { ...props.modelValue.registrations };
|
|
106
|
-
const previousRegistration = registrationId.value;
|
|
107
|
-
if (changes.authentication && next.authentication.method !== "oauth2" && previousRegistration &&
|
|
108
|
-
registrations[previousRegistration]?.source === "own" && registrations[previousRegistration]?.clientId === "" &&
|
|
109
|
-
!Object.entries(props.modelValue.integrations).some(([id, value]) =>
|
|
110
|
-
id !== props.integrationId && value.authentication.registrationRef === previousRegistration)) {
|
|
111
|
-
delete registrations[previousRegistration];
|
|
112
|
-
}
|
|
113
|
-
emit("update:modelValue", {
|
|
114
|
-
...props.modelValue,
|
|
115
|
-
registrations,
|
|
116
|
-
integrations: { ...props.modelValue.integrations, [props.integrationId]: next }
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function editSetting(field, value) {
|
|
121
|
-
const settings = { ...integration.value.settings };
|
|
122
|
-
if (value === undefined || value === "") delete settings[field];
|
|
123
|
-
else settings[field] = value;
|
|
124
|
-
if (typeof definition.value.settingsSchema === "function") {
|
|
125
|
-
const fields = getProviderSettingsSchema(definition.value, settings).getFieldDefinitions();
|
|
126
|
-
for (const key of Object.keys(settings)) if (!Object.hasOwn(fields, key)) delete settings[key];
|
|
127
|
-
}
|
|
128
|
-
const available = getProviderScopes(definition.value, settings, grantType.value, integration.value.authentication.method);
|
|
129
|
-
const scopes = integration.value.scopes.filter((value) => available.some((scope) => scope.value === value));
|
|
130
|
-
for (const scope of available) if (scope.required && !scopes.includes(scope.value)) scopes.push(scope.value);
|
|
131
|
-
const methods = getProviderAuthenticationMethods(definition.value, settings);
|
|
132
|
-
const credentialScope = definition.value.settingsFields?.find((item) => item.name === field)?.credentialScope;
|
|
133
|
-
const changedProvider = credentialScope && credentialScope(value) !== credentialScope(integration.value.settings?.[field] ?? settingProperties.value[field]?.defaultTo);
|
|
134
|
-
const authentication = changedProvider || !methods.includes(integration.value.authentication.method)
|
|
135
|
-
? { method: methods[0] } : integration.value.authentication;
|
|
136
|
-
const accountModes = getProviderAccountModes(definition.value, settings);
|
|
137
|
-
const accountMode = accountModes.includes(integration.value.accountMode) ? integration.value.accountMode : accountModes[0];
|
|
138
|
-
if (authentication.method === "oauth2" && !authentication.registrationRef) {
|
|
139
|
-
editAuthentication("oauth2", { ...integration.value, settings, scopes, authentication, accountMode });
|
|
140
|
-
} else editIntegration({ settings, scopes, authentication, accountMode });
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function editAuthentication(method, current = integration.value) {
|
|
144
|
-
const settings = { ...current.settings };
|
|
145
|
-
for (const field of definition.value.settingsFields || []) {
|
|
146
|
-
if (field.authenticationMethods && !field.authenticationMethods.includes(method)) delete settings[field.name];
|
|
147
|
-
}
|
|
148
|
-
const grant = method === "oauth2" ? definition.value.oauthGrantTypes?.[0] || DEFAULT_GRANT_TYPE : DEFAULT_GRANT_TYPE;
|
|
149
|
-
const availableScopes = getProviderScopes(definition.value, settings, grant, method);
|
|
150
|
-
const scopes = availableScopes.filter(scope => current.scopes.includes(scope.value) || scope.required || (scope.authenticationMethods && scope.recommended)).map(scope => scope.value);
|
|
151
|
-
if (method === "oauth2") {
|
|
152
|
-
let id = props.integrationId;
|
|
153
|
-
let suffix = 2;
|
|
154
|
-
while (Object.hasOwn(props.modelValue.registrations, id)) id = `${props.integrationId}-${suffix++}`;
|
|
155
|
-
const prefix = environmentPrefix(id);
|
|
156
|
-
const clientAuthentication = getProviderClientAuthenticationMethods(definition.value, grant, settings)[0];
|
|
157
|
-
emit("update:modelValue", {
|
|
158
|
-
...props.modelValue,
|
|
159
|
-
integrations: { ...props.modelValue.integrations, [props.integrationId]: {
|
|
160
|
-
...current, scopes, authentication: { method, registrationRef: id },
|
|
161
|
-
accountMode: accountModeForGrant(grant, settings, current.accountMode),
|
|
162
|
-
...(current.settings ? { settings } : {})
|
|
163
|
-
} },
|
|
164
|
-
registrations: { ...props.modelValue.registrations, [id]: {
|
|
165
|
-
source: "own", clientId: "",
|
|
166
|
-
...(grant === "authorization_code" ? { callbackUrlRef: `env:${prefix}_CALLBACK_URL` } : { grantType: grant }),
|
|
167
|
-
...(clientAuthentication !== DEFAULT_TOKEN_ENDPOINT_AUTH_METHOD ? { tokenEndpointAuthMethod: clientAuthentication } : {}),
|
|
168
|
-
...(clientAuthentication !== "none" ? { clientSecretRef: `env:${prefix}_CLIENT_SECRET` } : {})
|
|
169
|
-
} }
|
|
170
|
-
});
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
editIntegration({ scopes, authentication: { method }, ...(current.settings ? { settings } : {}) });
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function editSecretReference(value) {
|
|
177
|
-
const authentication = { ...integration.value.authentication, secretRef: value };
|
|
178
|
-
if (!value && definition.value.apiKeySecretOptional) delete authentication.secretRef;
|
|
179
|
-
editIntegration({ authentication });
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function editRegistration(field, value) {
|
|
183
|
-
emit("update:modelValue", {
|
|
184
|
-
...props.modelValue,
|
|
185
|
-
registrations: {
|
|
186
|
-
...props.modelValue.registrations,
|
|
187
|
-
[registrationId.value]: { ...registration.value, [field]: value }
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function editGrantType(value) {
|
|
193
|
-
const nextRegistration = { ...registration.value, grantType: value };
|
|
194
|
-
const methods = getProviderClientAuthenticationMethods(definition.value, value, integration.value.settings || {});
|
|
195
|
-
if (!methods.includes(registrationClientAuthentication(nextRegistration))) nextRegistration.tokenEndpointAuthMethod = methods[0];
|
|
196
|
-
if (nextRegistration.tokenEndpointAuthMethod === "none") delete nextRegistration.clientSecretRef;
|
|
197
|
-
if (value === "client_credentials") delete nextRegistration.callbackUrlRef;
|
|
198
|
-
const allowed = getProviderScopes(definition.value, integration.value.settings || {}, value, integration.value.authentication.method).map((scope) => scope.value);
|
|
199
|
-
emit("update:modelValue", {
|
|
200
|
-
...props.modelValue,
|
|
201
|
-
registrations: { ...props.modelValue.registrations, [registrationId.value]: nextRegistration },
|
|
202
|
-
integrations: { ...props.modelValue.integrations, [props.integrationId]: {
|
|
203
|
-
...integration.value,
|
|
204
|
-
accountMode: accountModeForGrant(value, integration.value.settings, integration.value.accountMode),
|
|
205
|
-
scopes: integration.value.scopes.filter((scope) => allowed.includes(scope))
|
|
206
|
-
} }
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
97
|
</script>
|
|
210
98
|
|
|
211
99
|
<template>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// The values connectors-web's client hands out and receives across files.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The configuration the fields edit: integrations and registrations by id.
|
|
5
|
+
* @typedef {object} IntegrationConfiguration
|
|
6
|
+
* @property {Record<string, Record<string, any>>} integrations
|
|
7
|
+
* @property {Record<string, Record<string, any>>} registrations
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* What `useIntegrationConfiguration()` reads from the fields component's props.
|
|
12
|
+
* @typedef {object} IntegrationConfigurationProps
|
|
13
|
+
* @property {IntegrationConfiguration} modelValue
|
|
14
|
+
* @property {string} integrationId
|
|
15
|
+
* @property {Record<string, any>} provider The provider's public definition.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** @typedef {ReturnType<typeof import("./useIntegrationConfiguration.js").useIntegrationConfiguration>} IntegrationConfigurationEditor */
|
|
19
|
+
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { computed } from "vue";
|
|
2
|
+
import { DEFAULT_GRANT_TYPE, DEFAULT_TOKEN_ENDPOINT_AUTH_METHOD, MESSAGE_KEY_SOURCE, getProviderAccountModes, getProviderAuthenticationMethods, getProviderClientAuthenticationMethods, getProviderScopes, getProviderSettingsSchema, registrationClientAuthentication, registrationGrantType } from "@jskit-ai/connectors-core/shared/configuration";
|
|
3
|
+
|
|
4
|
+
// The environment-variable prefix editAuthentication uses for a new registration's references.
|
|
5
|
+
function environmentPrefix(id) {
|
|
6
|
+
return id.toUpperCase().replaceAll("-", "_");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// readable-check: allow method-probe - input validation: a provider's settingsSchema is a schema, or a function of the settings
|
|
10
|
+
function hasSettingsFunction(provider) {
|
|
11
|
+
return typeof provider.settingsSchema === "function";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The integration a component edits: what it reads from the configuration, and each change it emits.
|
|
16
|
+
* @param {object} options
|
|
17
|
+
* @param {import("./types.js").IntegrationConfigurationProps} options.props
|
|
18
|
+
* @param {(event: "update:modelValue", configuration: import("./types.js").IntegrationConfiguration) => void} options.emit
|
|
19
|
+
*/
|
|
20
|
+
function useIntegrationConfiguration({ props, emit }) {
|
|
21
|
+
// The catalog's public definitions are English; each keeps its keyed original under MESSAGE_KEY_SOURCE.
|
|
22
|
+
const definition = computed(() => props.provider[MESSAGE_KEY_SOURCE] || props.provider);
|
|
23
|
+
const integration = computed(() => props.modelValue.integrations[props.integrationId]);
|
|
24
|
+
const registrationId = computed(() => integration.value?.authentication.registrationRef);
|
|
25
|
+
const registration = computed(() => props.modelValue.registrations[registrationId.value]);
|
|
26
|
+
const grantType = computed(() => registrationGrantType(registration.value));
|
|
27
|
+
const settingProperties = computed(() => getProviderSettingsSchema(definition.value, integration.value?.settings)?.getFieldDefinitions() || {});
|
|
28
|
+
|
|
29
|
+
// A service account cannot connect as each app user; fall back to a mode these settings allow.
|
|
30
|
+
function accountModeForGrant(grant, settings, accountMode) {
|
|
31
|
+
return grant === "client_credentials" && accountMode === "per-user"
|
|
32
|
+
? getProviderAccountModes(definition.value, settings || {}).find((mode) => mode !== "per-user") : accountMode;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function editAssistantPolicy(changes) {
|
|
36
|
+
editIntegration({ assistantPolicy: { enabled: true, defaultPermission: "ask", actions: {}, ...integration.value.assistantPolicy, ...changes } });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function editIntegration(changes) {
|
|
40
|
+
const next = { ...integration.value, ...changes };
|
|
41
|
+
for (const key of Object.keys(changes)) if (changes[key] === undefined) delete next[key];
|
|
42
|
+
const registrations = { ...props.modelValue.registrations };
|
|
43
|
+
const previousRegistration = registrationId.value;
|
|
44
|
+
if (changes.authentication && next.authentication.method !== "oauth2" && previousRegistration &&
|
|
45
|
+
registrations[previousRegistration]?.source === "own" && registrations[previousRegistration]?.clientId === "" &&
|
|
46
|
+
!Object.entries(props.modelValue.integrations).some(([id, value]) =>
|
|
47
|
+
id !== props.integrationId && value.authentication.registrationRef === previousRegistration)) {
|
|
48
|
+
delete registrations[previousRegistration];
|
|
49
|
+
}
|
|
50
|
+
emit("update:modelValue", {
|
|
51
|
+
...props.modelValue,
|
|
52
|
+
registrations,
|
|
53
|
+
integrations: { ...props.modelValue.integrations, [props.integrationId]: next }
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function editSetting(field, value) {
|
|
58
|
+
const settings = { ...integration.value.settings };
|
|
59
|
+
if (value === undefined || value === "") delete settings[field];
|
|
60
|
+
else settings[field] = value;
|
|
61
|
+
if (hasSettingsFunction(definition.value)) {
|
|
62
|
+
const fields = getProviderSettingsSchema(definition.value, settings).getFieldDefinitions();
|
|
63
|
+
for (const key of Object.keys(settings)) if (!Object.hasOwn(fields, key)) delete settings[key];
|
|
64
|
+
}
|
|
65
|
+
const available = getProviderScopes(definition.value, settings, grantType.value, integration.value.authentication.method);
|
|
66
|
+
const scopes = integration.value.scopes.filter((value) => available.some((scope) => scope.value === value));
|
|
67
|
+
for (const scope of available) if (scope.required && !scopes.includes(scope.value)) scopes.push(scope.value);
|
|
68
|
+
const methods = getProviderAuthenticationMethods(definition.value, settings);
|
|
69
|
+
const credentialScope = definition.value.settingsFields?.find((item) => item.name === field)?.credentialScope;
|
|
70
|
+
const changedProvider = credentialScope && credentialScope(value) !== credentialScope(integration.value.settings?.[field] ?? settingProperties.value[field]?.defaultTo);
|
|
71
|
+
const authentication = changedProvider || !methods.includes(integration.value.authentication.method)
|
|
72
|
+
? { method: methods[0] } : integration.value.authentication;
|
|
73
|
+
const accountModes = getProviderAccountModes(definition.value, settings);
|
|
74
|
+
const accountMode = accountModes.includes(integration.value.accountMode) ? integration.value.accountMode : accountModes[0];
|
|
75
|
+
if (authentication.method === "oauth2" && !authentication.registrationRef) {
|
|
76
|
+
editAuthentication("oauth2", { ...integration.value, settings, scopes, authentication, accountMode });
|
|
77
|
+
} else editIntegration({ settings, scopes, authentication, accountMode });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function editAuthentication(method, current = integration.value) {
|
|
81
|
+
const settings = { ...current.settings };
|
|
82
|
+
for (const field of definition.value.settingsFields || []) {
|
|
83
|
+
if (field.authenticationMethods && !field.authenticationMethods.includes(method)) delete settings[field.name];
|
|
84
|
+
}
|
|
85
|
+
const grant = method === "oauth2" ? definition.value.oauthGrantTypes?.[0] || DEFAULT_GRANT_TYPE : DEFAULT_GRANT_TYPE;
|
|
86
|
+
const availableScopes = getProviderScopes(definition.value, settings, grant, method);
|
|
87
|
+
const scopes = availableScopes.filter(scope => current.scopes.includes(scope.value) || scope.required || (scope.authenticationMethods && scope.recommended)).map(scope => scope.value);
|
|
88
|
+
if (method === "oauth2") {
|
|
89
|
+
let id = props.integrationId;
|
|
90
|
+
let suffix = 2;
|
|
91
|
+
while (Object.hasOwn(props.modelValue.registrations, id)) id = `${props.integrationId}-${suffix++}`;
|
|
92
|
+
const prefix = environmentPrefix(id);
|
|
93
|
+
const clientAuthentication = getProviderClientAuthenticationMethods(definition.value, grant, settings)[0];
|
|
94
|
+
emit("update:modelValue", {
|
|
95
|
+
...props.modelValue,
|
|
96
|
+
integrations: { ...props.modelValue.integrations, [props.integrationId]: {
|
|
97
|
+
...current, scopes, authentication: { method, registrationRef: id },
|
|
98
|
+
accountMode: accountModeForGrant(grant, settings, current.accountMode),
|
|
99
|
+
...(current.settings ? { settings } : {})
|
|
100
|
+
} },
|
|
101
|
+
registrations: { ...props.modelValue.registrations, [id]: {
|
|
102
|
+
source: "own", clientId: "",
|
|
103
|
+
...(grant === "authorization_code" ? { callbackUrlRef: `env:${prefix}_CALLBACK_URL` } : { grantType: grant }),
|
|
104
|
+
...(clientAuthentication !== DEFAULT_TOKEN_ENDPOINT_AUTH_METHOD ? { tokenEndpointAuthMethod: clientAuthentication } : {}),
|
|
105
|
+
...(clientAuthentication !== "none" ? { clientSecretRef: `env:${prefix}_CLIENT_SECRET` } : {})
|
|
106
|
+
} }
|
|
107
|
+
});
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
editIntegration({ scopes, authentication: { method }, ...(current.settings ? { settings } : {}) });
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function editSecretReference(value) {
|
|
114
|
+
const authentication = { ...integration.value.authentication, secretRef: value };
|
|
115
|
+
if (!value && definition.value.apiKeySecretOptional) delete authentication.secretRef;
|
|
116
|
+
editIntegration({ authentication });
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function editRegistration(field, value) {
|
|
120
|
+
emit("update:modelValue", {
|
|
121
|
+
...props.modelValue,
|
|
122
|
+
registrations: {
|
|
123
|
+
...props.modelValue.registrations,
|
|
124
|
+
[registrationId.value]: { ...registration.value, [field]: value }
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function editGrantType(value) {
|
|
130
|
+
const nextRegistration = { ...registration.value, grantType: value };
|
|
131
|
+
const methods = getProviderClientAuthenticationMethods(definition.value, value, integration.value.settings || {});
|
|
132
|
+
if (!methods.includes(registrationClientAuthentication(nextRegistration))) nextRegistration.tokenEndpointAuthMethod = methods[0];
|
|
133
|
+
if (nextRegistration.tokenEndpointAuthMethod === "none") delete nextRegistration.clientSecretRef;
|
|
134
|
+
if (value === "client_credentials") delete nextRegistration.callbackUrlRef;
|
|
135
|
+
const allowed = getProviderScopes(definition.value, integration.value.settings || {}, value, integration.value.authentication.method).map((scope) => scope.value);
|
|
136
|
+
emit("update:modelValue", {
|
|
137
|
+
...props.modelValue,
|
|
138
|
+
registrations: { ...props.modelValue.registrations, [registrationId.value]: nextRegistration },
|
|
139
|
+
integrations: { ...props.modelValue.integrations, [props.integrationId]: {
|
|
140
|
+
...integration.value,
|
|
141
|
+
accountMode: accountModeForGrant(value, integration.value.settings, integration.value.accountMode),
|
|
142
|
+
scopes: integration.value.scopes.filter((scope) => allowed.includes(scope))
|
|
143
|
+
} }
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
definition,
|
|
149
|
+
integration,
|
|
150
|
+
registrationId,
|
|
151
|
+
registration,
|
|
152
|
+
grantType,
|
|
153
|
+
settingProperties,
|
|
154
|
+
editAssistantPolicy,
|
|
155
|
+
editIntegration,
|
|
156
|
+
editSetting,
|
|
157
|
+
editAuthentication,
|
|
158
|
+
editSecretReference,
|
|
159
|
+
editRegistration,
|
|
160
|
+
editGrantType
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export { environmentPrefix, useIntegrationConfiguration };
|