@twentyhq/teams 1.1.2 → 1.2.1
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/dependencies/yarn.lock +723 -3
- package/manifest.json +46 -29
- package/package.json +4 -2
- package/src/features/chat/logic-functions/teams-activities-enqueue.mjs +378 -162
- package/src/features/chat/logic-functions/teams-activities-enqueue.mjs.map +4 -4
- package/src/features/chat/logic-functions/teams-activities-enqueue.ts +1 -1
- package/src/features/chat/logic-functions/teams-activities-resolver.mjs +500 -40
- package/src/features/chat/logic-functions/teams-activities-resolver.mjs.map +4 -4
- package/src/features/chat/logic-functions/teams-activities-resolver.ts +13 -2
- package/src/features/chat/logic-functions/teams-list-unlinked-users.mjs +95 -61
- package/src/features/chat/logic-functions/teams-list-unlinked-users.mjs.map +4 -4
- package/src/features/chat/logic-functions/teams-match-user-links.mjs +105 -86
- package/src/features/chat/logic-functions/teams-match-user-links.mjs.map +4 -4
- package/src/features/chat/logic-functions/teams-register-connection.mjs +119 -101
- package/src/features/chat/logic-functions/teams-register-connection.mjs.map +4 -4
- package/src/features/chat/logic-functions/teams-register-connection.ts +1 -1
- package/src/features/chat/logic-functions/teams-search-users.mjs +96 -62
- package/src/features/chat/logic-functions/teams-search-users.mjs.map +4 -4
- package/src/features/chat/logic-functions/teams-set-user-link.mjs +88 -54
- package/src/features/chat/logic-functions/teams-set-user-link.mjs.map +4 -4
- package/src/features/chat/logic-functions/teams-tenant-release.mjs +72 -41
- package/src/features/chat/logic-functions/teams-tenant-release.mjs.map +4 -4
- package/src/features/transcripts/logic-functions/teams-count-transcript-history.mjs +99 -68
- package/src/features/transcripts/logic-functions/teams-count-transcript-history.mjs.map +4 -4
- package/src/features/transcripts/logic-functions/teams-import-transcript-history.mjs +99 -68
- package/src/features/transcripts/logic-functions/teams-import-transcript-history.mjs.map +4 -4
- package/src/features/transcripts/logic-functions/teams-import-transcript.mjs +96 -65
- package/src/features/transcripts/logic-functions/teams-import-transcript.mjs.map +4 -4
- package/src/features/transcripts/logic-functions/teams-list-organizer-transcripts.mjs +89 -58
- package/src/features/transcripts/logic-functions/teams-list-organizer-transcripts.mjs.map +4 -4
- package/src/features/transcripts/logic-functions/teams-sync-transcript.mjs +96 -65
- package/src/features/transcripts/logic-functions/teams-sync-transcript.mjs.map +4 -4
- package/src/features/transcripts/logic-functions/teams-transcript-history-count.mjs +0 -1
- package/src/features/transcripts/logic-functions/teams-transcript-history-count.mjs.map +2 -2
- package/src/features/transcripts/logic-functions/teams-transcript-history-import.mjs +0 -1
- package/src/features/transcripts/logic-functions/teams-transcript-history-import.mjs.map +2 -2
- package/src/features/transcripts/logic-functions/teams-transcript-history-status.mjs +0 -1
- package/src/features/transcripts/logic-functions/teams-transcript-history-status.mjs.map +2 -2
- package/src/features/transcripts/logic-functions/teams-transcripts-webhook.mjs +104 -73
- package/src/features/transcripts/logic-functions/teams-transcripts-webhook.mjs.map +4 -4
- package/src/features/transcripts/logic-functions/teams-uninstall.mjs +72 -41
- package/src/features/transcripts/logic-functions/teams-uninstall.mjs.map +4 -4
- package/src/front-components/settings.front-component.mjs +113 -113
- package/src/front-components/settings.front-component.mjs.map +4 -4
- package/src/logic-functions/teams-health-check.mjs +46 -25
- package/src/logic-functions/teams-health-check.mjs.map +4 -4
- package/src/logic-functions/teams-health-check.ts +21 -6
- package/src/logic-functions/teams-post-install.mjs +1270 -0
- package/src/logic-functions/teams-post-install.mjs.map +7 -0
- package/src/logic-functions/teams-post-install.ts +15 -0
|
@@ -0,0 +1,1270 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from 'module';
|
|
2
|
+
const require = __createRequire(import.meta.url);
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
10
|
+
try {
|
|
11
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
12
|
+
} catch (e3) {
|
|
13
|
+
throw mod = 0, e3;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
30
|
+
mod
|
|
31
|
+
));
|
|
32
|
+
|
|
33
|
+
// node_modules/@sniptt/guards/build/guards/primitives.js
|
|
34
|
+
var require_primitives = __commonJS({
|
|
35
|
+
"node_modules/@sniptt/guards/build/guards/primitives.js"(exports) {
|
|
36
|
+
"use strict";
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.isSymbol = exports.isBigInt = exports.isString = exports.isNumber = exports.isBoolean = exports.isUndefined = void 0;
|
|
39
|
+
var isUndefined = (term) => {
|
|
40
|
+
return typeof term === "undefined";
|
|
41
|
+
};
|
|
42
|
+
exports.isUndefined = isUndefined;
|
|
43
|
+
var isBoolean = (term) => {
|
|
44
|
+
return typeof term === "boolean";
|
|
45
|
+
};
|
|
46
|
+
exports.isBoolean = isBoolean;
|
|
47
|
+
var isNumber = (term) => {
|
|
48
|
+
return typeof term === "number" && !Number.isNaN(term);
|
|
49
|
+
};
|
|
50
|
+
exports.isNumber = isNumber;
|
|
51
|
+
var isString = (term) => {
|
|
52
|
+
return typeof term === "string";
|
|
53
|
+
};
|
|
54
|
+
exports.isString = isString;
|
|
55
|
+
var isBigInt = (term) => {
|
|
56
|
+
return typeof term === "bigint";
|
|
57
|
+
};
|
|
58
|
+
exports.isBigInt = isBigInt;
|
|
59
|
+
var isSymbol = (term) => {
|
|
60
|
+
return typeof term === "symbol";
|
|
61
|
+
};
|
|
62
|
+
exports.isSymbol = isSymbol;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// node_modules/@sniptt/guards/build/guards/structural.js
|
|
67
|
+
var require_structural = __commonJS({
|
|
68
|
+
"node_modules/@sniptt/guards/build/guards/structural.js"(exports) {
|
|
69
|
+
"use strict";
|
|
70
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
71
|
+
exports.isDate = exports.isWeakSet = exports.isWeakMap = exports.isSet = exports.isMap = exports.isArray = exports.isObject = exports.isFunction = exports.isNull = void 0;
|
|
72
|
+
var isNull = (term) => {
|
|
73
|
+
return term === null;
|
|
74
|
+
};
|
|
75
|
+
exports.isNull = isNull;
|
|
76
|
+
var isFunction = (term) => {
|
|
77
|
+
return typeof term === "function";
|
|
78
|
+
};
|
|
79
|
+
exports.isFunction = isFunction;
|
|
80
|
+
var isObject = (term) => {
|
|
81
|
+
return !exports.isNull(term) && typeof term === "object";
|
|
82
|
+
};
|
|
83
|
+
exports.isObject = isObject;
|
|
84
|
+
var isArray = (term) => {
|
|
85
|
+
return Array.isArray(term);
|
|
86
|
+
};
|
|
87
|
+
exports.isArray = isArray;
|
|
88
|
+
var isMap = (term) => {
|
|
89
|
+
return term instanceof Map;
|
|
90
|
+
};
|
|
91
|
+
exports.isMap = isMap;
|
|
92
|
+
var isSet = (term) => {
|
|
93
|
+
return term instanceof Set;
|
|
94
|
+
};
|
|
95
|
+
exports.isSet = isSet;
|
|
96
|
+
var isWeakMap = (term) => {
|
|
97
|
+
return term instanceof WeakMap;
|
|
98
|
+
};
|
|
99
|
+
exports.isWeakMap = isWeakMap;
|
|
100
|
+
var isWeakSet = (term) => {
|
|
101
|
+
return term instanceof WeakSet;
|
|
102
|
+
};
|
|
103
|
+
exports.isWeakSet = isWeakSet;
|
|
104
|
+
var isDate = (term) => {
|
|
105
|
+
return term instanceof Date;
|
|
106
|
+
};
|
|
107
|
+
exports.isDate = isDate;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// node_modules/@sniptt/guards/build/guards/convenience.js
|
|
112
|
+
var require_convenience = __commonJS({
|
|
113
|
+
"node_modules/@sniptt/guards/build/guards/convenience.js"(exports) {
|
|
114
|
+
"use strict";
|
|
115
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
116
|
+
exports.isNegativeInteger = exports.isNonNegativeInteger = exports.isPositiveInteger = exports.isInteger = exports.isNumberOrNaN = exports.isNonEmptyString = exports.isNonEmptyArray = exports.isObjectOrNull = void 0;
|
|
117
|
+
var primitives_1 = require_primitives();
|
|
118
|
+
var structural_1 = require_structural();
|
|
119
|
+
var isObjectOrNull = (term) => {
|
|
120
|
+
return typeof term === "object";
|
|
121
|
+
};
|
|
122
|
+
exports.isObjectOrNull = isObjectOrNull;
|
|
123
|
+
var isNonEmptyArray = (term) => {
|
|
124
|
+
return structural_1.isArray(term) && term.length > 0;
|
|
125
|
+
};
|
|
126
|
+
exports.isNonEmptyArray = isNonEmptyArray;
|
|
127
|
+
var isNonEmptyString17 = (term) => {
|
|
128
|
+
return primitives_1.isString(term) && term.length > 0;
|
|
129
|
+
};
|
|
130
|
+
exports.isNonEmptyString = isNonEmptyString17;
|
|
131
|
+
var isNumberOrNaN = (term) => {
|
|
132
|
+
return typeof term === "number";
|
|
133
|
+
};
|
|
134
|
+
exports.isNumberOrNaN = isNumberOrNaN;
|
|
135
|
+
var isInteger = (term) => {
|
|
136
|
+
return primitives_1.isNumber(term) && Number.isInteger(term);
|
|
137
|
+
};
|
|
138
|
+
exports.isInteger = isInteger;
|
|
139
|
+
var isPositiveInteger = (term) => {
|
|
140
|
+
return exports.isInteger(term) && term > 0;
|
|
141
|
+
};
|
|
142
|
+
exports.isPositiveInteger = isPositiveInteger;
|
|
143
|
+
var isNonNegativeInteger = (term) => {
|
|
144
|
+
return exports.isInteger(term) && term >= 0;
|
|
145
|
+
};
|
|
146
|
+
exports.isNonNegativeInteger = isNonNegativeInteger;
|
|
147
|
+
var isNegativeInteger = (term) => {
|
|
148
|
+
return exports.isInteger(term) && term < 0;
|
|
149
|
+
};
|
|
150
|
+
exports.isNegativeInteger = isNegativeInteger;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// node_modules/@sniptt/guards/build/index.js
|
|
155
|
+
var require_build = __commonJS({
|
|
156
|
+
"node_modules/@sniptt/guards/build/index.js"(exports) {
|
|
157
|
+
"use strict";
|
|
158
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o2, m2, k2, k22) {
|
|
159
|
+
if (k22 === void 0) k22 = k2;
|
|
160
|
+
Object.defineProperty(o2, k22, { enumerable: true, get: function() {
|
|
161
|
+
return m2[k2];
|
|
162
|
+
} });
|
|
163
|
+
}) : (function(o2, m2, k2, k22) {
|
|
164
|
+
if (k22 === void 0) k22 = k2;
|
|
165
|
+
o2[k22] = m2[k2];
|
|
166
|
+
}));
|
|
167
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? (function(o2, v2) {
|
|
168
|
+
Object.defineProperty(o2, "default", { enumerable: true, value: v2 });
|
|
169
|
+
}) : function(o2, v2) {
|
|
170
|
+
o2["default"] = v2;
|
|
171
|
+
});
|
|
172
|
+
var __importStar = exports && exports.__importStar || function(mod) {
|
|
173
|
+
if (mod && mod.__esModule) return mod;
|
|
174
|
+
var result = {};
|
|
175
|
+
if (mod != null) {
|
|
176
|
+
for (var k2 in mod) if (k2 !== "default" && Object.prototype.hasOwnProperty.call(mod, k2)) __createBinding(result, mod, k2);
|
|
177
|
+
}
|
|
178
|
+
__setModuleDefault(result, mod);
|
|
179
|
+
return result;
|
|
180
|
+
};
|
|
181
|
+
var __exportStar = exports && exports.__exportStar || function(m2, exports2) {
|
|
182
|
+
for (var p2 in m2) if (p2 !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p2)) __createBinding(exports2, m2, p2);
|
|
183
|
+
};
|
|
184
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
185
|
+
exports.structural = exports.primitives = exports.convenience = void 0;
|
|
186
|
+
exports.convenience = __importStar(require_convenience());
|
|
187
|
+
__exportStar(require_convenience(), exports);
|
|
188
|
+
exports.primitives = __importStar(require_primitives());
|
|
189
|
+
__exportStar(require_primitives(), exports);
|
|
190
|
+
exports.structural = __importStar(require_structural());
|
|
191
|
+
__exportStar(require_structural(), exports);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// twenty-sdk-define-stub:__twenty-sdk-define-stub__
|
|
196
|
+
var __defineFactoryStub = (config) => ({
|
|
197
|
+
success: true,
|
|
198
|
+
config,
|
|
199
|
+
errors: []
|
|
200
|
+
});
|
|
201
|
+
var __anyHandler = {
|
|
202
|
+
get(_target, prop) {
|
|
203
|
+
if (prop === "__esModule") return true;
|
|
204
|
+
if (prop === Symbol.toPrimitive) return () => "";
|
|
205
|
+
if (typeof prop === "symbol") return void 0;
|
|
206
|
+
return new Proxy(() => void 0, __anyHandler);
|
|
207
|
+
},
|
|
208
|
+
apply() {
|
|
209
|
+
return new Proxy(() => void 0, __anyHandler);
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
var __anyStub = new Proxy(() => void 0, __anyHandler);
|
|
213
|
+
var definePostInstallLogicFunction = __defineFactoryStub;
|
|
214
|
+
|
|
215
|
+
// src/constants/universal-identifiers.ts
|
|
216
|
+
var POST_INSTALL_UNIVERSAL_IDENTIFIER = "dd5a2d18-d787-4b1c-90d6-4f2036d67123";
|
|
217
|
+
|
|
218
|
+
// src/features/chat/logic-functions/utils/claim-teams-tenants-of-existing-connections.ts
|
|
219
|
+
var import_guards18 = __toESM(require_build());
|
|
220
|
+
|
|
221
|
+
// src/features/chat/logic-functions/utils/fetch-current-workspace-id-or-throw.ts
|
|
222
|
+
var import_guards = __toESM(require_build());
|
|
223
|
+
import { MetadataApiClient } from "twenty-client-sdk/metadata";
|
|
224
|
+
var fetchCurrentWorkspaceIdOrThrow = async () => {
|
|
225
|
+
const { currentWorkspace } = await new MetadataApiClient().query({
|
|
226
|
+
currentWorkspace: { id: true }
|
|
227
|
+
});
|
|
228
|
+
if (!(0, import_guards.isNonEmptyString)(currentWorkspace?.id)) {
|
|
229
|
+
throw new Error("Could not read the id of the current workspace");
|
|
230
|
+
}
|
|
231
|
+
return currentWorkspace.id;
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
// node_modules/twenty-sdk/dist/utils/index.mjs
|
|
235
|
+
var import_guards2 = __toESM(require_build(), 1);
|
|
236
|
+
var o = (n2) => !(0, import_guards2.isUndefined)(n2) && !(0, import_guards2.isNull)(n2);
|
|
237
|
+
|
|
238
|
+
// src/features/chat/logic-functions/utils/is-working-teams-workspace-connection.ts
|
|
239
|
+
var isWorkingTeamsWorkspaceConnection = (connection) => connection.scope === "WORKSPACE" && !o(connection.authFailedAt);
|
|
240
|
+
|
|
241
|
+
// src/features/chat/logic-functions/utils/register-teams-connection.ts
|
|
242
|
+
var import_guards17 = __toESM(require_build());
|
|
243
|
+
|
|
244
|
+
// node_modules/twenty-sdk/dist/logic-function/index.mjs
|
|
245
|
+
var import_guards3 = __toESM(require_build(), 1);
|
|
246
|
+
import { MetadataApiClient as a } from "twenty-client-sdk/metadata";
|
|
247
|
+
var s = (e3) => !(0, import_guards3.isUndefined)(e3) && !(0, import_guards3.isNull)(e3);
|
|
248
|
+
var c = (t3) => {
|
|
249
|
+
let n2 = { type: "unknown" };
|
|
250
|
+
switch (t3.type) {
|
|
251
|
+
case "string":
|
|
252
|
+
n2.type = "string";
|
|
253
|
+
break;
|
|
254
|
+
case "number":
|
|
255
|
+
case "integer":
|
|
256
|
+
n2.type = "number";
|
|
257
|
+
break;
|
|
258
|
+
case "boolean":
|
|
259
|
+
n2.type = "boolean";
|
|
260
|
+
break;
|
|
261
|
+
case "array":
|
|
262
|
+
n2.type = "array", t3.items && (n2.items = c(t3.items));
|
|
263
|
+
break;
|
|
264
|
+
case "object":
|
|
265
|
+
n2.type = "object", t3.properties && (n2.properties = Object.fromEntries(Object.entries(t3.properties).map(([e3, t4]) => [e3, c(t4)])));
|
|
266
|
+
break;
|
|
267
|
+
case "record":
|
|
268
|
+
n2.type = "record";
|
|
269
|
+
break;
|
|
270
|
+
case "records":
|
|
271
|
+
n2.type = "records";
|
|
272
|
+
break;
|
|
273
|
+
default:
|
|
274
|
+
n2.type = "unknown";
|
|
275
|
+
}
|
|
276
|
+
return Array.isArray(t3.enum) && (n2.enum = t3.enum.filter((e3) => typeof e3 == "string")), t3.multiline === true && (n2.multiline = true), (0, import_guards3.isNonEmptyString)(t3.label) && (n2.label = t3.label), (0, import_guards3.isNonEmptyString)(t3.objectUniversalIdentifier) && (n2.objectUniversalIdentifier = t3.objectUniversalIdentifier), n2;
|
|
277
|
+
};
|
|
278
|
+
var l = (e3) => [c(e3)];
|
|
279
|
+
l({
|
|
280
|
+
type: "object",
|
|
281
|
+
properties: {
|
|
282
|
+
a: { type: "string" },
|
|
283
|
+
b: { type: "number" }
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
var f = class extends Error {
|
|
287
|
+
constructor(e3) {
|
|
288
|
+
super(`App connection ${e3} requires the user to reconnect (authFailedAt is set). Surface a "Reconnect" prompt in your UI.`), this.name = "AppConnectionAuthFailedError", this.connectionId = e3;
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
var p = {
|
|
292
|
+
user: "USER",
|
|
293
|
+
workspace: "WORKSPACE"
|
|
294
|
+
};
|
|
295
|
+
var m = "TWENTY_API_URL";
|
|
296
|
+
var h = "TWENTY_APP_APPLICATION_ACCESS_TOKEN";
|
|
297
|
+
var g = {
|
|
298
|
+
USER: "user",
|
|
299
|
+
WORKSPACE: "workspace"
|
|
300
|
+
};
|
|
301
|
+
var _ = (e3) => ({
|
|
302
|
+
...e3,
|
|
303
|
+
visibility: g[e3.scope]
|
|
304
|
+
});
|
|
305
|
+
var v = () => process.env.TWENTY_APP_APPLICATION_ACCESS_TOKEN ?? process.env.TWENTY_APP_ACCESS_TOKEN;
|
|
306
|
+
var y = async ({ query: e3, variables: t3, caller: n2 }) => {
|
|
307
|
+
let r2 = process.env[m], i2 = v();
|
|
308
|
+
if (!r2 || !i2) throw Error(`${n2}() requires the app runtime env vars ${m} and ${h}.`);
|
|
309
|
+
let a2 = await fetch(`${r2}/metadata`, {
|
|
310
|
+
method: "POST",
|
|
311
|
+
headers: {
|
|
312
|
+
"Content-Type": "application/json",
|
|
313
|
+
Authorization: `Bearer ${i2}`
|
|
314
|
+
},
|
|
315
|
+
body: JSON.stringify({
|
|
316
|
+
query: e3,
|
|
317
|
+
variables: t3
|
|
318
|
+
})
|
|
319
|
+
});
|
|
320
|
+
if (!a2.ok) throw Error(`${n2}() failed: HTTP ${a2.status} ${a2.statusText}`);
|
|
321
|
+
let o2 = await a2.json();
|
|
322
|
+
if (o2.errors && o2.errors.length > 0) throw Error(`${n2}() failed: ${o2.errors.map((e4) => e4.message).join(", ")}`);
|
|
323
|
+
if (!o2.data) throw Error(`${n2}() failed: response contained no data.`);
|
|
324
|
+
return o2.data;
|
|
325
|
+
};
|
|
326
|
+
var b = "\n query GetAppConnection($id: ID!) {\n appConnection(id: $id) {\n id\n providerName\n name\n handle\n externalAccountId\n scope\n userWorkspaceId\n workspaceMemberId\n providerType\n accessToken\n scopes\n authFailedAt\n authFailedReason\n }\n }\n";
|
|
327
|
+
var x = async (e3) => {
|
|
328
|
+
let { appConnection: t3 } = await y({
|
|
329
|
+
query: b,
|
|
330
|
+
variables: { id: e3 },
|
|
331
|
+
caller: "getConnection"
|
|
332
|
+
});
|
|
333
|
+
if (t3.authFailedAt !== null) throw new f(t3.id);
|
|
334
|
+
return _(t3);
|
|
335
|
+
};
|
|
336
|
+
var S = "agentChatAssistant";
|
|
337
|
+
var C = ({ objectNameSingular: e3, recordId: t3, displayName: n2 }) => e3 === "agentChatAssistant" ? `@${n2}` : `[[record:${e3}:${t3}:${n2}]]`;
|
|
338
|
+
var te = "\n query ListAppConnections($filter: ListAppConnectionsInput) {\n appConnections(filter: $filter) {\n id\n providerName\n name\n handle\n externalAccountId\n scope\n userWorkspaceId\n workspaceMemberId\n providerType\n accessToken\n scopes\n authFailedAt\n authFailedReason\n }\n }\n";
|
|
339
|
+
var w = async ({ visibility: e3, ...t3 } = {}) => {
|
|
340
|
+
let { appConnections: n2 } = await y({
|
|
341
|
+
query: te,
|
|
342
|
+
variables: { filter: {
|
|
343
|
+
...t3,
|
|
344
|
+
scope: t3.scope ?? (s(e3) ? p[e3] : void 0)
|
|
345
|
+
} },
|
|
346
|
+
caller: "listConnections"
|
|
347
|
+
});
|
|
348
|
+
return n2.map(_);
|
|
349
|
+
};
|
|
350
|
+
var O = "\n id\n handle\n displayName\n visibility\n connectedAccountId\n isSyncEnabled\n participantHandleFieldUniversalIdentifier\n messagingProviderUniversalIdentifier\n";
|
|
351
|
+
var k = `
|
|
352
|
+
mutation CreateAppMessageChannel($input: CreateAppMessageChannelInput!) {
|
|
353
|
+
createAppMessageChannel(input: $input) {
|
|
354
|
+
${O}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
`;
|
|
358
|
+
var j = `
|
|
359
|
+
query ListAppMessageChannels($filter: ListAppMessageChannelsInput) {
|
|
360
|
+
appMessageChannels(filter: $filter) {
|
|
361
|
+
${O}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
`;
|
|
365
|
+
var N = `
|
|
366
|
+
mutation UpdateAppMessageChannel($input: UpdateAppMessageChannelInput!) {
|
|
367
|
+
updateAppMessageChannel(input: $input) {
|
|
368
|
+
${O}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
`;
|
|
372
|
+
var F = `
|
|
373
|
+
mutation DeleteAppMessageChannel($id: UUID!) {
|
|
374
|
+
deleteAppMessageChannel(id: $id) {
|
|
375
|
+
${O}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
`;
|
|
379
|
+
var z = "\n id\n externalId\n name\n isSynced\n messageChannelId\n";
|
|
380
|
+
var B = `
|
|
381
|
+
query ListAppMessageFolders($filter: ListAppMessageFoldersInput) {
|
|
382
|
+
appMessageFolders(filter: $filter) {
|
|
383
|
+
${z}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
`;
|
|
387
|
+
var H = `
|
|
388
|
+
mutation SyncAppMessageFolders($input: SyncAppMessageFoldersInput!) {
|
|
389
|
+
syncAppMessageFolders(input: $input) {
|
|
390
|
+
${z}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
`;
|
|
394
|
+
var ce = C({
|
|
395
|
+
objectNameSingular: S,
|
|
396
|
+
recordId: S,
|
|
397
|
+
displayName: "Ada"
|
|
398
|
+
});
|
|
399
|
+
var me = "\n query GetAppKeyValue($key: String!, $scope: AppKeyValueScope) {\n appKeyValue(key: $key, scope: $scope) {\n key\n value\n scope\n }\n }\n";
|
|
400
|
+
var Q = "\n mutation SetAppKeyValue($input: SetAppKeyValueInput!) {\n setAppKeyValue(input: $input) {\n key\n value\n scope\n }\n }\n";
|
|
401
|
+
var he = "\n mutation DeleteAppKeyValue($key: String!, $scope: AppKeyValueScope) {\n deleteAppKeyValue(key: $key, scope: $scope)\n }\n";
|
|
402
|
+
var $ = "WORKSPACE";
|
|
403
|
+
var ge = {
|
|
404
|
+
async get(e3, t3) {
|
|
405
|
+
let { appKeyValue: n2 } = await y({
|
|
406
|
+
query: me,
|
|
407
|
+
variables: {
|
|
408
|
+
key: e3,
|
|
409
|
+
scope: t3?.scope ?? $
|
|
410
|
+
},
|
|
411
|
+
caller: "kv.get"
|
|
412
|
+
});
|
|
413
|
+
return n2?.value ?? null;
|
|
414
|
+
},
|
|
415
|
+
async set(e3, t3, n2) {
|
|
416
|
+
await y({
|
|
417
|
+
query: Q,
|
|
418
|
+
variables: { input: {
|
|
419
|
+
key: e3,
|
|
420
|
+
value: t3,
|
|
421
|
+
scope: n2?.scope ?? $
|
|
422
|
+
} },
|
|
423
|
+
caller: "kv.set"
|
|
424
|
+
});
|
|
425
|
+
},
|
|
426
|
+
async delete(e3, t3) {
|
|
427
|
+
let { deleteAppKeyValue: n2 } = await y({
|
|
428
|
+
query: he,
|
|
429
|
+
variables: {
|
|
430
|
+
key: e3,
|
|
431
|
+
scope: t3?.scope ?? $
|
|
432
|
+
},
|
|
433
|
+
caller: "kv.delete"
|
|
434
|
+
});
|
|
435
|
+
return n2;
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
// src/features/chat/logic-functions/constants/teams-connected-account-tenant-kv-key-prefix.ts
|
|
440
|
+
var TEAMS_CONNECTED_ACCOUNT_TENANT_KV_KEY_PREFIX = "teams-connected-account-tenant";
|
|
441
|
+
|
|
442
|
+
// src/features/chat/logic-functions/utils/build-teams-connected-account-tenant-kv-key.ts
|
|
443
|
+
var buildTeamsConnectedAccountTenantKvKey = (connectedAccountId) => `${TEAMS_CONNECTED_ACCOUNT_TENANT_KV_KEY_PREFIX}:${connectedAccountId}`;
|
|
444
|
+
|
|
445
|
+
// src/features/chat/logic-functions/constants/teams-tenant-claim-conflict-kv-key-prefix.ts
|
|
446
|
+
var TEAMS_TENANT_CLAIM_CONFLICT_KV_KEY_PREFIX = "teams-tenant-claim-conflict";
|
|
447
|
+
|
|
448
|
+
// src/features/chat/logic-functions/utils/build-teams-tenant-claim-conflict-kv-key.ts
|
|
449
|
+
var buildTeamsTenantClaimConflictKvKey = (connectedAccountId) => `${TEAMS_TENANT_CLAIM_CONFLICT_KV_KEY_PREFIX}:${connectedAccountId}`;
|
|
450
|
+
|
|
451
|
+
// src/features/chat/logic-functions/constants/teams-tenant-kv-key-prefix.ts
|
|
452
|
+
var TEAMS_TENANT_KV_KEY_PREFIX = "teams-tenant";
|
|
453
|
+
|
|
454
|
+
// src/features/chat/logic-functions/utils/build-teams-tenant-kv-key.ts
|
|
455
|
+
var buildTeamsTenantKvKey = (tenantId) => `${TEAMS_TENANT_KV_KEY_PREFIX}:${tenantId}`;
|
|
456
|
+
|
|
457
|
+
// src/features/chat/logic-functions/utils/is-teams-tenant-held-by-another-workspace.ts
|
|
458
|
+
var import_guards4 = __toESM(require_build());
|
|
459
|
+
var isTeamsTenantHeldByAnotherWorkspace = async ({
|
|
460
|
+
tenantId,
|
|
461
|
+
workspaceId
|
|
462
|
+
}) => {
|
|
463
|
+
const claimingWorkspaceId = await ge.get(
|
|
464
|
+
buildTeamsTenantKvKey(tenantId),
|
|
465
|
+
{ scope: "SERVER" }
|
|
466
|
+
);
|
|
467
|
+
return (0, import_guards4.isNonEmptyString)(claimingWorkspaceId) && claimingWorkspaceId !== workspaceId;
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
// src/features/chat/logic-functions/utils/claim-teams-tenant.ts
|
|
471
|
+
var claimTeamsTenant = async ({
|
|
472
|
+
tenantId,
|
|
473
|
+
workspaceId
|
|
474
|
+
}) => {
|
|
475
|
+
try {
|
|
476
|
+
await ge.set(buildTeamsTenantKvKey(tenantId), null, { scope: "SERVER" });
|
|
477
|
+
return true;
|
|
478
|
+
} catch (error) {
|
|
479
|
+
if (await isTeamsTenantHeldByAnotherWorkspace({ tenantId, workspaceId })) {
|
|
480
|
+
return false;
|
|
481
|
+
}
|
|
482
|
+
throw error;
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
// src/features/chat/logic-functions/utils/delete-teams-tenant-claim-conflict.ts
|
|
487
|
+
var deleteTeamsTenantClaimConflict = async ({
|
|
488
|
+
connectedAccountId
|
|
489
|
+
}) => {
|
|
490
|
+
await ge.delete(buildTeamsTenantClaimConflictKvKey(connectedAccountId));
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
// src/features/chat/logic-functions/utils/fetch-teams-tenant-id.ts
|
|
494
|
+
var import_guards7 = __toESM(require_build());
|
|
495
|
+
|
|
496
|
+
// src/features/transcripts/logic-functions/utils/fetch-graph-response.ts
|
|
497
|
+
var import_guards6 = __toESM(require_build());
|
|
498
|
+
|
|
499
|
+
// src/features/transcripts/logic-functions/constants/graph-request-max-attempts.ts
|
|
500
|
+
var GRAPH_REQUEST_MAX_ATTEMPTS = 4;
|
|
501
|
+
|
|
502
|
+
// src/features/transcripts/logic-functions/constants/graph-request-retry-base-delay-milliseconds.ts
|
|
503
|
+
var GRAPH_REQUEST_RETRY_BASE_DELAY_MILLISECONDS = 1e3;
|
|
504
|
+
|
|
505
|
+
// src/features/transcripts/logic-functions/constants/graph-retryable-statuses.ts
|
|
506
|
+
var GRAPH_RETRYABLE_STATUSES = /* @__PURE__ */ new Set([429, 502, 503, 504]);
|
|
507
|
+
|
|
508
|
+
// src/features/transcripts/logic-functions/types/graph-request-error.ts
|
|
509
|
+
var GraphRequestError = class extends Error {
|
|
510
|
+
constructor({
|
|
511
|
+
message,
|
|
512
|
+
status,
|
|
513
|
+
innerErrorCode
|
|
514
|
+
}) {
|
|
515
|
+
super(message);
|
|
516
|
+
this.name = "GraphRequestError";
|
|
517
|
+
this.status = status;
|
|
518
|
+
this.innerErrorCode = innerErrorCode;
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
// src/features/transcripts/logic-functions/constants/microsoft-graph-base-url.ts
|
|
523
|
+
var MICROSOFT_GRAPH_BASE_URL = "https://graph.microsoft.com/v1.0";
|
|
524
|
+
|
|
525
|
+
// src/features/transcripts/logic-functions/utils/resolve-graph-url-or-throw.ts
|
|
526
|
+
var resolveGraphUrlOrThrow = (url) => {
|
|
527
|
+
const resolvedUrl = new URL(url, `${MICROSOFT_GRAPH_BASE_URL}/`);
|
|
528
|
+
if (resolvedUrl.origin !== new URL(MICROSOFT_GRAPH_BASE_URL).origin) {
|
|
529
|
+
throw new Error("Microsoft Graph URLs must use graph.microsoft.com");
|
|
530
|
+
}
|
|
531
|
+
return resolvedUrl.toString();
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
// src/utils/parse-retry-after-ms.ts
|
|
535
|
+
var import_guards5 = __toESM(require_build());
|
|
536
|
+
var parseRetryAfterMs = (retryAfter) => {
|
|
537
|
+
if (!(0, import_guards5.isNonEmptyString)(retryAfter)) {
|
|
538
|
+
return void 0;
|
|
539
|
+
}
|
|
540
|
+
const retryAfterSeconds = Number(retryAfter);
|
|
541
|
+
if (Number.isFinite(retryAfterSeconds)) {
|
|
542
|
+
return Math.max(retryAfterSeconds * 1e3, 0);
|
|
543
|
+
}
|
|
544
|
+
const retryAtMs = Date.parse(retryAfter);
|
|
545
|
+
return Number.isNaN(retryAtMs) ? void 0 : Math.max(retryAtMs - Date.now(), 0);
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
// src/utils/sleep-for-milliseconds.ts
|
|
549
|
+
var sleepForMilliseconds = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
550
|
+
|
|
551
|
+
// src/utils/fetch-with-retries.ts
|
|
552
|
+
var fetchWithRetries = async ({
|
|
553
|
+
sendRequest,
|
|
554
|
+
maxAttempts,
|
|
555
|
+
isRetryableStatus,
|
|
556
|
+
getRetryDelayMs,
|
|
557
|
+
retryAbortSignal
|
|
558
|
+
}) => {
|
|
559
|
+
const sendAttempt = async ({
|
|
560
|
+
attempt,
|
|
561
|
+
waitedMs
|
|
562
|
+
}) => {
|
|
563
|
+
const response = await sendRequest();
|
|
564
|
+
if (response.ok || !isRetryableStatus(response.status) || attempt + 1 >= maxAttempts) {
|
|
565
|
+
return response;
|
|
566
|
+
}
|
|
567
|
+
const delayMs = getRetryDelayMs({
|
|
568
|
+
attempt,
|
|
569
|
+
retryAfterMs: parseRetryAfterMs(response.headers.get("retry-after")),
|
|
570
|
+
waitedMs
|
|
571
|
+
});
|
|
572
|
+
if (!o(delayMs)) {
|
|
573
|
+
return response;
|
|
574
|
+
}
|
|
575
|
+
await sleepForMilliseconds(delayMs);
|
|
576
|
+
if (o(retryAbortSignal) && retryAbortSignal.aborted) {
|
|
577
|
+
return response;
|
|
578
|
+
}
|
|
579
|
+
await response.body?.cancel();
|
|
580
|
+
return sendAttempt({ attempt: attempt + 1, waitedMs: waitedMs + delayMs });
|
|
581
|
+
};
|
|
582
|
+
return sendAttempt({ attempt: 0, waitedMs: 0 });
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
// src/features/transcripts/logic-functions/utils/fetch-graph-response.ts
|
|
586
|
+
var fetchGraphResponse = async ({
|
|
587
|
+
accessToken,
|
|
588
|
+
url,
|
|
589
|
+
accept,
|
|
590
|
+
method,
|
|
591
|
+
body
|
|
592
|
+
}) => {
|
|
593
|
+
const resolvedUrl = resolveGraphUrlOrThrow(url);
|
|
594
|
+
const response = await fetchWithRetries({
|
|
595
|
+
sendRequest: () => fetch(resolvedUrl, {
|
|
596
|
+
method,
|
|
597
|
+
redirect: "error",
|
|
598
|
+
headers: {
|
|
599
|
+
Authorization: `Bearer ${accessToken}`,
|
|
600
|
+
Accept: accept,
|
|
601
|
+
...o(body) ? { "Content-Type": "application/json" } : {}
|
|
602
|
+
},
|
|
603
|
+
body: o(body) ? JSON.stringify(body) : void 0
|
|
604
|
+
}),
|
|
605
|
+
maxAttempts: GRAPH_REQUEST_MAX_ATTEMPTS,
|
|
606
|
+
isRetryableStatus: (status) => GRAPH_RETRYABLE_STATUSES.has(status),
|
|
607
|
+
getRetryDelayMs: ({ attempt, retryAfterMs }) => o(retryAfterMs) && retryAfterMs > 0 ? retryAfterMs : GRAPH_REQUEST_RETRY_BASE_DELAY_MILLISECONDS * 2 ** attempt
|
|
608
|
+
});
|
|
609
|
+
if (response.ok) {
|
|
610
|
+
return response;
|
|
611
|
+
}
|
|
612
|
+
const errorBody = await response.json().catch(() => ({}));
|
|
613
|
+
const innerErrorCode = (0, import_guards6.isNonEmptyString)(errorBody.error?.innerError?.code) ? errorBody.error.innerError.code : void 0;
|
|
614
|
+
const message = (0, import_guards6.isNonEmptyString)(errorBody.error?.message) ? errorBody.error.message : response.statusText;
|
|
615
|
+
throw new GraphRequestError({
|
|
616
|
+
message: `Microsoft Graph request failed (${response.status}${(0, import_guards6.isNonEmptyString)(innerErrorCode) ? ` ${innerErrorCode}` : ""}): ${message}`,
|
|
617
|
+
status: response.status,
|
|
618
|
+
innerErrorCode
|
|
619
|
+
});
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
// src/features/transcripts/logic-functions/utils/fetch-graph-json.ts
|
|
623
|
+
var fetchGraphJson = async ({
|
|
624
|
+
accessToken,
|
|
625
|
+
url,
|
|
626
|
+
method,
|
|
627
|
+
body
|
|
628
|
+
}) => {
|
|
629
|
+
const response = await fetchGraphResponse({
|
|
630
|
+
accessToken,
|
|
631
|
+
url,
|
|
632
|
+
accept: "application/json",
|
|
633
|
+
method,
|
|
634
|
+
body
|
|
635
|
+
});
|
|
636
|
+
const responseBody = await response.json();
|
|
637
|
+
return responseBody;
|
|
638
|
+
};
|
|
639
|
+
|
|
640
|
+
// src/features/chat/logic-functions/utils/fetch-teams-tenant-id.ts
|
|
641
|
+
var fetchTeamsTenantId = async (accessToken) => {
|
|
642
|
+
const page = await fetchGraphJson({
|
|
643
|
+
accessToken,
|
|
644
|
+
url: "organization?$select=id"
|
|
645
|
+
});
|
|
646
|
+
const tenantId = page.value?.[0]?.id;
|
|
647
|
+
if (!(0, import_guards7.isNonEmptyString)(tenantId)) {
|
|
648
|
+
throw new Error("Microsoft Graph returned no organization to claim");
|
|
649
|
+
}
|
|
650
|
+
return tenantId;
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
// src/features/chat/constants/chat-enabled-application-variable-key.ts
|
|
654
|
+
var CHAT_ENABLED_APPLICATION_VARIABLE_KEY = "TEAMS_CHAT_ENABLED";
|
|
655
|
+
|
|
656
|
+
// src/features/chat/logic-functions/utils/is-teams-chat-enabled.ts
|
|
657
|
+
var isTeamsChatEnabled = () => process.env[CHAT_ENABLED_APPLICATION_VARIABLE_KEY] === "true";
|
|
658
|
+
|
|
659
|
+
// src/features/chat/logic-functions/utils/match-teams-directory-by-email.ts
|
|
660
|
+
var import_guards15 = __toESM(require_build());
|
|
661
|
+
import { CoreApiClient } from "twenty-client-sdk/core";
|
|
662
|
+
|
|
663
|
+
// src/features/chat/logic-functions/data/find-workspace-member-ids-by-emails.ts
|
|
664
|
+
var import_guards8 = __toESM(require_build());
|
|
665
|
+
|
|
666
|
+
// src/features/chat/logic-functions/utils/escape-sql-like-pattern.ts
|
|
667
|
+
var escapeSqlLikePattern = (value) => value.replace(/[\\%_]/g, (wildcard) => `\\${wildcard}`);
|
|
668
|
+
|
|
669
|
+
// src/features/chat/logic-functions/data/find-workspace-member-ids-by-emails.ts
|
|
670
|
+
var EMAILS_PER_QUERY = 50;
|
|
671
|
+
var MEMBERS_PER_PAGE = 200;
|
|
672
|
+
var MAX_PAGES_PER_QUERY = 5;
|
|
673
|
+
var findWorkspaceMemberIdsByEmails = async ({
|
|
674
|
+
client,
|
|
675
|
+
emails
|
|
676
|
+
}) => {
|
|
677
|
+
const lookedUpEmails = [
|
|
678
|
+
...new Set(emails.map((email) => email.toLowerCase()))
|
|
679
|
+
];
|
|
680
|
+
const workspaceMemberIdByEmail = /* @__PURE__ */ new Map();
|
|
681
|
+
const ambiguousEmails = /* @__PURE__ */ new Set();
|
|
682
|
+
for (let queryStart = 0; queryStart < lookedUpEmails.length; queryStart += EMAILS_PER_QUERY) {
|
|
683
|
+
const queriedEmails = lookedUpEmails.slice(
|
|
684
|
+
queryStart,
|
|
685
|
+
queryStart + EMAILS_PER_QUERY
|
|
686
|
+
);
|
|
687
|
+
let after;
|
|
688
|
+
for (let page = 0; page < MAX_PAGES_PER_QUERY; page += 1) {
|
|
689
|
+
const queryResult = await client.query({
|
|
690
|
+
workspaceMembers: {
|
|
691
|
+
__args: {
|
|
692
|
+
filter: {
|
|
693
|
+
or: queriedEmails.map((email) => ({
|
|
694
|
+
userEmail: { ilike: escapeSqlLikePattern(email) }
|
|
695
|
+
}))
|
|
696
|
+
},
|
|
697
|
+
first: MEMBERS_PER_PAGE,
|
|
698
|
+
...o(after) ? { after } : {}
|
|
699
|
+
},
|
|
700
|
+
edges: { node: { id: true, userEmail: true } },
|
|
701
|
+
pageInfo: { hasNextPage: true, endCursor: true }
|
|
702
|
+
}
|
|
703
|
+
});
|
|
704
|
+
for (const edge of queryResult.workspaceMembers?.edges ?? []) {
|
|
705
|
+
const node = edge?.node;
|
|
706
|
+
if (!(0, import_guards8.isNonEmptyString)(node?.id) || !(0, import_guards8.isNonEmptyString)(node.userEmail)) {
|
|
707
|
+
continue;
|
|
708
|
+
}
|
|
709
|
+
const email = node.userEmail.toLowerCase();
|
|
710
|
+
const alreadyMappedMemberId = workspaceMemberIdByEmail.get(email);
|
|
711
|
+
if (o(alreadyMappedMemberId) && alreadyMappedMemberId !== node.id) {
|
|
712
|
+
ambiguousEmails.add(email);
|
|
713
|
+
continue;
|
|
714
|
+
}
|
|
715
|
+
workspaceMemberIdByEmail.set(email, node.id);
|
|
716
|
+
}
|
|
717
|
+
const pageInfo = queryResult.workspaceMembers?.pageInfo;
|
|
718
|
+
if (!pageInfo?.hasNextPage || !(0, import_guards8.isNonEmptyString)(pageInfo.endCursor)) {
|
|
719
|
+
break;
|
|
720
|
+
}
|
|
721
|
+
after = pageInfo.endCursor;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
for (const ambiguousEmail of ambiguousEmails) {
|
|
725
|
+
workspaceMemberIdByEmail.delete(ambiguousEmail);
|
|
726
|
+
}
|
|
727
|
+
return {
|
|
728
|
+
workspaceMemberIdByEmail,
|
|
729
|
+
ambiguousEmailCount: ambiguousEmails.size
|
|
730
|
+
};
|
|
731
|
+
};
|
|
732
|
+
|
|
733
|
+
// src/features/chat/logic-functions/data/list-linked-teams-user-aad-object-ids.ts
|
|
734
|
+
var import_guards9 = __toESM(require_build());
|
|
735
|
+
var LINKS_PER_PAGE = 200;
|
|
736
|
+
var MAX_PAGES = 50;
|
|
737
|
+
var listLinkedTeamsUserAadObjectIdsOrThrow = async ({
|
|
738
|
+
client,
|
|
739
|
+
teamsTenantId
|
|
740
|
+
}) => {
|
|
741
|
+
const linkedAadObjectIds = /* @__PURE__ */ new Set();
|
|
742
|
+
let after;
|
|
743
|
+
for (let page = 0; page < MAX_PAGES; page += 1) {
|
|
744
|
+
const queryResult = await client.query({
|
|
745
|
+
teamsUserLinks: {
|
|
746
|
+
__args: {
|
|
747
|
+
filter: { teamsTenantId: { eq: teamsTenantId } },
|
|
748
|
+
first: LINKS_PER_PAGE,
|
|
749
|
+
...(0, import_guards9.isNonEmptyString)(after) ? { after } : {}
|
|
750
|
+
},
|
|
751
|
+
edges: { node: { teamsUserAadObjectId: true } },
|
|
752
|
+
pageInfo: { hasNextPage: true, endCursor: true }
|
|
753
|
+
}
|
|
754
|
+
});
|
|
755
|
+
for (const edge of queryResult.teamsUserLinks?.edges ?? []) {
|
|
756
|
+
const teamsUserAadObjectId = edge?.node?.teamsUserAadObjectId;
|
|
757
|
+
if ((0, import_guards9.isNonEmptyString)(teamsUserAadObjectId)) {
|
|
758
|
+
linkedAadObjectIds.add(teamsUserAadObjectId);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
const pageInfo = queryResult.teamsUserLinks?.pageInfo;
|
|
762
|
+
if (!pageInfo?.hasNextPage || !(0, import_guards9.isNonEmptyString)(pageInfo.endCursor)) {
|
|
763
|
+
return linkedAadObjectIds;
|
|
764
|
+
}
|
|
765
|
+
after = pageInfo.endCursor;
|
|
766
|
+
}
|
|
767
|
+
throw new Error(
|
|
768
|
+
`More than ${MAX_PAGES * LINKS_PER_PAGE} Teams user links exist for this tenant, so they cannot all be read at once. Use the search to link a specific person.`
|
|
769
|
+
);
|
|
770
|
+
};
|
|
771
|
+
|
|
772
|
+
// src/features/chat/logic-functions/utils/collect-graph-users.ts
|
|
773
|
+
var import_guards11 = __toESM(require_build());
|
|
774
|
+
|
|
775
|
+
// src/features/chat/logic-functions/utils/is-linkable-graph-user.ts
|
|
776
|
+
var import_guards10 = __toESM(require_build());
|
|
777
|
+
var isLinkableGraphUser = (user) => (0, import_guards10.isNonEmptyString)(user.id) && ((0, import_guards10.isNonEmptyString)(user.mail) || (0, import_guards10.isNonEmptyString)(user.userPrincipalName));
|
|
778
|
+
|
|
779
|
+
// src/features/chat/logic-functions/utils/collect-graph-users.ts
|
|
780
|
+
var DEFAULT_MAX_PAGES = 5;
|
|
781
|
+
var collectGraphUsers = async ({
|
|
782
|
+
accessToken,
|
|
783
|
+
url,
|
|
784
|
+
shouldCollectUser,
|
|
785
|
+
maxUsers,
|
|
786
|
+
maxPages = DEFAULT_MAX_PAGES
|
|
787
|
+
}) => {
|
|
788
|
+
const users = [];
|
|
789
|
+
const seenAadObjectIds = /* @__PURE__ */ new Set();
|
|
790
|
+
let nextUrl = url;
|
|
791
|
+
for (let page = 0; page < maxPages; page += 1) {
|
|
792
|
+
if (!(0, import_guards11.isNonEmptyString)(nextUrl)) {
|
|
793
|
+
return { users, isTruncated: false };
|
|
794
|
+
}
|
|
795
|
+
const pageResult = await fetchGraphJson({
|
|
796
|
+
accessToken,
|
|
797
|
+
url: nextUrl
|
|
798
|
+
});
|
|
799
|
+
const collectibleUsers = (pageResult.value ?? []).filter(isLinkableGraphUser).filter(
|
|
800
|
+
(user) => !o(shouldCollectUser) || shouldCollectUser(user)
|
|
801
|
+
);
|
|
802
|
+
nextUrl = pageResult["@odata.nextLink"];
|
|
803
|
+
for (const user of collectibleUsers) {
|
|
804
|
+
if (seenAadObjectIds.has(user.id)) {
|
|
805
|
+
continue;
|
|
806
|
+
}
|
|
807
|
+
if (o(maxUsers) && users.length >= maxUsers) {
|
|
808
|
+
return { users, isTruncated: true };
|
|
809
|
+
}
|
|
810
|
+
seenAadObjectIds.add(user.id);
|
|
811
|
+
users.push(user);
|
|
812
|
+
}
|
|
813
|
+
if (o(maxUsers) && users.length >= maxUsers) {
|
|
814
|
+
return { users, isTruncated: (0, import_guards11.isNonEmptyString)(nextUrl) };
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
return { users, isTruncated: (0, import_guards11.isNonEmptyString)(nextUrl) };
|
|
818
|
+
};
|
|
819
|
+
|
|
820
|
+
// src/features/chat/logic-functions/utils/get-teams-directory-user-email.ts
|
|
821
|
+
var import_guards12 = __toESM(require_build());
|
|
822
|
+
var GUEST_USER_PRINCIPAL_NAME_MARKER = "#EXT#";
|
|
823
|
+
var getTeamsDirectoryUserEmail = (user) => {
|
|
824
|
+
if ((0, import_guards12.isNonEmptyString)(user.userPrincipalName) && user.userPrincipalName.includes(GUEST_USER_PRINCIPAL_NAME_MARKER)) {
|
|
825
|
+
return void 0;
|
|
826
|
+
}
|
|
827
|
+
return [user.mail, user.userPrincipalName].find(import_guards12.isNonEmptyString);
|
|
828
|
+
};
|
|
829
|
+
|
|
830
|
+
// src/features/chat/logic-functions/utils/link-teams-directory-candidates.ts
|
|
831
|
+
var import_guards13 = __toESM(require_build());
|
|
832
|
+
|
|
833
|
+
// src/features/chat/logic-functions/constants/teams-user-link-source.ts
|
|
834
|
+
var TEAMS_USER_LINK_SOURCE = {
|
|
835
|
+
AUTO: "AUTO",
|
|
836
|
+
MANUAL: "MANUAL"
|
|
837
|
+
};
|
|
838
|
+
|
|
839
|
+
// src/features/chat/logic-functions/data/create-teams-user-link.ts
|
|
840
|
+
var createTeamsUserLink = async ({
|
|
841
|
+
client,
|
|
842
|
+
name,
|
|
843
|
+
teamsTenantId,
|
|
844
|
+
teamsUserAadObjectId,
|
|
845
|
+
workspaceMemberId,
|
|
846
|
+
source
|
|
847
|
+
}) => {
|
|
848
|
+
await client.mutation({
|
|
849
|
+
createTeamsUserLink: {
|
|
850
|
+
__args: {
|
|
851
|
+
data: {
|
|
852
|
+
name,
|
|
853
|
+
teamsTenantId,
|
|
854
|
+
teamsUserAadObjectId,
|
|
855
|
+
workspaceMemberId,
|
|
856
|
+
source
|
|
857
|
+
}
|
|
858
|
+
},
|
|
859
|
+
id: true
|
|
860
|
+
}
|
|
861
|
+
});
|
|
862
|
+
};
|
|
863
|
+
|
|
864
|
+
// src/features/chat/logic-functions/data/create-teams-user-links.ts
|
|
865
|
+
var createTeamsUserLinks = async ({
|
|
866
|
+
client,
|
|
867
|
+
drafts
|
|
868
|
+
}) => {
|
|
869
|
+
await client.mutation({
|
|
870
|
+
createTeamsUserLinks: {
|
|
871
|
+
__args: { data: drafts },
|
|
872
|
+
id: true
|
|
873
|
+
}
|
|
874
|
+
});
|
|
875
|
+
};
|
|
876
|
+
|
|
877
|
+
// src/features/chat/logic-functions/utils/is-duplicate-record-error.ts
|
|
878
|
+
var DUPLICATE_RECORD_MESSAGE_PATTERN = /duplicate (entry|key)/i;
|
|
879
|
+
var isDuplicateRecordError = (error) => error instanceof Error && DUPLICATE_RECORD_MESSAGE_PATTERN.test(error.message);
|
|
880
|
+
|
|
881
|
+
// src/utils/to-error-message.ts
|
|
882
|
+
var toErrorMessage = (error) => error instanceof Error ? error.message : String(error);
|
|
883
|
+
|
|
884
|
+
// src/features/chat/logic-functions/utils/link-teams-directory-candidates.ts
|
|
885
|
+
var LINKS_PER_BATCH = 200;
|
|
886
|
+
var MAX_ONE_BY_ONE_RETRIES = LINKS_PER_BATCH;
|
|
887
|
+
var toTeamsUserLinkDraft = ({
|
|
888
|
+
candidate,
|
|
889
|
+
teamsTenantId
|
|
890
|
+
}) => ({
|
|
891
|
+
teamsTenantId,
|
|
892
|
+
teamsUserAadObjectId: candidate.teamsUserAadObjectId,
|
|
893
|
+
workspaceMemberId: candidate.workspaceMemberId,
|
|
894
|
+
name: (0, import_guards13.isNonEmptyString)(candidate.displayName) ? candidate.displayName : candidate.teamsUserAadObjectId,
|
|
895
|
+
source: TEAMS_USER_LINK_SOURCE.AUTO
|
|
896
|
+
});
|
|
897
|
+
var createCandidatesOneByOne = async ({
|
|
898
|
+
client,
|
|
899
|
+
candidates,
|
|
900
|
+
teamsTenantId
|
|
901
|
+
}) => {
|
|
902
|
+
let linkedCount = 0;
|
|
903
|
+
for (const candidate of candidates) {
|
|
904
|
+
try {
|
|
905
|
+
await createTeamsUserLink({
|
|
906
|
+
client,
|
|
907
|
+
...toTeamsUserLinkDraft({ candidate, teamsTenantId })
|
|
908
|
+
});
|
|
909
|
+
linkedCount += 1;
|
|
910
|
+
} catch (error) {
|
|
911
|
+
if (isDuplicateRecordError(error)) {
|
|
912
|
+
linkedCount += 1;
|
|
913
|
+
continue;
|
|
914
|
+
}
|
|
915
|
+
console.warn(
|
|
916
|
+
`[teams] directory match could not link ${candidate.teamsUserAadObjectId}: ${toErrorMessage(error)}`
|
|
917
|
+
);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
return { linkedCount, failedCount: candidates.length - linkedCount };
|
|
921
|
+
};
|
|
922
|
+
var linkTeamsDirectoryCandidates = async ({
|
|
923
|
+
client,
|
|
924
|
+
candidates,
|
|
925
|
+
teamsTenantId
|
|
926
|
+
}) => {
|
|
927
|
+
const outcome = { linkedCount: 0, failedCount: 0 };
|
|
928
|
+
let remainingOneByOneRetries = MAX_ONE_BY_ONE_RETRIES;
|
|
929
|
+
for (let batchStart = 0; batchStart < candidates.length; batchStart += LINKS_PER_BATCH) {
|
|
930
|
+
const batchCandidates = candidates.slice(
|
|
931
|
+
batchStart,
|
|
932
|
+
batchStart + LINKS_PER_BATCH
|
|
933
|
+
);
|
|
934
|
+
try {
|
|
935
|
+
await createTeamsUserLinks({
|
|
936
|
+
client,
|
|
937
|
+
drafts: batchCandidates.map(
|
|
938
|
+
(candidate) => toTeamsUserLinkDraft({ candidate, teamsTenantId })
|
|
939
|
+
)
|
|
940
|
+
});
|
|
941
|
+
outcome.linkedCount += batchCandidates.length;
|
|
942
|
+
continue;
|
|
943
|
+
} catch (error) {
|
|
944
|
+
console.warn(
|
|
945
|
+
`[teams] directory match batch of ${batchCandidates.length} failed: ${toErrorMessage(error)}`
|
|
946
|
+
);
|
|
947
|
+
}
|
|
948
|
+
if (remainingOneByOneRetries < batchCandidates.length) {
|
|
949
|
+
outcome.failedCount += batchCandidates.length;
|
|
950
|
+
continue;
|
|
951
|
+
}
|
|
952
|
+
remainingOneByOneRetries -= batchCandidates.length;
|
|
953
|
+
const retryOutcome = await createCandidatesOneByOne({
|
|
954
|
+
client,
|
|
955
|
+
candidates: batchCandidates,
|
|
956
|
+
teamsTenantId
|
|
957
|
+
});
|
|
958
|
+
outcome.linkedCount += retryOutcome.linkedCount;
|
|
959
|
+
outcome.failedCount += retryOutcome.failedCount;
|
|
960
|
+
}
|
|
961
|
+
return outcome;
|
|
962
|
+
};
|
|
963
|
+
|
|
964
|
+
// src/features/chat/logic-functions/utils/plan-teams-directory-match.ts
|
|
965
|
+
var import_guards14 = __toESM(require_build());
|
|
966
|
+
var planDirectoryUser = ({
|
|
967
|
+
user,
|
|
968
|
+
workspaceMemberIdByEmail,
|
|
969
|
+
linkedAadObjectIds
|
|
970
|
+
}) => {
|
|
971
|
+
if (linkedAadObjectIds.has(user.id)) {
|
|
972
|
+
return { status: "alreadyLinked" };
|
|
973
|
+
}
|
|
974
|
+
const email = getTeamsDirectoryUserEmail(user);
|
|
975
|
+
const workspaceMemberId = (0, import_guards14.isNonEmptyString)(email) ? workspaceMemberIdByEmail.get(email.toLowerCase()) : void 0;
|
|
976
|
+
if (!o(workspaceMemberId)) {
|
|
977
|
+
return { status: "unmatched" };
|
|
978
|
+
}
|
|
979
|
+
return {
|
|
980
|
+
status: "candidate",
|
|
981
|
+
candidate: {
|
|
982
|
+
teamsUserAadObjectId: user.id,
|
|
983
|
+
workspaceMemberId,
|
|
984
|
+
displayName: (0, import_guards14.isNonEmptyString)(user.displayName) ? user.displayName : void 0
|
|
985
|
+
}
|
|
986
|
+
};
|
|
987
|
+
};
|
|
988
|
+
var planTeamsDirectoryMatch = ({
|
|
989
|
+
users,
|
|
990
|
+
workspaceMemberIdByEmail,
|
|
991
|
+
linkedAadObjectIds
|
|
992
|
+
}) => {
|
|
993
|
+
const plannedUsers = users.map(
|
|
994
|
+
(user) => planDirectoryUser({ user, workspaceMemberIdByEmail, linkedAadObjectIds })
|
|
995
|
+
);
|
|
996
|
+
return {
|
|
997
|
+
candidates: plannedUsers.flatMap(
|
|
998
|
+
(plannedUser) => plannedUser.status === "candidate" ? [plannedUser.candidate] : []
|
|
999
|
+
),
|
|
1000
|
+
alreadyLinkedCount: plannedUsers.filter(
|
|
1001
|
+
(plannedUser) => plannedUser.status === "alreadyLinked"
|
|
1002
|
+
).length,
|
|
1003
|
+
unmatchedCount: plannedUsers.filter(
|
|
1004
|
+
(plannedUser) => plannedUser.status === "unmatched"
|
|
1005
|
+
).length
|
|
1006
|
+
};
|
|
1007
|
+
};
|
|
1008
|
+
|
|
1009
|
+
// src/features/chat/logic-functions/constants/teams-directory-match-run-outcome-kv-key.ts
|
|
1010
|
+
var TEAMS_DIRECTORY_MATCH_RUN_OUTCOME_KV_KEY = "teams-directory-match-run-outcome";
|
|
1011
|
+
|
|
1012
|
+
// src/features/chat/logic-functions/utils/save-teams-directory-match-run-outcome.ts
|
|
1013
|
+
var saveTeamsDirectoryMatchRunOutcome = async (outcome) => {
|
|
1014
|
+
try {
|
|
1015
|
+
await ge.set(TEAMS_DIRECTORY_MATCH_RUN_OUTCOME_KV_KEY, outcome);
|
|
1016
|
+
} catch (error) {
|
|
1017
|
+
console.warn(
|
|
1018
|
+
`[teams] failed to record the directory match outcome: ${toErrorMessage(error)}`
|
|
1019
|
+
);
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
1022
|
+
|
|
1023
|
+
// src/features/chat/logic-functions/utils/match-teams-directory-by-email.ts
|
|
1024
|
+
var DIRECTORY_GRAPH_URL = "users?$select=id,displayName,mail,userPrincipalName&$top=999";
|
|
1025
|
+
var DIRECTORY_MAX_PAGES = 10;
|
|
1026
|
+
var INTERRUPTED_RUN_OUTCOME = {
|
|
1027
|
+
isSuccessful: false,
|
|
1028
|
+
errorMessage: "The directory match was interrupted before it finished."
|
|
1029
|
+
};
|
|
1030
|
+
var runTeamsDirectoryMatch = async ({
|
|
1031
|
+
accessToken,
|
|
1032
|
+
teamsTenantId
|
|
1033
|
+
}) => {
|
|
1034
|
+
const client = new CoreApiClient({ runAs: "application" });
|
|
1035
|
+
const [linkedAadObjectIds, directory] = await Promise.all([
|
|
1036
|
+
listLinkedTeamsUserAadObjectIdsOrThrow({ client, teamsTenantId }),
|
|
1037
|
+
collectGraphUsers({
|
|
1038
|
+
accessToken,
|
|
1039
|
+
url: DIRECTORY_GRAPH_URL,
|
|
1040
|
+
maxPages: DIRECTORY_MAX_PAGES
|
|
1041
|
+
})
|
|
1042
|
+
]);
|
|
1043
|
+
const { workspaceMemberIdByEmail, ambiguousEmailCount } = await findWorkspaceMemberIdsByEmails({
|
|
1044
|
+
client,
|
|
1045
|
+
emails: directory.users.map(getTeamsDirectoryUserEmail).filter(import_guards15.isNonEmptyString)
|
|
1046
|
+
});
|
|
1047
|
+
const { candidates, alreadyLinkedCount, unmatchedCount } = planTeamsDirectoryMatch({
|
|
1048
|
+
users: directory.users,
|
|
1049
|
+
workspaceMemberIdByEmail,
|
|
1050
|
+
linkedAadObjectIds
|
|
1051
|
+
});
|
|
1052
|
+
const { linkedCount, failedCount } = await linkTeamsDirectoryCandidates({
|
|
1053
|
+
client,
|
|
1054
|
+
candidates,
|
|
1055
|
+
teamsTenantId
|
|
1056
|
+
});
|
|
1057
|
+
return {
|
|
1058
|
+
linkedCount,
|
|
1059
|
+
alreadyLinkedCount,
|
|
1060
|
+
unmatchedCount,
|
|
1061
|
+
ambiguousEmailCount,
|
|
1062
|
+
failedCount,
|
|
1063
|
+
isDirectoryTruncated: directory.isTruncated
|
|
1064
|
+
};
|
|
1065
|
+
};
|
|
1066
|
+
var matchTeamsDirectoryByEmail = async ({
|
|
1067
|
+
accessToken,
|
|
1068
|
+
teamsTenantId
|
|
1069
|
+
}) => {
|
|
1070
|
+
await saveTeamsDirectoryMatchRunOutcome(INTERRUPTED_RUN_OUTCOME);
|
|
1071
|
+
try {
|
|
1072
|
+
const summary = await runTeamsDirectoryMatch({
|
|
1073
|
+
accessToken,
|
|
1074
|
+
teamsTenantId
|
|
1075
|
+
});
|
|
1076
|
+
await saveTeamsDirectoryMatchRunOutcome({
|
|
1077
|
+
isSuccessful: summary.failedCount === 0
|
|
1078
|
+
});
|
|
1079
|
+
return summary;
|
|
1080
|
+
} catch (error) {
|
|
1081
|
+
await saveTeamsDirectoryMatchRunOutcome({
|
|
1082
|
+
isSuccessful: false,
|
|
1083
|
+
errorMessage: toErrorMessage(error)
|
|
1084
|
+
});
|
|
1085
|
+
throw error;
|
|
1086
|
+
}
|
|
1087
|
+
};
|
|
1088
|
+
|
|
1089
|
+
// src/features/chat/logic-functions/utils/release-teams-connection-tenant.ts
|
|
1090
|
+
var import_guards16 = __toESM(require_build());
|
|
1091
|
+
|
|
1092
|
+
// src/features/transcripts/constants/teams-provider-name.ts
|
|
1093
|
+
var TEAMS_PROVIDER_NAME = "microsoft-teams";
|
|
1094
|
+
|
|
1095
|
+
// src/features/transcripts/constants/teams-user-provider-name.ts
|
|
1096
|
+
var TEAMS_USER_PROVIDER_NAME = "microsoft-teams-user";
|
|
1097
|
+
|
|
1098
|
+
// src/features/transcripts/constants/teams-provider-names.ts
|
|
1099
|
+
var TEAMS_PROVIDER_NAMES = [
|
|
1100
|
+
TEAMS_PROVIDER_NAME,
|
|
1101
|
+
TEAMS_USER_PROVIDER_NAME
|
|
1102
|
+
];
|
|
1103
|
+
|
|
1104
|
+
// src/features/transcripts/logic-functions/utils/list-teams-connections.ts
|
|
1105
|
+
var listTeamsConnections = async () => (await w()).filter(
|
|
1106
|
+
(connection) => TEAMS_PROVIDER_NAMES.includes(connection.providerName)
|
|
1107
|
+
);
|
|
1108
|
+
|
|
1109
|
+
// src/features/chat/logic-functions/utils/release-teams-connection-tenant.ts
|
|
1110
|
+
var listTeamsConnectionIds = async () => (await listTeamsConnections()).map((connection) => connection.id);
|
|
1111
|
+
var isTenantHeldByConnections = async ({
|
|
1112
|
+
tenantId,
|
|
1113
|
+
connectionIds
|
|
1114
|
+
}) => {
|
|
1115
|
+
const claimedTenantIds = await Promise.all(
|
|
1116
|
+
connectionIds.map(
|
|
1117
|
+
(connectionId) => ge.get(buildTeamsConnectedAccountTenantKvKey(connectionId))
|
|
1118
|
+
)
|
|
1119
|
+
);
|
|
1120
|
+
return claimedTenantIds.includes(tenantId);
|
|
1121
|
+
};
|
|
1122
|
+
var releaseTeamsConnectionTenant = async ({
|
|
1123
|
+
connectedAccountId
|
|
1124
|
+
}) => {
|
|
1125
|
+
const connectedAccountTenantKvKey = buildTeamsConnectedAccountTenantKvKey(connectedAccountId);
|
|
1126
|
+
const tenantId = await ge.get(connectedAccountTenantKvKey);
|
|
1127
|
+
if (!(0, import_guards16.isNonEmptyString)(tenantId)) {
|
|
1128
|
+
return { releasedTenantId: null };
|
|
1129
|
+
}
|
|
1130
|
+
const connectionIds = await listTeamsConnectionIds();
|
|
1131
|
+
await ge.delete(connectedAccountTenantKvKey);
|
|
1132
|
+
const isTenantHeldElsewhere = await isTenantHeldByConnections({
|
|
1133
|
+
tenantId,
|
|
1134
|
+
connectionIds
|
|
1135
|
+
}).catch(async (error) => {
|
|
1136
|
+
await ge.set(connectedAccountTenantKvKey, tenantId);
|
|
1137
|
+
throw error;
|
|
1138
|
+
});
|
|
1139
|
+
if (isTenantHeldElsewhere) {
|
|
1140
|
+
return { releasedTenantId: null };
|
|
1141
|
+
}
|
|
1142
|
+
const tenantKvKey = buildTeamsTenantKvKey(tenantId);
|
|
1143
|
+
const hasReleasedTenant = await ge.delete(tenantKvKey, { scope: "SERVER" });
|
|
1144
|
+
if (await isTenantHeldByConnections({
|
|
1145
|
+
tenantId,
|
|
1146
|
+
connectionIds: await listTeamsConnectionIds()
|
|
1147
|
+
})) {
|
|
1148
|
+
await ge.set(tenantKvKey, null, { scope: "SERVER" });
|
|
1149
|
+
return { releasedTenantId: null };
|
|
1150
|
+
}
|
|
1151
|
+
return { releasedTenantId: hasReleasedTenant ? tenantId : null };
|
|
1152
|
+
};
|
|
1153
|
+
|
|
1154
|
+
// src/features/transcripts/constants/teams-oauth-config.ts
|
|
1155
|
+
var TEAMS_GRAPH_DIRECTORY_SCOPE = "https://graph.microsoft.com/User.ReadBasic.All";
|
|
1156
|
+
|
|
1157
|
+
// src/utils/get-connection-access-token-or-throw.ts
|
|
1158
|
+
var getConnectionAccessTokenOrThrow = (connection) => {
|
|
1159
|
+
if (!o(connection.accessToken)) {
|
|
1160
|
+
throw new Error(`Connection ${connection.id} has no access token`);
|
|
1161
|
+
}
|
|
1162
|
+
return connection.accessToken;
|
|
1163
|
+
};
|
|
1164
|
+
|
|
1165
|
+
// src/features/chat/logic-functions/utils/register-teams-connection.ts
|
|
1166
|
+
var matchTeamsDirectoryOnConnect = async ({
|
|
1167
|
+
connection,
|
|
1168
|
+
accessToken,
|
|
1169
|
+
tenantId
|
|
1170
|
+
}) => {
|
|
1171
|
+
if (!connection.scopes.includes(TEAMS_GRAPH_DIRECTORY_SCOPE)) {
|
|
1172
|
+
console.warn(
|
|
1173
|
+
"[teams] directory email match skipped: the connection cannot read the organization directory"
|
|
1174
|
+
);
|
|
1175
|
+
return;
|
|
1176
|
+
}
|
|
1177
|
+
try {
|
|
1178
|
+
await matchTeamsDirectoryByEmail({ accessToken, teamsTenantId: tenantId });
|
|
1179
|
+
} catch (error) {
|
|
1180
|
+
console.warn(
|
|
1181
|
+
`[teams] directory email match skipped: ${toErrorMessage(error)}`
|
|
1182
|
+
);
|
|
1183
|
+
}
|
|
1184
|
+
};
|
|
1185
|
+
var registerTeamsConnection = async ({
|
|
1186
|
+
connectedAccountId,
|
|
1187
|
+
workspaceId,
|
|
1188
|
+
shouldMatchDirectory = true
|
|
1189
|
+
}) => {
|
|
1190
|
+
const connection = await x(connectedAccountId);
|
|
1191
|
+
if (connection?.scope !== "WORKSPACE") {
|
|
1192
|
+
await releaseTeamsConnectionTenant({ connectedAccountId });
|
|
1193
|
+
await deleteTeamsTenantClaimConflict({ connectedAccountId });
|
|
1194
|
+
return { claimedTenantId: null };
|
|
1195
|
+
}
|
|
1196
|
+
const accessToken = getConnectionAccessTokenOrThrow(connection);
|
|
1197
|
+
const tenantId = await fetchTeamsTenantId(accessToken);
|
|
1198
|
+
const connectedAccountTenantKvKey = buildTeamsConnectedAccountTenantKvKey(connectedAccountId);
|
|
1199
|
+
const previousTenantId = await ge.get(connectedAccountTenantKvKey);
|
|
1200
|
+
if ((0, import_guards17.isNonEmptyString)(previousTenantId) && previousTenantId !== tenantId) {
|
|
1201
|
+
await releaseTeamsConnectionTenant({ connectedAccountId });
|
|
1202
|
+
}
|
|
1203
|
+
await ge.set(connectedAccountTenantKvKey, tenantId);
|
|
1204
|
+
const isTenantClaimed = await claimTeamsTenant({ tenantId, workspaceId });
|
|
1205
|
+
if (!isTenantClaimed) {
|
|
1206
|
+
await ge.delete(connectedAccountTenantKvKey);
|
|
1207
|
+
await ge.set(
|
|
1208
|
+
buildTeamsTenantClaimConflictKvKey(connectedAccountId),
|
|
1209
|
+
{ tenantId }
|
|
1210
|
+
);
|
|
1211
|
+
return { claimedTenantId: null, conflictingTenantId: tenantId };
|
|
1212
|
+
}
|
|
1213
|
+
await deleteTeamsTenantClaimConflict({ connectedAccountId });
|
|
1214
|
+
if (shouldMatchDirectory && isTeamsChatEnabled()) {
|
|
1215
|
+
await matchTeamsDirectoryOnConnect({ connection, accessToken, tenantId });
|
|
1216
|
+
}
|
|
1217
|
+
return { claimedTenantId: tenantId };
|
|
1218
|
+
};
|
|
1219
|
+
|
|
1220
|
+
// src/features/chat/logic-functions/utils/claim-teams-tenants-of-existing-connections.ts
|
|
1221
|
+
var claimTeamsTenantsOfExistingConnections = async () => {
|
|
1222
|
+
const connections = (await listTeamsConnections()).filter(
|
|
1223
|
+
isWorkingTeamsWorkspaceConnection
|
|
1224
|
+
);
|
|
1225
|
+
const result = {
|
|
1226
|
+
claimedConnectionCount: 0,
|
|
1227
|
+
conflictingConnectionCount: 0,
|
|
1228
|
+
failedConnectionCount: 0
|
|
1229
|
+
};
|
|
1230
|
+
if (connections.length === 0) {
|
|
1231
|
+
return result;
|
|
1232
|
+
}
|
|
1233
|
+
const workspaceId = await fetchCurrentWorkspaceIdOrThrow();
|
|
1234
|
+
for (const connection of connections) {
|
|
1235
|
+
try {
|
|
1236
|
+
const { claimedTenantId, conflictingTenantId } = await registerTeamsConnection({
|
|
1237
|
+
connectedAccountId: connection.id,
|
|
1238
|
+
workspaceId,
|
|
1239
|
+
shouldMatchDirectory: false
|
|
1240
|
+
});
|
|
1241
|
+
if ((0, import_guards18.isNonEmptyString)(claimedTenantId)) {
|
|
1242
|
+
result.claimedConnectionCount += 1;
|
|
1243
|
+
}
|
|
1244
|
+
if ((0, import_guards18.isNonEmptyString)(conflictingTenantId)) {
|
|
1245
|
+
result.conflictingConnectionCount += 1;
|
|
1246
|
+
}
|
|
1247
|
+
} catch (error) {
|
|
1248
|
+
result.failedConnectionCount += 1;
|
|
1249
|
+
console.warn(
|
|
1250
|
+
`[teams] could not claim the tenant of connection ${connection.id}: ${toErrorMessage(error)}`
|
|
1251
|
+
);
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
return result;
|
|
1255
|
+
};
|
|
1256
|
+
|
|
1257
|
+
// src/logic-functions/teams-post-install.ts
|
|
1258
|
+
var teams_post_install_default = definePostInstallLogicFunction({
|
|
1259
|
+
universalIdentifier: POST_INSTALL_UNIVERSAL_IDENTIFIER,
|
|
1260
|
+
name: "teams-post-install",
|
|
1261
|
+
description: "Runs when the app is installed or upgraded. Claims the Microsoft tenant of every working workspace-shared connection for this workspace, so connections added before chat existed route their Teams messages here without being removed and added again.",
|
|
1262
|
+
timeoutSeconds: 120,
|
|
1263
|
+
shouldRunOnVersionUpgrade: true,
|
|
1264
|
+
shouldRunSynchronously: false,
|
|
1265
|
+
handler: claimTeamsTenantsOfExistingConnections
|
|
1266
|
+
});
|
|
1267
|
+
export {
|
|
1268
|
+
teams_post_install_default as default
|
|
1269
|
+
};
|
|
1270
|
+
//# sourceMappingURL=teams-post-install.mjs.map
|