1 | import { urlEncode, makeDsn, dsnToString } from '@sentry/utils';
|
2 |
|
3 | var SENTRY_API_VERSION = '7';
|
4 |
|
5 |
|
6 | function getBaseApiEndpoint(dsn) {
|
7 | var protocol = dsn.protocol ? `${dsn.protocol}:` : '';
|
8 | var port = dsn.port ? `:${dsn.port}` : '';
|
9 | return `${protocol}//${dsn.host}${port}${dsn.path ? `/${dsn.path}` : ''}/api/`;
|
10 | }
|
11 |
|
12 |
|
13 | function _getIngestEndpoint(dsn) {
|
14 | return `${getBaseApiEndpoint(dsn)}${dsn.projectId}/envelope/`;
|
15 | }
|
16 |
|
17 |
|
18 | function _encodedAuth(dsn, sdkInfo) {
|
19 | return urlEncode({
|
20 |
|
21 |
|
22 | sentry_key: dsn.publicKey,
|
23 | sentry_version: SENTRY_API_VERSION,
|
24 | ...(sdkInfo && { sentry_client: `${sdkInfo.name}/${sdkInfo.version}` }),
|
25 | });
|
26 | }
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | function getEnvelopeEndpointWithUrlEncodedAuth(
|
34 | dsn,
|
35 | // TODO (v8): Remove `tunnelOrOptions` in favor of `options`, and use the substitute code below
|
36 | // options: ClientOptions = {} as ClientOptions,
|
37 | tunnelOrOptions = {} ,
|
38 | ) {
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | var tunnel = typeof tunnelOrOptions === 'string' ? tunnelOrOptions : tunnelOrOptions.tunnel;
|
44 | var sdkInfo =
|
45 | typeof tunnelOrOptions === 'string' || !tunnelOrOptions._metadata ? undefined : tunnelOrOptions._metadata.sdk;
|
46 |
|
47 | return tunnel ? tunnel : `${_getIngestEndpoint(dsn)}?${_encodedAuth(dsn, sdkInfo)}`;
|
48 | }
|
49 |
|
50 |
|
51 | function getReportDialogEndpoint(
|
52 | dsnLike,
|
53 | dialogOptions
|
54 |
|
55 | ,
|
56 | ) {
|
57 | var dsn = makeDsn(dsnLike);
|
58 | var endpoint = `${getBaseApiEndpoint(dsn)}embed/error-page/`;
|
59 |
|
60 | let encodedOptions = `dsn=${dsnToString(dsn)}`;
|
61 | for (var key in dialogOptions) {
|
62 | if (key === 'dsn') {
|
63 | continue;
|
64 | }
|
65 |
|
66 | if (key === 'user') {
|
67 | var user = dialogOptions.user;
|
68 | if (!user) {
|
69 | continue;
|
70 | }
|
71 | if (user.name) {
|
72 | encodedOptions += `&name=${encodeURIComponent(user.name)}`;
|
73 | }
|
74 | if (user.email) {
|
75 | encodedOptions += `&email=${encodeURIComponent(user.email)}`;
|
76 | }
|
77 | } else {
|
78 | encodedOptions += `&${encodeURIComponent(key)}=${encodeURIComponent(dialogOptions[key] )}`;
|
79 | }
|
80 | }
|
81 |
|
82 | return `${endpoint}?${encodedOptions}`;
|
83 | }
|
84 |
|
85 | export { getEnvelopeEndpointWithUrlEncodedAuth, getReportDialogEndpoint };
|
86 |
|