@effect/chat-teams 0.0.0 → 4.1.6
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/AGENTS.md +434 -0
- package/CLAUDE.md +434 -0
- package/LICENSE +21 -0
- package/README.md +116 -0
- package/ai-docs/README.md +44 -0
- package/ai-docs/package.json +36 -0
- package/ai-docs/src/01_effect/01_basics/01_effect-gen.ts +30 -0
- package/ai-docs/src/01_effect/01_basics/02_effect-fn.ts +52 -0
- package/ai-docs/src/01_effect/01_basics/10_creating-effects.ts +74 -0
- package/ai-docs/src/01_effect/01_basics/index.md +7 -0
- package/ai-docs/src/01_effect/02_schema/10_schema-basics.ts +43 -0
- package/ai-docs/src/01_effect/02_schema/index.md +7 -0
- package/ai-docs/src/01_effect/03_services/01_service.ts +45 -0
- package/ai-docs/src/01_effect/03_services/10_reference.ts +10 -0
- package/ai-docs/src/01_effect/03_services/20_layer-composition.ts +70 -0
- package/ai-docs/src/01_effect/03_services/20_layer-unwrap.ts +66 -0
- package/ai-docs/src/01_effect/03_services/index.md +5 -0
- package/ai-docs/src/01_effect/04_errors/01_error-handling.ts +30 -0
- package/ai-docs/src/01_effect/04_errors/10_catch-tags.ts +24 -0
- package/ai-docs/src/01_effect/04_errors/20_reason-errors.ts +64 -0
- package/ai-docs/src/01_effect/04_errors/index.md +1 -0
- package/ai-docs/src/01_effect/05_resources/10_acquire-release.ts +105 -0
- package/ai-docs/src/01_effect/05_resources/20_layer-side-effects.ts +31 -0
- package/ai-docs/src/01_effect/05_resources/30_layer-map.ts +86 -0
- package/ai-docs/src/01_effect/05_resources/index.md +3 -0
- package/ai-docs/src/01_effect/06_running/10_run-main.ts +30 -0
- package/ai-docs/src/01_effect/06_running/20_layer-launch.ts +27 -0
- package/ai-docs/src/01_effect/06_running/index.md +1 -0
- package/ai-docs/src/01_effect/07_pubsub/10_pubsub.ts +56 -0
- package/ai-docs/src/01_effect/07_pubsub/index.md +3 -0
- package/ai-docs/src/03_stream/10_creating-streams.ts +103 -0
- package/ai-docs/src/03_stream/20_consuming-streams.ts +137 -0
- package/ai-docs/src/03_stream/30_encoding.ts +163 -0
- package/ai-docs/src/03_stream/index.md +4 -0
- package/ai-docs/src/04_integration/10_managed-runtime.ts +129 -0
- package/ai-docs/src/04_integration/index.md +5 -0
- package/ai-docs/src/05_batching/10_request-resolver.ts +89 -0
- package/ai-docs/src/05_batching/index.md +3 -0
- package/ai-docs/src/06_schedule/10_schedules.ts +111 -0
- package/ai-docs/src/06_schedule/index.md +3 -0
- package/ai-docs/src/07_datetime/10_creating-and-formatting.ts +30 -0
- package/ai-docs/src/07_datetime/20_time-zones.ts +44 -0
- package/ai-docs/src/07_datetime/index.md +5 -0
- package/ai-docs/src/08_observability/10_logging.ts +66 -0
- package/ai-docs/src/08_observability/20_otlp-tracing.ts +95 -0
- package/ai-docs/src/08_observability/index.md +7 -0
- package/ai-docs/src/09_testing/10_effect-tests.ts +55 -0
- package/ai-docs/src/09_testing/20_layer-tests.ts +138 -0
- package/ai-docs/src/09_testing/index.md +1 -0
- package/ai-docs/src/10_predicate/01_basics.ts +14 -0
- package/ai-docs/src/10_predicate/index.md +9 -0
- package/ai-docs/src/40_sql/10_basics.ts +175 -0
- package/ai-docs/src/40_sql/index.md +6 -0
- package/ai-docs/src/50_http-client/10_basics.ts +102 -0
- package/ai-docs/src/50_http-client/index.md +3 -0
- package/ai-docs/src/51_http-server/10_basics.ts +118 -0
- package/ai-docs/src/51_http-server/20_testing.ts +100 -0
- package/ai-docs/src/51_http-server/fixtures/api/Api.ts +14 -0
- package/ai-docs/src/51_http-server/fixtures/api/Authorization.ts +36 -0
- package/ai-docs/src/51_http-server/fixtures/api/System.ts +10 -0
- package/ai-docs/src/51_http-server/fixtures/api/Users.ts +107 -0
- package/ai-docs/src/51_http-server/fixtures/domain/User.ts +21 -0
- package/ai-docs/src/51_http-server/fixtures/domain/UserErrors.ts +22 -0
- package/ai-docs/src/51_http-server/fixtures/server/Authorization.ts +37 -0
- package/ai-docs/src/51_http-server/fixtures/server/Users/http.ts +80 -0
- package/ai-docs/src/51_http-server/fixtures/server/Users.ts +183 -0
- package/ai-docs/src/51_http-server/index.md +3 -0
- package/ai-docs/src/52_graphql/10_basics.ts +117 -0
- package/ai-docs/src/52_graphql/20_testing.ts +45 -0
- package/ai-docs/src/52_graphql/30_batching.ts +118 -0
- package/ai-docs/src/52_graphql/40_aliased-batching.ts +124 -0
- package/ai-docs/src/52_graphql/50_errors-and-retries.ts +74 -0
- package/ai-docs/src/52_graphql/index.md +6 -0
- package/ai-docs/src/60_child-process/10_working-with-child-processes.ts +117 -0
- package/ai-docs/src/60_child-process/index.md +3 -0
- package/ai-docs/src/70_cli/10_basics.ts +162 -0
- package/ai-docs/src/70_cli/index.md +5 -0
- package/ai-docs/src/71_ai/10_language-model.ts +156 -0
- package/ai-docs/src/71_ai/20_tools.ts +226 -0
- package/ai-docs/src/71_ai/30_chat.ts +158 -0
- package/ai-docs/src/71_ai/fixtures/domain/LaunchPlan.ts +9 -0
- package/ai-docs/src/71_ai/index.md +5 -0
- package/ai-docs/src/80_cluster/10_entities.ts +97 -0
- package/ai-docs/src/80_cluster/index.md +4 -0
- package/ai-docs/src/index.md +10 -0
- package/ai-docs/tsconfig.json +28 -0
- package/dist/TeamsChat.d.ts +318 -0
- package/dist/TeamsChat.d.ts.map +1 -0
- package/dist/TeamsChat.js +316 -0
- package/dist/TeamsChat.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/adapter.d.ts +2 -0
- package/dist/internal/adapter.d.ts.map +1 -0
- package/dist/internal/adapter.js +300 -0
- package/dist/internal/adapter.js.map +1 -0
- package/dist/internal/address.d.ts +2 -0
- package/dist/internal/address.d.ts.map +1 -0
- package/dist/internal/address.js +52 -0
- package/dist/internal/address.js.map +1 -0
- package/dist/internal/auth.d.ts +2 -0
- package/dist/internal/auth.d.ts.map +1 -0
- package/dist/internal/auth.js +142 -0
- package/dist/internal/auth.js.map +1 -0
- package/dist/internal/connector.d.ts +2 -0
- package/dist/internal/connector.d.ts.map +1 -0
- package/dist/internal/connector.js +173 -0
- package/dist/internal/connector.js.map +1 -0
- package/dist/internal/download.d.ts +5 -0
- package/dist/internal/download.d.ts.map +1 -0
- package/dist/internal/download.js +183 -0
- package/dist/internal/download.js.map +1 -0
- package/dist/internal/envelope.d.ts +2 -0
- package/dist/internal/envelope.d.ts.map +1 -0
- package/dist/internal/envelope.js +337 -0
- package/dist/internal/envelope.js.map +1 -0
- package/dist/internal/errors.d.ts +2 -0
- package/dist/internal/errors.d.ts.map +1 -0
- package/dist/internal/errors.js +113 -0
- package/dist/internal/errors.js.map +1 -0
- package/dist/internal/interactions.d.ts +2 -0
- package/dist/internal/interactions.d.ts.map +1 -0
- package/dist/internal/interactions.js +288 -0
- package/dist/internal/interactions.js.map +1 -0
- package/dist/internal/length.d.ts +2 -0
- package/dist/internal/length.d.ts.map +1 -0
- package/dist/internal/length.js +147 -0
- package/dist/internal/length.js.map +1 -0
- package/dist/internal/normalize.d.ts +2 -0
- package/dist/internal/normalize.d.ts.map +1 -0
- package/dist/internal/normalize.js +224 -0
- package/dist/internal/normalize.js.map +1 -0
- package/dist/internal/parse.d.ts +2 -0
- package/dist/internal/parse.d.ts.map +1 -0
- package/dist/internal/parse.js +33 -0
- package/dist/internal/parse.js.map +1 -0
- package/dist/internal/render.d.ts +2 -0
- package/dist/internal/render.d.ts.map +1 -0
- package/dist/internal/render.js +316 -0
- package/dist/internal/render.js.map +1 -0
- package/dist/internal/webhook.d.ts +2 -0
- package/dist/internal/webhook.d.ts.map +1 -0
- package/dist/internal/webhook.js +88 -0
- package/dist/internal/webhook.js.map +1 -0
- package/package.json +61 -1
- package/src/TeamsChat.ts +470 -0
- package/src/index.ts +12 -0
- package/src/internal/adapter.ts +351 -0
- package/src/internal/address.ts +67 -0
- package/src/internal/auth.ts +192 -0
- package/src/internal/connector.ts +253 -0
- package/src/internal/download.ts +277 -0
- package/src/internal/envelope.ts +427 -0
- package/src/internal/errors.ts +94 -0
- package/src/internal/interactions.ts +294 -0
- package/src/internal/length.ts +170 -0
- package/src/internal/normalize.ts +232 -0
- package/src/internal/parse.ts +41 -0
- package/src/internal/render.ts +318 -0
- package/src/internal/webhook.ts +117 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { retrySafe } from "effect/chat/ChatAdapter";
|
|
2
|
+
import * as Clock from "effect/Clock";
|
|
3
|
+
import * as DateTime from "effect/DateTime";
|
|
4
|
+
import * as Duration from "effect/Duration";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
7
|
+
import * as HttpClient from "effect/http/HttpClient";
|
|
8
|
+
import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
|
9
|
+
import * as Option from "effect/Option";
|
|
10
|
+
import * as Predicate from "effect/Predicate";
|
|
11
|
+
import * as Redacted from "effect/Redacted";
|
|
12
|
+
import * as Semaphore from "effect/Semaphore";
|
|
13
|
+
import * as Errors from "./errors.js";
|
|
14
|
+
import { parseUrl } from "./parse.js";
|
|
15
|
+
/** A cloud is privileged configuration: nothing in it is ever read from an activity. @internal */
|
|
16
|
+
export const publicCloud = {
|
|
17
|
+
connectorUrl: "https://smba.trafficmanager.net/teams",
|
|
18
|
+
connectorHosts: ["smba.trafficmanager.net"],
|
|
19
|
+
openIdMetadataUrl: "https://login.botframework.com/v1/.well-known/openidconfiguration",
|
|
20
|
+
issuer: "https://api.botframework.com",
|
|
21
|
+
loginUrl: "https://login.microsoftonline.com",
|
|
22
|
+
connectorScope: "https://api.botframework.com/.default",
|
|
23
|
+
fileHostSuffixes: ["sharepoint.com"],
|
|
24
|
+
redirectHosts: []
|
|
25
|
+
};
|
|
26
|
+
/** How long before `expiresAt` a cached token is dropped. */
|
|
27
|
+
const refreshMargin = /*#__PURE__*/Duration.minutes(5);
|
|
28
|
+
/**
|
|
29
|
+
* The trust step for a Connector base URL: `https:`, the default port, no
|
|
30
|
+
* userinfo and an exact host in the allowlist. Gives the URL without a
|
|
31
|
+
* trailing slash, or `undefined`.
|
|
32
|
+
*
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
export const trustedServiceUrl = (url, hosts) => {
|
|
36
|
+
const parsed = parseUrl(url);
|
|
37
|
+
if (parsed === undefined || parsed.protocol !== "https:" || parsed.port !== "" || parsed.username !== "" || parsed.password !== "" || parsed.search !== "" || parsed.hash !== "" || !hosts.includes(parsed.hostname)) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
return parsed.origin + parsed.pathname.replace(/\/+$/, "");
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Gets a token by client credentials, or from the consumer's provider, and
|
|
44
|
+
* caches it until five minutes before it expires. A token with no expiry is
|
|
45
|
+
* not cached.
|
|
46
|
+
*
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
export const makeTokens = options => {
|
|
50
|
+
const cache = new Map();
|
|
51
|
+
const lock = Semaphore.makeUnsafe(1);
|
|
52
|
+
const fail = reason => Effect.fail(Errors.chatError("token", reason));
|
|
53
|
+
const clientCredentials = secret => scope => Effect.gen(function* () {
|
|
54
|
+
const url = `${options.cloud.loginUrl}/${encodeURIComponent(options.tenantId)}/oauth2/v2.0/token`;
|
|
55
|
+
const request = HttpClientRequest.post(url).pipe(HttpClientRequest.bodyUrlParams({
|
|
56
|
+
grant_type: "client_credentials",
|
|
57
|
+
client_id: options.appId,
|
|
58
|
+
client_secret: Redacted.value(secret),
|
|
59
|
+
scope
|
|
60
|
+
}));
|
|
61
|
+
const response = yield* send(options.http, request, false, "token");
|
|
62
|
+
if (response.status !== 200) {
|
|
63
|
+
return yield* fail(Errors.reasonForStatus(response.status, {
|
|
64
|
+
write: false
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
const json = yield* response.json.pipe(Effect.catch(cause => fail(Errors.invalidResponse(false, "invalid_json", cause))));
|
|
68
|
+
if (!Predicate.isObject(json) || typeof json.access_token !== "string" || json.access_token === "") {
|
|
69
|
+
return yield* fail(Errors.invalidResponse(false, "missing_access_token"));
|
|
70
|
+
}
|
|
71
|
+
const now = yield* Clock.currentTimeMillis;
|
|
72
|
+
const expiresIn = typeof json.expires_in === "number" ? json.expires_in : Number(json.expires_in);
|
|
73
|
+
return {
|
|
74
|
+
token: Redacted.make(json.access_token),
|
|
75
|
+
...(Number.isFinite(expiresIn) && expiresIn > 0 ? {
|
|
76
|
+
expiresAt: DateTime.makeUnsafe(now + expiresIn * 1000)
|
|
77
|
+
} : {})
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
const provider = Redacted.isRedacted(options.credentials) ? clientCredentials(options.credentials) : options.credentials;
|
|
81
|
+
return scope => lock.withPermit(Effect.gen(function* () {
|
|
82
|
+
const now = yield* Clock.currentTimeMillis;
|
|
83
|
+
const cached = cache.get(scope);
|
|
84
|
+
if (cached !== undefined && cached.until > now) return cached.token;
|
|
85
|
+
cache.delete(scope);
|
|
86
|
+
const token = yield* retrySafe(provider(scope));
|
|
87
|
+
if (token.expiresAt !== undefined) {
|
|
88
|
+
const until = DateTime.toEpochMillis(token.expiresAt) - Duration.toMillis(refreshMargin);
|
|
89
|
+
if (until > now) cache.set(scope, {
|
|
90
|
+
token: token.token,
|
|
91
|
+
until
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return token.token;
|
|
95
|
+
}));
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* The client with Fetch's redirects off, for every request it sends,
|
|
99
|
+
* including those made by code the adapter hands it to, such as the key set.
|
|
100
|
+
*
|
|
101
|
+
* @internal
|
|
102
|
+
*/
|
|
103
|
+
export const noRedirects = http => HttpClient.transform(http, effect => Effect.provideService(effect, FetchHttpClient.RequestInit, {
|
|
104
|
+
redirect: "manual"
|
|
105
|
+
}));
|
|
106
|
+
/**
|
|
107
|
+
* The URL a request goes to, with its query parameters and without a hash.
|
|
108
|
+
*
|
|
109
|
+
* @internal
|
|
110
|
+
*/
|
|
111
|
+
export const effectiveUrl = request => {
|
|
112
|
+
const url = Option.getOrUndefined(HttpClientRequest.toUrl(request));
|
|
113
|
+
if (url === undefined) return undefined;
|
|
114
|
+
url.hash = "";
|
|
115
|
+
return url.href;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Sends one request with redirects off. A response from another URL than
|
|
119
|
+
* the request's, query included, means something followed a redirect, and
|
|
120
|
+
* is refused.
|
|
121
|
+
*
|
|
122
|
+
* @internal
|
|
123
|
+
*/
|
|
124
|
+
export const send = (http, request, write, op) => noRedirects(http).execute(request).pipe(Effect.catch(error => Effect.fail(Errors.chatError(op, Errors.transport(write, error.reason._tag, error)))), Effect.flatMap(response => response.url !== effectiveUrl(request) ? Effect.fail(Errors.chatError(op, Errors.untrustedUrl())) : Effect.succeed(response)));
|
|
125
|
+
/**
|
|
126
|
+
* The Connector client. `path` starts with `/v3/` and has its segments
|
|
127
|
+
* encoded by the caller.
|
|
128
|
+
*
|
|
129
|
+
* @internal
|
|
130
|
+
*/
|
|
131
|
+
export const make = options => {
|
|
132
|
+
const once = (method, path, body, callOptions) => {
|
|
133
|
+
const write = callOptions?.write === true;
|
|
134
|
+
const op = callOptions?.op ?? `${method} ${path.split("/").slice(0, 3).join("/")}`;
|
|
135
|
+
const fail = reason => Effect.fail(Errors.chatError(op, reason));
|
|
136
|
+
return Effect.gen(function* () {
|
|
137
|
+
const base = callOptions?.serviceUrl === undefined ? options.cloud.connectorUrl : trustedServiceUrl(callOptions.serviceUrl, options.cloud.connectorHosts);
|
|
138
|
+
if (base === undefined) return yield* fail(Errors.untrustedUrl());
|
|
139
|
+
const token = yield* Effect.mapError(options.token(options.cloud.connectorScope), Errors.withOp(op));
|
|
140
|
+
let request = HttpClientRequest.make(method)(base + path).pipe(HttpClientRequest.bearerToken(Redacted.value(token)), HttpClientRequest.setHeader("accept", "application/json"));
|
|
141
|
+
if (callOptions?.query !== undefined) request = HttpClientRequest.setUrlParams(request, callOptions.query);
|
|
142
|
+
if (body !== undefined) request = HttpClientRequest.bodyJsonUnsafe(request, body);
|
|
143
|
+
const response = yield* send(options.http, request, write, op);
|
|
144
|
+
const retryAfter = Errors.parseRetryAfter(response.headers["retry-after"]);
|
|
145
|
+
if (response.status < 200 || response.status >= 300) {
|
|
146
|
+
const json = yield* Effect.orElseSucceed(response.json, () => undefined);
|
|
147
|
+
const error = Predicate.isObject(json) && Predicate.isObject(json.error) ? json.error : undefined;
|
|
148
|
+
const code = typeof error?.code === "string" ? error.code : undefined;
|
|
149
|
+
return yield* fail(Errors.reasonForStatus(response.status, {
|
|
150
|
+
write,
|
|
151
|
+
retryAfter,
|
|
152
|
+
code
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
const text = yield* response.text.pipe(Effect.catch(cause => fail(Errors.invalidResponse(write, "invalid_body", cause))));
|
|
156
|
+
if (text.trim() === "") return undefined;
|
|
157
|
+
try {
|
|
158
|
+
return JSON.parse(text);
|
|
159
|
+
} catch (cause) {
|
|
160
|
+
return yield* fail(Errors.invalidResponse(write, "invalid_json", cause));
|
|
161
|
+
}
|
|
162
|
+
}).pipe(Effect.scoped);
|
|
163
|
+
};
|
|
164
|
+
return {
|
|
165
|
+
call: (method, path, body, callOptions) => {
|
|
166
|
+
const call = once(method, path, body, callOptions);
|
|
167
|
+
return callOptions?.retry === false ? call : retrySafe(call);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
/** Encodes one path segment. @internal */
|
|
172
|
+
export const segment = value => encodeURIComponent(value);
|
|
173
|
+
//# sourceMappingURL=connector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connector.js","names":[],"sources":["../../src/internal/connector.ts"],"sourcesContent":[null],"mappings":"AAAA,SAAS,SAAS,QAAQ,yBAAyB;AAEnD,OAAO,KAAK,KA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AAC,MAAM,CAAC,eAAe,CAAC,QAAQ,CAAC,MAAM,EAAE;UAAE,KAAK;UAAE,UAAU;UAAE;QAAI,CAAE,CAAC,CAAC;MAC1F;MACA,MAAM,IAAI,GAAG,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CACpC,MAAM,CAAC,KAAK,CAAE,KAAK,IAAK,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,cAAc,EAAE,KAAK,CAAC,CAAC,CAAC,CACpF;MACD,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,OAAO,SAAS;MACxC,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAgB;MACxC,CAAC,CAAC,OAAO,KAAK,EAAE;QACd,OAAO,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,cAAc,EAAE,KAAK,CAAC,CAAC;MAC1E;IACF,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;EACxB,CAAC;EACD,OAAO;IACL,IAAI,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,KAAI;MACxC,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,CAAC;MAClD,OAAO,WAAW,EAAE,KAAK,KAAK,KAAK,GAAG,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC;IAC9D;GACD;AACH,CAAC;AAED;AACA,OAAO,MAAM,OAAO,GAAI,KAAa,IAAa,kBAAkB,CAAC,KAAK,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ChatError } from "effect/chat/ChatError";
|
|
2
|
+
import * as HttpClient from "effect/http/HttpClient";
|
|
3
|
+
import * as Stream from "effect/Stream";
|
|
4
|
+
export declare function download(id: string, options: DownloadOptions): Stream.Stream<Uint8Array, ChatError, HttpClient.HttpClient>;
|
|
5
|
+
//# sourceMappingURL=download.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../src/internal/download.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAmB,MAAM,uBAAuB,CAAA;AAIvE,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAA;AAKpD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAwLvC,wBAAgB,QAAQ,CACtB,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,eAAe,GACvB,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,SAAS,EAAE,UAAU,CAAC,UAAU,CAAC,CAAA"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
3
|
+
import * as HttpClient from "effect/http/HttpClient";
|
|
4
|
+
import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
|
5
|
+
import * as Option from "effect/Option";
|
|
6
|
+
import * as Redacted from "effect/Redacted";
|
|
7
|
+
import * as Stream from "effect/Stream";
|
|
8
|
+
import * as Errors from "./errors.js";
|
|
9
|
+
import { isObject, object, parseUrl, string } from "./parse.js";
|
|
10
|
+
const op = "download";
|
|
11
|
+
/** The content type of a personal chat file the bot may fetch without credentials. @internal */
|
|
12
|
+
export const fileDownloadInfo = "application/vnd.microsoft.teams.file.download.info";
|
|
13
|
+
const kinds = ["connector", "preauth", "url"];
|
|
14
|
+
/**
|
|
15
|
+
* The path of a Connector attachment view:
|
|
16
|
+
* `/{region}/v3/attachments/{id}/views/{view}`, where the region segment may be
|
|
17
|
+
* absent. Each segment is letters, digits, `_` or `-`, and the URL has no
|
|
18
|
+
* query.
|
|
19
|
+
*
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export const connectorPath = /^(?:\/[A-Za-z0-9_-]+)?\/v3\/attachments\/[A-Za-z0-9_-]+\/views\/[A-Za-z0-9_-]+$/;
|
|
23
|
+
/** Whether `host` is `suffix` or ends with `.{suffix}`. @internal */
|
|
24
|
+
export const underSuffix = (host, suffixes) => suffixes.some(raw => {
|
|
25
|
+
const suffix = raw.toLowerCase().replace(/^\./, "");
|
|
26
|
+
return suffix.length > 0 && (host === suffix || host.endsWith(`.${suffix}`));
|
|
27
|
+
});
|
|
28
|
+
const isIpLiteral = host => host.startsWith("[") || /^\d+\.\d+\.\d+\.\d+$/.test(host);
|
|
29
|
+
/**
|
|
30
|
+
* Parses `input` and checks the parts every hop needs: `https:`, no userinfo,
|
|
31
|
+
* the default port and a host name rather than an IP literal. The fragment is
|
|
32
|
+
* dropped, since it is never sent.
|
|
33
|
+
*
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
export const safeUrl = (input, base) => {
|
|
37
|
+
const url = parseUrl(input, base);
|
|
38
|
+
if (url === undefined || url.protocol !== "https:" || url.username !== "" || url.password !== "" || url.port !== "" || url.hostname.length === 0 || isIpLiteral(url.hostname)) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
url.hash = "";
|
|
42
|
+
return url;
|
|
43
|
+
};
|
|
44
|
+
const size = record => {
|
|
45
|
+
const value = record.size;
|
|
46
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : undefined;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Turns a Bot Framework activity attachment into a chat attachment.
|
|
50
|
+
*
|
|
51
|
+
* - `connector:` when `contentUrl` has the origin of the activity's
|
|
52
|
+
* `serviceUrl`, its host is in `connectorHosts` and its path is
|
|
53
|
+
* {@link connectorPath}.
|
|
54
|
+
* - `preauth:` for a file download info attachment in a personal chat whose
|
|
55
|
+
* `content.downloadUrl` is under one of `fileHostSuffixes`. Its
|
|
56
|
+
* `contentType` is Teams' own, so it is left out.
|
|
57
|
+
* - `url:` for any other `https:` or `http:` `contentUrl`.
|
|
58
|
+
*
|
|
59
|
+
* An attachment with no usable URL, such as a card or the HTML copy of the
|
|
60
|
+
* message, is `undefined`.
|
|
61
|
+
*
|
|
62
|
+
* @internal
|
|
63
|
+
*/
|
|
64
|
+
export const classify = (attachment, context) => {
|
|
65
|
+
if (!isObject(attachment)) return undefined;
|
|
66
|
+
const contentType = string(attachment, "contentType");
|
|
67
|
+
const name = string(attachment, "name");
|
|
68
|
+
const content = object(attachment, "content");
|
|
69
|
+
const make = (id, type, bytes) => ({
|
|
70
|
+
id,
|
|
71
|
+
...(name === undefined ? {} : {
|
|
72
|
+
name
|
|
73
|
+
}),
|
|
74
|
+
...(type === undefined ? {} : {
|
|
75
|
+
contentType: type
|
|
76
|
+
}),
|
|
77
|
+
...(bytes === undefined ? {} : {
|
|
78
|
+
size: bytes
|
|
79
|
+
})
|
|
80
|
+
});
|
|
81
|
+
if (contentType === fileDownloadInfo && context.conversationType === "personal" && content !== undefined) {
|
|
82
|
+
const raw = string(content, "downloadUrl");
|
|
83
|
+
const url = raw === undefined ? undefined : safeUrl(raw);
|
|
84
|
+
if (url !== undefined && underSuffix(url.hostname, context.fileHostSuffixes)) {
|
|
85
|
+
return make(`preauth:${url.href}`, undefined, size(content) ?? size(attachment));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const raw = string(attachment, "contentUrl");
|
|
89
|
+
if (raw === undefined) return undefined;
|
|
90
|
+
const type = contentType === fileDownloadInfo ? undefined : contentType;
|
|
91
|
+
const url = safeUrl(raw);
|
|
92
|
+
const service = parseUrl(context.serviceUrl);
|
|
93
|
+
if (url !== undefined && service !== undefined && url.origin === service.origin && context.connectorHosts.has(url.hostname) && url.search === "" && connectorPath.test(url.pathname)) {
|
|
94
|
+
return make(`connector:${url.href}`, type, size(attachment));
|
|
95
|
+
}
|
|
96
|
+
const other = parseUrl(raw);
|
|
97
|
+
if (other === undefined || other.protocol !== "https:" && other.protocol !== "http:") return undefined;
|
|
98
|
+
return make(`url:${other.href}`, type, size(attachment));
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Splits an attachment id into its kind and URL.
|
|
102
|
+
*
|
|
103
|
+
* @internal
|
|
104
|
+
*/
|
|
105
|
+
export const parseId = id => {
|
|
106
|
+
const at = id.indexOf(":");
|
|
107
|
+
if (at === -1) return undefined;
|
|
108
|
+
const kind = kinds.find(kind => kind === id.slice(0, at));
|
|
109
|
+
return kind === undefined ? undefined : {
|
|
110
|
+
kind,
|
|
111
|
+
url: id.slice(at + 1)
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
/** The most redirects one download follows. @internal */
|
|
115
|
+
export const maxRedirects = 3;
|
|
116
|
+
const redirects = /*#__PURE__*/new Set([301, 302, 303, 307, 308]);
|
|
117
|
+
const fail = reason => Effect.fail(Errors.chatError(op, reason));
|
|
118
|
+
export function download(id, options) {
|
|
119
|
+
return Stream.unwrap(Effect.gen(function* () {
|
|
120
|
+
const parsed = parseId(id);
|
|
121
|
+
if (parsed === undefined) return yield* fail(Errors.invalidRequest("attachment_id"));
|
|
122
|
+
if (parsed.kind === "url") return yield* fail(Errors.unsupported("download", "url_attachment"));
|
|
123
|
+
const {
|
|
124
|
+
kind
|
|
125
|
+
} = parsed;
|
|
126
|
+
const redirectHosts = options.redirectHosts ?? new Set();
|
|
127
|
+
// The id's own allowlist. `redirectHosts` never vouches for the first
|
|
128
|
+
// hop, since the first hop of a `connector:` id is the one with the token.
|
|
129
|
+
const own = url => kind === "connector" ? options.connectorHosts.has(url.hostname) : underSuffix(url.hostname, options.fileHostSuffixes);
|
|
130
|
+
const allowed = url => own(url) || redirectHosts.has(url.hostname);
|
|
131
|
+
const first = safeUrl(parsed.url);
|
|
132
|
+
if (first === undefined || !own(first) || kind === "connector" && (first.search !== "" || !connectorPath.test(first.pathname))) {
|
|
133
|
+
return yield* fail(Errors.untrustedUrl());
|
|
134
|
+
}
|
|
135
|
+
const http = HttpClient.withScope(options.http ?? (yield* HttpClient.HttpClient));
|
|
136
|
+
const tooLarge = Errors.chatError(op, Errors.tooLarge("files", "max_bytes"));
|
|
137
|
+
const send = (url, hop) => Effect.gen(function* () {
|
|
138
|
+
let request = HttpClientRequest.get(url.href);
|
|
139
|
+
if (kind === "connector" && hop === 0) {
|
|
140
|
+
const token = yield* Effect.mapError(options.token, Errors.withOp(op));
|
|
141
|
+
request = HttpClientRequest.bearerToken(request, Redacted.value(token));
|
|
142
|
+
}
|
|
143
|
+
const sent = Option.getOrUndefined(HttpClientRequest.toUrl(request))?.href;
|
|
144
|
+
const response = yield* http.execute(request).pipe(Effect.provideService(FetchHttpClient.RequestInit, {
|
|
145
|
+
redirect: "manual"
|
|
146
|
+
}), Effect.provideService(HttpClient.TracerDisabledWhen, () => true), Effect.mapError(error => Errors.chatError(op, Errors.transport(false, error.reason._tag))));
|
|
147
|
+
yield* Effect.annotateCurrentSpan("http.response.status_code", response.status);
|
|
148
|
+
if (response.url !== sent) return yield* fail(Errors.untrustedUrl());
|
|
149
|
+
return response;
|
|
150
|
+
}).pipe(Effect.withSpan("TeamsChat.download.request", {
|
|
151
|
+
kind: "client",
|
|
152
|
+
attributes: {
|
|
153
|
+
"server.address": url.hostname,
|
|
154
|
+
"teams.download.hop": hop
|
|
155
|
+
}
|
|
156
|
+
}));
|
|
157
|
+
let url = first;
|
|
158
|
+
let response;
|
|
159
|
+
for (let hop = 0;; hop++) {
|
|
160
|
+
response = yield* send(url, hop);
|
|
161
|
+
if (!redirects.has(response.status)) break;
|
|
162
|
+
if (hop === maxRedirects) return yield* fail(Errors.invalidResponse(false, "too_many_redirects"));
|
|
163
|
+
const location = response.headers.location;
|
|
164
|
+
if (location === undefined) return yield* fail(Errors.invalidResponse(false, "missing_location"));
|
|
165
|
+
const next = safeUrl(location, url.href);
|
|
166
|
+
if (next === undefined || !allowed(next)) return yield* fail(Errors.untrustedUrl());
|
|
167
|
+
url = next;
|
|
168
|
+
}
|
|
169
|
+
if (response.status < 200 || response.status >= 300) {
|
|
170
|
+
return yield* fail(Errors.reasonForStatus(response.status, {
|
|
171
|
+
write: false
|
|
172
|
+
}));
|
|
173
|
+
}
|
|
174
|
+
const length = Number(response.headers["content-length"]);
|
|
175
|
+
if (Number.isFinite(length) && length > options.maxBytes) return yield* Effect.fail(tooLarge);
|
|
176
|
+
let received = 0;
|
|
177
|
+
return response.stream.pipe(Stream.mapError(error => Errors.chatError(op, Errors.transport(false, error.reason._tag))), Stream.mapEffect(chunk => {
|
|
178
|
+
received += chunk.length;
|
|
179
|
+
return received > options.maxBytes ? Effect.fail(tooLarge) : Effect.succeed(chunk);
|
|
180
|
+
}));
|
|
181
|
+
}));
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=download.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"download.js","names":[],"sources":["../../src/internal/download.ts"],"sourcesContent":[null],"mappings":"AAEA,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,eAAe,MAAM,6BAA6B;AAC9D,OAAO,KAAK,UAAU,MAAM,wBAAwB;AACpD,OAAO,KAAK,iBAAiB,MAAM,+BAA+B;AAElE,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,MAAM,MAAM,aAAa;AACrC,SAAS,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAAQ,YAAY;AAE/D,MAAM,EAAE,GAAG,UAAU;AAErB;AACA,OAAO,MAAM,gBAAgB,GAAG,oDAAoD;AAepF,MAAM,KAAK,GAAwB,CAAC,WAAW,EAAE,SAAS,EAAE,KAAK,CAAC;AAElE;;;;;;;;AAQA,OAAO,MAAM,aAAa,GAAG,iFAAiF;AAE9G;AACA,OAAO,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,QAA+B,KACvE,QAAQ,CAAC,IAAI,CAAE,GAAG,IAAI;EACpB,MAAM,MAAM,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,OAAO,C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