@microsoft/agents-hosting 0.1.49 → 0.2.7-gd7a3e9ef95
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/src/activityWireCompat.d.ts +19 -0
- package/dist/src/activityWireCompat.js +49 -0
- package/dist/src/activityWireCompat.js.map +1 -0
- package/dist/src/agent-client/agentClient.d.ts +8 -2
- package/dist/src/agent-client/agentClient.js +7 -10
- package/dist/src/agent-client/agentClient.js.map +1 -1
- package/dist/src/agent-client/{expressApi.d.ts → agentResponseHandler.d.ts} +2 -1
- package/dist/src/agent-client/{expressApi.js → agentResponseHandler.js} +16 -12
- package/dist/src/agent-client/agentResponseHandler.js.map +1 -0
- package/dist/src/agent-client/index.d.ts +1 -1
- package/dist/src/agent-client/index.js +1 -1
- package/dist/src/agent-client/index.js.map +1 -1
- package/dist/src/app/agentApplication.d.ts +9 -8
- package/dist/src/app/agentApplication.js +17 -8
- package/dist/src/app/agentApplication.js.map +1 -1
- package/dist/src/app/{applicationBuilder.d.ts → agentApplicationBuilder.d.ts} +6 -6
- package/dist/src/app/{applicationBuilder.js → agentApplicationBuilder.js} +4 -4
- package/dist/src/app/agentApplicationBuilder.js.map +1 -0
- package/dist/src/app/{applicationOptions.d.ts → agentApplicationOptions.d.ts} +3 -3
- package/dist/src/app/{applicationOptions.js → agentApplicationOptions.js} +1 -1
- package/dist/src/app/agentApplicationOptions.js.map +1 -0
- package/dist/src/app/index.d.ts +4 -3
- package/dist/src/app/index.js +4 -3
- package/dist/src/app/index.js.map +1 -1
- package/dist/src/app/oauth/userIdentity.d.ts +43 -0
- package/dist/src/app/oauth/userIdentity.js +54 -0
- package/dist/src/app/oauth/userIdentity.js.map +1 -0
- package/dist/src/app/turnState.d.ts +1 -1
- package/dist/src/app/turnState.js +2 -2
- package/dist/src/app/turnState.js.map +1 -1
- package/dist/src/app/turnStateProperty.d.ts +40 -0
- package/dist/src/app/turnStateProperty.js +57 -0
- package/dist/src/app/turnStateProperty.js.map +1 -0
- package/dist/src/auth/authConfiguration.d.ts +21 -2
- package/dist/src/auth/authConfiguration.js +23 -4
- package/dist/src/auth/authConfiguration.js.map +1 -1
- package/dist/src/auth/jwt-middleware.js +2 -1
- package/dist/src/auth/jwt-middleware.js.map +1 -1
- package/dist/src/auth/msalTokenProvider.js +1 -1
- package/dist/src/auth/msalTokenProvider.js.map +1 -1
- package/dist/src/cards/cardFactory.d.ts +8 -0
- package/dist/src/cards/cardFactory.js +22 -1
- package/dist/src/cards/cardFactory.js.map +1 -1
- package/dist/src/cloudAdapter.d.ts +1 -2
- package/dist/src/cloudAdapter.js +7 -2
- package/dist/src/cloudAdapter.js.map +1 -1
- package/dist/src/connector-client/connectorClient.d.ts +3 -2
- package/dist/src/connector-client/connectorClient.js +15 -3
- package/dist/src/connector-client/connectorClient.js.map +1 -1
- package/dist/src/connector-client/index.d.ts +0 -1
- package/dist/src/connector-client/index.js +0 -1
- package/dist/src/connector-client/index.js.map +1 -1
- package/dist/src/getProductInfo.d.ts +1 -0
- package/dist/src/getProductInfo.js +11 -0
- package/dist/src/getProductInfo.js.map +1 -0
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/oauth/index.d.ts +3 -4
- package/dist/src/oauth/index.js +3 -4
- package/dist/src/oauth/index.js.map +1 -1
- package/dist/src/oauth/{oauthCard.d.ts → oAuthCard.d.ts} +1 -2
- package/dist/src/oauth/{oauthCard.js → oAuthCard.js} +1 -1
- package/dist/src/oauth/oAuthCard.js.map +1 -0
- package/dist/src/oauth/oAuthFlow.d.ts +47 -0
- package/dist/src/oauth/oAuthFlow.js +158 -0
- package/dist/src/oauth/oAuthFlow.js.map +1 -0
- package/dist/src/oauth/signingResource.d.ts +27 -3
- package/dist/src/oauth/tokenResponse.d.ts +29 -0
- package/dist/src/oauth/tokenResponse.js +25 -0
- package/dist/src/oauth/tokenResponse.js.map +1 -0
- package/dist/src/oauth/userTokenClient.d.ts +4 -3
- package/dist/src/oauth/userTokenClient.js +23 -13
- package/dist/src/oauth/userTokenClient.js.map +1 -1
- package/dist/src/state/agentState.d.ts +8 -3
- package/dist/src/state/agentState.js +17 -6
- package/dist/src/state/agentState.js.map +1 -1
- package/dist/src/state/agentStatePropertyAccesor.d.ts +58 -5
- package/dist/src/state/agentStatePropertyAccesor.js +6 -6
- package/dist/src/state/agentStatePropertyAccesor.js.map +1 -1
- package/package.json +3 -6
- package/src/activityWireCompat.ts +45 -0
- package/src/agent-client/agentClient.ts +21 -13
- package/src/agent-client/{expressApi.ts → agentResponseHandler.ts} +20 -12
- package/src/agent-client/index.ts +1 -1
- package/src/app/agentApplication.ts +24 -15
- package/src/app/{applicationBuilder.ts → agentApplicationBuilder.ts} +5 -5
- package/src/app/{applicationOptions.ts → agentApplicationOptions.ts} +3 -3
- package/src/app/index.ts +4 -3
- package/src/app/oauth/userIdentity.ts +78 -0
- package/src/app/turnState.ts +2 -2
- package/src/app/turnStateProperty.ts +72 -0
- package/src/auth/authConfiguration.ts +23 -4
- package/src/auth/jwt-middleware.ts +2 -1
- package/src/auth/msalTokenProvider.ts +1 -1
- package/src/cards/cardFactory.ts +26 -2
- package/src/cloudAdapter.ts +8 -4
- package/src/connector-client/connectorClient.ts +15 -5
- package/src/connector-client/index.ts +0 -1
- package/src/getProductInfo.ts +3 -0
- package/src/index.ts +2 -2
- package/src/oauth/index.ts +3 -4
- package/src/oauth/{oauthCard.ts → oAuthCard.ts} +1 -3
- package/src/oauth/oAuthFlow.ts +175 -0
- package/src/oauth/signingResource.ts +28 -3
- package/src/oauth/tokenResponse.ts +43 -0
- package/src/oauth/userTokenClient.ts +26 -16
- package/src/state/agentState.ts +25 -6
- package/src/state/agentStatePropertyAccesor.ts +65 -8
- package/dist/src/agent-client/expressApi.js.map +0 -1
- package/dist/src/app/applicationBuilder.js.map +0 -1
- package/dist/src/app/applicationOptions.js.map +0 -1
- package/dist/src/app/oauth/authenticationOptions.d.ts +0 -7
- package/dist/src/app/oauth/authenticationOptions.js +0 -7
- package/dist/src/app/oauth/authenticationOptions.js.map +0 -1
- package/dist/src/app/oauth/webChatOAuthFlowAppStyle.d.ts +0 -11
- package/dist/src/app/oauth/webChatOAuthFlowAppStyle.js +0 -85
- package/dist/src/app/oauth/webChatOAuthFlowAppStyle.js.map +0 -1
- package/dist/src/connector-client/conversationParameters.d.ts +0 -38
- package/dist/src/connector-client/conversationParameters.js +0 -7
- package/dist/src/connector-client/conversationParameters.js.map +0 -1
- package/dist/src/oauth/oauthCard.js.map +0 -1
- package/dist/src/oauth/tokenExchangeResource.d.ts +0 -17
- package/dist/src/oauth/tokenExchangeResource.js +0 -5
- package/dist/src/oauth/tokenExchangeResource.js.map +0 -1
- package/dist/src/oauth/tokenPostResource.d.ts +0 -9
- package/dist/src/oauth/tokenPostResource.js +0 -5
- package/dist/src/oauth/tokenPostResource.js.map +0 -1
- package/dist/src/oauth/webChatOAuthFlow.d.ts +0 -41
- package/dist/src/oauth/webChatOAuthFlow.js +0 -117
- package/dist/src/oauth/webChatOAuthFlow.js.map +0 -1
- package/src/app/oauth/authenticationOptions.ts +0 -8
- package/src/app/oauth/webChatOAuthFlowAppStyle.ts +0 -90
- package/src/connector-client/conversationParameters.ts +0 -40
- package/src/oauth/tokenExchangeResource.ts +0 -20
- package/src/oauth/tokenPostResource.ts +0 -12
- package/src/oauth/webChatOAuthFlow.ts +0 -123
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
// Licensed under the MIT License.
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.WebChatOAuthFlowAppStyle = void 0;
|
|
6
|
-
const userTokenClient_1 = require("../../oauth/userTokenClient");
|
|
7
|
-
const cardFactory_1 = require("../../cards/cardFactory");
|
|
8
|
-
const messageFactory_1 = require("../../messageFactory");
|
|
9
|
-
const logger_1 = require("../../logger");
|
|
10
|
-
const logger = (0, logger_1.debug)('agents:web-chat-oauth-flow');
|
|
11
|
-
class WebChatOAuthFlowAppStyle {
|
|
12
|
-
constructor(storage) {
|
|
13
|
-
this.storage = storage;
|
|
14
|
-
}
|
|
15
|
-
async getOAuthToken(context, state) {
|
|
16
|
-
var _a, _b, _c;
|
|
17
|
-
if (Object.keys(state.sso).length === 0) {
|
|
18
|
-
state.sso.flowStarted = false;
|
|
19
|
-
state.sso.userToken = '';
|
|
20
|
-
state.sso.flowExpires = 0;
|
|
21
|
-
await state.save(context);
|
|
22
|
-
}
|
|
23
|
-
if (state.sso.userToken !== '') {
|
|
24
|
-
return state.sso.userToken;
|
|
25
|
-
}
|
|
26
|
-
if (((_a = state.sso) === null || _a === void 0 ? void 0 : _a.flowExpires) !== 0 && Date.now() > state.sso.flowExpires) {
|
|
27
|
-
logger.warn('Sign-in flow expired');
|
|
28
|
-
state.sso.flowStarted = false;
|
|
29
|
-
state.sso.userToken = '';
|
|
30
|
-
await context.sendActivity(messageFactory_1.MessageFactory.text('Sign-in session expired. Please try again.'));
|
|
31
|
-
}
|
|
32
|
-
let retVal = '';
|
|
33
|
-
const authConfig = context.adapter.authConfig;
|
|
34
|
-
if (authConfig.connectionName === undefined) {
|
|
35
|
-
throw new Error('connectionName is not set in the auth config, review your environment variables');
|
|
36
|
-
}
|
|
37
|
-
const adapter = context.adapter;
|
|
38
|
-
const scope = 'https://api.botframework.com';
|
|
39
|
-
const accessToken = await adapter.authProvider.getAccessToken(authConfig, scope);
|
|
40
|
-
this.userTokenClient = new userTokenClient_1.UserTokenClient(accessToken);
|
|
41
|
-
if (state.sso.flowStarted === true) {
|
|
42
|
-
const userToken = await this.userTokenClient.getUserToken(authConfig.connectionName, context.activity.channelId, (_b = context.activity.from) === null || _b === void 0 ? void 0 : _b.id);
|
|
43
|
-
if (userToken !== null) {
|
|
44
|
-
logger.info('Token obtained');
|
|
45
|
-
state.sso.userToken = userToken.token;
|
|
46
|
-
state.sso.flowStarted = false;
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
const code = context.activity.text;
|
|
50
|
-
const userToken = await this.userTokenClient.getUserToken(authConfig.connectionName, context.activity.channelId, (_c = context.activity.from) === null || _c === void 0 ? void 0 : _c.id, code);
|
|
51
|
-
if (userToken !== null) {
|
|
52
|
-
logger.info('Token obtained with code');
|
|
53
|
-
state.sso.userToken = userToken.token;
|
|
54
|
-
state.sso.flowStarted = false;
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
logger.error('Sign in failed');
|
|
58
|
-
await context.sendActivity(messageFactory_1.MessageFactory.text('Sign in failed'));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
retVal = state.sso.userToken;
|
|
62
|
-
}
|
|
63
|
-
else if (state.sso.flowStarted === false) {
|
|
64
|
-
const signingResource = await this.userTokenClient.getSignInResource(authConfig.clientId, authConfig.connectionName, context.activity);
|
|
65
|
-
const oCard = cardFactory_1.CardFactory.oauthCard(authConfig.connectionName, 'Sign in', '', signingResource);
|
|
66
|
-
await context.sendActivity(messageFactory_1.MessageFactory.attachment(oCard));
|
|
67
|
-
state.sso.flowStarted = true;
|
|
68
|
-
state.sso.flowExpires = Date.now() + 30000;
|
|
69
|
-
logger.info('OAuth flow started');
|
|
70
|
-
}
|
|
71
|
-
state.save(context);
|
|
72
|
-
return retVal;
|
|
73
|
-
}
|
|
74
|
-
async signOut(context, state) {
|
|
75
|
-
var _a;
|
|
76
|
-
await this.userTokenClient.signOut((_a = context.activity.from) === null || _a === void 0 ? void 0 : _a.id, context.adapter.authConfig.connectionName, context.activity.channelId);
|
|
77
|
-
state.sso.flowStarted = false;
|
|
78
|
-
state.sso.userToken = '';
|
|
79
|
-
state.sso.flowExpires = 0;
|
|
80
|
-
state.save(context);
|
|
81
|
-
logger.info('User signed out successfully');
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
exports.WebChatOAuthFlowAppStyle = WebChatOAuthFlowAppStyle;
|
|
85
|
-
//# sourceMappingURL=webChatOAuthFlowAppStyle.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"webChatOAuthFlowAppStyle.js","sourceRoot":"","sources":["../../../../src/app/oauth/webChatOAuthFlowAppStyle.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;AAGlC,iEAA6D;AAE7D,yDAAqD;AAErD,yDAAqD;AACrD,yCAAoC;AAIpC,MAAM,MAAM,GAAG,IAAA,cAAK,EAAC,4BAA4B,CAAC,CAAA;AAElD,MAAa,wBAAwB;IAInC,YAAa,OAAgB;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAEM,KAAK,CAAC,aAAa,CAAE,OAAoB,EAAE,KAAgB;;QAChE,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxC,KAAK,CAAC,GAAG,CAAC,WAAW,GAAG,KAAK,CAAA;YAC7B,KAAK,CAAC,GAAG,CAAC,SAAS,GAAG,EAAE,CAAA;YACxB,KAAK,CAAC,GAAG,CAAC,WAAW,GAAG,CAAC,CAAA;YACzB,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAC3B,CAAC;QACD,IAAI,KAAK,CAAC,GAAI,CAAC,SAAS,KAAK,EAAE,EAAE,CAAC;YAChC,OAAO,KAAK,CAAC,GAAG,CAAC,SAAS,CAAA;QAC5B,CAAC;QACD,IAAI,CAAA,MAAA,KAAK,CAAC,GAAG,0CAAE,WAAW,MAAK,CAAC,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;YACvE,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAA;YACnC,KAAK,CAAC,GAAG,CAAC,WAAW,GAAG,KAAK,CAAA;YAC7B,KAAK,CAAC,GAAG,CAAC,SAAS,GAAG,EAAE,CAAA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AC,OAAO,CAAC,CAAA;QACnB,OAAO,MAAM,CAAA;IACf,CAAC;IAED,KAAK,CAAC,OAAO,CAAE,OAAoB,EAAE,KAAgB;;QACnD,MAAM,IAAI,CAAC,eAAgB,CAAC,OAAO,CAAC,MAAA,OAAO,CAAC,QAAQ,CAAC,IAAI,0CAAE,EAAG,EAAE,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,cAAe,EAAE,OAAO,CAAC,QAAQ,CAAC,SAAU,CAAC,CAAA;QACxI,KAAK,CAAC,GAAI,CAAC,WAAW,GAAG,KAAK,CAAA;QAC9B,KAAK,CAAC,GAAI,CAAC,SAAS,GAAG,EAAE,CAAA;QACzB,KAAK,CAAC,GAAI,CAAC,WAAW,GAAG,CAAC,CAAA;QAC1B,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACnB,MAAM,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAA;IAC7C,CAAC;CACF;AA1ED,4DA0EC"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright(c) Microsoft Corporation.All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { Activity, ChannelAccount } from '@microsoft/agents-activity';
|
|
6
|
-
/**
|
|
7
|
-
* Represents the parameters for creating a conversation.
|
|
8
|
-
*/
|
|
9
|
-
export interface ConversationParameters {
|
|
10
|
-
/**
|
|
11
|
-
* Indicates whether the conversation is a group conversation.
|
|
12
|
-
*/
|
|
13
|
-
isGroup: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* The bot account initiating the conversation.
|
|
16
|
-
*/
|
|
17
|
-
bot: ChannelAccount;
|
|
18
|
-
/**
|
|
19
|
-
* The members to include in the conversation.
|
|
20
|
-
*/
|
|
21
|
-
members?: ChannelAccount[];
|
|
22
|
-
/**
|
|
23
|
-
* The topic name of the conversation.
|
|
24
|
-
*/
|
|
25
|
-
topicName?: string;
|
|
26
|
-
/**
|
|
27
|
-
* The tenant ID of the conversation.
|
|
28
|
-
*/
|
|
29
|
-
tenantId?: string;
|
|
30
|
-
/**
|
|
31
|
-
* The initial activity to send to the conversation.
|
|
32
|
-
*/
|
|
33
|
-
activity: Activity;
|
|
34
|
-
/**
|
|
35
|
-
* Channel-specific data for the conversation.
|
|
36
|
-
*/
|
|
37
|
-
channelData: unknown;
|
|
38
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"conversationParameters.js","sourceRoot":"","sources":["../../../src/connector-client/conversationParameters.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"oauthCard.js","sourceRoot":"","sources":["../../../src/oauth/oauthCard.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents a resource for exchanging tokens.
|
|
3
|
-
*/
|
|
4
|
-
export interface TokenExchangeResource {
|
|
5
|
-
/**
|
|
6
|
-
* The ID of the token exchange resource.
|
|
7
|
-
*/
|
|
8
|
-
id?: string;
|
|
9
|
-
/**
|
|
10
|
-
* The URI of the token exchange resource.
|
|
11
|
-
*/
|
|
12
|
-
uri?: string;
|
|
13
|
-
/**
|
|
14
|
-
* The provider ID for the token exchange resource.
|
|
15
|
-
*/
|
|
16
|
-
providerId?: string;
|
|
17
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tokenExchangeResource.js","sourceRoot":"","sources":["../../../src/oauth/tokenExchangeResource.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tokenPostResource.js","sourceRoot":"","sources":["../../../src/oauth/tokenPostResource.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { UserTokenClient } from './userTokenClient';
|
|
2
|
-
import { AgentStatePropertyAccessor } from '../state/agentStatePropertyAccesor';
|
|
3
|
-
import { UserState } from '../state/userState';
|
|
4
|
-
import { TurnContext } from '../turnContext';
|
|
5
|
-
declare class FlowState {
|
|
6
|
-
flowStarted: boolean;
|
|
7
|
-
userToken: string;
|
|
8
|
-
flowExpires: number;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Manages the OAuth flow for Web Chat.
|
|
12
|
-
*/
|
|
13
|
-
export declare class WebChatOAuthFlow {
|
|
14
|
-
userTokenClient?: UserTokenClient;
|
|
15
|
-
state: FlowState | null;
|
|
16
|
-
flowStateAccessor: AgentStatePropertyAccessor<FlowState | null>;
|
|
17
|
-
/**
|
|
18
|
-
* Creates a new instance of WebChatOAuthFlow.
|
|
19
|
-
* @param userState The user state.
|
|
20
|
-
*/
|
|
21
|
-
constructor(userState: UserState);
|
|
22
|
-
/**
|
|
23
|
-
* Gets the OAuth token.
|
|
24
|
-
* @param context The turn context.
|
|
25
|
-
* @returns A promise that resolves to the user token.
|
|
26
|
-
*/
|
|
27
|
-
getOAuthToken(context: TurnContext): Promise<string>;
|
|
28
|
-
/**
|
|
29
|
-
* Signs the user out.
|
|
30
|
-
* @param context The turn context.
|
|
31
|
-
* @returns A promise that resolves when the sign-out operation is complete.
|
|
32
|
-
*/
|
|
33
|
-
signOut(context: TurnContext): Promise<void>;
|
|
34
|
-
/**
|
|
35
|
-
* Gets the user state.
|
|
36
|
-
* @param context The turn context.
|
|
37
|
-
* @returns A promise that resolves to the user state.
|
|
38
|
-
*/
|
|
39
|
-
private getUserState;
|
|
40
|
-
}
|
|
41
|
-
export {};
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
// Licensed under the MIT License.
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.WebChatOAuthFlow = void 0;
|
|
6
|
-
const userTokenClient_1 = require("./userTokenClient");
|
|
7
|
-
const cardFactory_1 = require("../cards/cardFactory");
|
|
8
|
-
const messageFactory_1 = require("../messageFactory");
|
|
9
|
-
const logger_1 = require("../logger");
|
|
10
|
-
const logger = (0, logger_1.debug)('agents:web-chat-oauth-flow');
|
|
11
|
-
class FlowState {
|
|
12
|
-
constructor() {
|
|
13
|
-
this.flowStarted = false;
|
|
14
|
-
this.userToken = '';
|
|
15
|
-
this.flowExpires = 0;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Manages the OAuth flow for Web Chat.
|
|
20
|
-
*/
|
|
21
|
-
class WebChatOAuthFlow {
|
|
22
|
-
/**
|
|
23
|
-
* Creates a new instance of WebChatOAuthFlow.
|
|
24
|
-
* @param userState The user state.
|
|
25
|
-
*/
|
|
26
|
-
constructor(userState) {
|
|
27
|
-
this.state = null;
|
|
28
|
-
this.flowStateAccessor = userState.createProperty('flowState');
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Gets the OAuth token.
|
|
32
|
-
* @param context The turn context.
|
|
33
|
-
* @returns A promise that resolves to the user token.
|
|
34
|
-
*/
|
|
35
|
-
async getOAuthToken(context) {
|
|
36
|
-
var _a, _b, _c;
|
|
37
|
-
this.state = await this.getUserState(context);
|
|
38
|
-
if (this.state.userToken !== '') {
|
|
39
|
-
return this.state.userToken;
|
|
40
|
-
}
|
|
41
|
-
if (((_a = this.state) === null || _a === void 0 ? void 0 : _a.flowExpires) !== 0 && Date.now() > this.state.flowExpires) {
|
|
42
|
-
logger.warn('Sign-in flow expired');
|
|
43
|
-
this.state.flowStarted = false;
|
|
44
|
-
this.state.userToken = '';
|
|
45
|
-
await context.sendActivity(messageFactory_1.MessageFactory.text('Sign-in session expired. Please try again.'));
|
|
46
|
-
}
|
|
47
|
-
let retVal = '';
|
|
48
|
-
const authConfig = context.adapter.authConfig;
|
|
49
|
-
if (authConfig.connectionName === undefined) {
|
|
50
|
-
throw new Error('connectionName is not set in the auth config, review your environment variables');
|
|
51
|
-
}
|
|
52
|
-
const adapter = context.adapter;
|
|
53
|
-
const scope = 'https://api.botframework.com';
|
|
54
|
-
const accessToken = await adapter.authProvider.getAccessToken(authConfig, scope);
|
|
55
|
-
this.userTokenClient = new userTokenClient_1.UserTokenClient(accessToken);
|
|
56
|
-
if (this.state.flowStarted === true) {
|
|
57
|
-
const userToken = await this.userTokenClient.getUserToken(authConfig.connectionName, context.activity.channelId, (_b = context.activity.from) === null || _b === void 0 ? void 0 : _b.id);
|
|
58
|
-
if (userToken !== null) {
|
|
59
|
-
logger.info('Token obtained');
|
|
60
|
-
this.state.userToken = userToken.token;
|
|
61
|
-
this.state.flowStarted = false;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
const code = context.activity.text;
|
|
65
|
-
const userToken = await this.userTokenClient.getUserToken(authConfig.connectionName, context.activity.channelId, (_c = context.activity.from) === null || _c === void 0 ? void 0 : _c.id, code);
|
|
66
|
-
if (userToken !== null) {
|
|
67
|
-
logger.info('Token obtained with code');
|
|
68
|
-
this.state.userToken = userToken.token;
|
|
69
|
-
this.state.flowStarted = false;
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
logger.error('Sign in failed');
|
|
73
|
-
await context.sendActivity(messageFactory_1.MessageFactory.text('Sign in failed'));
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
retVal = this.state.userToken;
|
|
77
|
-
}
|
|
78
|
-
else if (this.state.flowStarted === false) {
|
|
79
|
-
const signingResource = await this.userTokenClient.getSignInResource(authConfig.clientId, authConfig.connectionName, context.activity);
|
|
80
|
-
const oCard = cardFactory_1.CardFactory.oauthCard(authConfig.connectionName, 'Sign in', '', signingResource);
|
|
81
|
-
await context.sendActivity(messageFactory_1.MessageFactory.attachment(oCard));
|
|
82
|
-
this.state.flowStarted = true;
|
|
83
|
-
this.state.flowExpires = Date.now() + 30000;
|
|
84
|
-
logger.info('OAuth flow started');
|
|
85
|
-
}
|
|
86
|
-
this.flowStateAccessor.set(context, this.state);
|
|
87
|
-
return retVal;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Signs the user out.
|
|
91
|
-
* @param context The turn context.
|
|
92
|
-
* @returns A promise that resolves when the sign-out operation is complete.
|
|
93
|
-
*/
|
|
94
|
-
async signOut(context) {
|
|
95
|
-
var _a;
|
|
96
|
-
await this.userTokenClient.signOut((_a = context.activity.from) === null || _a === void 0 ? void 0 : _a.id, context.adapter.authConfig.connectionName, context.activity.channelId);
|
|
97
|
-
this.state.flowStarted = false;
|
|
98
|
-
this.state.userToken = '';
|
|
99
|
-
this.state.flowExpires = 0;
|
|
100
|
-
this.flowStateAccessor.set(context, this.state);
|
|
101
|
-
logger.info('User signed out successfully');
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Gets the user state.
|
|
105
|
-
* @param context The turn context.
|
|
106
|
-
* @returns A promise that resolves to the user state.
|
|
107
|
-
*/
|
|
108
|
-
async getUserState(context) {
|
|
109
|
-
let userProfile = await this.flowStateAccessor.get(context, null);
|
|
110
|
-
if (userProfile === null) {
|
|
111
|
-
userProfile = new FlowState();
|
|
112
|
-
}
|
|
113
|
-
return userProfile;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
exports.WebChatOAuthFlow = WebChatOAuthFlow;
|
|
117
|
-
//# sourceMappingURL=webChatOAuthFlow.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"webChatOAuthFlow.js","sourceRoot":"","sources":["../../../src/oauth/webChatOAuthFlow.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;AAGlC,uDAAmD;AAEnD,sDAAkD;AAIlD,sDAAkD;AAClD,sCAAiC;AAEjC,MAAM,MAAM,GAAG,IAAA,cAAK,EAAC,4BAA4B,CAAC,CAAA;AAElD,MAAM,SAAS;IAAf;QACS,gBAAW,GAAY,KAAK,CAAA;QAC5B,c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B,IAAI,CAAC,KAAM,CAAC,SAAS,GAAG,EAAE,CAAA;QAC1B,IAAI,CAAC,KAAM,CAAC,WAAW,GAAG,CAAC,CAAA;QAC3B,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;QAC/C,MAAM,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAA;IAC7C,CAAC;IAED;;;;OAIG;IACK,KAAK,CAAC,YAAY,CAAE,OAAoB;QAC9C,IAAI,WAAW,GAAqB,MAAM,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QACnF,IAAI,WAAW,KAAK,IAAI,EAAE,CAAC;YACzB,WAAW,GAAG,IAAI,SAAS,EAAE,CAAA;QAC/B,CAAC;QACD,OAAO,WAAW,CAAA;IACpB,CAAC;CACF;AAlGD,4CAkGC"}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
import { Attachment } from '@microsoft/agents-activity'
|
|
5
|
-
import { UserTokenClient } from '../../oauth/userTokenClient'
|
|
6
|
-
import { CloudAdapter } from '../../cloudAdapter'
|
|
7
|
-
import { CardFactory } from '../../cards/cardFactory'
|
|
8
|
-
import { TurnContext } from '../../turnContext'
|
|
9
|
-
import { MessageFactory } from '../../messageFactory'
|
|
10
|
-
import { debug } from '../../logger'
|
|
11
|
-
import { TurnState } from '../turnState'
|
|
12
|
-
import { Storage } from '../../storage'
|
|
13
|
-
|
|
14
|
-
const logger = debug('agents:web-chat-oauth-flow')
|
|
15
|
-
|
|
16
|
-
export class WebChatOAuthFlowAppStyle {
|
|
17
|
-
userTokenClient?: UserTokenClient
|
|
18
|
-
storage: Storage
|
|
19
|
-
|
|
20
|
-
constructor (storage: Storage) {
|
|
21
|
-
this.storage = storage
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public async getOAuthToken (context: TurnContext, state: TurnState) : Promise<string> {
|
|
25
|
-
if (Object.keys(state.sso).length === 0) {
|
|
26
|
-
state.sso.flowStarted = false
|
|
27
|
-
state.sso.userToken = ''
|
|
28
|
-
state.sso.flowExpires = 0
|
|
29
|
-
await state.save(context)
|
|
30
|
-
}
|
|
31
|
-
if (state.sso!.userToken !== '') {
|
|
32
|
-
return state.sso.userToken
|
|
33
|
-
}
|
|
34
|
-
if (state.sso?.flowExpires !== 0 && Date.now() > state.sso.flowExpires) {
|
|
35
|
-
logger.warn('Sign-in flow expired')
|
|
36
|
-
state.sso.flowStarted = false
|
|
37
|
-
state.sso.userToken = ''
|
|
38
|
-
await context.sendActivity(MessageFactory.text('Sign-in session expired. Please try again.'))
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
let retVal: string = ''
|
|
42
|
-
const authConfig = context.adapter.authConfig
|
|
43
|
-
if (authConfig.connectionName === undefined) {
|
|
44
|
-
throw new Error('connectionName is not set in the auth config, review your environment variables')
|
|
45
|
-
}
|
|
46
|
-
const adapter = context.adapter as CloudAdapter
|
|
47
|
-
const scope = 'https://api.botframework.com'
|
|
48
|
-
const accessToken = await adapter.authProvider.getAccessToken(authConfig, scope)
|
|
49
|
-
this.userTokenClient = new UserTokenClient(accessToken)
|
|
50
|
-
|
|
51
|
-
if (state.sso!.flowStarted === true) {
|
|
52
|
-
const userToken = await this.userTokenClient.getUserToken(authConfig.connectionName!, context.activity.channelId!, context.activity.from?.id!)
|
|
53
|
-
if (userToken !== null) {
|
|
54
|
-
logger.info('Token obtained')
|
|
55
|
-
state.sso.userToken = userToken.token
|
|
56
|
-
state.sso.flowStarted = false
|
|
57
|
-
} else {
|
|
58
|
-
const code = context.activity.text as string
|
|
59
|
-
const userToken = await this.userTokenClient!.getUserToken(authConfig.connectionName!, context.activity.channelId!, context.activity.from?.id!, code)
|
|
60
|
-
if (userToken !== null) {
|
|
61
|
-
logger.info('Token obtained with code')
|
|
62
|
-
state.sso.userToken = userToken.token
|
|
63
|
-
state.sso.flowStarted = false
|
|
64
|
-
} else {
|
|
65
|
-
logger.error('Sign in failed')
|
|
66
|
-
await context.sendActivity(MessageFactory.text('Sign in failed'))
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
retVal = state.sso.userToken
|
|
70
|
-
} else if (state.sso!.flowStarted === false) {
|
|
71
|
-
const signingResource = await this.userTokenClient.getSignInResource(authConfig.clientId!, authConfig.connectionName!, context.activity)
|
|
72
|
-
const oCard: Attachment = CardFactory.oauthCard(authConfig.connectionName!, 'Sign in', '', signingResource)
|
|
73
|
-
await context.sendActivity(MessageFactory.attachment(oCard))
|
|
74
|
-
state.sso!.flowStarted = true
|
|
75
|
-
state.sso.flowExpires = Date.now() + 30000
|
|
76
|
-
logger.info('OAuth flow started')
|
|
77
|
-
}
|
|
78
|
-
state.save(context)
|
|
79
|
-
return retVal
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async signOut (context: TurnContext, state: TurnState) {
|
|
83
|
-
await this.userTokenClient!.signOut(context.activity.from?.id!, context.adapter.authConfig.connectionName!, context.activity.channelId!)
|
|
84
|
-
state.sso!.flowStarted = false
|
|
85
|
-
state.sso!.userToken = ''
|
|
86
|
-
state.sso!.flowExpires = 0
|
|
87
|
-
state.save(context)
|
|
88
|
-
logger.info('User signed out successfully')
|
|
89
|
-
}
|
|
90
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright(c) Microsoft Corporation.All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { Activity, ChannelAccount } from '@microsoft/agents-activity'
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Represents the parameters for creating a conversation.
|
|
10
|
-
*/
|
|
11
|
-
export interface ConversationParameters {
|
|
12
|
-
/**
|
|
13
|
-
* Indicates whether the conversation is a group conversation.
|
|
14
|
-
*/
|
|
15
|
-
isGroup: boolean
|
|
16
|
-
/**
|
|
17
|
-
* The bot account initiating the conversation.
|
|
18
|
-
*/
|
|
19
|
-
bot: ChannelAccount
|
|
20
|
-
/**
|
|
21
|
-
* The members to include in the conversation.
|
|
22
|
-
*/
|
|
23
|
-
members?: ChannelAccount[]
|
|
24
|
-
/**
|
|
25
|
-
* The topic name of the conversation.
|
|
26
|
-
*/
|
|
27
|
-
topicName?: string
|
|
28
|
-
/**
|
|
29
|
-
* The tenant ID of the conversation.
|
|
30
|
-
*/
|
|
31
|
-
tenantId?: string
|
|
32
|
-
/**
|
|
33
|
-
* The initial activity to send to the conversation.
|
|
34
|
-
*/
|
|
35
|
-
activity: Activity
|
|
36
|
-
/**
|
|
37
|
-
* Channel-specific data for the conversation.
|
|
38
|
-
*/
|
|
39
|
-
channelData: unknown
|
|
40
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Represents a resource for exchanging tokens.
|
|
6
|
-
*/
|
|
7
|
-
export interface TokenExchangeResource {
|
|
8
|
-
/**
|
|
9
|
-
* The ID of the token exchange resource.
|
|
10
|
-
*/
|
|
11
|
-
id?: string
|
|
12
|
-
/**
|
|
13
|
-
* The URI of the token exchange resource.
|
|
14
|
-
*/
|
|
15
|
-
uri?: string
|
|
16
|
-
/**
|
|
17
|
-
* The provider ID for the token exchange resource.
|
|
18
|
-
*/
|
|
19
|
-
providerId?: string
|
|
20
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Represents a resource for posting tokens.
|
|
6
|
-
*/
|
|
7
|
-
export interface TokenPostResource {
|
|
8
|
-
/**
|
|
9
|
-
* The SAS URL for the token post resource.
|
|
10
|
-
*/
|
|
11
|
-
sasUrl?: string
|
|
12
|
-
}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
import { Attachment } from '@microsoft/agents-activity'
|
|
5
|
-
import { UserTokenClient } from './userTokenClient'
|
|
6
|
-
import { CloudAdapter } from '../cloudAdapter'
|
|
7
|
-
import { CardFactory } from '../cards/cardFactory'
|
|
8
|
-
import { AgentStatePropertyAccessor } from '../state/agentStatePropertyAccesor'
|
|
9
|
-
import { UserState } from '../state/userState'
|
|
10
|
-
import { TurnContext } from '../turnContext'
|
|
11
|
-
import { MessageFactory } from '../messageFactory'
|
|
12
|
-
import { debug } from '../logger'
|
|
13
|
-
|
|
14
|
-
const logger = debug('agents:web-chat-oauth-flow')
|
|
15
|
-
|
|
16
|
-
class FlowState {
|
|
17
|
-
public flowStarted: boolean = false
|
|
18
|
-
public userToken: string = ''
|
|
19
|
-
public flowExpires: number = 0
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Manages the OAuth flow for Web Chat.
|
|
24
|
-
*/
|
|
25
|
-
export class WebChatOAuthFlow {
|
|
26
|
-
userTokenClient?: UserTokenClient
|
|
27
|
-
state: FlowState | null
|
|
28
|
-
flowStateAccessor: AgentStatePropertyAccessor<FlowState | null>
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Creates a new instance of WebChatOAuthFlow.
|
|
32
|
-
* @param userState The user state.
|
|
33
|
-
*/
|
|
34
|
-
constructor (userState: UserState) {
|
|
35
|
-
this.state = null
|
|
36
|
-
this.flowStateAccessor = userState.createProperty('flowState')
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Gets the OAuth token.
|
|
41
|
-
* @param context The turn context.
|
|
42
|
-
* @returns A promise that resolves to the user token.
|
|
43
|
-
*/
|
|
44
|
-
public async getOAuthToken (context: TurnContext) : Promise<string> {
|
|
45
|
-
this.state = await this.getUserState(context)
|
|
46
|
-
if (this.state!.userToken !== '') {
|
|
47
|
-
return this.state.userToken
|
|
48
|
-
}
|
|
49
|
-
if (this.state?.flowExpires !== 0 && Date.now() > this.state.flowExpires) {
|
|
50
|
-
logger.warn('Sign-in flow expired')
|
|
51
|
-
this.state.flowStarted = false
|
|
52
|
-
this.state.userToken = ''
|
|
53
|
-
await context.sendActivity(MessageFactory.text('Sign-in session expired. Please try again.'))
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
let retVal: string = ''
|
|
57
|
-
const authConfig = context.adapter.authConfig
|
|
58
|
-
if (authConfig.connectionName === undefined) {
|
|
59
|
-
throw new Error('connectionName is not set in the auth config, review your environment variables')
|
|
60
|
-
}
|
|
61
|
-
const adapter = context.adapter as CloudAdapter
|
|
62
|
-
const scope = 'https://api.botframework.com'
|
|
63
|
-
const accessToken = await adapter.authProvider.getAccessToken(authConfig, scope)
|
|
64
|
-
this.userTokenClient = new UserTokenClient(accessToken)
|
|
65
|
-
|
|
66
|
-
if (this.state!.flowStarted === true) {
|
|
67
|
-
const userToken = await this.userTokenClient.getUserToken(authConfig.connectionName!, context.activity.channelId!, context.activity.from?.id!)
|
|
68
|
-
if (userToken !== null) {
|
|
69
|
-
logger.info('Token obtained')
|
|
70
|
-
this.state.userToken = userToken.token
|
|
71
|
-
this.state.flowStarted = false
|
|
72
|
-
} else {
|
|
73
|
-
const code = context.activity.text as string
|
|
74
|
-
const userToken = await this.userTokenClient!.getUserToken(authConfig.connectionName!, context.activity.channelId!, context.activity.from?.id!, code)
|
|
75
|
-
if (userToken !== null) {
|
|
76
|
-
logger.info('Token obtained with code')
|
|
77
|
-
this.state.userToken = userToken.token
|
|
78
|
-
this.state.flowStarted = false
|
|
79
|
-
} else {
|
|
80
|
-
logger.error('Sign in failed')
|
|
81
|
-
await context.sendActivity(MessageFactory.text('Sign in failed'))
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
retVal = this.state.userToken
|
|
85
|
-
} else if (this.state!.flowStarted === false) {
|
|
86
|
-
const signingResource = await this.userTokenClient.getSignInResource(authConfig.clientId!, authConfig.connectionName!, context.activity)
|
|
87
|
-
const oCard: Attachment = CardFactory.oauthCard(authConfig.connectionName!, 'Sign in', '', signingResource)
|
|
88
|
-
await context.sendActivity(MessageFactory.attachment(oCard))
|
|
89
|
-
this.state!.flowStarted = true
|
|
90
|
-
this.state.flowExpires = Date.now() + 30000
|
|
91
|
-
logger.info('OAuth flow started')
|
|
92
|
-
}
|
|
93
|
-
this.flowStateAccessor.set(context, this.state)
|
|
94
|
-
return retVal
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Signs the user out.
|
|
99
|
-
* @param context The turn context.
|
|
100
|
-
* @returns A promise that resolves when the sign-out operation is complete.
|
|
101
|
-
*/
|
|
102
|
-
async signOut (context: TurnContext) {
|
|
103
|
-
await this.userTokenClient!.signOut(context.activity.from?.id!, context.adapter.authConfig.connectionName!, context.activity.channelId!)
|
|
104
|
-
this.state!.flowStarted = false
|
|
105
|
-
this.state!.userToken = ''
|
|
106
|
-
this.state!.flowExpires = 0
|
|
107
|
-
this.flowStateAccessor.set(context, this.state)
|
|
108
|
-
logger.info('User signed out successfully')
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Gets the user state.
|
|
113
|
-
* @param context The turn context.
|
|
114
|
-
* @returns A promise that resolves to the user state.
|
|
115
|
-
*/
|
|
116
|
-
private async getUserState (context: TurnContext) {
|
|
117
|
-
let userProfile: FlowState | null = await this.flowStateAccessor.get(context, null)
|
|
118
|
-
if (userProfile === null) {
|
|
119
|
-
userProfile = new FlowState()
|
|
120
|
-
}
|
|
121
|
-
return userProfile
|
|
122
|
-
}
|
|
123
|
-
}
|